We often encounter this situation, in Program During the running process, the crash suddenly fell, and it was crash at the customer. In this case, we need to use the dump file to find the location where exception occurs. The following Code Is to create a minidump file. For the reason of Mini, it is not because it is small or the content is small, but relative to fulldump, the minidump file only stores some key virtual memory information of the Process in crash. Code
# Include " Stdafx. h "
# Include < Windows. h >
# Include < Dbghelp. h >
# PragmaComment (Lib, "dbghelp. lib ")
void createminidump (lpexception_pointers lpexceptioninfo) {
// open a file
handle hfile = createfile (_ T ( " minidump. DMP " ), generic_read | generic_write,
0 , null, create_always, file_attribute_normal, null);
If (hfile ! = null & hfile ! = invalid_handle_value) {
// Create the minidump
minidump_exception_information mdei;
mdei. threadid = getcurrentthreadid ();
mdei. predictionpointers = lpexceptioninfo;
mdei. clientpointers = false;
Minidump_type MDT = Minidumpnormal;
Bool retv = Minidumpwritedump (getcurrentprocess (), getcurrentprocessid (),
Hfile, MDT, (lpexceptioninfo ! = 0 ) ? & Mdei: 0 , 0 , 0 );
If ( ! Retv ){
_ Tprintf (_ T ( " Minidumpwritedump failed. Error: % u \ n " ), Getlasterror ());
} Else {
_ Tprintf (_ T ( " Minidump created. \ n " ));
}
//Close the file
Closehandle (hfile );
}Else{
_ Tprintf (_ T ("Createfile failed. Error: % u \ n"), Getlasterror ());
}
}
Int _ Tmain ( Int Argc, _ tchar * Argv [])
{
_ Try {
Int * P = NULL;
* P = 20 ;
}
_ Effect (createminidump (getexceptioninformation (), exception_execute_handler ){
}
Return 0;
}
When a minidump file is created, the dump file cannot be written. That is, there is an exception processing module outside the exception block, and the minidump file is not saved for processing. At this time, there is no way to write dump.