Click here to Skip to main content
15,884,085 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.3K   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: Examples of Using CrashRptProbe API</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_error_reports.html">Using Error Reports</a>&nbsp;&raquo&nbsp;<a class="el" href="automating_crash_report_processing.html">Automating Crash Report Processing</a>
  </div>
</div>
<div class="contents">
<h1><a class="anchor" name="crashrptprobe_api_examples">Examples of Using CrashRptProbe API </a></h1>This page contains several examples of using CrashRptProbe API described in <a class="el" href="using_crashrptprobe_api.html">Using CrashRptProbe API</a>.<h2><a class="anchor" name="opening_an_error_report">
Opening Error Report</a></h2>
The following example shows how to open an error report file: <div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="_crash_rpt_probe_8h.html" title="Defines the interface for the CrashRptProbe.DLL.">CrashRptProbe.h</a>&gt;</span>

<span class="comment">//...</span>
  
<a class="code" href="_crash_rpt_probe_8h.html#2b2d28276d67dd476ea8aa9c45669d82" title="Handle to an opened error report.">CrpHandle</a> hReport = 0;
<span class="keywordtype">int</span> nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g6321942ac8b4635b13300df5219cac6e" title="Character set-independent mapping of crpOpenErrorReportW() and crpOpenErrorReportA()...">crpOpenErrorReport</a>(
               _T(<span class="stringliteral">"0b3b0c1b-3450-4c39-9459-42221ae66460.zip"</span>), <span class="comment">// Zip archive name</span>
               _T(<span class="stringliteral">"2e4345603454a345064371ab34195316"</span>), <span class="comment">// MD5 hash for the file</span>
               _T(<span class="stringliteral">"D:\\MyApp\\1.3.4\\Sym; D:\\MyApp\\1.3.5\\Sym"</span>), <span class="comment">// Where to look for symbols</span>
               0, <span class="comment">// Reserved</span>
               &amp;hReport
               );

<span class="keywordflow">if</span>(nResult!=0) <span class="comment">// Check the result</span>
{
  <span class="comment">// Get the error message</span>
  TCHAR szErrorMsg[256];
  <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0d9c05a90d82156c237f6d50bb2157c6" title="Defines character set-independent mapping for crpGetLastErrorMsgW() and crpGetLastErrorMsgA()...">crpGetLastErrorMsg</a>(szErrorMsg, 256);
  <span class="keywordflow">return</span>;
}

<span class="comment">// Read the properties, extract files...</span>

<span class="comment">// Finally, close the report</span>
<a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e7fd985622aae142ead686d5380c6c5" title="Closes the crash report.">crpCloseErrorReport</a>(hReport);
</pre></div><h2><a class="anchor" name="gettion_row_count">
Getting Row Count in a Table</a></h2>
The following example shows how to get count of rows in a table.<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="_crash_rpt_probe_8h.html" title="Defines the interface for the CrashRptProbe.DLL.">CrashRptProbe.h</a>"</span>
<span class="preprocessor">#include &lt;assert.h&gt;</span>

<a class="code" href="_crash_rpt_probe_8h.html#2b2d28276d67dd476ea8aa9c45669d82" title="Handle to an opened error report.">CrpHandle</a> hReport; <span class="comment">// We assume this variable </span>
                   <span class="comment">// contains handle to opened error report.</span>

<span class="comment">// Get row count in the CRP_TBL_XMLDESC_MISC table. </span>
<span class="comment">// This table contains miscellaneous info loaded from XML descriptor file.</span>
<span class="keywordtype">int</span> nRowCount = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#06fd07f7a9ad9d549708aa3bedb68061" title="Table: Miscellaneous info contained in crash description XML file.">CRP_TBL_XMLDESC_MISC</a>, 
                    <a class="code" href="_crash_rpt_probe_8h.html#37d896e593fa4667d38907b2adb98372" title="Row count in the table.">CRP_META_ROW_COUNT</a>, 0, NULL, 0, NULL);
assert(nRowCount==1); <span class="comment">// This table should always contain single row.</span>


<span class="comment">// Get row count in the CRP_TBL_MDMP_MODULES table. </span>
<span class="comment">// This table contains the list of modules loaded from minidump file.</span>
nRowCount = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#f6846fd2538956b0f7fba6f1b2ce7d8f" title="Table: The list of loaded modules.">CRP_TBL_MDMP_MODULES</a>, 
                    <a class="code" href="_crash_rpt_probe_8h.html#37d896e593fa4667d38907b2adb98372" title="Row count in the table.">CRP_META_ROW_COUNT</a>, 0, NULL, 0, NULL);
