Leaked source code of windows server 2003
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.

106 lines
2.6 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // core utility functions
  4. //
  5. // 30 Nov 1999 sburns
  6. #ifndef COREUTIL_HPP_INCLUDED
  7. #define COREUTIL_HPP_INCLUDED
  8. #define BREAK_ON_FAILED_HRESULT(hr) \
  9. if (FAILED(hr)) \
  10. { \
  11. LOG_HRESULT(hr); \
  12. break; \
  13. }
  14. #define BREAK_ON_FAILED_HRESULT2(hr,msg) \
  15. if (FAILED(hr)) \
  16. { \
  17. LOG(msg) \
  18. LOG_HRESULT(hr); \
  19. break; \
  20. }
  21. namespace Burnslib
  22. {
  23. // Loads various message dlls in an an attempt to resolve the HRESULT into
  24. // an error message. Returns a "unknown error" string on failure.
  25. String
  26. GetErrorMessage(HRESULT hr);
  27. // Returns the HINSTANCE of the DLL designated to contain all resources.
  28. //
  29. // This function requires that the first module loaded (whether it be a DLL or
  30. // EXE) set the global variable hResourceModuleHandle to the HINSTANCE of the
  31. // module (DLL or EXE) that contains all of the program's binary resources.
  32. // This should be done as early as possible in the module's startup code.
  33. HINSTANCE
  34. GetResourceModuleHandle();
  35. // a safe version of HRESULT_FROM_WIN32 that doesn't repeatedly evaluate
  36. // it's arguement. The problem with using the macro directly is that the
  37. // argument -- the win32 error to convert -- will be evaluated more than
  38. // once. So, if you use an expression as the argument, at best you get
  39. // an inefficiency, at worst you get unexpected side effects.
  40. inline
  41. HRESULT
  42. Win32ToHresult(DWORD win32Error)
  43. {
  44. ASSERT(win32Error < 0xFFFF);
  45. // If win32Error is really an HRESULT, then this will preserve that
  46. // HRESULT, rather than whack off the error code part and change the
  47. // facility code. See winerror.h
  48. return HRESULT_FROM_WIN32(win32Error);
  49. }
  50. // unsigned version
  51. inline
  52. HRESULT
  53. Win32ToHresult(LONG win32Error)
  54. {
  55. ASSERT(win32Error < 0xFFFF);
  56. return HRESULT_FROM_WIN32(win32Error);
  57. }
  58. inline
  59. HRESULT
  60. NtStatusToHRESULT(NTSTATUS status)
  61. {
  62. return Win32ToHresult(::RtlNtStatusToDosError(status));
  63. }
  64. } // namespace Burnslib
  65. #endif // COREUTIL_HPP_INCLUDED