使用Visual Stuido 2012应用程序向导创建MFC DLL

来源:互联网 发布:淘宝网买笔和笔蕊 编辑:程序博客网 时间:2024/06/06 02:56

系统环境:Windows8

开发工具:Visual Studio 2012试用版


应用程序向导创建MFC DLL步骤如下:




图一 选择MFC DLL和项目命名


图二 点击Next,详细设置



图三 设置界面1

使用Visual Studio 2012 应用程序向导创建MFC DLL时候有三种DLL类型,每种类型都是什么意思呢?

以下解释摘自stackoverflow

If you use MFC DLL as dynamic linking, your code will need the Microsoft Foundation Library DLL's (specifically the version your code requires) installed along with your application or dll in the user end. So this means your installation package would contain

  • Your application/DLL and supporting files
  • All MFC Dlls

This makes the installation package size go bigger and also make take time for user to download your installation setup.

If you link to MFC as static library, you code will work even without MFC DLLs present at the user end . The reason being pretty simple that all the MFC libraries you refererred in your code, will be linked into your application or dll. This means those MFC libraries used in your app/dll becomes the part of the your binary; however, your app/dll will be little bigger.

以下解释摘自MSDN

MFC 扩展 DLL 是通常实现从现有 Microsoft 基础类库类派生的可重用类的 DLL。

MFC 扩展 DLL 具有下列功能和要求:

  • 客户端可执行文件必须是用定义的 _AFXDLL 编译的 MFC 应用程序。

  • 扩展 DLL 也可由动态链接到 MFC 的规则 DLL 使用。

  • 扩展 DLL 应该用定义的 _AFXEXT 编译。 这将强制同时定义 _AFXDLL,并确保从 MFC 头文件中拉入正确的声明。 它也确保了在生成 DLL 时将 AFX_EXT_CLASS 定义为 __declspec(dllexport),这在使用此宏声明扩展 DLL 中的类时是必要的。

  • 扩展 DLL 不应实例化从 CWinApp 派生的类,而应依赖客户端应用程序(或 DLL)提供此对象。

  • 但扩展 DLL 应提供 DllMain 函数,并在那里执行任何必需的初始化。

扩展 DLL 是使用 MFC 动态链接库版本(也称作共享 MFC 版本)生成的。 只有用共享 MFC 版本生成的 MFC 可执行文件(应用程序或规则 DLL)才能使用扩展 DLL。 客户端应用程序和扩展 DLL 必须使用相同版本的 MFCx0.dll。 使用扩展 DLL,可以从 MFC 派生新的自定义类,然后将此“扩展”版本的 MFC 提供给调用 DLL 的应用程序。

本文最后一图 项目文件展示


原创粉丝点击