Click here to Skip to main content
15,886,799 members
Articles / Programming Languages / C++

Trapping Bugs with BlackBox

Rate me:
Please Sign up or sign in to vote.
3.72/5 (27 votes)
25 May 2003BSD6 min read 263.6K   2.1K   130  
A brief article explaining how to use BlackBox in your programs to trap errors
// BlackBox.cpp : Defines the entry point for the DLL application.
//

#include "stdafx.h"
#include "BlackBox.h"
#include "Internal.h"
#include "BugSlayerUtil.h"
#include "BlackBoxUI.h"

static HINSTANCE g_hInst = NULL ;

LONG __stdcall BlackBoxCrashHandlerFilter ( EXCEPTION_POINTERS * pExPtrs );

const char* g_errorLable = 
					"A crash has been detected by BlackBox\n\n"\
					"To help the development process, this program will try "\
					"and gather as much information about the crash, and the state "\
					"of your machine at the time of the crash. This data will can then "\
					"be either copied to the clipboard or saved to a filed as plain text.\n"\
					"You can then either email to ddiego@users.sourceforge.net or submit "\
					"a new bug (http://sourceforge.net/tracker/?func=add&group_id=6796&atid=106796)"\
					" and paste the information into the Detailed Description field";


const char* g_mailToAddress = "mailto:ddiego@users.sourceforge.net";

const char* g_submitBugURL = "http://sourceforge.net/tracker/?func=add&group_id=6796&atid=106796";

BOOL APIENTRY DllMain ( HINSTANCE hInst       ,
                      DWORD     dwReason    ,
                      LPVOID    )
{
    BOOL bRet = TRUE ;	

    switch ( dwReason )   {

	    case DLL_PROCESS_ATTACH : {

			// Save off the DLL hInstance.
			g_hInst = hInst ;
			// I don't need the thread notifications.
			DisableThreadLibraryCalls ( g_hInst ) ;

#ifdef _DEBUG
		bRet = InternalMemStressInitialize ( ) ;
#endif
			
		if ( SetCrashHandlerFilter( BlackBoxCrashHandlerFilter ) ) {
			OutputDebugString( "SetCrashHandlerFilter succeeded\n" );			
		}
		else {
			OutputDebugString( "SetCrashHandlerFilter failed\n" );
		}

		}
		break ;		
		
		case DLL_PROCESS_DETACH : {
		
#ifdef _DEBUG
		bRet = InternalMemStressShutdown ( ) ;
#endif	
		}
		break ;

		default : {

		}
		break ;
    }
    return ( bRet ) ;
}



LONG __stdcall BlackBoxCrashHandlerFilter ( EXCEPTION_POINTERS * pExPtrs )
{
	ShowBlackBoxUI( pExPtrs, g_hInst );
	
	return EXCEPTION_EXECUTE_HANDLER;
}

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 BSD License


Written By
Software Developer (Senior)
United States United States
Currently working on the Visual Component Framework, a really cool C++ framework. Currently the VCF has millions upon millions upon billions of Users. If I make anymore money from it I'll have to buy my own country.

Comments and Discussions