创建了一个Win32下的dll,可是忽然发现要用到MFC下的函数,有什么解决办法吗?

解决方案 »

  1.   

    1.加入相应的头文件    由于在SDK程序中一定要包含windows.h头文件,所以在使用MFC中的类时,如加入afx.h一类的头文件会有一个提示与windows.h相冲突,解决的办法是,去掉windows.h,然后在所有的.h文件前加入#include "stdafx.h"#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    注意一定要在所有的头文件之前加入这几行,而且顺序最好不要改变,否则会有大量的错误提示。2.更改编译设置    在Project->Setting->General中选Use MFC in a Shared DLL或者Use MFC in static Library或者添加:#define _AFXDLL并把project->Setting->C/C++ 中的Use runing-time library 由Single-Threaded改为相应的Multithreaded。
      

  2.   

    c/c++ 运行时库有很多字符串操作函数,没必要因为要用CString带个mfc42.dll吧
      

  3.   

    把CString的代码拷到你的程序里面
      

  4.   

    创建一个 win32 dll 并选择MFC支持,察看生成的代码中与你的有什么不同,照着葫芦画瓢