MFC Extension dll VS Regular Dll

VC++ MFC类库中文手册实战指南:从核心架构到高级编程 在Windows桌面开发领域,应用程序框架是构建原生界面的核心基础。MFC(Microsoft Foundation Classes)作为经典的C++框架,通过文档-视图架构和消息映射机制,实现了数据与界面的高效分离。其技术价值在于为高性能、高稳定性的工业控制、金融交易等专业领域提供了坚实的开发基础。理解MFC的运行时类信息、序列化等机制,对于维护海量遗留系统和深入掌握Windows平台编程思想至关重要。本文聚焦于**MFC核心架构**与**高级编程实战**,通过系统化的中文指南,帮助开发者解决实际开发中的 阅读详情


1. Dll types
Three:
Win32 dll
MFC regular dll
MFC extension dll


2. MFC extension dll
Basic[MSDN]:
An MFC extension DLL is a DLL that typically implements reusable classes derived from the existing Microsoft Foundation Class Library classes.

An MFC extension DLL has the following features and requirements:

    *      The client executable must be an MFC application compiled with _AFXDLL defined.
    *      An extension DLL can also be used by a regular DLL that is dynamically linked to MFC.
    *      Extension DLLs should be compiled with _AFXEXT defined. This forces _AFXDLL to be also defined and ensures that the proper declarations is pulled in from the MFC header files. It also ensures that AFX_EXT_CLASS is defined as __declspec(dllexport) while building the DLL, which is necessary if you are using this macro to declare the classes in your extension DLL.
    *      Extension DLLs should not instantiate a class derived from CWinApp, but should rely on the client application (or DLL) to provide this object. [my note: since every CWinApp needs to manage its module state, as extension dll just use the caller's, so it just accepts the current module state.]
    *      Extension DLLs should, however, provide a DllMain function and do any necessary initialization there.

An MFC extension DLL uses a shared version of MFC in the same way an application uses the shared DLL version of MFC, with a few additional considerations:

    *      It does not have a CWinApp-derived object. It must work with the CWinApp-derived object of the client application. This means that the client application owns the main message pump, the idle loop, and so on.
    *      It calls AfxInitExtensionModule in its DllMain function. The return value of this function should be checked. If a zero value is returned from AfxInitExtensionModule, return 0 from your DllMain function.
    *      It creates a CDynLinkLibrary object during initialization if the extension DLL wants to export CRuntimeClass objects or resources to the application.

Memory Management

MFCx0.dll and all extension DLLs loaded into a client application's address space use the same memory allocator, resource loading, and other MFC global states as if they were in the same application. This is significant because the non-MFC DLL libraries and the regular DLLs do the exact opposite and have each DLL allocating out of its own memory pool.

Sharing Resources and Classes

Exporting resources is done through a resource list. Each application contains a singly linked list of CDynLinkLibrary objects. When looking for a resource, most of the standard MFC implementations that load resources look first at the current resource module (AfxGetResourceHandle) and if the resource is not found walk the list of CDynLinkLibrary objects attempting to load the requested resource.

Walking the list has the disadvantages that it is slightly slower and requires managing resource ID ranges. It has the advantage that a client application that links to several extension DLLs can use any DLL-provided resource without having to specify the DLL instance handle. AfxFindResourceHandle is an API used for walking the resource list to look for a given match. It takes the name and type of a resource and returns the resource handle where it was first found (or NULL).

If you do not want to walk the list and only load resources from a specific place, use the functions AfxGetResourceHandle and AfxSetResourceHandle to save the old handle and set the new handle. Be sure to restore the old resource handle before you return to the client application. For an example of using this approach to explicitly load a menu, see Testdll2 .cpp in the MFC sample DLLHUSK.

3. MFC regular dll (Talk only Regular DLLs Dynamically Linked to MFC)

Basic [MSDN]: 

A regular DLL dynamically linked to MFC is a DLL that uses MFC internally, and the exported functions in the DLL can be called by either MFC or non-MFC executables. As the name describes, this kind of DLL is built using the dynamic-link library version of MFC (also known as the shared version of MFC). Functions are usually exported from a regular DLL using the standard C interface.

You must add the AFX_MANAGE_STATE macro at the beginning of all the exported functions in regular DLLs that dynamically link to MFC to set the current module state to the one for the DLL. This is done by adding the following line of code to the beginning of functions exported from the DLL:

AFX_MANAGE_STATE(AfxGetStaticModuleState( ))

A regular DLL, dynamically linked to MFC has the following features:

    *      This is a new type of DLL introduced by Visual C++ 4.0.
    *      The client executable can be written in any language that supports the use of DLLs (C, C++, Pascal, Visual Basic, and so on); it does not have to be an MFC application.
    *      Unlike the statically linked regular DLL, this type of DLL is dynamically linked to the MFC DLL (also known as the shared MFC DLL).
    *      The MFC import library linked to this type of DLL is the same one used for extension DLLs or applications using the MFC DLL: MFCxx(D).lib.

A regular DLL, dynamically linked to MFC has the following requirements:

    *      These DLLs are compiled with _AFXDLL defined, just like an executable that is dynamically linked to the MFC DLL. But _USRDLL is also defined, just like a regular DLL that is statically linked to MFC.
    *      This type of DLL must instantiate a CWinApp-derived class.

    *      This type of DLL uses the DllMain provided by MFC. Place all DLL-specific initialization code in the InitInstance member function and termination code in ExitInstance as in a normal MFC application. 

All memory allocations within a regular DLL should stay within the DLL; the DLL should not pass to or receive from the calling executable any of the following:

    *      pointers to MFC objects
    *      pointers to memory allocated by MFC

If you need to do any of the above, or if you need to pass MFC-derived objects between the calling executable and the DLL, then you must build an extension DLL.

Key points:
1) it has its own module state. So regards to resource loading (string, dialog, etc), in order to load its resource correctly, module state switch before loading resource is a must.
2) for every exported function from this dll, the switching module state sentence must be the first code line of every function.
3) The AFX_MANAGE_STATE macro should not be used in regular DLLs that statically link to MFC or in extension DLLs.

