Win32 - Get current directory fails
Posted: Fri Jun 07, 2013 8:29 am
I have coded an application which loads some data files. The application has no fixed path. The filestructure looks something liks this:
[code
..\MyApplication\App.exe
\MyApplication\Data\file001.dat
[/code
To get the current direcory i used:
This works only as long, as i change to the directory of the executeable and run it from its folder. All datafiles will be loaded and currentDir.s is correct.
I added the path and its executeable filename to the AutoRuns entry in the registry, so the application will be started directly at booting / starting the system.
The application is running but it does not find any datafiles and currentDir.s returns an incorrect path, which shows always: "c:\windows\system32\"
So i tried another next code to get the correct path to get the application work - even with autorun.
This returns the correct path of the executeable - but always including the filename of the executeable. Is there any other API / way to get just only the full correct path - without filename?
[code
..\MyApplication\App.exe
\MyApplication\Data\file001.dat
[/code
To get the current direcory i used:
Code: Select all
Global currentDir.s = Space(#MAX_PATH)
GetCurrentDirectory_(255,@currentDir.s)
...
The path for loading the files looks something like: Load( currentDir.s + "\Data\File001.dat")
I added the path and its executeable filename to the AutoRuns entry in the registry, so the application will be started directly at booting / starting the system.
The application is running but it does not find any datafiles and currentDir.s returns an incorrect path, which shows always: "c:\windows\system32\"

So i tried another next code to get the correct path to get the application work - even with autorun.
Code: Select all
currentDir.s = Space(#MAX_PATH)
GetModuleFileName_(0,@currentDir.s, 255)