亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? ch14.htm

?? 用VC開發(fā)ACTIVEX書籍和隨書源碼
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!--last modified on Tue, Apr 15, 1997 1:42 PM-->
<HTML>

<HEAD>
<!-- This document was created from RTF source by rtftohtml version 3.0.1 -->

	<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">
	<META NAME="Author" Content="Steph Mineart">
	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
	<TITLE>Chapter 14</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<H1>Chapter 14<BR>
Creating ActiveX COM Objects and Custom Interfaces on Your Own</H1>

<UL>
	<LI><A HREF="#Heading1">Creating ActiveX COM Objects and Custom Interfaces on Your
	Own</A>
	<UL>
		<LI><A HREF="#Heading2">Creating a Basic In-Process Server</A>
		<UL>
			<LI><A HREF="#Heading3">Creating the Project Definition File</A>
			<LI><A HREF="#Heading4">Listing 14.1 CUSTOMBASS.DEF--DLL Library Definition File
			for CUSTOMBASS.DLL</A>
			<LI><A HREF="#Heading5">Custom COM Server Architecture</A>
		</UL>
		<LI><A HREF="#Heading6">Creating the COM Class COBass</A>
		<UL>
			<LI><A HREF="#Heading7">Listing 14.2 COBASS.H--COM Object COBass that Implements
			the IFish and IBass Interfaces</A>
			<LI><A HREF="#Heading8">Listing 14.3 COBASS.CPP--IUnknown Implementation for COBass</A>
			<LI><A HREF="#Heading9">Listing 14.4 COBASS.CPP--COBass Interface Implementations
			of the IFish and IBass Interfaces</A>
			<LI><A HREF="#Heading10">Listing 14.5 CUSTOMBASSID.H--Header File CUSTOMBASSID.H,
			which Contains the Implementation of CLSID for the COBass Class</A>
		</UL>
		<LI><A HREF="#Heading11">Implementing the COBass Class Factory</A>
		<UL>
			<LI><A HREF="#Heading12">Listing 14.6 FACTORY.H--Class Factory Definition File, FACTORY.H,
			for CFBass</A>
			<LI><A HREF="#Heading13">Listing 14.7 FACTORY.CPP--Implementation of the CFBass Class
			and IUnknown Interface</A>
			<LI><A HREF="#Heading14">Listing 14.8 FACTORY.CPP--IUnknown and IClassFactory Implementations
			in CImpIClassFactory</A>
		</UL>
		<LI><A HREF="#Heading15">Implementation of the Server Application</A>
		<UL>
			<LI><A HREF="#Heading16">Listing 14.9 SERVER.H--CServer Class Definition</A>
			<LI><A HREF="#Heading17">Listing 14.10 SERVER.CPP--CServer Object Implementation</A>
		</UL>
		<LI><A HREF="#Heading18">Implementation of the Server Access Functions</A>
		<UL>
			<LI><A HREF="#Heading19">Listing 14.11 CUSTOMBASS.CPP--Server Access Function Implementation</A>
		</UL>
		<LI><A HREF="#Heading20">Compiling and Testing the COM Server</A>
		<LI><A HREF="#Heading21">From Here...</A>
	</UL>
</UL>

<P>
<HR SIZE="4">

<H1><A NAME="Heading1"></A>Creating ActiveX COM Objects and Custom Interfaces on
Your Own</H1>

<UL>
	<LI><B>Writing a custom handler for registering components for regsvr32.exe</B> 
<SPACER TYPE="VERTICAL" SIZE="2">
 The server can directly register all of the COM Objects that it supports.
	<P>
	<LI><B>Implementing a custom class factory (IClassFactory) interface</B> 
<SPACER TYPE="VERTICAL" SIZE="2">
 Without the benefit of a COM framework, you must implement an IClassFactory interface
	for each COM Object created.
	<P>
	<LI><B>Building a DLL-based server for containing COM Objects</B> 
<SPACER TYPE="VERTICAL" SIZE="2">
 Building COM servers without a framework requires implementing some basic COM APIs
	that are entry points into DLL-based servers.
	<P>
	<LI><B>Unloading DLLs from memory when instances of COM Objects are no longer being
	used</B> 
<SPACER TYPE="VERTICAL" SIZE="2">
 COM servers are responsible for removal of all COM components that are no longer
	being used.
	<P>
	<LI><B>Utilizing different strategies for implementing COM interfaces</B> 
<SPACER TYPE="VERTICAL" SIZE="2">
 Multiple techniques can be used for implementing COM Objects.
