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
3.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Microsoft WMIOLE DB Provider
  4. // (C) Copyright 1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // UTIL.h - HEader file for utility functions
  7. //
  8. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #ifndef _UTIL_HEADER
  10. #define _UTIL_HEADER
  11. class CWbemConnectionWrapper;
  12. #define SAFE_DELETE_PTR(pv) \
  13. { if(pv) delete pv; \
  14. pv = NULL; }
  15. #define SAFE_RELEASE_PTR(pv) \
  16. { if(pv){ pv->Release(); } \
  17. pv = NULL; }
  18. #define SAFE_DELETE_ARRAY(pv) \
  19. { if(pv) delete []pv; \
  20. pv = NULL; }
  21. #define SAFE_FREE_SYSSTRING(pv) \
  22. { if(pv){ SysFreeString(pv);} \
  23. pv = NULL; }
  24. #define TRY_BLOCK try {
  25. #define CATCH_BLOCK_HRESULT(hr , str) } \
  26. catch(CStructured_Exception e_SE) \
  27. { \
  28. hr = E_UNEXPECTED; \
  29. FormatAndLogMessage(L"%s: HEAP_EXCEPTION",str); \
  30. } \
  31. catch(CHeap_Exception e_HE) \
  32. { \
  33. FormatAndLogMessage(L"%s: STRUCTURED_EXCEPTION",str); \
  34. hr = E_OUTOFMEMORY; \
  35. } \
  36. catch(...) \
  37. { \
  38. FormatAndLogMessage(L"%s: UNSPECIFIED_EXCEPTION",str); \
  39. hr = E_UNEXPECTED; \
  40. }
  41. #define CATCH_BLOCK_BOOL(bVal,str) } \
  42. catch(CStructured_Exception e_SE) \
  43. { \
  44. bVal = FALSE; \
  45. FormatAndLogMessage(L"%s: HEAP_EXCEPTION",str); \
  46. } \
  47. catch(CHeap_Exception e_HE) \
  48. { \
  49. FormatAndLogMessage(L"%s: STRUCTURED_EXCEPTION",str); \
  50. bVal = FALSE; \
  51. } \
  52. catch(...) \
  53. { \
  54. FormatAndLogMessage(L"%s: UNSPECIFIED_EXCEPTION",str); \
  55. bVal = FALSE; \
  56. }
  57. BOOL UnicodeToAnsi(WCHAR * pszW, char *& pAnsi);
  58. void AllocateAndConvertAnsiToUnicode(char * pstr, WCHAR *& pszW);
  59. void TranslateAndLog( WCHAR * wcsMsg );
  60. void LogMessage( char * szMsg );
  61. void LogMessage( char * szMsg , HRESULT hr);
  62. void LogMessage( WCHAR * szMsg );
  63. void LogMessage( WCHAR * szMsg , HRESULT hr);
  64. BOOL OnUnicodeSystem();
  65. void FormatAndLogMessage( LPCWSTR pszFormatString,... );
  66. BSTR Wmioledb_SysAllocString(const OLECHAR * sz);
  67. void GetInitAndBindFlagsFromBindFlags(DBBINDURLFLAG dwBindURLFlags,LONG & lInitMode ,LONG & lInitBindFlags);
  68. int WMIOledb_LoadStringW(UINT nID, LPWSTR lpszBuf, UINT nMaxBuf);
  69. int wbem_wcsicmp(const wchar_t* wsz1, const wchar_t* wsz2);
  70. int wbem_wcsincmp(const wchar_t* wsz1, const wchar_t* wsz2,int nChars);
  71. DWORD GetImpLevel(DWORD dwImpPropVal);
  72. DWORD GetAuthnLevel(DWORD dwAuthnPropVal);
  73. HRESULT InitializeConnectionProperties(CWbemConnectionWrapper *pConWrap,DBPROPSET* prgPropertySets,BSTR strPath);
  74. HRESULT GetClassName(CURLParser *pUrlParser,DBPROPSET* prgPropertySets,BSTR &strClassName,CWbemConnectionWrapper *pConWrapper = NULL);
  75. DBTYPE GetVBCompatibleAutomationType(DBTYPE dbInType);
  76. class CTString
  77. {
  78. TCHAR * m_pStr;
  79. public:
  80. CTString();
  81. ~CTString();
  82. HRESULT LoadStr(UINT lStrID);
  83. operator LPTSTR() { return m_pStr; }
  84. // operator LPCTSTR() { return (LPCTSTR)m_pStr; }
  85. };
  86. typedef enum FetchDir
  87. {
  88. FETCHDIRNONE = -1,
  89. FETCHDIRFORWARD,
  90. FETCHDIRBACKWARD,
  91. } FETCHDIRECTION;
  92. #endif