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.

85 lines
1.3 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. UNK.CPP
  5. Abstract:
  6. IUnknown Helpers
  7. History:
  8. --*/
  9. #include "precomp.h"
  10. #include "unk.h"
  11. CUnk::CUnk(CLifeControl* pControl, IUnknown* pOuter)
  12. : m_lRef(0), m_pControl(pControl), m_pOuter(pOuter)
  13. {
  14. if( m_pControl )
  15. {
  16. m_pControl->ObjectCreated((IUnknown*)this);
  17. }
  18. }
  19. CUnk::~CUnk()
  20. {
  21. if( m_pControl )
  22. {
  23. m_pControl->ObjectDestroyed((IUnknown*)this);
  24. }
  25. }
  26. BOOL CUnk::Initialize()
  27. {
  28. m_lRef++;
  29. GetUnknown()->AddRef();
  30. BOOL bRes = OnInitialize();
  31. GetUnknown()->Release();
  32. m_lRef--;
  33. return bRes;
  34. }
  35. // Non-delegating implementation
  36. STDMETHODIMP CUnk::QueryInterface(REFIID riid, void** ppv)
  37. {
  38. *ppv = NULL;
  39. if(riid == IID_IUnknown)
  40. *ppv = (IUnknown*)this;
  41. else
  42. *ppv = GetInterface(riid);
  43. if(*ppv)
  44. {
  45. ((IUnknown*)*ppv)->AddRef();
  46. return S_OK;
  47. }
  48. else return E_NOINTERFACE;
  49. }
  50. ULONG CUnk::AddRef()
  51. {
  52. return InterlockedIncrement(&m_lRef);
  53. }
  54. ULONG CUnk::Release()
  55. {
  56. long lRef = InterlockedDecrement(&m_lRef);
  57. if(lRef == 0)
  58. {
  59. m_lRef++;
  60. delete this;
  61. }
  62. return lRef;
  63. }