什么是Linux相当于LPTSTR和LPCSTR?

Par*_*ani 6 c linux porting lptstr lpcstr

我正在将Windows库转换为linux.我需要在linux中找到LPTSTR和LPCSTR.

我知道我可以使用wchar_t可以使用,但我不确定使用它.

使用LPTSTR的方法之一如下:

void ErrorExit(LPTSTR zFunction)
{
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激!

rod*_*igo 7

在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宏有条件地键入LPTSTRLPTCSTR其他一个,但这可能不需要你的问题.


suj*_*jin 5

LPTSTR - L\xe2\x80\x8cong P\xe2\x80\x8cointer 到 T\xe2\x80\x8cCHAR STR\xe2\x80\x8cing (别担心,长指针与指针相同。)

\n\n

LPCSTR - L\xe2\x80\x8cong P\xe2\x80\x8cointer 到 C\xe2\x80\x8const STR\xe2\x80\x8cing

\n\n
LPSTR = char*\nLPCSTR = const char*\nLPWSTR = wchar_t*\nLPCWSTR = const wchar_t*\nLPTSTR = char* or wchar_t* depending on _UNICODE\nLPCTSTR = const char* or const wchar_t* depending on _UNICODE\n
Run Code Online (Sandbox Code Playgroud)\n\n

来自 msn 页面 LPCSTR

\n\n
typedef const char* LPCSTR;\n
Run Code Online (Sandbox Code Playgroud)\n\n

来自 msn 页面 LPTSTR =>

\n\n
#ifdef UNICODE\n typedef LPWSTR LPTSTR;\n#else\n typedef LPSTR LPTSTR;\n#endif\n
Run Code Online (Sandbox Code Playgroud)\n