AnnieB
2010-02-13 19:59:01 UTC
I know GetOpenFileName in not recommended in Windows 7, but it worked fine
until around the beginning of 2010. Even now, the problem is only showing up
on a very few machines (maybe only 64-bit machines). Did something relevant
change in Windows 7 at the beginning of the year? It still works fine on all
of my own Windows 7 machines and I can't find anything unique about the
setups of the machines it is happening on.
The problem: As soon as the user clicks a button that calls
GetOpenFileName, the program crashes. The file-opening dialog box does not
even appear. It seemed possible that the problem was the initial directory
setting, so I changed that from NULL (default) to the directory where the
user double-clicked a file to start up the program. I figured that was a
directory the user clearly had permission to access, and it was also a legit
existing directory. Unfortunately, GetOpenFileName still makes the program
crash.
I think my initialization of the OPENFILENAME structure is standard, but I'm
including it below, just in case I've missed some vital detail.
//code snippet (startingDirectory is determined before this)
char myLongFileName[MAX_PATH] = "";
char myFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = myLongFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "My test file\0*.zzz\0\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = myFileName;
ofn.nMaxFileTitle = MAX_PATH;
ofn.lpstrInitialDir = startingDirectory;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box (except this is where the crash is)
if (GetOpenFileName(&ofn))
{
//deal with the results (except it doesn't get this far)
}
TIA,
Ann
until around the beginning of 2010. Even now, the problem is only showing up
on a very few machines (maybe only 64-bit machines). Did something relevant
change in Windows 7 at the beginning of the year? It still works fine on all
of my own Windows 7 machines and I can't find anything unique about the
setups of the machines it is happening on.
The problem: As soon as the user clicks a button that calls
GetOpenFileName, the program crashes. The file-opening dialog box does not
even appear. It seemed possible that the problem was the initial directory
setting, so I changed that from NULL (default) to the directory where the
user double-clicked a file to start up the program. I figured that was a
directory the user clearly had permission to access, and it was also a legit
existing directory. Unfortunately, GetOpenFileName still makes the program
crash.
I think my initialization of the OPENFILENAME structure is standard, but I'm
including it below, just in case I've missed some vital detail.
//code snippet (startingDirectory is determined before this)
char myLongFileName[MAX_PATH] = "";
char myFileName[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = myLongFileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "My test file\0*.zzz\0\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = myFileName;
ofn.nMaxFileTitle = MAX_PATH;
ofn.lpstrInitialDir = startingDirectory;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
// Display the Open dialog box (except this is where the crash is)
if (GetOpenFileName(&ofn))
{
//deal with the results (except it doesn't get this far)
}
TIA,
Ann