Click here to Skip to main content
15,898,035 members
Articles / Web Development / HTML

Integrating Crash Reporting into Your Application - A Beginners Tutorial

Rate me:
Please Sign up or sign in to vote.
4.91/5 (30 votes)
5 Feb 2012CPOL12 min read 90.8K   4.4K   170  
This article shows how to use CrashRpt error reporting library with an MFC application
<!-- This comment will put IE 6, 7 and 8 in quirks mode -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>CrashRpt: Compiling CrashRpt</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>

<table border="0" bgcolor="#FFFFFF" cellspacing="5" width="100%">
 <tr>
  <td width="24px" rowspan="2"><img src="../logo.png" alt="Logo" /></td>
  <td><font family="Arial" size="+2">crashrpt</font></td>
  <td rowspan="2" align="right"><a href="http://sourceforge.net/donate/index.php?group_id=279722"><img src="../donate_small.png" alt="Donate" /></a></td>
 </tr>
 <tr>
  <td colspan="2"><i>A crash reporting system for Windows applications</i></td>
 </tr>


</table>


</body>
<!-- Generated by Doxygen 1.5.9 -->
<script type="text/javascript">
<!--
function changeDisplayState (e){
  var num=this.id.replace(/[^[0-9]/g,'');
  var button=this.firstChild;
  var sectionDiv=document.getElementById('dynsection'+num);
  if (sectionDiv.style.display=='none'||sectionDiv.style.display==''){
    sectionDiv.style.display='block';
    button.src='open.gif';
  }else{
    sectionDiv.style.display='none';
    button.src='closed.gif';
  }
}
function initDynSections(){
  var divs=document.getElementsByTagName('div');
  var sectionCounter=1;
  for(var i=0;i<divs.length-1;i++){
    if(divs[i].className=='dynheader'&&divs[i+1].className=='dynsection'){
      var header=divs[i];
      var section=divs[i+1];
      var button=header.firstChild;
      if (button!='IMG'){
        divs[i].insertBefore(document.createTextNode(' '),divs[i].firstChild);
        button=document.createElement('img');
        divs[i].insertBefore(button,divs[i].firstChild);
      }
      header.style.cursor='pointer';
      header.onclick=changeDisplayState;
      header.id='dynheader'+sectionCounter;
      button.src='closed.gif';
      section.id='dynsection'+sectionCounter;
      section.style.display='none';
      section.style.marginLeft='14px';
      sectionCounter++;
    }
  }
}
window.onload = initDynSections;
-->
</script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Contents</span></a></li>
      <li><a href="modules.html"><span>API&nbsp;Reference</span></a></li>
      <li><a href="files.html"><span>File&nbsp;Reference</span></a></li>
    <li>
      <form action="search.php" method="get">
        <table cellspacing="0" cellpadding="0" border="0">
          <tr>
            <td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
            <td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
          </tr>
        </table>
      </form>
    </li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="index.html">CrashRpt Documentation</a>&nbsp;&raquo&nbsp;<a class="el" href="using_crashrpt.html">Using CrashRpt in Your Project</a>
  </div>
</div>
<div class="contents">
<h1><a class="anchor" name="compiling_crashrpt">Compiling CrashRpt </a></h1>By default, CrashRpt archive's <b>bin</b> directory contains binary files compiled in Visual Studio 2010. These files are provided for demonstration purposes only. It is strongly recommended that you compile CrashRpt yourself using your version of Visual Studio. This is needed to ensure CrashRpt uses the same version of C run-time libraries (CRT) as your application does.<h2><a class="anchor" name="building_solution">
Building Solution</a></h2>
The top-level directory of CrashRpt distribution contains solution file for Visual Studio 2010 (<b>CrashRpt_vs2010.sln</b>). Open this solution file to compile CrashRpt in <b>Visual C++ 2010</b> or in <b>Visual C++ Express 2010</b>.<p>
If you use another version of Visual Studio, you can generate solution/project files for your version of Visual Studio using CMake. See below for instructions.<h2><a class="anchor" name="cmake_build">
Generating Project Files with CMake</a></h2>
<b>Since v.1.3.0</b>, you can generate Visual Studio project files using <a href="http://www.cmake.org/">CMake</a> cross-platform make system. Although CrashRpt doesn't support operating systems other than Windows and doesn't support compilers other than Visual C++, CMake is useful, because it makes it easier to maintain multiple build configurations between different versions of Visual Studio.<p>
To generate CrashRpt solution/project files for your favorite version of Visual Studio with CMake, do the following:<p>
<ul>
<li>Download <a href="http://www.cmake.org/">CMake</a> (version 2.8 or later) and install it. This will create CMake shortcuts in All Programs menu in the Start menu.</li><li>Run CMake (cmake-gui) application. This will display the cmake-gui window.</li><li>In the <em>Where is the source code:</em> field, enter the path to your top-level directory of CrashRpt distribution. The top-level directory and its subdirectories contain CMakeLists.txt files which are CMake configuration files.</li><li>In the <em>Where to build the binaries:</em> field, enter the path to the directory where you want to generate project files. It is recommended to enter the path to your top-level directory of CrashRpt distribution here, too.</li><li>Press the <em>Configure</em> button. When prompted, select your version of Visual Studio from the list. If everything is OK, you should see the message "Configuring done".</li><li>In the option list, modify build options as you wish.<ul>
<li><em>CRASHRPT_BUILD_SHARED_LIBS</em> option controls whether to build CrashRpt as DLL or as a static LIB. It is recommended that you have this checked. Unchecking the option will force CrashRpt to build static libs instead of DLLs.</li><li><em>CRASHRPT_LINK_CRT_AS_DLL</em> option controls how CrashRpt should be linked to C run-time (CRT) libraries. Unchecking this option will force CrashRpt to link CRT as a multi-threaded static library. It is recommended that you have this checked, which results in linking CRT as multi-threaded DLL.</li></ul>
</li><li>After modifying options, press the <em>Configure</em> button the second time to force changes to make effect. If everything is OK, you should see the message "Configuring done".</li><li>Press the <em>Generate</em> button. This will generate project files to the directory you have specified. If everything is OK, you should see the message "Generating done".</li><li>And finally, go to the directory you have specified in the <em>Where to build the binaries:</em> field. You should see <b>CrashRpt.sln</b> file that you can use to compile CrashRpt.</li></ul>
<h2><a class="anchor" name="solution_structure">
CrashRpt Solution Structure</a></h2>
There are several projects in CrashRpt solution.<p>
<ul>
<li><b>CrashRpt</b> project contains API implementation and provides functionality for intercepting exceptions.</li></ul>
<p>
<ul>
<li><b>CrashSender</b> project contains functionality for displaying GUI, sending the error report and showing error report sending progress.</li></ul>
<p>
<ul>
<li><b>CrashRptTest</b> is a GUI application that helps to test that CrashRpt API functions work as expected.</li></ul>
<p>
<ul>
<li><b>crashcon</b> is a console application that helps to test how CrashRpt works with console applications.</li></ul>
<p>
<ul>
<li><b>zlib</b> project contains file compression functionality.</li></ul>
<p>
<ul>
<li><b>libpng</b> project contains PNG file management functionality.</li></ul>
<p>
<ul>
<li><b>jpeg</b> project contains JPEG file management functionality.</li></ul>
<p>
<ul>
<li><b>minizip</b> project contains ZIP file management functionality.</li></ul>
<p>
<ul>
<li><b>CrashRptProbe</b> project contains functionality for processing error reports.</li></ul>
<p>
<ul>
<li><b>crprober</b> is a console tool for error reports processing.</li></ul>
<p>
<ul>
<li><b>Tests</b> project contains automated tests.</li></ul>
<p>
To build the solution, choose the <b>Release</b> build configuration and press F7 to start building process.<h2><a class="anchor" name="compiling_x64_platform">
Compilation for 64-bit (x64) Platform</a></h2>
<b>Since v.1.2.1</b>, CrashRpt can be compiled for both 32-bit (Win32) and 64-bit (x64) platforms. You can choose the current platform by opening menu Build-&gt;Configuration Manager... and by selecting the desired platform from the 'Active solution platform:' combo box.<p>
If you use CMake to generate project files, select a 64-bit compiler from the drop-down list when configuring CMake.<p>
You should have x64 compiler tools and SDK files properly installed (ensure you have checked these components during Visual C++ installation).<h2><a class="anchor" name="notes_about_evc">
Notes About Compiling in Visual C++ Express</a></h2>
Compilation in free Visual C++ Express is a little more complicated than compilation in a commercial edition of Visual C++.<p>
CrashRpt depends on WTL. WTL itself depends on Microsoft's library called ATL (Active Template Library). ATL library is a part of Visual Studio SDKs. An older version, ATL 3.0, is included into Microsoft Platform SDK for Windows Server 2003. Since then, Platform SDK was renamed into Windows SDK. However, Microsoft doesn't include ATL into Windows SDK to encourage using of commercial Visual Studio having ATL.<p>
So, there are two ways to compile CrashRpt in Visual C++ Express:<p>
<b>The first way.</b> You need to have Platform SDK for Windows Server 2003, because this Platform SDK contains ATL 3.0 source code. Download and install Microsoft Platform SDK for Windows Server 2003, for example <a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=A55B6B43-E24F-4EA3-A93E-40C0EC4F68E5&displaylang=en">from here</a>.<p>
In VC++ Express window, open Tools-&gt;Options...-&gt;Projects and Solutions-&gt; VC++ Directories. In the 'Show directories for' combo, select 'Include files' and then add <em>&lt;Platform_SDK_Folder&gt;\Include\atl</em> path to the list of include directories (replace the &lt;Platform_SDK_Folder&gt; with the actual directory name).<p>
<b>The second way.</b> Install <a href="http://www.microsoft.com/whdc/devtools/wdk/wdkpkg.mspx">Windows Driver Kit</a>, version 7.0 or later, because it contains ATL 7.1 source code. When WinDDK is installed, in VC++ Express window, open Tools-&gt;Options...-&gt;Projects and Solutions-&gt; VC++ Directories. In the 'Show directories for' combo, select 'Include files' and then add <em>C:\WinDDK\6001.18002\inc\crt\atl71</em> path to the list of include directories.<h2><a class="anchor" name="builddox">
Generating Project Documentation</a></h2>
By default, project documentation is already generated and included into the CrashRpt distribution. To open the documentation, click <code>index.html</code> file in the top-level directory of CrashRpt distribution.<p>
You can also build documentation yourself. CrashRpt documentation can be generated using the Doxygen tool. You can download the tool from <a href="http://www.stack.nl/~dimitri/doxygen/">here</a>.<p>
To build the documentation, go to the <code>docs</code> folder and type in the command line:<p>
<div class="fragment"><pre class="fragment">doxygen Doxyfile
</pre></div><p>
When doxygen finishes, go to the top level directory and open <code>index.html</code>.<h2><a class="anchor" name="compilation_faq">
FAQ</a></h2>
<b>What is the Release LIB build configuration?</b><p>
The Release LIB configuration is an addition to the standard Debug and Release build configurations. Typically, you do not compile CrashRpt in this configuration. However, it may be useful if you use static CRT linkage.<p>
In the Release LIB configuration, the build generates CrashSender.exe executable file and CrashRptLIB.lib static library. In this configuration, CrashSender.exe and CrashRptLIB.lib use static linkage to CRT. </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sat Oct 22 17:37:43 2011 for CrashRpt by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.9 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Russian Federation Russian Federation
I am a software developer currently living in Tomsk, Russia. I received a PhD degree in Computer Science from Tomsk Polytechnic University in 2010. I have been professionally developing C/C++ and PHP software since 2005. I like contributing to open-source and writing programming articles for popular web resources, like CodeProject. Besides writing, I love skiing and watching Formula-1.

Comments and Discussions