tags:

views:

299

answers:

2

Here is my code:

TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
GetModuleFileNameEx (hProcess, NULL, szProcessName, 
                     sizeof(szProcessName)/sizeof(TCHAR));

I need the path in char*, and not in TCHAR[]. Is it somehow possible without converting (WideCharToMultiByte)?

Thanks...

+5  A: 

GetModuleFileNameEx is just a macro. You could use GetModuleFileNameExA for ANSI version. It will call GetModuleFileNameExW and then internally make all conversions.

But you should make sure that module filename does not contain Unicode characters.

char szProcessName[MAX_PATH] = "<unknown>";
GetModuleFileNameExA(hProcess, NULL, szProcessName, sizeof szProcessName);
Kirill V. Lyadvinsky
Thank, but why is it throws an error: // TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>"); char* szProcessName = "<unknown>"; GetModuleFileNameExA (hProcess, NULL, szProcessName, MAX_PATH);printf("%s", szProcessName);
It might be easier to figure out what you are trying to say if you edit your original post ...
Goz
szProcessName should be large enough to keep MAX_PATH characters.
Kirill V. Lyadvinsky
Unknown, you had an array at first. That was correct. When you changed the base type to `char`, you also made it a pointer instead of an array. That was wrong. Keep it as an array.
Rob Kennedy
A: 

Note that if you're not building a Unicode application (i.e., _UNICODE is not defined), then TCHAR == char

Paul Mitchell