public object CallMult(Array args) { if (numArgs != -1) { throw new InvalidOperationException(); } Array <object> hxArray = (Array <object>)args; CSHandleScope scope = CSHandleScope.Create(); GCHandle[] handles = new GCHandle[hxArray.length]; for (int i = 0; i < hxArray.length; ++i) { handles[i] = GCHandle.Alloc(hxArray[i]); } IntPtr[] pointers = new IntPtr[hxArray.length]; for (int i = 0; i < hxArray.length; ++i) { pointers[i] = GCHandle.ToIntPtr(handles[i]); } GCHandle pinnedArray = GCHandle.Alloc(pointers, GCHandleType.Pinned); CallMultDelegate cfunc = (CallMultDelegate)func; object result = HandleUtils.GetObjectFromIntPtr(cfunc(pinnedArray.AddrOfPinnedObject())); scope.Destroy(); for (int i = 0; i < hxArray.length; ++i) { handles[i].Free(); } pinnedArray.Free(); return(result); }
public object Call0() { if (numArgs != 0) { throw new InvalidOperationException(); } CSHandleScope scope = CSHandleScope.Create(); Call0Delegate cfunc = (Call0Delegate)func; object result = HandleUtils.GetObjectFromIntPtr(cfunc()); scope.Destroy(); return(result); }
private static void cs_val_gc(IntPtr inArg1, CSAbstract.FinalizerDelegate arg2) { object value = HandleUtils.GetObjectFromIntPtr(inArg1); if (value == null) { return; } if (value is CSAbstract) { CSAbstract arg1 = (CSAbstract)value; arg1.Finalizer = arg2; } else { // TODO } }