From 4df33c8318de51ca723ffaae3e9799264299b06a Mon Sep 17 00:00:00 2001 From: "dotnet-maestro[bot]" <42748379+dotnet-maestro[bot]@users.noreply.github.com> Date: Wed, 8 Jun 2022 07:55:36 -0500 Subject: [PATCH] [main] Update dependencies from 8 repositories (#69709) * Update dependencies from https://github.com/dotnet/icu build 20220523.1 Microsoft.NETCore.Runtime.ICU.Transport From Version 7.0.0-preview.5.22269.3 -> To Version 7.0.0-preview.5.22273.1 * Update dependencies from https://github.com/dotnet/xharness build 20220524.1 Microsoft.DotNet.XHarness.CLI , Microsoft.DotNet.XHarness.TestRunners.Common , Microsoft.DotNet.XHarness.TestRunners.Xunit From Version 1.0.0-prerelease.22270.1 -> To Version 1.0.0-prerelease.22274.1 * Update dependencies from https://github.com/dotnet/runtime-assets build 20220523.1 Microsoft.DotNet.CilStrip.Sources , System.ComponentModel.TypeConverter.TestData , System.Drawing.Common.TestData , System.Formats.Tar.TestData , System.IO.Compression.TestData , System.IO.Packaging.TestData , System.Net.TestData , System.Private.Runtime.UnicodeData , System.Runtime.Numerics.TestData , System.Runtime.TimeZoneData , System.Security.Cryptography.X509Certificates.TestData , System.Text.RegularExpressions.TestData , System.Windows.Extensions.TestData From Version 7.0.0-beta.22267.1 -> To Version 7.0.0-beta.22273.1 * Update dependencies from https://github.com/dotnet/roslyn-analyzers build 20220524.2 Microsoft.CodeAnalysis.NetAnalyzers From Version 7.0.0-preview1.22252.2 -> To Version 7.0.0-preview1.22274.2 * Update dependencies from https://github.com/dotnet/msquic build 20220523.2 System.Net.MsQuic.Transport From Version 7.0.0-alpha.1.22273.1 -> To Version 7.0.0-alpha.1.22273.2 * Update dependencies from https://github.com/dotnet/icu build 20220525.2 Microsoft.NETCore.Runtime.ICU.Transport From Version 7.0.0-preview.5.22269.3 -> To Version 7.0.0-preview.6.22275.2 * Update dependencies from https://github.com/dotnet/emsdk build 20220525.2 Microsoft.NET.Workload.Emscripten.Manifest-7.0.100 From Version 7.0.0-preview.5.22268.1 -> To Version 7.0.0-preview.6.22275.2 * Update dependencies from https://github.com/dotnet/xharness build 20220526.1 Microsoft.DotNet.XHarness.CLI , Microsoft.DotNet.XHarness.TestRunners.Common , Microsoft.DotNet.XHarness.TestRunners.Xunit From Version 1.0.0-prerelease.22270.1 -> To Version 1.0.0-prerelease.22276.1 * Update dependencies from https://github.com/dotnet/emsdk build 20220525.3 Microsoft.NET.Workload.Emscripten.Manifest-7.0.100 From Version 7.0.0-preview.5.22268.1 -> To Version 7.0.0-preview.6.22275.3 * Update dependencies from https://github.com/dotnet/roslyn-analyzers build 20220527.2 Microsoft.CodeAnalysis.NetAnalyzers From Version 7.0.0-preview1.22252.2 -> To Version 7.0.0-preview1.22277.2 * Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20220529.1 optimization.linux-x64.MIBC.Runtime , optimization.windows_nt-x64.MIBC.Runtime , optimization.windows_nt-x86.MIBC.Runtime , optimization.PGO.CoreCLR From Version 1.0.0-prerelease.22217.3 -> To Version 1.0.0-prerelease.22279.1 * Update dependencies from https://github.com/dotnet/runtime build 20220529.1 Microsoft.NET.Sdk.IL , Microsoft.NETCore.App.Runtime.win-x64 , Microsoft.NETCore.DotNetHost , Microsoft.NETCore.DotNetHostPolicy , Microsoft.NETCore.ILAsm , runtime.native.System.IO.Ports , System.Text.Json From Version 7.0.0-preview.5.22272.3 -> To Version 7.0.0-preview.6.22279.1 * Update dependencies from https://github.com/dotnet/icu build 20220530.1 Microsoft.NETCore.Runtime.ICU.Transport From Version 7.0.0-preview.5.22269.3 -> To Version 7.0.0-preview.6.22280.1 * Update dependencies from https://github.com/dotnet/icu build 20220530.2 Microsoft.NETCore.Runtime.ICU.Transport From Version 7.0.0-preview.5.22269.3 -> To Version 7.0.0-preview.6.22280.2 * Update dependencies from https://github.com/dotnet/xharness build 20220530.1 Microsoft.DotNet.XHarness.CLI , Microsoft.DotNet.XHarness.TestRunners.Common , Microsoft.DotNet.XHarness.TestRunners.Xunit From Version 1.0.0-prerelease.22270.1 -> To Version 1.0.0-prerelease.22280.1 * Add manual marshalling for non-blittable delegates defined in System.Drawing.Common (which has the DisableRuntimeMarshallingAttribute applied) passed to P/Invokes. * Update dependencies from https://github.com/dotnet/xharness build 20220601.1 Microsoft.DotNet.XHarness.CLI , Microsoft.DotNet.XHarness.TestRunners.Common , Microsoft.DotNet.XHarness.TestRunners.Xunit From Version 1.0.0-prerelease.22270.1 -> To Version 1.0.0-prerelease.22301.1 * Update dependencies from https://github.com/dotnet/runtime-assets build 20220531.1 Microsoft.DotNet.CilStrip.Sources , System.ComponentModel.TypeConverter.TestData , System.Drawing.Common.TestData , System.Formats.Tar.TestData , System.IO.Compression.TestData , System.IO.Packaging.TestData , System.Net.TestData , System.Private.Runtime.UnicodeData , System.Runtime.Numerics.TestData , System.Runtime.TimeZoneData , System.Security.Cryptography.X509Certificates.TestData , System.Text.RegularExpressions.TestData , System.Windows.Extensions.TestData From Version 7.0.0-beta.22267.1 -> To Version 7.0.0-beta.22281.1 * Update dependencies from https://github.com/dotnet/emsdk build 20220531.1 Microsoft.NET.Workload.Emscripten.Manifest-7.0.100 From Version 7.0.0-preview.5.22268.1 -> To Version 7.0.0-preview.6.22281.1 * Update dependencies from https://github.com/dotnet/msquic build 20220531.1 System.Net.MsQuic.Transport From Version 7.0.0-alpha.1.22273.1 -> To Version 7.0.0-alpha.1.22281.1 * Update dependencies from https://github.com/dotnet/roslyn-analyzers build 20220601.1 Microsoft.CodeAnalysis.NetAnalyzers From Version 7.0.0-preview1.22252.2 -> To Version 7.0.0-preview1.22301.1 * Update dependencies from https://github.com/dotnet/msquic build 20220601.1 System.Net.MsQuic.Transport From Version 7.0.0-alpha.1.22273.1 -> To Version 7.0.0-alpha.1.22301.1 * Move OleDB to use more manual marshalling instead of delegate marshalling. * Update dependencies from https://github.com/dotnet/roslyn-analyzers build 20220602.1 Microsoft.CodeAnalysis.NetAnalyzers From Version 7.0.0-preview1.22252.2 -> To Version 7.0.0-preview1.22302.1 * Update dependencies from https://github.com/dotnet/runtime build 20220605.4 Microsoft.NET.Sdk.IL , Microsoft.NETCore.App.Runtime.win-x64 , Microsoft.NETCore.DotNetHost , Microsoft.NETCore.DotNetHostPolicy , Microsoft.NETCore.ILAsm , runtime.native.System.IO.Ports , System.Text.Json From Version 7.0.0-preview.5.22272.3 -> To Version 7.0.0-preview.6.22305.4 * Update dependencies from https://github.com/dotnet/xharness build 20220605.1 Microsoft.DotNet.XHarness.CLI , Microsoft.DotNet.XHarness.TestRunners.Common , Microsoft.DotNet.XHarness.TestRunners.Xunit From Version 1.0.0-prerelease.22270.1 -> To Version 1.0.0-prerelease.22305.1 * Update dependencies from https://github.com/dotnet/icu build 20220606.1 Microsoft.NETCore.Runtime.ICU.Transport From Version 7.0.0-preview.5.22269.3 -> To Version 7.0.0-preview.6.22306.1 Co-authored-by: dotnet-maestro[bot] Co-authored-by: Larry Ewing Co-authored-by: Jeremy Koritzinsky --- .config/dotnet-tools.json | 2 +- eng/Version.Details.xml | 124 +++++++++--------- eng/Versions.props | 60 ++++----- global.json | 2 +- .../System.Data.OleDb/src/OleDbWrapper.cs | 111 ++++++++++++++-- .../src/UnsafeNativeMethods.cs | 26 ++-- .../src/System/Drawing/GdiplusNative.cs | 102 +++++++++++--- .../src/System/Drawing/Graphics.cs | 59 +++++++++ .../src/System/Drawing/Image.cs | 28 ++++ 9 files changed, 379 insertions(+), 135 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 4ecf1c67a9938..76d5359f980ba 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -15,7 +15,7 @@ ] }, "microsoft.dotnet.xharness.cli": { - "version": "1.0.0-prerelease.22270.1", + "version": "1.0.0-prerelease.22305.1", "commands": [ "xharness" ] diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 346cd4414a5aa..df1d92585c1e8 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -1,16 +1,16 @@ - + https://github.com/dotnet/icu - 769d436d511fc775473f2cd9dff15afbe5566010 + 7c13e1a1740e54ba0c9b38636ae36195c9e9d3bd - + https://github.com/dotnet/msquic - e9fbff6a1de0e390a636dc73dcd986ffa2ee88e7 + b4d67ca60d3f819e2450095ab8a33a9f65513e4a - + https://github.com/dotnet/emsdk - dca71051151e0515887671938196f3b87ad1c19f + ea10b4e5534de1806cc2e84ddd3b00eabcab962f https://github.com/dotnet/wcf @@ -130,53 +130,53 @@ https://github.com/microsoft/vstest 140434f7109d357d0158ade9e5164a4861513965 - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf https://github.com/dotnet/llvm-project @@ -210,81 +210,81 @@ https://github.com/dotnet/llvm-project 54cc196d506692c366d9e116cdb3a9a56342f720 - + https://github.com/dotnet/runtime - 0864cc5539e0ddd109b443b0bee804878cd7ba76 + f21ace52e357bbf0019da5c9e42d66705a087235 - + https://github.com/dotnet/runtime - 0864cc5539e0ddd109b443b0bee804878cd7ba76 + f21ace52e357bbf0019da5c9e42d66705a087235 - + https://github.com/dotnet/runtime - 0864cc5539e0ddd109b443b0bee804878cd7ba76 + f21ace52e357bbf0019da5c9e42d66705a087235 - + https://github.com/dotnet/runtime - 0864cc5539e0ddd109b443b0bee804878cd7ba76 + f21ace52e357bbf0019da5c9e42d66705a087235 - + https://github.com/dotnet/runtime - 0864cc5539e0ddd109b443b0bee804878cd7ba76 + f21ace52e357bbf0019da5c9e42d66705a087235 - + https://github.com/dotnet/runtime - 0864cc5539e0ddd109b443b0bee804878cd7ba76 + f21ace52e357bbf0019da5c9e42d66705a087235 - + https://github.com/dotnet/runtime - 0864cc5539e0ddd109b443b0bee804878cd7ba76 + f21ace52e357bbf0019da5c9e42d66705a087235 https://github.com/dotnet/linker 1481a51970586b26208a7bc6173dc77d658f3508 - + https://github.com/dotnet/xharness - 9cacd2f874c946a6497110124a2369fb5131c68f + a1d9a67e971fc0b8724507847491fe93f65728db - + https://github.com/dotnet/xharness - 9cacd2f874c946a6497110124a2369fb5131c68f + a1d9a67e971fc0b8724507847491fe93f65728db - + https://github.com/dotnet/xharness - 9cacd2f874c946a6497110124a2369fb5131c68f + a1d9a67e971fc0b8724507847491fe93f65728db https://github.com/dotnet/arcade ba1c3aff4be864c493031d989259ef92aaa23fc3 - + https://dev.azure.com/dnceng/internal/_git/dotnet-optimization - 198a04ad65a5c0731fb96dbc464f0a2a25812aff + d5b85fdae5fa46aa3955218446fb6809aeffb476 - + https://dev.azure.com/dnceng/internal/_git/dotnet-optimization - 198a04ad65a5c0731fb96dbc464f0a2a25812aff + d5b85fdae5fa46aa3955218446fb6809aeffb476 - + https://dev.azure.com/dnceng/internal/_git/dotnet-optimization - 198a04ad65a5c0731fb96dbc464f0a2a25812aff + d5b85fdae5fa46aa3955218446fb6809aeffb476 - + https://dev.azure.com/dnceng/internal/_git/dotnet-optimization - 198a04ad65a5c0731fb96dbc464f0a2a25812aff + d5b85fdae5fa46aa3955218446fb6809aeffb476 https://github.com/dotnet/hotreload-utils 3c641f5b79f90b0341bc0b6f728bae56ede711fd - + https://github.com/dotnet/runtime-assets - bef6668f71c27e2e25d63712cbf02f67ef8c7863 + 0920468fa7db4ee8ea8bbcba186421cb92713adf - + https://github.com/dotnet/roslyn-analyzers - d2ef898a6283858c1224c0114cd87fa27b6cb091 + 114d5f2927b8afc90f169df80fdcbe8c7a644bac https://github.com/dotnet/sdk diff --git a/eng/Versions.props b/eng/Versions.props index ae0db208b95d2..86bf5b84d9a36 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -44,7 +44,7 @@ 4.3.0-1.22206.2 4.3.0-1.22206.2 4.3.0-1.22206.2 - 7.0.0-preview1.22252.2 + 7.0.0-preview1.22302.1 4.3.0-1.22206.2 6.0.0-preview.1.102 - 7.0.0-preview.5.22272.3 - 7.0.0-preview.5.22272.3 - 7.0.0-preview.5.22272.3 + 7.0.0-preview.6.22305.4 + 7.0.0-preview.6.22305.4 + 7.0.0-preview.6.22305.4 3.1.0 - 7.0.0-preview.5.22272.3 + 7.0.0-preview.6.22305.4 1.0.0-alpha.1.22252.1 1.0.0-alpha.1.22252.1 1.0.0-alpha.1.22252.1 @@ -111,30 +111,30 @@ 5.0.0 5.0.0 4.9.0 - 7.0.0-preview.5.22272.3 + 7.0.0-preview.6.22305.4 6.0.0 4.5.4 4.5.0 - 7.0.0-preview.5.22272.3 + 7.0.0-preview.6.22305.4 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 - 7.0.0-beta.22267.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 + 7.0.0-beta.22281.1 - 1.0.0-prerelease.22217.3 - 1.0.0-prerelease.22217.3 - 1.0.0-prerelease.22217.3 - 1.0.0-prerelease.22217.3 + 1.0.0-prerelease.22279.1 + 1.0.0-prerelease.22279.1 + 1.0.0-prerelease.22279.1 + 1.0.0-prerelease.22279.1 16.9.0-beta1.21055.5 2.0.0-beta3.22114.1 @@ -150,9 +150,9 @@ 1.1.0 16.9.0-preview-20201201-01 - 1.0.0-prerelease.22270.1 - 1.0.0-prerelease.22270.1 - 1.0.0-prerelease.22270.1 + 1.0.0-prerelease.22305.1 + 1.0.0-prerelease.22305.1 + 1.0.0-prerelease.22305.1 1.1.0-alpha.0.22306.2 2.4.2-pre.22 0.12.0-pre.20 @@ -171,9 +171,9 @@ 7.0.100-1.22306.1 $(MicrosoftNETILLinkTasksVersion) - 7.0.0-preview.5.22269.3 + 7.0.0-preview.6.22306.1 - 7.0.0-alpha.1.22273.1 + 7.0.0-alpha.1.22301.1 11.1.0-alpha.1.22259.2 11.1.0-alpha.1.22259.2 @@ -184,7 +184,7 @@ 11.1.0-alpha.1.22259.2 11.1.0-alpha.1.22259.2 - 7.0.0-preview.5.22268.1 + 7.0.0-preview.6.22281.1 $(MicrosoftNETWorkloadEmscriptenManifest70100Version) 1.1.87-gba258badda diff --git a/global.json b/global.json index 7fb0faf6d58ee..7809f8ebf190d 100644 --- a/global.json +++ b/global.json @@ -13,6 +13,6 @@ "Microsoft.DotNet.SharedFramework.Sdk": "7.0.0-beta.22266.1", "Microsoft.Build.NoTargets": "3.5.0", "Microsoft.Build.Traversal": "3.1.6", - "Microsoft.NET.Sdk.IL": "7.0.0-preview.5.22272.3" + "Microsoft.NET.Sdk.IL": "7.0.0-preview.6.22305.4" } } diff --git a/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs b/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs index bc458f68223e2..bb7f00064c3c1 100644 --- a/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs +++ b/src/libraries/System.Data.OleDb/src/OleDbWrapper.cs @@ -43,7 +43,7 @@ internal OleDbServicesWrapper(object? unknown) : base() } } - internal void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper datasrcWrapper) + internal unsafe void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper datasrcWrapper) { OleDbHResult hr; UnsafeNativeMethods.IDataInitializeGetDataSource GetDataSource = DangerousIDataInitializeGetDataSource!; @@ -59,7 +59,31 @@ internal void GetDataSource(OleDbConnectionString constr, ref DataSourceWrapper // base.handle is the 'this' pointer for making the COM call to GetDataSource // the datasrcWrapper will store the IID_IDBInitialize pointer // call IDataInitiailze::GetDataSource via the delegate - hr = GetDataSource(base.handle, IntPtr.Zero, ODB.CLSCTX_ALL, connectionString, ref ODB.IID_IDBInitialize, ref datasrcWrapper); + fixed (char* connectionStringPtr = connectionString) + fixed (Guid* riid = &ODB.IID_IDBInitialize) + { + bool addRefd = false; + DataSourceWrapper newWrapper = new DataSourceWrapper(); + datasrcWrapper.DangerousAddRef(ref addRefd); + IntPtr originalHandle = datasrcWrapper.DangerousGetHandle(); + IntPtr handle = originalHandle; + try + { + hr = GetDataSource(base.handle, IntPtr.Zero, ODB.CLSCTX_ALL, connectionStringPtr, riid, &handle); + } + finally + { + if (addRefd) + { + datasrcWrapper.DangerousRelease(); + } + if (handle != originalHandle) + { + Marshal.InitHandle(newWrapper, handle); + datasrcWrapper = newWrapper; + } + } + } } finally { @@ -98,7 +122,7 @@ public DataSourceWrapper() : base() { } - internal OleDbHResult InitializeAndCreateSession(OleDbConnectionString constr, ref SessionWrapper sessionWrapper) + internal unsafe OleDbHResult InitializeAndCreateSession(OleDbConnectionString constr, ref SessionWrapper sessionWrapper) { OleDbHResult hr; bool mustRelease = false; @@ -149,7 +173,10 @@ internal OleDbHResult InitializeAndCreateSession(OleDbConnectionString constr, r if ((0 <= hr) || (OleDbHResult.DB_E_ALREADYINITIALIZED == hr)) { // call IUnknown::QueryInterface via the delegate - hr = (OleDbHResult)QueryInterface(base.handle, ref ODB.IID_IDBCreateSession, ref idbCreateSession); + fixed (Guid* riid = &ODB.IID_IDBCreateSession) + { + hr = (OleDbHResult)QueryInterface(base.handle, riid, &idbCreateSession); + } if ((0 <= hr) && (IntPtr.Zero != idbCreateSession)) { // native COM rules are the QI result is the 'this' pointer @@ -172,7 +199,30 @@ internal OleDbHResult InitializeAndCreateSession(OleDbConnectionString constr, r if (null != constr.DangerousIDBCreateCommandCreateCommand) { // call IDBCreateSession::CreateSession via the delegate directly for IDBCreateCommand - hr = CreateSession(idbCreateSession, IntPtr.Zero, ref ODB.IID_IDBCreateCommand, ref sessionWrapper); + fixed (Guid* riid = &ODB.IID_IDBCreateCommand) + { + bool addRefd = false; + SessionWrapper newWrapper = new SessionWrapper(); + sessionWrapper.DangerousAddRef(ref addRefd); + IntPtr originalHandle = sessionWrapper.DangerousGetHandle(); + IntPtr handle = originalHandle; + try + { + hr = CreateSession(idbCreateSession, IntPtr.Zero, riid, &handle); + } + finally + { + if (addRefd) + { + sessionWrapper.DangerousRelease(); + } + if (handle != originalHandle) + { + Marshal.InitHandle(newWrapper, handle); + sessionWrapper = newWrapper; + } + } + } if ((0 <= hr) && !sessionWrapper.IsInvalid) { // double check the cached delegate is correct @@ -182,7 +232,30 @@ internal OleDbHResult InitializeAndCreateSession(OleDbConnectionString constr, r else { // otherwise ask for IUnknown (it may be first time usage or IDBCreateCommand not supported) - hr = CreateSession(idbCreateSession, IntPtr.Zero, ref ODB.IID_IUnknown, ref sessionWrapper); + fixed (Guid* riid = &ODB.IID_IUnknown) + { + bool addRefd = false; + SessionWrapper newWrapper = new SessionWrapper(); + sessionWrapper.DangerousAddRef(ref addRefd); + IntPtr originalHandle = sessionWrapper.DangerousGetHandle(); + IntPtr handle = originalHandle; + try + { + hr = CreateSession(idbCreateSession, IntPtr.Zero, riid, &handle); + } + finally + { + if (addRefd) + { + sessionWrapper.DangerousRelease(); + } + if (handle != originalHandle) + { + Marshal.InitHandle(newWrapper, handle); + sessionWrapper = newWrapper; + } + } + } if ((0 <= hr) && !sessionWrapper.IsInvalid) { // and check support for IDBCreateCommand and create delegate for CreateCommand @@ -238,7 +311,7 @@ public SessionWrapper() : base() // if OleDbConnectionString.DangerousIDBCreateCommandCreateCommand does not exist // this method will be called to query for IDBCreateCommand (and cache that interface pointer) // or it will be known that IDBCreateCommand is not supported - internal void QueryInterfaceIDBCreateCommand(OleDbConnectionString constr) + internal unsafe void QueryInterfaceIDBCreateCommand(OleDbConnectionString constr) { // DangerousAddRef/DangerousRelease are not neccessary here in the current implementation // only used from within OleDbConnectionInternal.ctor->DataSourceWrapper.InitializeAndCreateSession @@ -266,7 +339,11 @@ internal void QueryInterfaceIDBCreateCommand(OleDbConnectionString constr) IntPtr method = Marshal.ReadIntPtr(vtable, 0); UnsafeNativeMethods.IUnknownQueryInterface QueryInterface = (UnsafeNativeMethods.IUnknownQueryInterface)Marshal.GetDelegateForFunctionPointer(method, typeof(UnsafeNativeMethods.IUnknownQueryInterface)); - int hresult = QueryInterface(base.handle, ref ODB.IID_IDBCreateCommand, ref idbCreateCommand); + int hresult; + fixed (Guid* riid = &ODB.IID_IDBCreateCommand) + { + hresult = QueryInterface(base.handle, riid, &idbCreateCommand); + } if ((0 <= hresult) && (IntPtr.Zero != idbCreateCommand)) { vtable = Marshal.ReadIntPtr(idbCreateCommand, 0); @@ -321,21 +398,32 @@ internal void VerifyIDBCreateCommand(OleDbConnectionString constr) DangerousIDBCreateCommandCreateCommand = CreateCommand; } - internal OleDbHResult CreateCommand(ref object? icommandText) + internal unsafe OleDbHResult CreateCommand(ref object? icommandText) { // if (null == CreateCommand), the IDBCreateCommand isn't supported - aka E_NOINTERFACE OleDbHResult hr = OleDbHResult.E_NOINTERFACE; UnsafeNativeMethods.IDBCreateCommandCreateCommand? CreateCommand = DangerousIDBCreateCommandCreateCommand; if (null != CreateCommand) { + IntPtr nativeICommandText = IntPtr.Zero; bool mustRelease = false; RuntimeHelpers.PrepareConstrainedRegions(); try { DangerousAddRef(ref mustRelease); - // call IDBCreateCommand::CreateCommand via the delegate directly for IDBCreateCommand - hr = CreateCommand(base.handle, IntPtr.Zero, ref ODB.IID_ICommandText, ref icommandText); + if (icommandText is not null) + { + nativeICommandText = Marshal.GetIUnknownForObject(icommandText); + } + + fixed (Guid* riid = &ODB.IID_ICommandText) + { + // call IDBCreateCommand::CreateCommand via the delegate directly for IDBCreateCommand + hr = CreateCommand(base.handle, IntPtr.Zero, riid, &nativeICommandText); + } + + icommandText = Marshal.GetObjectForIUnknown(nativeICommandText); } finally { @@ -343,6 +431,7 @@ internal OleDbHResult CreateCommand(ref object? icommandText) { DangerousRelease(); } + Marshal.Release(nativeICommandText); } } return hr; diff --git a/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs b/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs index ed5bbe6d69ae0..8238379f70105 100644 --- a/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs +++ b/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs @@ -773,20 +773,20 @@ System.Data.OleDb.OleDbHResult StartTransaction( // dangerous delegate around IUnknown::QueryInterface (0th vtable entry) [SuppressUnmanagedCodeSecurity] - internal delegate int IUnknownQueryInterface( + internal unsafe delegate int IUnknownQueryInterface( IntPtr pThis, - ref Guid riid, - ref IntPtr ppInterface); + Guid* riid, + IntPtr* ppInterface); // dangerous delegate around IDataInitialize::GetDataSource (4th vtable entry) [SuppressUnmanagedCodeSecurity] - internal delegate System.Data.OleDb.OleDbHResult IDataInitializeGetDataSource( + internal unsafe delegate System.Data.OleDb.OleDbHResult IDataInitializeGetDataSource( IntPtr pThis, // first parameter is always the 'this' value, must use use result from QI IntPtr pUnkOuter, int dwClsCtx, - [MarshalAs(UnmanagedType.LPWStr)] string pwszInitializationString, - ref Guid riid, - ref System.Data.OleDb.DataSourceWrapper ppDataSource); + char* pwszInitializationString, + Guid* riid, + IntPtr* ppDataSource); // dangerous wrapper around IDBInitialize::Initialize (4th vtable entry) [SuppressUnmanagedCodeSecurity] @@ -795,19 +795,19 @@ internal delegate System.Data.OleDb.OleDbHResult IDBInitializeInitialize( // dangerous wrapper around IDBCreateSession::CreateSession (4th vtable entry) [SuppressUnmanagedCodeSecurity] - internal delegate System.Data.OleDb.OleDbHResult IDBCreateSessionCreateSession( + internal unsafe delegate System.Data.OleDb.OleDbHResult IDBCreateSessionCreateSession( IntPtr pThis, // first parameter is always the 'this' value, must use use result from QI IntPtr pUnkOuter, - ref Guid riid, - ref System.Data.OleDb.SessionWrapper ppDBSession); + Guid* riid, + IntPtr* ppDBSession); // dangerous wrapper around IDBCreateCommand::CreateCommand (4th vtable entry) [SuppressUnmanagedCodeSecurity] - internal delegate System.Data.OleDb.OleDbHResult IDBCreateCommandCreateCommand( + internal unsafe delegate System.Data.OleDb.OleDbHResult IDBCreateCommandCreateCommand( IntPtr pThis, // first parameter is always the 'this' value, must use use result from QI IntPtr pUnkOuter, - ref Guid riid, - [MarshalAs(UnmanagedType.Interface)] ref object? ppCommand); + Guid* riid, + IntPtr* ppCommand); // // Advapi32.dll Integrated security functions diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs index 660bb5d7bed3b..0b43bd7686993 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs @@ -3281,7 +3281,11 @@ internal static partial int GdipDrawImageRectRectI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef imageAttributes, Graphics.DrawImageAbort? callback, + HandleRef imageAttributes, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.DrawImageAbortMarshaller))] +#endif + Graphics.DrawImageAbort? callback, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -3300,7 +3304,11 @@ internal static partial int GdipDrawImagePointsRect( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef imageAttributes, Graphics.DrawImageAbort? callback, + HandleRef imageAttributes, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.DrawImageAbortMarshaller))] +#endif + Graphics.DrawImageAbort? callback, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -3319,7 +3327,11 @@ internal static partial int GdipDrawImageRectRect( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef imageAttributes, Graphics.DrawImageAbort? callback, + HandleRef imageAttributes, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.DrawImageAbortMarshaller))] +#endif + Graphics.DrawImageAbort? callback, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -3338,7 +3350,11 @@ internal static partial int GdipDrawImagePointsRectI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef imageAttributes, Graphics.DrawImageAbort? callback, + HandleRef imageAttributes, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.DrawImageAbortMarshaller))] +#endif + Graphics.DrawImageAbort? callback, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4029,7 +4045,11 @@ internal static partial int GdipGetImageThumbnail( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef image, int thumbWidth, int thumbHeight, out IntPtr thumbImage, Image.GetThumbnailImageAbort? callback, IntPtr callbackdata); + HandleRef image, int thumbWidth, int thumbHeight, out IntPtr thumbImage, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Image.GetThumbnailImageAbortMarshaller))] +#endif + Image.GetThumbnailImageAbort? callback, IntPtr callbackdata); [LibraryImport(LibraryName)] internal static partial int GdipGetImagePalette( @@ -4131,7 +4151,11 @@ internal static partial int GdipEnumerateMetafileDestPoint( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, ref PointF destPoint, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, ref PointF destPoint, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4146,7 +4170,11 @@ internal static partial int GdipEnumerateMetafileDestPointI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, ref Point destPoint, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, ref Point destPoint, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4161,7 +4189,11 @@ internal static partial int GdipEnumerateMetafileDestRect( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, ref RectangleF destRect, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, ref RectangleF destRect, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4176,7 +4208,11 @@ internal static partial int GdipEnumerateMetafileDestRectI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, ref Rectangle destRect, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, ref Rectangle destRect, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4191,7 +4227,11 @@ internal static partial int GdipEnumerateMetafileDestPoints( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, PointF* destPoints, int count, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, PointF* destPoints, int count, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4206,7 +4246,11 @@ internal static partial int GdipEnumerateMetafileDestPointsI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, Point* destPoints, int count, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, Point* destPoints, int count, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4221,7 +4265,11 @@ internal static partial int GdipEnumerateMetafileSrcRectDestPoint( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, ref PointF destPoint, ref RectangleF srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, ref PointF destPoint, ref RectangleF srcRect, GraphicsUnit pageUnit, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4236,7 +4284,11 @@ internal static partial int GdipEnumerateMetafileSrcRectDestPointI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, ref Point destPoint, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, ref Point destPoint, ref Rectangle srcRect, GraphicsUnit pageUnit, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4251,7 +4303,11 @@ internal static partial int GdipEnumerateMetafileSrcRectDestRect( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, ref RectangleF destRect, ref RectangleF srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, ref RectangleF destRect, ref RectangleF srcRect, GraphicsUnit pageUnit, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4266,7 +4322,11 @@ internal static partial int GdipEnumerateMetafileSrcRectDestRectI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, ref Rectangle destRect, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, ref Rectangle destRect, ref Rectangle srcRect, GraphicsUnit pageUnit, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4281,7 +4341,11 @@ internal static partial int GdipEnumerateMetafileSrcRectDestPoints( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, PointF* destPoints, int count, ref RectangleF srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, PointF* destPoints, int count, ref RectangleF srcRect, GraphicsUnit pageUnit, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif @@ -4296,7 +4360,11 @@ internal static partial int GdipEnumerateMetafileSrcRectDestPointsI( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef metafile, Point* destPoints, int count, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, + HandleRef metafile, Point* destPoints, int count, ref Rectangle srcRect, GraphicsUnit pageUnit, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(Graphics.EnumerateMetafileProcMarshaller))] +#endif + Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs index b779a7d4a8d44..fb57368150ae1 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs @@ -11,6 +11,9 @@ using System.Numerics; using System.Runtime.InteropServices; using System.Runtime.Versioning; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif using Gdip = System.Drawing.SafeNativeMethods.Gdip; namespace System.Drawing @@ -60,6 +63,31 @@ internal static string GetAllocationStack() { public delegate bool DrawImageAbort(IntPtr callbackdata); +#if NET7_0_OR_GREATER + [CustomTypeMarshaller(typeof(DrawImageAbort), CustomTypeMarshallerKind.Value, Direction = CustomTypeMarshallerDirection.In, Features = CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)] + internal unsafe struct DrawImageAbortMarshaller + { + private delegate Interop.BOOL DrawImageAbortNative(IntPtr callbackdata); + private DrawImageAbortNative? _managed; + private delegate* unmanaged _nativeFunction; + public DrawImageAbortMarshaller(DrawImageAbort? managed) + { + _managed = managed is null ? null : data => managed(data) ? Interop.BOOL.TRUE : Interop.BOOL.FALSE; + _nativeFunction = _managed is null ? null : (delegate* unmanaged)Marshal.GetFunctionPointerForDelegate(_managed); + } + + public delegate* unmanaged ToNativeValue() + { + return _nativeFunction; + } + + public void FreeNative() + { + GC.KeepAlive(_managed); + } + } +#endif + /// /// Callback for EnumerateMetafile methods. /// This method can then call Metafile.PlayRecord to play the record that was just enumerated. @@ -77,6 +105,37 @@ public delegate bool EnumerateMetafileProc( IntPtr data, PlayRecordCallback callbackData); +#if NET7_0_OR_GREATER + [CustomTypeMarshaller(typeof(EnumerateMetafileProc), CustomTypeMarshallerKind.Value, Direction = CustomTypeMarshallerDirection.In, Features = CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)] + internal unsafe struct EnumerateMetafileProcMarshaller + { + private delegate Interop.BOOL EnumerateMetafileProcNative( + EmfPlusRecordType recordType, + int flags, + int dataSize, + IntPtr data, + IntPtr callbackData); + private EnumerateMetafileProcNative? _managed; + private delegate* unmanaged _nativeFunction; + public EnumerateMetafileProcMarshaller(EnumerateMetafileProc? managed) + { + _managed = managed is null ? null : (recordType, flags, dataSize, data, callbackData) => + managed(recordType, flags, dataSize, data, Marshal.GetDelegateForFunctionPointer(callbackData)) ? Interop.BOOL.TRUE : Interop.BOOL.FALSE; + _nativeFunction = _managed is null ? null : (delegate* unmanaged)Marshal.GetFunctionPointerForDelegate(_managed); + } + + public delegate* unmanaged ToNativeValue() + { + return _nativeFunction; + } + + public void FreeNative() + { + GC.KeepAlive(_managed); + } + } +#endif + /// /// Constructor to initialize this object from a native GDI+ Graphics pointer. /// diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs index cc4c37999206f..2493fe701ef97 100644 --- a/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs +++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs @@ -10,6 +10,9 @@ using System.IO; using System.Runtime.InteropServices; using System.Runtime.Serialization; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif using Gdip = System.Drawing.SafeNativeMethods.Gdip; namespace System.Drawing @@ -40,6 +43,31 @@ public abstract class Image : MarshalByRefObject, IDisposable, ICloneable, ISeri // to modify it, in order to preserve compatibility. public delegate bool GetThumbnailImageAbort(); +#if NET7_0_OR_GREATER + [CustomTypeMarshaller(typeof(GetThumbnailImageAbort), CustomTypeMarshallerKind.Value, Direction = CustomTypeMarshallerDirection.In, Features = CustomTypeMarshallerFeatures.TwoStageMarshalling | CustomTypeMarshallerFeatures.UnmanagedResources)] + internal unsafe struct GetThumbnailImageAbortMarshaller + { + private delegate Interop.BOOL GetThumbnailImageAbortNative(IntPtr callbackdata); + private GetThumbnailImageAbortNative _managed; + private delegate* unmanaged _nativeFunction; + public GetThumbnailImageAbortMarshaller(GetThumbnailImageAbort managed) + { + _managed = data => managed() ? Interop.BOOL.TRUE : Interop.BOOL.FALSE; + _nativeFunction = (delegate* unmanaged)Marshal.GetFunctionPointerForDelegate(_managed); + } + + public delegate* unmanaged ToNativeValue() + { + return _nativeFunction; + } + + public void FreeNative() + { + GC.KeepAlive(_managed); + } + } +#endif + internal IntPtr nativeImage; private object? _userData;