Discussion:
GetOpenFileName crash in Windows 7
(too old to reply)
AnnieB
2010-02-13 19:59:01 UTC
Permalink
Raw Message
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
Leslie Milburn
2010-02-14 02:03:15 UTC
Permalink
Raw Message
Post by AnnieB
I know GetOpenFileName in not recommended in Windows 7, but it worked fine
until around the beginning of 2010.
Can you provide a reference to that information because I find it hard to
believe as it will break a lot of existing applications.
Post by AnnieB
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.
A long time ago I had a problem which was traced back to the Adobe Acrobat
Reader being installed on the machine. What basically happened was that if I
did *not* use CoInitialize() or OLEInitiaize() the application crashed when
using OpenFileName. I was able to repeat the crash just by using Notepad.
Now this was back in the days of Reader Version 8 but my understanding is
that problem still exists.
Post by AnnieB
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
I cannot see anything obviousyl wrong with this but its been a while since I
looked at my code which does this. Some Win32 functions require the
lStructSize needs to be a predefined value rather than the real size, also
get rid of the filter stuff for now to see if you can get it to open.
Leslie
AnnieB
2010-02-17 16:47:01 UTC
Permalink
Raw Message
I haven't had any trouble with any of my code in Windows 7 except for this
oddity that's happened to only about 5 users (unlike Apple system changes
where code has to be rewritten over and over again with each new "advance").
My programs run faster in Windows 7 than they did in Vista, so I've loved
Windows 7 except for this.

Will check out the possible conflict with Adobe Reader or possibly with some
other program these few users may have installed. Thanks for the suggestion.
I'll have them try opening something with NotePad next, just to see if the
problem might be more widespread than just my program. I just wish I could
make it happen on my own computers. As it is, I have to try things and then
rely on generally flaky users to get back to me and tell me whether it helped
or not. (We've solved their immediate problems, so they tend to disappear
once we've done that.)

Thanks for the suggestions. You've given me more things to try . . .!

AnnieB
Post by Leslie Milburn
Post by AnnieB
I know GetOpenFileName in not recommended in Windows 7, but it worked fine
until around the beginning of 2010.
Can you provide a reference to that information because I find it hard to
believe as it will break a lot of existing applications.
Post by AnnieB
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.
A long time ago I had a problem which was traced back to the Adobe Acrobat
Reader being installed on the machine. What basically happened was that if I
did *not* use CoInitialize() or OLEInitiaize() the application crashed when
using OpenFileName. I was able to repeat the crash just by using Notepad.
Now this was back in the days of Reader Version 8 but my understanding is
that problem still exists.
Post by AnnieB
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
I cannot see anything obviousyl wrong with this but its been a while since I
looked at my code which does this. Some Win32 functions require the
lStructSize needs to be a predefined value rather than the real size, also
get rid of the filter stuff for now to see if you can get it to open.
Leslie
.
Mihai N.
2010-02-14 03:26:37 UTC
Permalink
Raw Message
Post by AnnieB
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).
Just tried your code on Win 7 64 bit, all updates installed, and works fine.
Do you have something more then "crashes"?
Stack info? Registers? Anything?
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
AnnieB
2010-02-17 16:36:01 UTC
Permalink
Raw Message
No, I don't have any more info. I wish I did. The students this is
happening to get the message saying the program has stopped working and
Windows will close the program and notify them if a solution is found. It
works fine on my 64-bit Windows 7 computer too. If I could duplicate the
error, I could probably figure out a way to fix it, but I thought maybe
someone else had run into something like this. It's only happened to about 5
users so far, but it's still worrisome. Thanks for trying to help!

AnnieB
Post by Mihai N.
Post by AnnieB
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).
Just tried your code on Win 7 64 bit, all updates installed, and works fine.
Do you have something more then "crashes"?
Stack info? Registers? Anything?
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
.
Devendra
2010-06-24 18:54:48 UTC
Permalink
Raw Message
Mihai,
For me getopenfilename api crashes when I click on the new folder push
button on the explorer style dialg that shows up. I am using Windows XP
professional.
Below is the code shippet. I would appreciate if you can point out the issue.

TCHAR szFile[MAX_PATH];
OPENFILENAME ofn;


ZeroMemory(&ofn, sizeof(ofn));

