Answer the question
In order to leave comments, you need to log in
How to get current username in C++?
I want to get the username of the current Windows session, but nothing happens.
char buffer[256]; // буфер
DWORD size; // размер
size = sizeof(buffer); // размер буфера
GetUserName(buffer, &size);
string userName = buffer;
Answer the question
In order to leave comments, you need to log in
Windows indeed. In the headers, the function is defined like this:
BOOL WINAPI GetUserNameW(LPWSTR lpBuffer, LPDWORD lpnSize);
BOOL WINAPI GetUserNameA(LPSTR lpBuffer, LPDWORD lpnSize);
#ifdef _UNICODE
#define GetUserName GetUserNameW
#else
#define GetUserName GetUserNameA
#endif
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question