Hello everybody, I'm trying to get the user name using GetUserName() API function, it was sucessful in the console project however in the Visual C++ project it gives me this error:

1>MyProgram.obj : error LNK2028: unresolved token (0A00000F) "extern "C" int __stdcall GetUserNameA(char *,unsigned long *)" (?GetUserNameA@@$$J18YGHPADPAK@Z) referenced in function "private: void __clrcall MyProgram::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@MyProgram@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>MyProgram.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall GetUserNameA(char *,unsigned long *)" (?GetUserNameA@@$$J18YGHPADPAK@Z) referenced in function "private: void __clrcall MyProgram::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@MyProgram@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

And I'm using this piece of code:

char LoginID[256];
DWORD buffer = 256;
GetUserName(LoginID, &buffer);

Any Help appreciated :).

Edited 6 Years Ago by Jiwe: n/a

error LNK2028: unresolved token (0A00000F) "extern "C" int __stdcall GetUserNameA(char *,unsigned long *)"

Where is GetUserNameA() defined?

It's part of the windows.h library I think?

Edited 6 Years Ago by Jiwe: n/a

It's part of the windows.h library I think?

Yes it is, but you need to be sure that you link with Advapi32.lib.

In Visual Studio, open

Project properties / Configuration properties / Linker / Input / Additional Dependencies

and add Advapi32.lib there.

This question has already been answered. Start a new discussion instead.