com_sample4
所属分类:ActiveX/DCOM/ATL
开发工具:Visual C++
文件大小:18KB
下载次数:11
上传日期:2006-04-09 10:27:11
上 传 者:
张启
说明: < COM编程精彩实例>>一书的随书源代码光盘的代码,这是第四章的
(lt; Lt; COM programming wonderful example gt; Gt; A book with the CD-ROM source code, which is the fourth chapter)
文件列表:
C4\RESOURCE.H (684, 1999-11-14)
C4\StdAfx.cpp (208, 1999-11-14)
C4\StdAfx.h (1054, 1999-11-14)
C4\TestDlg.cpp (5291, 2000-02-21)
C4\TestDlg.h (1353, 2000-02-21)
C4\Tester.cpp (2110, 2000-02-21)
C4\Tester.dsp (4186, 2000-02-21)
C4\Tester.dsw (820, 1999-12-05)
C4\Tester.h (1324, 1999-11-14)
C4\Tester.rc (5485, 1999-12-13)
C4\Wizard (0, 2006-04-09)
C4\Server\Resource.h (378, 1999-12-05)
C4\Server\Server.cpp (2713, 1999-12-05)
C4\Server\Server.def (266, 1999-12-05)
C4\Server\Server.dsp (4332, 1999-12-05)
C4\Server\Server.h (1294, 1999-12-05)
C4\Server\Server.odl (1064, 1999-12-05)
C4\Server\Server.rc (3123, 1999-12-05)
C4\Server\StdAfx.cpp (208, 1999-12-05)
C4\Server\StdAfx.h (1447, 1999-12-05)
C4\Server\Wzd.cpp (2407, 1999-12-05)
C4\Server\Wzd.h (1479, 1999-12-05)
C4\Server\RES\Server.rc2 (398, 1999-12-05)
C4\Server\RES (0, 2006-04-09)
C4\Server (0, 2006-04-09)
C4\RES\Tester.ico (1078, 1999-11-14)
C4\RES\Tester.rc2 (398, 1999-11-14)
C4\RES (0, 2006-04-09)
C4 (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) Import the type library of the server using one of several formats:
#import "server\server.tlb" // must specify SERVERLib:: namespace scope in
// front of every IWzdPtr, etc.
-OR-
#import "server\debug\server.tlb" no_namespace // don't need to use a SERVERLib:: scope in
// front of every IWzdPtr, etc.
-OR-
#import "server\server.tlb" raw_interfaces_only // doesn't create wrappers around each method
3) Create the COM object using the smart pointer:
IWzdPtr wzd(
__uuidof(Wzd) //guid of DLL or EXE that contains class
);
4) Call the methods of the COM object:
wzd->Method1(1234);
wzd->PutProperty1(4321);
long lVal=wzd->GetProperty1();
(The smart pointer takes care of converting your mthod calls into Invoke()'s.)
5) Catch any COM errors with:
try
{
}
catch (_com_error &err)
{
AfxMessageBox(err.ErrorMessage());
return;
}
/////////////////////////////////////////////////////////////////////
// From: COM Programming by Example by John E. Swanke
// Copyright (C) 2000 jeswanke. All rights reserved.
/////////////////////////////////////////////////////////////////////
近期下载者:
相关文件:
收藏者: