//--------------------------------------------------------------------
// Microsoft OLE DB Sample Provider
// (C) Copyright 1994 - 1996 Microsoft Corporation. All Rights Reserved.
//
// @doc
//
// @module ASSERTS.CPP | Simple Assertion Routines
//
//
#include "headers.h"
#include <time.h>
#include "asserts.h"
#ifdef DEBUG // only compile for debug!
//--------------------------------------------------------------------
// @func Variable argument formatter and Dump routine for messages
//
// @rdesc NONE
//
void OLEDB_Trace
(
const char *format, //@parm IN | Format String
... //@parm IN | Variable Arg List
)
{
char buff[300 ];
int cBytesWritten;
va_list argptr;
// If this overflows, it will wipe out the return stack.
// However, we have a wonderful version that ensures no overwrite.
// Nice because we can't do anything about errors here.
va_start( argptr, format );
cBytesWritten = _vsnprintf( buff, sizeof( buff ), format, argptr );
va_end( argptr );
// assert would report overflow first, recursively, but don't bother.
// Would be OK, since this assert could be proven
// not to overflow temp buffer in assert.
//assert( cBytesWritten < sizeof(buff) );
OutputDebugString( buff );
}
//--------------------------------------------------------------------
// @func This an internal assertion routine that dumps more information
// than the normal assertion routines..
//
// @rdesc NONE
//
void OLEDB_Assert
(
LPSTR expression, //@parm IN | Expression to assert on
LPSTR filename, //@parm IN | Filname where assertion occurred
long linenum //@parm IN | Line number where assertion occurred
)
{
char szbuff[350 ];
int cBytesWritten;
volatile int fAbort;
// If this overflows, it will wipe out the return stack.
// However, we have a wonderful version that ensures no overwrite.
// Good thing, because we can't do much about overflows here anyway.
// (However, use of "%.nns" works well.)
cBytesWritten = _snprintf( szbuff, sizeof( szbuff ),
"Assertion error!\n File '%.50s', line '%ld'\n Expression '%.200s'\n",
filename, linenum, expression );
TRACE( szbuff );
// We're a DLL (therefore Windows), so may not have an output stream we can write to.
::MessageBox(
NULL, // HWND, which we don't have
szbuff, // Text
"Assertion Error", // Title
MB_SYSTEMMODAL | MB_ICONHAND | MB_OK );
// Break and let the user get a crack at it.
// You can set fAbort=0 to continue merrily along.
fAbort = 1;
if (fAbort)
{
abort(); // Raises SIGABRT
}
}
#endif