<转>VC在dll中使用CString类
2011-04-03 03:17
561 查看
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 <afx.h> // 加在这里
// Windows Header Files:
#include <windows.h>
#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;
}
具体的修改方法如下,与大家分享一下。
在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 <afx.h> // 加在这里
// Windows Header Files:
#include <windows.h>
#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;
}
相关文章推荐
- 【转】VC中的class“std::vector<_Ty>”需要有 dll 接口由 class“Test”的客户端使用错误
- 如何在VS VC 中DLL使用CString类
- 如何在VS VC 中DLL使用CString类
- <U3D>Unity3D项目程序加密1——在Unity3D里使用自己的dll和生成dll
- RxAndroid 操作符使用<一>
- <s:iterator>标签的使用
- <关于数据仓库>基于docker的Mysql与Hadoop/Hive之间的数据转移 (使用Apache Sqoop™)
- <bitset> 简单使用
- VC++ DLL创建与使用_v2
- Thinkphp的<in>、<notin>和<range>标签的使用和异同
- <音频基础> - Linein和Micin的区别及使用
- 使用struts2的<s>标签出错
- <转载>linux gcc编译器中使用gdb单步调试程序,程序不是顺序执行的。
- <顶>vim快捷键映射Map使用
- VC++使用纯资源Dll
- MyBatis中<resultMap>的<association>和<collection>标签的使用
- VC++ .NET 动态加载DLL,使用反射方式Invoke委托调用
- 使用vc++ 6.0制作dll,并在java程序中使用(转)
- 编译2010年x264最新的代码供VC编译使用DLL与LIB
- <转>RestKit在iOS项目中的使用,包含xcode配置说明