errCheck.cpp 1.2 KB

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