• Advertisement

Archived

This topic is now archived and is closed to further replies.

GetOpenFileName() givin me one hell of a time

This topic is 5091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You know, those things you see every tiem you go to save or open a file? They're so "standard issue" i cant help but assume theres some pre-made class or function that takes care of that, am i wrong? if not, whats it called? -Dan Yes I realize im a n00b... [edited by - Ademan555 on February 7, 2004 9:06:16 PM] [edited by - Ademan555 on February 8, 2004 4:31:01 AM]

Share this post


Link to post
Share on other sites
Advertisement
They''re part of the common dialog box library. You can access them with the GetOpenFileName() or GetSaveFileName() Win32 functions.

Share this post


Link to post
Share on other sites
I used the function GetOpenFileName() and absolutely nothing happened... i have WIN32_LEAN_AND_MEAN defined, though it still didnt show without it defined, and i have windows.h included, along with commdlg.h any clue whats wrong?

Share this post


Link to post
Share on other sites
I''m unclear here. Did you program even actually compile and link? Assuming that it did, what does CommDlgExtendedError() say?

Share this post


Link to post
Share on other sites
Didnt check for an error, ill do that... it does compile, and it does link, i can run the program just fine, but it doesnt show up...

Share this post


Link to post
Share on other sites
CommDlgExtendedError() returned a value of 0x00000001 now... i looked into it, and apparently... a value of 0x0001 is CDERR_STRUCTSIZE ... should i assume thats the error? (well im gonna look into that anyways)

edit: fixed, thanks a lot, apparently i should have looked into the OPENFILENAME struct more, you need to give it the sizeof(OPENFILENAME) in the lStructSize member.... (for anyone else who has the same problem)

[edited by - Ademan555 on February 7, 2004 10:47:05 PM]

Share this post


Link to post
Share on other sites
When calling Windows functions, ALWAYS do these two things:

1) ALWAYS memset the entire struct to 0.
2) If the struct has a size field, set it to sizeof(the struct).

Share this post


Link to post
Share on other sites
I ALWAYS ZeroMemory() :-D (which calls memset lol) but yeah, actually never saw the size field

Share this post


Link to post
Share on other sites
So i set the size member to sizeof(OPENFILENAME), and i set the nMaxFile to MAX_PATH what now? the function doesnt return an error ive checked... and yet.... the lpstrFile (which should be the file path) is NULL... what gives?

OPENFILENAME Path;

ZeroMemory(&Path, sizeof(OPENFILENAME));
Path.lStructSize = sizeof(OPENFILENAME);
Path.nMaxFile = MAX_PATH;

GetOpenFileName(&Path);

and when i check...

Path.lpstrFile .... its null....

any ideas?

Share this post


Link to post
Share on other sites
You need to assign allocate storage and assign lpstrFile yourself, before you call GetOpenFileName(). Plus you aren''t initializing the owning hwnd.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Have a similar problem with commdlg: GetOpenFileName.
I''m relativly sure, that the struct ist correct initialized, because it''s an example from MS. But the dialog does''nt open.
Extended Error Info is 2. Maybe i forgot something (or MS).

ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER;

GetOpenFileName(&ofn);

Thanks
christian

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Found something...
The string ofn.lpstrFile must have enough space (allocate)
AND !!!!!
the first char must be \0

Share this post


Link to post
Share on other sites

  • Advertisement