How to add MFC Common class into your application based on SDK?

 
Recently, I meet a request that modify a DLL based on SDK to support MFC common class.It seems a easy task, but I meet a great difficult. So I have a idea of writing something to record my experience and hope others can benefit from it.        
 
    For there are some common class like CFileDialog,CFileFind,CString which provide a easy way to suit your needs.otherwise you would need multi-effort If you implement by API .Using MFC can save a lot of time. Following is the steps:   
1.     add Related Header file.
For Application based on SDK need include “windows.h”, When you uing MFC common class , adding “afx.h”would result in conflicting with “windows.h”. The way to solve it is removing “windows.h”,after that add #include “stdafx.h”in front of all “.H”header file.
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
   #include <afxwin.h> // MFC core and standard components
  #include <afxext.h> // MFC extensions
  #include <afxdisp.h> // MFC Automation classes
  #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
  #ifndef _AFX_NO_AFXCMN_SUPPORT
  #include <afxcmn.h> // MFC support for Windows Common Controls
  #endif // _AFX_NO_AFXCMN_SUPPORT
Notes: above code must be added in front all head file and its order cann’t change, or it occurs some compile errors. 
2. Modify compile setting.
   Open Project->Setting->General, select Use MFC in a Shared DLL or Use MFC in static Library,and change Use runing-time library From Single-Threaded to Multithreaded From project->Setting->C/C++.
 
    After above modification, I re-compile project, there occurs a error: error LNK2005: _DllMain@12 already defined in OCRDLL.obj. Don’t worry , you should only remove _USRDLL from preprocessor definitions seetings.
 
OK. You have successfully modify a sdk application to support MFC common class!    
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值