com_sample3

所属分类:ActiveX/DCOM/ATL
开发工具:Visual C++
文件大小:19KB
下载次数:8
上传日期:2006-04-09 10:26:19
上 传 者张启
说明:  < COM编程精彩实例>>一书的随书源代码光盘的代码,这是第三章的
(lt; Lt; COM programming wonderful example gt; Gt; A book with the CD-ROM source code, which is the third chapter)

文件列表:
C3\GUIDS.H (283, 1999-12-05)
C3\RESOURCE.H (684, 1999-11-14)
C3\SERVER.CPP (766, 1999-12-05)
C3\SERVER.H (558, 1999-12-05)
C3\StdAfx.cpp (208, 1999-11-14)
C3\StdAfx.h (1054, 1999-11-14)
C3\TestDlg.cpp (5036, 2000-02-21)
C3\TestDlg.h (1353, 2000-02-21)
C3\Tester.cpp (2110, 2000-02-21)
C3\Tester.dsp (4370, 2000-02-21)
C3\Tester.dsw (820, 1999-12-05)
C3\Tester.h (1324, 1999-11-14)
C3\Tester.rc (5485, 1999-12-13)
C3\Wizard (0, 2006-04-09)
C3\Server\Resource.h (378, 1999-12-05)
C3\Server\Server.cpp (2713, 1999-12-05)
C3\Server\Server.def (266, 1999-12-05)
C3\Server\Server.dsp (4332, 1999-12-05)
C3\Server\Server.h (1294, 1999-12-05)
C3\Server\Server.odl (1064, 1999-12-05)
C3\Server\Server.rc (3123, 1999-12-05)
C3\Server\StdAfx.cpp (208, 1999-12-05)
C3\Server\StdAfx.h (1447, 1999-12-05)
C3\Server\Wzd.cpp (2407, 1999-12-05)
C3\Server\Wzd.h (1479, 1999-12-05)
C3\Server\RES\Server.rc2 (398, 1999-12-05)
C3\Server\RES (0, 2006-04-09)
C3\Server (0, 2006-04-09)
C3\RES\Tester.ico (1078, 1999-11-14)
C3\RES\Tester.rc2 (398, 1999-11-14)
C3\RES (0, 2006-04-09)
C3 (0, 2006-04-09)

///////////////////////////////////////////////////////////////////// // How to use the COM object. ///////////////////////////////////////////////////////////////////// 1) The client should call the following to initialize the COM DLL from the main process _and_ from any thread that will be using COM: ::CoInitializeEx( NULL, //always NULL COINIT_APARTMENTTHREADED //see book about threading models ); NOTE: You also need to add _WIN32_DCOM to your project settings under "Preprocessor definitions" in order to get the prototype definition for ::CoInitializeEx() included in your compile. 2) Create a guids.h file containing the class ID of COM object, unless you plan to use a ProgID to create the object. #if !defined guids_h #define guids_h const CLSID CLSID_IWzdSrv = { 0x351495d1, 0xaa6d, 0x11d3, 0x80, 0x7e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; #endif 3) Create a helper class that will wrap this COM object by first opening the ClassWizard and clicking on the Member Variables page. Then click on the "Add Class..." button and select the "From a type library" menu item. Then find and select your server's .tlb file. 4) To create this class in your client use: IWzd wzd; if (!wzd.CreateDispatch( CLSID_IWzdSrv, // or Program ID (ex:"Server.Wzd.6") e)) throw e; 5) Access it's methods and properties as usual: wzd.Method1(1234); wzd.SetProperty1(4321); long lVal=wzd.GetProperty1(); 6) Catch any errors with: COleException *e=new COleException; try { } catch (COleException *e) { _com_error err(e->m_sc); AfxMessageBox(err.ErrorMessage()); e->Delete(); } ///////////////////////////////////////////////////////////////////// // From: COM Programming by Example by John E. Swanke // Copyright (C) 2000 jeswanke. All rights reserved. /////////////////////////////////////////////////////////////////////

近期下载者

相关文件


收藏者