errCheck.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include "Win32.h"
  2. static bool errShow = FALSE;
  3. static LPWSTR GetError()
  4. {
  5. DWORD error = GetLastError();
  6. LPWSTR errorMsg = NULL;
  7. FormatMessage(
  8. FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  9. NULL, error, 0, (LPWSTR)&errorMsg, 256, NULL);
  10. return errorMsg;
  11. }
  12. int Err(HWND hwnd, LPCTSTR message)
  13. {
  14. if ((!hwnd) && !errShow)
  15. {
  16. errShow = TRUE;
  17. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  18. errShow = FALSE;
  19. return 1;
  20. }
  21. return 0;
  22. }
  23. int Err(ATOM atom, LPCTSTR message)
  24. {
  25. if ((!atom) && !errShow)
  26. {
  27. errShow = TRUE;
  28. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  29. errShow = FALSE;
  30. return 1;
  31. }
  32. return 0;
  33. }
  34. int Err(LPCTSTR message)
  35. {
  36. if ((GetLastError() != 0) && !errShow)
  37. {
  38. errShow = TRUE;
  39. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  40. errShow = FALSE;
  41. return 1;
  42. }
  43. return 0;
  44. }
  45. void ForceErrCheck(LPCTSTR title)
  46. {
  47. MessageBox(NULL, GetError(), title, MB_ICONWARNING);
  48. }
  49. int Err(std::ifstream* file, LPCTSTR message)
  50. {
  51. if ((!file) && !errShow)
  52. {
  53. errShow = TRUE;
  54. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  55. errShow = FALSE;
  56. return 1;
  57. }
  58. return 0;
  59. }
  60. int Err(std::ofstream* file, LPCTSTR message)
  61. {
  62. if ((!file) && !errShow)
  63. {
  64. errShow = TRUE;
  65. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  66. errShow = FALSE;
  67. return 1;
  68. }
  69. return 0;
  70. }