Is it possible to disable C ++ confirmation from a .net application

I have the following problem: I use the C ++ library from my WPF application, the library throws approval in some very rare cases. It shows a nice dialog with the C ++ file name, line number and assert expression. So the question is: can I turn off the statements in the C ++ library, assuming I don’t have the source code. I really need to β€œcatch” this statement and register it.

Thanks.

+6
c ++ c #
source share
3 answers

One way is to create a thread that runs EnumWindows every so often and detects if a confirmation window appears, then it can capture the message and click the ignore button. This will still cause the window to appear for a short time (depending on your interval between EnumWindows , but I assume that you will not get the DLL for debugging, so it does not matter.


Another option is to call _CrtSetReportMode(_CRT_ASSERT, 0) to turn off confirmations from showing at all. If you want PInvoke this from .NET, note that _CRT_ASSERT is 2.

+3
source share

Depending on your assembler skills and whether deliberate steps have been taken to block this type of thing, you can usually change the binary code to prevent this kind of message from appearing.

However, dismissal with an allegation is often a precursor to a more impressive collapse or other misconduct, so simply stopping the message from spreading may not give you much more. Of course, some statements are wrong, so that may be all you need.

If I had to modify this DLL, I would parse it with the IDA and develop a patch. Hide this statement is likely to be quite easy, running it is much more difficult.

+1
source share

I recently had to fix some old code that relied on a DLL that sometimes exposed an assert message. I tried all of the above suggestions, and the only thing I got was to click the "Ignore" button. The user above suggested running EnumWindows in a separate thread - instead, I used FindWindow.

This is a function that finds the Assert pop-up message, finds the Ignore button there, and then clicks on it. It goes through a loop that checks a global variable each time (ugly but fast):

 void CloseAssertBox (void *param) { HWND window, button; Sleep (200); //wait 200 milliseconds while (!finishThread) { //see if we can stop checking if ((window = FindWindow (NULL, L"Microsoft Visual C++ Runtime Library")) && (button = FindWindowEx (window, NULL, L"Button", L"&Ignore"))) SendMessage (button, BM_CLICK, 0, 0); //click the button Sleep (50); //then check every 50 milliseconds } } 

Your Assert field name may vary. If your Ignore button is specified differently, you can use EnumChildWindows to get the name of each child control, including the buttons.

Before the bit of code that assert pops up, I start a new thread that calls the function above.

 finishThread = 0; //this is set to 1 when the thread should finish _beginthread (CloseAssertBox, 0, NULL); //begin the thread 

After going through a dangerous code in doubt, I installed:

 finishThread = 1; //done threaded stuff 

Thus, the thread will close the next time around its cycle. There are probably better ways to do this.

I had to enable these libraries in order for them to work:

 #include <process.h> //for multithreading #include <WinBase.h> //for Sleep function int finishThread; //to tell the thread when encoding has finished 

All this has been done in Visual Studio 2010 using the library since 2006.

0
source share

All Articles