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.

153 lines
3.2 KiB

  1. /****************************************************************************
  2. bcw.cpp
  3. Owner: Srinik
  4. Copyright (c) 1995 Microsoft Corporation
  5. This file contains code for BCW class which implements wrappers for IBindCtx
  6. and IRunningObjectTable. We use this object to trick the moniker binding
  7. code to create a new instance of the object (that the moniker is
  8. referring to) instead connecting to already running instance.
  9. ****************************************************************************/
  10. // #include "hlmain.h"
  11. #include "bcw.h"
  12. ASSERTDATA
  13. /****************************************************************************
  14. Implementation of BCW methods.
  15. ****************************************************************************/
  16. BCW::BCW(IBindCtx * pibc)
  17. {
  18. m_pibc = pibc;
  19. pibc->AddRef();
  20. m_cObjRef = 1;
  21. DllAddRef();
  22. }
  23. BCW::~BCW()
  24. {
  25. m_pibc->Release();
  26. DllRelease();
  27. }
  28. IBindCtx * BCW::Create(IBindCtx * pibc)
  29. {
  30. BCW * pbcw = new BCW(pibc);
  31. if (pbcw == NULL)
  32. return NULL;
  33. if (! pbcw->m_ROT.FInitROTPointer())
  34. {
  35. delete pbcw;
  36. return NULL;
  37. }
  38. return pbcw;
  39. }
  40. STDMETHODIMP BCW::QueryInterface(REFIID riid, void **ppvObj)
  41. {
  42. if (ppvObj == NULL)
  43. return E_INVALIDARG;
  44. if (riid == IID_IUnknown || riid == IID_IBindCtx)
  45. {
  46. *ppvObj = this;
  47. }
  48. else
  49. {
  50. *ppvObj = NULL;
  51. return E_NOINTERFACE;
  52. }
  53. ((IUnknown *) *ppvObj)->AddRef();
  54. return NOERROR;
  55. }
  56. STDMETHODIMP_(ULONG) BCW::AddRef(void)
  57. {
  58. return ++m_cObjRef;
  59. }
  60. STDMETHODIMP_(ULONG) BCW::Release(void)
  61. {
  62. /* Decrement refcount, destroy object if refcount goes to zero.
  63. Return the new refcount. */
  64. if (!(--m_cObjRef))
  65. {
  66. delete this;
  67. return 0;
  68. }
  69. return m_cObjRef;
  70. }
  71. /****************************************************************************
  72. Implementation of BCW_ROT methods.
  73. ****************************************************************************/
  74. /****************************************************************************
  75. BCW_ROT is the IRunningObjectTable imlementation of BCW_ROT.
  76. ****************************************************************************/
  77. BCW_ROT::BCW_ROT()
  78. {
  79. Debug(m_cRef = 0);
  80. m_piROT = NULL;
  81. }
  82. BCW_ROT::~BCW_ROT()
  83. {
  84. if (m_piROT)
  85. m_piROT->Release();
  86. }
  87. BOOL_PTR BCW_ROT::FInitROTPointer(void)
  88. {
  89. if (m_piROT == NULL)
  90. {
  91. if (GetRunningObjectTable(NULL/*reserved*/, &m_piROT) == NOERROR)
  92. m_piROT->AddRef();
  93. }
  94. return (BOOL_PTR) (m_piROT);
  95. }
  96. inline BCW * BCW_ROT::PBCW()
  97. {
  98. return BACK_POINTER(this, m_ROT, BCW);
  99. }
  100. STDMETHODIMP BCW_ROT::QueryInterface(REFIID riid, void **ppvObj)
  101. {
  102. if (riid == IID_IUnknown || riid == IID_IRunningObjectTable)
  103. {
  104. *ppvObj = this;
  105. }
  106. else
  107. {
  108. *ppvObj = NULL;
  109. return E_NOINTERFACE;
  110. }
  111. ((IUnknown *) *ppvObj)->AddRef();
  112. return NOERROR;
  113. }
  114. STDMETHODIMP_(ULONG) BCW_ROT::AddRef(void)
  115. {
  116. return PBCW()->AddRef();
  117. }
  118. STDMETHODIMP_(ULONG) BCW_ROT::Release(void)
  119. {
  120. return PBCW()->Release();
  121. }