安全地将uint8_t转换为wchar_t
问题描述:
这是我在AIR和C++之间的第一个本地扩展,也是在C++编程中,所以我不确定在哪里寻找类型转换的帮助。安全地将uint8_t转换为wchar_t
从AIR端我收到一个字符串在uint8_t(FRE ...函数调用)。我需要使用此字符串写入注册表,其中wchar_t是预期的。 我不确定是否可以简单地进行类型转换,或者创建具有相同大小和复制字符的新wchar []数组,或者是否需要使用像MultiByteToWideChar()将UTF-8字符转换为wchar_t。我不确定在这种情况下输出数组的大小是否正确。如果你能字节数组写入到`的std :: stringstream`
...
FREObject retObj = NULL;
uint32_t strLength = 0;
const uint8_t *path8 = NULL;
// this is what I get from actionscript call
FREResult status = FREGetObjectAsUTF8(argv[ARG_PATH], &strLength, &path8);
if ((status != FRE_OK) || (strLength <= 0) || (path8 == NULL)) \t return retObj;
LONG hStatus;
HKEY hKey;
wchar_t *path;
// ??? how to copy uint_t into wchar_t
hStatus = RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_ALL_ACCESS, &hKey);
...
答
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> cv;
std::wstring dst = cv.from_bytes(src);
+0
谢谢。它帮助了我。对不起,作为董事会的新蜜蜂无法评价答案 – sorrex
奇迹,设置字符串流的区域用'的std :: basic_ios :: imbue'为utf8,和读回为'wchar'。如果它有效,它会非常简单易用。 – user4581301