Reputation: 3433
Our application loads 3rd party DLLs that sometimes pops MessageBoxes. We've notices that sometimes we can't just use exit(0) when there's an open MessageBox.
How can we still force an exist in such a case?
Thanks
Upvotes: 0
Views: 186
Reputation: 12943
Seems like your ugly DLL calls MessageBox
(or whatever) from within DLL_THREAD_DETACH
or DLL_PROCESS_DETACH
.
If this happens in the same thread (i.e. the thread the calls exit
) you may try to call PostQuitMessage
right before the application exit. This should abort any message loop. If this happens in another thread - you may call PostThreadMessage
.
There's also an option to intercept calls to Win32 API functions by hooking the appropriate module (Exe/Dll) import table. Invented by J.Richter (if I remember correctly). http://www.player.idv.tw/prog/index.php/APIHook
Upvotes: 1
Reputation: 67118
If you want to use brute force you may call the TerminateProcess()
function. I'm not sure this is a good idea, you may want to detect if there's an open message box and send a close to it (for example using a FindWindow()
)
Take a look at MSDN.
Upvotes: 0