4. Loading resource example (from codeguru)

The article link is:http://www.codeguru.com/cpp/w-p/dll/article.php/c109

[Key extraction]The next issue involving DLLs and dialog boxes, involves a DLL invoking a dialog which is located in a different DLL. There are four calling possibilities: 1. Regular calling and Regular DLL, 2. An Extension calling and Regular DLL, 3. A Regular calling an Extension DLL, 4. Extension calling a Extension DLL.
case 1: since it's hard to directly use the exported dialog class as module state can't be switched to the parent regular dll's of the wanted dialog, the dialog resource can't be located, the only way to be able to call the dialog is by exporting a function which inside it can show the dialog.
case 2: same as #1.
case 3: as the regular dll has its module state and the extension dll has no way to join in its resource chain and no way to do module state switch as it can only accept the caller's module state, so no way to realize the dialog call here.
case 4: easy. any way can be fine.


5. Other

1) No need to worry about the project setting's preprocessors and CRT setting. New a MFC extension or regular dll in VS, you will get standard setting there.

2) MFC Module state. Only regular dll needs to manage module state, while for MFC extension dll, it will only accept a module state as it may be called by regular dll or MFC application directly (exe), but it really has no way to do sth with module state.




注:本文转载自:http://www.cnblogs.com/taoxu0903/archive/2009/05/10/1453718.html


MFC规则Regular DLL 例子源码 MFC规则DLL例子源码,VC6.0平台开发,亲自调试完成 立即下载

相关推荐

MFC规则DLL(MFC Regular DLL)添加DLLMain()函数方法-(Vc6.0 与 Vc8.0 都适用)

