Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem with GetOpenFileName() on Win XP SP2

83 views
Skip to first unread message

Clayton Arends

unread,
Oct 19, 2006, 2:10:49 PM10/19/06
to
Hello. I would like to discuss a problem that some colleagues and I have
recently discovered. We worked out the details over the past week and a
half in our compiler's newsgroups. At first we believed the problem to be
with our compiler but after some sleuthing we believe it to be a problem
with Windows XP SP2. I do not frequent this newsgroup so please forgive me
if this is not the appropriate place to post this topic. If you do know of
a better location then please respond and point me in the correct direction.

The issue we have uncovered is with the use of the Win32 API functions
GetOpenFileName() and GetSaveFileName(). The problem happens when browsing
for a file on the Desktop. The first time the dialog is executed the
application behaves as expected. The second time time the dialog is
executed the application will unexpectedly close when the "hint" window pops
up after hovering the mouse over a file.

Before jumping into code I should mention that we can duplicate our findings
by using "Notepad". The steps to reproduce are:

- Launch notepad
- Choose "File | Open" from the menu
- Click the "Desktop" icon to the left
- Open a text file
- Choose "File | Open" from the menu
- Hover the mouse over the file previously opened until the hint window
appears. If the hint window displays normally move the mouse to another
file. If notepad closes without warning or error dialog then you will have
witnessed the error.

I can usually duplicate the above findings the first time through on
multiple computers. Some people have mentioned that it takes a few cycles
of opening files before the problem can be duplicated. Some other people
have been unsuccessful in duplicating the problem at all. This could be due
to a slight configuration difference or they might not understand how to
duplicate the problem.

I created the following code which demonstrates the behavior. I have tested
it in my vendor's compiler and in VS.NET using a "Win32 Console Project".

#include <windows.h>

// This code goes in the main entry function, main(), WinMain(),
// or other similar function
while (1)
{
char filter[] = "All files\0*.*\0";
char filename[MAX_PATH + 2] = {0};
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
if (GetOpenFileName(&ofn) == 0)
break;
}

Once the program is running the steps to duplicate are similar to those used
for Notepad. Simply open a file. When the dialog appears again hover the
mouse over a file to cause a hint window to appear. When I run the above
code in my compiler's IDE and cause the error condition the debugger informs
me that the code has stopped in shell32.dll.

Before concluding this post I would like to mention some other tests that we
have done. I have tested this code on Windows 2003 Server and Windows 2000
SP4 and the problem does not occur. I cannot find an XP or XP SP1 machine
to test against. We also tested similar steps using Wordpad without causing
the error to happen. I created a test C#.NET Windows Form project and used
the "File Open Dialog" component. This, too, does not fail.

Does anyone here have any insight into this problem? I searched the
knowledge base and did not find a similar report. I searched the newsgroup
archives using Google and found a few similar references but nothing
conclusive.

Thank you for your time,

- Clayton


ne...@rtrussell.co.uk

unread,
Oct 19, 2006, 5:07:05 PM10/19/06
to
Clayton Arends wrote:
> Before jumping into code I should mention that we can duplicate our findings
> by using "Notepad". The steps to reproduce are:

I can reproduce it using the steps you described.

I would suggest you report it on microsoft.public.win32.programmer.ui
if you haven't already, since that group is more likely to be monitored
by Microsoft people. I also understand that (if you are in the US) you
can report Windows bugs at http://support.microsoft.com/gp/contactbug/

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.

[jongware]

unread,
Oct 19, 2006, 6:36:43 PM10/19/06
to
"Clayton Arends" <nospam_cla...@hotmail.com> wrote in message
news:qcPZg.21$iA...@newsfe05.lga...
[...]

> The issue we have uncovered is with the use of the Win32 API functions
> GetOpenFileName() and GetSaveFileName(). The problem happens when
browsing
> for a file on the Desktop. The first time the dialog is executed the
> application behaves as expected. The second time time the dialog is
> executed the application will unexpectedly close when the "hint" window
pops
> up after hovering the mouse over a file.
>
> Before jumping into code I should mention that we can duplicate our
findings
> by using "Notepad". The steps to reproduce are:
>
> - Launch notepad
> - Choose "File | Open" from the menu
> - Click the "Desktop" icon to the left
> - Open a text file
> - Choose "File | Open" from the menu
> - Hover the mouse over the file previously opened until the hint window
> appears. If the hint window displays normally move the mouse to another
> file. If notepad closes without warning or error dialog then you will
have
> witnessed the error.

