I recently switched from Visual studio code to Visual studio 2019 because I wanted to download C++ package using VCPKG.
My code worked on Visual Studio Code but do not work on Visual Studio 2019, maybe because it's not the same compilator.
The code I found on a StackOverflow post (Get Computer Name and logged user name) retrieve the Computer name and the Username of a PC.
#define INFO_BUFFER_SIZE 32767
TCHAR infoBuf[INFO_BUFFER_SIZE];
DWORD bufCharCount = INFO_BUFFER_SIZE;
SID_IDENTIFIER_AUTHORITY pIdentStruct = SECURITY_NT_AUTHORITY;
PSID ptrSidStruct;
BOOL isMember;
Constructor::Contructor(): c_online(true), c_status("Alive"), c_master("Master IP"), c_port(80)
{
bufCharCount = INFO_BUFFER_SIZE;
if (GetComputerName(infoBuf, &bufCharCount))
{
c_pc = TEXT(infoBuf);
}
bufCharCount = INFO_BUFFER_SIZE;
if (GetUserName(infoBuf, &bufCharCount))
{
c_user = TEXT(infoBuf);
}
}
However while using the TEXT() function, I get the error "LinfoBuf not define". I don't understand this error, plus I declared infoBuf not LinfoBuf. I didn't find the GetUserName function using <windows.h> in MSND documentation but I found GetUserNameA using the header <winbase.h>