I have an MFC application (using a legacy library that I can’t change). When the application starts, it loads a couple of drivers and shows message boxes if some drivers couldn’t be loaded. The loading of the drivers and the showing of the message boxes is done by a method inside the library that can’t be changed (let’s call this method Init). I would like to disable those message boxes (preventing them from “popping”). Is there something I could call before calling Init to disable Message Boxes temporarily and then re-enable them after?
(Note that if it is impossible to re-enable them after, I can very well live with that, I mostly want to disable them)
Thanks to all,
Note: If someone wonders about why I would like to do that, it is because my application exposes a COM interface and will be used by other applications. The only reason it is an application is that the library I use is much more easy to use when creating an MFC application (and not a dll). When it is called by my other applications, I don’t want the message boxes to show, I just want to get the errors if something goes wrong.
I am not sure whether this could work. I use it for subclassing some messageboxes not to preven them to popup and they are not from a dll.
I set a hook to capture message boxes before poping up:
The new hook procedure (CbtHookProc) would be like this:
From microsoft documentation for HCBT_CREATEWND:
Then after calling Init you can remove the hook and message boxes will pop up again:
As I told you I can’t assure it works but give it a try.