Configuration File

The following code I'm using creates a runtime error, I'm unsure why. What have I done wrong here?

Also will "\"'s in the Config file be counted as escape chars?

1
2
3
4
5
char *szDir = _getcwd(NULL, MAX_PATH);
strcat(szDir, "\\Config.ini");
char	*szPath;
DWORD	Size;
Size = GetPrivateProfileString("Global", "Path", "", szPath, sizeof(szPath), szDir);


Config.ini
1
2
[Global]
Path=C:\Program Files\Some Folder\Program.exe
szPath needs to be a buffer. At the moment, it's an uninitialised pointer.
szPath is always being set to the default now.

1
2
3
4
char	szPath[MAX_PATH];
DWORD	Size;
Size = GetPrivateProfileString("Global", "Path", "Default", szPath, sizeof(szPath), szDir);
MessageBox(0, szPath, "", 0);


1
2
[Global]
Path=H:\Program Files\Diablo II\Game.exe


Edit:

Weird, if I launch the program manually, instead of hitting F5 in VS it works.
Last edited on
Topic archived. No new replies allowed.