MFC 规则DLL 添加自定义的 DLLMAIN() 函数!(Vc6.0 与 Vc8.0 同样适用) 这也是我自己一直困扰了好久的问题,本来编程水平就不高,总想借助MFC的类库编写程序,方便不少啊!但是MFC规则DLL中却不提供DLLMAIN()函数,被MFC给封装了,Win32 DLL倒是有DLLMAIN()函数了,可是却用不了MFC,到网上找资料也很少,后来看到了一篇微软MSDN上的文章,不过是英文的(中文翻译的更看不懂了),看了之后自己回去实践了一下,不好用啊,而且多余的代码太多了。于是有放置了一段时间,这段时间正好没事,研究了一下,搞明白了,呵呵~好用了……与大家分享!

MFC--Extension DLL(扩展DLL)

本文阐述的动态链接库的一种,mfc 扩展动态链接库--MFC Extension DLL.最后以一个程序的启动画面来用实例说明一下这个dll的使用 MFC扩展dll主要是为了实现可重用类,也就是MFC标准类库进行继承,然后通过DLL进行重用,一次开发,多次使用。扩展dll使用MFC的动态连接的库版本生成的。只有使用动态连接库的可执行程序或是regular dll(规则动态链接库)才可以使用扩展d

xinzhiyounizhiyouni的专栏 2851

事件相机数据处理实战:从原始事件流到视觉表征的三种核心方法

本文深入探讨了事件相机数据处理的核心环节,即如何将异步、稀疏的原始事件流转换为深度学习模型可处理的视觉表征。文章重点解析了三种核心方法:逐通道累积、体素网格双线性插值和对称累积事件表示,详细阐述了其原理、代码实现、可视化效果及各自的适用场景,为事件相机在目标识别、光流估计等视觉任务中的高效应用提供了实战指南。

read5的博客 444

五. MFC规则DLL(Regular)

5.1 概述   MFC规则DLL的概念体现在两方面:   (1) 它是MFC的   “是MFC的”意味着可以在这种DLL的内部使用MFC;   (2) 它是规则的   “是规则的”意味着它不同于MFC扩展DLL,在MFC规则DLL的内部虽然可以使用MFC,但是其与应用程序的接口不能是MFC。而MFC扩展DLL与应用程序的接口可以是MFC,可以从MFC扩展DLL中导出一个MFC类的派生类

hlfkyo的专栏 993

VASP能带计算避坑指南:从CHGCAR读取失败到成功解决的全过程

本文深度解析VASP能带计算中常见的“CHGCAR读取失败”报错,并提供从静态自洽到非自洽计算的全流程避坑指南。核心解决方案包括使用CONTCAR替代POSCAR、调整SYMPREC参数以处理对称性判定问题,并推荐利用vaspkit工具自动化生成输入文件,确保计算流程稳健高效。

weixin_29245767的博客 784

三极管特性曲线看不懂?手把手教你用Multisim仿真分析放大电路频率响应

本文针对模拟电路初学者,详细讲解如何利用Multisim软件进行电路仿真,将抽象的三极管特性曲线与放大电路频率响应分析变得直观可视。通过手把手教学,指导读者从导入三极管SPICE模型、仿真输出特性曲线,到分析动态工作点,最终使用波特图仪深入分析频率响应并进行补偿设计,有效帮助理解电路原理并指导实践调试。

weixin_29230059的博客 127

MFC Regular DLL封装窗体详细步骤

vc6.0 环境下,将MFC Regular DLL封装窗体在里面。 1. File->Projects->MFC AppWizard(dll)->输入RegularDLL; 2. 选择Regular DLL using shared MFC DLL 和 Yes,please 3. 选择ResourceView视图,再RegularDLL resource目录上右键单击->Insert->

278

【嵌入式原理系列-第七篇】ld脚本实战:从零构建MCU内存布局

