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.

91 lines
1.6 KiB

  1. // Copyright (c) 2000 Microsoft Corp.
  2. //
  3. // random other stuff
  4. #ifndef MISC_HPP_INCLUDED
  5. #define MISC_HPP_INCLUDED
  6. void
  7. logMessage(const wchar_t* msg)
  8. {
  9. if (msg)
  10. {
  11. ::OutputDebugString(L"dhcpwiz: ");
  12. ::OutputDebugString(msg);
  13. ::OutputDebugString(L"\n");
  14. }
  15. }
  16. void
  17. logHresult(HRESULT hr)
  18. {
  19. wchar_t buf[1024];
  20. wsprintf(buf, L"HRESULT = 0x%08X\n", (hr));
  21. logMessage(buf);
  22. }
  23. #ifdef DBG
  24. #define LOG_HRESULT(hr) logHresult(hr)
  25. #define LOG_MESSAGE(msg) logMessage(msg)
  26. #else
  27. #define LOG_HRESULT(hr)
  28. #define LOG_MESSAGE(msg)
  29. #endif DBG
  30. #define BREAK_ON_FAILED_HRESULT(hr,msg) \
  31. if (FAILED(hr)) \
  32. { \
  33. LOG_MESSAGE(msg); \
  34. LOG_HRESULT(hr); \
  35. break; \
  36. }
  37. // A BSTR wrapper that frees itself upon destruction.
  38. //
  39. // From Box, D. Essential COM. pp 80-81. Addison-Wesley. ISBN 0-201-63446-5
  40. class AutoBstr
  41. {
  42. public:
  43. explicit
  44. AutoBstr(const wchar_t* s)
  45. :
  46. bstr(::SysAllocString(s))
  47. {
  48. ASSERT(s);
  49. }
  50. ~AutoBstr()
  51. {
  52. ::SysFreeString(bstr);
  53. bstr = 0;
  54. }
  55. operator BSTR () const
  56. {
  57. return bstr;
  58. }
  59. private:
  60. BSTR bstr;
  61. };
  62. #endif // MISC_HPP_INCLUDED