我正在将 windows 库转换为 linux。我需要在 linux 中找到 LPTSTR 和 LPCSTR。
我知道我可以使用 wchar_t 可以使用,但我不确定是否使用它。
使用 LPTSTR 的方法之一如下:
void ErrorExit(LPTSTR zFunction)
{
}
任何帮助将不胜感激!
在 Linux 中,您通常不使用wchar_t
库 API 函数。大多数库使用 UTF-8 编码的字符串,因此它们将 NUL 终止字符的纯数组作为字符串(IMO 这比使用 ANSI 和 Unicode 版本复制所有函数要好得多)。
所以,考虑到这一点:
LPCTSTR
, LPCSTR
, LPCWSTR
-> const char *
.LPTSTR
, LPSTR
, LPWSTR
-> char *
.如果你坚持使用 Unicode 函数,MS 风格,你必须知道它们实际上使用 UTF-16 编码的字符串,并且wchar_t
不是可移植类型,因为它的大小不是由语言指定的。相反,您可以使用uint16_t
:
LPCWSTR
-> const uint16_t *
。LPWSTR
-> uint16_t *
。如果你想额外兼容 MS,你可以使用UNICODE
宏有条件地 typedefLPTSTR
和LPTCSTR
进入其他之一,但这可能不是你的问题所需要的。
LPTSTR - Long Ppointer to TCHAR STRing(别担心,长指针与指针相同。)
LPCSTR - Long 指向 Const STRing 的指针
LPSTR = char*
LPCSTR = const char*
LPWSTR = wchar_t*
LPCWSTR = const wchar_t*
LPTSTR = char* or wchar_t* depending on _UNICODE
LPCTSTR = const char* or const wchar_t* depending on _UNICODE
typedef const char* LPCSTR;
#ifdef UNICODE
typedef LPWSTR LPTSTR;
#else
typedef LPSTR LPTSTR;
#endif