1.CString未定义标识符
CString并非是标准类型,为MFC中定义的类型;
情况1:创建了一个C++的动态链接库,属性上已经选中了dll中支持MFC,仍报错CString未定义标识符,
在工程的stafx.h中,增加了如下语句
#include <afxext.h> // MFC 扩展
情况2:不使用MFC;使用#include"afx.h" 或者#include <atlstr.h>即可解决;
修改不使用MFC到使用MFC:
注意:当出现#error : Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d]错误时,改工程设置: Project|Properties|Configuration Properties|General|Use of MFC :
Use MFC in a Shared DLL(项目-〉属性-〉use of MFC 改成use MFC in a share dll)
2. 类型转换
转换1:CString->char*
方法一:
char* ch;
CString temp;
ch=T2A(temp.GetBuffer(0));
方法二:
使用强制转换
CString theString( "This is a test" );
LPTSTR lpsz =(LPTSTR)(LPCTSTR)theString;
转换2:char*->CString
方法一:
可以直接赋值
CString cstr;
char* ch;
cstr=ch;
方法二:
通过使用Format函数
char chArray[] = "This is a test";
CString cstr;
MBCS下(即没定义UNICODE时):
cstr.Format(_T("%s"), chArray);
定义UNICODE时:
USES_CONVERSION;
cstr.Format(_T("%s"), A2W(chArray));
typedef wchar_t ACHAR;
int acedGetDist (const ads_point pt, const ACHAR *prompt,ads_real *result);
_T("\n指定圆的半径或[直径(D)]:") 格式: const wchar_t *
_RXST("\n objIdList为:%d"), objIdList.length()
"\n指定圆的半径或[直径(D)]:" 格式: const char *
"\n objIdList为:%d"