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.

165 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. oleutil.h
  5. Abstract:
  6. Defines some useful functions for dealing with OLE.
  7. Author:
  8. Magnus Hedlund (MagnusH) --
  9. Revision History:
  10. --*/
  11. #ifndef _OLEUTIL_INCLUDED_
  12. #define _OLEUTIL_INCLUDED_
  13. // Dependencies:
  14. class CMultiSz;
  15. // Common Property Operations:
  16. HRESULT StdPropertyGet ( const BSTR strProperty, BSTR * ppstrOut );
  17. HRESULT StdPropertyGet ( long lProperty, long * plOut );
  18. HRESULT StdPropertyGet ( DATE dateProperty, DATE * pdateOut );
  19. inline HRESULT StdPropertyGet ( DWORD lProperty, DWORD * pdwOut );
  20. inline HRESULT StdPropertyGet ( BOOL fProperty, BOOL * plOut );
  21. HRESULT StdPropertyGet ( const CMultiSz * pmszProperty, SAFEARRAY ** ppsaStrings );
  22. HRESULT StdPropertyGetBit ( DWORD bvBitVector, DWORD dwBit, BOOL * pfOut );
  23. HRESULT StdPropertyPut ( BSTR * pstrProperty, const BSTR strNew, DWORD * pbvChangedProps = NULL, DWORD dwBitMask = 0 );
  24. HRESULT StdPropertyPut ( long * plProperty, long lNew, DWORD * pbvChangedProps = NULL, DWORD dwBitMask = 0 );
  25. HRESULT StdPropertyPut ( DATE * pdateProperty, DATE dateNew, DWORD * pbvChangedProps = NULL, DWORD dwBitMask = 0 );
  26. inline HRESULT StdPropertyPut ( DWORD * plProperty, long lNew, DWORD * pbvChangedProps = NULL, DWORD dwBitMask = 0 );
  27. inline HRESULT StdPropertyPut ( BOOL * pfProperty, BOOL fNew, DWORD * pbvChangedProps = NULL, DWORD dwBitMask = 0 );
  28. HRESULT StdPropertyPut ( CMultiSz * pmszProperty, SAFEARRAY * psaStrings, DWORD * pbvChangedProps = NULL, DWORD dwBitMask = 0 );
  29. HRESULT StdPropertyPutBit ( DWORD * pbvBitVector, DWORD dwBit, BOOL fIn );
  30. inline HRESULT StdPropertyPutServerName ( BSTR * pstrProperty, const BSTR strNew, DWORD * pbvChangedProps = NULL, DWORD dwBitMask = 0 );
  31. HRESULT LongArrayToVariantArray ( SAFEARRAY * psaLongs, SAFEARRAY ** ppsaVariants );
  32. HRESULT StringArrayToVariantArray ( SAFEARRAY * psaStrings, SAFEARRAY ** ppsaVariants );
  33. HRESULT VariantArrayToStringArray ( SAFEARRAY * psaVariants, SAFEARRAY ** ppsaStrings );
  34. // Property Field Validation: (based on the mfc DDV_ routines)
  35. // These routines return FALSE if the validation fails.
  36. BOOL PV_MaxChars ( const BSTR strProperty, DWORD nMaxChars );
  37. BOOL PV_MinMax ( int nProperty, int nMin, int nMax );
  38. BOOL PV_MinMax ( DWORD dwProperty, DWORD dwMin, DWORD dwMax );
  39. BOOL PV_Boolean ( BOOL fProperty );
  40. // Handing off IDispatch pointers:
  41. template<class T> HRESULT StdPropertyHandoffIDispatch (
  42. REFCLSID clisd,
  43. REFIID riid,
  44. T ** ppIAdmin,
  45. IDispatch ** ppIDispatchResult
  46. );
  47. HRESULT StdPropertyGetIDispatch ( REFCLSID clsid, IDispatch ** ppIDispatchResult );
  48. // Internet addresses <-> Strings
  49. BOOL InetAddressToString ( DWORD dwAddress, LPWSTR wszAddress, DWORD cAddress );
  50. BOOL StringToInetAddress ( LPCWSTR wszAddress, DWORD * pdwAddress );
  51. //--------------------------------------------------------------------
  52. // Inlined functions:
  53. //--------------------------------------------------------------------
  54. inline HRESULT StdPropertyGet ( DWORD lProperty, DWORD * pdwOut )
  55. {
  56. return StdPropertyGet ( (long) lProperty, (long *) pdwOut );
  57. }
  58. inline HRESULT StdPropertyGet ( BOOL fProperty, BOOL * plOut )
  59. {
  60. // Make sure it's our kind of boolean:
  61. fProperty = !!fProperty;
  62. return StdPropertyGet ( (long) fProperty, (long *) plOut );
  63. }
  64. inline HRESULT StdPropertyPut ( DWORD * plProperty, long lNew, DWORD * pbvChangedProps, DWORD dwBitMask )
  65. {
  66. return StdPropertyPut ( (long *) plProperty, lNew, pbvChangedProps, dwBitMask );
  67. }
  68. inline HRESULT StdPropertyPut ( BOOL * pfProperty, BOOL fNew, DWORD * pbvChangedProps, DWORD dwBitMask )
  69. {
  70. // Make sure it's our kind of boolean:
  71. fNew = !!fNew;
  72. return StdPropertyPut ( (long *) pfProperty, (long) fNew, pbvChangedProps, dwBitMask );
  73. }
  74. inline HRESULT StdPropertyPutServerName ( BSTR * pstrProperty, const BSTR strNew, DWORD * pbvChangedProps, DWORD dwBitMask )
  75. {
  76. if ( strNew && lstrcmpi ( strNew, _T("localhost") ) == 0 ) {
  77. // Special case: localhost => ""
  78. return StdPropertyPut ( pstrProperty, _T(""), pbvChangedProps, dwBitMask );
  79. }
  80. return StdPropertyPut ( pstrProperty, strNew, pbvChangedProps, dwBitMask );
  81. }
  82. template<class T>
  83. HRESULT StdPropertyHandoffIDispatch ( REFCLSID clsid, REFIID riid, T ** ppIAdmin, IDispatch ** ppIDispatchResult )
  84. {
  85. // Validate parameters:
  86. _ASSERT ( ppIAdmin != NULL );
  87. _ASSERT ( ppIDispatchResult != NULL );
  88. if ( ppIAdmin == NULL || ppIDispatchResult == NULL ) {
  89. return E_POINTER;
  90. }
  91. // Variables:
  92. HRESULT hr = NOERROR;
  93. CComPtr<T> pIAdmin;
  94. // Zero the out parameters:
  95. *ppIAdmin = NULL;
  96. *ppIDispatchResult = NULL;
  97. // Get the IDispatch pointer to return:
  98. hr = StdPropertyGetIDispatch (
  99. clsid,
  100. ppIDispatchResult
  101. );
  102. if ( FAILED (hr) ) {
  103. goto Error;
  104. }
  105. // Get the specific interface pointer:
  106. hr = (*ppIDispatchResult)->QueryInterface ( riid, (void **) &pIAdmin );
  107. if ( FAILED (hr) ) {
  108. goto Error;
  109. }
  110. *ppIAdmin = pIAdmin;
  111. pIAdmin.p->AddRef ();
  112. return hr;
  113. Error:
  114. SAFE_RELEASE ( *ppIDispatchResult );
  115. *ppIDispatchResult = NULL;
  116. return hr;
  117. // Destructor releases pINntpAdminExpiration
  118. }
  119. #endif // _OLEUTIL_INCLUDED_