</pre></div><h2><a class="anchor" name="getting_misc_info">
Getting Miscellaneous Information about Error Report</a></h2>
The following example shows how to get miscellaneous information from <a class="el" href="_crash_rpt_probe_8h.html#06fd07f7a9ad9d549708aa3bedb68061">CRP_TBL_XMLDESC_MISC</a> and <a class="el" href="_crash_rpt_probe_8h.html#d001f9f10bafbacf60c9c2f6b06b796d">CRP_TBL_MDMP_MISC</a> tables.<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="_crash_rpt_probe_8h.html" title="Defines the interface for the CrashRptProbe.DLL.">CrashRptProbe.h</a>"</span>

<a class="code" href="_crash_rpt_probe_8h.html#2b2d28276d67dd476ea8aa9c45669d82" title="Handle to an opened error report.">CrpHandle</a> hReport; <span class="comment">// We assume this variable </span>
                   <span class="comment">// contains handle to opened error report.</span>

<span class="keyword">const</span> <span class="keywordtype">int</span> BUFF_SIZE = 1024;
TCHAR szBuffer[BUFF_SIZE];

<span class="comment">// Get the CrashRpt version</span>
<span class="keywordtype">int</span> nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#06fd07f7a9ad9d549708aa3bedb68061" title="Table: Miscellaneous info contained in crash description XML file.">CRP_TBL_XMLDESC_MISC</a>,
  <a class="code" href="_crash_rpt_probe_8h.html#9d54fafc774b44f11c62bdf2094f6483" title="Column: Version of CrashRpt library that generated the report.">CRP_COL_CRASHRPT_VERSION</a>, 0, szBuffer, BUFF_SIZE, NULL);

<span class="comment">// Get the name of the application </span>
nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#06fd07f7a9ad9d549708aa3bedb68061" title="Table: Miscellaneous info contained in crash description XML file.">CRP_TBL_XMLDESC_MISC</a>,
  <a class="code" href="_crash_rpt_probe_8h.html#c016feb498b37c39f603461718fd7961" title="Column: Application name.">CRP_COL_APP_NAME</a>, 0, szBuffer, BUFF_SIZE, NULL);

<span class="comment">// Get the exception address</span>
nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#d001f9f10bafbacf60c9c2f6b06b796d" title="Table: Miscellaneous info contained in crash minidump file.">CRP_TBL_MDMP_MISC</a>,
  <a class="code" href="_crash_rpt_probe_8h.html#ddd0dbd38130b8de54b55a0c60577064" title="Column: Exception address.">CRP_COL_EXCEPTION_ADDRESS</a>, 0, szBuffer, BUFF_SIZE, NULL);

<span class="comment">// Get the exception thread ROWID</span>
nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#d001f9f10bafbacf60c9c2f6b06b796d" title="Table: Miscellaneous info contained in crash minidump file.">CRP_TBL_MDMP_MISC</a>,
  <a class="code" href="_crash_rpt_probe_8h.html#a4ef51827e7229e738f87a47dd432bff" title="Column: ROWID in CRP_TBL_MDMP_THREADS of the thread in which exception occurred.">CRP_COL_EXCEPTION_THREAD_ROWID</a>, 0, szBuffer, BUFF_SIZE, NULL);

<span class="comment">// Convert string to int</span>
<span class="keywordtype">int</span> nExceptionThreadRowId = _ttoi(szBuffer);

<span class="keywordflow">if</span>(nResult==0)
{
  <span class="comment">// Get the exception thread ID</span>
  nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#57c9d3fe736ed0f2b77f22422a865c06" title="Table: The list of threads.">CRP_TBL_MDMP_THREADS</a>,
    <a class="code" href="_crash_rpt_probe_8h.html#aafd0bdebd39e932c003b954bc9e43f7" title="Column: Thread ID.">CRP_COL_THREAD_ID</a>, nExceptionThreadRowId, szBuffer, BUFF_SIZE, NULL);
  
  <span class="comment">// Get stack trace for the exception thread.</span>
  <span class="comment">// See the section below to learn how to enumerate stack frames.</span>
}
</pre></div><h2><a class="anchor" name="enumerating_threads">
Enumerating Threads and Loading Stack Trace for Each Thread</a></h2>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="_crash_rpt_probe_8h.html" title="Defines the interface for the CrashRptProbe.DLL.">CrashRptProbe.h</a>"</span>
<span class="preprocessor">#include &lt;assert.h&gt;</span>

