#ifdef _DEBUG

#define AssertDebugBreak() _asm { int 3 }

inline BOOL AssertDialog(const char* pcszExpr, const char* pcszfile, int nLine)
{
    char szBuf[MAX_PATH * 2];

    sprintf(szBuf, "ASSERT!!! in \"%s\" at line %d\n\nDo you want to debug?", pcszfile, nLine);

#ifdef WIN32
    return ::MessageBox(NULL, szBuf, pcszExpr, MB_YESNO) == IDYES;
#else // !WIN32
    return FALSE;
#endif // WIN32
}

inline BOOL __cdecl AssertReturnFALSE()
{
    return FALSE;
}

#ifndef ASSERT
#define ASSERT(x) { if (!(x)) AssertDialog(#x, THIS_FILE, __LINE__); }
#endif
#define ASSERT_FALSE() ASSERT(AssertReturnFALSE())

#ifndef VERIFY
#define VERIFY(x) { if (!(x)) AssertDialog(#x, THIS_FILE, __LINE__); }
#endif

#ifndef TRACE
inline int __DbgTrace(const char* pcszFormat, ...)
{
	va_list ap;
	va_start(ap, pcszFormat);
	char caBuffer[1024];
	vsprintf(caBuffer, pcszFormat, ap);
	va_end(ap);
	::OutputDebugString(caBuffer);

    return 0;
}

#define TRACE __DbgTrace
#endif

#ifndef THIS_FILE
#define THIS_FILE          __FILE__
#endif // !THIS_FILE
#ifndef BASED_CODE
	#define BASED_CODE
#endif // !BASED_CODE

#ifdef malloc
#undef malloc
#undef calloc
#undef realloc
#undef _expand
#undef free
#undef _msize
#endif

#define malloc(s)         _malloc_dbg(s, _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define calloc(c, s)      _calloc_dbg(c, s, _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define realloc(p, s)     _realloc_dbg(p, s, _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define _expand(p, s)     _expand_dbg(p, s, _NORMAL_BLOCK, THIS_FILE, __LINE__)
#define free(p)           _free_dbg(p, _NORMAL_BLOCK)
#define _msize(p)         _msize_dbg(p, _NORMAL_BLOCK)

//----------------------------------------------------------------------------------------------------------
inline void* __cdecl operator new(size_t nSize, LPCSTR lpszFileName, int nLine)
{
	void* p = _malloc_dbg(nSize, _NORMAL_BLOCK, lpszFileName, nLine);
	return p;
}

inline void __cdecl operator delete(void* p, LPCSTR lpszFileName, int nLine)
{
    _free_dbg(p, _NORMAL_BLOCK);
}
//----------------------------------------------------------------------------------------------------------

#ifndef _AFX
#define DEBUG_NEW		new		//(THIS_FILE, __LINE__)
#define DEBUG_DELETE	delete	//(THIS_FILE, __LINE__)
#endif

#else // !_DEBUG

#define ASSERTDLG_PUSH(hWnd)
#define ASSERTDLG_POP()

#ifndef ASSERT
#define ASSERT(x)
#endif
#define ASSERT_FALSE()

#ifndef VERIFY
#define VERIFY(x)	x
#endif
#ifndef TRACE
inline int __DbgTraceIgnore(const char* pcszFormat, ...) { &pcszFormat; return 0; }
#define TRACE 1 ? 0: __DbgTraceIgnore
#endif

#endif // _DEBUG

