• 注册
当前位置:1313e > 默认分类 >正文

转VC在dll中使用CString类

CString类用起来非常方便,可是如果不对默认的工程进行一些手术,就没法使用它

具体的修改方法如下,与大家分享一下。

在stdfax中加入下面的红色部分

  // stdafx。h
  #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
  #define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
 
  #if _MSC_VER > 1000
  #pragma once
  #endif // _MSC_VER > 1000
 
  #define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
 
  #include   // 加在这里
    // Windows Header Files:
  #include
  
  #ifdef _DEBUG
   #pragma comment(lib, "libcmtd.lib")
  #else
   #pragma comment(lib, "libcmt.lib")
  #endif
  // Local Header Files
 
  #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)

此时你的程序仍然不能使用Cstring,这是因为由于afx.h默认带了一个DllMain,致使要使用CString类需要几个步骤。
因此在你的dllMain之前加入下面的红色部分的代码即可。

#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 

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
      )
{
    return TRUE;
}

转载于:https://www.cnblogs.com/cnmyp/archive/2011/04/03/2004177.html

本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 162202241@qq.com 举报,一经查实,本站将立刻删除。

最新评论

欢迎您发表评论:

请登录之后再进行评论

登录