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.

102 lines
2.3 KiB

  1. #include "precomp.h"
  2. #include <stdio.h>
  3. #include <wbemmeta.h>
  4. #pragma warning(disable:4786)
  5. #include <wbemcomn.h>
  6. #include <genutils.h>
  7. HRESULT STDMETHODCALLTYPE CMetaData::QueryInterface(REFIID riid, void** ppv)
  8. {
  9. if(riid == IID_IUnknown || riid == IID_IWbemMetaData)
  10. *ppv = (void*)(IWbemMetaData*)this;
  11. else return E_NOINTERFACE;
  12. ((IUnknown*)*ppv)->AddRef();
  13. return S_OK;
  14. }
  15. ULONG STDMETHODCALLTYPE CMetaData::AddRef()
  16. {
  17. return InterlockedIncrement(&m_lRef);
  18. }
  19. ULONG STDMETHODCALLTYPE CMetaData::Release()
  20. {
  21. long lRef = InterlockedDecrement(&m_lRef);
  22. if(lRef == 0)
  23. delete this;
  24. return lRef;
  25. }
  26. HRESULT CMetaData::GetClass(LPCWSTR wszName, IWbemContext* pContext,
  27. IWbemClassObject** ppClass)
  28. {
  29. _IWmiObject* pClass = NULL;
  30. HRESULT hres = GetClass(wszName, pContext, &pClass);
  31. *ppClass = pClass;
  32. return hres;
  33. }
  34. CContextMetaData::CContextMetaData(CMetaData* pMeta, IWbemContext* pContext)
  35. : m_pMeta(pMeta), m_pContext(pContext)
  36. {
  37. if(m_pMeta)
  38. m_pMeta->AddRef();
  39. if(m_pContext)
  40. m_pContext->AddRef();
  41. }
  42. CContextMetaData::~CContextMetaData()
  43. {
  44. if(m_pMeta)
  45. m_pMeta->Release();
  46. if(m_pContext)
  47. m_pContext->Release();
  48. }
  49. HRESULT CContextMetaData::GetClass(LPCWSTR wszName, _IWmiObject** ppClass)
  50. {
  51. _IWmiObject* pObj = NULL;
  52. HRESULT hres = m_pMeta->GetClass(wszName, m_pContext, &pObj);
  53. *ppClass = pObj;
  54. return hres;
  55. }
  56. CStandardMetaData::CStandardMetaData(IWbemServices* pNamespace)
  57. : m_pNamespace(pNamespace)
  58. {
  59. if(m_pNamespace)
  60. m_pNamespace->AddRef();
  61. }
  62. CStandardMetaData::~CStandardMetaData()
  63. {
  64. if(m_pNamespace)
  65. m_pNamespace->Release();
  66. }
  67. void CStandardMetaData::Clear()
  68. {
  69. if(m_pNamespace)
  70. m_pNamespace->Release();
  71. m_pNamespace = NULL;
  72. }
  73. HRESULT CStandardMetaData::GetClass(LPCWSTR wszName, IWbemContext* pContext,
  74. _IWmiObject** ppObj)
  75. {
  76. BSTR strName = SysAllocString(wszName);
  77. CSysFreeMe sfm(strName);
  78. IWbemClassObject* pObj = NULL;
  79. HRESULT hres = m_pNamespace->GetObject(strName, 0, pContext, &pObj, NULL);
  80. if(FAILED(hres))
  81. return hres;
  82. CReleaseMe rm1(pObj);
  83. return pObj->QueryInterface(IID__IWmiObject, (void**)ppObj);
  84. }