Advertisement

Desperate help needed with GetOpenFileName()

Started by April 04, 2000 04:46 AM
5 comments, last by xstreme2000 24 years, 8 months ago
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
hi

As far as i know the function want''s something at the ofn.lpstrFile Pointer, so you should set it to something usefull, like "*.*" to show all files.

Lars
--------> http://www.larswolter.de <---------
Advertisement
If I put anything into the onf.lpstrFile the program crashes!

//--- Created by Tom Oram ---
// tom.oram@vodafone.net
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!!!!!!

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
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.
Advertisement
Thank you all for your help. I can''t try any of these at the moment but I will soon. Thanks again

This topic is closed to new replies.

Advertisement