Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.4 KiB

  1. /*
  2. Copyright 1999 Microsoft Corporation
  3. Common coding utilities
  4. Walter Smith (wsmith)
  5. */
  6. #pragma once
  7. #ifdef DBG
  8. #define _DEBUG 1
  9. #endif
  10. #include <crtdbg.h>
  11. #ifdef _DEBUG
  12. #define _CONFIRM(exp) _ASSERT(exp)
  13. #else
  14. #define _CONFIRM(exp) (exp)
  15. #endif
  16. #define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
  17. #define ASSERT_WRITE_PTR(p) _ASSERT(!IsBadWritePtr((p), sizeof(*(p))))
  18. #define ASSERT_READ_PTR(p) _ASSERT(!IsBadReadPtr((p), sizeof(*(p))))
  19. typedef std::basic_string<TCHAR> tstring;
  20. // REVIEW: Make this out of line?
  21. inline void ThrowLastError() {
  22. DWORD err = GetLastError();
  23. if (err == 0)
  24. throw E_FAIL;
  25. else
  26. throw HRESULT_FROM_WIN32(GetLastError());
  27. }
  28. inline void ThrowIfFail(HRESULT hr) {
  29. if (FAILED(hr))
  30. throw hr;
  31. }
  32. inline void ThrowIfNull(const void* pv) {
  33. if (pv == NULL)
  34. throw E_POINTER;
  35. }
  36. inline void ThrowIfNullHandle(HANDLE h) {
  37. if (h == NULL)
  38. ThrowLastError();
  39. }
  40. inline void ThrowIfZero(int i) {
  41. if (i == 0)
  42. ThrowLastError();
  43. }
  44. inline void ThrowIfTrue(bool b) {
  45. if (b)
  46. ThrowLastError();
  47. }
  48. inline void ThrowIfFalse(bool b) {
  49. ThrowIfTrue(!b);
  50. }
  51. inline void ThrowIfW32Fail(LONG l) {
  52. if (l != ERROR_SUCCESS)
  53. ThrowLastError();
  54. }
  55. inline void ThrowIfW32Error(LONG l) {
  56. if (l != ERROR_SUCCESS)
  57. throw HRESULT_FROM_WIN32(l);
  58. }