COM_Programming_by_Example(11-15)

所属分类:ActiveX/DCOM/ATL
开发工具:Visual C++
文件大小:120KB
下载次数:29
上传日期:2006-04-13 09:22:27
上 传 者kongwe
说明:  COM编程精彩实例随书的第11章至第15章源代码
(COM programming with wonderful examples of the Chapter 11 to Chapter 15 source code)

文件列表:
C15 (0, 2006-01-16)
C15\GUIDS.H (375, 1999-11-30)
C15\IServer (0, 2006-01-16)
C15\IServer\IWzd.def (244, 1999-11-30)
C15\IServer\IWzd.dsp (2411, 1999-11-30)
C15\IServer\IWzd.dsw (533, 1999-11-30)
C15\IServer\IWzd.idl (404, 1999-11-30)
C15\IServer\IWzd.mak (574, 1999-11-30)
C15\RES (0, 2006-01-16)
C15\RES\Tester.ico (1078, 1999-11-14)
C15\RES\Tester.rc2 (398, 1999-11-14)
C15\RESOURCE.H (684, 1999-11-14)
C15\Server (0, 2006-01-16)
C15\Server\RES (0, 2006-01-16)
C15\Server\RES\Server.rc2 (398, 1999-11-30)
C15\Server\Resource.h (378, 1999-11-30)
C15\Server\Server.cpp (2713, 1999-11-30)
C15\Server\Server.def (266, 1999-11-30)
C15\Server\Server.dsp (4338, 1999-11-30)
C15\Server\Server.h (1294, 1999-11-30)
C15\Server\Server.odl (1020, 1999-11-30)
C15\Server\Server.rc (3123, 1999-11-30)
C15\Server\StdAfx.cpp (208, 1999-11-30)
C15\Server\StdAfx.h (1447, 1999-11-30)
C15\Server\WzdSrv.cpp (3264, 1999-12-07)
C15\Server\WzdSrv.h (2953, 1999-12-07)
C15\StdAfx.cpp (208, 1999-11-14)
C15\StdAfx.h (1054, 1999-11-14)
C15\TestDlg.cpp (5814, 2000-02-21)
C15\TestDlg.h (1353, 2000-02-21)
C15\Tester.cpp (2110, 2000-02-21)
C15\Tester.dsp (4246, 2000-02-21)
C15\Tester.dsw (1098, 1999-11-30)
C15\Tester.h (1324, 1999-11-14)
C15\Tester.rc (5486, 1999-12-13)
C15\Wizard (0, 2006-01-16)
C11 (0, 2006-01-16)
C11\Guids.h (375, 1999-11-30)
C11\IServer (0, 2006-01-16)
... ...

///////////////////////////////////////////////////////////////////// // How to write the COM object. ///////////////////////////////////////////////////////////////////// 1) Write your MFC COM class as usual. 2) To the top of the .h file of this COM class, add your own definitions for the MFC OLE macros DECLARE_OLECREATE and IMPLEMENT_OLECREATE. We do this because the class name it uses for COleObjectFactory is hard coded and we can't get to it otherwise to specify our own class name: ///////////////////////////////////////////////////////////////////////////// // Implement our own DECLARE_OLECREATE macros class CWzdOleObjectFactory; #define DECLARE_OLECREATE_WZD(class_name) \ public: \ static AFX_DATA CWzdOleObjectFactory factory; \ static AFX_DATA const GUID guid; \ #define IMPLEMENT_OLECREATE_WZD(class_name, external_name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ AFX_DATADEF CWzdOleObjectFactory class_name::factory(class_name::guid, \ RUNTIME_CLASS(class_name), FALSE, _T(external_name)); \ AFX_COMDAT const AFX_DATADEF GUID class_name::guid = \ { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }; \ 3) Substitute these macros for the current macros. In the .h file, find the DECLARE_OLECREATE macro and rename it to DECLARE_OLECREATE_WZD. In the .cpp file, it's the IMPLEMENT_OLECREATE macro for the IMPLEMENT_OLECREATE_WZD macro. 4) Implement this new derivation of COleObjectFactory at the bottom of this .h file: ///////////////////////////////////////////////////////////////////////////// // Implement our own derivation of COleObjectFactory class factory class CWzdOleObjectFactory : public COleObjectFactory { public: CWzdOleObjectFactory( REFCLSID clsid, CRuntimeClass* pRuntimeClass, BOOL bMultiInstance, LPCTSTR lpszProgID ) : COleObjectFactory(clsid,pRuntimeClass,bMultiInstance,lpszProgID) {}; // singleton version of CreateInstance CCmdTarget *OnCreateObject() { // return static singleton object static CWzdSrv wzd; return &wzd; } }; 5) Override COleObjectFactory's OnCreateObject() method to return a single, static instance of our COM class. We need to do this at the bottom of the .h file after the COM class has been defined. ///////////////////////////////////////////////////////////////////// // From: COM Programming by Example by John E. Swanke // Copyright (C) 2000 jeswanke. All rights reserved. /////////////////////////////////////////////////////////////////////

近期下载者

相关文件


收藏者