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.

114 lines
2.5 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. ENTER_API_CALL
  30. _IWmiObject* pClass = NULL;
  31. HRESULT hres = GetClass(wszName, pContext, &pClass);
  32. *ppClass = pClass;
  33. return hres;
  34. EXIT_API_CALL
  35. }
  36. CContextMetaData::CContextMetaData(CMetaData* pMeta, IWbemContext* pContext)
  37. : m_pMeta(pMeta), m_pContext(pContext)
  38. {
  39. if(m_pMeta)
  40. m_pMeta->AddRef();
  41. if(m_pContext)
  42. m_pContext->AddRef();
  43. }
  44. CContextMetaData::~CContextMetaData()
  45. {
  46. if(m_pMeta)
  47. m_pMeta->Release();
  48. if(m_pContext)
  49. m_pContext->Release();
  50. }
  51. HRESULT CContextMetaData::GetClass(LPCWSTR wszName, _IWmiObject** ppClass)
  52. {
  53. ENTER_API_CALL
  54. _IWmiObject* pObj = NULL;
  55. HRESULT hres = m_pMeta->GetClass(wszName, m_pContext, &pObj);
  56. *ppClass = pObj;
  57. return hres;
  58. EXIT_API_CALL
  59. }
  60. CStandardMetaData::CStandardMetaData(IWbemServices* pNamespace)
  61. : m_pNamespace(pNamespace)
  62. {
  63. if(m_pNamespace)
  64. m_pNamespace->AddRef();
  65. }
  66. CStandardMetaData::~CStandardMetaData()
  67. {
  68. if(m_pNamespace)
  69. m_pNamespace->Release();
  70. }
  71. void CStandardMetaData::Clear()
  72. {
  73. if(m_pNamespace)
  74. m_pNamespace->Release();
  75. m_pNamespace = NULL;
  76. }
  77. HRESULT CStandardMetaData::GetClass(LPCWSTR wszName, IWbemContext* pContext,
  78. _IWmiObject** ppObj)
  79. {
  80. ENTER_API_CALL
  81. BSTR strName = SysAllocString(wszName);
  82. CSysFreeMe sfm(strName);
  83. IWbemClassObject* pObj = NULL;
  84. HRESULT hres = m_pNamespace->GetObject(strName, 0, pContext, &pObj, NULL);
  85. if(FAILED(hres))
  86. return hres;
  87. CReleaseMe rm1(pObj);
  88. return pObj->QueryInterface(IID__IWmiObject, (void**)ppObj);
  89. EXIT_API_CALL
  90. }