mirror of
https://github.com/raylib-cs/raylib-cs
synced 2025-06-30 19:03:42 -04:00
committed by
GitHub
parent
f4c70a2872
commit
d067c6c0aa
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user