GetOpenFileName() givin me one hell of a time

Started by
12 comments, last by Ademan555 20 years, 1 month ago
You need to assign allocate storage and assign lpstrFile yourself, before you call GetOpenFileName(). Plus you aren''t initializing the owning hwnd.
Advertisement
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
Anon, did you ever allocate space for lpstrFile? Or I guess szFile?
Found something...
The string ofn.lpstrFile must have enough space (allocate)
AND !!!!!
the first char must be \0

This topic is closed to new replies.

Advertisement