OPENFILENAME structure usage for GetSaveFileName

S

Simon K

LPTSTR szName ="";

sfn.lStructSize = sizeof(OPENFILENAME);
sfn.hwndOwner = hWnd;
sfn.lpstrFilter = NULL;
sfn.lpstrFilter = TEXT("Play List File(*.plc)\0*.plc\0\0");
sfn.lpstrCustomFilter = NULL;
sfn.nFilterIndex = 1;
sfn.lpstrFile = szName;
sfn.nMaxFile = MAX_PATH;
sfn.lpstrTitle = TEXT("Save Play list as...\0");
sfn.lpstrFileTitle = NULL;
sfn.lpstrDefExt = TEXT("*\0");
sfn.Flags = OFN_CREATEPROMPT | OFN_OVERWRITEPROMPT |
OFN_NOREADONLYRETURN;

if(bSetInitialDir == FALSE)
{
sfn.lpstrInitialDir = TEXT(".\0");
bSetInitialDir = TRUE;
}
else
sfn.lpstrInitialDir = NULL;


GetSaveFileName((LPOPENFILENAME)&sfn);


I'm trying to get a file name to SAVE something. I set the
OPENFILENAME structure as above and I call GetSaveFileName.

Well, the Save Dialog shows up and as I press the SAVE button on the
dialog, an access violation error occurs only to launch a disassembly
code.

I really don't get what I've done wrong with this.
 
I

Ian Collins

Simon said:
I'm trying to get a file name to SAVE something. I set the
OPENFILENAME structure as above and I call GetSaveFileName.

Well, the Save Dialog shows up and as I press the SAVE button on the
dialog, an access violation error occurs only to launch a disassembly
code.
I haven't a clue which library this is, maybe you should try a platform
or library specific group.
 
S

Simon K

I haven't a clue which library this is, maybe you should try a platform
or library specific group.

it's from the common dialog box library.
static OPENFILENAME sfn;

btw, thx for advice
 
Z

zhangyw80

it's from the common dialog box library.
static OPENFILENAME sfn;

btw, thx for advice

the sfn.lpstrFile must be a buffer long enough
you should declare szName like this:
TCHAR szName[MAX_PATH] = "";
then when GetSaveFileName return,
you can get the selected file path from szName
 
R

red floyd

Simon K wrote:
[Windows API question redacted]

It's OT here. This is a Windows API. ISO/IEC 14882 does not discuss
OPENFILENAME or GetSaveFileName or Common Dialogs.

Try MSDN or a newsgroup with "Windows" in its name.
 
C

Christopher

it's from the common dialog box library.
static OPENFILENAME sfn;
btw, thx for advice

the sfn.lpstrFile must be a buffer long enough
you should declare szName like this:
TCHAR szName[MAX_PATH] = "";
then when GetSaveFileName return,
you can get the selected file path from szName


zhangy - rather than promote OT discussion by supplying an answer.
Could you please, in the future refer the poster to an appropriate
newsgroup and answer it there? If we keep on providing answers to OT
topics, people will keep asking for them and the NG will get cluttered
with obscure questions. I'd be happy to have answered this question
had I seen it on one of the microsoft.public ui programming groups or
thier forum, both of which could use more traffic.
 
R

Ron Natalie

GETOPENFILENAME is one of the biggest pieces of horsepoop that Micrsoft
has ever foisted on the development community. God help anybody trying
to do anything intelligent with it. Try a group with microsoft in the
name, but I have no hope you'll get it to work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,512
Latest member
FinleyNick

Latest Threads

Top