(ded4a3e0a) v0.9.0.7
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace TwoMGFX
|
||||
{
|
||||
internal class MarshalHelper
|
||||
{
|
||||
public static T Unmarshal<T>(IntPtr ptr)
|
||||
{
|
||||
var type = typeof(T);
|
||||
var result = (T)Marshal.PtrToStructure(ptr, type);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static T[] UnmarshalArray<T>(IntPtr ptr, int count)
|
||||
{
|
||||
var type = typeof(T);
|
||||
var size = Marshal.SizeOf(type);
|
||||
var ret = new T[count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var offset = i * size;
|
||||
var structPtr = new IntPtr(ptr.ToInt64() + offset);
|
||||
ret[i] = (T)Marshal.PtrToStructure(structPtr, type);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static byte[] UnmarshalArray(IntPtr ptr, int count)
|
||||
{
|
||||
var result = new byte[count];
|
||||
Marshal.Copy(ptr, result, 0, count);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user