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.

56 lines
951 B

  1. #include "dataobj.h"
  2. HRESULT
  3. GetStgMedpUnkForRelease(LPSTGMEDIUM pSTM, IUnknown **pp_unk)
  4. {
  5. CStgMedIf *p_smi = new CStgMedIf(pSTM);
  6. HRESULT hr = p_smi->QueryInterface(IID_IUnknown, (PPVOID)pp_unk);
  7. return hr;
  8. }
  9. CStgMedIf::CStgMedIf(LPSTGMEDIUM pSTM)
  10. {
  11. m_pSTM = pSTM;
  12. m_cRef = 0;
  13. }
  14. STDMETHODIMP
  15. CStgMedIf::QueryInterface(
  16. REFIID riid,
  17. LPLPVOID ppv
  18. )
  19. {
  20. *ppv = NULL;
  21. if (IsEqualIID(riid, IID_IUnknown))
  22. {
  23. *ppv = (LPVOID)this;
  24. ((LPUNKNOWN)*ppv)->AddRef();
  25. return NOERROR;
  26. }
  27. return ResultFromScode(E_NOINTERFACE);
  28. }
  29. STDMETHODIMP_(ULONG)
  30. CStgMedIf::AddRef(void)
  31. {
  32. return ++m_cRef;
  33. }
  34. STDMETHODIMP_(ULONG)
  35. CStgMedIf::Release(void)
  36. {
  37. ULONG cRefT;
  38. cRefT = --m_cRef;
  39. if (0==m_cRef)
  40. {
  41. m_pSTM->pUnkForRelease = 0;
  42. ReleaseStgMedium(m_pSTM);
  43. delete this;
  44. }
  45. return cRefT;
  46. }
  47.