arnold100
asked on
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.
Thanks,
AJ.
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.
Thanks,
AJ.
Just pass NULL as module handle.
<quote>
hModule
[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.
</quote>
<quote>
hModule
[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.
</quote>
ASKER
This works: lstrcpy( (char *) szFilePath ,LPCTSTR("c:\\Dir\\file.ex e") );
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).
Thanks,
AJ.
But the path is known.
This doesn't: lstrcpy( (char *) szFilePath ,LPCTSTR(GetModuleFileName
Unknown path.
How do I make this return the full path? (c:\Dir\file.exe).
Thanks,
AJ.
Just use it directly :
char szFilePath[MAX_PATH];
GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
char szFilePath[MAX_PATH];
GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
ASKER
I have to use lstrcpy( (char *) szFilePath ,LPCTSTR("c:\\Dir\\file.ex e") ); because I need unsigned char szFilePath; for RegSetValueEx.
I get errors when I try to use unsigned char in GetModuleFileName.
Any ideas?
Thanks,
AJ.
I get errors when I try to use unsigned char in GetModuleFileName.
Any ideas?
Thanks,
AJ.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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,
AJ.
Works perfect.
Thank you very much for your help, Excellent,
AJ.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getmodulefilename.asp