预 定 义 :与(4.1) 相比,增加了_WINDLL,_AFXDLL 的定 义
编译 参数:没有太大区 别 。
连 接参数:/nologo /dll /incremental:yes /pdb:"Debug/Win32DllDemo.pdb" /debug/machine:I386/out:"Debug/Win32DllDemo.dll" /implib:"Debug/Win32DllDemo.lib" /pdbtype:sept
可以看出,(4.1) 里 连 接的很多 库 消失了, 这时 , 项 目4 变 成了 类 似于 项 目2 中的 设 置。 编 程 时 需要注意, 项 目4 的stdafx.h 仅 包含了<windows.h> ,此 时 如果要用MFC 的 类 ,需要自己加入MFC 的几个 头 文件(<afxwin.h> 、<afxext.h> 等),并且将#include <windows.h> 和DllMain 入口函数注 释 掉!
(4.3) Use MFC in a Static DLL
使用MFC DLL 的方式Shared 和Static 之 间 的区 别 与上述 项 目 类 似,不再做比 较 。
5.Win32 Static Library 项 目
预编译头 文件stdafx.h( 可能没有 这 个文件):
不使用MFC , 仅仅 #define WIN32_LEAN_AND_MEAN ,而如果使用MFC ,内容如下:
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afx.h> #include <afxwin.h>
(5.1) Not Using MFC
预 定 义 :WIN32,_DEBUG,_MBCS,_LIB ,新出 现 了符号_LIB
编译 参数:/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /Fp"Debug/W32StaPrehead.pch" /Yu"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD /GZ /c
注意到使用的Run-time library 参数 为 /MLd 。
库 参数: 这 个 项 目没有Link 设 置 页 ,代替的是Library 页 ,参数如下:/nologo /out:"Debug/W32StaPrehead.lib"
(5.2) Use MFC in a Shared DLL
预 定 义 :WIN32,_DEBUG,_WINDOWS,_MBCS,_AFXDLL ,与 项 目1 (MFC Exe ) 设 置相同。
编译 参数:注意使用的Run-time library 参数 为 /MDd 。
库 参数:没有太大区 别 。
(5.3) Use MFC in a Static DLL
编译 参数:注意使用的Run-time library 参数 为 /MTd 。
6.Win32 Application 项 目
预编译头 文件stdafx.h
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h> // Windows Header Files:
#include <stdlib.h> #include <malloc.h> #include <memory.h> #include <tchar.h> // C RunTime Header Files
出
现
了Win32
程序的入口函数WinMain
。
这
个
项
目,Project->settings->General
中
设
置使用MFC
的方式,一般
设为
Not Using MFC
,否
则
程序
结
构的改
动
比
较
大。从Not Using MFC
到使用MFC
的改
变
,
对连
接的
库
的影响
类
似于
项
目4
(Win32 DLL
)。
(6.1) Not Using MFC
预
定
义
:WIN32,_DEBUG,_WINDOWS,_MBCS
编译
参数:/nologo
/MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB"
/Fp"Debug/W32StaPrehead.pch" /Yu"stdafx.h" /Fo"Debug/" /Fd"Debug/" /FD
/GZ /c
注意到使用的Run-time library
参数
为
/MLd
。
连
接参数:kernel32.lib
user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib
ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo
/subsystem:windows /incremental:yes /pdb:"Debug/W32AppDemo.pdb" /debug
/machine:I386 /out:"Debug/W32AppDemo.exe" /pdbtype:sept
(6.2) Use MFC in a Shared DLL
编译
参数:注意使用的Run-time library
参数
为
/MDd
。
(6.3) Use MFC in a Static DLL
编译
参数:注意使用的Run-time library
参数
为
/MTd
。

本文详细介绍了如何在静态和共享DLL中使用MFC,并对比了不同配置下的编译及链接参数变化,对于理解MFC与DLL结合使用时的项目设置具有指导意义。
3171

被折叠的 条评论
为什么被折叠?