<a class="code" href="_crash_rpt_probe_8h.html#2b2d28276d67dd476ea8aa9c45669d82" title="Handle to an opened error report.">CrpHandle</a> hReport; <span class="comment">// We assume this variable </span>
                   <span class="comment">// contains handle to opened error report.</span>

<span class="comment">// Get row count in the CRP_TBL_MDMP_THREADS table.</span>
<span class="keywordtype">int</span> nThreadCount = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#57c9d3fe736ed0f2b77f22422a865c06" title="Table: The list of threads.">CRP_TBL_MDMP_THREADS</a>, 
                    <a class="code" href="_crash_rpt_probe_8h.html#37d896e593fa4667d38907b2adb98372" title="Row count in the table.">CRP_META_ROW_COUNT</a>, 0, NULL, 0, NULL);

<span class="comment">// Enumerate threads</span>
<span class="keywordtype">int</span> i;
<span class="keywordflow">for</span>(i=0; i&lt;nThreadCount; i++)
{
  <span class="keyword">const</span> <span class="keywordtype">int</span> BUFF_SIZE = 1024;
  TCHAR szThreadID[BUFF_SIZE];     <span class="comment">// Here we will store thread ID</span>
  TCHAR szStackTableID[BUFF_SIZE]; <span class="comment">// Here we will store stack trace </span>
                                   <span class="comment">// table ID for a thread.</span>
  TCHAR szBuffer[BUFF_SIZE]; 

  <span class="comment">// Get thread ID.</span>
  <span class="keywordtype">int</span> nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#57c9d3fe736ed0f2b77f22422a865c06" title="Table: The list of threads.">CRP_TBL_MDMP_THREADS</a>,
                 <a class="code" href="_crash_rpt_probe_8h.html#aafd0bdebd39e932c003b954bc9e43f7" title="Column: Thread ID.">CRP_COL_THREAD_ID</a>, i, szThreadID, BUFF_SIZE, NULL);
  assert(nResult==0);

  <span class="comment">// Get stack trace table ID for this thread.</span>
  nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#57c9d3fe736ed0f2b77f22422a865c06" title="Table: The list of threads.">CRP_TBL_MDMP_THREADS</a>,
                 <a class="code" href="_crash_rpt_probe_8h.html#ca6b2a52907531385b9e46592d2435a7" title="Column: The table ID of the table containing stack trace for this thread.">CRP_COL_THREAD_STACK_TABLEID</a>, i, szStackTableID, BUFF_SIZE, NULL);
  assert(nResult==0);

  <span class="comment">// Get row count in the stack trace table.</span>
  <span class="keywordtype">int</span> nFrameCount = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, szStackTableID, 
                      <a class="code" href="_crash_rpt_probe_8h.html#37d896e593fa4667d38907b2adb98372" title="Row count in the table.">CRP_META_ROW_COUNT</a>, 0, NULL, 0, NULL);

  <span class="keywordtype">int</span> j;
  <span class="keywordflow">for</span>(j=0; j&lt;nFrameCount; j++)
  {
    <span class="comment">// Get the row ID of the module for this stack frame.</span>
    nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, szStackTableID,
                 <a class="code" href="_crash_rpt_probe_8h.html#cfe4f1c042765f598f561682dd58aa4d" title="Column: Stack trace: ROWID of the module in the CRP_TBL_MODULES table.">CRP_COL_STACK_MODULE_ROWID</a>, j, szStackTableID, BUFF_SIZE, NULL);
    <span class="keywordflow">if</span>(nResult==0)
    {
      <span class="comment">// Convert row ID to int</span>
      <span class="keywordtype">int</span> nModuleRowID = _ttoi(szBuffer);

      <span class="comment">// Get the module name from CRP_MDMP_MODULES table.</span>
      nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#f6846fd2538956b0f7fba6f1b2ce7d8f" title="Table: The list of loaded modules.">CRP_TBL_MDMP_MODULES</a>,
                      <a class="code" href="_crash_rpt_probe_8h.html#965d1dfd2cb14cdd5b26cead80692e99" title="Column: Module name.">CRP_COL_MODULE_NAME</a>, nModuleRowID, szBuffer, BUFF_SIZE, NULL);            
    }
 
    <span class="comment">// Get the symbol name for this stack frame ().</span>
    nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, szStackTableID,
                 <a class="code" href="_crash_rpt_probe_8h.html#2f18d540568e12f72e3d41aaf38b4f95" title="Column: Stack trace: symbol name.">CRP_COL_STACK_SYMBOL_NAME</a>, j, szStackTableID, BUFF_SIZE, NULL);
    assert(nResult==0);
    
    <span class="comment">// Check if we have valid symbol name for this stack trace.</span>
    <span class="keywordflow">if</span>(_tcscmp(szBuffer, _T(<span class="stringliteral">""</span>))!=0)
    {
      <span class="comment">// We have a symbol loaded for this stack frame.</span>
      <span class="comment">// Get the offset in symbol.</span>
      nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, szStackTableID,
                 <a class="code" href="_crash_rpt_probe_8h.html#296fa91c1ec2d448c9477aa7ef9925d0" title="Column: Stack trace: offset in symbol, hexadecimal.">CRP_COL_STACK_OFFSET_IN_SYMBOL</a>, j, szStackTableID, BUFF_SIZE, NULL);
    }
    <span class="keywordflow">else</span>
    {
      <span class="comment">// We do not have symbol loaded for this stack frame, but we can</span>
      <span class="comment">// get the program counter CPU register address for this stack frame.</span>
      nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, szStackTableID,
                 <a class="code" href="_crash_rpt_probe_8h.html#a27c745dc1550285f7f5d1e7a436e3ca" title="Column: Stack trace: AddrPC offset.">CRP_COL_STACK_ADDR_PC_OFFSET</a>, j, szStackTableID, BUFF_SIZE, NULL);
    }       
  }
}
</pre></div><h2><a class="anchor" name="enumerating_modules">
Enumerating Loaded Modules</a></h2>
The following examples shows how to enumerate loaded modules.<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="_crash_rpt_probe_8h.html" title="Defines the interface for the CrashRptProbe.DLL.">CrashRptProbe.h</a>"</span>
<span class="preprocessor">#include &lt;assert.h&gt;</span>

