I have the following problem: I use c++ library from my WPF app, the library throws an assertion in some very rare cases. It shows a nice dialog with c++ filename, the line number and assert expression. So the question is: can I disable asserts in the c++ library assuming that I don't have source code. What I really need is to "catch" this assertion and log it.
Thanks.
One way is to create a thread that performs EnumWindows
every so often and detects if an assert window pops up, it can then capture the message and click the ignore button. This will still cause the window to show up for a short while (depending on your interval between EnumWindows
but I assume you customers aren't going to be getting the debug DLL so it shouldn't matter.
Another option is calling _CrtSetReportMode(_CRT_ASSERT, 0)
to disable asserts from being shown altogether.
If you want to PInvoke this from .NET note that _CRT_ASSERT
is equal to 2.
Depending on your assembler skills and whether steps have been taken deliberately to block this type of stuff, it's usually possible to modify binary code to prevent this sort of message being displayed.
However, an assertion firing is often a precursor to some more spectacular crash or other misbehaviour, so just stopping the message box might not get you much further. Of course, some assertions are buggy, so this might be all you need.
If I had to modify this DLL, I would disassemble it with IDA and work out a patch. Hiding the assertion would probably be fairly easy, logging it quite a lot harder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With