gpt4 book ai didi

c++ - 将 UInt16* 转换为字符

转载 作者:行者123 更新时间:2023-11-28 05:46:41 25 4
gpt4 key购买 nike

我想引用the test application code for 7zip

在下一行(第 383 行):

SzArEx_GetFileNameUtf16(&db, i, temp); //Line 383, gets directory and filename

uint16* 值 temp 获取文件路径的引用表达式(我假设它是一个字符串)。

我有一个 const char,我们将其命名为 filePathToCheck,它基本上是一个文件路径名称。我想要的是一种将 filePathToCheck 值与临时值进行比较的方法,以便我可以“选择”我想要解密的文件

我最初的实现是获取 temp 的多字节值,但这给出了一个空字符串,可在以下方法中找到:

WideCharToMultiByte(CP_UTF8,NULL,temp,sizeof(temp),testa /* char * */, 0, NULL, NULL);

当运行测试应用程序时(参数已被处理),testa 在 WideCharToMultiByte 函数之后仍然是一个空字符串。我是否完全走错了路,我应该用另一种方式处理?

Sample code because the minimum code is still too large

最佳答案

sizeof(temp) 返回 uint * 的大小,它是 4 或 8。你想要的是 temp 的长度(以字符为单位),或者如果 temp 以 null 结尾,您可以简单地传递 -1。

testa 最好是一个足够大的字节数组(不是字符指针!)。下一个参数不应为 0,而应为 sizeof(testa)

关于c++ - 将 UInt16* 转换为字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36078324/

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