0 Replies Latest reply: May 22, 2014 4:55 AM by degaia RSS

    Win32 API call results from C++ to Flash - how to pass chars to utf8

    degaia Community Member

      Hi everyone I was trying to debug the code running from an ANE i'm building from C++ to Flash

       

      This is the basic code

       

      DWORD error = NULL;

       

       

        // New way

        FREObject obj0 = NULL;

        HRSRC resource = ::FindResource(NULL, MAKEINTRESOURCE(IDR_RCDATA1), RT_RCDATA);

        if (resource != NULL){

        FRENewObjectFromUint32((UINT32)resource, &obj0);

        FRESetObjectProperty(result, (const uint8_t*)"HRSRC", obj0, NULL);

        }

        else{

        error = GetLastError();

        char * lpBuffer = new char[1024];

        if (error != 0){    // Don't want to see a "operation done successfully" error ;-)

        if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,

        NULL,

        error,

        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // default language

        (LPTSTR)lpBuffer,

        strlen(lpBuffer),

        NULL)){

        FREObject objMsg;

        FRENewObjectFromUint32(strlen(lpBuffer), &objMsg);

        FRESetObjectProperty(result, (const uint8_t*)"errorMessageLength", objMsg, NULL);

        }

        else{

        static char buffer[1024];

        _snprintf_s(buffer, sizeof(buffer), "ERROR: %s\n", lpBuffer);

        FREObject objMsg;

        FRENewObjectFromUint32(strlen(buffer), &objMsg);

        FRESetObjectProperty(result, (const uint8_t*)"errorMessageLength", objMsg, NULL);

       

       

        //char * utf8Error = new char[strlen(lpBuffer)+1];

        //WideCharToMultiByte(CP_UTF8, 0, (LPCWCH)lpBuffer, -1, utf8Error, strlen(utf8Error), NULL, NULL);

        FREObject objerr;

        FRENewObjectFromUTF8(strlen(buffer), (const uint8_t*)buffer, &objerr);

        FRESetObjectProperty(result, (const uint8_t*)"error1", objerr, NULL);

       

        }

        }

        LocalFree(lpBuffer);

        lpBuffer = NULL;

        }

       

       

      What I get inside of Flash is the UTF8 string but It's weird chararacters.

      I was wondering how is it possible to get the content of this variable

       

      char * lpBuffer = new char[1024];

       

      and transform it to fit inside of this call

       

      FRENewObjectFromUTF8(strlen(buffer), (const uint8_t*)buffer, &objerr);

       

      Thanx