区别:Use MFC In A Shared DLL 和 Use MFC In A Static Library

本文探讨了在使用Visual C++进行Windows编程时,如何选择MFC的静态链接或动态链接方式。静态链接虽然增加了应用程序大小,但提高了移植性;而动态链接则能节省磁盘空间。

摘自:Programming Windows with MFC, 2nd Edition

Choosing Use MFC In A Shared DLL minimizes your application's executable file
size by allowing MFC to be accessed from a DLL. If you choose Use MFC In A Static
Library instead, Visual C++ links MFC code into your application's EXE file and the
file size grows considerably. Static linking uses disk space less efficiently than
dynamic linking because a hard disk containing 10 statically linked MFC
applications contains 10 copies of the same MFC library code. On the other hand,
an application that is statically linked can be run on any PC, whether or not the
MFC DLL is present. It's your call whether to link to MFC statically or dynamically,
but remember that if you distribute a dynamically linked EXE, you'll need to
distribute the DLL that houses MFC, too. For a release-build MFC application
created with Visual C++ version 6, that DLL is named Mfc42.dll if the program
uses ANSI characters and Mfc42u.dll if it uses Unicode characters.

转载于:https://www.cnblogs.com/qrlozte/p/4616774.html

<think>好的,我需要回答用户关于MFC中Regular DLLExtension DLL在工程配置上的差异的问题。首先,我得回忆一下之前看到的引用内容。引用[2]提到在Project Settings的General里设置Use MFC in a Shared DLL,而引用[3]则说ExtensionRegular DLL在新建项目时会有标准配置,不需要太担心预处理CRT设置。用户可能想知道在Visual Studio中具体配置的不同步骤,比如预处理宏、库链接、资源处理等方面。 根据引用[1],Regular DLLExtension DLL的主要区别在于接口是否可以是MFC的。Extension DLL用于派生MFC类,而Regular DLL则提供C接口。在项目配置上,引用[2][3]都提到了使用共享MFC库的必要性,但具体配置步骤可能不同。比如,Regular DLL可能需要定义特定的预处理宏,如_AFXDLL_WINDLL,而Extension DLL可能需要AFX_EXT_CLASS导出类。此外,资源处理方面,引用[4]说明MFC DLL的资源加载顺序,这可能影响两者的资源配置方式。 我需要整理这些信息,分点列出配置差异,如预处理宏、导出方式、资源管理、依赖关系等。同时,要确保使用正确的中文术语,并按照用户要求的结构清晰回答。最后生成相关问题,比如使用场景、资源管理差异等。</think>### MFC Regular DLL 与 Extension DLL 的工程配置差异 #### 1. **MFC 库依赖配置** - **Regular DLL** 在项目属性中需选择`Use MFC in a Static Library`或`Use MFC in a Shared DLL`。若选择共享模式,需确保客户端程序也使用相同配置[^2][^4]。 ```cpp // 预处理宏需包含 _AFXDLL _WINDLL #define _AFXDLL #define _WINDLL ``` - **Extension DLL** 必须强制使用`Use MFC in a Shared DLL`,因为其依赖动态链接的MFC库实现派生类扩展[^1][^3]。 #### 2. **导出符号声明** - **Regular DLL** 使用`__declspec(dllexport)`导出C风格函数,或通过`.def`文件显式定义导出符号。例如: ```cpp extern "C" __declspec(dllexport) void MyFunction(); ``` - **Extension DLL** 通过宏`AFX_EXT_CLASS`导出MFC派生类,编译器自动处理符号可见性[^1]: ```cpp class AFX_EXT_CLASS CMyDerivedClass : public CButton { /*...*/ }; ``` #### 3. **资源管理** - **Regular DLL** 需独立管理资源文件(如对话框、字符串表),避免与主程序资源冲突。MFC框架优先加载EXE资源,再搜索DLL资源[^4]。 - **Extension DLL** 若扩展资源(如自定义控件模板),需通过`AfxSetResourceHandle`显式切换资源句柄,确保正确加载[^4]。 #### 4. **编译预处理配置** - **Regular DLL** 需手动添加预处理宏`_USRDLL`,表明生成用户定义的DLL[^3]。 - **Extension DLL** 自动包含`_AFXEXT`宏,标识为MFC扩展库,无需手动设置[^1][^3]。 #### 5. **客户端兼容性** - **Regular DLL** 客户端可以是任意支持C接口的程序(包括非MFC应用)[^1]。 - **Extension DLL** 客户端必须为MFC程序且使用共享MFC库,否则无法解析扩展类[^1][^2]。 --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值