MTVERIFY.H 982 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma comment( lib, "USER32" )
  2. #include <crtdbg.h>
  3. #define MTASSERT(a) _ASSERTE(a)
  4. #define MTVERIFY(a) if (!(a)) PrintError(L#a, __FUNCTIONW__, __LINE__, GetLastError())
  5. __inline void PrintError(LPWSTR linedesc, LPWSTR filename, int lineno, DWORD errnum)
  6. {
  7. LPWSTR lpBuffer;
  8. WCHAR errbuf[256];
  9. #ifdef _WINDOWS
  10. WCHAR modulename[MAX_PATH];
  11. #else // _WINDOWS
  12. DWORD numread;
  13. #endif // _WINDOWS
  14. FormatMessage(
  15. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  16. NULL,
  17. errnum,
  18. LANG_NEUTRAL,
  19. (LPTSTR)&lpBuffer,
  20. 0,
  21. NULL );
  22. swprintf_s(errbuf, L"\nThe following call failed at line %d in %s:\n\n\t%s\n\nReason: %s\n",
  23. lineno, filename, linedesc, lpBuffer);
  24. #ifndef _WINDOWS
  25. WriteFile(GetStdHandle(STD_ERROR_HANDLE), errbuf, _tcslen(errbuf), &numread, FALSE );
  26. Sleep(3000);
  27. #else
  28. GetModuleFileNameW(NULL, modulename, MAX_PATH);
  29. MessageBoxW(NULL, errbuf, modulename, MB_ICONWARNING|MB_OK|MB_TASKMODAL|MB_SETFOREGROUND);
  30. #endif
  31. exit(EXIT_FAILURE);
  32. }