views:

394

answers:

4

How do I suppress a MessageBox from showing that comes from a reference to an assembly that I do not own (nor have the code for)?

For example, my application (MyApplication.exe) is referencing an assembly coded by someone else (SomeoneElsesAssembly.dll). Inside of this assembly I'm calling a static method, which does what it's supposes to, but also is firing a MessageBox that I want to suppress.

I thought there was a way to reference an assembly in Non-Interactive mode or something along these lines.

Thank you for your help.

-Jessy Houle

A: 

Basically you're asking if you can reference an assembly which calls MessageBox() and have the code not actually show a message box. The answer is unfortunately no.

You're best bet is to use screen scrapping to close the message box once it shows up. This post has some example code of how to close an InProc message box. http://www.codeproject.com/KB/dialog/AutoCloseMessageBox.aspx

JaredPar
And someone marked me down because ...
JaredPar
I put it back to 0. Sorry if that was me. I was going to make it as the answer, but marked a different one, as they had the very same code sample (in a link), but was in C#, instead of C++.Thank you again.
Jessy Houle
+2  A: 

What you are asking is basically "How can I modify the behavior of code in a third-party assembly".

Short of disassembling/reassembling, the answer is "You can't".

There are some icky options;

With managed code you always have the source in some form. If the function is somewhat self-contained you could use Reflector to copy it into your own code

You could have a 2nd thread that waits till the message box appears and then automatically closes it.

Andrew Grant
+1  A: 

I thought there was a way to reference an assembly in Non-Interactive mode or something along these lines.

I believe it's possible to run a process in a non-interactive mode (such as Windows Services, for example), but assemblies are loaded into the process and are subject to the same interaction levels as other assemblies in the process, afaik.

So, either disassemble-reassemble or send windows messages directly to the box to automatically close it.

Drew Noakes
+2  A: 

This article may be able to help

Ryan Emerle