Obtaining an Application's Folder
-
I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron
-
I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron
Well I dont use MFC I only know the API way so: you can get it like this: [code] char path[_MAX_PATH]; GetModuleFileName(GetModuleHandle(NULL), path, _MAX_PATH ); [/code] Path holds the full address of your exe like "C:\Program Files\Program\test.exe" just delete text.exe from it and its done... Well... I am a beginner ...
-
I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron
You might want to check this article out. (in particular, the last 3/4 topics) How To Write a Windows XP Application That Stores User and Application Data in the Correct Location by Using Visual C++ .NET You could run into access problems when users run the app from a limited account in the Program Files\App folder.
Painted on the side of a dog trainer's van: SIT HAPPENS
-
I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron
Check if this code is of any help :-
//========================= // Get Current Path //========================= CString szCurrentDirectory; { CString csPath; //==================== // Get File Path //==================== ::GetModuleFileName(NULL,csPath.GetBuffer(MAX_PATH),MAX_PATH); csPath.ReleaseBuffer(); //==================== //Get current Directory //==================== szCurrentDirectory=csPath.Left(csPath.ReverseFind('\\')); }
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
I am using MFC and want to know the application folder (typically, but not necessarily "C:\Program Files\MyProgram") so I can read and save an initialization file for the program. A program that uses the main() function, arg[0] is usually the program's command line with subsequent arg[n] being the additional command line parameters. CWinApp does not appear to provide this information and I have looked through the help files and the CodeProject message board without success. Any help would be greatly appreciated. TIA Ron