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.

118 lines
5.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: K K U T I L S . H
  7. //
  8. // Contents: Misc. helper functions
  9. //
  10. // Notes:
  11. //
  12. // Author: kumarp 14 Jan 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #pragma once
  16. #include "kkstl.h"
  17. #ifndef NCAPI
  18. #define NCAPI extern "C" HRESULT __declspec(dllexport)
  19. #endif
  20. #ifdef ENABLETRACE
  21. #define DefineFunctionName(name) static char __FUNCNAME__[] = name
  22. #else
  23. #define DefineFunctionName(name) (void) 0
  24. #define __FUNCNAME__ ""
  25. #endif
  26. #define DeleteIfNotNull(p) \
  27. delete p; \
  28. p = NULL;
  29. #define ReturnHrIfFailedSz(hr,msg) if (FAILED(hr)) \
  30. { \
  31. TraceError(msg, hr); \
  32. return hr; \
  33. }
  34. #define ReturnHrIfFailed(hr) if (FAILED(hr)) \
  35. { \
  36. TraceError(__FUNCNAME__, hr); \
  37. return hr; \
  38. }
  39. #define ReturnErrorIf(condition,hr) if (condition) \
  40. { \
  41. TraceError(__FUNCNAME__, hr); \
  42. return hr; \
  43. }
  44. #define ReturnError(hr) if (1) { TraceFunctionError(hr); return hr; }
  45. #define DoErrorCleanupAndReturnError(status_var,error_code) \
  46. { \
  47. status_var = error_code; \
  48. goto error_cleanup; \
  49. }
  50. #define DoErrorCleanupAndReturnErrorIf(condition,status_var,error_code) \
  51. if (condition) \
  52. { \
  53. status_var = error_code; \
  54. goto error_cleanup; \
  55. }
  56. #define TraceFunctionEntry(ttid) TraceTag(ttid, "---------> entering %s", __FUNCNAME__)
  57. #define TraceFunctionError(hr) TraceError(__FUNCNAME__, hr)
  58. #define TraceLastWin32ErrorInCurrentFunction() TraceLastWin32Error(__FUNCNAME__)
  59. #define TraceWin32FunctionError(e) TraceFunctionError(HRESULT_FROM_WIN32(e))
  60. #define ReturnNULLIf(condition) if (condition) return NULL
  61. #define BreakIf(condition) if (condition) break
  62. #define ContinueIf(condition) if (condition) continue
  63. //#define ReturnFalseIfFailed(hr) if ((hr) != S_OK) return FALSE
  64. #define DoErrorCleanupIf(condition) if (condition) goto error_cleanup
  65. #define AppendErrorAndReturnFalseIf(condition,e) if (condition) { AppendError(e); return FALSE;}
  66. #define BenignAssert() AssertSz(FALSE,"Benign Assert (this is not a bug): Click Ignore to continue...")
  67. #define CR L"\n"
  68. void AddOnlyOnceToStringList(IN TStringList* psl, IN PCWSTR pszString);
  69. void ConvertDelimitedListToStringList(IN const tstring& strDelimitedList,
  70. IN WCHAR chDelimiter,
  71. OUT TStringList &slList);
  72. void ConvertCommaDelimitedListToStringList(IN const tstring& strDelimitedList,
  73. OUT TStringList &slList);
  74. void ConvertSpaceDelimitedListToStringList(IN const tstring& strDelimitedList,
  75. OUT TStringList &slList);
  76. void ConvertStringListToCommaList(IN const TStringList &slList,
  77. OUT tstring &strList);
  78. void ConvertStringListToDelimitedList(IN const TStringList &slList,
  79. OUT tstring &strList, IN WCHAR chDelimiter);
  80. BOOL IsBoolString(IN PCWSTR pszStr, OUT BOOL *pbValue);
  81. BOOL UpgradingFromNT(IN DWORD dwUpgradeFlag);
  82. BOOL FIsInStringArray(
  83. IN const PCWSTR* ppszStrings,
  84. IN DWORD cNumStrings,
  85. IN PCWSTR pszStringToFind,
  86. OUT UINT* puIndex=NULL);
  87. HRESULT HrRegOpenServiceKey(IN PCWSTR pszServiceName,
  88. REGSAM samDesired,
  89. OUT HKEY* phKey);
  90. HRESULT HrRegOpenServiceSubKey(IN PCWSTR pszServiceName,
  91. IN PCWSTR pszSubKey,
  92. REGSAM samDesired,
  93. OUT HKEY* phKey);
  94. BOOL FIsServiceKeyPresent(IN PCWSTR pszServiceName);
  95. void AppendToPath(IN OUT tstring* pstrPath, IN PCWSTR pszItem);
  96. void EraseAndDeleteAll(IN TStringArray* sa);
  97. void ConvertDelimitedListToStringArray(IN const tstring& strDelimitedList,
  98. IN WCHAR chDelimiter,
  99. OUT TStringArray &saStrings);
  100. void ConvertCommaDelimitedListToStringArray(IN const tstring& strDelimitedList,
  101. OUT TStringArray &saStrings);