How to get path of executable
-
How can I get the path of the executable? I want to Open a file in the same directory - the problem is that something causes the relative directory to change, so just specifying the filename can give me a FileNotFound exception. thanks, Jake ***** Jake Palmer www.duke.edu/~jp6
-
How can I get the path of the executable? I want to Open a file in the same directory - the problem is that something causes the relative directory to change, so just specifying the filename can give me a FileNotFound exception. thanks, Jake ***** Jake Palmer www.duke.edu/~jp6
Its easy. use function GetModuleFileName like this
char szFileName[MAX_PATH]; GetModuleFileName(NULL,szFileName,MAX_PATH);
but you want to know the directory of your file you can use function GetCurrentDirectory like thischar szFileName[MAX_PATH]; GetCurrentDirectory(MAX_PATH,szFileName);
Secondly you may be having this problem because you are executing the file from within visual c which makes the parent folder the working directory and not the "Debug" or "Release" folder of your project. Put the file you want to access in the parent of your "Debug" folder. In my dream, I was dorwning in my §orrow§ But my §orrow§, they learned to §wim -
How can I get the path of the executable? I want to Open a file in the same directory - the problem is that something causes the relative directory to change, so just specifying the filename can give me a FileNotFound exception. thanks, Jake ***** Jake Palmer www.duke.edu/~jp6
Since GetModuleFileName(...) has some restrictions when used under Win9x, I prefer to evaluate the public variable CWinApp::m_pszHelpFilePath.