Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

AxPipeAssert.cpp

Go to the documentation of this file.
00001 
00030 #include "StdAfx.h"
00031 #include <Shlwapi.h>
00032 #include "AxPipeAssert.h"
00033 
00036 #pragma warning(disable:4172)
00037 const _TCHAR *
00038 AxPipe::Assert::LastErrorMsg() {
00039     // Since this is only intended to be called for fatal failed asserts, including
00040     // memory allocation, we preallocate a fixed size buffer here.
00041     static _TCHAR szMsg[300];
00042 
00043     (void)lstrcpy(szMsg, _T("Invalid GetLastError()"));
00044     if (FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_FROM_SYSTEM,
00045         NULL, GetLastError(), 0, szMsg, sizeof szMsg / sizeof szMsg[0], NULL) == 0) {
00046             return _T("FormatMessage()/GetLastError() failed.");
00047     }
00048     return szMsg;
00049 };
00050 #pragma warning(default:4172)
00051 
00057 void
00058 AxPipe::Assert::AssFunc(bool fOk, const _TCHAR *sz, const _TCHAR *szFile, int iLine) {
00059     if (!fOk) {
00060         MessageBoxF(NULL, _T("Failed assertion in %s at line %d\n\n%s"), _T("AxPipe"),  MB_OK|MB_ICONSTOP, PathFindFileName(szFile), iLine, sz);
00061         exit(1);
00062     }
00063 }
00064 
00070 void
00071 AxPipe::Assert::MessageBoxF(HWND hWnd, const _TCHAR *szFmt, const _TCHAR *szCaption, UINT uType, ...) {
00072     va_list vaArgs;
00073     va_start(vaArgs, uType);
00074 
00075     // wvsprintf guarantees not to write more than 1024 chars
00076     static _TCHAR szBuf[1024];
00077     wvsprintf(szBuf, szFmt, vaArgs);
00078     va_end(vaArgs);
00079     MessageBox(hWnd, szBuf, szCaption, uType);
00080 }
00081 
00082 #ifdef _DEBUG
00086 void
00087 AxPipe::Assert::OutputDebugStringF(const _TCHAR *szFmt, ...) {
00088     va_list vaArgs;
00089     va_start(vaArgs, szFmt);
00090 
00091     // wvsprintf guarantees not to write more than 1024 chars
00092     static _TCHAR szBuf[1024];
00093     wvsprintf(szBuf, szFmt, vaArgs);
00094     va_end(vaArgs);
00095     OutputDebugString(szBuf);
00096 }
00097 #endif

Generated on Mon Feb 2 13:19:18 2004 for AxPipe by doxygen 1.3.5