<a class="code" href="_crash_rpt_probe_8h.html#2b2d28276d67dd476ea8aa9c45669d82" title="Handle to an opened error report.">CrpHandle</a> hReport; <span class="comment">// We assume this variable </span>
                   <span class="comment">// contains handle to opened error report.</span>

<span class="comment">// Get row count in the CRP_TBL_MDMP_MODULES table.</span>
<span class="keywordtype">int</span> nRowCount = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#f6846fd2538956b0f7fba6f1b2ce7d8f" title="Table: The list of loaded modules.">CRP_TBL_MDMP_MODULES</a>, 
                    <a class="code" href="_crash_rpt_probe_8h.html#37d896e593fa4667d38907b2adb98372" title="Row count in the table.">CRP_META_ROW_COUNT</a>, 0, NULL, 0, NULL);

<span class="comment">// Enumerate modules</span>
<span class="keywordtype">int</span> i;
<span class="keywordflow">for</span>(i=0; i&lt;nRowCount; i++)
{
  <span class="keyword">const</span> <span class="keywordtype">int</span> BUFF_SIZE = 1024;
  TCHAR szBuffer[BUFF_SIZE];

  <span class="comment">// Get module name.</span>
  <span class="keywordtype">int</span> nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#f6846fd2538956b0f7fba6f1b2ce7d8f" title="Table: The list of loaded modules.">CRP_TBL_MDMP_MODULES</a>,
                 <a class="code" href="_crash_rpt_probe_8h.html#965d1dfd2cb14cdd5b26cead80692e99" title="Column: Module name.">CRP_COL_MODULE_NAME</a>, i, szBuffer, BUFF_SIZE, NULL);
  assert(nResult==0);

  <span class="comment">// Get module image name.</span>
  nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#f6846fd2538956b0f7fba6f1b2ce7d8f" title="Table: The list of loaded modules.">CRP_TBL_MDMP_MODULES</a>,
                 <a class="code" href="_crash_rpt_probe_8h.html#4a8ca26a5492dd05f0fbbbe3e78dc601" title="Column: Image name containing full path.">CRP_COL_MODULE_IMAGE_NAME</a>, i, szBuffer, BUFF_SIZE, NULL);
  assert(nResult==0);

  <span class="comment">// Get module PDB file name (can be used to determine if symbols were</span>
  <span class="comment">// loaded for this module).</span>
  nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#f6846fd2538956b0f7fba6f1b2ce7d8f" title="Table: The list of loaded modules.">CRP_TBL_MDMP_MODULES</a>,
                 <a class="code" href="_crash_rpt_probe_8h.html#f535cc949670edfadd168f197d9893d5" title="Column: The full path and file name of the .pdb file.">CRP_COL_MODULE_LOADED_PDB_NAME</a>, i, szBuffer, BUFF_SIZE, NULL);
  assert(nResult==0);  
                                           
}
</pre></div><h2><a class="anchor" name="enumerating_file_items">
Enumerating and Extracting Files Contained in Error Report</a></h2>
The following example shows how to enumerate files contained in the error report and extract them.<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include "<a class="code" href="_crash_rpt_probe_8h.html" title="Defines the interface for the CrashRptProbe.DLL.">CrashRptProbe.h</a>"</span>
<span class="preprocessor">#include &lt;assert.h&gt;</span>

