VS2010中的LPTSTR主要是为了不同版本之间的兼容问题而设计的。
L:long P:pointer C:const T:type STR:string W:wide
如果是使用了UniCode编码方式,则#define LPWSTR LPTSTR #define LPCWSTR LPCTSTR
如果是使用了Ascii的编码方式,则#define LPSTR LPTSTR #define LPCSTR LPCTSTR
VS2010默认的是UniCode的编码,1个字符要占用2个字节
如下代码
#include <atlstr.h>
#include <windows.h>
void testString()
{
char* chStr= "This is a string test";
const BYTE* temp = (BYTE*)chStr;
LPTSTR lptstr = new TCHAR[20];
wsprintf(lptstr, _T("%s"), temp);
}
int main()
{
testString();
return 0;
}
在Unicode的环境中是编译不过的,因为采用了宽字节编码
工程右键 --> 属性 --> 配置属性 --> 常规 --> 字符集
将UniCode修改为未设置
则编译通过