📄 vc++动态链接库编程之mfc扩展 dll-开发者网络-dll-天极yes1ky.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0038)http://dev.yesky.com/359/2145859.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>VC++动态链接库编程之MFC扩展 DLL-开发者网络-dll-天极Yesky</TITLE>
<META content="VC++动态链接库编程之MFC扩展 DLL," name=description>
<META content="VC++动态链接库编程之MFC扩展 DLL," name=keywords>
<META content="天极Yesky | 全球中文IT第一门户" name=author>
<META content="天极Yesky | 全球中文IT第一门户" name=Copyright>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN><LINK media=all
href="VC++动态链接库编程之MFC扩展 DLL-开发者网络-dll-天极Yes1ky.files/y_mobile_content.css"
type=text/css rel=stylesheet>
<SCRIPT
src="VC++动态链接库编程之MFC扩展 DLL-开发者网络-dll-天极Yes1ky.files/showlay.js"></SCRIPT>
<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY><!--页面头部--><!--头部-->
<DIV id=topmenu><A href="http://www.yesky.com/">Yesky首页</A>| <A
href="http://product.yesky.com/">产品报价</A>| <A
href="http://cseek.yesky.com/">行情</A>| <A href="http://mobile.yesky.com/">手机</A>
| <A href="http://digital.yesky.com/">数码</A> | <A
href="http://notebook.yesky.com/">笔记本</A> | <A
href="http://pc.yesky.com/">台式机</A> | <A href="http://diy.yesky.com/">DIY硬件</A>
| <A href="http://oa.yesky.com/">外设</A> | <A href="http://net.yesky.com/">网络</A>
| <A href="http://dh.yesky.com/">数字家庭</A> | <A
href="http://lab.yesky.com/">评测</A> | <A href="http://soft.yesky.com/">软件</A> |
<A href="http://e.yesky.com/">e时代</A> | <A href="http://game.yesky.com/">游戏</A>
| <A href="http://pic.yesky.com/">图片</A> | <A
href="http://desktop.yesky.com/">壁纸</A> | <A href="http://q.yesky.com/">群乐</A> |
<A href="http://my.yesky.com/">社区</A> | <A href="http://blog.yesky.com/">博客</A>
| <A href="http://www.mydown.com/">下载</A></DIV>
<DIV id=topbox>
<DIV class=tleft><A href="http://www.yesky.com/"><IMG alt=天极Yesky_全球中文IT第一门户
src="VC++动态链接库编程之MFC扩展 DLL-开发者网络-dll-天极Yes1ky.files/logo.gif"
border=0></A></DIV>
<DIV class=tad><SPAN id=ad1></SPAN></DIV>
<DIV id=search>
<DIV>
<FORM name=searchform action=http://search.chinabyte.com/search method=get
target=_blank><INPUT id=searchzz onmouseover=this.focus() onfocus=this.select()
name=q><INPUT type=hidden value=GB2312 name=encoding><INPUT type=hidden
value=connect name=dir><INPUT type=hidden value=20002 name=cid><INPUT id=search_btn type=submit value=天极搜索> </FORM></DIV>
<DIV class=tdq>
<DIV class=rightarea><A href="http://bj.yesky.com/">北京</A> <A
href="http://hd.yesky.com/">上海</A> <A href="http://gd.yesky.com/">广东</A> <A
href="http://xa.yesky.com/">西安</A><BR><A href="http://cq.yesky.com/">重庆</A> <A
href="http://cd.yesky.com/">成都</A> <A href="http://sy.yesky.com/">沈阳</A> <A
href="http://js.yesky.com/">江苏</A> </DIV>
<DIV class=rightarea_right><A
href="http://my.yesky.com/">用户<BR>登录</A></DIV></DIV></DIV>
<DIV class=tright>
<DIV class=box1>
<SCRIPT src="VC++动态链接库编程之MFC扩展 DLL-开发者网络-dll-天极Yes1ky.files/content_text_ad.js"
type=text/javascript></SCRIPT>
</DIV></DIV></DIV>
<SCRIPT src="VC++动态链接库编程之MFC扩展 DLL-开发者网络-dll-天极Yes1ky.files/flash.js"
type=text/javascript></SCRIPT>
<DIV id=childmenu><A href="http://soft.yesky.com/">软件频道></A><A
href="http://dev.yesky.com/">程序开发></A><A
href="http://dev.yesky.com/devjava/">Java</A><A
href="http://dev.yesky.com/ysdevvb">VB</A><A
href="http://dev.yesky.com/ysdevvc">VC</A><A
href="http://dev.yesky.com/ysdevdelphi">Delphi</A><A
href="http://dev.yesky.com/ysdevc">C/C++</A><A
href="http://dev.yesky.com/web/">Web开发</A><A
href="http://dev.yesky.com/msdn/">微软专栏</A><A
href="http://dev.yesky.com/devydkf/">移动</A><A
href="http://dev.yesky.com/devsjk/">数据库</A><A
href="http://dev.yesky.com/ysdevcxrs">程序人生</A><A
href="http://dev.yesky.com/ysdevrjgc">软件工程</A>|<A
href="http://soft.yesky.com/lesson/">产品中心</A><A
href="http://www.mydown.com/soft/develop/news.shtml">下载</A><A
href="http://q.yesky.com/group/202019"><FONT color=#ff0000>群乐:<FONT
face=Verdana>Vista系统</FONT></FONT></A></DIV><!--导航条-->
<DIV id=location>
<DIV class=loleft>您现在的位置: <A href="http://www.yesky.com/">天极网</A> > <A
href="http://dev.yesky.com/">开发频道</A> > VC++动态链接库编程之MFC扩展 DLL</DIV>
<DIV class=adright><SPAN id=ad2></SPAN></DIV></DIV><!--内容块开始-->
<DIV id=conbox><!--左边开始-->
<DIV id=conleft>
<DIV id=contopla1>
<DIV id=__001>
<DIV class=qkong></DIV>
<DIV class=qw1>全文</DIV>
<DIV class=zkong>
<DIV class=kl></DIV>
<DIV class=bj><A href="http://dev.yesky.com/359/2145859.shtml#pls"
target=_self>评论</A></DIV>
<DIV class=kr></DIV><!-- Error -->
<SCRIPT type=text/javascript>
var titiepic ="#";
if (titiepic!="#")
{
document.write("<div class=\"kl\"></div><div class=\"bj\"><a href=\"#\" target=\"_blank\">图片</a></div><div class=\"kr\"></div>");
}
</SCRIPT>
<!-- Error --></DIV></DIV></DIV>
<DIV class=topadbg><SPAN id=ad10></SPAN></DIV><A name=top></A>
<DIV id=contitle>
<H1>VC++动态链接库编程之MFC扩展 DLL</H1></DIV>
<DIV id=conauthor><SPAN>2005-10-10 08:52 </SPAN><SPAN>作者: 宋宝华 </SPAN><SPAN>出处:
天极网 </SPAN><SPAN>责任编辑:<A title=向本编辑提问
href="http://comments.yesky.com/t/·½ÖÛ/6,324/2145859.shtml" target=_blank>方舟</A>
</SPAN></DIV>
<DIV class=topadbg><SPAN id=ad9></SPAN></DIV>
<DIV id=conneirong><SPAN id=ad3></SPAN>
<TABLE cellSpacing=1 cellPadding=2 width=600 align=center bgColor=#ff3300
border=0>
<TBODY>
<TR bgColor=#ffffff>
<TD bgColor=#cc0000 colSpan=4><A
href="http://soft.yesky.com/lesson/"><FONT
color=#ffffff><B>天极软件专题专区精选</B></FONT></A> <A
href="http://comments.yesky.com/t/100913/6,324/2069547.shtml"
target=_blank><FONT color=#ffffff><B>到天极软件“读编交流区”畅所欲言</B></FONT></A></TD></TR>
<TR bgColor=#ffffff>
<TD width="25%"><A href="http://soft.yesky.com/tools/google">Google专区</A>
</TD>
<TD width="23%"><A href="http://soft.yesky.com/tools/popo">POPO专区</A></TD>
<TD width="24%"><A href="http://qq.yesky.com/">QQ专区</A> <A
href="http://soft.yesky.com/lesson/401/2047901.shtml">QQ挂机</A></TD>
<TD width="28%"><A
href="http://soft.yesky.com/327/2055327.shtml">了解Web2.0</A></TD></TR>
<TR bgColor=#ffffff>
<TD width="25%"><A href="http://design.yesky.com/flash/mx/">Flash MX
视频教程</A></TD>
<TD width="23%"><A
href="http://soft.yesky.com/SoftChannel/72348986094125056/20040623/1823629.shtml">Photoshop视频教程</A></TD>
<TD width="24%"><A
href="http://www.yesky.com/259/1926759.shtml">网页设计视频教程</A></TD>
<TD width="28%"><A
href="http://www.yesky.com/SoftChannel/72348986094125056/20050430/1943944.shtml">照片处理数字暗房</A></TD></TR>
<TR bgColor=#ffffff>
<TD width="25%"><A
href="http://www.yesky.com/SoftChannel/72348968914255872/20050517/1950125.shtml">PPT动画演示教程</A></TD>
<TD width="23%"><A
href="http://soft.yesky.com/SoftChannel/72348968914255872/20050126/1905902.shtml">Excel动画教程集</A></TD>
<TD width="24%"><A
href="http://soft.yesky.com/SoftChannel/72348968914255872/20050223/1914058.shtml">Word动画演示教程</A></TD>
<TD width="28%"><A href="http://soft.yesky.com/os/vista/">Windows
Vista专区</A> </TD></TR>
<TR bgColor=#ffffff>
<TD width="25%" height=18><A
href="http://soft.yesky.com/security/muma/">特洛伊木马专区</A></TD>
<TD width="23%" height=18><A
href="http://soft.yesky.com/security/hkjc/">黑客知识教程专区</A></TD>
<TD width="24%" height=18><A
href="http://soft.yesky.com//security/firewall/">防火墙应用专区</A></TD>
<TD width="28%" height=18><A
href="http://soft.yesky.com/os/zcb/">注册表应用专区</A></TD></TR>
<TR bgColor=#ffffff>
<TD width="25%"><A href="http://soft.yesky.com/lesson/vbapi/"
target=_blank>Windows API开发专区</A></TD>
<TD width="23%"><A href="http://soft.yesky.com/lesson/network/"
target=_blank>网络编程专区</A></TD>
<TD width="24%"><A href="http://soft.yesky.com/lesson/vbdatabase/"
target=_blank>VB数据库编程专区</A></TD>
<TD width="28%"><A
href="http://soft.yesky.com/lesson/multimedia/">图像处理与多媒体编程</A></TD></TR></TBODY></TABLE><BR> 前文我们对非MFC
DLL和MFC规则DLL进行了介绍,现在开始详细分析DLL的最后一种类型――MFC扩展DLL。
<BR><BR> <B>6.1概论</B><BR><BR> MFC扩展DLL与MFC规则DLL的相同点在于在两种DLL的内部都可以使用MFC类库,其不同点在于MFC扩展DLL与应用程序的接口可以是MFC的。MFC扩展DLL的含义在于它是MFC的扩展,其主要功能是实现从现有MFC库类中派生出可重用的类。MFC扩展DLL使用MFC
动态链接库版本,因此只有用共享MFC 版本生成的MFC 可执行文件(应用程序或规则DLL)才能使用MFC扩展DLL。<BR><BR>
<DIV class=guanggao><SPAN
id=contentAdv></SPAN></DIV> 从前文可知,MFC规则DLL被MFC向导自动添加了一个CWinApp的对象,而MFC扩展DLL则不包含该对象,它只是被自动添加了DllMain
函数。对于MFC扩展DLL,开发人员必须在DLL的DllMain函数中添加初始化和结束代码。<BR><BR> 从下表我们可以看出三种DLL对DllMain入口函数的不同处理方式:<BR><BR>
<TABLE cellSpacing=0 cellPadding=2 width="90%" align=center border=1>
<TBODY>
<TR>
<TD>DLL类型</TD>
<TD>入口函数</TD></TR>
<TR>
<TD>非 MFC DLL</TD>
<TD>编程者提供DllMain函数</TD></TR>
<TR>
<TD>MFC规则 DLL</TD>
<TD>CWinApp对象的InitInstance 和 ExitInstance</TD></TR>
<TR>
<TD>MFC扩展 DLL</TD>
<TD>MFC DLL向导生成DllMain
函数</TD></TR></TBODY></TABLE><BR> 对于MFC扩展DLL,系统会自动在工程中添加如下表所示的宏,这些宏为DLL和应用程序的编写提供了方便。像AFX_EXT_CLASS、AFX_EXT_API、AFX_EXT_DATA这样的宏,在DLL和应用程序中将具有不同的定义,这取决于_AFXEXT宏是否被定义。这使得在DLL和应用程序中,使用统一的一个宏就可以表示出输出和输入的不同意思。在DLL中,表示输出(因为_AFXEXT被定义,通常是在编译器的标识参数中指定/D_AFXEXT);在应用程序中,则表示输入(_AFXEXT没有定义)。<BR><BR>
<TABLE cellSpacing=0 cellPadding=2 width="90%" align=center border=1>
<TBODY>
<TR>
<TD>宏</TD>
<TD>定义</TD></TR>
<TR>
<TD>AFX_CLASS_IMPORT</TD>
<TD>__declspec(dllexport)</TD></TR>
<TR>
<TD>AFX_API_IMPORT</TD>
<TD>__declspec(dllexport)</TD></TR>
<TR>
<TD>AFX_DATA_IMPORT</TD>
<TD>__declspec(dllexport)</TD></TR>
<TR>
<TD>AFX_CLASS_EXPORT</TD>
<TD>__declspec(dllexport)</TD></TR>
<TR>
<TD>AFX_API_EXPORT</TD>
<TD>__declspec(dllexport)</TD></TR>
<TR>
<TD>AFX_DATA_EXPORT</TD>
<TD>__declspec(dllexport)</TD></TR>
<TR>
<TD>AFX_EXT_CLASS</TD>
<TD>#ifdef
_AFXEXT<BR> AFX_CLASS_EXPORT<BR>#else<BR> AFX_CLASS_IMPORT</TD></TR>
<TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -