errCheck.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "Win32.h"
  2. #include "ID.h"
  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)
  15. {
  16. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  17. return 1;
  18. }
  19. return 0;
  20. }
  21. int Err(ATOM atom, LPCTSTR message)
  22. {
  23. if (!atom)
  24. {
  25. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  26. return 1;
  27. }
  28. return 0;
  29. }
  30. int Err(LPCTSTR message)
  31. {
  32. if (GetLastError() != 0)
  33. {
  34. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  35. return 1;
  36. }
  37. return 0;
  38. }
  39. void ForceErrCheck(LPCTSTR title)
  40. {
  41. MessageBox(NULL, GetError(), title, MB_ICONWARNING);
  42. }
  43. int Err(std::ifstream* file, LPCTSTR message)
  44. {
  45. if (!file)
  46. {
  47. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  48. return 1;
  49. }
  50. return 0;
  51. }
  52. int Err(std::fstream* file, LPCTSTR message)
  53. {
  54. if (!file)
  55. {
  56. MessageBox(NULL, message, GetError(), MB_ICONERROR);
  57. return 1;
  58. }
  59. return 0;
  60. }