Impl GB2312ToUtf8

This commit is contained in:
Changhua 2023-11-22 22:35:00 +08:00
parent 322d62c8b8
commit 6b954e0a4b
2 changed files with 16 additions and 0 deletions

View File

@ -35,6 +35,21 @@ string Wstring2String(wstring ws)
return s; return s;
} }
string GB2312ToUtf8(const char *gb2312)
{
int size_needed = 0;
size_needed = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
wstring ws(size_needed, 0);
MultiByteToWideChar(CP_ACP, 0, gb2312, -1, &ws[0], size_needed);
size_needed = WideCharToMultiByte(CP_UTF8, 0, &ws[0], -1, NULL, 0, NULL, NULL);
string s(size_needed, 0);
WideCharToMultiByte(CP_UTF8, 0, &ws[0], -1, &s[0], size_needed, NULL, NULL);
return s;
}
static int GetWeChatPath(wchar_t *path) static int GetWeChatPath(wchar_t *path)
{ {
int ret = -1; int ret = -1;

View File

@ -28,6 +28,7 @@ DWORD GetMemoryIntByAddress(HANDLE hProcess, DWORD address);
std::wstring GetUnicodeInfoByAddress(HANDLE hProcess, DWORD address); std::wstring GetUnicodeInfoByAddress(HANDLE hProcess, DWORD address);
std::wstring String2Wstring(std::string s); std::wstring String2Wstring(std::string s);
std::string Wstring2String(std::wstring ws); std::string Wstring2String(std::wstring ws);
std::string GB2312ToUtf8(const char *gb2312);
std::string GetStringByAddress(DWORD address); std::string GetStringByAddress(DWORD address);
std::string GetStringByStrAddr(DWORD addr); std::string GetStringByStrAddr(DWORD addr);
std::string GetStringByWstrAddr(DWORD addr); std::string GetStringByWstrAddr(DWORD addr);