GetCurrentDirectory vs GetModuleFileName
-
Hi! I develop my own application using Visual C++. I need to get a directory where my application is launched. I've found in MSDN two function: GetCurrentDirectory and GetModuleFileName. It seems that both methods are shown the right results (except for GetModuleFileName I need to make ReverseFind the first slash - but it's not hard to do). What method is the best ? Yours sincerely, Alex Bash
-
Hi! I develop my own application using Visual C++. I need to get a directory where my application is launched. I've found in MSDN two function: GetCurrentDirectory and GetModuleFileName. It seems that both methods are shown the right results (except for GetModuleFileName I need to make ReverseFind the first slash - but it's not hard to do). What method is the best ? Yours sincerely, Alex Bash
I strongly recommend you to use
GetModuleFileName
, this will give you the correct result. Be careful withGetCurrentDirectory
, this will return the path your app is currently working in. E.g. if you create a file in "C:\Windows", this will be the current directory, regardless of whether your app is located there or not. regards Greg -
I strongly recommend you to use
GetModuleFileName
, this will give you the correct result. Be careful withGetCurrentDirectory
, this will return the path your app is currently working in. E.g. if you create a file in "C:\Windows", this will be the current directory, regardless of whether your app is located there or not. regards Greg -
At the first state of application (I don't perform any creating of files) - do GetModuleFileName and GetCurrentDirectory show the same results ? Yours sincerely, Alex Bash
They can, but need not. Example: Create a shortcut to your program. Modify the shortcut and specify a different directory for the working directory. Run the program using the shortcut. When you do this, those API routines will return two different things. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
At the first state of application (I don't perform any creating of files) - do GetModuleFileName and GetCurrentDirectory show the same results ? Yours sincerely, Alex Bash