Seperate UTF8 from Ansi
This commit is contained in:
parent
e29d28de6b
commit
be61ce992b
5 changed files with 102 additions and 49 deletions
36
Raylib-cs/types/native/AnsiBuffer.cs
Normal file
36
Raylib-cs/types/native/AnsiBuffer.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts text to a Ansi buffer for passing to native code
|
||||
/// </summary>
|
||||
public readonly ref struct AnsiBuffer
|
||||
{
|
||||
private readonly IntPtr data;
|
||||
|
||||
public AnsiBuffer(string text)
|
||||
{
|
||||
data = Marshal.StringToHGlobalAnsi(text);
|
||||
}
|
||||
|
||||
public unsafe sbyte* AsPointer()
|
||||
{
|
||||
return (sbyte*)data.ToPointer();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Marshal.FreeHGlobal(data);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnsiStringUtils
|
||||
{
|
||||
public static AnsiBuffer ToAnsiBuffer(this string text)
|
||||
{
|
||||
return new AnsiBuffer(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
using System;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace Raylib_cs
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts text to a UTF8 buffer for passing to native code
|
||||
/// </summary>
|
||||
public ref struct UTF8Buffer
|
||||
public readonly ref struct UTF8Buffer
|
||||
{
|
||||
private IntPtr data;
|
||||
private readonly IntPtr data;
|
||||
|
||||
public UTF8Buffer(string text)
|
||||
{
|
||||
this.data = Marshal.StringToHGlobalAnsi(text);
|
||||
data = Marshal.StringToCoTaskMemUTF8(text);
|
||||
}
|
||||
|
||||
public unsafe sbyte* AsPointer()
|
||||
|
|
@ -23,7 +23,7 @@ namespace Raylib_cs
|
|||
|
||||
public void Dispose()
|
||||
{
|
||||
Marshal.FreeHGlobal(data);
|
||||
Marshal.ZeroFreeCoTaskMemUTF8(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue