Òåõíîëîãèÿ Êëèåíò-Ñåðâåð 1998'3 |
|||||||
|
Ðèñóíîê 8. QuoteProviders
ProviderYahoo.h // ProviderYahoo.h : Declaration of the CProviderYahoo // #ifndef __PROVIDERYAHOO_H_ #define __PROVIDERYAHOO_H_ #include “resource.h” // main symbols #include “CPQuoteProviders.h” ///////////////////////////////////////////////////////////////////////////// // CProviderYahoo class ATL_NO_VTABLE CProviderYahoo : public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CProviderYahoo, &CLSID_ProviderYahoo>, public IConnectionPointContainerImpl<CProviderYahoo>, public CProxyIQuoteProviderEvent<CProviderYahoo>, public IQuoteProvider { public: CProviderYahoo(){} ~CProviderYahoo(){} DECLARE_REGISTRY_RESOURCEID(IDR_PROVIDERYAHOO) BEGIN_COM_MAP(CProviderYahoo) COM_INTERFACE_ENTRY(IQuoteProvider) COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer) END_COM_MAP() BEGIN_CONNECTION_POINT_MAP(CProviderYahoo) CONNECTION_POINT_ENTRY(IID_IQuoteProviderEvent) END_CONNECTION_POINT_MAP() // IProviderYahoo public: STDMETHOD(InitializeData)(LPSTR lpszData); STDMETHOD(ParseResult)(LPSTR lpszResult); STDMETHOD(GetData)(LPSTR lpszData, DWORD dwLen); STDMETHOD(GetHeaders)(LPSTR lpszHeaders, DWORD dwLen); STDMETHOD(GetFlags)(DWORD* pdwFlags); STDMETHOD(GetHttpVersion)(LPSTR lpszHttpVersion, DWORD dwLen); STDMETHOD(GetAcceptTypes>(LPSTR lpszAcceptTypes, DWORD dwLen); STDMETHOD(GetURL)(LPSTR lpszURL, DWORD dwLen); STDMETHOD(GetMethod)(LPSTR lpszMethod, DWORD dwLen); STDMETHOD(LoginIsRequired)(BOOL* pbResult); STDMETHOD(GetPort)(USHORT* pnPort); STDHETHOD[GetHost)[LPSTR lpszHost, DblORD dwLen); }; #endif // _PROVIDERYAHOO_H_ CPQuoteProviders.h #ifndef __CPROXYIQUOTEPROVIDEREVENT_H__ #define __CPROXYIQUOTEPROVIDEREVENT_H__ ///////////////////////////////////////////////////////////////////////////// // CProxyIQuoteProviderEvent template <class T> class CProxyIQuoteProviderEvent : public IConnectionPointImpl<T, &IID_IOuoteProviderEvent, CComDynamicUnkArray> { public: //IQuoteProviderEvent : IUnknown public: HRESULT Fire_UpdateSymbol(LPCTSTR lpszSymbol, LPCTSTR lpszPrice, LPCTSTR lpszChange, LPCTSTR lpszOpen, LPCTSTR lpszVolume) { T* pT = (T*)this; pT->Lock(); HRESULT ret; IUnknown** pp = m_vec.begin(); while (pp < m_vec.end()){ if (*pp !- NULL){ IQuoteProviderEvent* pIQuoteProviderEvent = reinterpret_cast<IQuoteProviderEvent*>(*pp); ret = plQuoteProviderEvent->UpdateSymbol(lpszSymbol, lpszPrice, lpszChange, lpszOpen, lpszVolume); } pp++; } pT->Unlock(); return ret; } }; #endif QuoteProviders.cpp // QuoteProviders.cpp : Implementation of DLL Exports. // #include “stdafx.h” #include “resource.h” #include “CategoryGuid.h” #include “initguid.h #include “QuoteProviders.h” #include “QuoteProviders-i.c” #include “ProviderYahoo.h” #include “ProviderFastQuote.h” #include “comcat.h” //Component Category Helper Functions HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription); HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid); HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid): CRITICAL_SECTION g_CS; CComModule Module; BEGIN_OBJECT_MAP(ObjectMap) OBJECT_ENTRY(CLSID_ProviderYahoo, CProvtderYahoo) OBJECT_ENTRY(CLSID_ProviderFastQuote, CProviderFastQuote) END_OBJECT_MAP() class CQuoteProvidersApp : public CWinApp { public: virtual 800L InitInstance(); virtual int ExitInstance(); }; CQuoteProvidersApp theApp; BOOL CQuoteProvidersApp::InitInstance() { _Module.Init(ObjectMap, m_hInstance); return CWinApp::InitInstance(): } int CQuoteProvidersApp::ExitInstance() { _Module.Term(); return CWinApp::ExitInstance(); } ///////////////////////////////////////////////////////////////////////////// // Used to determine whether the DLL can be unloaded by OLE STOAPI DllCanUnloadNoe(void) { AFX MANAGE_STATE(AfxGetStaticModuleState()); return (AfxDllCanUnloadNow()==S_OK &&_Module.GetLockCount()==()) ? S_OK: S_FALSE; } ///////////////////////////////////////////////////////////////////////////// // Returns a class factory to create an object of the requested type STDAPl DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) { return _Module.GetClassObject(rclsid, riid. ppv); } ////////////////////////////////////////////////////////////////////////////////////// // DllRegisterServer - Adds entries to the system registry STDAPI DllRegisterServer(void) { HRESULT hr; // registers object, typelib and all interfaces in typelib hr = Module.RegisterServer(TRUE); if (FAILED(hr)) return hr; hr = CreateComponentCategory(CATID QuoteProviders, L”Stock Watcher Quote Providers”); if FAILED(hr)) return hr; hr = RegisterCLSIDInCategory(CLSID_ProviderYahoo, CATID_QuoteProviders); if (FAILED(hr)) return hr; hr = RegisterCLSIDlnCategary(CLSID ProviderFastOuote, CATID OuoteProviders); if (FAILED(hr)) return hr; return S_OK; } /////////////////////////////////////////////////////////////////////////// // DllUnregisterServer - Removes entries from the system registry STDAPI DllUnregisterServer(void) { HRESULT hr; _Module.UnregisterServer(); hr=UnRegisterCLSIDInCategory(CLSID_ProviderYahoo. CATID_QuoteProviders); if(FAILED(hr)) return hr; hr=UnRegtsterCLSIDInCategory(CLSID_ProviderFastQuote. CATID_QuoteProviders); if (FaILED(hr)) return hr; return S_OK; } HRESULT CreateComponentCategory(CATID catid, WCHAR* catDescription) { ICatRegister* pcr = NULL ; HRESULT hr = S_OK ; hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); if (FAILED(hr)) return hr; // Make sure the HKCR\Component Categories\{..catid...} // key is registered, CATEGORYINFO catinfo; catinfo.catid = catid; catinfo.lcid - Ox0409 ; // english // Make sure the provided description is not too long. // Only copy the first 127 characters if it is. int len = wcslen(catDescription); if (len>127) len = 127; wcsncpy(catinfo.szDescription, catDescription, len); // Make sure the description is null terminated. catinfo.szDescription[len] = ‘\0’; hr = per->RegisterCategories(1, &catinfo); pcr->Release(); return hr; } HRESULT RegisterCLSIDInCategory(REFCLSID clsid, CATID catid) { // Register your component categories information. ICatRegister* pcr = NULL ; HRESULT hr = S_OK ; hr = CoCreateInstance(CLSID StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID ICatRegister, (void**)&pcr); if (SUCCEEDED(hr)) { // Register this category as being “implemented” by the class. CATID rgcatid[1] ; rgcatid[0] = catid; hr = pcr->RegisterClassImplCategories(clsid, 1, rgcatid); } if (pcr != NULL) pcr->Release(); return hr; } HRESULT UnRegisterCLSIDInCategory(REFCLSID clsid, CATID catid) { ICatRegister* pcr = NULL ; HRESULT hr = S_OK ; hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_INPROC_SERVER, IID_ICatRegister, (void**)&pcr); if (SUCCEEDED(hr)) { // Unregister this category as being “implemented” by the class. CATID rgcatid[1] ; rgcatid[0] = catid: hr = pcr->UnRegisterClassImplCategories(clsid, 1, rgcatid); } if (pcr != NULL) pcr->Release(); return hr; }
Copyright © 1994-2016 ÎÎÎ "Ê-Ïðåññ"