[Interest] calling QMessageBox::warning() may break the DLL detaching on VS2010

Tony Rietwyk tony at rightsoft.com.au
Thu Nov 15 13:03:47 CET 2012

Hi Xulei, 


I've always considered DllMain to be only used for thread based
initialisations and finalisations.  IIRC, it's design is flawed - process
unload can occur without the individual thread unloads.  This made it
useless to disconnect thread specific database objects, for example.  


I'm amazed that window related calls like ::MessageBox are even allowed in
DllMain, I certainly wouldn't expect them to work!  


You're better off using standard debugging interfaces like qDebug() to track
things in DllMain.  






From: interest-bounces+tony=rightsoft.com.au at qt-project.org
[mailto:interest-bounces+tony=rightsoft.com.au at qt-project.org] On Behalf Of
Sent: Wednesday, 7 November 2012 1:58 PM
To: interest at qt-project.org
Subject: [Interest] calling QMessageBox::warning() may break the DLL
detaching on VS2010


Hi All,

I'm developing a project with Qt4.8.3 on Win7/VS2010. I found a critical
issue when calling QMessagebox::warning (actually, information(), critical()
have the same issue too, but question() not). To duplicate the issue
according the following steps:

1.       Create a "Qt Application" project (named QtTest) in VS2010 by Qt
Add-in with default settings.

2.       Add an action, and call QMessageBox::warning() in its slots.

3.       Create another DLL project (named MyDll) in VS2010, with a single
export function (named foo).

4.       Call the exported function "foo" in QtTest project.

5.       Call ::MessageBox of Windows API in "DllMain" of MyDll project to
show whether the DllMain with DLL_PROCESS_DETACH is called when program

6.       Start the QtTest.exe, then exit, the ::MessageBox in DllMain of
MyDll will be called.

7.       Start the QtTest.exe, then trigger the action create in step#2,
then exit, the MessageBox in DllMain of MyDll will not be called.


Note, the issue may not be duplicate on very PC, I had tested more than 10
PCs, and about half PCs could duplicate this issue.

As you know, when the DLL detach is not called, the other cleanup work won't
work too, such as destructors of local static objects and global objects
won't be called.

The URL is the source code I mentioned above.





-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20121115/d18396b0/attachment.html>

More information about the Interest mailing list