GME  13
CrashRpt.h
Go to the documentation of this file.
00001 /************************************************************************************* 
00002   This file is a part of CrashRpt library.
00003 
00004   Copyright (c) 2003, Michael Carruth
00005   All rights reserved.
00006  
00007   Redistribution and use in source and binary forms, with or without modification, 
00008   are permitted provided that the following conditions are met:
00009  
00010    * Redistributions of source code must retain the above copyright notice, this 
00011      list of conditions and the following disclaimer.
00012  
00013    * Redistributions in binary form must reproduce the above copyright notice, 
00014      this list of conditions and the following disclaimer in the documentation 
00015      and/or other materials provided with the distribution.
00016  
00017    * Neither the name of the author nor the names of its contributors 
00018      may be used to endorse or promote products derived from this software without 
00019      specific prior written permission.
00020  
00021 
00022   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
00023   EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
00024   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00025   SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
00026   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 
00027   TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 
00028   BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00029   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
00030   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 ***************************************************************************************/
00032 
00040 #ifndef _CRASHRPT_H_
00041 #define _CRASHRPT_H_
00042 
00043 #include <windows.h>
00044 #include <dbghelp.h>
00045 
00046 // Define SAL macros to be empty if some old Visual Studio used
00047 #ifndef __reserved
00048   #define __reserved
00049 #endif
00050 #ifndef __in
00051   #define __in
00052 #endif
00053 #ifndef __in_opt
00054   #define __in_opt
00055 #endif
00056 #ifndef __out_ecount_z
00057   #define __out_ecount_z(x)
00058 #endif
00059 
00060 #ifdef __cplusplus
00061 #define CRASHRPT_EXTERNC extern "C"
00062 #else
00063 #define CRASHRPT_EXTERNC
00064 #endif
00065 
00066 #define CRASHRPTAPI(rettype) CRASHRPT_EXTERNC rettype WINAPI
00067 
00069 #define CRASHRPT_VER 1210
00070 
00109 typedef BOOL (CALLBACK *LPGETLOGFILE) (__reserved LPVOID lpvState);
00110 
00111 #ifndef _CRASHRPT_REMOVE_DEPRECATED
00112 
00151 CRASHRPTAPI(LPVOID)
00152 InstallW(
00153    __in_opt LPGETLOGFILE pfnCallback,
00154    LPCWSTR pszEmailTo,    
00155    LPCWSTR pszEmailSubject
00156    );
00157 
00162 CRASHRPTAPI(LPVOID)
00163 InstallA(
00164    __in_opt LPGETLOGFILE pfnCallback,
00165    LPCSTR pszEmailTo,    
00166    LPCSTR pszEmailSubject
00167    );
00168 
00172 #ifdef UNICODE
00173 #define Install InstallW 
00174 #else
00175 #define Install InstallA
00176 #endif //UNICODE
00177 
00178 
00196 CRASHRPTAPI(void)
00197 Uninstall(
00198    __reserved LPVOID lpState                            
00199    );
00200 
00229 CRASHRPTAPI(void)
00230 AddFileW(
00231    __reserved LPVOID lpState,                         
00232    LPCWSTR pszFile,                         
00233    LPCWSTR pszDesc                          
00234    );
00235 
00241 CRASHRPTAPI(void)
00242 AddFileA(
00243    __reserved LPVOID lpState,                         
00244    LPCSTR pszFile,                         
00245    LPCSTR pszDesc                          
00246    );
00247 
00251 #ifdef UNICODE
00252 #define AddFile AddFileW
00253 #else
00254 #define AddFile AddFileA
00255 #endif //UNICODE
00256 
00257 
00258 
00285 CRASHRPTAPI(void)
00286 GenerateErrorReport(
00287    __reserved LPVOID lpState,
00288    PEXCEPTION_POINTERS pExInfo
00289    );
00290 
00291 #endif //_CRASHRPT_REMOVE_DEPRECATED
00292 
00293 // Array indices for CR_INSTALL_INFO::uPriorities.
00294 #define CR_HTTP 0  //!< Send error report via HTTP (or HTTPS) connection.
00295 #define CR_SMTP 1  //!< Send error report via SMTP connection.
00296 #define CR_SMAPI 2 //!< Send error report via simple MAPI (using default mail client).
00297 
00299 #define CR_NEGATIVE_PRIORITY ((UINT)-1)
00300 
00301 // Flags for CR_INSTALL_INFO::dwFlags
00302 #define CR_INST_STRUCTURED_EXCEPTION_HANDLER   0x1    //!< Install SEH handler (deprecated name, use \ref CR_INST_SEH_EXCEPTION_HANDLER instead).
00303 #define CR_INST_SEH_EXCEPTION_HANDLER          0x1    //!< Install SEH handler.
00304 #define CR_INST_TERMINATE_HANDLER              0x2    //!< Install terminate handler.
00305 #define CR_INST_UNEXPECTED_HANDLER             0x4    //!< Install unexpected handler.
00306 #define CR_INST_PURE_CALL_HANDLER              0x8    //!< Install pure call handler (VS .NET and later).
00307 #define CR_INST_NEW_OPERATOR_ERROR_HANDLER     0x10   //!< Install new operator error handler (VS .NET and later).
00308 #define CR_INST_SECURITY_ERROR_HANDLER         0x20   //!< Install security error handler (VS .NET and later).
00309 #define CR_INST_INVALID_PARAMETER_HANDLER      0x40   //!< Install invalid parameter handler (VS 2005 and later).
00310 #define CR_INST_SIGABRT_HANDLER                0x80   //!< Install SIGABRT signal handler.
00311 #define CR_INST_SIGFPE_HANDLER                 0x100  //!< Install SIGFPE signal handler.   
00312 #define CR_INST_SIGILL_HANDLER                 0x200  //!< Install SIGILL signal handler.  
00313 #define CR_INST_SIGINT_HANDLER                 0x400  //!< Install SIGINT signal handler.  
00314 #define CR_INST_SIGSEGV_HANDLER                0x800  //!< Install SIGSEGV signal handler.
00315 #define CR_INST_SIGTERM_HANDLER                0x1000 //!< Install SIGTERM signal handler.  
00316 
00317 #define CR_INST_ALL_EXCEPTION_HANDLERS         0       //!< Install all possible exception handlers.
00318 #define CR_INST_CRT_EXCEPTION_HANDLERS         0x1FFE  //!< Install exception handlers for the linked CRT module.
00319 
00320 #define CR_INST_NO_GUI                         0x2000  //!< Do not show GUI, send report silently (use for non-GUI apps only).
00321 #define CR_INST_HTTP_BINARY_ENCODING           0x4000  //!< Use multi-part HTTP uploads with binary attachment encoding.
00322 #define CR_INST_DONT_SEND_REPORT               0x8000  //!< Don't send error report immediately, just save it locally.
00323 #define CR_INST_APP_RESTART                    0x10000 //!< Restart the application on crash.
00324 #define CR_INST_NO_MINIDUMP                    0x20000 //!< Do not include minidump file to crash report.
00325 #define CR_INST_SEND_QUEUED_REPORTS            0x40000 //!< CrashRpt should send error reports that are waiting to be delivered.
00326 #define CR_INST_STORE_ZIP_ARCHIVES             0x80000 //!< CrashRpt should store both uncompressed error report files and ZIP archives.
00327 
00524 typedef struct tagCR_INSTALL_INFOW
00525 {
00526   WORD cb;                        
00527   LPCWSTR pszAppName;             
00528   LPCWSTR pszAppVersion;          
00529   LPCWSTR pszEmailTo;             
00530   LPCWSTR pszEmailSubject;        
00531   LPCWSTR pszUrl;                 
00532   LPCWSTR pszCrashSenderPath;     
00533   LPGETLOGFILE pfnCrashCallback;  
00534   UINT uPriorities[5];            
00535   DWORD dwFlags;                  
00536   LPCWSTR pszPrivacyPolicyURL;    
00537   LPCWSTR pszDebugHelpDLL;        
00538   MINIDUMP_TYPE uMiniDumpType;    
00539   LPCWSTR pszErrorReportSaveDir;  
00540   LPCWSTR pszRestartCmdLine;      
00541   LPCWSTR pszLangFilePath;        
00542   LPCWSTR pszEmailText;           
00543   LPCWSTR pszSmtpProxy;           
00544   LPCWSTR pszCustomSenderIcon;    
00545 }
00546 CR_INSTALL_INFOW;
00547 
00548 typedef CR_INSTALL_INFOW *PCR_INSTALL_INFOW;
00549 
00555 typedef struct tagCR_INSTALL_INFOA
00556 {
00557   WORD cb;                       
00558   LPCSTR pszAppName;             
00559   LPCSTR pszAppVersion;          
00560   LPCSTR pszEmailTo;             
00561   LPCSTR pszEmailSubject;        
00562   LPCSTR pszUrl;                 
00563   LPCSTR pszCrashSenderPath;     
00564   LPGETLOGFILE pfnCrashCallback; 
00565   UINT uPriorities[3];           
00566   DWORD dwFlags;                 
00567   LPCSTR pszPrivacyPolicyURL;    
00568   LPCSTR pszDebugHelpDLL;        
00569   MINIDUMP_TYPE uMiniDumpType;   
00570   LPCSTR pszErrorReportSaveDir;  
00571   LPCSTR pszRestartCmdLine;      
00572   LPCSTR pszLangFilePath;        
00573   LPCSTR pszEmailText;           
00574   LPCSTR pszSmtpProxy;           
00575   LPCSTR pszCustomSenderIcon;    
00576 }
00577 CR_INSTALL_INFOA;
00578 
00579 typedef CR_INSTALL_INFOA *PCR_INSTALL_INFOA;
00580 
00584 #ifdef UNICODE
00585 typedef CR_INSTALL_INFOW CR_INSTALL_INFO;
00586 typedef PCR_INSTALL_INFOW PCR_INSTALL_INFO;
00587 #else
00588 typedef CR_INSTALL_INFOA CR_INSTALL_INFO;
00589 typedef PCR_INSTALL_INFOA PCR_INSTALL_INFO; 
00590 #endif // UNICODE
00591 
00649 CRASHRPTAPI(int)
00650 crInstallW(
00651   __in PCR_INSTALL_INFOW pInfo
00652 );
00653 
00658 CRASHRPTAPI(int)
00659 crInstallA(
00660   __in PCR_INSTALL_INFOA pInfo
00661 );
00662 
00666 #ifdef UNICODE
00667 #define crInstall crInstallW
00668 #else
00669 #define crInstall crInstallA
00670 #endif //UNICODE
00671 
00693 CRASHRPTAPI(int)
00694 crUninstall();
00695 
00696 
00731 CRASHRPTAPI(int)
00732 crInstallToCurrentThread();
00733 
00780 CRASHRPTAPI(int)
00781 crInstallToCurrentThread2(DWORD dwFlags);
00782 
00805 CRASHRPTAPI(int)
00806 crUninstallFromCurrentThread();
00807 
00841 CRASHRPTAPI(int)
00842 crAddFileW(
00843    LPCWSTR pszFile,
00844    LPCWSTR pszDesc 
00845    );
00846 
00852 CRASHRPTAPI(int)
00853 crAddFileA(
00854    LPCSTR pszFile,
00855    LPCSTR pszDesc 
00856    );
00857 
00861 #ifdef UNICODE
00862 #define crAddFile crAddFileW
00863 #else
00864 #define crAddFile crAddFileA
00865 #endif //UNICODE
00866 
00867 // Flags for crAddFile2() function.
00868 
00869 #define CR_AF_TAKE_ORIGINAL_FILE  0 //!< Take the original file (do not copy it to the error report folder).
00870 #define CR_AF_MAKE_FILE_COPY      1 //!< Copy the file to the error report folder.
00871 
00872 #define CR_AF_FILE_MUST_EXIST     0 //!< Function will fail if file doesn't exist at the moment of function call.
00873 #define CR_AF_MISSING_FILE_OK     2 //!< Do not fail if file is missing (assume it will be created later).
00874 
00926 CRASHRPTAPI(int)
00927 crAddFile2W(
00928    LPCWSTR pszFile,
00929    LPCWSTR pszDestFile,
00930    LPCWSTR pszDesc,
00931    DWORD dwFlags
00932    );
00933 
00938 CRASHRPTAPI(int)
00939 crAddFile2A(
00940    LPCSTR pszFile,
00941    LPCSTR pszDestFile,
00942    LPCSTR pszDesc,
00943    DWORD dwFlags
00944    );
00945 
00949 #ifdef UNICODE
00950 #define crAddFile2 crAddFile2W
00951 #else
00952 #define crAddFile2 crAddFile2A
00953 #endif //UNICODE
00954 
00955 
00956 // Flags for crAddScreenshot function.
00957 #define CR_AS_VIRTUAL_SCREEN  0  //!< Take a screenshot of the virtual screen.
00958 #define CR_AS_MAIN_WINDOW     1  //!< Take a screenshot of application's main window.
00959 #define CR_AS_PROCESS_WINDOWS 2  //!< Take a screenshot of all visible process windows.
00960 #define CR_AS_GRAYSCALE_IMAGE 4  //!< Make a grayscale image instead of a full-color one.
00961 #define CR_AS_USE_JPEG_FORMAT 8  //!< Store screenshots as JPG files.
00962 
01011 CRASHRPTAPI(int)
01012 crAddScreenshot(
01013    DWORD dwFlags
01014    );
01015 
01065 CRASHRPTAPI(int)
01066 crAddScreenshot2(
01067    DWORD dwFlags,
01068    int nJpegQuality
01069    );
01070 
01098 CRASHRPTAPI(int)
01099 crAddPropertyW(
01100    LPCWSTR pszPropName,
01101    LPCWSTR pszPropValue
01102    );
01103 
01108 CRASHRPTAPI(int)
01109 crAddPropertyA(
01110    LPCSTR pszPropName,
01111    LPCSTR pszPropValue
01112    );
01113 
01117 #ifdef UNICODE
01118 #define crAddProperty crAddPropertyW
01119 #else
01120 #define crAddProperty crAddPropertyA
01121 #endif //UNICODE
01122 
01159 CRASHRPTAPI(int)
01160 crAddRegKeyW(   
01161    LPCWSTR pszRegKey,
01162    LPCWSTR pszDstFileName,
01163    DWORD dwFlags
01164    );
01165 
01170 CRASHRPTAPI(int)
01171 crAddRegKeyA(   
01172    LPCSTR pszRegKey,
01173    LPCSTR pszDstFileName,
01174    DWORD dwFlags
01175    );
01176 
01180 #ifdef UNICODE
01181 #define crAddRegKey crAddRegKeyW
01182 #else
01183 #define crAddRegKey crAddRegKeyA
01184 #endif //UNICODE
01185 
01186 // Exception types
01187 #define CR_WIN32_STRUCTURED_EXCEPTION   0    //!< SEH exception (deprecated name, use \ref CR_SEH_EXCEPTION instead).
01188 #define CR_SEH_EXCEPTION                0    //!< SEH exception.
01189 #define CR_CPP_TERMINATE_CALL           1    //!< C++ terminate() call.
01190 #define CR_CPP_UNEXPECTED_CALL          2    //!< C++ unexpected() call.
01191 #define CR_CPP_PURE_CALL                3    //!< C++ pure virtual function call (VS .NET and later).
01192 #define CR_CPP_NEW_OPERATOR_ERROR       4    //!< C++ new operator fault (VS .NET and later).
01193 #define CR_CPP_SECURITY_ERROR           5    //!< Buffer overrun error (VS .NET only).
01194 #define CR_CPP_INVALID_PARAMETER        6    //!< Invalid parameter exception (VS 2005 and later).
01195 #define CR_CPP_SIGABRT                  7    //!< C++ SIGABRT signal (abort).
01196 #define CR_CPP_SIGFPE                   8    //!< C++ SIGFPE signal (flotating point exception).
01197 #define CR_CPP_SIGILL                   9    //!< C++ SIGILL signal (illegal instruction).
01198 #define CR_CPP_SIGINT                   10   //!< C++ SIGINT signal (CTRL+C).
01199 #define CR_CPP_SIGSEGV                  11   //!< C++ SIGSEGV signal (invalid storage access).
01200 #define CR_CPP_SIGTERM                  12   //!< C++ SIGTERM signal (termination request).
01201 
01202 
01266 typedef struct tagCR_EXCEPTION_INFO
01267 {
01268   WORD cb;                   
01269   PEXCEPTION_POINTERS pexcptrs; 
01270   int exctype;               
01271   DWORD code;                
01272   unsigned int fpe_subcode;  
01273   const wchar_t* expression; 
01274   const wchar_t* function;   
01275   const wchar_t* file;       
01276   unsigned int line;         
01277   BOOL bManual;              
01278   HANDLE hSenderProcess;     
01279 }
01280 CR_EXCEPTION_INFO;
01281 
01282 typedef CR_EXCEPTION_INFO *PCR_EXCEPTION_INFO;
01283 
01328 CRASHRPTAPI(int)
01329 crGenerateErrorReport(   
01330    __in_opt CR_EXCEPTION_INFO* pExceptionInfo
01331    );
01332 
01333 
01374 CRASHRPTAPI(int)
01375 crExceptionFilter(
01376   unsigned int code, 
01377   __in_opt struct _EXCEPTION_POINTERS* ep);
01378 
01379 #define CR_NONCONTINUABLE_EXCEPTION  32  //!< Non continuable sofware exception. 
01380 #define CR_THROW                     33  //!< Throw C++ typed exception.
01381 
01433 CRASHRPTAPI(int)
01434 crEmulateCrash(
01435   unsigned ExceptionType) throw (...);
01436 
01437 
01438 
01471 CRASHRPTAPI(int)
01472 crGetLastErrorMsgW(
01473   __out_ecount_z(uBuffSize) LPWSTR pszBuffer, 
01474   UINT uBuffSize);
01475 
01481 CRASHRPTAPI(int)
01482 crGetLastErrorMsgA(
01483   __out_ecount_z(uBuffSize) LPSTR pszBuffer, 
01484   UINT uBuffSize);
01485 
01490 #ifdef UNICODE
01491 #define crGetLastErrorMsg crGetLastErrorMsgW
01492 #else
01493 #define crGetLastErrorMsg crGetLastErrorMsgA
01494 #endif //UNICODE
01495 
01496 
01498 
01499 #ifndef _CRASHRPT_NO_WRAPPERS
01500 
01546 class CrAutoInstallHelper
01547 {
01548 public:
01549 
01551   CrAutoInstallHelper(__in PCR_INSTALL_INFOA pInfo)
01552   {
01553     m_nInstallStatus = crInstallA(pInfo);
01554   }
01555 
01557   CrAutoInstallHelper(__in PCR_INSTALL_INFOW pInfo)
01558   {
01559     m_nInstallStatus = crInstallW(pInfo);
01560   }
01561 
01563   ~CrAutoInstallHelper()
01564   {
01565     crUninstall();
01566   }
01567 
01569   int m_nInstallStatus;
01570 };
01571 
01597 class CrThreadAutoInstallHelper
01598 {
01599 public:
01600 
01602   CrThreadAutoInstallHelper(DWORD dwFlags=0)
01603   {
01604     m_nInstallStatus = crInstallToCurrentThread2(dwFlags);    
01605   }
01606 
01608   ~CrThreadAutoInstallHelper()
01609   {
01610     crUninstallFromCurrentThread();
01611   }
01612 
01614   int m_nInstallStatus;
01615 };
01616 
01617 #endif //!_CRASHRPT_NO_WRAPPERS
01618 
01619 #endif //_CRASHRPT_H_
01620 
01621