I'm writing a small app and upon exit it saves its various setting in a .dat file in the base directory.

I've run into a problem when I use the OpenFile Dialog to load a file. It must affect the base directory of the program so that when I exit the .dat file gets created in the folder from which I loaded the other file.

Is there any way to reset the directory to which the .dat file gets saved or maybe specify it somehow in its path address.

I'm sure that this is a simple problem but off hand I can't find any solution.
Posted on 2001-08-12 20:53:11 by Eóin
There's a number of things you can do. Firts, you could GetCurrentDirectory
on program startup, and SetCurrentDirectory before writing your file.
But since you can change program working folder when doing shortcuts,
this is a bad solution imo.

A better (but tougher) solution would be to GetCommandLine and
parse this, since it has the executable filename as the first part.
Split off the filename and the rest of the commandline, and you will
be left with the directory your program executable is in. Be sure to
handle cases where the program file is enquoted (" "), and also cases
where it isn't. Damn win32, it should be consequent and ALWAYS
quote the filename.... but it isn't.
Posted on 2001-08-13 00:55:05 by f0dder
use GetAppPath (from m32lib) to get full path of your app
use SetCurrentDirectory to set directory you need
if you want OpenFile to open in the particular directory use
fullpath names (or just directory) with the structure to set current directory
you need for the dialog
Posted on 2001-08-13 03:49:21 by The Svin
you can also use the GetModuleFileName and strip of the
exe name. This prevents you from ugly fights against the
different possibilities of ordering the " signs in the command line.
Posted on 2001-08-13 03:54:44 by beaster
GetAppPath is actually using
GetModuleFileName to retrive the app path
Posted on 2001-08-13 05:12:43 by The Svin
Nice beaster, I hadn't thought of that way to do it :)
Posted on 2001-08-13 08:38:26 by f0dder