本文是一篇针对嵌入式开发者的实战指南,详细讲解了如何从零开始为MCU编写ld链接器脚本以构建自定义内存布局。文章以STM32F103C8T6为例,深入剖析了MEMORY和SECTIONS指令的用法,并提供了OTA分区、非易失数据存储等高级定制案例,帮助开发者解决实际工程中的Flash与RAM管理难题,实现对程序运行的深度掌控。

weixin_29271263的博客 252

一个MFC Extension DLL的Dialog例子

这是个老外写的例子,挺不错的,有学习的意义!特别要注意加粗字段,就是有时候问题所在!Create Skeleton of the DllUse MFC AppWizard to create an extension dlls skeletonSelect MFC Extension DllClick Finish. As you see on this dialog, Main Source

bqw2008的专栏 2424

TBtools的序列提取步骤

本教程详细介绍了如何使用TBtools软件从原来的FASTA序列中提取特定的DNA序列。

weixin_47509995的博客 1万+

UniApp实战:5分钟搞定后台持续定位与轨迹实时更新(附完整代码)

本文详细介绍了在UniApp中实现后台持续定位与动态轨迹地图系统的完整方案。针对物流配送、运动健身等场景,文章深入讲解了权限申请、坐标系选择、定位防抖优化、地图轨迹线(polyline)实时绘制等核心步骤,并提供了可复用的完整代码,帮助开发者高效解决App切后台定位停止、轨迹漂移等常见难题。

weixin_29266679的博客 493

MFC Regular DLL 中自己 DllMain

HOWTO: 如何提供一个 MFC Regular DLL 中自己 DllMainfunction loadTOCNode(){}注意:这篇文章是由无人工介入的自动的机器翻译系统翻译完成。这些文章是微软为不懂英语的用户提供的, 以使他们能够理解这些文章的内容。微软不保证机器翻译的正确度,也不对由于内容的误译或者客户对它的使用所引起的任何直接的, 或间接的可能的问题负责。

谬论的幻想的专栏 3223

SAP公司间STO业务解析(包含主数据解析、后台配置解析、前台业务演示)

SAP公司间STO业务解析

ww114784的博客 1028

四种DLL:NON-MFC DLL, Regular DLL Statically/Dynamically Linked to MFC, MFC Extension DLL

参考资料: https://msdn.microsoft.com/en-us/library/30c674tx.aspx http://www.cnblogs.com/qrlozte/p/4844429.html http://www.cnblogs.com/qrlozte/p/4850642.html   在上面给出的MSDN链接中,你可以看到四种DLL的定义。这里就不赘述。捡重点的说...

weixin_33797791的博客 181

2026华为OD机试真题 11月15日 新系统 【近邻向量检索】

华为OD机试真题 新系统【近邻向量检索】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试真题 【近邻向量检索】多语言题解。

qq_45776114的博客 352

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

VC定义的三种类型DLL有什么区别?

微软的Visual C++支持三种DLL,它们分别是Non-MFC Dll(非MFC动态库)、Regular Dll(常规DLL)、Extension Dll(扩展DLL)。 Non-MFC DLL指的是不用MFC的类库结构,直接用C语言写的DLL,其导出的函数是标准的C接口,能被非MFC或MFC编写的应用程序所调用。Regular DLL:和下述的Extension Dlls一样,是用MF

「东哥说MES」 专注于MES制造执行系统,为你拆解核心架构、功能模块及与ERP/PLC的集成逻辑。提供从入门到精通的系列干货、精选行业报告与实用工具,构建你的数字化知识体系,关注我,用实战经验照亮你的数字化之路。 1542

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

基于Visual C++6.0的DLL编程实现

一、前言  自从微软推出16位的Windows操作系统起,此后每种版本的Windows操作系统都非常依赖于动态链接库(DLL)中的函数和数据,实际上Windows操作系统中几乎所有的内容都由DLL以一种或另外一种形式代表着,例如显示的字体和图标存储在GDI DLL中、显示Windows桌面和处理用户的输入所需要的代码被存储在一个User DLL中、Windows编程所需要的大量的API函数也被包含

