private static IntPtr RuntimeStartupCallback(object parameter, RuntimeStartupCallbackDelegate callback, out IntPtr nativeParameter) { NativeRuntimeStartupCallbackDelegate native = (IntPtr cordbg, IntPtr param, HResult hresult) => { GCHandle gch = GCHandle.FromIntPtr(param); callback(ICorDebug.Create(cordbg), gch.Target, hresult); gch.Free(); }; GCHandle gchParameter = GCHandle.Alloc(parameter); nativeParameter = GCHandle.ToIntPtr(gchParameter); return(Marshal.GetFunctionPointerForDelegate(native)); }
private static IntPtr RuntimeStartupCallback(object parameter, RuntimeStartupCallbackDelegate callback, out GCHandle nativeCallbackHandle, out IntPtr nativeParameter) { NativeRuntimeStartupCallbackDelegate native = (IntPtr cordbg, IntPtr param, HResult hresult) => { GCHandle gch = GCHandle.FromIntPtr(param); callback(ICorDebug.Create(cordbg), gch.Target, hresult); gch.Free(); }; // Need to keep native callback delegate alive until UnregisterForRuntimeStartup nativeCallbackHandle = GCHandle.Alloc(native); // Need to keep parameter alive until the callback is invoked GCHandle gchParameter = GCHandle.Alloc(parameter); nativeParameter = GCHandle.ToIntPtr(gchParameter); // Return the function pointer for the native callback return(Marshal.GetFunctionPointerForDelegate(native)); }