How to get the complete path to my file in my file.

Hi experts,
I am working in vc++ 6 mfc and I need code to get the full path to my program from within my program. My program uses a registry key to start up when the computer starts. If the user installs my program to the default directory in my installer all is fine. The problem is when they install to a different directory the registry key points to the wrong path. I need a way to find the new path. I looked at the GetFilePath fuction but it doesn't take any parameters. How can it return the path if it doesn't
take any parameters? Vc++ help doesn't give much on it.

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.

Just pass NULL as module handle.

[in] Handle to the module whose path is being requested. If this parameter is NULL, GetModuleFileName retrieves the path of the executable file of the current process.
arnold100Author Commented:
This works: lstrcpy( (char *) szFilePath ,LPCTSTR("c:\\Dir\\file.exe") );
But the path is known.

This doesn't: lstrcpy( (char *) szFilePath ,LPCTSTR(GetModuleFileName(NULL,file.exe,20)) );
Unknown path.
How do I make this return the full path? (c:\Dir\file.exe).

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Just use it directly :

  char szFilePath[MAX_PATH];
  GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
arnold100Author Commented:
I have to use lstrcpy( (char *) szFilePath ,LPCTSTR("c:\\Dir\\file.exe") ); because I need unsigned char szFilePath; for RegSetValueEx.
I get errors when I try to use unsigned char in GetModuleFileName.
Any ideas?

Well then, following should compile ok I think :

  char szModulePath[MAX_PATH];
  GetModuleFileName(NULL, szModulePath, sizeof(szModulePath));
  lstrcpy( (char *) szFilePath ,LPCTSTR(szModulePath) );

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
arnold100Author Commented:
Got it by copying a char in to unsigned char and using the value in RegSetValueEx.
Works perfect.

  Thank you very much for your help, Excellent,
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.