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.

173 lines
5.6 KiB

  1. /****************************************************************************
  2. bcw.h
  3. Owner: Srinik
  4. Copyright (c) 1995 Microsoft Corporation
  5. This header file 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. #ifndef BCW_H
  11. #define BCW_H
  12. /****************************************************************************
  13. BCW_ROT is the IRunningObjectTable imlementation of BCW_ROT.
  14. ****************************************************************************/
  15. class BCW_ROT: public IRunningObjectTable
  16. {
  17. friend class BCW;
  18. public:
  19. BCW_ROT();
  20. ~BCW_ROT();
  21. private:
  22. BOOL_PTR FInitROTPointer(void);
  23. private:
  24. // *** IUnknown methods ***
  25. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  26. STDMETHODIMP_(ULONG) AddRef(void);
  27. STDMETHODIMP_(ULONG) Release(void);
  28. // *** IRunningObjectTable methods ***
  29. STDMETHODIMP Register(DWORD grfFlags, IUnknown *punkObject,
  30. IMoniker *pmkObjectName, DWORD *pdwRegister)
  31. {
  32. if (m_piROT == NULL)
  33. return E_FAIL;
  34. return m_piROT->Register(grfFlags, punkObject, pmkObjectName, pdwRegister);
  35. }
  36. STDMETHODIMP Revoke(DWORD dwRegister)
  37. {
  38. if (m_piROT == NULL)
  39. return E_FAIL;
  40. return m_piROT->Revoke(dwRegister);
  41. }
  42. STDMETHODIMP IsRunning(IMoniker *pmkObjectName)
  43. {
  44. // Trick the moniker binding code into thinking that the object is not
  45. // running. This way it will try to create a new instance of the object.
  46. // REVIEW: we may want to check the pmkObjectName, and if is not the one
  47. // that we are concerned with,then we may want to delegate the call.
  48. return S_FALSE;
  49. }
  50. STDMETHODIMP GetObject(IMoniker *pmkObjectName,IUnknown **ppunkObject)
  51. {
  52. // Trick the moniker binding code into thinking that the object is not
  53. // running. This way it will try to create a new instance of the object.
  54. // REVIEW: we may want to check the pmkObjectName, and if is not the one
  55. // that we are concerned with,then we may want to delegate the call.
  56. return MK_E_UNAVAILABLE;
  57. }
  58. STDMETHODIMP NoteChangeTime(DWORD dwRegister, FILETIME *pfiletime)
  59. {
  60. if (m_piROT == NULL)
  61. return E_FAIL;
  62. return m_piROT->NoteChangeTime(dwRegister, pfiletime);
  63. }
  64. STDMETHODIMP GetTimeOfLastChange(IMoniker *pmkObjectName, FILETIME *pfiletime)
  65. {
  66. if (m_piROT == NULL)
  67. return E_FAIL;
  68. return m_piROT->GetTimeOfLastChange(pmkObjectName, pfiletime);
  69. }
  70. STDMETHODIMP EnumRunning(IEnumMoniker **ppenumMoniker)
  71. {
  72. if (m_piROT == NULL)
  73. return E_FAIL;
  74. return m_piROT->EnumRunning(ppenumMoniker);
  75. }
  76. private:
  77. /* Return back pointer to containing BCW object. */
  78. inline BCW* PBCW();
  79. IRunningObjectTable * m_piROT;
  80. #ifdef DEBUG
  81. Debug(ULONG m_cRef);
  82. #endif
  83. };
  84. /****************************************************************************
  85. Declaration of BCW. This class implements IBindCtx and IRunningObjectTable
  86. This is class is used to manipulate the binding process, such that the
  87. moniker binding code will create a new instance of the object instead of
  88. binding to the existing instance
  89. ****************************************************************************/
  90. class BCW: public IBindCtx
  91. {
  92. friend class BCW_ROT;
  93. public:
  94. BCW(IBindCtx * pibc);
  95. ~BCW();
  96. static IBindCtx * Create(IBindCtx * pibc);
  97. private:
  98. // *** IUnknown methods ***
  99. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj);
  100. STDMETHODIMP_(ULONG) AddRef(void);
  101. STDMETHODIMP_(ULONG) Release(void);
  102. // *** IBindCtx methods ***
  103. STDMETHODIMP RegisterObjectBound(IUnknown *punk)
  104. { return m_pibc->RegisterObjectBound(punk); }
  105. STDMETHODIMP RevokeObjectBound(IUnknown *punk)
  106. { return m_pibc->RevokeObjectBound(punk); }
  107. STDMETHODIMP ReleaseBoundObjects(void)
  108. { return m_pibc->ReleaseBoundObjects(); }
  109. STDMETHODIMP SetBindOptions(BIND_OPTS *pbindopts)
  110. { return m_pibc->SetBindOptions(pbindopts); }
  111. STDMETHODIMP GetBindOptions(BIND_OPTS *pbindopts)
  112. { return m_pibc->GetBindOptions(pbindopts); }
  113. STDMETHODIMP GetRunningObjectTable(IRunningObjectTable **pprot)
  114. {
  115. if (pprot == NULL)
  116. return E_INVALIDARG;
  117. *pprot = (IRunningObjectTable *) &m_ROT;
  118. ((IUnknown *) *pprot)->AddRef();
  119. return NOERROR;
  120. }
  121. STDMETHODIMP RegisterObjectParam(LPOLESTR pszKey, IUnknown *punk)
  122. { return m_pibc->RegisterObjectParam(pszKey, punk); }
  123. STDMETHODIMP GetObjectParam(LPOLESTR pszKey, IUnknown **ppunk)
  124. { return m_pibc->GetObjectParam(pszKey, ppunk); }
  125. STDMETHODIMP EnumObjectParam(IEnumString **ppenum)
  126. { return m_pibc->EnumObjectParam(ppenum); }
  127. STDMETHODIMP RevokeObjectParam(LPOLESTR pszKey)
  128. { return m_pibc->RevokeObjectParam(pszKey); }
  129. private:
  130. BCW_ROT m_ROT; // IRunningObjectTable implementation
  131. DWORD m_cObjRef;
  132. IBindCtx * m_pibc;
  133. };
  134. #endif // BCW_H