Archived

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

xstreme2000

Desperate help needed with GetOpenFileName()

Recommended Posts

I am calling a GetOpenFileName(&ofn); It all runs perfectly...returns TRUE and the CommDlgExtendedError returns 0 but the ofn.lpstrFile == ""; Why? Maybe I missed something out in the ofn??? Here is the ofn properties: ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWndO; ofn.hInstance = NULL; ofn.lpstrFilter = "Level Files(*.lvl)\0*.LVL\0All Files(*.*)\0*.*\0"; ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; ofn.nFilterIndex = 1; ofn.lpstrFile = NULL; ofn.nMaxFile = 1024; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = NULL; ofn.lpstrInitialDir = ""; ofn.Flags = OFN_FILEMUSTEXIST / OFN_HIDEREADONLY / OFN_LONGNAMES / OFN_CREATEPROMPT / OFN_EXTENSIONDIFFERENT / OFN_OVERWRITEPROMPT; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = ".LVL"; ofn.lpfnHook = NULL; ofn.lpTemplateName = NULL; ofn.lpstrTitle = NULL; //--- Created by Tom Oram --- // tom.oram@vodafone.net

Share this post


Link to post
Share on other sites
I don''t believe this is true. The lpstrFile member must have a pointer to where your selected file is going to be written. You can''t pass NULL there. And remember to fill it with zeros or else you may get some irritating filename when your opening the dialog window.
I hope that should do fine. Happy programming!!!!!!

Share this post


Link to post
Share on other sites

Here's what I use most of the time:


//Clear out the name and ofn
char fileName[500];
ZeroMemory(fileName, 500);
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(OPENFILENAME));

//...usual stuff
ofn.lpstrFile = fileName;
ofn.nMaxFile = 500;
//...




Now after the call to GetOpenFileName(&ofn), ofn.lpstrFile has the name of the file.


Andrew


Edited by - acraig on 4/4/00 6:33:12 AM

Share this post


Link to post
Share on other sites
yeah, you need to pass an allocated string to GetOpenFileName.
but i would be interested if you get it to work, because i am using this function and it always creates (non-critical) access violations according to the debugger. nothing crashes, but nevertheless it''s nasty.

Share this post


Link to post
Share on other sites