gpt4 book ai didi

c++ - 在没有 USES_CONVERSTION 的情况下从 const char * 转换为 LPTSTR

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:24:43 26 4
gpt4 key购买 nike

我正在尝试将 const char * 转换为 LPTSTR。但我不想使用 USES_CONVERSION 来执行它。

以下是我使用 USES_CONVERSION 进行转换的代码。有没有办法使用 sprintf 或 tcscpy 等进行转换?

USES_CONVERSION;
jstring JavaStringVal = (some value passed from other function);
const char *constCharStr = env->GetStringUTFChars(JavaStringVal, 0);
LPTSTR lpwstrVal = CA2T(constCharStr); //I do not want to use the function CA2T..

最佳答案

LPTSTR 有两种模式:

如果定义了 UNICODE,则为 LPWSTR,否则为 LPSTR

#ifdef UNICODE
typedef LPWSTR LPTSTR;
#else
typedef LPSTR LPTSTR;
#endif

或者换个方式:

LPTSTR is wchar_t* or char* depending on _UNICODE

如果您的 LPTSTR 是非 unicode:

根据 MSDN Full MS-DTYP IDL文档中,LPSTRchar *typedef:

typedef char* PSTR, *LPSTR;

所以你可以试试这个:

const char *ch = "some chars ...";
LPSTR lpstr = const_cast<LPSTR>(ch);

关于c++ - 在没有 USES_CONVERSTION 的情况下从 const char * 转换为 LPTSTR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14682480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com