Nakruf Nakruf - 10 days ago 5
C++ Question

Trying to find exec file using GetModuleFileName but returns numbers

Here is my code. I have a buffer to save the output but it returns numbers. could someone explain this and how would I be able to get my exe file?

wchar_t buffer[MAX_PATH];
GetModuleFileName(NULL,buffer,sizeof(buffer));
cout << buffer << "\n";

Answer

cout is ansi version of console output. You have to use wide version of cout: wcout:

wchar_t buffer[MAX_PATH];
GetModuleFileName(NULL,buffer,sizeof(buffer));
wcout << buffer << "\n";

Or use the ansi version of everything:

char buffer[MAX_PATH];
GetModuleFileNameA(NULL,buffer,sizeof(buffer));
cout << buffer << "\n";
Comments