memset(szFile,0,MAX_PATH * sizeof(TCHAR));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = main_win ? main_win->m_hWnd : NULL;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile)/sizeof(szFile[0]);
ofn.lpstrFilter = TEXT("All Files (*.*)\0*.*\0");

ofn.Flags =
OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
GetOpenFileName(&ofn)

........
Devendra
Post by Mihai N.
Post by AnnieB
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).
Just tried your code on Win 7 64 bit, all updates installed, and works fine.
Do you have something more then "crashes"?
Stack info? Registers? Anything?
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
.
Mihai N.
2010-06-25 09:42:13 UTC
Permalink
Raw Message
Post by Devendra
Below is the code shippet. I would appreciate if you can point out the issue.
There is no issue with the code (except some style-related stuff that
don't have anything with the crash).
I took your code, compiled it and runs just fine one my Win7 6x bit.

Can you post any info about the crash?
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Dudley Benton
2011-01-17 19:57:03 UTC
Permalink
Raw Message
AnnieB, did you ever get a resolution to this problem? If so, what was it?
Post by AnnieB
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 cannot 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 am
including it below, just in case I have 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 does not get this far)
}
TIA,
Ann
Post by Leslie Milburn
Can you provide a reference to that information because I find it hard to
believe as it will break a lot of existing applications.
A long time ago I had a problem which was traced back to the Adobe Acrobat
Reader being installed on the machine. What basically happened was that if I
did *not* use CoInitialize() or OLEInitiaize() the application crashed when
using OpenFileName. I was able to repeat the crash just by using Notepad.
Now this was back in the days of Reader Version 8 but my understanding is
that problem still exists.
I cannot see anything obviousyl wrong with this but its been a while since I
looked at my code which does this. Some Win32 functions require the
lStructSize needs to be a predefined value rather than the real size, also
get rid of the filter stuff for now to see if you can get it to open.
Leslie
Post by Mihai N.
Just tried your code on Win 7 64 bit, all updates installed, and works fine.
Do you have something more then "crashes"?
Stack info? Registers? Anything?
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
No, I do not have any more info. I wish I did. The students this is
happening to get the message saying the program has stopped working and
Windows will close the program and notify them if a solution is found. It
works fine on my 64-bit Windows 7 computer too. If I could duplicate the
error, I could probably figure out a way to fix it, but I thought maybe
someone else had run into something like this. it is only happened to about 5
users so far, but it is still worrisome. Thanks for trying to help!
AnnieB
I have not had any trouble with any of my code in Windows 7 except for this
oddity that is happened to only about 5 users (unlike Apple system changes
where code has to be rewritten over and over again with each new "advance").
My programs run faster in Windows 7 than they did in Vista, so I have loved
Windows 7 except for this.
Will check out the possible conflict with Adobe Reader or possibly with some
other program these few users may have installed. Thanks for the suggestion.
I will have them try opening something with NotePad next, just to see if the
problem might be more widespread than just my program. I just wish I could
make it happen on my own computers. As it is, I have to try things and then
rely on generally flaky users to get back to me and tell me whether it helped
or not. (We've solved their immediate problems, so they tend to disappear
once we have done that.)
Thanks for the suggestions. You've given me more things to try . . .!
AnnieB
Post by Devendra
Mihai,
For me getopenfilename api crashes when I click on the new folder push
button on the explorer style dialg that shows up. I am using Windows XP
professional.
Below is the code shippet. I would appreciate if you can point out the issue.
TCHAR szFile[MAX_PATH];
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(ofn));
memset(szFile,0,MAX_PATH * sizeof(TCHAR));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = main_win ? main_win->m_hWnd : NULL;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile)/sizeof(szFile[0]);
ofn.lpstrFilter = TEXT("All Files (*.*)\0*.*\0");
ofn.Flags =
OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_EXPLORER;
GetOpenFileName(&ofn)
........
Devendra
Post by Mihai N.
There is no issue with the code (except some style-related stuff that
do not have anything with the crash).
I took your code, compiled it and runs just fine one my Win7 6x bit.
Can you post any info about the crash?
--
Mihai Nita [Microsoft MVP, Visual C++]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email
Submitted via EggHeadCafe
Creating Google Motion Charts from Excel data
http://www.eggheadcafe.com/tutorials/aspnet/86599bca-edda-4204-af15-7a1cf901a071/creating-google-motion-charts-from-excel-data.aspx
Loading...