Click to See Complete Forum and Search --> : GetSaveFileName() fails


ReneG
March 17th, 2004, 04:27 PM
Hi, can anyone help me figure out why my GetSaveFileName fails..?

char FileBuffer[500];
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = MainWindow.Handle;
ofn.lpstrFilter = "Filetype (*.tst)\0*.tst\0\0";
ofn.lpstrFile = FileBuffer;
ofn.nMaxFile = sizeof(FileBuffer);
ofn.lpstrDefExt = "tst";
ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT;
GetSaveFileName(&ofn)

I checked CommDlgExtendedError(), and it returns CDERR_INITIALIZATION, so i guess it must be something in the OPENFILENAME structure i haven't filled out correctly...

Any help is greatly appreciated!

Best regards
ReneG

imthesponge
March 18th, 2004, 03:24 AM
ofn.lpstrFilter = "Filetype (*.tst)\0*.tst\0\0";

You only need to append one null at the end, the one added automatically counts as one.

ReneG
March 18th, 2004, 03:58 AM
Okay, you're right. But it still doesn't show my Save dialog. :(

imthesponge
March 18th, 2004, 04:14 AM
Maybe setting the first byte of lpstrFile to zero would make it work? I dunno.

ReneG
March 18th, 2004, 04:43 AM
You know what? That worked!! Thanks alot sponge! :D

imthesponge
March 18th, 2004, 04:49 AM
Glad to be of assistance. :)