DOCUMENT:Q192883 07-MAY-2001 [visualc] TITLE :HOWTO: Modify the VC++ COMPLEXDB Sample to Work on a Web Page PRODUCT :Microsoft C Compiler PROD/VER:winnt:6.0 OPER/SYS: KEYWORDS:kbtemplate kbDatabase kbInternet kbVC600 kbATL300 kbGrpDSVCDB ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0 - Microsoft Visual C++, 32-bit Professional Edition, version 6.0 - Microsoft Visual C++, 32-bit Learning Edition, version 6.0 ------------------------------------------------------------------------------- SUMMARY ======= Visual C++, version 6.0 contains a sample called COMPLEXDB that demonstrates how to use the Active Template Library (ATL) to write a complex data bound control. While the control works when placed into an MFC dialog as the sample demonstrates, additional work needs to be done to use the control from a Web page. This article details those steps. MORE INFORMATION ================ Perform the following steps to get the COMPLEXDB sample to work on a Web page. 1. Create a CDataSourceListener class that is derived from DataSourceListener (DataSourceListener is described in the ActiveX Control Writer's Kit). 2. Add the following code to the end of the ComplexCtl.cpp: class CDataSourceListener : public DataSourceListener { public: ULONG m_ulRefCount; CComplexCtl * m_pControl; CDataSourceListener(CComplexCtl * pControl):m_ulRefCount(0), m_pControl(pControl){} STDMETHOD(QueryInterface)(REFIID iid, LPVOID * ppvObject) { if (IsEqualIID(__uuidof(IUnknown), iid) || IsEqualIID(__uuidof(DataSourceListener), iid)) { *ppvObject = this; AddRef(); return S_OK; } else return E_NOINTERFACE; } STDMETHOD_(ULONG, AddRef)() { return m_ulRefCount++; } STDMETHOD_(ULONG, Release)() { if (--m_ulRefCount == 0) { delete this; return 0; } else return m_ulRefCount; } STDMETHOD(dataMemberChanged)(DataMember bstrDM) { m_pControl->UpdateControl(); return S_OK; }; STDMETHOD(dataMemberAdded)(DataMember bstrDM){return S_OK;}; STDMETHOD(dataMemberRemoved)(DataMember bstrDM){return S_OK;}; }; 3. Modify the CComplexCtl::putref_DataSource() method in CComplexCtl.cpp file to the following: STDMETHODIMP CComplexCtl::putref_DataSource(DataSource* pDataSource) { m_spDataSource = pDataSource; CDataSourceListener * pListener = new CDataSourceListener(this); // Listener object is deleted when it is released. m_spDataSource->addDataSourceListener(pListener); } 4. Create the Web page to bind the data source object to the COMPLEXDB control. The following example uses the RDS.DataControl control to bind data to the COMPLEXDB control: