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.

150 lines
4.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Binder.h : Declaration of CBinder - Provider binder for DS OLE DB Provider
  3. //
  4. #if (!defined(BUILD_FOR_NT40))
  5. #ifndef __BINDER_H_
  6. #define __BINDER_H_
  7. /////////////////////////////////////////////////////////////////////////////
  8. // CBinder
  9. class ATL_NO_VTABLE CBinder :
  10. INHERIT_TRACKING,
  11. public CComObjectRootEx<CComMultiThreadModel>,
  12. public CComCoClass<CBinder, &CLSID_ADSI_BINDER>,
  13. public ISupportErrorInfo,
  14. public IBindResource,
  15. public IDBBinderProperties
  16. {
  17. public:
  18. CBinder()
  19. {
  20. m_pUnkMarshaler = NULL;
  21. m_pDataSource = NULL;
  22. m_pSession = NULL;
  23. m_pDBInitialize = NULL;
  24. m_pOpenRowset = NULL;
  25. }
  26. DECLARE_GET_CONTROLLING_UNKNOWN()
  27. BEGIN_COM_MAP(CBinder)
  28. COM_INTERFACE_ENTRY(IBindResource)
  29. COM_INTERFACE_ENTRY(IDBBinderProperties)
  30. COM_INTERFACE_ENTRY(IDBProperties)
  31. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  32. END_COM_MAP()
  33. HRESULT FinalConstruct()
  34. {
  35. //Create Datasource object and get IDBInitialize interface.
  36. HRESULT hr = CreateDataSource();
  37. if (FAILED(hr))
  38. RRETURN(hr);
  39. //Create a session and get the IOpenRowset interface.
  40. hr = CreateSession();
  41. if (FAILED(hr))
  42. RRETURN(hr);
  43. //Now initialize binder properties
  44. hr = InitializeProperties();
  45. if (FAILED(hr))
  46. RRETURN(hr);
  47. //Create an instance of FTM (Free Threaded Marshaler).
  48. //When aggregated, FTM makes it possible for this object
  49. //to bypass standard marshaling (and use raw interface pointer)
  50. //for intraprocess access and use standard marshaling
  51. //for interprocess access.
  52. //This FTM is aggregated above in the line:
  53. //COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  54. hr = CoCreateFreeThreadedMarshaler(
  55. GetControllingUnknown(), &m_pUnkMarshaler.p);
  56. RRETURN(hr);
  57. }
  58. void FinalRelease()
  59. {
  60. m_pUnkMarshaler.Release();
  61. }
  62. // ISupportsErrorInfo
  63. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  64. // IBindResource:
  65. STDMETHODIMP Bind (
  66. IUnknown * punkOuter,
  67. LPCOLESTR pwszURL,
  68. DBBINDURLFLAG dwBindFlags,
  69. REFGUID rguid,
  70. REFIID riid,
  71. IAuthenticate * pAuthenticate,
  72. DBIMPLICITSESSION * pImplSession,
  73. DWORD * pdwBindStatus,
  74. IUnknown ** ppUnk
  75. );
  76. // IDBBinderProperties : IDBProperties
  77. STDMETHODIMP GetProperties(
  78. ULONG cPropertyIDSets,
  79. const DBPROPIDSET rgPropertyIDSets[ ],
  80. ULONG *pcPropertySets,
  81. DBPROPSET **prgPropertySets);
  82. STDMETHODIMP GetPropertyInfo(
  83. ULONG cPropertyIDSets,
  84. const DBPROPIDSET rgPropertyIDSets[ ],
  85. ULONG *pcPropertyInfoSets,
  86. DBPROPINFOSET **prgPropertyInfoSets,
  87. OLECHAR **ppDescBuffer);
  88. STDMETHODIMP SetProperties(
  89. ULONG cPropertySets,
  90. DBPROPSET rgPropertySets[ ]);
  91. STDMETHODIMP Reset( void);
  92. public:
  93. private:
  94. //Internal methods
  95. //Function for initializing Binder properties
  96. HRESULT InitializeProperties();
  97. //Function for getting Bind flags from initialization properties.
  98. //This is used when IBindResource::Bind is called with dwBindFlags = 0
  99. DWORD BindFlagsFromDbProps();
  100. //Function to create a data source object - used only at construction time
  101. HRESULT CreateDataSource();
  102. //Function to create a session object - used only at construction time.
  103. HRESULT CreateSession();
  104. //Smart pointer to FTM.
  105. CComPtr<IUnknown> m_pUnkMarshaler;
  106. //Auto critical section.
  107. auto_cs m_autocs;
  108. //Implicitly created Data source object.
  109. CDSOObject *m_pDataSource;
  110. //pointer to DataSource's IDBInitialize interface.
  111. auto_rel<IDBInitialize> m_pDBInitialize;
  112. //Implicitly created Session object.
  113. CSessionObject *m_pSession;
  114. //pointer to Session's IOpenRowset interface.
  115. auto_rel<IOpenRowset> m_pOpenRowset;
  116. //object that manages properties for this binder instance.
  117. CDBProperties m_dbProperties;
  118. };
  119. #endif //__BINDER_H_
  120. #endif