util/register: fix crashing when value string contains non-ascii chars

We can't use RegGetValueA because RegGetValueA converts wide string to non UTF-8 string, which results in crashing when printing
This commit is contained in:
李通洲
2022-11-23 15:42:19 +08:00
parent 66f8a8cdd0
commit 4fa3ca98a2
11 changed files with 88 additions and 45 deletions
+19
View File
@@ -15,3 +15,22 @@ void ffWcharToUtf8(const wchar_t* input, FFstrbuf* result)
result->length = (uint32_t)size_needed;
result->chars[size_needed] = '\0';
}
FFstrbuf ffStrbufFromWchar(const wchar_t* input)
{
FFstrbuf result;
int len = input ? (int)wcslen(input) : 0;
if(len <= 0)
ffStrbufInit(&result);
else
{
int size_needed = WideCharToMultiByte(CP_UTF8, 0, input, len, NULL, 0, NULL, NULL);
ffStrbufInitA(&result, (uint32_t)size_needed);
WideCharToMultiByte(CP_UTF8, 0, input, len, result.chars, size_needed, NULL, NULL);
result.length = (uint32_t)size_needed;
result.chars[size_needed] = '\0';
}
return result;
}