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.

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.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

char szModName[MAX_PATH];

Replace with:

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mugman21Author Commented:
Well, that was stupid :-)

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.