</UL>

<P>A variety of methods are available for creating COM classes based upon the MFC
and ActiveX frameworks. In this chapter, you will examine methods for creating COM
classes without MFC or ActiveX frameworks.</P>
<P>How the COM class was defined or implemented does not matter to the client application
using the class. The use and function of the class are identical to the client. Defining
and implementing COM classes without a framework such as MFC or ActiveX is an easy
task, although additional work must be performed by the COM developer for object
creation and termination.</P>
<P>Although application frameworks tend to make the creation of COM components easier,
you will find several advantages to creating your own COM classes:

<UL>
	<LI>The component does not have to carry excess baggage (code) incurred from using
	a framework.
	<P>
	<LI>When using C++ without a framework, a particular base class is not required from
	which to derive COM classes. This removes excess baggage which is not needed from
	the implementation of the class.
	<LI>COM components not derived from a framework class can still be used and accessed
	from within a framework-based DLL or EXE.
</UL>

<P>Creating COM components without the benefit of a framework also has some disadvantages.
The biggest drawback is that you need to perform all of the detailed work such as
creating <TT>IClassFactory</TT> interfaces, which are normally supplied by the framework.
<H2><A NAME="Heading2"></A>Creating a Basic In-Process Server</H2>
<P>In <A HREF="ch12.htm">Chapter 12</A>, two COM interfaces are defined: <TT>IFish</TT>
and <TT>IBass</TT>. These interfaces are defined within a project called IFISH.DLL.
The <TT>IFish</TT> and <TT>IBass</TT> interfaces are accessed through a COM class
entitled <TT>CBass</TT>, which is derived from the MFC base class <TT>CCmdTarget</TT>.</P>
<P>In this chapter, the interfaces <TT>IFish</TT> and <TT>IBass</TT> will again be
used along with a new class entitled <TT>COBass</TT>, which is used to access the
interfaces. The <TT>COBass</TT> class will be implemented within a DLL and will not
be derived from a framework class.</P>
<P>To create the basic in-process server, the New dialog will be used. To create
the CUSTOMBASS project, perform the following steps:

<OL>
	<LI>From within the Visual C++ development environment, select the command <U>N</U>ew
	from the <U>F</U>ile menu.
	<P>
	<LI>Select Projects tab from the New dialog.
	<P>
	<LI>From the Projects tab, select Win32 Dynamic Link Library. Enter the project name
	<B>CUSTOMBASS</B> into the Project <U>n</U>ame edit box. Select the OK button.
	<P>
	<LI>The project CUSTOMBASS is now created.
</OL>

