安全地将uint8_t转换为wchar_t

时间:2016-08-18 08:04:34

标签: c++ air ane

这是我在AIR和C ++之间的第一个原生扩展,也是在C ++编程中,所以我不确定在哪里寻找类型转换的帮助。

从AIR端我在uint8_t(FRE ...函数调用)中收到一个字符串。我需要使用此字符串写入注册表,其中wchar_t是预期的。 我不确定我是否可以简单地进行类型转换,或者创建相同大小和复制字符的新wchar []数组,或者我需要使用类似MultiByteToWideChar()的转换将UTF-8字符转换为wchar_t。在这种情况下,我不确定输出数组的大小是否正确。

...
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))	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);
...

1 个答案:

答案 0 :(得分:1)

std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> cv;
std::wstring dst = cv.from_bytes(src);
相关问题