This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 416
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #74 by adding support for UTF-8 in options
- Loading branch information
1 parent
3fd6915
commit eaa8f54
Showing
3 changed files
with
29 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 27 additions & 6 deletions
33
src/Vlc.DotNet.Core.Interops/VlcManager.CreateNewInstance.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
using Vlc.DotNet.Core.Interops.Signatures; | ||
|
||
namespace Vlc.DotNet.Core.Interops | ||
namespace Vlc.DotNet.Core.Interops | ||
{ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Vlc.DotNet.Core.Interops.Signatures; | ||
using System.Text; | ||
|
||
public sealed partial class VlcManager | ||
{ | ||
public void CreateNewInstance(string[] args) | ||
{ | ||
if (args == null) | ||
args = new string[0]; | ||
myVlcInstance = new VlcInstance(this, GetInteropDelegate<CreateNewInstance>().Invoke(args.Length, args)); | ||
IntPtr[] utf8Args = new IntPtr[args?.Length ?? 0]; | ||
try | ||
{ | ||
for (var i = 0; i < utf8Args.Length; i++) | ||
{ | ||
byte[] bytes = Encoding.UTF8.GetBytes(args[i]); | ||
var buffer = Marshal.AllocHGlobal(bytes.Length + 1); | ||
Marshal.Copy(bytes, 0, buffer, bytes.Length); | ||
Marshal.WriteByte(buffer, bytes.Length, 0); | ||
utf8Args[i] = buffer; | ||
} | ||
|
||
myVlcInstance = new VlcInstance(this, GetInteropDelegate<CreateNewInstance>().Invoke(utf8Args.Length, utf8Args)); | ||
} | ||
finally | ||
{ | ||
foreach (var arg in utf8Args) | ||
{ | ||
Marshal.FreeHGlobal(arg); | ||
} | ||
} | ||
} | ||
} | ||
} |