3

This is my very first native extension between AIR and C++, and in C++ programming as well, so I am not sure where to look for help with type conversions.

From AIR side I receive a string in uint8_t (FRE... function call). I need to use this string for writing to registry, where wchar_t is expected. I am not sure if I can simply make a type casting, or make new wchar[] array of the same size and copy characters or do I need to use someting like MultiByteToWideChar() to convert UTF-8 characters to wchar_t. Im not sure about the correct size of output array in this case.

...
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);
...
sorrex
  • 31
  • 3
  • Wonder if you can write the byte array into a `std::stringstream`, set the stringstream's locale to utf8 with `std::basic_ios::imbue`, and read back as `wchar`. If it works, it'll be brutally simple to use. – user4581301 Aug 18 '16 at 08:53

1 Answers1

2
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> cv;
std::wstring dst = cv.from_bytes(src);
J. Doe
  • 121
  • 2