zoukankan      html  css  js  c++  java
  • 在WIN32 DLL中使用MFC

    最近用WIN32 DLL,为了方便要用到MFC的一些库,又不想转工程,就网上找了很多方法,发现没有详细的介绍,有的也行不通,现在成功在WIN32 DLL中使用了MFC,记录一下以防以后用到忘记

    一、修改预编译头文件(stdafx.h)

    在stdafx.h文件中添加下面代码,包含一些MFC的头文件,这些可以在一个MFC工程中复制过来

    复制代码
     1 #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS    // 某些 CString 构造函数将为显式的
    2
    3 #include <afxwin.h> // MFC 核心组件和标准组件
    4 #include <afxext.h> // MFC 扩展
    5
    6 #ifndef _AFX_NO_OLE_SUPPORT
    7 #include <afxole.h> // MFC OLE 类
    8 #include <afxodlgs.h> // MFC OLE 对话框类
    9 #include <afxdisp.h> // MFC 自动化类
    10 #endif // _AFX_NO_OLE_SUPPORT
    11
    12 #ifndef _AFX_NO_DB_SUPPORT
    13 #include <afxdb.h> // MFC ODBC 数据库类
    14 #endif // _AFX_NO_DB_SUPPORT
    15
    16 #ifndef _AFX_NO_DAO_SUPPORT
    17 #include <afxdao.h> // MFC DAO 数据库类
    18 #endif // _AFX_NO_DAO_SUPPORT
    19
    20 #include <afxdtctl.h> // MFC 对 Internet Explorer 4 公共控件的支持
    21 #ifndef _AFX_NO_AFXCMN_SUPPORT
    22 #include <afxcmn.h> // MFC 对 Windows 公共控件的支持
    23 #endif // _AFX_NO_AFXCMN_SUPPORT
    复制代码


    二、修改编译配置

    我使有的是VS2003

    1、项目->属性->常规->MFC的使用->在静态库中使用MFC(动态或静态都可以)

    2、链接器->输入->

        因为编译的时候会因为链接的顺序问题导致链接错误,所以这里要改两个LIB的链接顺序

        先在‘忽略指定库中’忽略掉这两个DLL,分别是uafxcw.lib和libcpmt.lib,如果是DEBUG工程,还需要填入libcmt.lib

        再在'附加依赖项'中以uafxcw.lib libcpmt.lib的顺序填入

    三、在你的主文件中加入代码

    在最前面加入

    复制代码
    #ifdef _DEBUG
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif

    #define new DEBUG_NEW

    /////////////////////////////////////////////////////////////////////////////
    // global data

    // The following symbol used to force inclusion of this module for _USRDLL
    #ifdef _X86_
    extern "C" { int _afxForceUSRDLL; }
    #else
    extern "C" { int __afxForceUSRDLL; }
    #endif
    复制代码

    这样不用从CWinApp中派生一个类再外部定义来使用MFC的入口点,可以直接使用原来的写好的DllMain入口点

    谢谢观看!

  • 相关阅读:
    Chrome cookies folder
    Fat URLs Client Identification
    User Login Client Identification
    Client IP Address Client Identification
    HTTP Headers Client Identification
    The Personal Touch Client Identification 个性化接触 客户识别
    购物车 cookie session
    购物车删除商品,总价变化 innerHTML = ''并没有删除节点,内容仍存在
    453
    购物车-删除单行商品-HTMLTableElement.deleteRow()
  • 原文地址:https://www.cnblogs.com/lidabo/p/3501131.html
Copyright © 2011-2022 走看看