Hi,
We are working on VC++ CLR (Windows Forms) application.
We are writing a code to generate Mini dump file (using MINIDUMPWRITEDUMP in dbghelp.dll) whenever application crashes.
The code available on internet for writing mini dump file in c# generates the mini dump but without Exception code and information, because _EXCEPTION_INFORMATION was set using Marshal::GetExceptionPointers() which returns 0. We called MINIDUMPWRITEDUMP inside AppDomain::UnhandledExceptionEventHandler for this.
To get the valid exception pointer for mini dump we made following attempts with and without AppDomain::UnhandledExceptionEventHandler –
- Used mixed (managed and unmanaged ) dll to add SetUnhandledExceptionFilter. Inside top level exception filter function added code to write mini dump. Inside main the handler is set on 1<sup>st</sup> line. But handler is not invoked on any exception. This works fine with console C# project.
// inside dll
#pragma unmanaged
LONG WINAPI ABCExceptionFilter(__in struct _EXCEPTION_POINTERS *pExceptionInfo)
{ // code to write dump
}
#pragma managed
Namespacee SEHHandler {
public ref class SEHExpHandler
{
public:
static void AddHandler()
{
SetUnhandledExceptionFilter(ABCExceptionFilter);
}
};
}
// inside app main()
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
SEHHandler::SEHExpHandler::AddHandler();
//some code . . .
Application::Run(gcnew Form1());
//some code . . .
}- Used __try __except inside application main. The exception filter was written in other C++ dll and called inside __except ( expression ) using platform Invoke. But this throws the caught exception while trying to call handler.
// inside app class
[DllImport("SEHhandler.dll")]
extern int __stdcall se_handler(unsigned int code, IntPtr ep);
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
__try
{ //some code. . .
}
__except(se_handler(GetExceptionCode(),
(IntPtr)GetExceptionInformation()))
{ //some code. . .
}
}
// inside dll
__declspec(dllexport)
extern int WINAPI se_handler(unsigned int code,
struct _EXCEPTION_POINTERS* ep)
{ // code to write minidump
return EXCEPTION_EXECUTE_HANDLER;
}Can anyone help us to get either of the code work. The aim is to write dump file with correct stack trace where exception was thrown.
Thanks in advance.
-- Sumit