<H3><A NAME="Heading3"></A>Creating the Project Definition File</H3>
<P>When creating a generic dynamic link library (DLL), the New dialog does not create
a definition file (DEF). All DLLs must have a definition file that is used to define
information about the project, such as functions that are exported from the library.</P>
<P>All DLLs that support COM classes <I>must</I> export some basic functions in order
for the client applications to access the COM classes. From within the Visual C++
Developer Studio, create a file called CUSTOMBASS.DEF. Listing 14.1 illustrates the
contents of this file.
<H3><A NAME="Heading4"></A>Listing 14.1<SPACER TYPE="HORIZONTAL" SIZE="10"> CUSTOMBASS.DEF--DLL
Library Definition File for CUSTOMBASS.DLL</H3>
<P><FONT COLOR="#0066FF"><TT>LIBRARY CUSTOMBASS<BR>
DESCRIPTION `CUSTOMBASS Dynamic Link Library' <BR>
EXPORTS<BR>
DllGetClassObject<BR>
DllCanUnloadNow<BR>
DllRegisterServer<BR>
DllUnregisterServer</TT></FONT></P>
<P>The function <TT>DllGetClassObject</TT> is called to create an instance of a COM
Object. <TT>DLLCanUnloadNow</TT> is called periodically by the operating system to
remove unused DLLs from system memory. <TT>DllRegisterServer</TT> is used by the
program regsvr32.exe to allow the DLL to register all COM Objects with the Windows
Registry. The function <TT>DllUnregisterServer</TT> is called to remove all registry
settings for the COM Objects from the Windows Registry.
<H3><A NAME="Heading5"></A>Custom COM Server Architecture</H3>
<P>When creating a COM server without the aid of an application framework such as
MFC, you need to establish a system architecture for implementing the COM model.
The architecture used in the CUSTOMBASS project consists of three classes:

<UL>
	<LI><TT>CServer</TT>: A global class within CUSTOMBASS.DLL that acts as a reference
	manager for all COM Objects within the server. This class is responsible for unloading
	the DLL from memory and providing reference bookkeeping.
	<P>
	<LI><TT>CFBass</TT>: A class factory for the <TT>COBass</TT> COM Object. This class
	implements the <TT>IClassFactory</TT> interface for the server.
	<P>
	<LI><TT>COBass</TT>: The COM Object class that contains and implements the <TT>IFish</TT>
	and <TT>IBass</TT> interfaces.
</UL>

<P><IMG SRC="bar.gif" WIDTH="480" HEIGHT="6" ALIGN="BOTTOM" BORDER="0"></P>


<BLOCKQUOTE>
	<P><B>NOTE:</B> While the CUSTOMBASS project utilizes three classes as its basic
	architecture, many different approaches can be used. The only requirement is that
	in all COM architectures there <I>must </I>be a COM Object class and a class factory
	for each COM class.

</BLOCKQUOTE>

<P><IMG SRC="bar.gif" WIDTH="480" HEIGHT="6" ALIGN="BOTTOM" BORDER="0"><BR>
When implementing COM Objects without the use of a framework, the interfaces supported
by the class can be implemented through several methods:

<UL>
	<LI>Single inheritance: In this scheme, each interface is implemented with a single
	C++ implementation class. One controlling object then contains pointers to all of
	the implementation classes. Although this mechanism works, it requires a significant
	amount of coding, and each additional interface supported by the COM class requires
	reprogramming of the COM Object.
	<P>
	<LI>Nested interface classes: This technique is similar to single inheritance, but
	instead of having a separate C++ class for each interface, the interface implementation
	classes are contained or nested within the COM Object. When a COM Object is created,
	it also creates each of the interface classes. This technique is the one that MFC
	uses for interface implementation within a class. Although this technique requires
	less code than the single inheritance technique, it still requires a fair amount
	of coding to implement. <TT>CFBass</TT><I>, </I>the class factory in CUSTOMBASS,
	uses this technique.
	<P>
	<LI>Multiple inheritance: This method is by far the easiest one for implementing
	and coding. The multiple inheritance technique requires that the COM Object class
	be derived from the interface classes. The ATL framework utilizes this method. This
	technique requires less code and consumes much less memory at runtime. The COM class
	<TT>COBass</TT> supports the <TT>IFish</TT> and <TT>IBass</TT> interfaces through
	multiple inheritance.
</UL>

<H2><A NAME="Heading6"></A>Creating the COM Class COBass</H2>
<P>In the CUSTOMBASS project, the COM class <TT>COBass,</TT> which will implement
the <TT>IFish</TT> and <TT>IBass</TT> COM interfaces, is created. You may want to
refer to <A HREF="ch12.htm">Chapter 12</A>, where the <TT>IFish</TT> and <TT>IBass</TT>
interfaces are implemented in the MFC-derived COM class <TT>CBass</TT>.</P>
<P>The class <TT>COBass</TT> is derived directly from the <TT>IFish</TT> and <TT>IBass</TT>
interfaces. By definition, this makes the interface methods of <TT>IFish</TT>, <TT>IBass</TT>,
and <TT>IUnknown</TT> an integral part of <TT>COBass</TT>. The class <TT>Cbass</TT>
is derived from the <TT>CCmdTarget</TT> class. The <TT>IFish</TT> and <TT>IBass</TT>
interfaces are added as members of the <TT>COBass</TT> class (nested interfaces).</P>
<P><TT>COBass</TT> is a C++ class that is derived from the <TT>IBass</TT> and <TT>IFish</TT>
interfaces. Listing 14.2 shows the class definition for <TT>COBass</TT>. This is
different from <TT>CBass</TT><I>,</I> which was derived from the MFC class <TT>CCmdTarget</TT>.
<H3><A NAME="Heading7"></A>Listing 14.2 <SPACER TYPE="HORIZONTAL" SIZE="10">COBASS.H--COM
Object COBass that Implements the IFish and IBass Interfaces</H3>
<P><FONT COLOR="#0066FF"><TT>#if !defined(COBASS_H)<BR>
#define COBASS_H <BR>
#ifdef __cplusplus <BR>
#include &quot;..\ifish\ifish.h&quot;<BR>
#include &quot;..\ifish\ibass.h&quot; <BR>
class COBass : public IFish , public IBass<BR>
{<BR>
public:<BR>
// Main Object Constructor &amp; Destructor.<BR>
COBass(IUnknown* pUnkOuter, CServer* pServer);<BR>
~COBass(void); <BR>
// shared IUnknown methods. Main object, non-delegating.<BR>
STDMETHODIMP QueryInterface(REFIID, PPVOID);<BR>
STDMETHODIMP_(ULONG) AddRef(void);<BR>
STDMETHODIMP_(ULONG) Release(void); <BR>
// IFish methods<BR>
STDMETHODIMP IsFreshwater(BOOL *);<BR>
STDMETHODIMP GetFishName( LPTSTR ); <BR>
// IBass methods<BR>
STDMETHODIMP GetLocation( LPTSTR );<BR>
STDMETHODIMP SetLocation( LPTSTR );<BR>
STDMETHODIMP EatsOtherFish( BOOL *); <BR>
private:<BR>
// We declare nested class interface implementations here. <BR>
// Main Object reference count.<BR>
ULONG m_cRefs; <BR>
// Outer unknown (aggregation &amp; delegation).<BR>
IUnknown* m_pUnkOuter; <BR>
// Pointer to this component server's control object.<BR>
CServer* m_pServer;<BR>
char m_zFishName[256];<BR>
char m_zLocation[256];<BR>
BOOL m_bEatsOtherFish;<BR>
BOOL m_bFreshwater;<BR>
};<BR>
typedef COBass* PCOBass;<BR>
#endif // __cplusplus <BR>
#endif // COBASS_H</TT></FONT></P>
<P>When deriving COM classes from multiple interfaces, less coding is needed to implement
the COM Object and the interfaces. One of the advantages of deriving a COM class
from multiple interfaces is that only one implementation of the <TT>IUnknown</TT>
interfaces is required. The delegation of the <TT>IUnknown</TT> interface is also
avoided. Listing 14.3 illustrates the implementation of the <TT>IUnknown</TT> interface
in the <TT>COBass</TT> class.
<H3><A NAME="Heading8"></A>Listing 14.3<SPACER TYPE="HORIZONTAL" SIZE="10"> COBASS.CPP--IUnknown
Implementation for COBass</H3>
<P><FONT COLOR="#0066FF"><TT>#include &lt;windows.h&gt;<BR>
#include &lt;ole2.h&gt;<BR>

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
福利一区二区在线| 欧美一级精品在线| 91精品国产福利| 中文字幕不卡在线| 日一区二区三区| 91视频免费播放| 精品国产精品一区二区夜夜嗨| 一区二区三区在线视频免费观看| 麻豆一区二区99久久久久| 91美女片黄在线观看91美女| 日韩免费在线观看| 亚洲成人免费视频| 成人av午夜电影| 精品久久久久久久久久久久久久久久久 | www一区二区| 亚洲丰满少妇videoshd| 懂色一区二区三区免费观看| 欧美一区二区三区男人的天堂| 国产精品高潮呻吟久久| 国产精品18久久久| 精品国产乱码久久久久久图片| 亚洲图片欧美综合| 91麻豆高清视频| 国产精品免费久久| 国产成人亚洲精品青草天美| 欧美xxxx老人做受| 蜜臀精品久久久久久蜜臀| 欧美性色综合网| 一区二区免费在线播放| 99久久久精品| 亚洲欧洲日韩综合一区二区| 国产ts人妖一区二区| 精品国产乱码久久久久久影片| 免播放器亚洲一区| 日韩一区二区三区免费看 | 99久久精品国产一区二区三区| 亚洲精品一区二区在线观看| 日韩国产高清在线| 欧美一区二区三区视频免费播放| 日韩影视精彩在线| 67194成人在线观看| 蜜桃视频一区二区三区在线观看| 日韩一区二区精品在线观看| 日本不卡123| 精品久久久久久无| 国产一区二区导航在线播放| 久久久久久久综合日本| 成人午夜在线免费| 亚洲欧美日韩在线| 欧美视频精品在线| 天堂av在线一区| 日韩欧美中文字幕精品| 国内成人精品2018免费看| 亚洲国产精品成人综合| 91尤物视频在线观看| 亚洲成人黄色小说| 精品国精品自拍自在线| 盗摄精品av一区二区三区| 中文字幕一区二区三区在线观看| 91福利资源站| 久久成人免费日本黄色| 欧美韩日一区二区三区| 欧美日韩一区二区三区视频| 秋霞av亚洲一区二区三| 欧美激情一区二区| 欧美综合在线视频| 极品美女销魂一区二区三区免费| 欧美激情综合网| 色婷婷亚洲精品| 久久国产生活片100| 中文字幕不卡的av| 欧美高清dvd| aaa欧美色吧激情视频| 视频一区二区国产| 国产欧美日韩一区二区三区在线观看| 色噜噜狠狠色综合中国| 久久99精品国产.久久久久| 中文字幕一区二区三区四区 | 91在线丨porny丨国产| 水野朝阳av一区二区三区| 久久久不卡网国产精品二区| 色综合天天综合在线视频| 狠狠久久亚洲欧美| 亚洲线精品一区二区三区| 久久精品夜色噜噜亚洲a∨| 欧美三级蜜桃2在线观看| 国产毛片精品视频| 日本中文字幕不卡| 亚洲黄色免费网站| 久久久久久久电影| 欧美一卡2卡三卡4卡5免费| 91亚洲精品久久久蜜桃网站| 久久99国产精品免费网站| 成人自拍视频在线观看| 日本免费新一区视频| 亚洲自拍都市欧美小说| 中国av一区二区三区| 久久新电视剧免费观看| 51精品视频一区二区三区| 欧美在线观看视频在线| 91丨九色丨尤物| 成人性生交大片免费看中文| 久久精品国产亚洲一区二区三区| 亚洲一区二区3| 中文字幕欧美一区| 国产精品理伦片| 国产网站一区二区三区| 精品久久久久久久人人人人传媒 | 99精品欧美一区二区三区小说| 九九视频精品免费| 日本不卡中文字幕| 日本成人在线电影网| 午夜电影一区二区| 一卡二卡三卡日韩欧美| 洋洋成人永久网站入口| 亚洲色图色小说| 亚洲欧美日韩中文播放| 亚洲综合久久久| 亚洲成人av一区| 日本v片在线高清不卡在线观看| 亚洲va欧美va国产va天堂影院| 亚洲午夜激情网站| 一区二区三区四区五区视频在线观看 | 成人在线视频首页| 成人免费视频caoporn| av中文字幕在线不卡| 成人av免费在线播放| av电影天堂一区二区在线观看| 99免费精品在线观看| 色哟哟国产精品| 欧美三级视频在线观看| 欧美一区三区四区| 精品国产乱码久久久久久久| 久久精品夜色噜噜亚洲a∨| 国产精品久久久久久久久免费桃花| 国产精品视频一区二区三区不卡 | 久久久精品国产免大香伊| 久久久蜜臀国产一区二区| 国产午夜精品一区二区| 中文字幕乱码亚洲精品一区| 一区二区欧美视频| 青娱乐精品视频| 国产成人av电影在线观看| 99久久精品国产观看| 一本久久a久久精品亚洲| 欧美一区二区成人| 国产女人18毛片水真多成人如厕| 亚洲三级电影全部在线观看高清| 偷拍一区二区三区| 国产精品一区二区免费不卡| 99久久99久久免费精品蜜臀| 欧美日韩久久一区二区| 亚洲午夜在线观看视频在线| 极品少妇一区二区| 91美女片黄在线| 日韩欧美一级二级三级| 国产精品久久久久久久久动漫| 亚洲曰韩产成在线| 国产一区二三区好的| 欧美色图在线观看| 久久综合久久综合九色| 亚洲图片欧美一区| 不卡一区二区中文字幕| 91精品国产91热久久久做人人| 欧美极品xxx| 麻豆国产欧美日韩综合精品二区| 97精品国产露脸对白| 日韩欧美电影一二三| 亚洲日本在线天堂| 国产精品一区久久久久| 欧美日韩高清一区二区不卡| 国产精品美女一区二区在线观看| 老司机精品视频线观看86| 91色porny在线视频| 亚洲精品在线免费观看视频| 亚洲一区二区三区四区在线免费观看 | 亚洲成av人片在www色猫咪| 国产不卡视频一区| 日韩精品资源二区在线| 亚洲综合图片区| 99精品国产热久久91蜜凸| 久久精品日产第一区二区三区高清版 | 自拍视频在线观看一区二区| 日韩精品每日更新| 欧日韩精品视频| 亚洲女人****多毛耸耸8| 国产资源在线一区| 精品国产91洋老外米糕| 视频一区二区国产| 欧美日韩国产一区| 亚洲综合色婷婷| 色呦呦日韩精品| 亚洲人精品午夜| 菠萝蜜视频在线观看一区| 久久精品欧美日韩精品| 狠狠色伊人亚洲综合成人| 日韩欧美国产小视频| 美女国产一区二区| 日韩欧美在线观看一区二区三区| 天堂va蜜桃一区二区三区|