Getting process name + path from PID

Hello experts,

I need the image name and path from a PID. I found this example code on MSDN's site, but I'm having some trouble with it. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/perfmon/base/enumerating_all_modules_for_a_process.asp

I'm using VC 2005 Express and it wont compile without a typecast on the 3rd parameter of GetModuleFileNameEx. If I do type cast it as (LPWSTR), then I run into stack curruption. When it does run, I only get a single char returned "C", without the path or image name.

Can someone please help me out here, I just need to resolve random PID's to image/path.

Thanks
LVL 8
mugman21Asked:
Who is Participating?
 
AlexFMConnect With a Mentor Commented:
char szModName[MAX_PATH];

Replace with:

TCHAR szModName[MAX_PATH];
or:
wchar szModName[MAX_PATH];

VC++ 8.0 creates Unicode applications by default.
If you don't want Unicode, you can change Character Set parameter in the Project Settings.
0
 
mugman21Author Commented:
Well, that was stupid :-)

Thanks
0
All Courses

From novice to tech pro — start learning today.