header file: Windows.h
BOOL WINAPI GetUserName(__out LPTSTR lpBuffer, __inout LPDWORD lpnSize);
This function retrieves the name of the current user.
The GetUserName function will provide the same information as
the Unix getlogin() function, but with a slightly different format.
Instead of returning the unsername, GetUserName stores it in the
parameter lpBuffer. It also requires a second parameter, lpnSize,
that specifies the size of lpBuffer. For complete details, see the
MSDN article.
Example of Use in Windows
#include <Winsock2.h>
char* buffer[256];
if (GetUserName(buffer, 256) == 0)
printf("The local username is %s.", buffer);
else
printf("GetUserName error.");