From e224d30a0d2dad76e501ff5d25e90f1b39c73807 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 9 Jan 2015 21:07:57 +0000 Subject: WinGui: Better UTF-8 Fix, Also fixed encode class git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6704 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs index a62fb82fe..1e6fe8506 100644 --- a/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs +++ b/win/CS/HandBrake.Interop/HandBrakeInterop/HandBrakeInstance.cs @@ -492,7 +492,7 @@ namespace HandBrake.Interop }; string encode = JsonConvert.SerializeObject(encodeObject, Formatting.Indented, settings); - HBFunctions.hb_add_json(this.hbHandle, Marshal.StringToHGlobalAnsi(encode)); + HBFunctions.hb_add_json(this.hbHandle, InteropUtilities.ToUtf8PtrFromString(encode)); HBFunctions.hb_start(this.hbHandle); this.encodePollTimer = new System.Timers.Timer(); @@ -605,12 +605,8 @@ namespace HandBrake.Interop this.titles = new List(); var jsonMsg = HBFunctions.hb_get_title_set_json(this.hbHandle); - // Convert UTF-8 encoded jsonMsg to string - int length = 0; - while (Marshal.ReadByte(jsonMsg, length) != 0) length++; // find 0 termination - byte[] buffer = new byte[length]; - Marshal.Copy(jsonMsg, buffer, 0, buffer.Length); - string scanJson = Encoding.UTF8.GetString(buffer); + + string scanJson = InteropUtilities.ToStringFromUtf8Ptr(jsonMsg); JsonScanObject scanObject = JsonConvert.DeserializeObject<JsonScanObject>(scanJson); lastScan = scanObject; -- cgit v1.2.3