<a class="code" href="_crash_rpt_probe_8h.html#2b2d28276d67dd476ea8aa9c45669d82" title="Handle to an opened error report.">CrpHandle</a> hReport; <span class="comment">// We assume this variable </span>
                   <span class="comment">// contains handle to opened error report.</span>

<span class="comment">// Get row count in the CRP_TBL_XMLDESC_FILE_ITEMS table.</span>
<span class="keywordtype">int</span> nRowCount = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#8c66617a7f801165edb294da48c5575b" title="Table: The list of file items contained in error report.">CRP_TBL_XMLDESC_FILE_ITEMS</a>, 
                    <a class="code" href="_crash_rpt_probe_8h.html#37d896e593fa4667d38907b2adb98372" title="Row count in the table.">CRP_META_ROW_COUNT</a>, 0, NULL, 0, NULL);

<span class="comment">// Enumerate file items</span>
<span class="keywordtype">int</span> i;
<span class="keywordflow">for</span>(i=0; i&lt;nRowCount; i++)
{
  <span class="keyword">const</span> <span class="keywordtype">int</span> BUFF_SIZE = 1024;
  TCHAR szBuffer[BUFF_SIZE];

  <span class="comment">// Get file item name</span>
  <span class="keywordtype">int</span> nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#8c66617a7f801165edb294da48c5575b" title="Table: The list of file items contained in error report.">CRP_TBL_XMLDESC_FILE_ITEMS</a>,
                 <a class="code" href="_crash_rpt_probe_8h.html#3812964f7e0aedfbc71b7f0ecf88d617" title="Column: File list: Name of the file contained in the report.">CRP_COL_FILE_ITEM_NAME</a>, i, szBuffer, BUFF_SIZE, NULL);
  <span class="keywordflow">if</span>(nResult==0)
  {
    <span class="comment">// Extract file overwriting if such file already exists</span>
    <span class="keywordtype">int</span> nExtract = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g237fcf61f3027bb315c54bf82e3779d2" title="Character set-independent mapping of crpExtractFileW() and crpExtractFileA() functions...">crpExtractFile</a>(hReport, szBuffer, szBuffer, TRUE);
  }

  <span class="comment">// Get file item description </span>
  nResult = <a class="code" href="group___crash_rpt_probe_a_p_i.html#g0e45570a3b25c6c5f8971b3179c5fdbf" title="Character set-independent mapping of crpGetPropertyW() and crpGetPropertyA() functions...">crpGetProperty</a>(hReport, <a class="code" href="_crash_rpt_probe_8h.html#8c66617a7f801165edb294da48c5575b" title="Table: The list of file items contained in error report.">CRP_TBL_XMLDESC_FILE_ITEMS</a>,
                 <a class="code" href="_crash_rpt_probe_8h.html#9ac7d60a02510e1e2b4c045f4c0b1f53" title="Column: File list: Description of the file contained in the report.">CRP_COL_FILE_ITEM_DESCRIPTION</a>, i, szBuffer, BUFF_SIZE, NULL);
  assert(nResult==0);

}
</pre></div> </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