GetOpenFileName unhandled exception.
-
here's the code, when i get to the GetOpenFileName line it gives me an unhandled exception, i can't figure out what's wrong, here's the code:
void OnBrowse()
{
OPENFILENAME ofn;
char szFileName[MAX_PATH+1];
const char szFilter[] = "All Files (*.*)\0" "*.*\0";szFileName\[0\] = '\\0'; ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = ghWnd; ofn.lpstrFilter = szFilter; ofn.lpstrCustomFilter = (LPSTR)NULL; ofn.nFilterIndex = 1; ofn.lpstrFile = szFileName; ofn.nMaxFile = sizeof(szFileName); ofn.lpstrFileTitle = NULL; ofn.lpstrTitle = (LPSTR)NULL; ofn.Flags = OFN\_ENABLESIZING | OFN\_FILEMUSTEXIST | OFN\_HIDEREADONLY | OFN\_PATHMUSTEXIST | OFN\_EXPLORER; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = "txt"; if (GetOpenFileName(&ofn)) SetDlgItemText(ghWnd, IDC\_LIST, szFileName);
}
Thanks in advance. -Rune Svendsen
-
here's the code, when i get to the GetOpenFileName line it gives me an unhandled exception, i can't figure out what's wrong, here's the code:
void OnBrowse()
{
OPENFILENAME ofn;
char szFileName[MAX_PATH+1];
const char szFilter[] = "All Files (*.*)\0" "*.*\0";szFileName\[0\] = '\\0'; ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = ghWnd; ofn.lpstrFilter = szFilter; ofn.lpstrCustomFilter = (LPSTR)NULL; ofn.nFilterIndex = 1; ofn.lpstrFile = szFileName; ofn.nMaxFile = sizeof(szFileName); ofn.lpstrFileTitle = NULL; ofn.lpstrTitle = (LPSTR)NULL; ofn.Flags = OFN\_ENABLESIZING | OFN\_FILEMUSTEXIST | OFN\_HIDEREADONLY | OFN\_PATHMUSTEXIST | OFN\_EXPLORER; ofn.nFileOffset = 0; ofn.nFileExtension = 0; ofn.lpstrDefExt = "txt"; if (GetOpenFileName(&ofn)) SetDlgItemText(ghWnd, IDC\_LIST, szFileName);
}
Thanks in advance. -Rune Svendsen
A couple of points I can see from looking at the documentation for
GetOpenFileName()
.- What operating system are you using? There's a note in the platform SDK documentation that says: "lStructSize Specifies the length, in bytes, of the structure. Windows NT 4.0: In an application that is compiled with WINVER and _WIN32_WINNT >= 0x0500, use OPENFILENAME_SIZE_VERSION_400 for this member. Windows 2000/XP: Use sizeof (OPENFILENAME) for this parameter."
- This is more likely to be the problem - you've forgotten
lpstrInitialDir
. It should either be the directory you want the dialog to start in, or NULL.
Hope that helps!
"We are the knights who say Ni" (The Knights Who Say Ni)
-
A couple of points I can see from looking at the documentation for
GetOpenFileName()
.- What operating system are you using? There's a note in the platform SDK documentation that says: "lStructSize Specifies the length, in bytes, of the structure. Windows NT 4.0: In an application that is compiled with WINVER and _WIN32_WINNT >= 0x0500, use OPENFILENAME_SIZE_VERSION_400 for this member. Windows 2000/XP: Use sizeof (OPENFILENAME) for this parameter."
- This is more likely to be the problem - you've forgotten
lpstrInitialDir
. It should either be the directory you want the dialog to start in, or NULL.
Hope that helps!
"We are the knights who say Ni" (The Knights Who Say Ni)