bcw.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 6k
Category:

Windows Kernel

Development Platform:

Visual C++

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