1

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...

2 Answers 2

6

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);
4
  • 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);
    – user145586
    Aug 3, 2009 at 9:46
  • It might be easier to figure out what you are trying to say if you edit your original post ...
    – Goz
    Aug 3, 2009 at 9:48
  • szProcessName should be large enough to keep MAX_PATH characters. Aug 3, 2009 at 9:49
  • 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. Aug 3, 2009 at 14:25
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.