private T[] GetArrayHelper <T>(GetArrayDelegate pDelegate, Action <IntPtr, T[]> copyFunc) where T : struct { UInt32 size = 0; IntPtr values = IntPtr.Zero; PInvokeUtils.ThrowIfResult(pDelegate(this.Interface, ref size, ref values)); T[] retValues = new T[size]; copyFunc(values, retValues); Marshal.FreeCoTaskMem(values); return(retValues); }
internal static IntPtr[] GetPtrArray(GetArrayDelegate pInvokeAction) { IntPtr values = IntPtr.Zero; UInt32 size = 0; int result = pInvokeAction(ref size, ref values); ThrowIfResult(result); IntPtr[] retValues = new IntPtr[size]; if (size > 0) { Marshal.Copy(values, retValues, 0, retValues.Length); } if (values != IntPtr.Zero) { Marshal.FreeCoTaskMem(values); } return(retValues); }
private static T[] GetIntfArray <T>(GetArrayDelegate f) where T : class { f(out var h, out var cnt); return(cnt == 0 ? new T[0] : h.ToEnumerable <IntPtr>((int)cnt).Select(p => (T)Marshal.GetObjectForIUnknown(p)).ToArray()); }