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.

110 lines
4.1 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Defines
  3. //
  4. // � 2000 Microsoft Corporation. All rights reserved
  5. //
  6. #pragma once
  7. #include <logging.h> // for CleanUpXxxx that use logging
  8. #include <tchar.h>
  9. //
  10. // 481561 IU: iucommon.h should use safefunc.h instead of redefining SafeRelease()
  11. // Actually, we were first :-), but will correct conflicts in the control code rather than AU.
  12. //
  13. // NOTE: since these headers came from different teams, the same defines may have different
  14. // behavior. For instance SafeRelease() in iucommon.h NULLs the pointer after release, but
  15. // not in safefunc.h. Appropriate adjustments made in the .cpp files.
  16. #include <safefunc.h>
  17. const TCHAR IDENTTXT[] = _T("iuident.txt");
  18. const CHAR SZ_SEE_IUHIST[] = "See iuhist.xml for details:";
  19. /**
  20. * constant for GetManifest()
  21. */
  22. const DWORD FLAG_USE_COMPRESSION = 0x00000001;
  23. /**
  24. * constnat for GetManifest(), Detect(), GetSystemSpec(), GetHistory()
  25. */
  26. const DWORD FLAG_OFFLINE_MODE = 0x00000002;
  27. //
  28. // MAX_SETUP_MULTI_SZ_SIZE is used to make sure SetupDiGetDeviceRegistryProperty
  29. // doesn't return an unreasonably large buffer (it has been hacked).
  30. //
  31. // Assumptions:
  32. // * Multi-SZ strings will have a max of 100 strings (should be on order of 10 or less)
  33. // * Each string will be <= MAX_INF_STRING
  34. // * Don't bother accounting for NULLs (that will be swampped by overestimate on number of strings)
  35. //
  36. #define MAX_INF_STRING_LEN 512 // From DDK docs "General Syntax Rules for INF Files" section
  37. #define MAX_SETUP_MULTI_SZ_SIZE (MAX_INF_STRING_LEN * 100 * sizeof(TCHAR))
  38. #define MAX_SETUP_MULTI_SZ_SIZE_W (MAX_INF_STRING_LEN * 100 * sizeof(WCHAR)) // For explicit WCHAR version
  39. //
  40. // the following are the customized error HRESULT
  41. //
  42. // IU selfupdate error codes
  43. #define IU_SELFUPDATE_NONEREQUIRED _HRESULT_TYPEDEF_(0x00040000L)
  44. #define IU_SELFUPDATE_USECURRENTDLL _HRESULT_TYPEDEF_(0x00040001L)
  45. #define IU_SELFUPDATE_USENEWDLL _HRESULT_TYPEDEF_(0x00040002L)
  46. #define IU_SELFUPDATE_TIMEOUT _HRESULT_TYPEDEF_(0x80040010L)
  47. #define IU_SELFUPDATE_FAILED _HRESULT_TYPEDEF_(0x8004FFFFL)
  48. // UrlAgent error codes
  49. #define ERROR_IU_QUERYSERVER_NOT_FOUND _HRESULT_TYPEDEF_(0x80040012L)
  50. #define ERROR_IU_SELFUPDSERVER_NOT_FOUND _HRESULT_TYPEDEF_(0x80040022L)
  51. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  52. #define SafeCloseInvalidHandle(h) if (INVALID_HANDLE_VALUE != h) { CloseHandle(h); h = INVALID_HANDLE_VALUE; }
  53. //
  54. // Replace with SafeReleaseNULL in safefunc.h
  55. //
  56. // #define SafeRelease(p) if (NULL != p) { (p)->Release(); p = NULL; }
  57. #define SafeHeapFree(p) if (NULL != p) { HeapFree(GetProcessHeap(), 0, p); p = NULL; }
  58. //
  59. // NOTE: SysFreeString() takes NULLs (just returns) so we don't have to check for NULL != p
  60. //
  61. #define SafeSysFreeString(p) {SysFreeString(p); p = NULL;}
  62. //
  63. // Use this if the function being called does logging
  64. //
  65. #define CleanUpIfFailedAndSetHr(x) {hr = x; if (FAILED(hr)) goto CleanUp;}
  66. //
  67. // Use this if function being called does *not* do logging
  68. //
  69. #define CleanUpIfFailedAndSetHrMsg(x) {hr = x; if (FAILED(hr)) {LOG_ErrorMsg(hr); goto CleanUp;}}
  70. //
  71. // Use this if function being called does *not* do logging
  72. //
  73. #define CleanUpIfFalseAndSetHrMsg(b,x) {if (b) {hr = x; LOG_ErrorMsg(hr); goto CleanUp;}}
  74. //
  75. // Use this to log Win32 errors returned from call
  76. //
  77. #define Win32MsgSetHrGotoCleanup(x) {LOG_ErrorMsg(x); hr = HRESULT_FROM_WIN32(x); goto CleanUp;}
  78. //
  79. // Set hr = x and goto Cleanup (when you need to check HR before going to cleanup)
  80. //
  81. #define SetHrAndGotoCleanUp(x) {hr = x; goto CleanUp;}
  82. //
  83. // Use this to log an hr msg and goto CleanUp (don't reassign hr like Failed variation)
  84. //
  85. #define SetHrMsgAndGotoCleanUp(x) {hr = x; LOG_ErrorMsg(hr); goto CleanUp;}
  86. //
  87. // Use this to log HeapAlloc failures only using a single const string
  88. //
  89. #define CleanUpFailedAllocSetHrMsg(x) {if (NULL == (x)) {hr = E_OUTOFMEMORY; LOG_ErrorMsg(hr); goto CleanUp;}}
  90. //
  91. // Same as CleanUpIfFailedAndSetHrMsg(), but no set hr, instead, pass in hr
  92. //
  93. #define CleanUpIfFailedAndMsg(hr) {if (FAILED(hr)) {LOG_ErrorMsg(hr); goto CleanUp;}}