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.

143 lines
3.0 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. LAZY.H
  5. Abstract:
  6. History:
  7. --*/
  8. #ifndef __HMM_LAZY__H_
  9. #define __HMM_LAZY__H_
  10. #include <windows.h>
  11. #include <providl.h>
  12. #include <parmdefs.h>
  13. template<class TInterface>
  14. class CSource
  15. {
  16. RELEASE_ME TInterface* GetPointer();
  17. };
  18. template<class TInterface>
  19. class CLazyInterface
  20. {
  21. private:
  22. IUnknown* m_pObject;
  23. REFIID m_iid;
  24. TInterface* m_pNewInterface;
  25. HRESULT m_hres;
  26. public:
  27. inline CLazyInterface(STORE IUnknown* pObject, REFIID riid)
  28. : m_pObject(pObject), m_iid(riid), m_pNewInterface(NULL),
  29. m_hres(S_OK)
  30. {
  31. }
  32. inline ~CLazyInterface()
  33. {
  34. if(m_pNewInterface) m_pNewInterface->Release();
  35. }
  36. inline INTERNAL TInterface* GetInterface()
  37. {
  38. if(m_pNewInterface == NULL)
  39. {
  40. m_hres = m_pObject->QueryInterface(m_iid,
  41. (void**)&m_pNewInterface);
  42. }
  43. return m_pNewInterface;
  44. }
  45. inline HRESULT GetErrorCode()
  46. {
  47. return m_hres;
  48. }
  49. };
  50. class CLazyProperty
  51. {
  52. protected:
  53. IHmmPropertySource* m_pSource;
  54. LPWSTR m_wszPropName;
  55. VARIANT m_vValue;
  56. HRESULT m_hres;
  57. public:
  58. CLazyProperty(STORE IHmmPropertySource* pSource, STORE LPWSTR wszPropName)
  59. : m_pSource(pSource), m_wszPropName(wszPropName), m_hres(S_OK)
  60. {
  61. VariantInit(&m_vValue);
  62. }
  63. ~CLazyProperty(){}
  64. inline INTERNAL const VARIANT& GetValue()
  65. {
  66. if(V_VT(&m_vValue) == VT_EMPTY)
  67. {
  68. m_hres = m_pSource->GetPropertyValue(m_wszPropName, 0, &m_vValue);
  69. if(FAILED(m_hres))
  70. {
  71. V_VT(&m_vValue) = VT_ERROR;
  72. }
  73. }
  74. return m_vValue;
  75. }
  76. inline HRESULT GetErrorCode()
  77. {
  78. GetValue();
  79. return m_hres;
  80. }
  81. };
  82. class CLazyClassName : public CLazyProperty
  83. {
  84. public:
  85. inline CLazyClassName(STORE IHmmPropertySource* pSource)
  86. : CLazyProperty(pSource, L"__CLASS")
  87. {}
  88. inline INTERNAL BSTR GetName()
  89. {
  90. GetValue();
  91. if(FAILED(m_hres) || V_VT(&m_vValue) != VT_BSTR)
  92. return NULL;
  93. return V_BSTR(&m_vValue);
  94. }
  95. };
  96. class CLazyDerivation : public CLazyProperty
  97. {
  98. public:
  99. inline CLazyDerivation(STORE IHmmPropertySource* pSource)
  100. : CLazyProperty(pSource, L"__DERIVATION")
  101. {}
  102. inline BOOL Contains(LPCWSTR wszName)
  103. {
  104. GetValue();
  105. if(FAILED(m_hres) || V_VT(&m_vValue) != (VT_BSTR | VT_ARRAY))
  106. return NULL;
  107. SAFEARRAY* psa = V_ARRAY(&m_vValue);
  108. long lLBound, lUBound;
  109. SafeArrayGetLBound(psa, 1, &lLBound);
  110. SafeArrayGetUBound(psa, 1, &lUBound);
  111. BOOL bFound = FALSE;
  112. for(long lIndex = lLBound; !bFound && lIndex <= lUBound; lIndex++)
  113. {
  114. BSTR strDerived;
  115. SafeArrayGetElement(psa, &lIndex, &strDerived);
  116. BOOL bFound = !_wcsicmp(strDerived, wszName);
  117. SysFreeString(strDerived);
  118. }
  119. return bFound;
  120. }
  121. };
  122. #endif