Error GetModuleFileName Visual Studio

Hello guys, i'm here with this code:
1
2
3
4
5
6
7
8
9
10
string exePath() {
	string path;
	char buffer[MAX_PATH];
	cout << "reading path\n";
	GetModuleFileName(NULL, buffer, MAX_PATH);
	string::size_type pos = string(buffer).find_last_of("\\/");
	path = string(buffer).substr(0, pos)/*+"\\system.exe"*/;
	return path;

}


i'm using VisualStudio, it gives me error at the second parameter (buffer):

the type "char *" argument is incompatible with the type parameter "LPWSTR" (translated from italian,i have vs in italian, hope you understand)

This code compile fine with code::blocks and dev c++ but only in vs doesn't

Thanks for your help!!
Can't convert char to LPWSTR
LPWSTR is for wide characters (type wchar_t ).
Since your buffer is of type char you need to use the ANSI version.

GetModuleFileNameA(NULL, buffer, MAX_PATH); - note the final character of the function name is 'A'.
thanks, now it works!
Topic archived. No new replies allowed.