tags:

views:

27

answers:

1

hi,

I'm developing a COM dll which is an add-in to MSoffice. Since I'm not creating any logs within add-in I would like to add a crash report generator into my add-in.

Hopefully 'Minidump' would be the best choice, but I have never use Minidump inside a COM object.

I appreciate if somebody can point out possibilities of creating such crash dump with minidump inside a COM object.

Thank You

+1  A: 

I suspect you should be able to use the technique described here, create a minidump.

The actual implementation is straightforward. The following is a simple example of how to use MiniDumpWriteDump.

#include <dbghelp.h>
#include <shellapi.h>
#include <shlobj.h>

int GenerateDump(EXCEPTION_POINTERS* pExceptionPointers)
{
    BOOL bMiniDumpSuccessful;
    WCHAR szPath[MAX_PATH]; 
    WCHAR szFileName[MAX_PATH]; 
    WCHAR* szAppName = L"AppName";
    WCHAR* szVersion = L"v1.0";
    DWORD dwBufferSize = MAX_PATH;
    HANDLE hDumpFile;
    SYSTEMTIME stLocalTime;
    MINIDUMP_EXCEPTION_INFORMATION ExpParam;

    GetLocalTime( &stLocalTime );
    GetTempPath( dwBufferSize, szPath );

    StringCchPrintf( szFileName, MAX_PATH, L"%s%s", szPath, szAppName );
    CreateDirectory( szFileName, NULL );

    StringCchPrintf( szFileName, MAX_PATH, L"%s%s\\%s-%04d%02d%02d-%02d%02d%02d-%ld-%ld.dmp", 
               szPath, szAppName, szVersion, 
               stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay, 
               stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond, 
               GetCurrentProcessId(), GetCurrentThreadId());
    hDumpFile = CreateFile(szFileName, GENERIC_READ|GENERIC_WRITE, 
                FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);

    ExpParam.ThreadId = GetCurrentThreadId();
    ExpParam.ExceptionPointers = pExceptionPointers;
    ExpParam.ClientPointers = TRUE;

    bMiniDumpSuccessful = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), 
                    hDumpFile, MiniDumpWithDataSegs, &ExpParam, NULL, NULL);

    return EXCEPTION_EXECUTE_HANDLER;
}


void SomeFunction()
{
    __try
    {
        int *pBadPtr = NULL;
        *pBadPtr = 0;
    }
    __except(GenerateDump(GetExceptionInformation()))
    {
    }
}
Preet Sangha
Yes. The fact that you're using COM has nothing to do with creating minidumps.
jeffamaphone
My dll is loaded by Excel, and I tried the code given at http://www.codeproject.com/KB/debug/postmortemdebug_standalone1.aspxIt works fine with EXEs, but when a crash occurs inside COM object, Excel just pop its own crash recovery window, and given minidump code is not loaded
nimo
How is you com object written? IN C++? The above example required that you handle the error.
Preet Sangha
Yes It is c++, but I tried code given by my above comment. It requires global object to be initialized. My guess is that callback function is not registering properly inside the COM object. Please help
nimo
SetUnhandledExceptionFilter() is not recommend to use within DLLs. I think best way is to use __try/__except. Thank you preet
nimo