I tried https://stackoverflow.com/a/11587467/2738536
#include <windows.h>
#include <Lmcons.h>
char username[UNLEN+1];
GetUserName(username, UNLEN+1);
But I got this error: 'GetUserNameA' : cannot convert parameter 2 from 'int' to 'LPDWORD'
I tried https://stackoverflow.com/a/11587467/2738536
#include <windows.h>
#include <Lmcons.h>
char username[UNLEN+1];
GetUserName(username, UNLEN+1);
But I got this error: 'GetUserNameA' : cannot convert parameter 2 from 'int' to 'LPDWORD'
As per the documentation, the length you pass in has to be a pointer to a double-word, because the function changes it based on what's returned.
Hence you should have something like:
TCHAR username[UNLEN+1]; // TCHAR to allow for MBCS and Unicode
DWORD len = UNLEN + 1; // if you're in to that sort of thing :-)
GetUserName(username, &len);
The type LPDWORD
is actually a pointer.
You need to do something like the following:
char username[UNLEN + 1];
DWORD name_length = ULEN + 1;
GetUserName(username, &name_length);