#ifndef __CeDebug_h__
#define __CeDebug_h__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#define HANDLE_EXCEPTION(n) \
((GetExceptionCode() ==(n)) ? EXCEPTION_EXECUTE_HANDLER: EXCEPTION_CONTINUE_SEARCH)
// Define TRACE behavior
#ifndef _DEBUG
inline void CeTrace(LPCTSTR, ...) { }
inline void CeAssert(BOOL, LPCTSTR) { }
# define TRACE 1 ? (void)0 : ::CeTrace
# define TRACE0(sz)
# define TRACE1(sz, p1)
# define TRACE2(sz, p1, p2)
# define TRACE3(sz, p1, p2, p3)
# define ISVALIDPTR(p, sz)
#else
void CeTrace(LPCTSTR lpszFormat, ...);
void CeAssert(BOOL bExp, LPCTSTR lpszFormat);
# define TRACE ::CeTrace
# define TRACE0(sz) ::CeTrace(_T("%s"), _T(sz))
# define TRACE1(sz, p1) ::CeTrace(sz, p1)
# define TRACE2(sz, p1, p2) ::CeTrace(sz, p1, p2)
# define TRACE3(sz, p1, p2, p3) ::CeTrace(sz, p1, p2, p3)
# define ISVALIDPTR(p, sz) (p != NULL && !IsBadReadPtr((void*)p, sz) && !IsBadWritePtr((void*)p, sz))
#endif
//#ifdef _DEBUG
# define TRAP(_stmt) \
__try { _stmt; } \
__except (EXCEPTION_EXECUTE_HANDLER) \
{ \
::MessageBox(NULL, L#_stmt, _T("Exception trapped"), MB_OK | MB_ICONSTOP); \
}
//#else
//# define TRAP(_stmt) _stmt
//#endif
// Define ASSERT behavior
#if defined(_DEBUG) && defined(_WIN32_WCE)
# ifdef UNICODE
# define CHW_ASSERT(_exp) ::CeAssert(BOOL(_exp), L"Assert Failed: " L#_exp)
# else
# define CHW_ASSERT(_exp) ::CeAssert(BOOL(_exp), "Assert Failed: " #_exp)
# endif
#elif defined(_DEBUG)
# include <crtdbg.h>
# define CHW_ASSERT(exp) _ASSERTE(exp)
#else
# define CHW_ASSERT(exp)
#endif
#undef ASSERT
#ifndef ASSERT
# define ASSERT(exp) CHW_ASSERT(exp)
#endif
#undef ASSERT_VALID
#ifndef ASSERT_VALID
# define ASSERT_VALID(p) ISVALIDPTR(p, sizeof *p)
#endif
#undef _ASSERTE
#ifndef _ASSERTE
# define _ASSERTE(exp) CHW_ASSERT(exp)
#endif
#undef VERIFY
#ifndef VERIFY
# ifdef _DEBUG
# define VERIFY(exp) ASSERT(exp)
# else
# define VERIFY(exp) ((void)(exp))
# endif
#endif
#endif __CeDebug_h__