jirentabu / crashrpt

Automatically exported from code.google.com/p/crashrpt
0 stars 0 forks source link

Using this in simple c# application. #128

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello Sir,
I want to use crash report with my simple c# application.
For that, I created a dll that has a function that can be called from c# code. 
That function registers the crash handlers.

It executed fine, without any error but did no catch the crash.

Here's my function. 
---------------------------------------------------------------------
extern "C" __declspec(dllexport) void LoadCrashHandlers()
{
    HRESULT hRes = ::CoInitialize(NULL);
    // If you are running on NT 4.0 or higher you can use the following call instead to 
    // make the EXE free threaded. This means that calls come in on a random RPC thread.
    //  HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ATLASSERT(SUCCEEDED(hRes));

    // Install crash reporting

    CR_INSTALL_INFO info;
    memset(&info, 0, sizeof(CR_INSTALL_INFO));
    info.cb = sizeof(CR_INSTALL_INFO);  
    info.pszAppName = _T("CrashRpt Tests"); // Define application name.
    //info.pszAppVersion = _T("1.2.7");     // Define application version.
    info.pszEmailSubject = _T("Error from CrashRptTests"); // Define subject for email.
    info.pszEmailTo = _T("test@hotmail.com");   // Define E-mail recipient address.  
    info.pszUrl = _T("http://localhost:80/crashrpt.php"); // URL for sending reports over HTTP.     
    info.pfnCrashCallback = CrashCallback; // Define crash callback function.   
    // Define delivery transport priorities. 
    info.uPriorities[CR_HTTP] = 3;         // Use HTTP the first.
    info.uPriorities[CR_SMTP] = 2;         // Use SMTP the second.
    info.uPriorities[CR_SMAPI] = 1;        // Use Simple MAPI the last.  
    info.dwFlags = 0;                    
    info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Install all available exception handlers.
    info.dwFlags |= CR_INST_HTTP_BINARY_ENCODING;   // Use binary encoding for HTTP uploads (recommended).  
    info.dwFlags |= CR_INST_APP_RESTART;            // Restart the application on crash.  
    //info.dwFlags |= CR_INST_NO_MINIDUMP;            // Do not include minidump.
    //info.dwFlags |= CR_INST_NO_GUI;               // Don't display GUI.
    //info.dwFlags |= CR_INST_DONT_SEND_REPORT;     // Don't send report immediately, just queue for later delivery.
    //info.dwFlags |= CR_INST_STORE_ZIP_ARCHIVES;   / Store ZIP archives along with uncompressed files (to be used with CR_INST_DONT_SEND_REPORT)
    info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS;    // Send reports that were failed to send recently.
    info.pszDebugHelpDLL = NULL;                    // Search for dbghelp.dll using default search sequence.
    info.uMiniDumpType = MiniDumpNormal;            // Define minidump size.
    // Define privacy policy URL.
    info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate");
    info.pszErrorReportSaveDir = NULL;       // Save error reports to the default location.
    info.pszRestartCmdLine = _T("/restart"); // Command line for automatic app restart.
    //info.pszLangFilePath = _T("D:\\");       // Specify custom dir or filename for language file.
    //info.pszSmtpProxy = _T("127.0.0.1:2525");  // Use SMTP proxy.
    CString sCustomSenderIcon = GetModulePath(NULL);
#ifdef _DEBUG
    //sCustomSenderIcon += _T("\\CrashRptTestd.exe, -203"); // Use custom icon
#else
    //sCustomSenderIcon += _T("\\CrashRptTest.exe, -203"); // Use custom icon
#endif
    //info.pszCustomSenderIcon = sCustomSenderIcon.GetBuffer(0);

    // Install crash handlers.
    CrAutoInstallHelper cr_install_helper(&info);
    if(cr_install_helper.m_nInstallStatus!=0)
    {
        TCHAR buff[256];
        crGetLastErrorMsg(buff, 256);
        MessageBox(NULL, buff, _T("crInstall error"), MB_OK);
        return;
    }
    ATLASSERT(cr_install_helper.m_nInstallStatus==0); 

    CString sLogFile = GetAppDir() + _T("\\dummy.log");
    CString sIniFile = GetAppDir() + _T("\\dummy.ini");

    int nResult = crAddFile2(sLogFile, NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY);
    ATLASSERT(nResult==0);

    nResult = crAddFile(sIniFile, _T("Dummy INI File"));
    ATLASSERT(nResult==0);

    nResult = crAddScreenshot2(CR_AS_PROCESS_WINDOWS|CR_AS_USE_JPEG_FORMAT, 10);
    //nResult = crAddScreenshot(CR_AS_MAIN_WINDOW);
    ATLASSERT(nResult==0);

    nResult = crAddProperty(_T("VideoCard"),_T("nVidia GeForce 9800"));
    ATLASSERT(nResult==0);

    nResult = crAddRegKey(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"), _T("regkey.xml"), 0);
    ATLASSERT(nResult==0);

    nResult = crAddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), _T("regkey.xml"), 0);
    ATLASSERT(nResult==0);
    return;
}
---------------------------------------------------------------------

It's called from c# via this code.

[DllImport("CrashHandlerRegistrar.dll", EntryPoint = "LoadCrashHandlers")]
extern public static void LoadCrashHandlers();

public Form1()
{
    InitializeComponent();
    LoadCrashHandlers();
}
Can you guide me on why it's not catching the crash.
Thanks a lot,
Mohan

Original issue reported on code.google.com by mohan848...@gmail.com on 11 Jan 2012 at 11:42

GoogleCodeExporter commented 9 years ago
I am using the latest version of CrashRpt.

Original comment by mohan848...@gmail.com on 11 Jan 2012 at 11:43

GoogleCodeExporter commented 9 years ago
In your code, I do not see the line causing crash. What type of exception are 
you trying to catch?

Original comment by zexspect...@gmail.com on 12 Jan 2012 at 3:32

GoogleCodeExporter commented 9 years ago
In your code, I do not see the line causing crash. What type of exception are 
you trying to catch?

Original comment by zexspect...@gmail.com on 12 Jan 2012 at 3:32

GoogleCodeExporter commented 9 years ago
In your code, I do not see the line causing crash. What type of exception are 
you trying to catch?

Original comment by zexspect...@gmail.com on 12 Jan 2012 at 3:32

GoogleCodeExporter commented 9 years ago
Closing this issue, because there is no feedback from the reporter.

Original comment by zexspect...@gmail.com on 20 Jan 2012 at 2:12