+ internal class ArrayCoder : ICustomMarshaler {
+ int size = 0;
+ GCHandle pinnedArray;
+ public static ICustomMarshaler GetInstance(string pstrCookie) {
+ return new ArrayCoder();
+ }
+
+ public Object MarshalNativeToManaged(IntPtr pNativeData) { throw new NotImplementedException(); }
+ public IntPtr MarshalManagedToNative(Object obj) {
+ if (obj.GetType() == typeof(byte[])) {
+ byte[] inp = (byte[])obj;
+ IntPtr data = Marshal.AllocHGlobal(inp.Length + 8);
+ Marshal.WriteInt64(data, inp.Length);
+ Marshal.Copy(inp, 0, data + 8, inp.Length);
+ this.size = inp.Length + 8;
+ return data;
+ } else {
+ throw new NotImplementedException();
+ }
+ }
+ public void CleanUpNativeData(IntPtr pNativeData) {
+ Marshal.FreeHGlobal(pNativeData);
+ }
+ public void CleanUpManagedData(Object ManagedObj) { }
+ public int GetNativeDataSize() {
+ // Blindly guess based on the last allocation, no idea how else to implement this.
+ return this.size;
+ }
+ }
+