示例#1
0
 internal static string GetAsString(IntPtr cefStringPtr)
 {
     unsafe
     {
         char *rawCefString_char16_t;
         int   actualLen;
         Cef3Binder.MyCefStringGetRawPtr(cefStringPtr, out rawCefString_char16_t, out actualLen);
         return(new string(rawCefString_char16_t, 0, actualLen));
     }
 }
示例#2
0
        unsafe static string MyCefJsReadString(JsValue *jsval)
        {
            int actualLen;
            int buffLen = jsval->I32 + 1; //string len

            //check if string is on method-call's frame stack or heap
            if (jsval->Type == JsValueType.NativeCefString)
            {
                char *rawCefString_char16_t;
                Cef3Binder.MyCefStringGetRawPtr(jsval->Ptr, out rawCefString_char16_t, out actualLen);
                return(new string(rawCefString_char16_t, 0, actualLen));
            }
            if (buffLen < 1024)
            {
                char *buffHead = stackalloc char[buffLen];
                Cef3Binder.MyCefStringHolder_Read(jsval->Ptr, buffHead, buffLen, out actualLen);
                if (actualLen > buffLen)
                {
                    //read more
                }
                return(new string(buffHead, 0, actualLen));
            }
            else
            {
                char[] buffHead = new char[buffLen];
                fixed(char *h = &buffHead[0])
                {
                    Cef3Binder.MyCefStringHolder_Read(jsval->Ptr, h, buffLen, out actualLen);
                    if (actualLen > buffLen)
                    {
                        //read more
                    }
                }

                return(new string(buffHead, 0, actualLen));
            }
        }