[...]


> Does anyone here have any insight into this problem? I searched the
> knowledge base and did not find a similar report. I searched the
newsgroup
> archives using Google and found a few similar references but nothing
> conclusive.

That rings a bell. I've heard that before;
http://groups.google.nl/group/microsoft.public.win32.programmer.ui/browse_frm/thread/5fd5638c2125150b/64cb85f1bc823060?lnk=st&q=getopenfilename+crash+notepad&rnum=2&hl=nl#64cb85f1bc823060
and a few other links suggest Acrobat Reader is the culprit -- not on my
machine, tho'.
http://groups.google.nl/group/comp.os.ms-windows.programmer.misc/browse_frm/thread/4fa3efaa0a63b954/fb15ae101411d102?lnk=st&q=getopenfilename+crash+notepad&rnum=6&hl=nl#fb15ae101411d102
proposes a solution which worked for the OP.

[Jongware]


Jim Langston

unread,
Oct 19, 2006, 7:17:23 PM10/19/06
to
"Clayton Arends" <nospam_cla...@hotmail.com> wrote in message
news:qcPZg.21$iA...@newsfe05.lga...
> Before jumping into code I should mention that we can duplicate our
> findings by using "Notepad". The steps to reproduce are:
>
> - Launch notepad
> - Choose "File | Open" from the menu
> - Click the "Desktop" icon to the left
> - Open a text file
> - Choose "File | Open" from the menu
> - Hover the mouse over the file previously opened until the hint window
> appears. If the hint window displays normally move the mouse to another
> file. If notepad closes without warning or error dialog then you will
> have witnessed the error.

Just confirming I also get this error, notepad CTD.


Tove Momerathsson

unread,
Oct 19, 2006, 9:59:51 PM10/19/06
to
Clayton Arends wrote:
>
> Hello. I would like to discuss a problem that some colleagues and I have
> recently discovered. We worked out the details over the past week and a
> half in our compiler's newsgroups. At first we believed the problem to be
> with our compiler but after some sleuthing we believe it to be a problem
> with Windows XP SP2. I do not frequent this newsgroup so please forgive me
> if this is not the appropriate place to post this topic. If you do know of
> a better location then please respond and point me in the correct direction.
>
> The issue we have uncovered is with the use of the Win32 API functions
> GetOpenFileName() and GetSaveFileName(). The problem happens when browsing
> for a file on the Desktop. The first time the dialog is executed the
> application behaves as expected. The second time time the dialog is
> executed the application will unexpectedly close when the "hint" window pops
> up after hovering the mouse over a file.
>
[snip]

>
> I can usually duplicate the above findings the first time through on
> multiple computers. Some people have mentioned that it takes a few cycles
> of opening files before the problem can be duplicated. Some other people
> have been unsuccessful in duplicating the problem at all. This could be due
> to a slight configuration difference or they might not understand how to
> duplicate the problem.

I ran into what might be the same problem last year, and the culprit was
the combination of Adobe Acrobat Reader 7.0 and Win XP SP2. The absence
of Reader 7.0 could account for the replication failures.

I found the post below via Google and the fix cited there worked for me.

Tove

