Knowing the directory in which an App resides
-
Hello, How can I know the path of a running app without recurring to neither registry entries nor to an .INI file ? I have been checking
CWinApp
for a function or variable member but was unable to find one... Any suggestions? David BTW,m_pszExeName/m_pszAppName
inCWinApp
do not retrieve the path... -
Hello, How can I know the path of a running app without recurring to neither registry entries nor to an .INI file ? I have been checking
CWinApp
for a function or variable member but was unable to find one... Any suggestions? David BTW,m_pszExeName/m_pszAppName
inCWinApp
do not retrieve the path... -
Hello, How can I know the path of a running app without recurring to neither registry entries nor to an .INI file ? I have been checking
CWinApp
for a function or variable member but was unable to find one... Any suggestions? David BTW,m_pszExeName/m_pszAppName
inCWinApp
do not retrieve the path...There is this Windows API function: GetCurrentDirectory. GetModuleFileName will only give you the file name, like "module.dll" instead of "C:\Program Files\Your Company\Your Product\bin\module.dll", the complete path. The prototype is as follows:
DWORD GetCurrentDirectory(DWORD nBufferLength, LPTSTR lpBuffer);
Greetings. I know there's something so dear to me, beyond words, beautiful feelings in my soul, sounds I've heard like humming birds in a dream. That mystical one I knew is returned, lulling me with those raincloud eyes, taking me and melting my heart away. -
There is this Windows API function: GetCurrentDirectory. GetModuleFileName will only give you the file name, like "module.dll" instead of "C:\Program Files\Your Company\Your Product\bin\module.dll", the complete path. The prototype is as follows:
DWORD GetCurrentDirectory(DWORD nBufferLength, LPTSTR lpBuffer);
Greetings. I know there's something so dear to me, beyond words, beautiful feelings in my soul, sounds I've heard like humming birds in a dream. That mystical one I knew is returned, lulling me with those raincloud eyes, taking me and melting my heart away.Wrong. GetCurrentDirectory will not always return the directory that the executable is in. You can not assume that it does as an a shortcut could change the working directory, the program can change the working directory or the user could launch the program from a command window using the full path. In each case GetCurrentDirectory will not be the directory that the program resides. GetModuleFileName returns the correct result. Here is the doc: GetModuleFileName The GetModuleFileName function retrieves the full path and file name for the file containing the specified module. John
-
There is this Windows API function: GetCurrentDirectory. GetModuleFileName will only give you the file name, like "module.dll" instead of "C:\Program Files\Your Company\Your Product\bin\module.dll", the complete path. The prototype is as follows:
DWORD GetCurrentDirectory(DWORD nBufferLength, LPTSTR lpBuffer);
Greetings. I know there's something so dear to me, beyond words, beautiful feelings in my soul, sounds I've heard like humming birds in a dream. That mystical one I knew is returned, lulling me with those raincloud eyes, taking me and melting my heart away.I use GetModuleFileName() and it returns the whole path for me. In the app I wrote I use this to append a "\\temp" to the end of it for a call to CreateDirectory to create a temp folder in the same folder where the app resides. So as far as I know GetModuleFileName returns the whole path. I have a call to it like this in my app:
::GetModuleFileName(NULL,szPath,512);
where 'szPath' is declaredchar szPath[512];
[insert witty comment here] bdiamond :zzz: -
I use GetModuleFileName() and it returns the whole path for me. In the app I wrote I use this to append a "\\temp" to the end of it for a call to CreateDirectory to create a temp folder in the same folder where the app resides. So as far as I know GetModuleFileName returns the whole path. I have a call to it like this in my app:
::GetModuleFileName(NULL,szPath,512);
where 'szPath' is declaredchar szPath[512];
[insert witty comment here] bdiamond :zzz:bdiamond wrote: ::GetModuleFileName(NULL,szPath,512); It's not a good idea to use constants like this. If the size of your variable ever changed, you could easily miss one. Use the
sizeof
operator instead.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
bdiamond wrote: ::GetModuleFileName(NULL,szPath,512); It's not a good idea to use constants like this. If the size of your variable ever changed, you could easily miss one. Use the
sizeof
operator instead.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
sorry, but you know from experience that I'm not the brightest guy around:) Is this what you're saying I should do?
char szPath[512]; ::GetModuleFileName(NULL,szPath,sizeof(szPath));
[insert witty comment here] bdiamond :zzz:bdiamond wrote: Is this what you're saying I should do? Correct.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
bdiamond wrote: Is this what you're saying I should do? Correct.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen