convert wchar_t* to LPSTR {aka char*}

Hello,


wchar_t buffer[50];
//wchar_t buffer[50] = {0};

GetModuleBaseName(hProcess, 0, buffer, 50);

The compile error I get is :-
cannot convert 'wchar_t*' to 'LPSTR {aka char*}' for argument '3' to 'DWORD GetModuleBaseNameA(HANDLE, HMODULE, LPSTR, DWORD)' GetModuleBaseName(hProcess, 0, buffer, 50);

Can someone suggest a solution?

Regards
1
2
3
char buffer[50];

GetModuleBaseName(hProcess, 0, buffer, 50);

1
2
3
wchar_t buffer[50];

GetModuleBaseNameW(hProcess, 0, buffer, 50);
1
2
  TCHAR buffer[50] = {0};
  GetModuleBaseName(hProcess, 0, buffer, 50);
Hello,

Thanks for your replies, gives me something to play with.

Regards
if your prefer to write your own conversions rather than using libraries, heres something that will work on any platform.

//pass in wchar pointer and wchar length

1
2
3
4
5
6
7
char * buff = new char[wcharLength+1];//alloc space for conversion plus 1, null terminate
buff[wcharLength] = 0;
for ( ;; )
{
	*buff++ = (wCharBuff) *wCharBuff;
	if(!*wCharBuff++)break;
}


forgot to mention this will only display properly if your using non unicode, if you need that and your using windows you could use WideCharToMultiByte
Last edited on
Topic archived. No new replies allowed.