mirror of
https://github.com/XWine1/VdCallDump.git
synced 2026-07-24 12:32:35 -07:00
31 lines
691 B
C#
31 lines
691 B
C#
using System.Runtime.CompilerServices;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace VdCallDump;
|
|
|
|
internal unsafe struct BSTR : IDisposable
|
|
{
|
|
private char* _ptr;
|
|
|
|
public readonly char** GetAddressOf()
|
|
{
|
|
return (char**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
|
|
}
|
|
|
|
public readonly ReadOnlySpan<char> AsSpan()
|
|
{
|
|
return _ptr != null ? MemoryMarshal.CreateReadOnlySpanFromNullTerminated(_ptr) : [];
|
|
}
|
|
|
|
public readonly override string ToString()
|
|
{
|
|
return _ptr != null ? Marshal.PtrToStringBSTR((nint)_ptr) : string.Empty;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Marshal.FreeBSTR((nint)_ptr);
|
|
_ptr = null;
|
|
}
|
|
}
|