# Win32 File Open/Save Dialog Weirdness

## Recommended Posts

Shock    140
Hello All! Im getting some weird issues with open/save file dialogs in Win32. I create/load my resources from my base path. For example to create a log file when running I would call fopen( "event.log", "w");. As you can see I dont include the full path. Now I need to save/open files in my program. The problem is not opening but saving. If I call GetOpenFileName() all works fine. If I call GetSaveFileName() its like my entire 'program base path' changes to the path where I save my files. For example the log I just created above gets moved to this new path as soon as I click ok. I ZeroMemory() OPENFILENAME structures before use. I checked the following: HINSTANCE's, HWND's, FILE NAME STRING BUFFERS, BUFFER SIZES, etc... I declare these structures in C++ method scope, they arn't being passed as arguments.

wchar_t world_name[ MAX_PATH ] = "";

/* Before we can create the world we need to save it's file for the first time */
/* Setup open file structure */
OPENFILENAME sfn;
ZeroMemory( &sfn, sizeof(sfn) );
sfn.hInstance = GetModuleHandle(0);
sfn.lStructSize = sizeof(sfn);
sfn.hwndOwner = window_get_handle();
sfn.lpstrFile = world_name;
sfn.nMaxFile = sizeof(world_name) / sizeof(wchar_t);
sfn.lpstrFilter = L"World\0*.wsf\0";
sfn.lpstrFileTitle = 0;
sfn.nMaxFileTitle = 0;
sfn.lpstrTitle = L"Save Created World As...";
sfn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;

/* Create and show the 'save file' dialog */
if ( ! GetSaveFileName( &sfn ) )
{
/* World creation aborted because user did not click ok when saving the file */
return false;
}



##### Share on other sites
Sandman    2210
There could be an implicit call to SetCurrentDirectory in the GetSaveFilename function.... It's not documented but the MSDN does have one or two omissions here and there [grin]

Try calling GetCurrentDirectory before and after the call... if it changes then you know this is the problem... and you should be able to remedy it fairly easily.

##### Share on other sites
Shock    140

Sandman, thank you very much! You are right!

I checked it before and after the call. Afterwards it was set to the save file path and no longer the path the program resides in.

Thanks Alot for the help!