wangchuanjin的专栏 1286

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

VS2008 静态库的生成与调用

第一章:VC++动态链接库编程之基础慨念 1.1、概论 先来阐述一下DLL(Dynamic Linkable Library)的概念,你可以简单的把DLL看成一种仓库,它提供给你一些可以直接拿来用的变量、函数或类。在仓库的发展史上经历了“无库-静态链接库-动态链接库”的时代。静态链接库与动态链接库都是共享代码的方式,如果采用静态链接库,则无论你愿不愿意,lib中的指令都被直接包含在最终生成

u011981018的专栏 1571

关于VC中的DLL的编程

转自:http://whzjzy.blog.163.com/blog/static/68634402008102711331884/  DLL的编程 关于VC中的DLL的编程 在我们实际用软件时,经常可看到许多动态连接库。动态连接库有其自身的优点如节省内存、支持多语种等功能,而且

侯文博的专栏 491

Windows C++开发实战:从环境搭建到性能优化的完整指南

C++作为高性能系统编程的核心语言,其内存管理、多线程和底层控制能力是构建高效软件的基础。在Windows平台上进行C++开发,需要深入理解其特有的运行时环境、编译链接机制和系统API。通过合理配置开发环境、管理依赖库和运行时,开发者可以充分发挥C++的性能优势,构建稳定可靠的桌面应用、系统服务和高性能计算程序。本文聚焦Windows C++开发中的**环境配置**和**调试技巧**,涵盖从Visual Studio与CMake工具链集成、vcpkg依赖管理,到多线程调试、内存泄漏检测等实战问题,为开发者提

afhu47033的博客 443

c++ MFC规则DLL的创建和显式调用

1 新建MFC动态链接库Dll2 如图选择使用共享MFC DLL的常规DLL 2 修改对话框资源如图 3 为该对话框绑定类CRegularDllDlg,头文件加入下面引用,否则无法找到CDIalogEx #include <afxdialogex.h> 4 实现Show按钮的事件 void CRegularDllDlg::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 MessageBox(_T("MFC规则DLL")

dxm809的博客 508

MFC DLL——Regular DLL and Extension DLL

2  MFC DLL——扩展的和正规的MFC的AppWizard可以让我们创建MFC库支持的两种DLL:扩展的DLL和正规的DLL。这两种类型的区别是什么呢?说明:当然,Developer Studio也让我们创建纯的、与MFC库无关的Win32 DLL,就像它让我们创建与

delphiwcdj的专栏 5010

Regular DLL(MFC规则DLL)、MFC...Extension DLL(MFC扩展DLL 区别

、Non-MFC   DLL:指的是不用MFC的类库结构,直接用C语言写的DLL,其输出的函数一般用的是标准C接口,并能被非MFC或MFC编写的应用程序所调用。 b、Regular   DLL:和下述的Extension   Dlls一样,是用MFC类库编写的。明显的特点是在源文件里有一个继承CWinApp的类。其又可细分成静态连接到MFC和动态连接到MFC上的。 静态连接到MF

无知人生,记录点滴 3279

MFC DLL 的三种类型

记得以前看过,为了不忘记,mark一下。。 a、Non-MFC DLL:指的是不用MFC的类库结构,直接用C语言写的DLL,其输出的函数一般用的是标准C接口,并能被非MFC或MFC编写的应用程序所调用。 b、Regular(常规) DLL:和下述的Extension Dlls一样,是用MFC类库编写的。明显的特点是在源文件里有一个继承CWinApp的类。其又可细分成静...

用心做事,用情做人 409
上一篇: VC 程序中定制对话框中的回车键
下一篇: Visual C++ 6.0 使用新的 SDK
DavidHsing
博客等级 码龄19年 782粉丝 127原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值