我想知道 下面三个分别是什么意思(LPCTSTR,LPTSTR,LPCSTR)

newman0708 2005-01-13 01:51:34
我想知道 下面三个分别是什么意思?

//LPCTSTR
//LPTSTR
//LPCSTR

是char的什么形式?

分别说一下,谢谢!
...全文
131 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
r_swordsman 2005-01-13
  • 打赏
  • 举报
回复

在Windows数据类型中有以下描述:
Windows Data Types

LPCSTR : Pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.
LPCTSTR : An LPCWSTR if UNICODE is defined, an LPCSTR otherwise.
LPCWSTR : Pointer to a constant null-terminated string of 16-bit Unicode characters.
LPTSTR : An LPWSTR if UNICODE is defined, an LPSTR otherwise.
LPSTR : Pointer to a null-terminated string of 8-bit Windows (ANSI) characters.
LPWSTR : Pointer to a null-terminated string of 16-bit Unicode characters.


这些数据类型在多个头文件中定义,以下是mapidefs.h中的定义:

typedef WORD WCHAR;

#ifdef UNICODE
typedef WCHAR TCHAR;
#else
typedef char TCHAR;
#endif

typedef WCHAR FAR * LPWSTR;
typedef const WCHAR FAR * LPCWSTR;
typedef TCHAR FAR * LPTSTR;
typedef const TCHAR FAR * LPCTSTR;
typedef BYTE FAR * LPBYTE;


实际上,它们都是char 或 wchar_t类型或该类型的指针:

WORD : typedef unsigned short WORD; 2 bytes
LPCTSTR : typedef const TCHAR *LPCTSTR;
TCHAR : typedef wchar_t TCHAR; 2 bytes
LPTSTR : typedef TCHAR *LPTSTR;
LPCSTR : typedef const CHAR *LPCSTR;
CHAR : typedef char CHAR; 1 byte

说到底,就是1个字节和两个字节的问题~也就是ANSI和Unicode:
char (1 byte) : Type char is an integral type that usually contains members of the execution character set — in Microsoft C++, this is ASCII. (8-bit Windows (ANSI) characters)
__wchar_t ( 2 bytes) : A variable of __wchar_t designates a wide-character or multibyte character type. By default, wchar_t is a typedef for unsigned short. (16-bit Unicode characters)

bonbonice 2005-01-13
  • 打赏
  • 举报
回复
查查MSDN吧

在使用上,str是指向char的,但是LPWSTR可以在wide char的编程中普遍应用

A simple example, if you have an application named test.exe

Then you execute c:>text.exe 你好
If you define LPSTR to contain the parameter, the application will crash
Only when you use LPWSTR, the application can work well.
猞猁狲 2005-01-13
  • 打赏
  • 举报
回复
这些都是为ascii字符系统和unicode字符系统的兼容性考虑

这些声明对接受字符型参数的函数很必要!编译时编译器就知道是按unicode(16位)接受字符还是按ASCII(8位)接受字符
oyljerry 2005-01-13
  • 打赏
  • 举报
回复
lpstr== long 的指向string的指针
lpcstr==long 的指向const string的指针
LPWSTR==long 的指向word string的指针
易旭昕 2005-01-13
  • 打赏
  • 举报
回复
LPCTSTR 解析为 long pointer const TCHAR string

TCHAR的定义是:如果 UNICODE宏被定义,它就是一个wchar_t宽字符类型,
否则就是一个unsigned char无符号字符类型。
LPCTSTR 就是一个指向TCHAR类型的const指针,也就是代表一个NULL结尾的C风格字符串。

其它的类推。

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