非MFC工程中用CString

这篇博客介绍了如何在非MFC工程中使用CString。首先,在工程中添加调试和非调试版本的库引用。接着,创建一个名为DLLMODULE.CPP的源文件,包含必要的预编译头文件和强制加载_USRDLL的符号。同时,确保在stdafx.h中,afx.h被放在windows.h之前。通过这些步骤,使得非MFC工程能够支持CString的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1  赋值一下代码到工程

  #ifdef _DEBUG  

  #pragma comment(lib, "libcmtd.lib")  

  #else   #pragma comment(lib, "libcmt.lib")  

  #endif

2  在工程中建一个CPP文件DLLMODEUL.CPP

3  此CPP文件内容如下

   #include "stdafx.h"  

   #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 #include "stdafx.h"  

  #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 

4  打开stdafx.h,把afx.h包含在windows.h前面

5  ok

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值