问题
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
回答1:
This article may be able to help
回答2:
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.
回答3:
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.
回答4:
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 scraping 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
来源:https://stackoverflow.com/questions/554373/suppress-messagebox-from-a-referenced-assembly