gpt4 book ai didi

c++ - 宽字符串 Visual Studio 2005 与 2017?

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:41:53 25 4
gpt4 key购买 nike

我正在尝试 Hook 一个用 Visual Studio 2005 编写的旧游戏的函数。

该函数使用 std::wstring,由于某种原因该函数根本不读取它,因为我使用的是 vs 2017。

我想知道 Visual Studio 2005 和 2017 中的宽字符串之间的区别。以及如何在 Visual Studio 2017 中使用 Visual Studio 2005 宽字符串?

注意: Hook 代码在 vs 2005 中运行良好。

提前致谢,致以最诚挚的问候。

更新#1:一个 friend 给我发了他的 vs 2005 的 wide string 类,但它仍然缺少 const wchar_t* 构造函数

namespace std {
class wstring {
void *allocator;
union {
wchar_t buffer[8];
wchar_t* p_buffer
} _myData;

int size;
int reserved_size;
};
}

最佳答案

经过一些研究人员和一些 friend 的帮助。我已经实现了我想要的,即使用 const wchar_t* 的构造函数构建 vs 2005 的旧 wstring 类并使用它。

class wstring05 {
public:
wstring05(const wchar_t* cstr)
{
allocator = nullptr;
reserved_size = size = wcslen(cstr);
if (size < 8)
memcpy(buffer, cstr, (size + 1) * sizeof(wchar_t));
else
p_buffer = cstr;
}

private:

void *allocator;
union {
wchar_t buffer[8];
const wchar_t* p_buffer;
};

int size;
int reserved_size;
};

关于c++ - 宽字符串 Visual Studio 2005 与 2017?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48266710/

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