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.

211 lines
6.1 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. WBEMUTIL.CPP
  5. Abstract:
  6. General utility functions prototypes and macros.
  7. History:
  8. a-raymcc 17-Apr-96 Created.
  9. --*/
  10. #ifndef _WBEMUTIL_H_
  11. #define _WBEMUTIL_H_
  12. #include "corepol.h"
  13. #ifdef DBG
  14. #define _DBG_ASSERT(X) { if (!(X)) { DebugBreak(); } }
  15. #else
  16. #define _DBG_ASSERT(X)
  17. #endif
  18. #ifndef VARIANT_TRUE
  19. #define VARIANT_TRUE ((VARIANT_BOOL) 0xFFFF)
  20. #define VARIANT_FALSE (0)
  21. #endif
  22. #ifdef __cplusplus
  23. inline wchar_t *Macro_CloneLPWSTR(LPCWSTR src)
  24. {
  25. if (!src)
  26. return 0;
  27. wchar_t *dest = new wchar_t[wcslen(src) + 1];
  28. if (!dest)
  29. return 0;
  30. return wcscpy(dest, src);
  31. }
  32. #endif
  33. #if (defined DEBUG || defined _DEBUG)
  34. #pragma message("_ASSERTs are being expanded.")
  35. #define _ASSERT(exp, msg) \
  36. if (!(exp)) { \
  37. TCHAR buf[256]; \
  38. int nFlag; \
  39. OSVERSIONINFO info; \
  40. info.dwOSVersionInfoSize = sizeof(info); \
  41. GetVersionEx(&info); \
  42. if(info.dwPlatformId != VER_PLATFORM_WIN32_NT) nFlag = 0; \
  43. else if(info.dwMajorVersion < 4) nFlag = MB_SERVICE_NOTIFICATION_NT3X; \
  44. else nFlag = MB_SERVICE_NOTIFICATION; \
  45. wsprintf(buf, __TEXT("%s [%s:%d]"), msg, __FILE__, __LINE__); \
  46. MessageBox(0, buf, __TEXT("WBEM Critical Error"), \
  47. MB_OK | MB_ICONSTOP | MB_SYSTEMMODAL | nFlag); \
  48. }
  49. #else
  50. #define _ASSERT(exp, msg)
  51. #endif
  52. #ifdef DBG
  53. #define _DBG_MSG_ASSERT(X, msg) { if (!(X)) { OutputDebugStringW( msg ); DebugBreak(); } }
  54. #define _DBG_ASSERT(X) { if (!(X)) { DebugBreak(); } }
  55. #else
  56. #define _DBG_MSG_ASSERT(X, msg)
  57. #define _DBG_ASSERT(X)
  58. #endif
  59. //LOGGING module.
  60. //This is an index into an array in wbemutil.cpp which uses
  61. //the filenames specified next
  62. #define LOG_WBEMCORE 0
  63. #define LOG_WINMGMT 1
  64. #define LOG_ESS 2
  65. #define LOG_WBEMPROX 3
  66. #define LOG_WBEMSTUB 4
  67. #define LOG_QUERY 5
  68. #define LOG_MOFCOMP 6
  69. #define LOG_EVENTLOG 7
  70. #define LOG_WBEMDISP 8
  71. #define LOG_STDPROV 9
  72. #define LOG_WIMPROV 10
  73. #define LOG_WMIOLEDB 11
  74. #define LOG_WMIADAP 12
  75. #define LOG_REPDRV 13
  76. //These are the log file names (possibly other things
  77. //as well!) which is used in conjunction with the above
  78. //ids.
  79. #define FILENAME_PREFIX_CORE __TEXT("wbemcore")
  80. #define FILENAME_PREFIX_EXE __TEXT("WinMgmt")
  81. #define FILENAME_PREFIX_EXE_W L"WinMgmt"
  82. #define FILENAME_PREFIX_CLI_MARSH __TEXT("wbemprox")
  83. #define FILENAME_PREFIX_SERV_MARSH __TEXT("wbemstub")
  84. #define FILENAME_PREFIX_ESS __TEXT("wbemess")
  85. #define FILENAME_PREFIX_QUERY __TEXT("query")
  86. #define FILENAME_PROFIX_MOFCOMP __TEXT("mofcomp")
  87. #define FILENAME_PROFIX_EVENTLOG __TEXT("eventlog")
  88. #define FILENAME_PROFIX_WBEMDISP __TEXT("wbemdisp")
  89. #define FILENAME_PROFIX_STDPROV __TEXT("stdprov")
  90. #define FILENAME_PROFIX_WMIPROV __TEXT("wmiprov")
  91. #define FILENAME_PROFIX_WMIOLEDB __TEXT("wmioledb")
  92. #define FILENAME_PREFIX_WMIADAP __TEXT("wmiadap")
  93. #define FILENAME_PREFIX_REPDRV __TEXT("replog")
  94. // True if unicode identifier, _, a-z, A-Z or 0x100-0xffef
  95. BOOL POLARITY isunialpha(wchar_t c);
  96. BOOL POLARITY isunialphanum(wchar_t c);
  97. BOOL POLARITY IsValidElementName(LPCWSTR wszName);
  98. // Can't use overloading and/or default parameters because
  99. // "C" files use these guys. No, I'm not happy about
  100. // this!
  101. BOOL POLARITY IsValidElementName2(LPCWSTR wszName, BOOL bAllowUnderscore);
  102. BOOL POLARITY LoggingLevelEnabled(DWORD nLevel);
  103. int POLARITY ErrorTrace(char cCaller, const char *fmt, ...);
  104. #define TRACE(x) DebugTrace x
  105. #define ERRORTRACE(x) ErrorTrace x
  106. #define DEBUGTRACE(x) DebugTrace x
  107. int POLARITY DebugTrace(char cCaller, const char *fmt, ...);
  108. int POLARITY CriticalFailADAPTrace(const char *string);
  109. // BLOB manipulation.
  110. // ==================
  111. BLOB POLARITY BlobCopy(BLOB *pSrc);
  112. void POLARITY BlobClear(BLOB *pSrc);
  113. void POLARITY BlobAssign(BLOB *pSrc, LPVOID pBytes, DWORD dwCount, BOOL bAcquire);
  114. #define BlobInit(p) \
  115. ((p)->cbSize = 0, (p)->pBlobData = 0)
  116. #define BlobLength(p) ((p)->cbSize)
  117. #define BlobDataPtr(p) ((p)->pBlobData)
  118. // Object ref count helpers.
  119. // =========================
  120. void ObjectCreated(DWORD,IUnknown * pThis);
  121. void ObjectDestroyed(DWORD,IUnknown * pThis);
  122. #define MAX_OBJECT_TYPES 16
  123. #define OBJECT_TYPE_LOCATOR 0
  124. #define OBJECT_TYPE_CLSOBJ 1
  125. #define OBJECT_TYPE_PROVIDER 2
  126. #define OBJECT_TYPE_QUALIFIER 3
  127. #define OBJECT_TYPE_NOTIFY 4
  128. #define OBJECT_TYPE_OBJENUM 5
  129. #define OBJECT_TYPE_FACTORY 6
  130. #define OBJECT_TYPE_WBEMLOGIN 7
  131. #define OBJECT_TYPE_WBEMLOGINHELP 8
  132. #define OBJECT_TYPE_CORE_BUSY 9
  133. #define OBJECT_TYPE_STATUS 10
  134. #define OBJECT_TYPE_BACKUP_RESTORE 11
  135. #define OBJECT_TYPE_PATH_PARSER 12
  136. #define OBJECT_TYPE_WMIARRAY 13
  137. #define OBJECT_TYPE_OBJ_FACTORY 14
  138. #define OBJECT_TYPE_FREEFORM_OBJ 15
  139. //Creates directories recursively
  140. BOOL POLARITY WbemCreateDirectory(const TCHAR *szDirectory);
  141. #define VT_EMBEDDED_OBJECT VT_UNKNOWN
  142. #define V_EMBEDDED_OBJECT(VAR) V_UNKNOWN(VAR)
  143. #define I_EMBEDDED_OBJECT IUnknown
  144. #define IDISPATCH_METHODS_STUB \
  145. STDMETHOD(GetTypeInfoCount)(UINT* pctinfo) \
  146. {return E_NOTIMPL;} \
  147. STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)\
  148. {return E_NOTIMPL;} \
  149. STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR** rgszNames, UINT cNames,\
  150. LCID lcid, DISPID* rgdispid) \
  151. {return E_NOTIMPL;} \
  152. STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,\
  153. DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, \
  154. UINT* puArgErr) \
  155. {return E_NOTIMPL;} \
  156. // Quick WCHAR to MBS conversion helper
  157. BOOL POLARITY AllocWCHARToMBS( WCHAR* pWstr, char** ppStr );
  158. // Helpers needed in a couple of places.
  159. LPTSTR POLARITY GetWbemWorkDir( void );
  160. LPTSTR POLARITY GetWMIADAPCmdLine( int nExtra );
  161. // In Debug this does something, in release, it's
  162. // a noop. C files don't need it.
  163. #if defined(__cplusplus)
  164. inline void WbemDebugBreak( void )
  165. {
  166. DebugBreak();
  167. }
  168. #endif
  169. #endif
  170.