非MFC工程使用MFC库

MFC工程使用MFC库时,可参考以下步骤

1、工程设置中,将MFC的使用由原来的“使用标准windows库”改为“在共享DLL中使用MFC”(VC71

如果是英文版,相关选项是:

Microsoft Foundation Classes: Use MFC in a shared dll, no using MFCVC6

NOTE:因为我用的是中文版的vc71,英文版的vc6.


2、头文件包含

不同的MFC类需包含的头文件是不一样的。

常用的类,如Cstring, Cedit 等,包含afxwin.h就可以了

//在控制台程序中使用mfc类需要以下代码
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
#endif
#include <afx.h>
#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>                     // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT


如果不清楚包含什么头文件的话,可以同msdn进行查询,msdn中,对于MFC类的介绍中,都会给出相应的header file requirement.

3、#include 语句一定要写在首行

这一点很重要,通常出现前面讲到的windows.h重复包含错误,都是因为#include 语句没有写在首行。

另外还要注意的是,如果#include语句是在一个头文件里,那么对应头文件的包含也要写在首行。


另外要注意将代码生成中运行库改成多线程

猜你喜欢

转载自blog.csdn.net/lasuerte/article/details/78392142
MFC
今日推荐