>> Newsgroups: microsoft.public.win32.programmer.ui
>> From: "Leslie Milburn" <C...@NOSPAM.bigpond.com>
>> Date: Thu, 2 Jun 2005 23:49:41 +1000
>> Subject: This problem is caused Adobe Acrobat 7 Reader Installation
>>
>> My thanks to everyone who has helped out in this thread. Your efforts have
>> proved invaluable in resolving this problem with GetOpenFileName() and
>> GetSaveFileName(). Actually it makes you wonder what else.
>>
>> I have now been able to reproduce the crash effect simply by installing
>> Adobe Acrobat Reader Version 7.0 (not version 6) on my Windows XP SP2
>> machine.
>>
>> This crash only happens to me when the Open File Dialog is in the Desktop
>> Folder. It appears that the crash will occur after a number of Tooltips has
>> been displayed. FYI: You do not even need to have any PDF's on the desktop -
>> its the mere installation of Reader that is the problem.
>>
>> This problem may indeed be caused by some sort of hook as James Brown
>> suggested a few days ago. Or it could be that Adobe is installing a DLL
>> which is incompatible with XP SP2 (the old DLL Hell) - I simply am too tired
>> to go into this level of detail. If anyone else ever follows up on this bit
>> I would be interested to know the outcome.
>>
>> The solution is to call either CoInitialize() or OleInitialize() and of
>> course the uninit functions at the end.

Clayton Arends

unread,
Oct 20, 2006, 4:56:24 PM10/20/06
to
Thank you for confirming. From reading the other posts apparently a lot of
people have Acrobat/Acroboat Reader. ;-)

> I would suggest you report it on microsoft.public.win32.programmer.ui

I posted first to microsoft.public.win32.programmer before posting here. I
waited four days for a response before posting here. Perhaps I should have
posted to the "ui" subgroup, eh? Though given the other responses and the
Google hits I think I'll consider this a problem caused by Adobe.

- Clayton


Clayton Arends

unread,
Oct 20, 2006, 5:00:53 PM10/20/06
to
Thanks to all who responded. I can confirm that the OleInitialize() ...
OleUninitialize() pair mends the problem in my application. I'll need to do
some more testing to confirm that it completely eliminates the issue. I am
optimistic, however.

- Clayton


Leslie Milburn

unread,
Oct 28, 2006, 8:48:30 AM10/28/06
to
Hi Clayton,

I have been waiting for someone else to be burnt by this problem ;-)

I can confirm that for well over a year now I have not had this problem in
over 200 different locations. I reported it to Adobe but the arrogant
ba*tards never responded. I have never bother to retest with 7.08 of Reader
or what ever the latest version is. From memory I think it is unrelated to
the service pack level of XP - its purely an Adobe issue.

Leslie.

"Clayton Arends" <nospam_cla...@hotmail.com> wrote in message

news:UNa_g.1194$6d1...@newsfe02.lga...

Grzegorz Wróbel

unread,
Oct 28, 2006, 10:24:44 AM10/28/06
to
Clayton Arends wrote:
> Hello. I would like to discuss a problem that some colleagues and I have
> recently discovered. We worked out the details over the past week and a
> half in our compiler's newsgroups. At first we believed the problem to be
> with our compiler but after some sleuthing we believe it to be a problem
> with Windows XP SP2. I do not frequent this newsgroup so please forgive me
> if this is not the appropriate place to post this topic. If you do know of
> a better location then please respond and point me in the correct direction.
>
> The issue we have uncovered is with the use of the Win32 API functions
> GetOpenFileName() and GetSaveFileName(). The problem happens when browsing
> for a file on the Desktop. The first time the dialog is executed the
> application behaves as expected. The second time time the dialog is
> executed the application will unexpectedly close when the "hint" window pops
> up after hovering the mouse over a file.

It's an access violation within Shell32.dll (unhandled exception 0xC0000005), most likely accessing NULL pointer or something like that.

> #include <windows.h>
>
> // This code goes in the main entry function, main(), WinMain(),
> // or other similar function
> while (1)
> {
> char filter[] = "All files\0*.*\0";
> char filename[MAX_PATH + 2] = {0};
> OPENFILENAME ofn;
> memset(&ofn, 0, sizeof(ofn));
> ofn.lStructSize = sizeof(ofn);
> ofn.lpstrFilter = filter;
> ofn.nFilterIndex = 1;
> ofn.lpstrFile = filename;
> ofn.nMaxFile = MAX_PATH;
> if (GetOpenFileName(&ofn) == 0)
> break;
> }

You may try adding: ofn.lpstrInitialDir="C:\\"; or something just to get a crash instead of silent close.

--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D

0 new messages