(SHLWAPI.DLL): 0xC00000FD: Stack Overflow - mfc

I have an SDI application Vc++6.0. I am running this application from an MDI application using ShellExecute function. When the SDI application runs it opens one ODBC dialog and if the user clicks on HELP butto, the application terminates. I checked using SPY++ and got the following reason for application termination
(SHLWAPI.DLL): 0xC00000FD: Stack Overflow.
Why is this occurring?

You could try to trap stack overflow in your Visual C++ application to:
get past that first stack overflow
analyze when it occurs (does it happens several times after that first occurrence or not ?)
This exception can be trapped with the __try and __except keywords in Microsoft Visual C++
__try
{
StackOverflow(0);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
printf("Exception handler %lX\n", _exception_code());
Sleep(2000);
}
The rest of the article explains how to handle subsequent stack overflows without, for them, to raise access violation exceptions.

Related

Is there something like non-catchable exception in C++?

I would like to terminate application when error occurs, something similar to throwing an exception that cannot be caught.
When C++ exception is thrown and not catched, Visual Studio 2017 automatically opens the file where exception is thrown and points to the exact line of exception in a text editor, which is exactly what I want, except that I would also like to prevent exception from being caught.
I tried using abort(0) and std::terminate(), but then a message box is shown, instead of pointing to the line in text editor where application is terminated.
Simillary, exit(0) only displays message to debugger output which says that application has exited.
Is there a way to terminate application, but still make Visual Studio point to the line in text editor where application is terminated?

TestStack White doesn't detect an SEHException

I'm writing a few tests for a managed/unmanaged Winform application. Some of the bugs occur in the unmanaged part, and result in the process terminating due to an unhandled System.Runtime.InteropServices.SEHException exception .
When this exception occurs, Windows pops up a message box explaining the error.
Unfortunately, neither MS Test nor White recognize this. The test itself finishes successfully without any sign of error, even though I can see the message box pop up right before the test goes on and closes the application.
How can I detect this kind of exception?
The message box is the result of the default unhandled exception handling of a Winforms application.
I ended up looking for it after the test has finished. If the message box is there, I fail the test.

Is it possible to debug UnhandledExceptionFilters with a debugger?

In the Microsoft Windows API, you can use SetUnhandledExceptionFilter, to set a handler for unhandled exceptions. The big catch, mentioned on that page, is:
If an exception occurs in a process that is not being debugged, and
the exception makes it to the unhandled exception filter, that filter
will call the exception filter function specified by the
lpTopLevelExceptionFilter parameter.
(emphasis added)
Which basically means, if the process is getting debugged, the debugger gets the exception, and my filter is skipped!
I can test & debug my ExceptionFilter the old-fashioned way, with printfs and trial-n-error.
But am I missing something? Is there a good way to interactively debug an ExceptionFilter if it is disabled when in a debugger?
Checkout the Resolution section of KB173652 which talks about placing all the code in main/WinMain in a _try/_except block like the following.
void main (int argc, char **argv)
{
__try
{
// all of code normally inside of main or WinMain here...
}
__except (MyUnFilter (GetExceptionInformation()))
{
OutputDebugString ("executed filter function\n");
}
}
Another article, Debugging custom filters for unhandled exceptions, describes a couple more techniques in addition to the one above. I personally use the one where you display a message box inside your exception filter and then attach the debugger. I use IsDebuggerPresent to determine whether to display the message box or not.
I know this post has been around for a while, but, I just happened upon it searching for something else. I’m happy to say that what user ‘abelenky’ asks is possible if the filter exists in a separate dll. You can debug an unhandled exception filter using a debugger. I’ve done it, and, here’s how:
The exception filter must exist in a separate dll. You’ll see why later.
You’ll need to add some code to the filter that displays a message box. I use the following code:
#ifdef _DEBUG
AfxMessageBox (_T("At this time, you must attach the debugger to this process in order to debug the filter code."));
#endif
The #ifdef is important because you don’t want the code executing in a Release build. I placed the above code at the very top of my filter.
To debug the filter:
Build a Release version of your application in Visual Studio
(instance #1).
Build a Debug version of your filter in a second instance of VS (#2).
Copy the Debug version of the filter to the Release folder of your
application.
Start your Release application from the Debug menu “without
debugging”.
Cause a crash in your application.
When the debug message box (above) appears, change to the second instance (#2) of Visual Studio.
In the #2 instance, open the filter project in Debug (if it isn't open) and attach the
debugger to your Application instance.
Set a breakpoint in your filter code after the message box displays.
Close the message box and your breakpoint should be hit.
Continue to debug your code.

CFileDialog delayed crashing

I have added an "Open file" dialog to my dialog-based MFC application. Now, exactly one minute(!) after an open file dialog is closed by pushing either Open or Cancel button my application crashes. While it crashes, the following things are happening in the output:
1) a bunch of Windows threads are exiting;
2) a bunch of COM exceptions (of 0x80010108 "the object invoked has disconnected from its clients" and 0x800401FD "Object is not connected to server" variety) are being thrown;
3) finally, an unhandled exception occurs: 0xC0000005: Access violation reading location 0xfeeefeee, with call stack pointing to ole32.dll.
To say that I am bewildered is quite an understatement. The code for invoking the dialog is as follows:
CFileDialog fileDlg( TRUE, _T(".txt"), NULL, OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
_T("Text file (*.txt)|*.txt||"), this);
INT_PTR res = fileDlg.DoModal();
What could cause such a thing?
How do I even debug it?
I had this exact issue in Windows 7 x64, and by enabling breakpoints on all Win32 exceptions not already chosen (in the VS2015 exceptions tab), I was able to narrow it down to a known issue with fundisc.dll that was resolved with an optional Hotfix from Microsoft: https://support.microsoft.com/en-us/kb/2494427
It also resolved issues on my PC of File Explorer windows crashing at seemingly random times. All were caused by some deadlock in the networking COM objects that is fixed by that hotfix.

What happens to an ActiveX control (COleControl) after the call to OnDestroy()?

I have an ActiveX control written in C++ that runs in Internet Explorer 8. Most of the time (approx 90%) when the tab or browser containing the control is closed, there is an access violation like this:
The thread 'Win32 Thread' (0x1bf0) has exited with code 0 (0x0).
Unhandled exception at 0x77b3b9fd in iexplore.exe: 0xC0000005: Access violation reading location 0x65007408.
The access violation occurs after the call to OnDestroy() but before the call to the control's destructor.
The debug output says:
No symbols are loaded for any call stack frame. The source code cannot be displayed.
None of my code is present in the stacktrace, although perhaps the heap was corrupted at some earlier point during execution.
What lifecycle events does an ActiveX control receive between the call to OnDestroy() and the control's destructor?
As I understand, there is no strictly event lifecycle for an ActiveX, it depends on host side. If your control is used with some AJAX framework, for example, after OnDestroy() can be called OnCreate() without calling destructor. So, make sure you don’t have uninitialize actions inside OnDestroy() handler.
You can load control in ActiveX Control Test Container and play with Activate/Deactivate, maybe it will be helpful.
Enable Application Verifier from debugging tools for windows and make sure your debugger downloads OS debug symbols. In this case stack trace will be more informative.