Added a parameter to semaphore constructor to avoid ambiguity
[pwlib.git] / tools / MsDevWizard / Debug.cpp
bloba3484cbc4c7adc444877d10889cb9258d706ce2a
1 #include "stdafx.h"
3 #ifdef _PSEUDO_DEBUG // entire file
5 #ifdef _PSEUDO_DEBUG
6 #undef THIS_FILE
7 static char THIS_FILE[] = __FILE__;
8 #endif
10 LONG AssertBusy = -1;
11 LONG AssertReallyBusy = -1;
13 BOOL AssertFailedLine(LPCSTR lpszFileName, int nLine)
15 TCHAR szMessage[_MAX_PATH*2];
17 InterlockedDecrement(&AssertReallyBusy);
19 // format message into buffer
20 wsprintf(szMessage, _T("File %hs, Line %d"),
21 lpszFileName, nLine);
23 TCHAR szT[_MAX_PATH*2 + 20];
24 wsprintf(szT, _T("Assertion Failed: %s\n"), szMessage);
25 OutputDebugString(szT);
27 if (InterlockedIncrement(&AssertBusy) > 0)
29 InterlockedDecrement(&AssertBusy);
31 // assert within assert (examine call stack to determine first one)
32 DebugBreak();
33 return FALSE;
36 // active popup window for the current thread
37 HWND hWndParent = GetActiveWindow();
38 if (hWndParent != NULL)
39 hWndParent = GetLastActivePopup(hWndParent);
41 // display the assert
42 int nCode = ::MessageBox(hWndParent, szMessage, _T("Assertion Failed!"),
43 MB_TASKMODAL|MB_ICONHAND|MB_ABORTRETRYIGNORE|MB_SETFOREGROUND);
45 // cleanup
46 InterlockedDecrement(&AssertBusy);
48 if (nCode == IDIGNORE)
49 return FALSE; // ignore
51 if (nCode == IDRETRY)
52 return TRUE; // will cause DebugBreak
54 AfxAbort(); // should not return (but otherwise DebugBreak)
55 return TRUE;
58 void Trace(LPCTSTR lpszFormat, ...)
60 va_list args;
61 va_start(args, lpszFormat);
63 int nBuf;
64 TCHAR szBuffer[512];
66 nBuf = _vstprintf(szBuffer, lpszFormat, args);
67 ASSERT(nBuf < (sizeof(szBuffer)/sizeof(szBuffer[0])));
69 CString strMessage;
71 if (AfxGetApp() != NULL)
72 strMessage = ((CString) (AfxGetApp()->m_pszExeName)) + _T(": ");
73 strMessage += szBuffer;
74 OutputDebugString(strMessage);
76 va_end(args);
80 #endif // _PSEUDO_DEBUG