Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Directory.Build.targets4
-rw-r--r--src/coreclr/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.CoreCLR.cs7
-rw-r--r--src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs54
-rw-r--r--src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs62
-rw-r--r--src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InteropServices/UnmanagedCallConvAttribute.cs25
-rw-r--r--src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs7
-rw-r--r--src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs69
-rw-r--r--src/coreclr/nativeaot/Test.CoreLib/src/System/Runtime/RuntimeImports.cs6
-rw-r--r--src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj8
-rw-r--r--src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs14
-rw-r--r--src/coreclr/vm/dllimport.cpp1
-rw-r--r--src/coreclr/vm/mlinfo.cpp120
-rw-r--r--src/libraries/Common/src/DisableRuntimeMarshalling.cs5
-rw-r--r--src/libraries/Common/src/Interop/Interop.HostPolicy.cs10
-rw-r--r--src/libraries/Common/src/Interop/Interop.Ldap.cs121
-rw-r--r--src/libraries/Common/src/Interop/Interop.Odbc.cs53
-rw-r--r--src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs7
-rw-r--r--src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ldap.cs42
-rw-r--r--src/libraries/Common/src/Interop/OSX/Interop.libc.cs7
-rw-r--r--src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.iOS.cs4
-rw-r--r--src/libraries/Common/src/Interop/Unix/System.Native/Interop.Abort.cs4
-rw-r--r--src/libraries/Common/src/Interop/Unix/System.Native/Interop.DynamicLoad.cs16
-rw-r--r--src/libraries/Common/src/Interop/Unix/System.Native/Interop.Exit.cs4
-rw-r--r--src/libraries/Common/src/Interop/Unix/System.Native/Interop.SchedGetCpu.cs4
-rw-r--r--src/libraries/Common/src/Interop/Unix/System.Native/Interop.Threading.cs4
-rw-r--r--src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs8
-rw-r--r--src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Activeds/Interop.ADsOpenObject.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs8
-rw-r--r--src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs2
-rw-r--r--src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs7
-rw-r--r--src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventRegister.cs7
-rw-r--r--src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs26
-rw-r--r--src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_DECRYPT_PARA.cs3
-rw-r--r--src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_KEY_AGREE_DECRYPT_PARA.cs3
-rw-r--r--src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptMsgControl.cs12
-rw-r--r--src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs173
-rw-r--r--src/libraries/Common/src/Interop/Windows/Gdi32/Interop.OffsetViewportOrgEx.cs7
-rw-r--r--src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs39
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DynamicLoad.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ExitProcess.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessorNumber.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetProcessName.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetTickCount64.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.IsDebuggerPresent.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.RaiseFailFastException.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPool.cs28
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPoolIO.cs16
-rw-r--r--src/libraries/Common/src/Interop/Windows/Kernel32/Interop.Timer.cs8
-rw-r--r--src/libraries/Common/src/Interop/Windows/Ole32/Interop.CLSIDFromProgID.cs7
-rw-r--r--src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoCreateGuid.cs7
-rw-r--r--src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetApartmentType.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetObjectContext.cs16
-rw-r--r--src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoInitializeEx.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoUninitialize.cs4
-rw-r--r--src/libraries/Common/src/Interop/Windows/PerfCounter/Interop.PerformanceData.cs12
-rw-r--r--src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs9
-rw-r--r--src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs35
-rw-r--r--src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs14
-rw-r--r--src/libraries/Common/src/Interop/Windows/SspiCli/Interop.TokenSource.cs5
-rw-r--r--src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs3
-rw-r--r--src/libraries/Common/src/Interop/Windows/User32/Interop.PostMessage.cs3
-rw-r--r--src/libraries/Common/src/Interop/Windows/User32/Interop.SendMessage.cs3
-rw-r--r--src/libraries/Common/src/Interop/Windows/WebSocket/Interop.Structs.cs26
-rw-r--r--src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs25
-rw-r--r--src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs23
-rw-r--r--src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs38
-rw-r--r--src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp_types.cs42
-rw-r--r--src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs23
-rw-r--r--src/libraries/Common/src/Interop/Windows/WinSock/Interop.WinsockBSD.cs42
-rw-r--r--src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs17
-rw-r--r--src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs17
-rw-r--r--src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs51
-rw-r--r--src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ldap.cs46
-rw-r--r--src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSRegisterSessionNotification.cs5
-rw-r--r--src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSUnRegisterSessionNotification.cs5
-rw-r--r--src/libraries/Common/src/System/Net/DebugCriticalHandleZeroOrMinusOneIsInvalid.cs29
-rw-r--r--src/libraries/Common/src/System/Net/DebugSafeHandleZeroOrMinusOneIsInvalid.cs (renamed from src/libraries/Common/src/System/Net/DebugCriticalHandleMinusOneIsInvalid.cs)6
-rw-r--r--src/libraries/Common/src/System/Net/Security/SecurityContextTokenHandle.cs11
-rw-r--r--src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs1
-rw-r--r--src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs11
-rw-r--r--src/libraries/Common/src/System/Runtime/InteropServices/HandleRefMarshaller.cs22
-rw-r--r--src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj2
-rw-r--r--src/libraries/Microsoft.Win32.Registry/tests/Helpers.cs14
-rw-r--r--src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj4
-rw-r--r--src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft.Win32.SystemEvents.csproj3
-rw-r--r--src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs39
-rw-r--r--src/libraries/System.Console/src/System.Console.csproj2
-rw-r--r--src/libraries/System.Console/tests/CancelKeyPress.Unix.cs8
-rw-r--r--src/libraries/System.Console/tests/ConsoleEncoding.Windows.cs8
-rw-r--r--src/libraries/System.Console/tests/System.Console.Tests.csproj2
-rw-r--r--src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj6
-rw-r--r--src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs18
-rw-r--r--src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj3
-rw-r--r--src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPoolIdentity.cs17
-rw-r--r--src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs8
-rw-r--r--src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj5
-rw-r--r--src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/UnsafeNativeMethods.cs125
-rw-r--r--src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj4
-rw-r--r--src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj4
-rw-r--r--src/libraries/System.Diagnostics.PerformanceCounter/src/System.Diagnostics.PerformanceCounter.csproj4
-rw-r--r--src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj2
-rw-r--r--src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj4
-rw-r--r--src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs4
-rw-r--r--src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj8
-rw-r--r--src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs20
-rw-r--r--src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs8
-rw-r--r--src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Windows.cs8
-rw-r--r--src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.Windows.cs3
-rw-r--r--src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs45
-rw-r--r--src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs16
-rw-r--r--src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj3
-rw-r--r--src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs169
-rw-r--r--src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs17
-rw-r--r--src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Shell32.cs13
-rw-r--r--src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.User32.cs53
-rw-r--r--src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs33
-rw-r--r--src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj8
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Gdiplus.cs4
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs235
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Windows.cs999
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs3867
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs13
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/BitmapData.cs20
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMatrix.cs18
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Unix.cs2
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Windows.cs65
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderEmf.cs23
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderWmf.cs97
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/WmfPlaceableFileHeader.cs18
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs6
-rw-r--r--src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs15
-rw-r--r--src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj2
-rw-r--r--src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj2
-rw-r--r--src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Unix.cs6
-rw-r--r--src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj2
-rw-r--r--src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj2
-rw-r--r--src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj2
-rw-r--r--src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Directory.NotifyFilter.cs7
-rw-r--r--src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.File.NotifyFilter.cs7
-rw-r--r--src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj2
-rw-r--r--src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj2
-rw-r--r--src/libraries/System.IO.FileSystem/tests/FileSystemTest.Unix.cs8
-rw-r--r--src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj2
-rw-r--r--src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Unix.cs8
-rw-r--r--src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Windows.cs8
-rw-r--r--src/libraries/System.IO.MemoryMappedFiles/tests/SafeMemoryMappedViewHandleTests.cs6
-rw-r--r--src/libraries/System.IO.MemoryMappedFiles/tests/System.IO.MemoryMappedFiles.Tests.csproj4
-rw-r--r--src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj2
-rw-r--r--src/libraries/System.IO.Ports/src/System.IO.Ports.csproj8
-rw-r--r--src/libraries/System.Management/src/System.Management.csproj2
-rw-r--r--src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj5
-rw-r--r--src/libraries/System.Net.Http/src/System.Net.Http.csproj8
-rw-r--r--src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj8
-rw-r--r--src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj1
-rw-r--r--src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj8
-rw-r--r--src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs2
-rw-r--r--src/libraries/System.Net.Mail/src/System.Net.Mail.csproj8
-rw-r--r--src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj8
-rw-r--r--src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj2
-rw-r--r--src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIcmpV6Statistics.cs2
-rw-r--r--src/libraries/System.Net.Ping/src/System.Net.Ping.csproj3
-rw-r--r--src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj3
-rw-r--r--src/libraries/System.Net.Quic/src/System.Net.Quic.csproj5
-rw-r--r--src/libraries/System.Net.Security/src/System.Net.Security.csproj9
-rw-r--r--src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj3
-rw-r--r--src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs249
-rw-r--r--src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs2
-rw-r--r--src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems5
-rw-r--r--src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs6
-rw-r--r--src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs8
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs47
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs5
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs22
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs9
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx3
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs2
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs21
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs6
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs59
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/IMarshallingGeneratorFactory.cs21
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshalAsMarshallingGeneratorFactory.cs (renamed from src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs)21
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/UnsupportedMarshallingFactory.cs18
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs124
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.Designer.cs9
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.resx3
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs4
-rw-r--r--src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs134
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj5
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs1
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AdditionalAttributesOnStub.cs24
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AttributeForwarding.cs113
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs117
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs39
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs38
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.Unit.Tests.csproj2
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ManualTypeMarshallingAnalyzerTests.cs390
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/Blittable.cs2
-rw-r--r--src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/NonBlittable.cs2
-rw-r--r--src/libraries/System.Security.AccessControl/src/System.Security.AccessControl.csproj2
-rw-r--r--src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/DecryptorPalWindows.Decrypt.cs113
-rw-r--r--src/libraries/System.Security.Cryptography.Pkcs/src/System.Security.Cryptography.Pkcs.csproj4
-rw-r--r--src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj6
-rw-r--r--src/libraries/System.Security.Cryptography.X509Certificates/tests/System.Security.Cryptography.X509Certificates.Tests.csproj2
-rw-r--r--src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj2
-rw-r--r--src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CapiHelper.Windows.cs4
-rw-r--r--src/libraries/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj2
-rw-r--r--src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs9
-rw-r--r--src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.TestService/System.ServiceProcess.ServiceController.TestService.csproj5
-rw-r--r--src/libraries/System.Speech/src/System.Speech.csproj4
-rw-r--r--src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj6
-rw-r--r--src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs23
-rw-r--r--src/mono/mono/mini/method-to-ir.c2
-rw-r--r--src/tests/Common/CoreCLRTestLibrary/HostPolicyMock.cs13
214 files changed, 6593 insertions, 2951 deletions
diff --git a/Directory.Build.targets b/Directory.Build.targets
index f59955242b2..541cdfb59f2 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -26,6 +26,10 @@
<InformationalVersion Condition="'$(InformationalVersion)' == '' and '$(VersionSuffix)' != ''">$(ProductVersion)-$(VersionSuffix)</InformationalVersion>
</PropertyGroup>
+ <ItemGroup>
+ <SupportedNETCoreAppTargetFramework Include=".NETCoreApp,Version=v$(NETCoreAppMaximumVersion)" DisplayName=".NET $(NETCoreAppMaximumVersion)" Alias="net$(NETCoreAppMaximumVersion)" />
+ </ItemGroup>
+
<!-- The Default behavior in VS is to show files for the first target framework in TargetFrameworks property.
This is required to show all the files corresponding to all target frameworks in VS. -->
<ItemGroup Condition="'$(DefaultLanguageSourceExtension)' != '' and
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.CoreCLR.cs
index 21f121b24f0..d4938c14002 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Diagnostics/Eventing/EventPipe.CoreCLR.cs
@@ -40,11 +40,8 @@ namespace System.Diagnostics.Tracing
[GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "EventPipeInternal_DeleteProvider")]
internal static partial void DeleteProvider(IntPtr provHandle);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(RuntimeHelpers.QCall, EntryPoint = "EventPipeInternal_EventActivityIdControl")]
- internal static extern int EventActivityIdControl(uint controlCode, ref Guid activityId);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "EventPipeInternal_EventActivityIdControl")]
+ internal static partial int EventActivityIdControl(uint controlCode, ref Guid activityId);
[GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "EventPipeInternal_WriteEventData")]
internal static unsafe partial void WriteEventData(IntPtr eventHandle, EventProvider.EventData* pEventData, uint dataCount, Guid* activityId, Guid* relatedActivityId);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
index fcd63c2b84b..07ae6ea0420 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
@@ -283,11 +283,9 @@ namespace System.Runtime.InteropServices
GetTypeFromCLSID(clsid, server, ObjectHandleOnStack.Create(ref type));
return type;
}
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(RuntimeHelpers.QCall, EntryPoint = "MarshalNative_GetTypeFromCLSID", CharSet = CharSet.Unicode)]
- private static extern void GetTypeFromCLSID(in Guid clsid, string? server, ObjectHandleOnStack retType);
-#pragma warning restore DLLIMPORTGENANALYZER015
+
+ [GeneratedDllImport(RuntimeHelpers.QCall, EntryPoint = "MarshalNative_GetTypeFromCLSID", CharSet = CharSet.Unicode)]
+ private static partial void GetTypeFromCLSID(in Guid clsid, string? server, ObjectHandleOnStack retType);
/// <summary>
/// Return the IUnknown* for an Object if the current context is the one
@@ -698,32 +696,48 @@ namespace System.Runtime.InteropServices
throw new NotSupportedException(SR.NotSupported_COM);
}
- CreateBindCtx(0, out IBindCtx bindctx);
-
- MkParseDisplayName(bindctx, monikerName, out _, out IMoniker pmoniker);
- BindMoniker(pmoniker, 0, ref IID_IUnknown, out object obj);
+ ThrowExceptionForHR(CreateBindCtx(0, out IntPtr bindctx));
- return obj;
+ try
+ {
+ ThrowExceptionForHR(MkParseDisplayName(bindctx, monikerName, out _, out IntPtr pmoniker));
+ try
+ {
+ ThrowExceptionForHR(BindMoniker(pmoniker, 0, ref IID_IUnknown, out IntPtr ptr));
+ try
+ {
+ return GetObjectForIUnknown(ptr);
+ }
+ finally
+ {
+ Release(ptr);
+ }
+ }
+ finally
+ {
+ Release(pmoniker);
+ }
+ }
+ finally
+ {
+ Release(bindctx);
+ }
}
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // These methods use built-in COM interop, which is not supported by the source generator.
-
// Revist after https://github.com/mono/linker/issues/1989 is fixed
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
- [DllImport(Interop.Libraries.Ole32, PreserveSig = false)]
- private static extern void CreateBindCtx(uint reserved, out IBindCtx ppbc);
+ [GeneratedDllImport(Interop.Libraries.Ole32)]
+ private static partial int CreateBindCtx(uint reserved, out IntPtr ppbc);
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
- [DllImport(Interop.Libraries.Ole32, PreserveSig = false)]
- private static extern void MkParseDisplayName(IBindCtx pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IMoniker ppmk);
+ [GeneratedDllImport(Interop.Libraries.Ole32, PreserveSig = false)]
+ private static partial int MkParseDisplayName(IntPtr pbc, [MarshalAs(UnmanagedType.LPWStr)] string szUserName, out uint pchEaten, out IntPtr ppmk);
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2050:UnrecognizedReflectionPattern",
Justification = "The calling method is annotated with RequiresUnreferencedCode")]
- [DllImport(Interop.Libraries.Ole32, PreserveSig = false)]
- private static extern void BindMoniker(IMoniker pmk, uint grfOpt, ref Guid iidResult, [MarshalAs(UnmanagedType.Interface)] out object ppvResult);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(Interop.Libraries.Ole32, PreserveSig = false)]
+ private static partial int BindMoniker(IntPtr pmk, uint grfOpt, ref Guid iidResult, out IntPtr ppvResult);
[SupportedOSPlatform("windows")]
[MethodImpl(MethodImplOptions.InternalCall)]
diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs
index 43754434469..b38f3563d62 100644
--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InternalCalls.cs
@@ -46,7 +46,7 @@ namespace System.Runtime
IDynamicCastableGetInterfaceImplementation = 9,
}
- internal static class InternalCalls
+ internal static partial class InternalCalls
{
//
// internalcalls for System.GC.
@@ -59,8 +59,9 @@ namespace System.Runtime
RhpCollect(generation, mode);
}
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- private static extern void RhpCollect(int generation, InternalGCCollectionMode mode);
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ private static partial void RhpCollect(int generation, InternalGCCollectionMode mode);
[RuntimeExport("RhGetGcTotalMemory")]
internal static long RhGetGcTotalMemory()
@@ -68,8 +69,9 @@ namespace System.Runtime
return RhpGetGcTotalMemory();
}
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- private static extern long RhpGetGcTotalMemory();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ private static partial long RhpGetGcTotalMemory();
[RuntimeExport("RhStartNoGCRegion")]
internal static int RhStartNoGCRegion(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC)
@@ -284,39 +286,49 @@ namespace System.Runtime
// Block the current thread until at least one object needs to be finalized (returns true) or
// memory is low (returns false and the finalizer thread should initiate a garbage collection).
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern uint RhpWaitForFinalizerRequest();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial uint RhpWaitForFinalizerRequest();
// Indicate that the current round of finalizations is complete.
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void RhpSignalFinalizationComplete();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial void RhpSignalFinalizationComplete();
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void RhpAcquireCastCacheLock();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial void RhpAcquireCastCacheLock();
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void RhpReleaseCastCacheLock();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial void RhpReleaseCastCacheLock();
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern ulong RhpGetTickCount64();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial ulong RhpGetTickCount64();
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void RhpAcquireThunkPoolLock();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial void RhpAcquireThunkPoolLock();
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern void RhpReleaseThunkPoolLock();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial void RhpReleaseThunkPoolLock();
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr RhAllocateThunksMapping();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial IntPtr RhAllocateThunksMapping();
// Enters a no GC region, possibly doing a blocking GC if there is not enough
// memory available to satisfy the caller's request.
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int RhpStartNoGCRegion(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC);
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial int RhpStartNoGCRegion(long totalSize, bool hasLohSize, long lohSize, bool disallowFullBlockingGC);
// Exits a no GC region, possibly doing a GC to clean up the garbage that
// the caller allocated.
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- internal static extern int RhpEndNoGCRegion();
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial int RhpEndNoGCRegion();
}
}
diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InteropServices/UnmanagedCallConvAttribute.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InteropServices/UnmanagedCallConvAttribute.cs
new file mode 100644
index 00000000000..969312264b5
--- /dev/null
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/InteropServices/UnmanagedCallConvAttribute.cs
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace System.Runtime.InteropServices
+{
+ /// <summary>
+ /// Provides an equivalent to <see cref="UnmanagedCallersOnlyAttribute"/> for native
+ /// functions declared in .NET.
+ /// </summary>
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
+ public sealed class UnmanagedCallConvAttribute : Attribute
+ {
+ public UnmanagedCallConvAttribute()
+ {
+ }
+
+ /// <summary>
+ /// Types indicating calling conventions for the unmanaged target.
+ /// </summary>
+ /// <remarks>
+ /// If <c>null</c>, the semantics are identical to <c>CallingConvention.Winapi</c>.
+ /// </remarks>
+ public Type[]? CallConvs;
+ }
+}
diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs
index 53860b7cdab..84accea33dd 100644
--- a/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs
+++ b/src/coreclr/nativeaot/Runtime.Base/src/System/Runtime/RuntimeExports.cs
@@ -14,7 +14,7 @@ using Internal.Runtime.CompilerServices;
namespace System.Runtime
{
- internal static class RuntimeExports
+ internal static partial class RuntimeExports
{
//
// internal calls for allocation
@@ -301,8 +301,9 @@ namespace System.Runtime
return RhpGetCurrentThreadStackTrace(pOutputBuffer, (uint)((outputBuffer != null) ? outputBuffer.Length : 0), new UIntPtr(&pOutputBuffer));
}
- [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
- private static extern unsafe int RhpGetCurrentThreadStackTrace(IntPtr* pOutputBuffer, uint outputBufferLength, UIntPtr addressInCurrentFrame);
+ [GeneratedDllImport(Redhawk.BaseName)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ private static unsafe partial int RhpGetCurrentThreadStackTrace(IntPtr* pOutputBuffer, uint outputBufferLength, UIntPtr addressInCurrentFrame);
// Worker for RhGetCurrentThreadStackTrace. RhGetCurrentThreadStackTrace just allocates a transition
// frame that will be used to seed the stack trace and this method does all the real work.
diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs
index b0d2fad5792..6caa27646b3 100644
--- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs
+++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs
@@ -22,16 +22,18 @@ namespace System.Runtime
// but if a class library wants to factor differently (such as putting the GCHandle methods in an
// optional library, those methods can be moved to a different file/namespace/dll
[ReflectionBlocked]
- public static class RuntimeImports
+ public static partial class RuntimeImports
{
private const string RuntimeLibrary = "*";
- [DllImport(RuntimeLibrary, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
[SuppressGCTransition]
- internal static extern ulong RhpGetTickCount64();
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial ulong RhpGetTickCount64();
- [DllImport(RuntimeLibrary, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
- internal static extern IntPtr RhpGetCurrentThread();
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial IntPtr RhpGetCurrentThread();
[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhpInitiateThreadAbort")]
@@ -67,8 +69,8 @@ namespace System.Runtime
private static extern bool _RhReRegisterForFinalize(object obj);
// Wait for all pending finalizers. This must be a p/invoke to avoid starving the GC.
- [DllImport(RuntimeLibrary, ExactSpelling = true)]
- private static extern void RhWaitForPendingFinalizers(int allowReentrantWait);
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ private static partial void RhWaitForPendingFinalizers(int allowReentrantWait);
// Temporary workaround to unblock shareable assembly bring-up - without shared interop,
// we must prevent RhWaitForPendingFinalizers from using marshaling because it would
@@ -80,8 +82,8 @@ namespace System.Runtime
RhWaitForPendingFinalizers(allowReentrantWait ? 1 : 0);
}
- [DllImport(RuntimeLibrary, ExactSpelling = true)]
- internal static extern void RhInitializeFinalizerThread();
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ internal static partial void RhInitializeFinalizerThread();
// Get maximum GC generation number.
[MethodImplAttribute(MethodImplOptions.InternalCall)]
@@ -185,18 +187,19 @@ namespace System.Runtime
[RuntimeImport(RuntimeLibrary, "RhGetTotalAllocatedBytes")]
internal static extern long RhGetTotalAllocatedBytes();
- [DllImport(RuntimeLibrary, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
- internal static extern long RhGetTotalAllocatedBytesPrecise();
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial long RhGetTotalAllocatedBytesPrecise();
[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhGetMemoryInfo")]
internal static extern void RhGetMemoryInfo(ref byte info, GCKind kind);
- [DllImport(RuntimeLibrary, ExactSpelling = true)]
- internal static unsafe extern void RhAllocateNewArray(IntPtr pArrayEEType, uint numElements, uint flags, void* pResult);
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ internal static unsafe partial void RhAllocateNewArray(IntPtr pArrayEEType, uint numElements, uint flags, void* pResult);
- [DllImport(RuntimeLibrary, ExactSpelling = true)]
- internal static unsafe extern void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ internal static unsafe partial void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhCompareObjectContentsAndPadding")]
@@ -365,23 +368,26 @@ namespace System.Runtime
internal static extern object RhMemberwiseClone(object obj);
// Busy spin for the given number of iterations.
- [DllImport(RuntimeLibrary, EntryPoint = "RhSpinWait", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
+ [GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhSpinWait", ExactSpelling = true)]
[SuppressGCTransition]
- internal static extern void RhSpinWait(int iterations);
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial void RhSpinWait(int iterations);
// Yield the cpu to another thread ready to process, if one is available.
- [DllImport(RuntimeLibrary, EntryPoint = "RhYield", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- private static extern int _RhYield();
+ [GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhYield", ExactSpelling = true)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ private static partial int _RhYield();
internal static bool RhYield() { return (_RhYield() != 0); }
- [DllImport(RuntimeLibrary, EntryPoint = "RhFlushProcessWriteBuffers", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
- internal static extern void RhFlushProcessWriteBuffers();
+ [GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhFlushProcessWriteBuffers", ExactSpelling = true)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static partial void RhFlushProcessWriteBuffers();
#if !TARGET_UNIX
// Wait for any object to be signalled, in a way that's compatible with the CLR's behavior in an STA.
// ExactSpelling = 'true' to force MCG to resolve it to default
- [DllImport(RuntimeLibrary, ExactSpelling = true)]
- private static extern unsafe int RhCompatibleReentrantWaitAny(int alertable, int timeout, int count, IntPtr* handles);
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ private static unsafe partial int RhCompatibleReentrantWaitAny(int alertable, int timeout, int count, IntPtr* handles);
// Temporary workaround to unblock shareable assembly bring-up - without shared interop,
// we must prevent RhCompatibleReentrantWaitAny from using marshaling because it would
@@ -611,8 +617,8 @@ namespace System.Runtime
internal static extern void RhCallDescrWorker(IntPtr callDescr);
// For Managed to Native calls
- [DllImport(RuntimeLibrary, EntryPoint = "RhCallDescrWorker", ExactSpelling = true)]
- internal static extern void RhCallDescrWorkerNative(IntPtr callDescr);
+ [GeneratedDllImport(RuntimeLibrary, EntryPoint = "RhCallDescrWorker", ExactSpelling = true)]
+ internal static partial void RhCallDescrWorkerNative(IntPtr callDescr);
// Moves memory from smem to dmem. Size must be a positive value.
// This copy uses an intrinsic to be safe for copying arbitrary bits of
@@ -929,15 +935,16 @@ namespace System.Runtime
[RuntimeImport(RuntimeLibrary, "modff")]
internal static extern unsafe float modff(float x, float* intptr);
- [DllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
- internal static extern unsafe void* memmove(byte* dmem, byte* smem, nuint size);
+ [GeneratedDllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
+ internal static unsafe partial void* memmove(byte* dmem, byte* smem, nuint size);
- [DllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
- internal static extern unsafe void* memset(byte* mem, int value, nuint size);
+ [GeneratedDllImport(RuntimeImports.RuntimeLibrary, ExactSpelling = true)]
+ internal static unsafe partial void* memset(byte* mem, int value, nuint size);
#if TARGET_X86 || TARGET_AMD64
- [DllImport(RuntimeLibrary, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
- internal static extern unsafe void RhCpuIdEx(int* cpuInfo, int functionId, int subFunctionId);
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvCdecl) })]
+ internal static unsafe partial void RhCpuIdEx(int* cpuInfo, int functionId, int subFunctionId);
#endif
internal static RhCorElementTypeInfo GetRhCorElementTypeInfo(CorElementType elementType)
diff --git a/src/coreclr/nativeaot/Test.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/coreclr/nativeaot/Test.CoreLib/src/System/Runtime/RuntimeImports.cs
index bcf47e47fc5..a4785f4d864 100644
--- a/src/coreclr/nativeaot/Test.CoreLib/src/System/Runtime/RuntimeImports.cs
+++ b/src/coreclr/nativeaot/Test.CoreLib/src/System/Runtime/RuntimeImports.cs
@@ -18,7 +18,7 @@ namespace System.Runtime
// but if a class library wants to factor differently (such as putting the GCHandle methods in an
// optional library, those methods can be moved to a different file/namespace/dll
- public static class RuntimeImports
+ public static partial class RuntimeImports
{
private const string RuntimeLibrary = "*";
@@ -85,8 +85,8 @@ namespace System.Runtime
internal static unsafe Array RhNewArray(EETypePtr pEEType, int length)
=> RhNewArray(pEEType.ToPointer(), length);
- [DllImport(RuntimeLibrary, ExactSpelling = true)]
- internal static unsafe extern void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
+ [GeneratedDllImport(RuntimeLibrary, ExactSpelling = true)]
+ internal static unsafe partial void RhAllocateNewObject(IntPtr pEEType, uint flags, void* pResult);
[MethodImpl(MethodImplOptions.InternalCall)]
[RuntimeImport(RuntimeLibrary, "RhpFallbackFailFast")]
diff --git a/src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj b/src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj
index 29a54764b2f..3f602c8f677 100644
--- a/src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj
+++ b/src/coreclr/nativeaot/Test.CoreLib/src/Test.CoreLib.csproj
@@ -3,6 +3,11 @@
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<TargetFramework>netstandard2.0</TargetFramework>
+ <EnableDllImportGenerator>true</EnableDllImportGenerator>
+ <!--
+ DLLIMPORTGEN003: DllImportGenerator Target Framework Not Supported.
+ -->
+ <NoWarn>$(NoWarn);DLLIMPORTGEN003</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DefineConstants>FEATURE_GC_STRESS;$(DefineConstants)</DefineConstants>
@@ -184,6 +189,9 @@
<Compile Include="..\..\Runtime.Base\src\System\Runtime\InteropServices\LayoutKind.cs">
<Link>System\Runtime\InteropServices\LayoutKind.cs</Link>
</Compile>
+ <Compile Include="..\..\Runtime.Base\src\System\Runtime\InteropServices\UnmanagedCallConvAttribute.cs">
+ <Link>System\Runtime\InteropServices\UnmanagedCallConvAttribute.cs</Link>
+ </Compile>
<Compile Include="..\..\Runtime.Base\src\System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs">
<Link>System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs</Link>
</Compile>
diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs
index e9a889f8233..4c11c057063 100644
--- a/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs
+++ b/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs
@@ -872,26 +872,28 @@ namespace Internal.TypeSystem.Interop
internal static MarshallerKind GetDisabledMarshallerKind(
TypeDesc type)
{
- if (type.Category == TypeFlags.Void)
+ // Get the underlying type for enum types.
+ TypeDesc underlyingType = type.UnderlyingType;
+ if (underlyingType.Category == TypeFlags.Void)
{
return MarshallerKind.VoidReturn;
}
- else if (type.IsByRef)
+ else if (underlyingType.IsByRef)
{
// Managed refs are not supported when runtime marshalling is disabled.
return MarshallerKind.Invalid;
}
- else if (type.IsPrimitive)
+ else if (underlyingType.IsPrimitive)
{
return MarshallerKind.BlittableValue;
}
- else if (type.IsPointer || type.IsFunctionPointer)
+ else if (underlyingType.IsPointer || underlyingType.IsFunctionPointer)
{
return MarshallerKind.BlittableValue;
}
- else if (type.IsValueType)
+ else if (underlyingType.IsValueType)
{
- var defType = (DefType)type;
+ var defType = (DefType)underlyingType;
if (!defType.ContainsGCPointers && !defType.IsAutoLayoutOrHasAutoLayoutFields)
{
return MarshallerKind.BlittableValue;
diff --git a/src/coreclr/vm/dllimport.cpp b/src/coreclr/vm/dllimport.cpp
index 3a35a8e108f..35446a502ae 100644
--- a/src/coreclr/vm/dllimport.cpp
+++ b/src/coreclr/vm/dllimport.cpp
@@ -3349,6 +3349,7 @@ BOOL NDirect::MarshalingRequired(
// any types that contain gc pointers, but all "unmanaged" types are treated as blittable
// as long as they aren't auto-layout and don't have any auto-layout fields.
if (!runtimeMarshallingEnabled &&
+ !hndArgType.IsEnum() &&
(hndArgType.GetMethodTable()->ContainsPointers()
|| hndArgType.GetMethodTable()->IsAutoLayoutOrHasAutoLayoutField()))
{
diff --git a/src/coreclr/vm/mlinfo.cpp b/src/coreclr/vm/mlinfo.cpp
index 5a071c2b9f8..81ae1ab7846 100644
--- a/src/coreclr/vm/mlinfo.cpp
+++ b/src/coreclr/vm/mlinfo.cpp
@@ -1065,65 +1065,79 @@ namespace
MethodTable** pMTOut,
UINT* errorResIDOut)
{
- switch (sig.PeekElemTypeNormalized(pModule, pTypeContext))
+ while (true)
{
- case ELEMENT_TYPE_BOOLEAN:
- case ELEMENT_TYPE_U1:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_U1;
- case ELEMENT_TYPE_I1:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_1;
- case ELEMENT_TYPE_CHAR:
- case ELEMENT_TYPE_U2:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_U2;
- case ELEMENT_TYPE_I2:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_2;
- case ELEMENT_TYPE_U4:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_U4;
- case ELEMENT_TYPE_I4:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_4;
- case ELEMENT_TYPE_U8:
- case ELEMENT_TYPE_I8:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_8;
-#ifdef TARGET_64BIT
- case ELEMENT_TYPE_U:
- case ELEMENT_TYPE_PTR:
- case ELEMENT_TYPE_FNPTR:
- case ELEMENT_TYPE_I:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_8;
-#else
- case ELEMENT_TYPE_U:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_U4;
- case ELEMENT_TYPE_PTR:
- case ELEMENT_TYPE_FNPTR:
- case ELEMENT_TYPE_I:
- return MarshalInfo::MARSHAL_TYPE_GENERIC_4;
-#endif
- case ELEMENT_TYPE_R4:
- return MarshalInfo::MARSHAL_TYPE_FLOAT;
- case ELEMENT_TYPE_R8:
- return MarshalInfo::MARSHAL_TYPE_DOUBLE;
- case ELEMENT_TYPE_VAR:
- case ELEMENT_TYPE_VALUETYPE:
- {
- TypeHandle sigTH = sig.GetTypeHandleThrowing(pModule, pTypeContext);
- MethodTable* pMT = sigTH.GetMethodTable();
-
- if (!pMT->IsValueType() || pMT->ContainsPointers())
+ switch (sig.PeekElemTypeNormalized(pModule, pTypeContext))
{
- *errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
- return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
+ // Skip modreqs and modopts in the signature.
+ case ELEMENT_TYPE_CMOD_OPT:
+ case ELEMENT_TYPE_CMOD_REQD:
+ {
+ if(FAILED(sig.GetElemType(NULL)))
+ {
+ *errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
+ return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
+ }
+ break;
}
- if (pMT->IsAutoLayoutOrHasAutoLayoutField())
+ case ELEMENT_TYPE_BOOLEAN:
+ case ELEMENT_TYPE_U1:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_U1;
+ case ELEMENT_TYPE_I1:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_1;
+ case ELEMENT_TYPE_CHAR:
+ case ELEMENT_TYPE_U2:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_U2;
+ case ELEMENT_TYPE_I2:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_2;
+ case ELEMENT_TYPE_U4:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_U4;
+ case ELEMENT_TYPE_I4:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_4;
+ case ELEMENT_TYPE_U8:
+ case ELEMENT_TYPE_I8:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_8;
+ #ifdef TARGET_64BIT
+ case ELEMENT_TYPE_U:
+ case ELEMENT_TYPE_PTR:
+ case ELEMENT_TYPE_FNPTR:
+ case ELEMENT_TYPE_I:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_8;
+ #else
+ case ELEMENT_TYPE_U:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_U4;
+ case ELEMENT_TYPE_PTR:
+ case ELEMENT_TYPE_FNPTR:
+ case ELEMENT_TYPE_I:
+ return MarshalInfo::MARSHAL_TYPE_GENERIC_4;
+ #endif
+ case ELEMENT_TYPE_R4:
+ return MarshalInfo::MARSHAL_TYPE_FLOAT;
+ case ELEMENT_TYPE_R8:
+ return MarshalInfo::MARSHAL_TYPE_DOUBLE;
+ case ELEMENT_TYPE_VAR:
+ case ELEMENT_TYPE_VALUETYPE:
{
- *errorResIDOut = IDS_EE_BADMARSHAL_AUTOLAYOUT;
+ TypeHandle sigTH = sig.GetTypeHandleThrowing(pModule, pTypeContext);
+ MethodTable* pMT = sigTH.GetMethodTable();
+
+ if (!pMT->IsValueType() || pMT->ContainsPointers())
+ {
+ *errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
+ return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
+ }
+ if (pMT->IsAutoLayoutOrHasAutoLayoutField())
+ {
+ *errorResIDOut = IDS_EE_BADMARSHAL_AUTOLAYOUT;
+ return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
+ }
+ *pMTOut = pMT;
+ return MarshalInfo::MARSHAL_TYPE_BLITTABLEVALUECLASS;
+ }
+ default:
+ *errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
}
- *pMTOut = pMT;
- return MarshalInfo::MARSHAL_TYPE_BLITTABLEVALUECLASS;
- }
- default:
- *errorResIDOut = IDS_EE_BADMARSHAL_MARSHAL_DISABLED;
- return MarshalInfo::MARSHAL_TYPE_UNKNOWN;
}
}
}
diff --git a/src/libraries/Common/src/DisableRuntimeMarshalling.cs b/src/libraries/Common/src/DisableRuntimeMarshalling.cs
new file mode 100644
index 00000000000..9a6bc544e55
--- /dev/null
+++ b/src/libraries/Common/src/DisableRuntimeMarshalling.cs
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+// Used to indicate that runtime marshalling should be disabled.
+[assembly: System.Runtime.CompilerServices.DisableRuntimeMarshalling]
diff --git a/src/libraries/Common/src/Interop/Interop.HostPolicy.cs b/src/libraries/Common/src/Interop/Interop.HostPolicy.cs
index b5e3a2109f4..d808de7bea1 100644
--- a/src/libraries/Common/src/Interop/Interop.HostPolicy.cs
+++ b/src/libraries/Common/src/Interop/Interop.HostPolicy.cs
@@ -8,12 +8,12 @@ internal static partial class Interop
{
internal static partial class HostPolicy
{
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
- internal delegate void corehost_resolve_component_dependencies_result_fn(string assemblyPaths,
- string nativeSearchPaths, string resourceSearchPaths);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void corehost_resolve_component_dependencies_result_fn(IntPtr assemblyPaths,
+ IntPtr nativeSearchPaths, IntPtr resourceSearchPaths);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Auto)]
- internal delegate void corehost_error_writer_fn(string message);
+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
+ internal delegate void corehost_error_writer_fn(IntPtr message);
#pragma warning disable CS3016 // Arrays as attribute arguments is not CLS-compliant
[GeneratedDllImport(Libraries.HostPolicy, CharSet = CharSet.Auto)]
diff --git a/src/libraries/Common/src/Interop/Interop.Ldap.cs b/src/libraries/Common/src/Interop/Interop.Ldap.cs
index c62e99f4b4f..a48640d1e46 100644
--- a/src/libraries/Common/src/Interop/Interop.Ldap.cs
+++ b/src/libraries/Common/src/Interop/Interop.Ldap.cs
@@ -1,7 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+using System.Security.Authentication;
internal static partial class Interop
{
@@ -15,7 +17,7 @@ internal static partial class Interop
namespace System.DirectoryServices.Protocols
{
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal sealed class Luid
+ internal readonly struct Luid
{
private readonly int _lowPart;
private readonly int _highPart;
@@ -24,8 +26,11 @@ namespace System.DirectoryServices.Protocols
public int HighPart => _highPart;
}
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(Native))]
+#endif
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal sealed class SEC_WINNT_AUTH_IDENTITY_EX
+ internal struct SEC_WINNT_AUTH_IDENTITY_EX
{
public int version;
public int length;
@@ -38,6 +43,45 @@ namespace System.DirectoryServices.Protocols
public int flags;
public string packageList;
public int packageListLength;
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal struct Native
+ {
+ public int version;
+ public int length;
+ public IntPtr user;
+ public int userLength;
+ public IntPtr domain;
+ public int domainLength;
+ public IntPtr password;
+ public int passwordLength;
+ public int flags;
+ public IntPtr packageList;
+ public int packageListLength;
+
+ public Native(SEC_WINNT_AUTH_IDENTITY_EX managed)
+ {
+ version = managed.version;
+ length = managed.length;
+ user = Marshal.StringToCoTaskMemUni(managed.user);
+ userLength = managed.userLength;
+ domain = Marshal.StringToCoTaskMemUni(managed.domain);
+ domainLength = managed.domainLength;
+ password = Marshal.StringToCoTaskMemUni(managed.password);
+ passwordLength = managed.passwordLength;
+ flags = managed.flags;
+ packageList = Marshal.StringToCoTaskMemUni(managed.packageList);
+ packageListLength = managed.packageListLength;
+ }
+
+ public void FreeNative()
+ {
+ Marshal.FreeCoTaskMem(user);
+ Marshal.FreeCoTaskMem(domain);
+ Marshal.FreeCoTaskMem(password);
+ Marshal.FreeCoTaskMem(packageList);
+ }
+ }
}
internal enum BindMethod : uint // Not Supported in Linux
@@ -113,19 +157,35 @@ namespace System.DirectoryServices.Protocols
}
[StructLayout(LayoutKind.Sequential)]
- internal sealed class LDAP_TIMEVAL
+ internal struct LDAP_TIMEVAL
{
public int tv_sec;
public int tv_usec;
}
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(PinningMarshaller))]
+#endif
[StructLayout(LayoutKind.Sequential)]
internal sealed class BerVal
{
public int bv_len;
public IntPtr bv_val = IntPtr.Zero;
- public BerVal() { }
+#if NET7_0_OR_GREATER
+ internal unsafe struct PinningMarshaller
+ {
+ private readonly BerVal _managed;
+ public PinningMarshaller(BerVal managed)
+ {
+ _managed = managed;
+ }
+
+ public ref int GetPinnableReference() => ref (_managed is null ? ref Unsafe.NullRef<int>() : ref _managed.bv_len);
+
+ public void* Value => Unsafe.AsPointer(ref GetPinnableReference());
+ }
+#endif
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
@@ -138,13 +198,64 @@ namespace System.DirectoryServices.Protocols
public LdapControl() { }
}
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(Marshaller))]
+#endif
+ [StructLayout(LayoutKind.Sequential)]
internal struct LdapReferralCallback
{
public int sizeofcallback;
public QUERYFORCONNECTIONInternal query;
public NOTIFYOFNEWCONNECTIONInternal notify;
public DEREFERENCECONNECTIONInternal dereference;
+#if NET7_0_OR_GREATER
+ public static readonly unsafe int Size = sizeof(Marshaller.Native);
+
+ public unsafe struct Marshaller
+ {
+ public unsafe struct Native
+ {
+ public int sizeofcallback;
+ public IntPtr query;
+ public IntPtr notify;
+ public IntPtr dereference;
+ }
+
+ private LdapReferralCallback _managed;
+ private Native _native;
+
+ public Marshaller(LdapReferralCallback managed)
+ : this()
+ {
+ _managed = managed;
+ _native.sizeofcallback = sizeof(Native);
+ _native.query = managed.query is not null ? Marshal.GetFunctionPointerForDelegate(managed.query) : IntPtr.Zero;
+ _native.notify = managed.notify is not null ? Marshal.GetFunctionPointerForDelegate(managed.notify) : IntPtr.Zero;
+ _native.dereference = managed.dereference is not null ? Marshal.GetFunctionPointerForDelegate(managed.dereference) : IntPtr.Zero;
+ }
+
+ public Native Value
+ {
+ get => _native;
+ set => _native = value;
+ }
+
+ public LdapReferralCallback ToManaged()
+ {
+ return new LdapReferralCallback()
+ {
+ sizeofcallback = _native.sizeofcallback,
+ query = _native.query != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer<QUERYFORCONNECTIONInternal>(_native.query) : null,
+ notify = _native.notify != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer<NOTIFYOFNEWCONNECTIONInternal>(_native.notify) : null,
+ dereference = _native.dereference != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer<DEREFERENCECONNECTIONInternal>(_native.dereference) : null
+ };
+ }
+
+ public void FreeNative() => GC.KeepAlive(_managed);
+ }
+#else
+ public static readonly unsafe int Size = Marshal.SizeOf<LdapReferralCallback>();
+#endif
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
diff --git a/src/libraries/Common/src/Interop/Interop.Odbc.cs b/src/libraries/Common/src/Interop/Interop.Odbc.cs
index 0b300951469..cad9bcab346 100644
--- a/src/libraries/Common/src/Interop/Interop.Odbc.cs
+++ b/src/libraries/Common/src/Interop/Interop.Odbc.cs
@@ -5,6 +5,9 @@ using System;
using System.Data.Odbc;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
using System.Runtime.Versioning;
using System.Security;
using System.Text;
@@ -29,12 +32,16 @@ internal static partial class Interop
/*SQLHANDLE*/OdbcHandle InputHandle,
/*SQLHANDLE* */out IntPtr OutputHandle);
- [DllImport(Interop.Libraries.Odbc32)]
- internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLBindCol(
+ [GeneratedDllImport(Interop.Libraries.Odbc32)]
+ internal static partial /*SQLRETURN*/ODBC32.SQLRETURN SQLBindCol(
/*SQLHSTMT*/OdbcStatementHandle StatementHandle,
/*SQLUSMALLINT*/ushort ColumnNumber,
/*SQLSMALLINT*/ODBC32.SQL_C TargetType,
- /*SQLPOINTER*/HandleRef TargetValue,
+ /*SQLPOINTER*/
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef TargetValue,
/*SQLLEN*/IntPtr BufferLength,
/*SQLLEN* */IntPtr StrLen_or_Ind);
@@ -47,8 +54,8 @@ internal static partial class Interop
/*SQLLEN*/IntPtr BufferLength,
/*SQLLEN* */IntPtr StrLen_or_Ind);
- [DllImport(Interop.Libraries.Odbc32)]
- internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLBindParameter(
+ [GeneratedDllImport(Interop.Libraries.Odbc32)]
+ internal static partial /*SQLRETURN*/ODBC32.SQLRETURN SQLBindParameter(
/*SQLHSTMT*/OdbcStatementHandle StatementHandle,
/*SQLUSMALLINT*/ushort ParameterNumber,
/*SQLSMALLINT*/short ParamDirection,
@@ -56,9 +63,17 @@ internal static partial class Interop
/*SQLSMALLINT*/short SQLType,
/*SQLULEN*/IntPtr cbColDef,
/*SQLSMALLINT*/IntPtr ibScale,
- /*SQLPOINTER*/HandleRef rgbValue,
+ /*SQLPOINTER*/
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef rgbValue,
/*SQLLEN*/IntPtr BufferLength,
- /*SQLLEN* */HandleRef StrLen_or_Ind);
+ /*SQLLEN* */
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef StrLen_or_Ind);
[GeneratedDllImport(Interop.Libraries.Odbc32)]
internal static partial ODBC32.SQLRETURN SQLCancel(
@@ -176,24 +191,24 @@ internal static partial class Interop
/*SQLINTEGER*/int BufferLength,
/*SQLINTEGER* */out int StringLength);
- [DllImport(Interop.Libraries.Odbc32, CharSet = CharSet.Unicode)]
- internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLGetDiagRecW(
+ [GeneratedDllImport(Interop.Libraries.Odbc32, CharSet = CharSet.Unicode)]
+ internal static partial ODBC32.SQLRETURN SQLGetDiagRecW(
/*SQLSMALLINT*/ODBC32.SQL_HANDLE HandleType,
/*SQLHANDLE*/OdbcHandle Handle,
/*SQLSMALLINT*/short RecNumber,
- /*SQLCHAR* */ [Out] StringBuilder rchState,
+ /*SQLCHAR* */ char[] rchState,
/*SQLINTEGER* */out int NativeError,
- /*SQLCHAR* */ [Out] StringBuilder MessageText,
+ /*SQLCHAR* */ char[] MessageText,
/*SQLSMALLINT*/short BufferLength,
/*SQLSMALLINT* */out short TextLength);
- [DllImport(Interop.Libraries.Odbc32, CharSet = CharSet.Unicode)]
- internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLGetDiagFieldW(
+ [GeneratedDllImport(Interop.Libraries.Odbc32, CharSet = CharSet.Unicode)]
+ internal static partial ODBC32.SQLRETURN SQLGetDiagFieldW(
/*SQLSMALLINT*/ ODBC32.SQL_HANDLE HandleType,
/*SQLHANDLE*/ OdbcHandle Handle,
/*SQLSMALLINT*/ short RecNumber,
/*SQLSMALLINT*/ short DiagIdentifier,
- /*SQLPOINTER*/ [Out] StringBuilder rchState,
+ /*SQLPOINTER*/ char[] rchState,
/*SQLSMALLINT*/ short BufferLength,
/*SQLSMALLINT* */ out short StringLength);
@@ -305,12 +320,16 @@ internal static partial class Interop
/*SQLPOINTER*/IntPtr Value,
/*SQLINTEGER*/int StringLength);
- [DllImport(Interop.Libraries.Odbc32)]
- internal static extern /*SQLRETURN*/ODBC32.SQLRETURN SQLSetDescFieldW(
+ [GeneratedDllImport(Interop.Libraries.Odbc32)]
+ internal static partial /*SQLRETURN*/ODBC32.SQLRETURN SQLSetDescFieldW(
/*SQLHSTMT*/OdbcDescriptorHandle StatementHandle,
/*SQLSMALLINT*/short ColumnNumber,
/*SQLSMALLINT*/ODBC32.SQL_DESC FieldIdentifier,
- /*SQLPOINTER*/HandleRef CharacterAttribute,
+ /*SQLPOINTER*/
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef CharacterAttribute,
/*SQLINTEGER*/int BufferLength);
[GeneratedDllImport(Interop.Libraries.Odbc32)]
diff --git a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs
index 468b73fe496..2521b4082e7 100644
--- a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs
+++ b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ber.cs
@@ -15,11 +15,8 @@ internal static partial class Interop
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ber_alloc_t", CharSet = CharSet.Ansi)]
public static partial IntPtr ber_alloc(int option);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.OpenLdap, EntryPoint = "ber_init", CharSet = CharSet.Ansi)]
- public static extern IntPtr ber_init(BerVal value);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ber_init", CharSet = CharSet.Ansi)]
+ public static partial IntPtr ber_init(BerVal value);
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ber_free", CharSet = CharSet.Ansi)]
public static partial IntPtr ber_free(IntPtr berelement, int option);
diff --git a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ldap.cs b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ldap.cs
index 8a8d3b01b0b..263d49c91e2 100644
--- a/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ldap.cs
+++ b/src/libraries/Common/src/Interop/Linux/OpenLdap/Interop.Ldap.cs
@@ -88,11 +88,8 @@ internal static partial class Interop
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_option", CharSet = CharSet.Ansi)]
public static partial int ldap_get_option_bool(ConnectionHandle ldapHandle, LdapOption option, ref bool outValue);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] We need to manually convert SecurityPackageContextConnectionInformation to marshal differently as layout classes are not supported in generated interop.
- [DllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_option", CharSet = CharSet.Ansi)]
- public static extern int ldap_get_option_secInfo(ConnectionHandle ldapHandle, LdapOption option, [In, Out] SecurityPackageContextConnectionInformation outValue);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_option", CharSet = CharSet.Ansi)]
+ public static unsafe partial int ldap_get_option_secInfo(ConnectionHandle ldapHandle, LdapOption option, void* outValue);
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_option", CharSet = CharSet.Ansi)]
public static partial int ldap_get_option_sechandle(ConnectionHandle ldapHandle, LdapOption option, ref SecurityHandle outValue);
@@ -109,11 +106,8 @@ internal static partial class Interop
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_get_values_len", CharSet = CharSet.Ansi)]
public static partial IntPtr ldap_get_values_len(ConnectionHandle ldapHandle, IntPtr result, string name);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.OpenLdap, EntryPoint = "ldap_result", CharSet = CharSet.Ansi, SetLastError = true)]
- public static extern int ldap_result(ConnectionHandle ldapHandle, int messageId, int all, LDAP_TIMEVAL timeout, ref IntPtr Mesage);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_result", CharSet = CharSet.Ansi, SetLastError = true)]
+ public static partial int ldap_result(ConnectionHandle ldapHandle, int messageId, int all, in LDAP_TIMEVAL timeout, ref IntPtr Mesage);
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_result2error", CharSet = CharSet.Ansi)]
public static partial int ldap_result2error(ConnectionHandle ldapHandle, IntPtr result, int freeIt);
@@ -139,11 +133,8 @@ internal static partial class Interop
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", CharSet = CharSet.Ansi)]
public static partial int ldap_set_option_string(ConnectionHandle ldapHandle, LdapOption option, string inValue);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", CharSet = CharSet.Ansi)]
- public static extern int ldap_set_option_referral(ConnectionHandle ldapHandle, LdapOption option, ref LdapReferralCallback outValue);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_set_option", CharSet = CharSet.Ansi)]
+ public static partial int ldap_set_option_referral(ConnectionHandle ldapHandle, LdapOption option, ref LdapReferralCallback outValue);
// Note that ldap_start_tls_s has a different signature across Windows LDAP and OpenLDAP
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_start_tls_s", CharSet = CharSet.Ansi)]
@@ -161,11 +152,8 @@ internal static partial class Interop
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_parse_reference", CharSet = CharSet.Ansi)]
public static partial int ldap_parse_reference(ConnectionHandle ldapHandle, IntPtr result, ref IntPtr referrals, IntPtr ServerControls, byte freeIt);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.OpenLdap, EntryPoint = "ldap_sasl_bind_s", CharSet = CharSet.Ansi)]
- internal static extern int ldap_sasl_bind(ConnectionHandle ld, string dn, string mechanism, BerVal cred, IntPtr serverctrls, IntPtr clientctrls, IntPtr servercredp);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_sasl_bind_s", CharSet = CharSet.Ansi)]
+ internal static partial int ldap_sasl_bind(ConnectionHandle ld, string dn, string mechanism, in BerVal cred, IntPtr serverctrls, IntPtr clientctrls, IntPtr servercredp);
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_sasl_interactive_bind_s", CharSet = CharSet.Ansi)]
internal static partial int ldap_sasl_interactive_bind(ConnectionHandle ld, string dn, string mechanism, IntPtr serverctrls, IntPtr clientctrls, uint flags, LDAP_SASL_INTERACT_PROC proc, IntPtr defaults);
@@ -173,11 +161,8 @@ internal static partial class Interop
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_err2string", CharSet = CharSet.Ansi)]
public static partial IntPtr ldap_err2string(int err);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.OpenLdap, EntryPoint = "ldap_extended_operation", CharSet = CharSet.Ansi)]
- public static extern int ldap_extended_operation(ConnectionHandle ldapHandle, string oid, BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_extended_operation", CharSet = CharSet.Ansi)]
+ public static partial int ldap_extended_operation(ConnectionHandle ldapHandle, string oid, in BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_first_attribute", CharSet = CharSet.Ansi)]
public static partial IntPtr ldap_first_attribute(ConnectionHandle ldapHandle, IntPtr result, ref IntPtr address);
@@ -233,10 +218,7 @@ internal static partial class Interop
[GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_rename", CharSet = CharSet.Ansi)]
public static partial int ldap_rename(ConnectionHandle ldapHandle, string dn, string newRdn, string newParentDn, int deleteOldRdn, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.OpenLdap, EntryPoint = "ldap_compare_ext", CharSet = CharSet.Ansi)]
- public static extern int ldap_compare(ConnectionHandle ldapHandle, string dn, string attributeName, BerVal binaryValue, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.OpenLdap, EntryPoint = "ldap_compare_ext", CharSet = CharSet.Ansi)]
+ public static partial int ldap_compare(ConnectionHandle ldapHandle, string dn, string attributeName, in BerVal binaryValue, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
}
}
diff --git a/src/libraries/Common/src/Interop/OSX/Interop.libc.cs b/src/libraries/Common/src/Interop/OSX/Interop.libc.cs
index 8157ef8c9a5..51cf2ac16b7 100644
--- a/src/libraries/Common/src/Interop/OSX/Interop.libc.cs
+++ b/src/libraries/Common/src/Interop/OSX/Interop.libc.cs
@@ -23,11 +23,8 @@ internal static partial class Interop
public const uint ATTR_CMN_CRTIME = 0x00000200;
}
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like CULong)
- [DllImport(Libraries.libc, EntryPoint = "setattrlist", SetLastError = true)]
- internal static unsafe extern int setattrlist(string path, AttrList* attrList, void* attrBuf, nint attrBufSize, CULong options);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(Libraries.libc, EntryPoint = "setattrlist", CharSet = CharSet.Ansi, SetLastError = true)]
+ internal static unsafe partial int setattrlist(string path, AttrList* attrList, void* attrBuf, nint attrBufSize, CULong options);
internal const uint FSOPT_NOFOLLOW = 0x00000001;
}
diff --git a/src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.iOS.cs b/src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.iOS.cs
index 8d73184ca4d..3b113c29c94 100644
--- a/src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.iOS.cs
+++ b/src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.iOS.cs
@@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class Sys
{
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SearchPath_TempDirectory")]
- internal static extern string SearchPathTempDirectory();
+ [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_SearchPath_TempDirectory", CharSet = CharSet.Ansi)]
+ internal static partial string SearchPathTempDirectory();
}
}
diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Abort.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Abort.cs
index 3d040c31545..c8abb85f00b 100644
--- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Abort.cs
+++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Abort.cs
@@ -10,7 +10,7 @@ internal static partial class Interop
internal unsafe partial class Sys
{
[DoesNotReturn]
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_Abort")]
- internal static extern void Abort();
+ [GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_Abort")]
+ internal static partial void Abort();
}
}
diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.DynamicLoad.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.DynamicLoad.cs
index 6fd3ab2bba6..a6ccd9121d8 100644
--- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.DynamicLoad.cs
+++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.DynamicLoad.cs
@@ -8,16 +8,16 @@ internal static partial class Interop
{
internal unsafe partial class Sys
{
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_LoadLibrary")]
- internal static extern IntPtr LoadLibrary(string filename);
+ [GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_LoadLibrary", CharSet = CharSet.Ansi)]
+ internal static partial IntPtr LoadLibrary(string filename);
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetProcAddress")]
- internal static extern IntPtr GetProcAddress(IntPtr handle, byte* symbol);
+ [GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetProcAddress")]
+ internal static partial IntPtr GetProcAddress(IntPtr handle, byte* symbol);
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetProcAddress")]
- internal static extern IntPtr GetProcAddress(IntPtr handle, string symbol);
+ [GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_GetProcAddress", CharSet = CharSet.Ansi)]
+ internal static partial IntPtr GetProcAddress(IntPtr handle, string symbol);
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_FreeLibrary")]
- internal static extern void FreeLibrary(IntPtr handle);
+ [GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_FreeLibrary")]
+ internal static partial void FreeLibrary(IntPtr handle);
}
}
diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Exit.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Exit.cs
index a1e4d94149b..69d57113aea 100644
--- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Exit.cs
+++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Exit.cs
@@ -10,7 +10,7 @@ internal static partial class Interop
internal unsafe partial class Sys
{
[DoesNotReturn]
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_Exit")]
- internal static extern void Exit(int exitCode);
+ [GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_Exit")]
+ internal static partial void Exit(int exitCode);
}
}
diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SchedGetCpu.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SchedGetCpu.cs
index afc91ab8a73..464dc333e07 100644
--- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SchedGetCpu.cs
+++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.SchedGetCpu.cs
@@ -8,7 +8,7 @@ internal static partial class Interop
{
internal unsafe partial class Sys
{
- [DllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_SchedGetCpu")]
- internal static extern int SchedGetCpu();
+ [GeneratedDllImport(Interop.Libraries.SystemNative, EntryPoint = "SystemNative_SchedGetCpu")]
+ internal static partial int SchedGetCpu();
}
}
diff --git a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Threading.cs b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Threading.cs
index cecbaca6de6..b948e77edef 100644
--- a/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Threading.cs
+++ b/src/libraries/Common/src/Interop/Unix/System.Native/Interop.Threading.cs
@@ -8,7 +8,7 @@ internal static partial class Interop
{
internal unsafe partial class Sys
{
- [DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateThread")]
- internal static extern unsafe bool CreateThread(IntPtr stackSize, delegate* unmanaged<IntPtr, IntPtr> startAddress, IntPtr parameter);
+ [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateThread")]
+ internal static unsafe partial bool CreateThread(IntPtr stackSize, delegate* unmanaged<IntPtr, IntPtr> startAddress, IntPtr parameter);
}
}
diff --git a/src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs b/src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs
index f3344792900..844d5c967cb 100644
--- a/src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs
+++ b/src/libraries/Common/src/Interop/Unix/System.Net.Security.Native/Interop.GssBuffer.cs
@@ -34,7 +34,7 @@ internal static partial class Interop
throw new NetSecurityNative.GssApiException(SR.Format(SR.net_context_buffer_too_small, sourceLength, destinationAvailable));
}
- Marshal.Copy(_data, destination, offset, sourceLength);
+ Span.CopyTo(destination.AsSpan(offset, sourceLength));
return sourceLength;
}
@@ -47,7 +47,7 @@ internal static partial class Interop
int destinationLength = Convert.ToInt32(_length);
byte[] destination = new byte[destinationLength];
- Marshal.Copy(_data, destination, 0, destinationLength);
+ Span.CopyTo(destination);
return destination;
}
@@ -67,11 +67,11 @@ internal static partial class Interop
}
#if DEBUG
- static GssBuffer()
+ static unsafe GssBuffer()
{
// Verify managed size on both 32-bit and 64-bit matches the PAL_GssBuffer
// native struct size, which is also padded on 32-bit.
- Debug.Assert(Marshal.SizeOf<GssBuffer>() == 16);
+ Debug.Assert(sizeof(GssBuffer) == 16);
}
#endif
}
diff --git a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs
index 18668ca9c76..d599fe7ecf7 100644
--- a/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs
+++ b/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.Ssl.cs
@@ -218,8 +218,8 @@ internal static partial class Interop
}
}
- [DllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslAddExtraChainCert")]
- internal static extern bool SslAddExtraChainCert(SafeSslHandle ssl, SafeX509Handle x509);
+ [GeneratedDllImport(Libraries.CryptoNative, EntryPoint = "CryptoNative_SslAddExtraChainCert")]
+ internal static partial bool SslAddExtraChainCert(SafeSslHandle ssl, SafeX509Handle x509);
internal static bool AddExtraChainCertificates(SafeSslHandle ssl, X509Certificate2[] chain)
{
diff --git a/src/libraries/Common/src/Interop/Windows/Activeds/Interop.ADsOpenObject.cs b/src/libraries/Common/src/Interop/Windows/Activeds/Interop.ADsOpenObject.cs
index ee31cd67ab5..cadacc56ce0 100644
--- a/src/libraries/Common/src/Interop/Windows/Activeds/Interop.ADsOpenObject.cs
+++ b/src/libraries/Common/src/Interop/Windows/Activeds/Interop.ADsOpenObject.cs
@@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class Activeds
{
- [DllImport(Interop.Libraries.Activeds, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int ADsOpenObject(string path, string? userName, string? password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject);
+ [GeneratedDllImport(Interop.Libraries.Activeds, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int ADsOpenObject(string path, string? userName, string? password, int flags, ref Guid iid, out IntPtr ppObject);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs
index 99a82e00cc9..92d048b9be0 100644
--- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs
+++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptGetDefaultProvider.cs
@@ -15,14 +15,12 @@ internal static partial class Interop
CRYPT_USER_DEFAULT = 0x00000002
}
- [DllImport(Libraries.Advapi32, SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CryptGetDefaultProviderW")]
- public static extern bool CryptGetDefaultProvider(
+ [GeneratedDllImport(Libraries.Advapi32, EntryPoint = "CryptGetDefaultProviderW", CharSet = CharSet.Unicode, SetLastError = true)]
+ public static partial bool CryptGetDefaultProvider(
int dwProvType,
IntPtr pdwReserved,
GetDefaultProviderFlags dwFlags,
-#pragma warning disable CA1838 // not on a hot path
- [Out] StringBuilder? pszProvName,
-#pragma warning restore CA1838
+ [Out] char[]? pszProvName,
ref int pcbProvName);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs
index 07cfaf95a3d..8d140920cc2 100644
--- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs
+++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EtwEnableCallback.cs
@@ -21,7 +21,7 @@ internal static partial class Interop
}
internal unsafe delegate void EtwEnableCallback(
- in Guid sourceId,
+ Guid* sourceId,
int isEnabled,
byte level,
long matchAnyKeywords,
diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs
index 9490c198b02..cd7ccb56d29 100644
--- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs
+++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventActivityIdControl.cs
@@ -8,10 +8,7 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(Libraries.Advapi32, ExactSpelling = true)]
- internal static extern int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(Libraries.Advapi32, ExactSpelling = true)]
+ internal static partial int EventActivityIdControl(ActivityControl ControlCode, ref Guid ActivityId);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventRegister.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventRegister.cs
index 1cc64001df4..c7f7e756404 100644
--- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventRegister.cs
+++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.EventRegister.cs
@@ -8,14 +8,11 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(Libraries.Advapi32, ExactSpelling = true)]
- internal static unsafe extern uint EventRegister(
+ [GeneratedDllImport(Libraries.Advapi32, ExactSpelling = true)]
+ internal static unsafe partial uint EventRegister(
in Guid providerId,
EtwEnableCallback enableCallback,
void* callbackContext,
ref long registrationHandle);
-#pragma warning restore DLLIMPORTGENANALYZER015
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs
index 1e4c0309a09..f2ada1ff4f4 100644
--- a/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs
+++ b/src/libraries/Common/src/Interop/Windows/Advapi32/Interop.LsaLookupNames2.cs
@@ -9,10 +9,8 @@ internal static partial class Interop
{
internal static partial class Advapi32
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupNames2", CharSet = CharSet.Unicode, SetLastError = true)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- internal static extern uint LsaLookupNames2(
+ [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "LsaLookupNames2", CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial uint LsaLookupNames2(
SafeLsaPolicyHandle handle,
int flags,
int count,
@@ -20,15 +18,29 @@ internal static partial class Interop
out SafeLsaMemoryHandle referencedDomains,
out SafeLsaMemoryHandle sids
);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
+ [NativeMarshalling(typeof(Native))]
internal struct MARSHALLED_UNICODE_STRING
{
internal ushort Length;
internal ushort MaximumLength;
- [MarshalAs(UnmanagedType.LPWStr)]
internal string Buffer;
+
+ public struct Native
+ {
+ internal ushort Length;
+ internal ushort MaximumLength;
+ internal IntPtr Buffer;
+
+ public Native(MARSHALLED_UNICODE_STRING managed)
+ {
+ Length = managed.Length;
+ MaximumLength = managed.MaximumLength;
+ Buffer = Marshal.StringToCoTaskMemUni(managed.Buffer);
+ }
+
+ public void FreeNative() => Marshal.FreeCoTaskMem(Buffer);
+ }
}
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_DECRYPT_PARA.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_DECRYPT_PARA.cs
index 99c920e611b..db2d80bcc72 100644
--- a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_DECRYPT_PARA.cs
+++ b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_DECRYPT_PARA.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
@@ -12,7 +13,7 @@ internal static partial class Interop
internal struct CMSG_CTRL_DECRYPT_PARA
{
internal int cbSize;
- internal SafeProvOrNCryptKeyHandle hKey;
+ internal IntPtr hKey;
internal CryptKeySpec dwKeySpec;
internal int dwRecipientIndex;
}
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_KEY_AGREE_DECRYPT_PARA.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_KEY_AGREE_DECRYPT_PARA.cs
index 99a60f60786..7c57d09b713 100644
--- a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_KEY_AGREE_DECRYPT_PARA.cs
+++ b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CMSG_CTRL_KEY_AGREE_DECRYPT_PARA.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
@@ -13,7 +14,7 @@ internal static partial class Interop
internal unsafe struct CMSG_CTRL_KEY_AGREE_DECRYPT_PARA
{
internal int cbSize;
- internal SafeProvOrNCryptKeyHandle hProv;
+ internal IntPtr hProv;
internal CryptKeySpec dwKeySpec;
internal CMSG_KEY_AGREE_RECIPIENT_INFO* pKeyAgree;
internal int dwRecipientIndex;
diff --git a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptMsgControl.cs b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptMsgControl.cs
index 6bd86b24e18..1be46df6255 100644
--- a/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptMsgControl.cs
+++ b/src/libraries/Common/src/Interop/Windows/Crypt32/Interop.CryptMsgControl.cs
@@ -8,22 +8,18 @@ internal static partial class Interop
{
internal static partial class Crypt32
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we add support for non-blittable struct marshalling.
- [DllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern bool CryptMsgControl(
+ [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial bool CryptMsgControl(
SafeCryptMsgHandle hCryptMsg,
int dwFlags,
MsgControlType dwCtrlType,
ref CMSG_CTRL_DECRYPT_PARA pvCtrlPara);
- [DllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern bool CryptMsgControl(
+ [GeneratedDllImport(Libraries.Crypt32, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial bool CryptMsgControl(
SafeCryptMsgHandle hCryptMsg,
int dwFlags,
MsgControlType dwCtrlType,
ref CMSG_CTRL_KEY_AGREE_DECRYPT_PARA pvCtrlPara);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
-
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs b/src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs
index a82ac99918a..e98d1aeb621 100644
--- a/src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs
+++ b/src/libraries/Common/src/Interop/Windows/CryptUI/Interop.CryptUIDlgCertificate.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
@@ -9,8 +10,12 @@ internal static partial class Interop
{
internal static partial class CryptUI
{
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(Native))]
+#else
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal sealed class CRYPTUI_VIEWCERTIFICATE_STRUCTW
+#endif
+ internal struct CRYPTUI_VIEWCERTIFICATE_STRUCTW
{
internal uint dwSize;
internal IntPtr hwndParent;
@@ -30,10 +35,91 @@ internal static partial class Interop
internal uint cPropSheetPages;
internal IntPtr rgPropSheetPages;
internal uint nStartPage;
+
+#if NET7_0_OR_GREATER
+ internal unsafe struct Native
+ {
+ private uint dwSize;
+ private IntPtr hwndParent;
+ private uint dwFlags;
+ private IntPtr szTitle;
+ private IntPtr pCertContext;
+ private IntPtr rgszPurposes;
+ private uint cPurposes;
+ private IntPtr pCryptProviderData;
+ private bool fpCryptProviderDataTrustedUsage;
+ private uint idxSigner;
+ private uint idxCert;
+ private bool fCounterSigner;
+ private uint idxCounterSigner;
+ private uint cStores;
+ private IntPtr rghStores;
+ private uint cPropSheetPages;
+ private IntPtr rgPropSheetPages;
+ private uint nStartPage;
+
+ public Native(CRYPTUI_VIEWCERTIFICATE_STRUCTW managed)
+ {
+ dwSize = managed.dwSize;
+ hwndParent = managed.hwndParent;
+ dwFlags = managed.dwFlags;
+ szTitle = Marshal.StringToCoTaskMemUni(managed.szTitle);
+ pCertContext = managed.pCertContext;
+ rgszPurposes = managed.rgszPurposes;
+ cPurposes = managed.cPurposes;
+ pCryptProviderData = managed.pCryptProviderData;
+ fpCryptProviderDataTrustedUsage = managed.fpCryptProviderDataTrustedUsage;
+ idxSigner = managed.idxSigner;
+ idxCert = managed.idxCert;
+ fCounterSigner = managed.fCounterSigner;
+ idxCounterSigner = managed.idxCounterSigner;
+ cStores = managed.cStores;
+ rghStores = managed.rghStores;
+ cPropSheetPages = managed.cPropSheetPages;
+ rgPropSheetPages = managed.rgPropSheetPages;
+ nStartPage = managed.nStartPage;
+
+ }
+
+ public void FreeNative()
+ {
+ Marshal.FreeCoTaskMem(szTitle);
+ }
+
+ public CRYPTUI_VIEWCERTIFICATE_STRUCTW ToManaged()
+ {
+ return new()
+ {
+ dwSize = dwSize,
+ hwndParent = hwndParent,
+ dwFlags = dwFlags,
+ szTitle = Marshal.PtrToStringUni(szTitle),
+ pCertContext = pCertContext,
+ rgszPurposes = rgszPurposes,
+ cPurposes = cPurposes,
+ pCryptProviderData = pCryptProviderData,
+ fpCryptProviderDataTrustedUsage = fpCryptProviderDataTrustedUsage,
+ idxSigner = idxSigner,
+ idxCert = idxCert,
+ fCounterSigner = fCounterSigner,
+ idxCounterSigner = idxCounterSigner,
+ cStores = cStores,
+ rghStores = rghStores,
+ cPropSheetPages = cPropSheetPages,
+ rgPropSheetPages = rgPropSheetPages,
+ nStartPage = nStartPage
+ };
+ }
+ }
+#endif
}
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(Native))]
+#else
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal sealed class CRYPTUI_SELECTCERTIFICATE_STRUCTW
+#endif
+ internal struct CRYPTUI_SELECTCERTIFICATE_STRUCTW
{
internal uint dwSize;
internal IntPtr hwndParent;
@@ -51,15 +137,84 @@ internal static partial class Interop
internal uint cPropSheetPages;
internal IntPtr rgPropSheetPages;
internal IntPtr hSelectedCertStore;
+
+#if NET7_0_OR_GREATER
+ internal unsafe struct Native
+ {
+ private uint dwSize;
+ private IntPtr hwndParent;
+ private uint dwFlags;
+ private IntPtr szTitle;
+ private uint dwDontUseColumn;
+ private IntPtr szDisplayString;
+ private IntPtr pFilterCallback;
+ private IntPtr pDisplayCallback;
+ private IntPtr pvCallbackData;
+ private uint cDisplayStores;
+ private IntPtr rghDisplayStores;
+ private uint cStores;
+ private IntPtr rghStores;
+ private uint cPropSheetPages;
+ private IntPtr rgPropSheetPages;
+ internal IntPtr hSelectedCertStore;
+
+ public Native(CRYPTUI_SELECTCERTIFICATE_STRUCTW managed)
+ {
+ dwSize = managed.dwSize;
+ hwndParent = managed.hwndParent;
+ dwFlags = managed.dwFlags;
+ szTitle = Marshal.StringToCoTaskMemUni(managed.szTitle);
+ dwDontUseColumn = managed.dwDontUseColumn;
+ szDisplayString = Marshal.StringToCoTaskMemUni(managed.szDisplayString);
+ pFilterCallback = managed.pFilterCallback;
+ pDisplayCallback = managed.pDisplayCallback;
+ pvCallbackData = managed.pvCallbackData;
+ cDisplayStores = managed.cDisplayStores;
+ rghDisplayStores = managed.rghDisplayStores;
+ cStores = managed.cStores;
+ rghStores = managed.rghStores;
+ cPropSheetPages = managed.cPropSheetPages;
+ rgPropSheetPages = managed.rgPropSheetPages;
+ hSelectedCertStore = managed.hSelectedCertStore;
+ }
+
+ public void FreeNative()
+ {
+ Marshal.FreeCoTaskMem(szTitle);
+ Marshal.FreeCoTaskMem(szDisplayString);
+ }
+
+ public CRYPTUI_SELECTCERTIFICATE_STRUCTW ToManaged()
+ {
+ return new()
+ {
+ dwSize = dwSize,
+ hwndParent = hwndParent,
+ dwFlags = dwFlags,
+ szTitle = Marshal.PtrToStringUni(szTitle),
+ dwDontUseColumn = dwDontUseColumn,
+ szDisplayString = Marshal.PtrToStringUni(szDisplayString),
+ pFilterCallback = pFilterCallback,
+ pDisplayCallback = pDisplayCallback,
+ pvCallbackData = pvCallbackData,
+ cDisplayStores = cDisplayStores,
+ rghDisplayStores = rghDisplayStores,
+ cStores = cStores,
+ rghStores = rghStores,
+ cPropSheetPages = cPropSheetPages,
+ rgPropSheetPages = rgPropSheetPages,
+ hSelectedCertStore = hSelectedCertStore
+ };
+ }
+ }
+#endif
}
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
- [DllImport(Interop.Libraries.CryptUI, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
- internal static extern bool CryptUIDlgViewCertificateW([MarshalAs(UnmanagedType.LPStruct)] CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo, IntPtr pfPropertiesChanged);
+ [GeneratedDllImport(Interop.Libraries.CryptUI, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
+ internal static partial bool CryptUIDlgViewCertificateW(
+ in CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo, IntPtr pfPropertiesChanged);
- [DllImport(Interop.Libraries.CryptUI, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
- internal static extern SafeCertContextHandle CryptUIDlgSelectCertificateW([In, Out, MarshalAs(UnmanagedType.LPStruct)] CRYPTUI_SELECTCERTIFICATE_STRUCTW csc);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(Interop.Libraries.CryptUI, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
+ internal static partial SafeCertContextHandle CryptUIDlgSelectCertificateW(ref CRYPTUI_SELECTCERTIFICATE_STRUCTW csc);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.OffsetViewportOrgEx.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.OffsetViewportOrgEx.cs
index 8768fd8493b..b9147cf1631 100644
--- a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.OffsetViewportOrgEx.cs
+++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.OffsetViewportOrgEx.cs
@@ -9,11 +9,8 @@ internal static partial class Interop
{
internal static partial class Gdi32
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(Libraries.Gdi32)]
- public static extern bool OffsetViewportOrgEx(IntPtr hdc, int x, int y, ref Point lppt);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.Gdi32)]
+ public static partial bool OffsetViewportOrgEx(IntPtr hdc, int x, int y, ref Point lppt);
public static bool OffsetViewportOrgEx(HandleRef hdc, int x, int y, ref Point lppt)
{
diff --git a/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs b/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs
index b3c412c4b8c..def17790cb7 100644
--- a/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs
+++ b/src/libraries/Common/src/Interop/Windows/IpHlpApi/Interop.NetworkInformation.cs
@@ -236,7 +236,7 @@ internal static partial class Interop
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
- internal struct MibIfRow2 // MIB_IF_ROW2
+ internal unsafe struct MibIfRow2 // MIB_IF_ROW2
{
private const int GuidLength = 16;
private const int IfMaxStringSize = 256;
@@ -244,17 +244,12 @@ internal static partial class Interop
internal ulong interfaceLuid;
internal uint interfaceIndex;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = GuidLength)]
- internal byte[] interfaceGuid;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = IfMaxStringSize + 1)]
- internal char[] alias; // Null terminated string.
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = IfMaxStringSize + 1)]
- internal char[] description; // Null terminated string.
+ internal Guid interfaceGuid;
+ internal fixed char alias[IfMaxStringSize + 1]; // Null terminated string.
+ internal fixed char description[IfMaxStringSize + 1]; // Null terminated string.
internal uint physicalAddressLength;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = IfMaxPhysAddressLength)]
- internal byte[] physicalAddress; // ANSI
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = IfMaxPhysAddressLength)]
- internal byte[] permanentPhysicalAddress; // ANSI
+ internal fixed byte physicalAddress[IfMaxPhysAddressLength]; // ANSI
+ internal fixed byte permanentPhysicalAddress[IfMaxPhysAddressLength]; // ANSI
internal uint mtu;
internal NetworkInterfaceType type;
internal InterfaceTunnelType tunnelType;
@@ -266,8 +261,7 @@ internal static partial class Interop
internal OperationalStatus operStatus;
internal uint adminStatus; // Enum
internal uint mediaConnectState; // Enum
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = GuidLength)]
- internal byte[] networkGuid;
+ internal Guid networkGuid;
internal InterfaceConnectionType connectionType;
internal ulong transmitLinkSpeed;
internal ulong receiveLinkSpeed;
@@ -382,12 +376,11 @@ internal static partial class Interop
}
[StructLayout(LayoutKind.Sequential)]
- internal struct MibIcmpStatsEx
+ internal unsafe struct MibIcmpStatsEx
{
internal uint dwMsgs;
internal uint dwErrors;
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
- internal uint[] rgdwTypeCount;
+ internal fixed uint rgdwTypeCount[256];
}
[StructLayout(LayoutKind.Sequential)]
@@ -519,11 +512,8 @@ internal static partial class Interop
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
internal static unsafe partial uint GetBestInterfaceEx(byte* ipAddress, int* index);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Interop.Libraries.IpHlpApi)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
- internal static extern uint GetIfEntry2(ref MibIfRow2 pIfRow);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Interop.Libraries.IpHlpApi)]
+ internal static partial uint GetIfEntry2(ref MibIfRow2 pIfRow);
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
internal static unsafe partial uint GetIpStatisticsEx(MibIpStats* statistics, AddressFamily family);
@@ -537,11 +527,8 @@ internal static partial class Interop
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
internal static unsafe partial uint GetIcmpStatistics(MibIcmpInfo* statistics);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Interop.Libraries.IpHlpApi)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
- internal static extern uint GetIcmpStatisticsEx(out MibIcmpInfoEx statistics, AddressFamily family);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Interop.Libraries.IpHlpApi)]
+ internal static partial uint GetIcmpStatisticsEx(out MibIcmpInfoEx statistics, AddressFamily family);
[GeneratedDllImport(Interop.Libraries.IpHlpApi)]
internal static unsafe partial uint GetTcpTable(IntPtr pTcpTable, uint* dwOutBufLen, bool order);
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DynamicLoad.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DynamicLoad.cs
index c0a0a2aeb5f..538e5bc43df 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DynamicLoad.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.DynamicLoad.cs
@@ -10,7 +10,7 @@ internal static partial class Interop
{
internal static unsafe partial class Kernel32
{
- [DllImport(Libraries.Kernel32)]
- internal static extern IntPtr GetProcAddress(IntPtr hModule, byte* lpProcName);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static partial IntPtr GetProcAddress(IntPtr hModule, byte* lpProcName);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ExitProcess.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ExitProcess.cs
index af50326e977..ff363379595 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ExitProcess.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ExitProcess.cs
@@ -11,7 +11,7 @@ internal static partial class Interop
internal static unsafe partial class Kernel32
{
[DoesNotReturn]
- [DllImport(Libraries.Kernel32, EntryPoint = "ExitProcess")]
- internal static extern void ExitProcess(int exitCode);
+ [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "ExitProcess")]
+ internal static partial void ExitProcess(int exitCode);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessorNumber.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessorNumber.cs
index 4ebdc93faf9..13865d75fe3 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessorNumber.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetCurrentProcessorNumber.cs
@@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
- [DllImport(Libraries.Kernel32)]
- internal static extern uint GetCurrentProcessorNumber();
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static partial uint GetCurrentProcessorNumber();
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetProcessName.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetProcessName.cs
index 293a9c0ee49..c3146abb588 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetProcessName.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetProcessName.cs
@@ -10,8 +10,8 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
- [DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "QueryFullProcessImageNameW", ExactSpelling = true, SetLastError = true)]
- private static unsafe extern bool QueryFullProcessImageName(
+ [GeneratedDllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, EntryPoint = "QueryFullProcessImageNameW", ExactSpelling = true, SetLastError = true)]
+ private static unsafe partial bool QueryFullProcessImageName(
SafeHandle hProcess,
uint dwFlags,
char* lpBuffer,
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetTickCount64.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetTickCount64.cs
index 97e3349aef8..b0b6d90baae 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetTickCount64.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetTickCount64.cs
@@ -9,8 +9,8 @@ internal static partial class Interop
{
internal static unsafe partial class Kernel32
{
- [DllImport(Libraries.Kernel32)]
+ [GeneratedDllImport(Libraries.Kernel32)]
[SuppressGCTransition]
- internal static extern ulong GetTickCount64();
+ internal static partial ulong GetTickCount64();
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.IsDebuggerPresent.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.IsDebuggerPresent.cs
index 232ac6b8f67..95cc4f1e1f8 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.IsDebuggerPresent.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.IsDebuggerPresent.cs
@@ -8,7 +8,7 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
- [DllImport(Libraries.Kernel32)]
- internal static extern bool IsDebuggerPresent();
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static partial bool IsDebuggerPresent();
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.RaiseFailFastException.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.RaiseFailFastException.cs
index 1e80b373368..004ca3a4376 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.RaiseFailFastException.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.RaiseFailFastException.cs
@@ -49,9 +49,9 @@ internal partial class Interop
pExAddress == IntPtr.Zero ? FAIL_FAST_GENERATE_EXCEPTION_ADDRESS : 0);
}
- [DllImport(Libraries.Kernel32, EntryPoint = "RaiseFailFastException")]
+ [GeneratedDllImport(Libraries.Kernel32, EntryPoint = "RaiseFailFastException")]
[DoesNotReturn]
- private static extern unsafe void RaiseFailFastException(
+ private static unsafe partial void RaiseFailFastException(
EXCEPTION_RECORD* pExceptionRecord,
IntPtr pContextRecord,
uint dwFlags);
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPool.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPool.cs
index a7d9abdaf47..d68aa0f19d2 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPool.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPool.cs
@@ -8,25 +8,25 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe IntPtr CreateThreadpoolWork(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> pfnwk, IntPtr pv, IntPtr pcbe);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial IntPtr CreateThreadpoolWork(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> pfnwk, IntPtr pv, IntPtr pcbe);
- [DllImport(Libraries.Kernel32)]
- internal static extern void SubmitThreadpoolWork(IntPtr pwk);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static partial void SubmitThreadpoolWork(IntPtr pwk);
- [DllImport(Libraries.Kernel32)]
- internal static extern void CloseThreadpoolWork(IntPtr pwk);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static partial void CloseThreadpoolWork(IntPtr pwk);
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe IntPtr CreateThreadpoolWait(delegate* unmanaged<IntPtr, IntPtr, IntPtr, uint, void> pfnwa, IntPtr pv, IntPtr pcbe);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial IntPtr CreateThreadpoolWait(delegate* unmanaged<IntPtr, IntPtr, IntPtr, uint, void> pfnwa, IntPtr pv, IntPtr pcbe);
- [DllImport(Libraries.Kernel32)]
- internal static extern void SetThreadpoolWait(IntPtr pwa, IntPtr h, IntPtr pftTimeout);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static partial void SetThreadpoolWait(IntPtr pwa, IntPtr h, IntPtr pftTimeout);
- [DllImport(Libraries.Kernel32)]
- internal static extern void WaitForThreadpoolWaitCallbacks(IntPtr pwa, bool fCancelPendingCallbacks);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static partial void WaitForThreadpoolWaitCallbacks(IntPtr pwa, bool fCancelPendingCallbacks);
- [DllImport(Libraries.Kernel32)]
- internal static extern void CloseThreadpoolWait(IntPtr pwa);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static partial void CloseThreadpoolWait(IntPtr pwa);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPoolIO.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPoolIO.cs
index 7dd7435c6a8..a0dda79bdf2 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPoolIO.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ThreadPoolIO.cs
@@ -9,16 +9,16 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
- [DllImport(Libraries.Kernel32, SetLastError = true)]
- internal static unsafe extern SafeThreadPoolIOHandle CreateThreadpoolIo(SafeHandle fl, delegate* unmanaged<IntPtr, IntPtr, IntPtr, uint, UIntPtr, IntPtr, void> pfnio, IntPtr context, IntPtr pcbe);
+ [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static unsafe partial SafeThreadPoolIOHandle CreateThreadpoolIo(SafeHandle fl, delegate* unmanaged<IntPtr, IntPtr, IntPtr, uint, UIntPtr, IntPtr, void> pfnio, IntPtr context, IntPtr pcbe);
- [DllImport(Libraries.Kernel32)]
- internal static unsafe extern void CloseThreadpoolIo(IntPtr pio);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial void CloseThreadpoolIo(IntPtr pio);
- [DllImport(Libraries.Kernel32)]
- internal static unsafe extern void StartThreadpoolIo(SafeThreadPoolIOHandle pio);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial void StartThreadpoolIo(SafeThreadPoolIOHandle pio);
- [DllImport(Libraries.Kernel32)]
- internal static unsafe extern void CancelThreadpoolIo(SafeThreadPoolIOHandle pio);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial void CancelThreadpoolIo(SafeThreadPoolIOHandle pio);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.Timer.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.Timer.cs
index 19f4987d14f..1fcf7da5583 100644
--- a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.Timer.cs
+++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.Timer.cs
@@ -8,10 +8,10 @@ internal static partial class Interop
{
internal static partial class Kernel32
{
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe IntPtr CreateThreadpoolTimer(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> pfnti, IntPtr pv, IntPtr pcbe);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial IntPtr CreateThreadpoolTimer(delegate* unmanaged<IntPtr, IntPtr, IntPtr, void> pfnti, IntPtr pv, IntPtr pcbe);
- [DllImport(Libraries.Kernel32)]
- internal static extern unsafe IntPtr SetThreadpoolTimer(IntPtr pti, long* pftDueTime, uint msPeriod, uint msWindowLength);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial IntPtr SetThreadpoolTimer(IntPtr pti, long* pftDueTime, uint msPeriod, uint msWindowLength);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CLSIDFromProgID.cs b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CLSIDFromProgID.cs
index fec2251f01e..0b7c7450080 100644
--- a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CLSIDFromProgID.cs
+++ b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CLSIDFromProgID.cs
@@ -8,10 +8,7 @@ internal static partial class Interop
{
internal static partial class Ole32
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(Interop.Libraries.Ole32, CharSet = CharSet.Unicode)]
- internal static extern int CLSIDFromProgID(string lpszProgID, out Guid lpclsid);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(Interop.Libraries.Ole32, CharSet = CharSet.Unicode)]
+ internal static partial int CLSIDFromProgID(string lpszProgID, out Guid lpclsid);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoCreateGuid.cs b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoCreateGuid.cs
index f79f17e3ec6..e2cc05f7578 100644
--- a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoCreateGuid.cs
+++ b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoCreateGuid.cs
@@ -8,10 +8,7 @@ internal static partial class Interop
{
internal static partial class Ole32
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(Interop.Libraries.Ole32)]
- internal static extern int CoCreateGuid(out Guid guid);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(Interop.Libraries.Ole32)]
+ internal static partial int CoCreateGuid(out Guid guid);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetApartmentType.cs b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetApartmentType.cs
index 01abd6333c8..970bd32f46e 100644
--- a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetApartmentType.cs
+++ b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetApartmentType.cs
@@ -29,7 +29,7 @@ internal static partial class Interop
internal static partial class Ole32
{
- [DllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
- internal static extern int CoGetApartmentType(out APTTYPE pAptType, out APTTYPEQUALIFIER pAptQualifier);
+ [GeneratedDllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
+ internal static partial int CoGetApartmentType(out APTTYPE pAptType, out APTTYPEQUALIFIER pAptQualifier);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetObjectContext.cs b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetObjectContext.cs
index 851878a8155..af00fce67e3 100644
--- a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetObjectContext.cs
+++ b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoGetObjectContext.cs
@@ -8,10 +8,16 @@ internal static partial class Interop
{
internal static partial class Ole32
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(Libraries.Ole32)]
- internal static extern int CoGetObjectContext([MarshalAs(UnmanagedType.LPStruct)] Guid riid, out IntPtr ppv);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ internal static unsafe int CoGetObjectContext(in Guid riid, out IntPtr ppv)
+ {
+ fixed (Guid* riidPtr = &riid)
+ fixed (IntPtr* ppvPtr = &ppv)
+ {
+ return CoGetObjectContext(riidPtr, ppvPtr);
+ }
+ }
+
+ [GeneratedDllImport(Libraries.Ole32)]
+ internal static unsafe partial int CoGetObjectContext(Guid* riid, IntPtr* ppv);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoInitializeEx.cs b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoInitializeEx.cs
index 7be311659ca..394b935685c 100644
--- a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoInitializeEx.cs
+++ b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoInitializeEx.cs
@@ -12,7 +12,7 @@ internal static partial class Interop
internal const uint COINIT_APARTMENTTHREADED = 2;
internal const uint COINIT_MULTITHREADED = 0;
- [DllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
- internal static extern int CoInitializeEx(IntPtr reserved, uint dwCoInit);
+ [GeneratedDllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
+ internal static partial int CoInitializeEx(IntPtr reserved, uint dwCoInit);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoUninitialize.cs b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoUninitialize.cs
index 2e92ce2a113..c19f3774d26 100644
--- a/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoUninitialize.cs
+++ b/src/libraries/Common/src/Interop/Windows/Ole32/Interop.CoUninitialize.cs
@@ -9,7 +9,7 @@ internal static partial class Interop
{
internal static partial class Ole32
{
- [DllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
- internal static extern int CoUninitialize();
+ [GeneratedDllImport(Interop.Libraries.Ole32, ExactSpelling = true)]
+ internal static partial int CoUninitialize();
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/PerfCounter/Interop.PerformanceData.cs b/src/libraries/Common/src/Interop/Windows/PerfCounter/Interop.PerformanceData.cs
index 1d266d08596..e6208dc3fa6 100644
--- a/src/libraries/Common/src/Interop/Windows/PerfCounter/Interop.PerformanceData.cs
+++ b/src/libraries/Common/src/Interop/Windows/PerfCounter/Interop.PerformanceData.cs
@@ -53,24 +53,20 @@ internal static partial class Interop
internal uint InstanceNameSize;
}
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(Libraries.Advapi32, ExactSpelling = true)]
- internal static extern uint PerfStartProvider(
+ [GeneratedDllImport(Libraries.Advapi32, ExactSpelling = true)]
+ internal static partial uint PerfStartProvider(
ref Guid ProviderGuid,
PERFLIBREQUEST ControlCallback,
out SafePerfProviderHandle phProvider
);
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(Libraries.Advapi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
- internal static extern unsafe PerfCounterSetInstanceStruct* PerfCreateInstance(
+ [GeneratedDllImport(Libraries.Advapi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
+ internal static unsafe partial PerfCounterSetInstanceStruct* PerfCreateInstance(
SafePerfProviderHandle hProvider,
ref Guid CounterSetGuid,
string szInstanceName,
uint dwInstance
);
-#pragma warning restore DLLIMPORTGENANALYZER015
[GeneratedDllImport(Libraries.Advapi32, ExactSpelling = true)]
internal static unsafe partial uint PerfSetCounterSetInfo(
diff --git a/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
index 5b3eaba1d14..7e5bf2718ee 100644
--- a/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
+++ b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.SHGetKnownFolderPath.cs
@@ -10,16 +10,13 @@ internal static partial class Interop
{
internal const int COR_E_PLATFORMNOTSUPPORTED = unchecked((int)0x80131539);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
// https://msdn.microsoft.com/en-us/library/windows/desktop/bb762188.aspx
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- [DllImport(Libraries.Shell32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)]
- internal static extern int SHGetKnownFolderPath(
- [MarshalAs(UnmanagedType.LPStruct)] Guid rfid,
+ [GeneratedDllImport(Libraries.Shell32, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = false)]
+ internal static partial int SHGetKnownFolderPath(
+ in Guid rfid,
uint dwFlags,
IntPtr hToken,
out string ppszPath);
-#pragma warning restore DLLIMPORTGENANALYZER015
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx
internal static class KnownFolders
diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs
index 6be3ad7e6dd..83efbbaab90 100644
--- a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs
+++ b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.LsaLogonUser.cs
@@ -10,25 +10,22 @@ internal static partial class Interop
{
internal static partial class SspiCli
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Libraries.SspiCli)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- internal static extern int LsaLogonUser(
- [In] SafeLsaHandle LsaHandle,
- [In] ref Advapi32.LSA_STRING OriginName,
- [In] SECURITY_LOGON_TYPE LogonType,
- [In] int AuthenticationPackage,
- [In] IntPtr AuthenticationInformation,
- [In] int AuthenticationInformationLength,
- [In] IntPtr LocalGroups,
- [In] ref TOKEN_SOURCE SourceContext,
- [Out] out SafeLsaReturnBufferHandle ProfileBuffer,
- [Out] out int ProfileBufferLength,
- [Out] out LUID LogonId,
- [Out] out SafeAccessTokenHandle Token,
- [Out] out QUOTA_LIMITS Quotas,
- [Out] out int SubStatus
+ [GeneratedDllImport(Libraries.SspiCli)]
+ internal static partial int LsaLogonUser(
+ SafeLsaHandle LsaHandle,
+ in Advapi32.LSA_STRING OriginName,
+ SECURITY_LOGON_TYPE LogonType,
+ int AuthenticationPackage,
+ IntPtr AuthenticationInformation,
+ int AuthenticationInformationLength,
+ IntPtr LocalGroups,
+ in TOKEN_SOURCE SourceContext,
+ out SafeLsaReturnBufferHandle ProfileBuffer,
+ out int ProfileBufferLength,
+ out LUID LogonId,
+ out SafeAccessTokenHandle Token,
+ out QUOTA_LIMITS Quotas,
+ out int SubStatus
);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs
index 84e30b45ef9..7fd660cb2ba 100644
--- a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs
+++ b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.SSPI.cs
@@ -344,13 +344,10 @@ internal static partial class Interop
uint sequenceNumber,
uint* qualityOfProtection);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- internal static extern int QuerySecurityContextToken(
+ [GeneratedDllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)]
+ internal static partial int QuerySecurityContextToken(
ref CredHandle phContext,
out SecurityContextTokenHandle handle);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
[GeneratedDllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)]
internal static partial int FreeContextBuffer(
@@ -478,14 +475,11 @@ internal static partial class Interop
string password,
out SafeSspiAuthDataHandle authData);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Interop.Libraries.SspiCli, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- internal static extern SECURITY_STATUS SetCredentialsAttributesW(
+ [GeneratedDllImport(Interop.Libraries.SspiCli, ExactSpelling = true, SetLastError = true)]
+ internal static partial SECURITY_STATUS SetCredentialsAttributesW(
in CredHandle handlePtr,
long ulAttribute,
in SecPkgCred_ClientCertPolicy pBuffer,
long cbBuffer);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.TokenSource.cs b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.TokenSource.cs
index abee3daa3b3..130497fd917 100644
--- a/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.TokenSource.cs
+++ b/src/libraries/Common/src/Interop/Windows/SspiCli/Interop.TokenSource.cs
@@ -9,10 +9,9 @@ internal static partial class Interop
internal static partial class SspiCli
{
[StructLayout(LayoutKind.Sequential)]
- internal struct TOKEN_SOURCE
+ internal unsafe struct TOKEN_SOURCE
{
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = TOKEN_SOURCE_LENGTH)]
- internal byte[] SourceName;
+ internal fixed byte SourceName[TOKEN_SOURCE_LENGTH];
internal LUID SourceIdentifier;
internal const int TOKEN_SOURCE_LENGTH = 8;
diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs
index daee2bf32eb..375be2c949b 100644
--- a/src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs
+++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.GetWindowThreadProcessId.cs
@@ -10,8 +10,5 @@ internal static partial class Interop
{
[GeneratedDllImport(Libraries.User32, ExactSpelling = true)]
public static unsafe partial int GetWindowThreadProcessId(IntPtr handle, int* processId);
-
- [DllImport(Libraries.User32, ExactSpelling = true)]
- public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.PostMessage.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.PostMessage.cs
index 962ccd2e2be..157e12f845f 100644
--- a/src/libraries/Common/src/Interop/Windows/User32/Interop.PostMessage.cs
+++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.PostMessage.cs
@@ -10,8 +10,5 @@ internal static partial class Interop
{
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial int PostMessageW(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam);
-
- [DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
- public static extern int PostMessageW(HandleRef hwnd, int msg, IntPtr wparam, IntPtr lparam);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.SendMessage.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.SendMessage.cs
index 9fa455f0b57..401e1bc5683 100644
--- a/src/libraries/Common/src/Interop/Windows/User32/Interop.SendMessage.cs
+++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.SendMessage.cs
@@ -10,8 +10,5 @@ internal static partial class Interop
{
[GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static partial IntPtr SendMessageW(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
-
- [DllImport(Libraries.User32, CharSet = CharSet.Unicode, ExactSpelling = true)]
- public static extern IntPtr SendMessageW(HandleRef hWnd, int msg, IntPtr wParam, IntPtr lParam);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.Structs.cs b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.Structs.cs
index aff7ee11a38..26c0dd93fd3 100644
--- a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.Structs.cs
+++ b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.Structs.cs
@@ -41,15 +41,35 @@ internal static partial class Interop
internal ushort CloseStatus;
}
- [StructLayout(LayoutKind.Sequential)]
+ [NativeMarshalling(typeof(Native))]
internal struct HttpHeader
{
- [MarshalAs(UnmanagedType.LPStr)]
internal string Name;
internal uint NameLength;
- [MarshalAs(UnmanagedType.LPStr)]
internal string Value;
internal uint ValueLength;
+
+ internal struct Native
+ {
+ private IntPtr Name;
+ private uint NameLength;
+ private IntPtr Value;
+ private uint ValueLength;
+
+ public Native(HttpHeader managed)
+ {
+ Name = Marshal.StringToCoTaskMemAnsi(managed.Name);
+ NameLength = managed.NameLength;
+ Value = Marshal.StringToCoTaskMemAnsi(managed.Value);
+ ValueLength = managed.ValueLength;
+ }
+
+ public void FreeNative()
+ {
+ Marshal.FreeCoTaskMem(Name);
+ Marshal.FreeCoTaskMem(Value);
+ }
+ }
}
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs
index 554d62ab160..f545dcf7ba5 100644
--- a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs
+++ b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginClientHandshake.cs
@@ -8,19 +8,16 @@ internal static partial class Interop
{
internal static partial class WebSocket
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Libraries.WebSocket)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- internal static extern int WebSocketBeginClientHandshake(
- [In] SafeHandle webSocketHandle,
- [In] IntPtr subProtocols,
- [In] uint subProtocolCount,
- [In] IntPtr extensions,
- [In] uint extensionCount,
- [In] HttpHeader[] initialHeaders,
- [In] uint initialHeaderCount,
- [Out] out IntPtr additionalHeadersPtr,
- [Out] out uint additionalHeaderCount);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.WebSocket)]
+ internal static partial int WebSocketBeginClientHandshake(
+ SafeHandle webSocketHandle,
+ IntPtr subProtocols,
+ uint subProtocolCount,
+ IntPtr extensions,
+ uint extensionCount,
+ HttpHeader[] initialHeaders,
+ uint initialHeaderCount,
+ out IntPtr additionalHeadersPtr,
+ out uint additionalHeaderCount);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs
index 68c10a704cb..5d93d76f263 100644
--- a/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs
+++ b/src/libraries/Common/src/Interop/Windows/WebSocket/Interop.WebSocketBeginServerHandshake.cs
@@ -8,18 +8,15 @@ internal static partial class Interop
{
internal static partial class WebSocket
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Libraries.WebSocket)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- internal static extern int WebSocketBeginServerHandshake(
- [In] SafeHandle webSocketHandle,
- [In] IntPtr subProtocol,
- [In] IntPtr extensions,
- [In] uint extensionCount,
- [In] HttpHeader[] requestHeaders,
- [In] uint requestHeaderCount,
- [Out] out IntPtr responseHeadersPtr,
- [Out] out uint responseHeaderCount);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.WebSocket)]
+ internal static partial int WebSocketBeginServerHandshake(
+ SafeHandle webSocketHandle,
+ IntPtr subProtocol,
+ IntPtr extensions,
+ uint extensionCount,
+ HttpHeader[] requestHeaders,
+ uint requestHeaderCount,
+ out IntPtr responseHeadersPtr,
+ out uint responseHeaderCount);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs b/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs
index ccd5084c430..165551fa6f9 100644
--- a/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs
+++ b/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp.cs
@@ -38,16 +38,41 @@ internal static partial class Interop
string acceptTypes,
uint flags);
- [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
+ [GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool WinHttpAddRequestHeaders(
+ public static partial bool WinHttpAddRequestHeaders(
SafeWinHttpHandle requestHandle,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(SimpleStringBufferMarshaller))] StringBuilder headers,
+#else
#pragma warning disable CA1838 // Uses pooled StringBuilder
[In] StringBuilder headers,
-#pragma warning restore CA1838
+#pragma warning restore CA1838 // Uses pooled StringBuilder
+#endif
uint headersLength,
uint modifiers);
+#if NET7_0_OR_GREATER
+ private unsafe struct SimpleStringBufferMarshaller
+ {
+ public SimpleStringBufferMarshaller(StringBuilder builder)
+ {
+ int length = builder.Length + 1;
+ Value = NativeMemory.Alloc(sizeof(char) * (nuint)length);
+ Span<char> buffer = new(Value, length);
+ buffer.Clear();
+ builder.CopyTo(0, buffer, length - 1);
+ }
+
+ public void* Value { get; }
+
+ public void FreeNative()
+ {
+ NativeMemory.Free(Value);
+ }
+ }
+#endif
+
[GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool WinHttpAddRequestHeaders(
@@ -187,15 +212,12 @@ internal static partial class Interop
public static partial bool WinHttpGetIEProxyConfigForCurrentUser(
out WINHTTP_CURRENT_USER_IE_PROXY_CONFIG proxyConfig);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [return: MarshalAs(UnmanagedType.Bool)]public static extern bool WinHttpGetProxyForUrl(
+ [GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]public static partial bool WinHttpGetProxyForUrl(
SafeWinHttpHandle? sessionHandle,
string url,
ref WINHTTP_AUTOPROXY_OPTIONS autoProxyOptions,
out WINHTTP_PROXY_INFO proxyInfo);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
[GeneratedDllImport(Interop.Libraries.WinHttp, CharSet = CharSet.Unicode, SetLastError = true)]
public static partial IntPtr WinHttpSetStatusCallback(
diff --git a/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp_types.cs b/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp_types.cs
index 99bcc38f0a7..47f105b6c3f 100644
--- a/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp_types.cs
+++ b/src/libraries/Common/src/Interop/Windows/WinHttp/Interop.winhttp_types.cs
@@ -244,6 +244,9 @@ internal static partial class Interop
IntPtr statusInformation,
uint statusInformationLength);
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(Native))]
+#endif
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WINHTTP_AUTOPROXY_OPTIONS
{
@@ -255,6 +258,45 @@ internal static partial class Interop
public uint Reserved2;
[MarshalAs(UnmanagedType.Bool)]
public bool AutoLoginIfChallenged;
+#if NET7_0_OR_GREATER
+ public struct Native
+ {
+ private uint Flags;
+ private uint AutoDetectFlags;
+ private IntPtr AutoConfigUrl;
+ private IntPtr Reserved1;
+ private uint Reserved2;
+ private int AutoLoginIfChallenged;
+
+ public Native(WINHTTP_AUTOPROXY_OPTIONS managed)
+ {
+ Flags = managed.Flags;
+ AutoDetectFlags = managed.AutoDetectFlags;
+ AutoConfigUrl = managed.AutoConfigUrl is not null ? Marshal.StringToCoTaskMemUni(managed.AutoConfigUrl) : IntPtr.Zero;
+ Reserved1 = managed.Reserved1;
+ Reserved2 = managed.Reserved2;
+ AutoLoginIfChallenged = managed.AutoLoginIfChallenged ? 1 : 0;
+ }
+
+ public WINHTTP_AUTOPROXY_OPTIONS ToManaged()
+ {
+ return new WINHTTP_AUTOPROXY_OPTIONS
+ {
+ Flags = Flags,
+ AutoDetectFlags = AutoDetectFlags,
+ AutoConfigUrl = AutoConfigUrl != IntPtr.Zero ? Marshal.PtrToStringUni(AutoConfigUrl) : null,
+ Reserved1 = Reserved1,
+ Reserved2 = Reserved2,
+ AutoLoginIfChallenged = AutoLoginIfChallenged != 0
+ };
+ }
+
+ public void FreeNative()
+ {
+ Marshal.FreeCoTaskMem(AutoConfigUrl);
+ }
+ }
+#endif
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs
index 2508a98bc2f..67757a5ef6f 100644
--- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs
+++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WSAIoctl.cs
@@ -9,21 +9,18 @@ internal static partial class Interop
{
internal static partial class Winsock
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
// Used with SIOGETEXTENSIONFUNCTIONPOINTER - we're assuming that will never block.
- [DllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we annotate blittable types used in interop in CoreLib (like Guid)
- internal static extern SocketError WSAIoctl(
+ [GeneratedDllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
+ internal static partial SocketError WSAIoctl(
SafeSocketHandle socketHandle,
- [In] int ioControlCode,
- [In, Out] ref Guid guid,
- [In] int guidSize,
- [Out] out IntPtr funcPtr,
- [In] int funcPtrSize,
- [Out] out int bytesTransferred,
- [In] IntPtr shouldBeNull,
- [In] IntPtr shouldBeNull2);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ int ioControlCode,
+ ref Guid guid,
+ int guidSize,
+ out IntPtr funcPtr,
+ int funcPtrSize,
+ out int bytesTransferred,
+ IntPtr shouldBeNull,
+ IntPtr shouldBeNull2);
[GeneratedDllImport(Interop.Libraries.Ws2_32, EntryPoint = "WSAIoctl", SetLastError = true)]
internal static partial SocketError WSAIoctl_Blocking(
diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WinsockBSD.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WinsockBSD.cs
index 72dc40f2aa4..28478031eb3 100644
--- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WinsockBSD.cs
+++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.WinsockBSD.cs
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System;
+using System.Diagnostics;
using System.Runtime.InteropServices;
internal static partial class Interop
@@ -57,23 +59,53 @@ internal static partial class Interop
// Argument structure for IP_ADD_MEMBERSHIP and IP_DROP_MEMBERSHIP.
[StructLayout(LayoutKind.Sequential)]
- internal struct IPMulticastRequest
+ internal unsafe struct IPMulticastRequest
{
internal int MulticastAddress; // IP multicast address of group
internal int InterfaceAddress; // local IP address of interface
- internal static readonly int Size = Marshal.SizeOf<IPMulticastRequest>();
+ internal static readonly int Size = sizeof(IPMulticastRequest);
}
// Argument structure for IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMBERSHIP.
- [StructLayout(LayoutKind.Sequential)]
+ [NativeMarshalling(typeof(Native))]
internal struct IPv6MulticastRequest
{
- [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
internal byte[] MulticastAddress; // IP address of group.
internal int InterfaceIndex; // Local interface index.
- internal static readonly int Size = Marshal.SizeOf<IPv6MulticastRequest>();
+ public unsafe struct Native
+ {
+ private const int MulticastAddressLength = 16;
+ private fixed byte _multicastAddress[MulticastAddressLength];
+ private int _interfaceIndex;
+
+ public Native(IPv6MulticastRequest managed)
+ {
+ Debug.Assert(managed.MulticastAddress.Length == MulticastAddressLength);
+ fixed (void* dest = _multicastAddress)
+ {
+ managed.MulticastAddress.CopyTo(new Span<byte>(dest, MulticastAddressLength));
+ }
+ _interfaceIndex = managed.InterfaceIndex;
+ }
+
+ public IPv6MulticastRequest ToManaged()
+ {
+ IPv6MulticastRequest managed = new()
+ {
+ MulticastAddress = new byte[MulticastAddressLength],
+ InterfaceIndex = _interfaceIndex
+ };
+ fixed (void* src = _multicastAddress)
+ {
+ new Span<byte>(src, 16).CopyTo(managed.MulticastAddress);
+ }
+ return managed;
+ }
+ }
+
+ internal static readonly unsafe int Size = sizeof(Native);
}
[StructLayout(LayoutKind.Sequential)]
diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs
index 047d46b484e..f9885d46f63 100644
--- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs
+++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.getsockopt.cs
@@ -32,15 +32,12 @@ internal static partial class Interop
out IPMulticastRequest optionValue,
ref int optionLength);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittale structs.
- internal static extern SocketError getsockopt(
- [In] SafeSocketHandle socketHandle,
- [In] SocketOptionLevel optionLevel,
- [In] SocketOptionName optionName,
- [Out] out IPv6MulticastRequest optionValue,
- [In, Out] ref int optionLength);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
+ internal static partial SocketError getsockopt(
+ SafeSocketHandle socketHandle,
+ SocketOptionLevel optionLevel,
+ SocketOptionName optionName,
+ out IPv6MulticastRequest optionValue,
+ ref int optionLength);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs
index 2aeb51a0c4d..a8eb5adc0d2 100644
--- a/src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs
+++ b/src/libraries/Common/src/Interop/Windows/WinSock/Interop.setsockopt.cs
@@ -57,15 +57,12 @@ internal static partial class Interop
ref IPMulticastRequest mreq,
int optionLength);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- [DllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittale structs.
- internal static extern SocketError setsockopt(
- [In] SafeSocketHandle socketHandle,
- [In] SocketOptionLevel optionLevel,
- [In] SocketOptionName optionName,
- [In] ref IPv6MulticastRequest mreq,
- [In] int optionLength);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Interop.Libraries.Ws2_32, SetLastError = true)]
+ internal static partial SocketError setsockopt(
+ SafeSocketHandle socketHandle,
+ SocketOptionLevel optionLevel,
+ SocketOptionName optionName,
+ in IPv6MulticastRequest mreq,
+ int optionLength);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs b/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs
index 5ca47f48b28..34fe73e8984 100644
--- a/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs
+++ b/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ber.cs
@@ -17,28 +17,49 @@ internal static partial class Interop
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial IntPtr ber_alloc(int option);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Requires some varargs support mechanism in generated interop
- [DllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
- public static extern int ber_printf(SafeBerHandle berElement, string format, __arglist);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial int ber_printf(SafeBerHandle berElement, string format, IntPtr value);
+
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial int ber_printf(SafeBerHandle berElement, string format, HGlobalMemHandle value, uint length);
+
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial int ber_printf(SafeBerHandle berElement, string format);
+
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial int ber_printf(SafeBerHandle berElement, string format, int value);
+
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_printf", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial int ber_printf(SafeBerHandle berElement, string format, uint tag);
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_flatten", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial int ber_flatten(SafeBerHandle berElement, ref IntPtr value);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.Wldap32, EntryPoint = "ber_init", CharSet = CharSet.Unicode)]
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_init", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial IntPtr ber_init(BerVal value);
+
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial int ber_scanf(SafeBerHandle berElement, string format);
+
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial int ber_scanf(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref uint bitLength);
+
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
- public static extern IntPtr ber_init(BerVal value);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ public static partial int ber_scanf(SafeBerHandle berElement, string format, ref int result);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Requires some varargs support mechanism in generated interop
- [DllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
- public static extern int ber_scanf(SafeBerHandle berElement, string format, __arglist);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_scanf", CharSet = CharSet.Unicode)]
+ [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
+ public static partial int ber_scanf(SafeBerHandle berElement, string format, ref IntPtr value);
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ber_bvfree", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
diff --git a/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ldap.cs b/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ldap.cs
index 4a6469602e9..84eb36ca776 100644
--- a/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ldap.cs
+++ b/src/libraries/Common/src/Interop/Windows/Wldap32/Interop.Ldap.cs
@@ -9,23 +9,17 @@ internal static partial class Interop
{
internal static partial class Ldap
{
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.Wldap32, EntryPoint = "ldap_bind_sW", CharSet = CharSet.Unicode)]
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_bind_sW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
- public static extern int ldap_bind_s(ConnectionHandle ldapHandle, string dn, SEC_WINNT_AUTH_IDENTITY_EX credentials, BindMethod method);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ public static partial int ldap_bind_s(ConnectionHandle ldapHandle, string dn, in SEC_WINNT_AUTH_IDENTITY_EX credentials, BindMethod method);
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_initW", CharSet = CharSet.Unicode, SetLastError = true)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial IntPtr ldap_init(string hostName, int portNumber);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.Wldap32, EntryPoint = "ldap_connect", CharSet = CharSet.Unicode, ExactSpelling = true)]
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_connect", CharSet = CharSet.Unicode, ExactSpelling = true)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
- public static extern int ldap_connect(ConnectionHandle ldapHandle, LDAP_TIMEVAL timeout);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ public static partial int ldap_connect(ConnectionHandle ldapHandle, in LDAP_TIMEVAL timeout);
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_unbind", CharSet = CharSet.Unicode, ExactSpelling = true)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
@@ -51,16 +45,13 @@ internal static partial class Interop
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial int ldap_get_option_sechandle(ConnectionHandle ldapHandle, LdapOption option, ref SecurityHandle outValue);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.Wldap32, EntryPoint = "ldap_get_optionW", CharSet = CharSet.Unicode)]
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_get_optionW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
- public static extern int ldap_get_option_secInfo(ConnectionHandle ldapHandle, LdapOption option, [In, Out] SecurityPackageContextConnectionInformation outValue);
+ public static unsafe partial int ldap_get_option_secInfo(ConnectionHandle ldapHandle, LdapOption option, void* outValue);
- [DllImport(Libraries.Wldap32, EntryPoint = "ldap_set_optionW", CharSet = CharSet.Unicode)]
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_set_optionW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
- public static extern int ldap_set_option_referral(ConnectionHandle ldapHandle, LdapOption option, ref LdapReferralCallback outValue);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ public static partial int ldap_set_option_referral(ConnectionHandle ldapHandle, LdapOption option, ref LdapReferralCallback outValue);
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_set_optionW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
@@ -86,12 +77,9 @@ internal static partial class Interop
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial int ldap_delete_ext(ConnectionHandle ldapHandle, string dn, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.Wldap32, EntryPoint = "ldap_result", CharSet = CharSet.Unicode, SetLastError = true)]
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_result", CharSet = CharSet.Unicode, SetLastError = true)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
- public static extern int ldap_result(ConnectionHandle ldapHandle, int messageId, int all, LDAP_TIMEVAL timeout, ref IntPtr Mesage);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ public static partial int ldap_result(ConnectionHandle ldapHandle, int messageId, int all, in LDAP_TIMEVAL timeout, ref IntPtr Mesage);
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_parse_resultW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
@@ -129,12 +117,9 @@ internal static partial class Interop
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial int ldap_rename(ConnectionHandle ldapHandle, string dn, string newRdn, string newParentDn, int deleteOldRdn, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.Wldap32, EntryPoint = "ldap_compare_extW", CharSet = CharSet.Unicode)]
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_compare_extW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
- public static extern int ldap_compare(ConnectionHandle ldapHandle, string dn, string attributeName, string strValue, BerVal binaryValue, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ public static partial int ldap_compare(ConnectionHandle ldapHandle, string dn, string attributeName, string strValue, BerVal binaryValue, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_add_extW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
@@ -144,12 +129,9 @@ internal static partial class Interop
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
public static partial int ldap_modify(ConnectionHandle ldapHandle, string dn, IntPtr attrs, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(Libraries.Wldap32, EntryPoint = "ldap_extended_operationW", CharSet = CharSet.Unicode)]
+ [GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_extended_operationW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
- public static extern int ldap_extended_operation(ConnectionHandle ldapHandle, string oid, BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ public static partial int ldap_extended_operation(ConnectionHandle ldapHandle, string oid, BerVal data, IntPtr servercontrol, IntPtr clientcontrol, ref int messageNumber);
[GeneratedDllImport(Libraries.Wldap32, EntryPoint = "ldap_parse_extended_resultW", CharSet = CharSet.Unicode)]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvCdecl) })]
diff --git a/src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSRegisterSessionNotification.cs b/src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSRegisterSessionNotification.cs
index 23c0a288629..11350ed5b46 100644
--- a/src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSRegisterSessionNotification.cs
+++ b/src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSRegisterSessionNotification.cs
@@ -1,13 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System;
using System.Runtime.InteropServices;
internal static partial class Interop
{
internal static partial class Wtsapi32
{
- [DllImport(Libraries.Wtsapi32, ExactSpelling = true)]
- public static extern bool WTSRegisterSessionNotification(HandleRef hWnd, int dwFlags);
+ [GeneratedDllImport(Libraries.Wtsapi32, ExactSpelling = true)]
+ public static partial bool WTSRegisterSessionNotification(IntPtr hWnd, int dwFlags);
}
}
diff --git a/src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSUnRegisterSessionNotification.cs b/src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSUnRegisterSessionNotification.cs
index a45ebf30491..6620f9c774b 100644
--- a/src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSUnRegisterSessionNotification.cs
+++ b/src/libraries/Common/src/Interop/Windows/WtsApi32/Interop.WTSUnRegisterSessionNotification.cs
@@ -1,13 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System;
using System.Runtime.InteropServices;
internal static partial class Interop
{
internal static partial class Wtsapi32
{
- [DllImport(Libraries.Wtsapi32, ExactSpelling = true)]
- public static extern bool WTSUnRegisterSessionNotification(HandleRef hWnd);
+ [GeneratedDllImport(Libraries.Wtsapi32, ExactSpelling = true)]
+ public static partial bool WTSUnRegisterSessionNotification(IntPtr hWnd);
}
}
diff --git a/src/libraries/Common/src/System/Net/DebugCriticalHandleZeroOrMinusOneIsInvalid.cs b/src/libraries/Common/src/System/Net/DebugCriticalHandleZeroOrMinusOneIsInvalid.cs
deleted file mode 100644
index ad3e9ab20f3..00000000000
--- a/src/libraries/Common/src/System/Net/DebugCriticalHandleZeroOrMinusOneIsInvalid.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using Microsoft.Win32.SafeHandles;
-
-namespace System.Net
-{
-#if DEBUG
- //
- // This is a helper class for debugging GC-ed handles that we define.
- // As a general rule normal code path should always destroy handles explicitly
- //
- internal abstract class DebugCriticalHandleZeroOrMinusOneIsInvalid : CriticalHandleZeroOrMinusOneIsInvalid
- {
- private string _trace;
-
- protected DebugCriticalHandleZeroOrMinusOneIsInvalid() : base()
- {
- _trace = "WARNING! GC-ed >>" + this.GetType().FullName + "<< (should be explicitly closed) \r\n";
- if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, "Creating SafeHandle");
- }
-
- ~DebugCriticalHandleZeroOrMinusOneIsInvalid()
- {
- if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, _trace);
- }
- }
-#endif // DEBUG
-}
diff --git a/src/libraries/Common/src/System/Net/DebugCriticalHandleMinusOneIsInvalid.cs b/src/libraries/Common/src/System/Net/DebugSafeHandleZeroOrMinusOneIsInvalid.cs
index bab71d17367..6afe348639a 100644
--- a/src/libraries/Common/src/System/Net/DebugCriticalHandleMinusOneIsInvalid.cs
+++ b/src/libraries/Common/src/System/Net/DebugSafeHandleZeroOrMinusOneIsInvalid.cs
@@ -10,17 +10,17 @@ namespace System.Net
// This is a helper class for debugging GC-ed handles that we define.
// As a general rule normal code path should always destroy handles explicitly
//
- internal abstract class DebugCriticalHandleMinusOneIsInvalid : CriticalHandleMinusOneIsInvalid
+ internal abstract class DebugSafeHandleZeroOrMinusOneIsInvalid : SafeHandleZeroOrMinusOneIsInvalid
{
private string _trace;
- protected DebugCriticalHandleMinusOneIsInvalid() : base()
+ protected DebugSafeHandleZeroOrMinusOneIsInvalid(bool ownsHandle) : base(ownsHandle)
{
_trace = "WARNING! GC-ed >>" + this.GetType().FullName + "<< (should be explicitly closed) \r\n";
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, "Creating SafeHandle");
}
- ~DebugCriticalHandleMinusOneIsInvalid()
+ ~DebugSafeHandleZeroOrMinusOneIsInvalid()
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Info(this, _trace);
}
diff --git a/src/libraries/Common/src/System/Net/Security/SecurityContextTokenHandle.cs b/src/libraries/Common/src/System/Net/Security/SecurityContextTokenHandle.cs
index 4f4c9951a72..754ef64c055 100644
--- a/src/libraries/Common/src/System/Net/Security/SecurityContextTokenHandle.cs
+++ b/src/libraries/Common/src/System/Net/Security/SecurityContextTokenHandle.cs
@@ -8,23 +8,18 @@ using System.Threading;
namespace System.Net.Security
{
#if DEBUG
- internal sealed class SecurityContextTokenHandle : DebugCriticalHandleZeroOrMinusOneIsInvalid
+ internal sealed class SecurityContextTokenHandle : DebugSafeHandleZeroOrMinusOneIsInvalid
{
#else
- internal sealed class SecurityContextTokenHandle : CriticalHandleZeroOrMinusOneIsInvalid
+ internal sealed class SecurityContextTokenHandle : SafeHandleZeroOrMinusOneIsInvalid
{
#endif
private int _disposed;
- public SecurityContextTokenHandle() : base()
+ public SecurityContextTokenHandle() : base(true)
{
}
- internal IntPtr DangerousGetHandle()
- {
- return handle;
- }
-
protected override bool ReleaseHandle()
{
if (!IsInvalid)
diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs b/src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs
index a1b99ab9223..7dfa067b001 100644
--- a/src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs
+++ b/src/libraries/Common/src/System/Runtime/InteropServices/ArrayMarshaller.cs
@@ -5,7 +5,6 @@
//
// Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md).
-// See the DllImportGenerator experiment in https://github.com/dotnet/runtimelab.
//
#if DLLIMPORTGENERATOR_INTERNALUNSAFE
using Internal.Runtime.CompilerServices;
diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs b/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs
index d27ed6f6423..c594fa3e7b7 100644
--- a/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs
+++ b/src/libraries/Common/src/System/Runtime/InteropServices/GeneratedMarshallingAttribute.cs
@@ -5,7 +5,6 @@
//
// Types in this file are used for generated p/invokes (docs/design/features/source-generator-pinvokes.md).
-// See the DllImportGenerator experiment in https://github.com/dotnet/runtimelab.
//
namespace System.Runtime.InteropServices
{
@@ -19,16 +18,6 @@ namespace System.Runtime.InteropServices
{
}
- [AttributeUsage(AttributeTargets.Struct)]
-#if DLLIMPORT_GENERATOR_TEST
- public
-#else
- internal
-#endif
- sealed class BlittableTypeAttribute : Attribute
- {
- }
-
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class)]
#if DLLIMPORT_GENERATOR_TEST
public
diff --git a/src/libraries/Common/src/System/Runtime/InteropServices/HandleRefMarshaller.cs b/src/libraries/Common/src/System/Runtime/InteropServices/HandleRefMarshaller.cs
new file mode 100644
index 00000000000..5278e31ae0e
--- /dev/null
+++ b/src/libraries/Common/src/System/Runtime/InteropServices/HandleRefMarshaller.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#nullable enable
+
+
+namespace System.Runtime.InteropServices.GeneratedMarshalling
+{
+ internal struct HandleRefMarshaller
+ {
+ private HandleRef _handle;
+
+ public HandleRefMarshaller(HandleRef handle)
+ {
+ _handle = handle;
+ }
+
+ public IntPtr Value => _handle.Handle;
+
+ public void FreeNative() => GC.KeepAlive(_handle.Wrapper);
+ }
+}
diff --git a/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj b/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
index 882394c96aa..d1308100580 100644
--- a/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
+++ b/src/libraries/Microsoft.Win32.Registry/src/Microsoft.Win32.Registry.csproj
@@ -11,6 +11,8 @@
<NoWarn Condition="'$(TargetsWindows)' != 'true'">$(NoWarn);CA1823</NoWarn> <!-- Avoid unused fields warnings in Unix build -->
</PropertyGroup>
<ItemGroup>
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.RegistryConstants.cs"
Link="Common\Interop\Windows\Advapi32\Interop.RegistryConstants.cs" />
<Compile Include="$(CoreLibSharedDir)Microsoft\Win32\SafeHandles\SafeRegistryHandle.cs"
diff --git a/src/libraries/Microsoft.Win32.Registry/tests/Helpers.cs b/src/libraries/Microsoft.Win32.Registry/tests/Helpers.cs
index 5f3ad44a105..ee86aa66a2b 100644
--- a/src/libraries/Microsoft.Win32.Registry/tests/Helpers.cs
+++ b/src/libraries/Microsoft.Win32.Registry/tests/Helpers.cs
@@ -7,10 +7,10 @@ using Microsoft.Win32.SafeHandles;
namespace Microsoft.Win32.RegistryTests
{
- internal static class Helpers
+ internal static partial class Helpers
{
- [DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueW", SetLastError = true)]
- private static extern int RegSetValue(SafeRegistryHandle handle, string value, int regType, string sb, int sizeIgnored);
+ [GeneratedDllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegSetValueW", SetLastError = true)]
+ private static partial int RegSetValue(SafeRegistryHandle handle, string value, int regType, string sb, int sizeIgnored);
internal static bool SetDefaultValue(this RegistryKey key, string value)
{
@@ -18,8 +18,8 @@ namespace Microsoft.Win32.RegistryTests
return RegSetValue(key.Handle, null, REG_SZ, value, 0) == 0;
}
- [DllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", SetLastError = true)]
- private static extern int RegQueryValueEx(SafeRegistryHandle handle, string valueName, int[] reserved, IntPtr regType, [Out] byte[] value, ref int size);
+ [GeneratedDllImport(Interop.Libraries.Advapi32, CharSet = CharSet.Unicode, EntryPoint = "RegQueryValueExW", SetLastError = true)]
+ private static partial int RegQueryValueEx(SafeRegistryHandle handle, string valueName, int[] reserved, IntPtr regType, byte[] value, ref int size);
internal static bool IsDefaultValueSet(this RegistryKey key)
{
@@ -29,7 +29,7 @@ namespace Microsoft.Win32.RegistryTests
return RegQueryValueEx(key.Handle, null, null, IntPtr.Zero, b, ref size) != ERROR_FILE_NOT_FOUND;
}
- [DllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern bool SetEnvironmentVariable(string lpName, string lpValue);
+ [GeneratedDllImport(Interop.Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial bool SetEnvironmentVariable(string lpName, string lpValue);
}
}
diff --git a/src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj b/src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj
index 97452ace1fc..6ec4e027b6e 100644
--- a/src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj
+++ b/src/libraries/Microsoft.Win32.Registry/tests/Microsoft.Win32.Registry.Tests.csproj
@@ -6,6 +6,8 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.RegSetValueEx.cs"
@@ -58,4 +60,4 @@
<Compile Include="TestData.cs" />
<Compile Include="XunitAssemblyAttributes.cs" />
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft.Win32.SystemEvents.csproj b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft.Win32.SystemEvents.csproj
index 0ccd62c3f8c..86e6af7fdab 100644
--- a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft.Win32.SystemEvents.csproj
+++ b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft.Win32.SystemEvents.csproj
@@ -120,6 +120,9 @@ Microsoft.Win32.SystemEvents</PackageDescription>
<Compile Include="Microsoft\Win32\UserPreferenceChangedEventHandler.cs" />
<Compile Include="Microsoft\Win32\UserPreferenceChangingEventArgs.cs" />
<Compile Include="Microsoft\Win32\UserPreferenceChangingEventHandler.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs"
+ Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))" />
<Compile Include="$(CoreLibSharedDir)System\Runtime\InteropServices\SuppressGCTransitionAttribute.cs"
Link="System\Runtime\InteropServices\SuppressGCTransitionAttribute.cs"
Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
diff --git a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs
index 2cee04edc07..c3f9bd89c5a 100644
--- a/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs
+++ b/src/libraries/Microsoft.Win32.SystemEvents/src/Microsoft/Win32/SystemEvents.cs
@@ -393,8 +393,9 @@ namespace Microsoft.Win32
}
EnsureSystemEvents(requireHandle: true);
- IntPtr timerId = Interop.User32.SendMessageW(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle),
+ IntPtr timerId = Interop.User32.SendMessageW(s_systemEvents!._windowHandle,
Interop.User32.WM_CREATETIMER, (IntPtr)interval, IntPtr.Zero);
+ GC.KeepAlive(s_systemEvents);
if (timerId == IntPtr.Zero)
{
@@ -409,7 +410,8 @@ namespace Microsoft.Win32
{
if (s_registeredSessionNotification)
{
- Interop.Wtsapi32.WTSUnRegisterSessionNotification(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle));
+ Interop.Wtsapi32.WTSUnRegisterSessionNotification(s_systemEvents!._windowHandle);
+ GC.KeepAlive(s_systemEvents);
}
IntPtr handle = _windowHandle;
@@ -507,7 +509,8 @@ namespace Microsoft.Win32
if (retval != IntPtr.Zero)
{
- Interop.Wtsapi32.WTSRegisterSessionNotification(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle), Interop.Wtsapi32.NOTIFY_FOR_THIS_SESSION);
+ Interop.Wtsapi32.WTSRegisterSessionNotification(s_systemEvents!._windowHandle, Interop.Wtsapi32.NOTIFY_FOR_THIS_SESSION);
+ GC.KeepAlive(s_systemEvents);
s_registeredSessionNotification = true;
Interop.Kernel32.FreeLibrary(retval);
}
@@ -752,9 +755,13 @@ namespace Microsoft.Win32
EnsureSystemEvents(requireHandle: true);
#if DEBUG
- int pid;
- int thread = Interop.User32.GetWindowThreadProcessId(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle), out pid);
- Debug.Assert(s_windowThread == null || thread != Interop.Kernel32.GetCurrentThreadId(), "Don't call MarshaledInvoke on the system events thread");
+ unsafe
+ {
+ int pid;
+ int thread = Interop.User32.GetWindowThreadProcessId(s_systemEvents!._windowHandle, &pid);
+ GC.KeepAlive(s_systemEvents);
+ Debug.Assert(s_windowThread == null || thread != Interop.Kernel32.GetCurrentThreadId(), "Don't call MarshaledInvoke on the system events thread");
+ }
#endif
if (s_threadCallbackList == null)
@@ -776,7 +783,8 @@ namespace Microsoft.Win32
s_threadCallbackList.Enqueue(method);
}
- Interop.User32.PostMessageW(new HandleRef(s_systemEvents, s_systemEvents!._windowHandle), s_threadCallbackMessage, IntPtr.Zero, IntPtr.Zero);
+ Interop.User32.PostMessageW(s_systemEvents!._windowHandle, s_threadCallbackMessage, IntPtr.Zero, IntPtr.Zero);
+ GC.KeepAlive(s_systemEvents);
}
/// <summary>
@@ -787,8 +795,9 @@ namespace Microsoft.Win32
EnsureSystemEvents(requireHandle: true);
if (s_systemEvents!._windowHandle != IntPtr.Zero)
{
- int res = (int)Interop.User32.SendMessageW(new HandleRef(s_systemEvents, s_systemEvents._windowHandle),
+ int res = (int)Interop.User32.SendMessageW(s_systemEvents._windowHandle,
Interop.User32.WM_KILLTIMER, timerId, IntPtr.Zero);
+ GC.KeepAlive(s_systemEvents);
if (res == 0)
throw new ExternalException(SR.ErrorKillTimer);
@@ -1080,18 +1089,22 @@ namespace Microsoft.Win32
if (s_windowThread != null)
{
#if DEBUG
- int pid;
- int thread = Interop.User32.GetWindowThreadProcessId(new HandleRef(s_systemEvents, s_systemEvents._windowHandle), out pid);
- Debug.Assert(thread != Interop.Kernel32.GetCurrentThreadId(), "Don't call Shutdown on the system events thread");
-#endif
+ unsafe
+ {
+ int pid;
+ int thread = Interop.User32.GetWindowThreadProcessId(s_systemEvents._windowHandle, &pid);
+ Debug.Assert(thread != Interop.Kernel32.GetCurrentThreadId(), "Don't call Shutdown on the system events thread");
+ }
+#endif
// The handle could be valid, Zero or invalid depending on the state of the thread
// that is processing the messages. We optimistically expect it to be valid to
// notify the thread to shutdown. The Zero or invalid values should be present
// only when the thread is already shutting down due to external factors.
if (s_systemEvents._windowHandle != IntPtr.Zero)
{
- Interop.User32.PostMessageW(new HandleRef(s_systemEvents, s_systemEvents._windowHandle), Interop.User32.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
+ Interop.User32.PostMessageW(s_systemEvents._windowHandle, Interop.User32.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
+ GC.KeepAlive(s_systemEvents);
}
s_windowThread.Join();
diff --git a/src/libraries/System.Console/src/System.Console.csproj b/src/libraries/System.Console/src/System.Console.csproj
index 4088dda76c0..db9d0fb39fb 100644
--- a/src/libraries/System.Console/src/System.Console.csproj
+++ b/src/libraries/System.Console/src/System.Console.csproj
@@ -21,6 +21,8 @@
<Compile Include="System\IO\CachedConsoleStream.cs" />
<Compile Include="System\IO\SyncTextReader.cs" />
<Compile Include="System\IO\Error.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\Text\ConsoleEncoding.cs"
Link="Common\System\Text\ConsoleEncoding.cs" />
</ItemGroup>
diff --git a/src/libraries/System.Console/tests/CancelKeyPress.Unix.cs b/src/libraries/System.Console/tests/CancelKeyPress.Unix.cs
index 2a8bc01fcf2..69aa37b6794 100644
--- a/src/libraries/System.Console/tests/CancelKeyPress.Unix.cs
+++ b/src/libraries/System.Console/tests/CancelKeyPress.Unix.cs
@@ -134,11 +134,11 @@ public partial class CancelKeyPressTests
}
}
- [DllImport("libc", SetLastError = true)]
- private static extern int kill(int pid, int sig);
+ [GeneratedDllImport("libc", SetLastError = true)]
+ private static partial int kill(int pid, int sig);
- [DllImport("libc", SetLastError = true)]
- private static unsafe extern int sigaction(int signum, struct_sigaction* act, struct_sigaction* oldact);
+ [GeneratedDllImport("libc", SetLastError = true)]
+ private static unsafe partial int sigaction(int signum, struct_sigaction* act, struct_sigaction* oldact);
private const int SIGINT = 2;
private const int SIGQUIT = 3;
diff --git a/src/libraries/System.Console/tests/ConsoleEncoding.Windows.cs b/src/libraries/System.Console/tests/ConsoleEncoding.Windows.cs
index 8a116f50c00..32363397a71 100644
--- a/src/libraries/System.Console/tests/ConsoleEncoding.Windows.cs
+++ b/src/libraries/System.Console/tests/ConsoleEncoding.Windows.cs
@@ -67,9 +67,9 @@ public partial class ConsoleEncoding
}).Dispose();
}
- [DllImport("kernel32.dll")]
- public static extern uint GetConsoleCP();
+ [GeneratedDllImport("kernel32.dll")]
+ public static partial uint GetConsoleCP();
- [DllImport("kernel32.dll")]
- public static extern uint GetConsoleOutputCP();
+ [GeneratedDllImport("kernel32.dll")]
+ public static partial uint GetConsoleOutputCP();
}
diff --git a/src/libraries/System.Console/tests/System.Console.Tests.csproj b/src/libraries/System.Console/tests/System.Console.Tests.csproj
index 3c83ac5db2f..4418da53021 100644
--- a/src/libraries/System.Console/tests/System.Console.Tests.csproj
+++ b/src/libraries/System.Console/tests/System.Console.Tests.csproj
@@ -24,6 +24,8 @@
<Compile Include="TermInfo.cs" />
<Compile Include="RedirectedStream.cs" />
<Compile Include="ReadKey.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonTestPath)System\IO\InterceptStreamWriter.cs"
Link="Common\System\IO\InterceptStreamWriter.cs" />
<Compile Include="$(CommonTestPath)System\ShouldNotBeInvokedException.cs"
diff --git a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
index 2005ee77156..d0818649229 100644
--- a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
+++ b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj
@@ -126,6 +126,12 @@ System.Data.Odbc.OdbcTransaction</PackageDescription>
<Compile Include="$(CommonPath)Interop\Interop.Odbc.cs"
Link="Common\Interop\Interop.Odbc.cs" />
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ <Compile Include="$(CommonPath)System\Runtime\InteropServices\HandleRefMarshaller.cs"
+ Link="Common\System\Runtime\InteropServices\HandleRefMarshaller.cs" />
+ </ItemGroup>
<ItemGroup Condition="'$(TargetsLinux)' == 'true' or '$(TargetsFreeBSD)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true'">
<Compile Include="$(CommonPath)Interop\Linux\Interop.Libraries.cs"
Link="Common\Interop\Linux\Interop.Libraries.cs" />
diff --git a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs
index a15469babaf..25f8aef9faa 100644
--- a/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs
+++ b/src/libraries/System.Data.Odbc/src/System/Data/Odbc/OdbcHandle.cs
@@ -178,19 +178,19 @@ namespace System.Data.Odbc
internal ODBC32.SQLRETURN GetDiagnosticField(out string sqlState)
{
// ODBC (MSDN) documents it expects a buffer large enough to hold 5(+L'\0') unicode characters
- StringBuilder sb = new StringBuilder(6);
+ char[] buffer = new char[6];
ODBC32.SQLRETURN retcode = Interop.Odbc.SQLGetDiagFieldW(
HandleType,
this,
(short)1,
ODBC32.SQL_DIAG_SQLSTATE,
- sb,
- checked((short)(2 * sb.Capacity)), // expects number of bytes, see \\kbinternal\kb\articles\294\1\69.HTM
+ buffer,
+ checked((short)(2 * buffer.Length)), // expects number of bytes, see \\kbinternal\kb\articles\294\1\69.HTM
out _);
ODBC.TraceODBC(3, "SQLGetDiagFieldW", retcode);
if ((retcode == ODBC32.SQLRETURN.SUCCESS) || (retcode == ODBC32.SQLRETURN.SUCCESS_WITH_INFO))
{
- sqlState = sb.ToString();
+ sqlState = new string(buffer.AsSpan().Slice(0, buffer.AsSpan().IndexOf('\0')));
}
else
{
@@ -199,21 +199,23 @@ namespace System.Data.Odbc
return retcode;
}
- internal ODBC32.SQLRETURN GetDiagnosticRecord(short record, out string sqlState, StringBuilder message, out int nativeError, out short cchActual)
+ internal ODBC32.SQLRETURN GetDiagnosticRecord(short record, out string sqlState, StringBuilder messageBuilder, out int nativeError, out short cchActual)
{
// ODBC (MSDN) documents it expects a buffer large enough to hold 4(+L'\0') unicode characters
- StringBuilder sb = new StringBuilder(5);
- ODBC32.SQLRETURN retcode = Interop.Odbc.SQLGetDiagRecW(HandleType, this, record, sb, out nativeError, message, checked((short)message.Capacity), out cchActual);
+ char[] buffer = new char[5];
+ char[] message = new char[1024];
+ ODBC32.SQLRETURN retcode = Interop.Odbc.SQLGetDiagRecW(HandleType, this, record, buffer, out nativeError, message, checked((short)message.Length), out cchActual);
ODBC.TraceODBC(3, "SQLGetDiagRecW", retcode);
if ((retcode == ODBC32.SQLRETURN.SUCCESS) || (retcode == ODBC32.SQLRETURN.SUCCESS_WITH_INFO))
{
- sqlState = sb.ToString();
+ sqlState = new string(buffer.AsSpan().Slice(0, buffer.AsSpan().IndexOf('\0')));
}
else
{
sqlState = string.Empty;
}
+ messageBuilder.Append(new string(message.AsSpan().Slice(0, message.AsSpan().IndexOf('\0'))));
return retcode;
}
}
diff --git a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
index 7e3cf5c3a8f..ff915761659 100644
--- a/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
+++ b/src/libraries/System.Data.OleDb/src/System.Data.OleDb.csproj
@@ -133,6 +133,9 @@ System.Data.OleDb.OleDbTransaction</PackageDescription>
<Compile Include="UnsafeNativeMethods.COMWrappers.cs" />
<Compile Include="OleDbComWrappers.cs" />
</ItemGroup>
+ <ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true' and !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))">
+ <Compile Include="UnsafeNativeMethods.NoCOMWrappers.cs" />
+ </ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\System.Data.OleDb.OleDbMetaData.xml"
diff --git a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPoolIdentity.cs b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPoolIdentity.cs
index 559e9d31711..bd21ab5c1bb 100644
--- a/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPoolIdentity.cs
+++ b/src/libraries/System.Data.OleDb/src/System/Data/ProviderBase/DbConnectionPoolIdentity.cs
@@ -19,7 +19,6 @@ namespace System.Data.ProviderBase
{
private const int E_NotImpersonationToken = unchecked((int)0x8007051D);
private const int Win32_CheckTokenMembership = 1;
- private const int Win32_CreateWellKnownSid = 5;
public static readonly DbConnectionPoolIdentity NoIdentity = new DbConnectionPoolIdentity(string.Empty, false, true);
@@ -41,22 +40,6 @@ namespace System.Data.ProviderBase
get { return _isRestricted; }
}
- private static byte[] CreateWellKnownSid(WellKnownSidType sidType)
- {
- // Passing an array as big as it can ever be is a small price to pay for
- // not having to P/Invoke twice (once to get the buffer, once to get the data)
-
- uint length = (uint)SecurityIdentifier.MaxBinaryLength;
-
- // NOTE - We copied this code from System.Security.Principal.Win32.CreateWellKnownSid...
-
- if (0 == UnsafeNativeMethods.CreateWellKnownSid((int)sidType, null, out byte[] resultSid, ref length))
- {
- IntegratedSecurityError(Win32_CreateWellKnownSid);
- }
- return resultSid;
- }
-
public override bool Equals(object? value)
{
bool result = ((this == NoIdentity) || (this == value));
diff --git a/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs b/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs
index 55d7aee68d1..ed5bbe6d69a 100644
--- a/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs
+++ b/src/libraries/System.Data.OleDb/src/UnsafeNativeMethods.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
@@ -831,12 +832,5 @@ namespace System.Data.Common
_name = name;
}
}
-
- [GeneratedDllImport(Interop.Libraries.Advapi32, EntryPoint = "CreateWellKnownSid", SetLastError = true, CharSet = CharSet.Unicode)]
- internal static partial int CreateWellKnownSid(
- int sidType,
- byte[]? domainSid,
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] out byte[] resultSid,
- ref uint resultSidLength);
}
}
diff --git a/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj b/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj
index 29a936cb89c..fd558833ee2 100644
--- a/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj
+++ b/src/libraries/System.Diagnostics.EventLog/src/System.Diagnostics.EventLog.csproj
@@ -110,7 +110,10 @@ System.Diagnostics.EventLog</PackageDescription>
<Compile Include="$(CommonPath)System\Diagnostics\NetFrameworkUtils.cs"
Link="Common\System\Diagnostics\NetFrameworkUtils.cs" />
</ItemGroup>
-
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" />
diff --git a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/UnsafeNativeMethods.cs b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/UnsafeNativeMethods.cs
index 1011901493d..f571f0246ae 100644
--- a/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/UnsafeNativeMethods.cs
+++ b/src/libraries/System.Diagnostics.EventLog/src/System/Diagnostics/Reader/UnsafeNativeMethods.cs
@@ -338,7 +338,10 @@ namespace Microsoft.Win32
EvtRpcLogin = 1
}
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(Marshaller))]
+#endif
+ [StructLayout(LayoutKind.Sequential)]
internal struct EvtRpcLogin
{
[MarshalAs(UnmanagedType.LPWStr)]
@@ -349,6 +352,72 @@ namespace Microsoft.Win32
public string Domain;
public CoTaskMemUnicodeSafeHandle Password;
public int Flags;
+#if NET7_0_OR_GREATER
+ public struct Marshaller
+ {
+ public struct Native
+ {
+ public IntPtr Server;
+ public IntPtr User;
+ public IntPtr Domain;
+ public IntPtr Password;
+ public int Flags;
+ }
+
+ private CoTaskMemUnicodeSafeHandle _passwordHandle;
+ private Native _value;
+ private bool _passwordHandleAddRefd;
+
+ public Marshaller(EvtRpcLogin managed)
+ {
+ _passwordHandleAddRefd = false;
+ _value.Server = Marshal.StringToCoTaskMemUni(managed.Server);
+ _value.User = Marshal.StringToCoTaskMemUni(managed.User);
+ _value.Domain = Marshal.StringToCoTaskMemUni(managed.Domain);
+ _passwordHandle = managed.Password;
+ _passwordHandle.DangerousAddRef(ref _passwordHandleAddRefd);
+ _value.Password = _passwordHandle.DangerousGetHandle();
+ _value.Flags = managed.Flags;
+ }
+
+ public Native Value
+ {
+ get => _value;
+ set
+ {
+ // SafeHandle fields cannot change the underlying handle value during marshalling.
+ if (_value.Password != value.Password)
+ {
+ throw new InvalidOperationException();
+ }
+ _value = value;
+ }
+ }
+
+ public EvtRpcLogin ToManaged()
+ {
+ return new EvtRpcLogin
+ {
+ Server = Marshal.PtrToStringUni(_value.Server),
+ User = Marshal.PtrToStringUni(_value.User),
+ Domain = Marshal.PtrToStringUni(_value.Domain),
+ Password = _passwordHandle,
+ Flags = _value.Flags
+ };
+ }
+
+ public void FreeNative()
+ {
+ Marshal.FreeCoTaskMem(_value.Server);
+ Marshal.FreeCoTaskMem(_value.User);
+ Marshal.FreeCoTaskMem(_value.Domain);
+ if (_passwordHandleAddRefd)
+ {
+ _passwordHandle.DangerousRelease();
+ }
+ }
+ }
+#endif
}
// SEEK
@@ -597,7 +666,10 @@ namespace Microsoft.Win32
out int buffUsed,
out int propCount);
- [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto)]
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(Native))]
+#endif
+ [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode)]
internal struct EvtStringVariant
{
[MarshalAs(UnmanagedType.LPWStr), FieldOffset(0)]
@@ -606,12 +678,45 @@ namespace Microsoft.Win32
public uint Count;
[FieldOffset(12)]
public uint Type;
+
+#if NET7_0_OR_GREATER
+ [StructLayout(LayoutKind.Explicit)]
+ public struct Native
+ {
+ [FieldOffset(0)]
+ private IntPtr StringVal;
+ [FieldOffset(8)]
+ private uint Count;
+ [FieldOffset(12)]
+ private uint Type;
+
+ public Native(EvtStringVariant managed)
+ {
+ StringVal = Marshal.StringToCoTaskMemUni(managed.StringVal);
+ Count = managed.Count;
+ Type = managed.Type;
+ }
+
+ public EvtStringVariant ToManaged()
+ {
+ return new EvtStringVariant
+ {
+ StringVal = Marshal.PtrToStringUni(StringVal),
+ Count = Count,
+ Type = Type
+ };
+ }
+
+ public void FreeNative()
+ {
+ Marshal.FreeCoTaskMem(StringVal);
+ }
+ }
+#endif
};
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
- [DllImport(Interop.Libraries.Wevtapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
- internal static extern bool EvtFormatMessage(
+ [GeneratedDllImport(Interop.Libraries.Wevtapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
+ internal static partial bool EvtFormatMessage(
EventLogHandle publisherMetadataHandle,
EventLogHandle eventHandle,
uint messageId,
@@ -621,7 +726,6 @@ namespace Microsoft.Win32
int bufferSize,
[Out] char[]? buffer,
out int bufferUsed);
-#pragma warning restore DLLIMPORTGENANALYZER015
[GeneratedDllImport(Interop.Libraries.Wevtapi, EntryPoint = "EvtFormatMessage", SetLastError = true)]
internal static partial bool EvtFormatMessageBuffer(
@@ -636,15 +740,12 @@ namespace Microsoft.Win32
out int bufferUsed);
// SESSION
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable types.
- [DllImport(Interop.Libraries.Wevtapi, SetLastError = true)]
- internal static extern EventLogHandle EvtOpenSession(
+ [GeneratedDllImport(Interop.Libraries.Wevtapi, SetLastError = true)]
+ internal static partial EventLogHandle EvtOpenSession(
EvtLoginClass loginClass,
ref EvtRpcLogin login,
int timeout,
int flags);
-#pragma warning restore DLLIMPORTGENANALYZER015
// BOOKMARK
[GeneratedDllImport(Interop.Libraries.Wevtapi, EntryPoint = "EvtCreateBookmark", SetLastError = true)]
diff --git a/src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj b/src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj
index a03f4dea580..9898d2491ca 100644
--- a/src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj
+++ b/src/libraries/System.Diagnostics.EventLog/tests/System.Diagnostics.EventLog.Tests.csproj
@@ -26,6 +26,8 @@
</ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Compile Include="EventLogMessagesTests.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.CloseHandle.cs"
Link="Common\Interop\Windows\Kernel32\Interop.CloseHandle.cs" />
<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeLibraryHandle.cs"
@@ -43,4 +45,4 @@
<ProjectReference Include="..\src\System.Diagnostics.EventLog.csproj" />
<ProjectReference Include="..\src\Messages\System.Diagnostics.EventLog.Messages.csproj" />
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj b/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj
index 91838430452..fae2dee2392 100644
--- a/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj
+++ b/src/libraries/System.Diagnostics.FileVersionInfo/src/System.Diagnostics.FileVersionInfo.csproj
@@ -6,10 +6,12 @@
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
- <GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsAnyOS)' == 'true'">SR.DiagnosticsFileVersionInfo_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
+ <GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsAnyOS)' == 'true'">SR.DiagnosticsFileVersionInfo_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
<Compile Include="System\Diagnostics\FileVersionInfo.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="System\Diagnostics\FileVersionInfo.Windows.cs" />
diff --git a/src/libraries/System.Diagnostics.PerformanceCounter/src/System.Diagnostics.PerformanceCounter.csproj b/src/libraries/System.Diagnostics.PerformanceCounter/src/System.Diagnostics.PerformanceCounter.csproj
index 5ebf58e40c5..f90314643f4 100644
--- a/src/libraries/System.Diagnostics.PerformanceCounter/src/System.Diagnostics.PerformanceCounter.csproj
+++ b/src/libraries/System.Diagnostics.PerformanceCounter/src/System.Diagnostics.PerformanceCounter.csproj
@@ -128,6 +128,10 @@ System.Diagnostics.PerformanceCounter</PackageDescription>
<Compile Include="$(CommonPath)System\Diagnostics\NetFrameworkUtils.cs"
Link="Common\System\Diagnostics\NetFrameworkUtils.cs" />
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Configuration.ConfigurationManager\src\System.Configuration.ConfigurationManager.csproj" />
<Reference Include="Microsoft.Win32.Primitives" />
diff --git a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
index 2521808c43c..8a41187ffa5 100644
--- a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
+++ b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
@@ -33,6 +33,8 @@
<Compile Include="System\Diagnostics\ThreadWaitReason.cs" />
<Compile Include="System\Diagnostics\MonitoringDescriptionAttribute.cs" />
<Compile Include="System\Collections\Specialized\StringDictionaryWrapper.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\Runtime\Serialization\SerializationGuard.cs"
Link="Common\System\Runtime\Serialization\SerializationGuard.cs" />
<Compile Include="$(CoreLibSharedDir)System\PasteArguments.cs"
diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj b/src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj
index c747c1d187c..b518e6ecd1f 100644
--- a/src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj
+++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System.DirectoryServices.AccountManagement.csproj
@@ -188,6 +188,10 @@
<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeTokenHandle.cs"
Link="Common\Microsoft\Win32\SafeHandles\SafeTokenHandle.cs" />
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Configuration.ConfigurationManager\src\System.Configuration.ConfigurationManager.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.DirectoryServices\src\System.DirectoryServices.csproj" />
diff --git a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs
index 23ef181e99b..64fcab520bf 100644
--- a/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs
+++ b/src/libraries/System.DirectoryServices.AccountManagement/src/System/DirectoryServices/AccountManagement/interopt.cs
@@ -25,7 +25,9 @@ namespace System.DirectoryServices.AccountManagement
{
try
{
- return Interop.Activeds.ADsOpenObject(path, userName, password, flags, ref iid, out ppObject);
+ int hr = Interop.Activeds.ADsOpenObject(path, userName, password, flags, ref iid, out IntPtr ppObjPtr);
+ ppObject = Marshal.GetObjectForIUnknown(ppObjPtr);
+ return hr;
}
catch (EntryPointNotFoundException)
{
diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj b/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj
index 0a92754626c..366ab1b3185 100644
--- a/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj
+++ b/src/libraries/System.DirectoryServices.Protocols/src/System.DirectoryServices.Protocols.csproj
@@ -41,9 +41,16 @@
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapPartialResultsProcessor.cs" />
<Compile Include="System\DirectoryServices\Protocols\ldap\LdapSessionOptions.cs" />
<Compile Include="System\DirectoryServices\Protocols\Interop\SafeHandles.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
+ <Link>Common\DisableRuntimeMarshalling.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)Interop\Interop.Ldap.cs">
<Link>Common\Interop\Interop.Ldap.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)Interop\Windows\Interop.BOOL.cs">
+ <Link>Common\Interop\Windows\Interop.BOOL.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="System\DirectoryServices\Protocols\common\BerConverter.Windows.cs" />
@@ -102,6 +109,7 @@
<Reference Include="System.Net.Primitives" />
<Reference Include="System.Resources.ResourceManager" />
<Reference Include="System.Runtime" />
+ <Reference Include="System.Runtime.CompilerServices.Unsafe" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Runtime.InteropServices" />
<Reference Include="System.Security.Cryptography.X509Certificates" />
diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs
index 586bcd7d39a..8d0d6bf93a8 100644
--- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/BerPal.Windows.cs
@@ -15,25 +15,25 @@ namespace System.DirectoryServices.Protocols
internal static int FlattenBerElement(SafeBerHandle berElement, ref IntPtr flattenptr) => Interop.Ldap.ber_flatten(berElement, ref flattenptr);
- internal static int PrintBerArray(SafeBerHandle berElement, string format, IntPtr value, nuint _) => Interop.Ldap.ber_printf(berElement, format, __arglist(value));
+ internal static int PrintBerArray(SafeBerHandle berElement, string format, IntPtr value, nuint _) => Interop.Ldap.ber_printf(berElement, format, value);
- internal static int PrintByteArray(SafeBerHandle berElement, string format, HGlobalMemHandle value, uint length, nuint _) => Interop.Ldap.ber_printf(berElement, format, __arglist(value, length));
+ internal static int PrintByteArray(SafeBerHandle berElement, string format, HGlobalMemHandle value, uint length, nuint _) => Interop.Ldap.ber_printf(berElement, format, value, length);
- internal static int PrintEmptyArgument(SafeBerHandle berElement, string format, nuint _) => Interop.Ldap.ber_printf(berElement, format, __arglist());
+ internal static int PrintEmptyArgument(SafeBerHandle berElement, string format, nuint _) => Interop.Ldap.ber_printf(berElement, format);
- internal static int PrintInt(SafeBerHandle berElement, string format, int value, nuint _) => Interop.Ldap.ber_printf(berElement, format, __arglist(value));
+ internal static int PrintInt(SafeBerHandle berElement, string format, int value, nuint _) => Interop.Ldap.ber_printf(berElement, format, value);
- internal static int PrintTag(SafeBerHandle berElement, string format, nuint tag) => Interop.Ldap.ber_printf(berElement, format, __arglist((uint)tag));
+ internal static int PrintTag(SafeBerHandle berElement, string format, nuint tag) => Interop.Ldap.ber_printf(berElement, format, (uint)tag);
- internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf(berElement, format, __arglist());
+ internal static int ScanNext(SafeBerHandle berElement, string format) => Interop.Ldap.ber_scanf(berElement, format);
- internal static int ScanNextBitString(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref uint bitLength) => Interop.Ldap.ber_scanf(berElement, format, __arglist(ref ptrResult, ref bitLength));
+ internal static int ScanNextBitString(SafeBerHandle berElement, string format, ref IntPtr ptrResult, ref uint bitLength) => Interop.Ldap.ber_scanf(berElement, format, ref ptrResult, ref bitLength);
- internal static int ScanNextInt(SafeBerHandle berElement, string format, ref int result) => Interop.Ldap.ber_scanf(berElement, format, __arglist(ref result));
+ internal static int ScanNextInt(SafeBerHandle berElement, string format, ref int result) => Interop.Ldap.ber_scanf(berElement, format, ref result);
- internal static int ScanNextPtr(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf(berElement, format, __arglist(ref value));
+ internal static int ScanNextPtr(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf(berElement, format, ref value);
- internal static int ScanNextMultiByteArray(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf(berElement, format, __arglist(ref value));
+ internal static int ScanNextMultiByteArray(SafeBerHandle berElement, string format, ref IntPtr value) => Interop.Ldap.ber_scanf(berElement, format, ref value);
internal static bool IsBerDecodeError(int errorCode) => errorCode != 0;
}
diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs
index 329237f10b3..cb4423b53d6 100644
--- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Linux.cs
@@ -50,7 +50,13 @@ namespace System.DirectoryServices.Protocols
internal static int GetSecurityHandleOption(ConnectionHandle ldapHandle, LdapOption option, ref SecurityHandle outValue) => Interop.Ldap.ldap_get_option_sechandle(ldapHandle, option, ref outValue);
// This option is not supported on Linux, so it would most likely throw.
- internal static int GetSecInfoOption(ConnectionHandle ldapHandle, LdapOption option, SecurityPackageContextConnectionInformation outValue) => Interop.Ldap.ldap_get_option_secInfo(ldapHandle, option, outValue);
+ internal static unsafe int GetSecInfoOption(ConnectionHandle ldapHandle, LdapOption option, SecurityPackageContextConnectionInformation outValue)
+ {
+ fixed (void* outValuePtr = outValue)
+ {
+ return Interop.Ldap.ldap_get_option_secInfo(ldapHandle, option, outValuePtr);
+ }
+ }
internal static IntPtr GetValuesFromAttribute(ConnectionHandle ldapHandle, IntPtr result, string name) => Interop.Ldap.ldap_get_values_len(ldapHandle, result, name);
diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Windows.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Windows.cs
index ddceb9b39f9..f914f707883 100644
--- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Windows.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/Interop/LdapPal.Windows.cs
@@ -42,7 +42,13 @@ namespace System.DirectoryServices.Protocols
internal static int GetSecurityHandleOption(ConnectionHandle ldapHandle, LdapOption option, ref SecurityHandle outValue) => Interop.Ldap.ldap_get_option_sechandle(ldapHandle, option, ref outValue);
- internal static int GetSecInfoOption(ConnectionHandle ldapHandle, LdapOption option, SecurityPackageContextConnectionInformation outValue) => Interop.Ldap.ldap_get_option_secInfo(ldapHandle, option, outValue);
+ internal static unsafe int GetSecInfoOption(ConnectionHandle ldapHandle, LdapOption option, SecurityPackageContextConnectionInformation outValue)
+ {
+ fixed (void* outValuePtr = outValue)
+ {
+ return Interop.Ldap.ldap_get_option_secInfo(ldapHandle, option, outValuePtr);
+ }
+ }
internal static IntPtr GetValuesFromAttribute(ConnectionHandle ldapHandle, IntPtr result, string name) => Interop.Ldap.ldap_get_values_len(ldapHandle, result, name);
diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.Windows.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.Windows.cs
index f47dc518a13..829a3abdc25 100644
--- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.Windows.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapConnection.Windows.cs
@@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Net;
+using System.Runtime.CompilerServices;
namespace System.DirectoryServices.Protocols
{
@@ -37,6 +38,6 @@ namespace System.DirectoryServices.Protocols
}
private int InternalBind(NetworkCredential tempCredential, SEC_WINNT_AUTH_IDENTITY_EX cred, BindMethod method)
- => tempCredential == null && AuthType == AuthType.External ? Interop.Ldap.ldap_bind_s(_ldapHandle, null, null, method) : Interop.Ldap.ldap_bind_s(_ldapHandle, null, cred, method);
+ => tempCredential == null && AuthType == AuthType.External ? Interop.Ldap.ldap_bind_s(_ldapHandle, null, Unsafe.NullRef<SEC_WINNT_AUTH_IDENTITY_EX>(), method) : Interop.Ldap.ldap_bind_s(_ldapHandle, null, cred, method);
}
}
diff --git a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs
index fb2a71e51ed..c0e9780ad47 100644
--- a/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs
+++ b/src/libraries/System.DirectoryServices.Protocols/src/System/DirectoryServices/Protocols/ldap/LdapSessionOptions.cs
@@ -21,16 +21,16 @@ namespace System.DirectoryServices.Protocols
public delegate bool VerifyServerCertificateCallback(LdapConnection connection, X509Certificate certificate);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate int QUERYFORCONNECTIONInternal(IntPtr Connection, IntPtr ReferralFromConnection, IntPtr NewDNPtr, string HostName, int PortNumber, SEC_WINNT_AUTH_IDENTITY_EX SecAuthIdentity, Luid CurrentUserToken, ref IntPtr ConnectionToUse);
+ internal unsafe delegate int QUERYFORCONNECTIONInternal(IntPtr Connection, IntPtr ReferralFromConnection, IntPtr NewDNPtr, IntPtr HostName, int PortNumber, SEC_WINNT_AUTH_IDENTITY_EX.Native* SecAuthIdentity, Luid* CurrentUserToken, IntPtr* ConnectionToUse);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate bool NOTIFYOFNEWCONNECTIONInternal(IntPtr Connection, IntPtr ReferralFromConnection, IntPtr NewDNPtr, string HostName, IntPtr NewConnection, int PortNumber, SEC_WINNT_AUTH_IDENTITY_EX SecAuthIdentity, Luid CurrentUser, int ErrorCodeFromBind);
+ internal unsafe delegate Interop.BOOL NOTIFYOFNEWCONNECTIONInternal(IntPtr Connection, IntPtr ReferralFromConnection, IntPtr NewDNPtr, IntPtr HostName, IntPtr NewConnection, int PortNumber, SEC_WINNT_AUTH_IDENTITY_EX.Native* SecAuthIdentity, Luid* CurrentUser, int ErrorCodeFromBind);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int DEREFERENCECONNECTIONInternal(IntPtr Connection, IntPtr ConnectionToDereference);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- internal delegate bool VERIFYSERVERCERT(IntPtr Connection, IntPtr pServerCert);
+ internal delegate Interop.BOOL VERIFYSERVERCERT(IntPtr Connection, IntPtr pServerCert);
[Flags]
public enum LocatorFlags : long
@@ -69,7 +69,8 @@ namespace System.DirectoryServices.Protocols
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class SecurityPackageContextConnectionInformation
{
- private readonly SecurityProtocol _securityProtocol;
+ // Not marked as readonly to enable passing to Unsafe.As in GetPinnableReference.
+ private SecurityProtocol _securityProtocol;
private readonly CipherAlgorithmType _identifier;
private readonly int _strength;
private readonly HashAlgorithmType _hashAlgorithm;
@@ -94,6 +95,8 @@ namespace System.DirectoryServices.Protocols
public int KeyExchangeAlgorithm => _keyExchangeAlgorithm;
public int ExchangeStrength => _exchangeStrength;
+
+ internal ref readonly byte GetPinnableReference() => ref Unsafe.As<SecurityProtocol, byte>(ref _securityProtocol);
}
public sealed class ReferralCallback
@@ -127,7 +130,7 @@ namespace System.DirectoryServices.Protocols
private readonly DEREFERENCECONNECTIONInternal _dereferenceDelegate;
private readonly VERIFYSERVERCERT _serverCertificateRoutine;
- internal LdapSessionOptions(LdapConnection connection)
+ internal unsafe LdapSessionOptions(LdapConnection connection)
{
_connection = connection;
_queryDelegate = new QUERYFORCONNECTIONInternal(ProcessQueryConnection);
@@ -858,9 +861,9 @@ namespace System.DirectoryServices.Protocols
ErrorChecking.CheckAndSetLdapError(error);
}
- private int ProcessQueryConnection(IntPtr PrimaryConnection, IntPtr ReferralFromConnection, IntPtr NewDNPtr, string HostName, int PortNumber, SEC_WINNT_AUTH_IDENTITY_EX SecAuthIdentity, Luid CurrentUserToken, ref IntPtr ConnectionToUse)
+ private unsafe int ProcessQueryConnection(IntPtr PrimaryConnection, IntPtr ReferralFromConnection, IntPtr NewDNPtr, IntPtr HostNamePtr, int PortNumber, SEC_WINNT_AUTH_IDENTITY_EX.Native* SecAuthIdentity, Luid* CurrentUserToken, IntPtr* ConnectionToUse)
{
- ConnectionToUse = IntPtr.Zero;
+ *ConnectionToUse = IntPtr.Zero;
string NewDN = null;
// The user must have registered callback function.
@@ -875,7 +878,7 @@ namespace System.DirectoryServices.Protocols
}
var target = new StringBuilder();
- target.Append(HostName);
+ target.Append(Marshal.PtrToStringUni(HostNamePtr));
target.Append(':');
target.Append(PortNumber);
var identifier = new LdapDirectoryIdentifier(target.ToString());
@@ -912,7 +915,7 @@ namespace System.DirectoryServices.Protocols
}
}
- long tokenValue = (uint)CurrentUserToken.LowPart + (((long)CurrentUserToken.HighPart) << 32);
+ long tokenValue = (uint)CurrentUserToken->LowPart + (((long)CurrentUserToken->HighPart) << 32);
LdapConnection con = _callbackRoutine.QueryForConnection(_connection, tempReferralConnection, NewDN, identifier, cred, tokenValue);
if (con != null && con._ldapHandle != null && !con._ldapHandle.IsInvalid)
@@ -920,7 +923,7 @@ namespace System.DirectoryServices.Protocols
bool success = AddLdapHandleRef(con);
if (success)
{
- ConnectionToUse = con._ldapHandle.DangerousGetHandle();
+ *ConnectionToUse = con._ldapHandle.DangerousGetHandle();
}
}
@@ -931,7 +934,7 @@ namespace System.DirectoryServices.Protocols
return 1;
}
- private bool ProcessNotifyConnection(IntPtr primaryConnection, IntPtr referralFromConnection, IntPtr newDNPtr, string hostName, IntPtr newConnection, int portNumber, SEC_WINNT_AUTH_IDENTITY_EX SecAuthIdentity, Luid currentUser, int errorCodeFromBind)
+ private unsafe Interop.BOOL ProcessNotifyConnection(IntPtr primaryConnection, IntPtr referralFromConnection, IntPtr newDNPtr, IntPtr hostNamePtr, IntPtr newConnection, int portNumber, SEC_WINNT_AUTH_IDENTITY_EX.Native* SecAuthIdentity, Luid* currentUser, int errorCodeFromBind)
{
if (newConnection != IntPtr.Zero && _callbackRoutine.NotifyNewConnection != null)
{
@@ -942,7 +945,7 @@ namespace System.DirectoryServices.Protocols
}
var target = new StringBuilder();
- target.Append(hostName);
+ target.Append(Marshal.PtrToStringUni(hostNamePtr));
target.Append(':');
target.Append(portNumber);
var identifier = new LdapDirectoryIdentifier(target.ToString());
@@ -1005,7 +1008,7 @@ namespace System.DirectoryServices.Protocols
}
}
- long tokenValue = (uint)currentUser.LowPart + (((long)currentUser.HighPart) << 32);
+ long tokenValue = (uint)currentUser->LowPart + (((long)currentUser->HighPart) << 32);
bool value = _callbackRoutine.NotifyNewConnection(_connection, tempReferralConnection, newDN, identifier, tempNewConnection, cred, tokenValue, errorCodeFromBind);
if (value)
@@ -1017,10 +1020,10 @@ namespace System.DirectoryServices.Protocols
}
}
- return value;
+ return value ? Interop.BOOL.TRUE : Interop.BOOL.FALSE;
}
- return false;
+ return Interop.BOOL.FALSE;
}
private int ProcessDereferenceConnection(IntPtr PrimaryConnection, IntPtr ConnectionToDereference)
@@ -1056,21 +1059,21 @@ namespace System.DirectoryServices.Protocols
return 1;
}
- private NetworkCredential ProcessSecAuthIdentity(SEC_WINNT_AUTH_IDENTITY_EX SecAuthIdentit)
+ private unsafe NetworkCredential ProcessSecAuthIdentity(SEC_WINNT_AUTH_IDENTITY_EX.Native* SecAuthIdentit)
{
if (SecAuthIdentit == null)
{
return new NetworkCredential();
}
- string user = SecAuthIdentit.user;
- string domain = SecAuthIdentit.domain;
- string password = SecAuthIdentit.password;
+ string user = Marshal.PtrToStringUni(SecAuthIdentit->user);
+ string domain = Marshal.PtrToStringUni(SecAuthIdentit->domain);
+ string password = Marshal.PtrToStringUni(SecAuthIdentit->password);
return new NetworkCredential(user, password, domain);
}
- private bool ProcessServerCertificate(IntPtr connection, IntPtr serverCert)
+ private Interop.BOOL ProcessServerCertificate(IntPtr connection, IntPtr serverCert)
{
// If callback is not specified by user, it means the server certificate is accepted.
bool value = true;
@@ -1092,7 +1095,7 @@ namespace System.DirectoryServices.Protocols
value = _serverCertificateDelegate(_connection, certificate);
}
- return value;
+ return value ? Interop.BOOL.TRUE : Interop.BOOL.FALSE;
}
private static bool AddLdapHandleRef(LdapConnection ldapConnection)
diff --git a/src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs b/src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs
index 7b4922c71fe..53cf23eb0d8 100644
--- a/src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs
+++ b/src/libraries/System.DirectoryServices/src/Interop/UnsafeNativeMethods.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
@@ -30,9 +31,22 @@ namespace System.DirectoryServices.Interop
{
public static int ADsOpenObject(string path, string? userName, string? password, int flags, [In, Out] ref Guid iid, [Out, MarshalAs(UnmanagedType.Interface)] out object ppObject)
{
+ IntPtr ppObjectNative = IntPtr.Zero;
try
{
- return global::Interop.Activeds.ADsOpenObject(path, userName, password, flags, ref iid, out ppObject);
+ int hr = global::Interop.Activeds.ADsOpenObject(path, userName, password, flags, ref iid, out ppObjectNative);
+ try
+ {
+ ppObject = ppObjectNative != IntPtr.Zero ? Marshal.GetObjectForIUnknown(ppObjectNative) : null!;
+ return hr;
+ }
+ finally
+ {
+ if (ppObjectNative != IntPtr.Zero)
+ {
+ Marshal.Release(ppObjectNative);
+ }
+ }
}
catch (EntryPointNotFoundException)
{
diff --git a/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj b/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj
index 71c695235a6..9f4bbc7733b 100644
--- a/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj
+++ b/src/libraries/System.DirectoryServices/src/System.DirectoryServices.csproj
@@ -153,6 +153,9 @@ System.DirectoryServices.ActiveDirectory.DomainController</PackageDescription>
<Compile Include="Interop\NativeMethods.cs" />
<Compile Include="Interop\SafeNativeMethods.cs" />
<Compile Include="Interop\UnsafeNativeMethods.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs"
+ Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.BOOL.cs"
Link="Common\Interop\Windows\Interop.BOOL.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.BOOLEAN.cs"
diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs
index 7ea26b42835..c438ef92640 100644
--- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs
+++ b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs
@@ -3,6 +3,9 @@
using System;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
internal static partial class Interop
{
@@ -12,35 +15,83 @@ internal static partial class Interop
internal const int CHECKJPEGFORMAT = 4119;
internal const int CHECKPNGFORMAT = 4120;
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true)]
- internal static extern IntPtr CreateCompatibleBitmap(HandleRef hDC, int width, int height);
+ [GeneratedDllImport(Libraries.Gdi32, ExactSpelling = true, SetLastError = true)]
+ internal static partial IntPtr CreateCompatibleBitmap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC, int width, int height);
- [DllImport(Libraries.Gdi32)]
- internal static extern int GetDIBits(HandleRef hdc, HandleRef hbm, int arg1, int arg2, IntPtr arg3, ref BITMAPINFO_FLAT bmi, int arg5);
+ [GeneratedDllImport(Libraries.Gdi32)]
+ internal static partial int GetDIBits(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hdc,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hbm, int arg1, int arg2, IntPtr arg3, ref BITMAPINFO_FLAT bmi, int arg5);
- [DllImport(Libraries.Gdi32)]
- internal static extern uint GetPaletteEntries(HandleRef hpal, int iStartIndex, int nEntries, byte[] lppe);
+ [GeneratedDllImport(Libraries.Gdi32)]
+ internal static partial uint GetPaletteEntries(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hpal, int iStartIndex, int nEntries, byte[] lppe);
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true)]
- internal static extern IntPtr CreateDIBSection(HandleRef hdc, ref BITMAPINFO_FLAT bmi, int iUsage, ref IntPtr ppvBits, IntPtr hSection, int dwOffset);
+ [GeneratedDllImport(Libraries.Gdi32, ExactSpelling = true, SetLastError = true)]
+ internal static partial IntPtr CreateDIBSection(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hdc, ref BITMAPINFO_FLAT bmi, int iUsage, ref IntPtr ppvBits, IntPtr hSection, int dwOffset);
- [DllImport(Libraries.Gdi32, SetLastError = true, CharSet = CharSet.Auto)]
- internal static extern int StartDoc(HandleRef hDC, DOCINFO lpDocInfo);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, SetLastError = true)]
+ internal static partial int StartDoc(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC, DOCINFO lpDocInfo);
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern int StartPage(HandleRef hDC);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial int StartPage(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC);
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern int EndPage(HandleRef hDC);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial int EndPage(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC);
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern int AbortDoc(HandleRef hDC);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial int AbortDoc(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC);
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern int EndDoc(HandleRef hDC);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial int EndDoc(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC);
- [DllImport(Libraries.Gdi32, SetLastError = true, CharSet = CharSet.Auto)]
- internal static extern IntPtr /*HDC*/ ResetDC(HandleRef hDC, HandleRef /*DEVMODE*/ lpDevMode);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, SetLastError = true)]
+ internal static partial IntPtr /*HDC*/ ResetDC(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef /*DEVMODE*/ lpDevMode);
[GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, SetLastError = true)]
internal static partial int AddFontResourceEx(string lpszFilename, int fl, IntPtr pdv);
@@ -50,22 +101,46 @@ internal static partial class Interop
return AddFontResourceEx(fileName, /*FR_PRIVATE*/ 0x10, IntPtr.Zero);
}
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern int ExtEscape(HandleRef hDC, int nEscape, int cbInput, ref int inData, int cbOutput, [Out] out int outData);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial int ExtEscape(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC, int nEscape, int cbInput, ref int inData, int cbOutput, out int outData);
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern int ExtEscape(HandleRef hDC, int nEscape, int cbInput, byte[] inData, int cbOutput, [Out] out int outData);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial int ExtEscape(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC, int nEscape, int cbInput, byte[] inData, int cbOutput, out int outData);
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern int IntersectClipRect(HandleRef hDC, int x1, int y1, int x2, int y2);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial int IntersectClipRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC, int x1, int y1, int x2, int y2);
- [DllImport(Libraries.Gdi32, SetLastError = true)]
- internal static extern int GetObject(HandleRef hObject, int nSize, ref BITMAP bm);
+ [GeneratedDllImport(Libraries.Gdi32, SetLastError = true)]
+ internal static partial int GetObject(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hObject, int nSize, ref BITMAP bm);
- [DllImport(Libraries.Gdi32, SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern int GetObject(HandleRef hObject, int nSize, ref Interop.User32.LOGFONT lf);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial int GetObject(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hObject, int nSize, ref Interop.User32.LOGFONT lf);
- internal static unsafe int GetObject(HandleRef hObject, ref Interop.User32.LOGFONT lp)
+ internal static unsafe int GetObject(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hObject, ref Interop.User32.LOGFONT lp)
=> GetObject(hObject, sizeof(Interop.User32.LOGFONT), ref lp);
[StructLayout(LayoutKind.Sequential)]
@@ -100,6 +175,9 @@ internal static partial class Interop
public fixed byte bmiColors[BITMAPINFO_MAX_COLORSIZE * 4]; // RGBQUAD structs... Blue-Green-Red-Reserved, repeat...
}
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(Native))]
+#endif
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal sealed class DOCINFO
{
@@ -108,6 +186,33 @@ internal static partial class Interop
internal string? lpszOutput;
internal string? lpszDatatype;
internal int fwType;
+
+#if NET7_0_OR_GREATER
+ internal struct Native
+ {
+ internal int cbSize;
+ internal IntPtr lpszDocName;
+ internal IntPtr lpszOutput;
+ internal IntPtr lpszDatatype;
+ internal int fwType;
+
+ public Native(DOCINFO docInfo)
+ {
+ cbSize = docInfo.cbSize;
+ lpszDocName = Marshal.StringToCoTaskMemAuto(docInfo.lpszDocName);
+ lpszOutput = Marshal.StringToCoTaskMemAuto(docInfo.lpszOutput);
+ lpszDatatype = Marshal.StringToCoTaskMemAuto(docInfo.lpszDatatype);
+ fwType = docInfo.fwType;
+ }
+
+ public void FreeNative()
+ {
+ Marshal.FreeCoTaskMem(lpszDocName);
+ Marshal.FreeCoTaskMem(lpszOutput);
+ Marshal.FreeCoTaskMem(lpszDatatype);
+ }
+ }
+#endif
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
@@ -192,4 +297,4 @@ internal static partial class Interop
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs
index 57d2b917178..5332459af64 100644
--- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs
+++ b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs
@@ -3,6 +3,9 @@
using System;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
internal static partial class Interop
{
@@ -19,7 +22,15 @@ internal static partial class Interop
return IntGlobalAlloc(uFlags, new UIntPtr(dwBytes));
}
- [DllImport(Libraries.Gdi32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern IntPtr SelectObject(HandleRef hdc, HandleRef obj);
+ [GeneratedDllImport(Libraries.Gdi32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial IntPtr SelectObject(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hdc,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef obj);
}
-} \ No newline at end of file
+}
diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Shell32.cs b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Shell32.cs
index 8122f6234cc..a15f358ccc2 100644
--- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Shell32.cs
+++ b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Shell32.cs
@@ -3,12 +3,19 @@
using System;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
internal static partial class Interop
{
internal static partial class Shell32
{
- [DllImport(Libraries.Shell32, CharSet = CharSet.Unicode)]
- internal static extern unsafe IntPtr ExtractAssociatedIcon(HandleRef hInst, char* iconPath, ref int index);
+ [GeneratedDllImport(Libraries.Shell32, CharSet = CharSet.Unicode)]
+ internal static unsafe partial IntPtr ExtractAssociatedIcon(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hInst, char* iconPath, ref int index);
}
-} \ No newline at end of file
+}
diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.User32.cs b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.User32.cs
index dc485e0bab5..95a82c34dda 100644
--- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.User32.cs
+++ b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.User32.cs
@@ -3,28 +3,59 @@
using System;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
internal static partial class Interop
{
internal static partial class User32
{
- [DllImport(Libraries.User32, SetLastError = true, CharSet = CharSet.Unicode)]
- internal static extern IntPtr LoadIcon(HandleRef hInst, IntPtr iconId);
+ [GeneratedDllImport(Libraries.User32, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial IntPtr LoadIcon(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hInst, IntPtr iconId);
- [DllImport(Libraries.User32, SetLastError = true, ExactSpelling = true)]
- internal static extern bool DestroyIcon(HandleRef hIcon);
+ [GeneratedDllImport(Libraries.User32, ExactSpelling = true, SetLastError = true)]
+ internal static partial bool DestroyIcon(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hIcon);
- [DllImport(Libraries.User32, SetLastError = true, ExactSpelling = true)]
- internal static extern IntPtr CopyImage(HandleRef hImage, int uType, int cxDesired, int cyDesired, int fuFlags);
+ [GeneratedDllImport(Libraries.User32, ExactSpelling = true, SetLastError = true)]
+ internal static partial IntPtr CopyImage(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hImage, int uType, int cxDesired, int cyDesired, int fuFlags);
- [DllImport(Libraries.User32, SetLastError = true, ExactSpelling = true)]
- internal static extern bool GetIconInfo(HandleRef hIcon, ref ICONINFO info);
+ [GeneratedDllImport(Libraries.User32, ExactSpelling = true, SetLastError = true)]
+ internal static partial bool GetIconInfo(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hIcon, ref ICONINFO info);
[GeneratedDllImport(Libraries.User32, SetLastError = true)]
public static partial int GetSystemMetrics(int nIndex);
- [DllImport(Libraries.User32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
- internal static extern bool DrawIconEx(HandleRef hDC, int x, int y, HandleRef hIcon, int width, int height, int iStepIfAniCursor, HandleRef hBrushFlickerFree, int diFlags);
+ [GeneratedDllImport(Libraries.User32, CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
+ internal static partial bool DrawIconEx(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hDC, int x, int y,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hIcon, int width, int height, int iStepIfAniCursor,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hBrushFlickerFree, int diFlags);
[GeneratedDllImport(Libraries.User32, SetLastError = true)]
internal static unsafe partial IntPtr CreateIconFromResourceEx(byte* pbIconBits, uint cbIconBits, bool fIcon, int dwVersion, int csDesired, int cyDesired, int flags);
@@ -39,4 +70,4 @@ internal static partial class Interop
internal IntPtr hbmColor;
}
}
-} \ No newline at end of file
+}
diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs
index 1b11a3fa45a..cc8ced8e126 100644
--- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs
+++ b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs
@@ -3,6 +3,9 @@
using System;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
internal static partial class Interop
{
@@ -11,13 +14,33 @@ internal static partial class Interop
[GeneratedDllImport(Libraries.Winspool, CharSet = CharSet.Auto, SetLastError = true)]
internal static partial int DeviceCapabilities(string pDevice, string pPort, short fwCapabilities, IntPtr pOutput, IntPtr /*DEVMODE*/ pDevMode);
- [DllImport(Libraries.Winspool, SetLastError = true, CharSet = CharSet.Auto, BestFitMapping = false)]
- internal static extern int DocumentProperties(HandleRef hwnd, HandleRef hPrinter, string pDeviceName, IntPtr /*DEVMODE*/ pDevModeOutput, HandleRef /*DEVMODE*/ pDevModeInput, int fMode);
+ [GeneratedDllImport(Libraries.Winspool, CharSet = CharSet.Auto, SetLastError = true)]
+ internal static partial int DocumentProperties(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hwnd,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hPrinter, string pDeviceName, IntPtr /*DEVMODE*/ pDevModeOutput,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef /*DEVMODE*/ pDevModeInput, int fMode);
- [DllImport(Libraries.Winspool, SetLastError = true, CharSet = CharSet.Auto, BestFitMapping = false)]
- internal static extern int DocumentProperties(HandleRef hwnd, HandleRef hPrinter, string pDeviceName, IntPtr /*DEVMODE*/ pDevModeOutput, IntPtr /*DEVMODE*/ pDevModeInput, int fMode);
+ [GeneratedDllImport(Libraries.Winspool, CharSet = CharSet.Auto, SetLastError = true)]
+ internal static partial int DocumentProperties(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hwnd,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hPrinter, string pDeviceName, IntPtr /*DEVMODE*/ pDevModeOutput, IntPtr /*DEVMODE*/ pDevModeInput, int fMode);
[GeneratedDllImport(Libraries.Winspool, CharSet = CharSet.Auto, SetLastError = true)]
internal static partial int EnumPrinters(int flags, string? name, int level, IntPtr pPrinterEnum/*buffer*/, int cbBuf, out int pcbNeeded, out int pcReturned);
}
-} \ No newline at end of file
+}
diff --git a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj
index 2870372f973..5a34aa4d3ad 100644
--- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj
+++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj
@@ -180,6 +180,8 @@ Unix support is disabled by default. See https://aka.ms/systemdrawingnonwindows
<Compile Include="System\Drawing\Imaging\ImageCodecInfo.cs" />
<Compile Include="System\Drawing\Imaging\ImageCodecInfoPrivate.cs" />
<Compile Include="System\Drawing\Imaging\MetafileFrameUnit.cs" />
+ <Compile Include="$(CommonPath)Interop\Windows\Interop.BOOL.cs"
+ Link="Common\Interop\Windows\Interop.BOOL.cs" />
<Compile Include="$(CommonPath)Interop\Windows\User32\Interop.LOGFONT.cs"
Link="Common\Interop\Windows\User32\Interop.LOGFONT.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Gdi32\Interop.RasterOp.cs"
@@ -391,6 +393,12 @@ Unix support is disabled by default. See https://aka.ms/systemdrawingnonwindows
<LogicalName>placeholder.ico</LogicalName>
</EmbeddedResource>
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0')) and '$(TargetsAnyOS)' != 'true'">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ <Compile Include="$(CommonPath)System\Runtime\InteropServices\HandleRefMarshaller.cs"
+ Link="Common\System\Runtime\InteropServices\HandleRefMarshaller.cs" />
+ </ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.SystemEvents\src\Microsoft.Win32.SystemEvents.csproj" />
<Reference Include="Microsoft.Win32.Primitives" />
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Gdiplus.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Gdiplus.cs
index 512dd06f3bf..743a41ad517 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Gdiplus.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Gdiplus.cs
@@ -26,11 +26,9 @@ namespace System.Drawing
PlatformInitialize();
- StartupInput input = StartupInput.GetDefault();
-
// GDI+ ref counts multiple calls to Startup in the same process, so calls from multiple
// domains are ok, just make sure to pair each w/GdiplusShutdown
- int status = GdiplusStartup(out s_initToken, ref input, out _);
+ int status = GdiplusStartup(out s_initToken, StartupInputEx.GetDefault(), out _);
CheckStatus(status);
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs
index cb74840b78e..3cd50a68186 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Unix.cs
@@ -9,6 +9,9 @@ using System.Drawing.Text;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
namespace System.Drawing
{
@@ -66,13 +69,8 @@ namespace System.Drawing
}
// Imported functions
-
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
-
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs
- [DllImport(LibraryName)]
- internal static extern int GdiplusStartup(out IntPtr token, ref StartupInput input, out StartupOutput output);
-#pragma warning restore DLLIMPORTGENANALYZER015
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdiplusStartup(out IntPtr token, in StartupInputEx input, out StartupOutput output);
[GeneratedDllImport(LibraryName)]
internal static partial void GdiplusShutdown(ref ulong token);
@@ -83,20 +81,36 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial void GdipFree(IntPtr ptr);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteBrush(HandleRef brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteBrush(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetBrushType(IntPtr brush, out BrushType type);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteGraphics(HandleRef graphics);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteGraphics(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipRestoreGraphics(IntPtr graphics, uint graphicsState);
- [DllImport(LibraryName)]
- internal static extern int GdipReleaseDC(HandleRef graphics, HandleRef hdc);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipReleaseDC(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef hdc);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipFillPath(IntPtr graphics, IntPtr brush, IntPtr path);
@@ -104,14 +118,11 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetNearestColor(IntPtr graphics, out int argb);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipAddPathString(IntPtr path, string s, int lenght, IntPtr family, int style, float emSize, ref RectangleF layoutRect, IntPtr format);
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipAddPathString(IntPtr path, string s, int lenght, IntPtr family, int style, float emSize, ref RectangleF layoutRect, IntPtr format);
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipAddPathStringI(IntPtr path, string s, int lenght, IntPtr family, int style, float emSize, ref Rectangle layoutRect, IntPtr format);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipAddPathStringI(IntPtr path, string s, int lenght, IntPtr family, int style, float emSize, ref Rectangle layoutRect, IntPtr format);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateFromHWND(IntPtr hwnd, out IntPtr graphics);
@@ -128,20 +139,14 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipSetImagePalette(IntPtr image, IntPtr palette);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageBounds(IntPtr image, out RectangleF source, ref GraphicsUnit unit);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageBounds(IntPtr image, out RectangleF source, ref GraphicsUnit unit);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetImageThumbnail(IntPtr image, uint width, uint height, out IntPtr thumbImage, IntPtr callback, IntPtr callBackData);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in CoreLib (like Guid).
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipSaveImageToFile(IntPtr image, string filename, ref Guid encoderClsID, IntPtr encoderParameters);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipSaveImageToFile(IntPtr image, string filename, ref Guid encoderClsID, IntPtr encoderParameters);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipSaveAdd(IntPtr image, IntPtr encoderParameters);
@@ -155,20 +160,21 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreatePath(FillMode brushMode, out IntPtr path);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipCreatePath2(PointF[] points, byte[] types, int count, FillMode brushMode, out IntPtr path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreatePath2(PointF[] points, byte[] types, int count, FillMode brushMode, out IntPtr path);
- [DllImport(LibraryName)]
- internal static extern int GdipCreatePath2I(Point[] points, byte[] types, int count, FillMode brushMode, out IntPtr path);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreatePath2I(Point[] points, byte[] types, int count, FillMode brushMode, out IntPtr path);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipClonePath(IntPtr path, out IntPtr clonePath);
- [DllImport(LibraryName)]
- internal static extern int GdipDeletePath(HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeletePath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipResetPath(IntPtr path);
@@ -179,14 +185,11 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetPathTypes(IntPtr path, byte[] types, int count);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathPoints(IntPtr path, [Out] PointF[] points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathPoints(IntPtr path, PointF[] points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathPointsI(IntPtr path, [Out] Point[] points, int count);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathPointsI(IntPtr path, Point[] points, int count);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetPathFillMode(IntPtr path, out FillMode fillMode);
@@ -212,23 +215,17 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipReversePath(IntPtr path);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathLastPoint(IntPtr path, out PointF lastPoint);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathLastPoint(IntPtr path, out PointF lastPoint);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathLine(IntPtr path, float x1, float y1, float x2, float y2);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathLine2(IntPtr path, PointF[] points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathLine2(IntPtr path, PointF[] points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathLine2I(IntPtr path, Point[] points, int count);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathLine2I(IntPtr path, Point[] points, int count);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathArc(IntPtr path, float x, float y, float width, float height, float startAngle, float sweepAngle);
@@ -236,50 +233,44 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathBezier(IntPtr path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathBeziers(IntPtr path, PointF[] points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathBeziers(IntPtr path, PointF[] points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve(IntPtr path, PointF[] points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve(IntPtr path, PointF[] points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurveI(IntPtr path, Point[] points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurveI(IntPtr path, Point[] points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve2(IntPtr path, PointF[] points, int count, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve2(IntPtr path, PointF[] points, int count, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve2I(IntPtr path, Point[] points, int count, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve2I(IntPtr path, Point[] points, int count, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve3(IntPtr path, PointF[] points, int count, int offset, int numberOfSegments, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve3(IntPtr path, PointF[] points, int count, int offset, int numberOfSegments, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve3I(IntPtr path, Point[] points, int count, int offset, int numberOfSegments, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve3I(IntPtr path, Point[] points, int count, int offset, int numberOfSegments, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathClosedCurve(IntPtr path, PointF[] points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathClosedCurve(IntPtr path, PointF[] points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathClosedCurveI(IntPtr path, Point[] points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathClosedCurveI(IntPtr path, Point[] points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathClosedCurve2(IntPtr path, PointF[] points, int count, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathClosedCurve2(IntPtr path, PointF[] points, int count, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathClosedCurve2I(IntPtr path, Point[] points, int count, float tension);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathClosedCurve2I(IntPtr path, Point[] points, int count, float tension);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathRectangle(IntPtr path, float x, float y, float width, float height);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathRectangles(IntPtr path, RectangleF[] rects, int count);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathRectangles(IntPtr path, RectangleF[] rects, int count);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathEllipse(IntPtr path, float x, float y, float width, float height);
@@ -293,11 +284,8 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathPieI(IntPtr path, int x, int y, int width, int height, float startAngle, float sweepAngle);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathPolygon(IntPtr path, PointF[] points, int count);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathPolygon(IntPtr path, PointF[] points, int count);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathPath(IntPtr path, IntPtr addingPath, bool connect);
@@ -311,23 +299,17 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathBezierI(IntPtr path, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathBeziersI(IntPtr path, Point[] points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathBeziersI(IntPtr path, Point[] points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathPolygonI(IntPtr path, Point[] points, int count);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathPolygonI(IntPtr path, Point[] points, int count);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipAddPathRectangleI(IntPtr path, int x, int y, int width, int height);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathRectanglesI(IntPtr path, Rectangle[] rects, int count);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathRectanglesI(IntPtr path, Rectangle[] rects, int count);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipFlattenPath(IntPtr path, IntPtr matrix, float floatness);
@@ -335,23 +317,17 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipTransformPath(IntPtr path, IntPtr matrix);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipWarpPath(IntPtr path, IntPtr matrix, PointF[] points, int count, float srcx, float srcy, float srcwidth, float srcheight, WarpMode mode, float flatness);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipWarpPath(IntPtr path, IntPtr matrix, PointF[] points, int count, float srcx, float srcy, float srcwidth, float srcheight, WarpMode mode, float flatness);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipWidenPath(IntPtr path, IntPtr pen, IntPtr matrix, float flatness);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathWorldBounds(IntPtr path, out RectangleF bounds, IntPtr matrix, IntPtr pen);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathWorldBounds(IntPtr path, out RectangleF bounds, IntPtr matrix, IntPtr pen);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathWorldBoundsI(IntPtr path, out Rectangle bounds, IntPtr matrix, IntPtr pen);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathWorldBoundsI(IntPtr path, out Rectangle bounds, IntPtr matrix, IntPtr pen);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipIsVisiblePathPoint(IntPtr path, float x, float y, IntPtr graphics, out bool result);
@@ -395,11 +371,8 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateFromContext_macosx(IntPtr cgref, int width, int height, out IntPtr graphics);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipSetVisibleClip_linux(IntPtr graphics, ref Rectangle rect);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetVisibleClip_linux(IntPtr graphics, ref Rectangle rect);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateFromXDrawable_linux(IntPtr drawable, IntPtr display, out IntPtr graphics);
@@ -410,13 +383,10 @@ namespace System.Drawing
StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
StreamCloseDelegate close, StreamSizeDelegate size, out IntPtr image);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in CoreLib (like Guid).
- [DllImport(LibraryName)]
- internal static extern int GdipSaveImageToDelegate_linux(IntPtr image, StreamGetBytesDelegate getBytes,
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSaveImageToDelegate_linux(IntPtr image, StreamGetBytesDelegate getBytes,
StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek, StreamCloseDelegate close,
StreamSizeDelegate size, ref Guid encoderClsID, IntPtr encoderParameters);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateMetafileFromDelegate_linux(StreamGetHeaderDelegate getHeader,
@@ -428,20 +398,17 @@ namespace System.Drawing
StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
StreamCloseDelegate close, StreamSizeDelegate size, IntPtr header);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipRecordMetafileFromDelegate_linux(StreamGetHeaderDelegate getHeader,
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipRecordMetafileFromDelegate_linux(StreamGetHeaderDelegate getHeader,
StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref RectangleF frameRect,
MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipRecordMetafileFromDelegateI_linux(StreamGetHeaderDelegate getHeader,
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipRecordMetafileFromDelegateI_linux(StreamGetHeaderDelegate getHeader,
StreamGetBytesDelegate getBytes, StreamPutBytesDelegate putBytes, StreamSeekDelegate doSeek,
StreamCloseDelegate close, StreamSizeDelegate size, IntPtr hdc, EmfType type, ref Rectangle frameRect,
MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetPostScriptGraphicsContext(
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Windows.cs
index 12941682860..2e246f79ec7 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Windows.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.Windows.cs
@@ -5,6 +5,9 @@ using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Internal;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
namespace System.Drawing
{
@@ -19,12 +22,8 @@ namespace System.Drawing
}
// Imported functions
-
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(LibraryName)]
- private static extern int GdiplusStartup(out IntPtr token, ref StartupInput input, out StartupOutput output);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ private static partial int GdiplusStartup(out IntPtr token, in StartupInputEx input, out StartupOutput output);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreatePath(int brushMode, out IntPtr path);
@@ -35,182 +34,490 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreatePath2I(Point* points, byte* types, int count, int brushMode, out IntPtr path);
- [DllImport(LibraryName)]
- internal static extern int GdipClonePath(HandleRef path, out IntPtr clonepath);
-
- [DllImport(LibraryName)]
- internal static extern int GdipDeletePath(HandleRef path);
-
- [DllImport(LibraryName)]
- internal static extern int GdipResetPath(HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipClonePath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, out IntPtr clonepath);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPointCount(HandleRef path, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeletePath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathTypes(HandleRef path, byte[] types, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipResetPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathPoints(HandleRef path, PointF* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPointCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathFillMode(HandleRef path, out FillMode fillmode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathTypes(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, byte[] types, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathFillMode(HandleRef path, FillMode fillmode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathPoints(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathData(HandleRef path, GpPathData* pathData);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathFillMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, out FillMode fillmode);
- [DllImport(LibraryName)]
- internal static extern int GdipStartPathFigure(HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathFillMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, FillMode fillmode);
- [DllImport(LibraryName)]
- internal static extern int GdipClosePathFigure(HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathData(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, GpPathData* pathData);
- [DllImport(LibraryName)]
- internal static extern int GdipClosePathFigures(HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipStartPathFigure(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathMarker(HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipClosePathFigure(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipClearPathMarkers(HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipClosePathFigures(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipReversePath(HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathMarker(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathLastPoint(HandleRef path, out PointF lastPoint);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipClearPathMarkers(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathLine(HandleRef path, float x1, float y1, float x2, float y2);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipReversePath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathLine2(HandleRef path, PointF* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathLastPoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, out PointF lastPoint);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathArc(HandleRef path, float x, float y, float width, float height, float startAngle, float sweepAngle);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathLine(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, float x1, float y1, float x2, float y2);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathBezier(HandleRef path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathLine2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathBeziers(HandleRef path, PointF* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathArc(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, float x, float y, float width, float height, float startAngle, float sweepAngle);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve(HandleRef path, PointF* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathBezier(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve2(HandleRef path, PointF* points, int count, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathBeziers(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve3(HandleRef path, PointF* points, int count, int offset, int numberOfSegments, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathClosedCurve(HandleRef path, PointF* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathClosedCurve2(HandleRef path, PointF* points, int count, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve3(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count, int offset, int numberOfSegments, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathRectangle(HandleRef path, float x, float y, float width, float height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathClosedCurve(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathRectangles(HandleRef path, RectangleF* rects, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathClosedCurve2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathEllipse(HandleRef path, float x, float y, float width, float height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathRectangle(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, float x, float y, float width, float height);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathPie(HandleRef path, float x, float y, float width, float height, float startAngle, float sweepAngle);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathRectangles(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, RectangleF* rects, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathPolygon(HandleRef path, PointF* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathEllipse(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, float x, float y, float width, float height);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathPath(HandleRef path, HandleRef addingPath, bool connect);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathPie(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, float x, float y, float width, float height, float startAngle, float sweepAngle);
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipAddPathString(HandleRef path, string s, int length, HandleRef fontFamily, int style, float emSize, ref RectangleF layoutRect, HandleRef format);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathPolygon(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, PointF* points, int count);
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipAddPathStringI(HandleRef path, string s, int length, HandleRef fontFamily, int style, float emSize, ref Rectangle layoutRect, HandleRef format);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef addingPath, bool connect);
+
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipAddPathString(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, string s, int length,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontFamily, int style, float emSize, ref RectangleF layoutRect,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format);
+
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipAddPathStringI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, string s, int length,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontFamily, int style, float emSize, ref Rectangle layoutRect,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathLineI(HandleRef path, int x1, int y1, int x2, int y2);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathLineI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, int x1, int y1, int x2, int y2);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathLine2I(HandleRef path, Point* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathLine2I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Point* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathArcI(HandleRef path, int x, int y, int width, int height, float startAngle, float sweepAngle);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathArcI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, int x, int y, int width, int height, float startAngle, float sweepAngle);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathBezierI(HandleRef path, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathBezierI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathBeziersI(HandleRef path, Point* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathBeziersI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Point* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurveI(HandleRef path, Point* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurveI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Point* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve2I(HandleRef path, Point* points, int count, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve2I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Point* points, int count, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathCurve3I(HandleRef path, Point* points, int count, int offset, int numberOfSegments, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathCurve3I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Point* points, int count, int offset, int numberOfSegments, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathClosedCurveI(HandleRef path, Point* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathClosedCurveI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Point* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathClosedCurve2I(HandleRef path, Point* points, int count, float tension);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathClosedCurve2I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Point* points, int count, float tension);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathRectangleI(HandleRef path, int x, int y, int width, int height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathRectangleI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, int x, int y, int width, int height);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathRectanglesI(HandleRef path, Rectangle* rects, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathRectanglesI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Rectangle* rects, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathEllipseI(HandleRef path, int x, int y, int width, int height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathEllipseI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, int x, int y, int width, int height);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathPieI(HandleRef path, int x, int y, int width, int height, float startAngle, float sweepAngle);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathPieI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, int x, int y, int width, int height, float startAngle, float sweepAngle);
- [DllImport(LibraryName)]
- internal static extern int GdipAddPathPolygonI(HandleRef path, Point* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipAddPathPolygonI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, Point* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipFlattenPath(HandleRef path, HandleRef matrixfloat, float flatness);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipFlattenPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrixfloat, float flatness);
- [DllImport(LibraryName)]
- internal static extern int GdipWidenPath(HandleRef path, HandleRef pen, HandleRef matrix, float flatness);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipWidenPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, float flatness);
- [DllImport(LibraryName)]
- internal static extern int GdipWarpPath(HandleRef path, HandleRef matrix, PointF* points, int count, float srcX, float srcY, float srcWidth, float srcHeight, WarpMode warpMode, float flatness);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipWarpPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, PointF* points, int count, float srcX, float srcY, float srcWidth, float srcHeight, WarpMode warpMode, float flatness);
- [DllImport(LibraryName)]
- internal static extern int GdipTransformPath(HandleRef path, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTransformPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathWorldBounds(HandleRef path, out RectangleF gprectf, HandleRef matrix, HandleRef pen);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathWorldBounds(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, out RectangleF gprectf,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisiblePathPoint(HandleRef path, float x, float y, HandleRef graphics, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisiblePathPoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, float x, float y,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisiblePathPointI(HandleRef path, int x, int y, HandleRef graphics, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisiblePathPointI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, int x, int y,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipIsOutlineVisiblePathPoint(HandleRef path, float x, float y, HandleRef pen, HandleRef graphics, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsOutlineVisiblePathPoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, float x, float y,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipIsOutlineVisiblePathPointI(HandleRef path, int x, int y, HandleRef pen, HandleRef graphics, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsOutlineVisiblePathPointI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, int x, int y,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteBrush(HandleRef brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteBrush(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipLoadImageFromStream(IntPtr stream, IntPtr* image);
@@ -218,38 +525,102 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipLoadImageFromStreamICM(IntPtr stream, IntPtr* image);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneImage(HandleRef image, out IntPtr cloneimage);
-
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipSaveImageToFile(HandleRef image, string filename, ref Guid classId, HandleRef encoderParams);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneImage(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out IntPtr cloneimage);
+
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipSaveImageToFile(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, string filename, ref Guid classId,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef encoderParams);
- [DllImport(LibraryName)]
- internal static extern int GdipSaveImageToStream(HandleRef image, IntPtr stream, Guid* classId, HandleRef encoderParams);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSaveImageToStream(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, IntPtr stream, Guid* classId,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef encoderParams);
- [DllImport(LibraryName)]
- internal static extern int GdipSaveAdd(HandleRef image, HandleRef encoderParams);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSaveAdd(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef encoderParams);
- [DllImport(LibraryName)]
- internal static extern int GdipSaveAddImage(HandleRef image, HandleRef newImage, HandleRef encoderParams);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSaveAddImage(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef newImage,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef encoderParams);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageGraphicsContext(HandleRef image, out IntPtr graphics);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageGraphicsContext(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out IntPtr graphics);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageBounds(HandleRef image, out RectangleF gprectf, out GraphicsUnit unit);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageBounds(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out RectangleF gprectf, out GraphicsUnit unit);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageThumbnail(HandleRef image, int thumbWidth, int thumbHeight, out IntPtr thumbImage, Image.GetThumbnailImageAbort? callback, IntPtr callbackdata);
+ [GeneratedDllImport(LibraryName)]
+ 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);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImagePalette(HandleRef image, IntPtr palette, int size);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImagePalette(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, IntPtr palette, int size);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImagePalette(HandleRef image, IntPtr palette);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImagePalette(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, IntPtr palette);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImagePaletteSize(HandleRef image, out int size);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImagePaletteSize(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out int size);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipImageForceValidation(IntPtr image);
@@ -260,74 +631,284 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateFromHWND(IntPtr hwnd, out IntPtr graphics);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteGraphics(HandleRef graphics);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteGraphics(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics);
- [DllImport(LibraryName)]
- internal static extern int GdipReleaseDC(HandleRef graphics, IntPtr hdc);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipReleaseDC(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, IntPtr hdc);
- [DllImport(LibraryName)]
- internal static extern int GdipGetNearestColor(HandleRef graphics, ref int color);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetNearestColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, ref int color);
[GeneratedDllImport(LibraryName)]
internal static partial IntPtr GdipCreateHalftonePalette();
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawBeziers(HandleRef graphics, HandleRef pen, PointF* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawBeziersI(HandleRef graphics, HandleRef pen, Point* points, int count);
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawBeziers(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PointF* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawBeziersI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Point* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillPath(HandleRef graphics, HandleRef brush, HandleRef path);
-
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileDestPoint(HandleRef graphics, HandleRef metafile, ref PointF destPoint, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
-
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileDestPointI(HandleRef graphics, HandleRef metafile, ref Point destPoint, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileDestPoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, ref PointF destPoint, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileDestRect(HandleRef graphics, HandleRef metafile, ref RectangleF destRect, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileDestPointI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, ref Point destPoint, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileDestRectI(HandleRef graphics, HandleRef metafile, ref Rectangle destRect, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileDestRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, ref RectangleF destRect, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileDestPoints(HandleRef graphics, HandleRef metafile, PointF* destPoints, int count, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileDestRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, ref Rectangle destRect, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileDestPointsI(HandleRef graphics, HandleRef metafile, Point* destPoints, int count, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileDestPoints(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, PointF* destPoints, int count, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileSrcRectDestPoint(HandleRef graphics, HandleRef metafile, ref PointF destPoint, ref RectangleF srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileDestPointsI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, Point* destPoints, int count, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileSrcRectDestPointI(HandleRef graphics, HandleRef metafile, ref Point destPoint, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileSrcRectDestPoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, ref PointF destPoint, ref RectangleF srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileSrcRectDestRect(HandleRef graphics, HandleRef metafile, ref RectangleF destRect, ref RectangleF srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileSrcRectDestPointI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, ref Point destPoint, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileSrcRectDestRectI(HandleRef graphics, HandleRef metafile, ref Rectangle destRect, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileSrcRectDestRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, ref RectangleF destRect, ref RectangleF srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileSrcRectDestPoints(HandleRef graphics, HandleRef metafile, PointF* destPoints, int count, ref RectangleF srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileSrcRectDestRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, ref Rectangle destRect, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipEnumerateMetafileSrcRectDestPointsI(HandleRef graphics, HandleRef metafile, Point* destPoints, int count, ref Rectangle srcRect, GraphicsUnit pageUnit, Graphics.EnumerateMetafileProc callback, IntPtr callbackdata, HandleRef imageattributes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileSrcRectDestPoints(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#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,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
- [DllImport(LibraryName)]
- internal static extern int GdipRestoreGraphics(HandleRef graphics, int state);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEnumerateMetafileSrcRectDestPointsI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#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,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattributes);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(LibraryName)]
- internal static extern int GdipGetMetafileHeaderFromWmf(IntPtr hMetafile, WmfPlaceableFileHeader wmfplaceable, [In] [Out] MetafileHeaderWmf metafileHeaderWmf);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipRestoreGraphics(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int state);
+
+ [GeneratedDllImport(LibraryName, EntryPoint = "GdipGetMetafileHeaderFromWmf")]
+ private static partial int GdipGetMetafileHeaderFromWmf_Internal(IntPtr hMetafile,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(WmfPlaceableFileHeader.PinningMarshaller))]
+#endif
+ WmfPlaceableFileHeader wmfplaceable,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(MetafileHeaderWmf.InPlaceMarshaller))]
+ ref MetafileHeaderWmf metafileHeaderWmf
+#else
+ MetafileHeaderWmf metafileHeaderWmf
+#endif
+ );
+
+ internal static int GdipGetMetafileHeaderFromWmf(IntPtr hMetafile,
+ WmfPlaceableFileHeader wmfplaceable,
+ MetafileHeaderWmf metafileHeaderWmf
+ )
+ {
+ return GdipGetMetafileHeaderFromWmf_Internal(hMetafile,
+ wmfplaceable,
+#if NET7_0_OR_GREATER
+ ref
+#endif
+ metafileHeaderWmf
+ );
+ }
- [DllImport(LibraryName)]
- internal static extern int GdipGetMetafileHeaderFromEmf(IntPtr hEnhMetafile, [In] [Out] MetafileHeaderEmf metafileHeaderEmf);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetMetafileHeaderFromEmf(IntPtr hEnhMetafile, MetafileHeaderEmf metafileHeaderEmf);
[GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial int GdipGetMetafileHeaderFromFile(string filename, IntPtr header);
@@ -335,11 +916,19 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetMetafileHeaderFromStream(IntPtr stream, IntPtr header);
- [DllImport(LibraryName)]
- internal static extern int GdipGetMetafileHeaderFromMetafile(HandleRef metafile, IntPtr header);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetMetafileHeaderFromMetafile(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, IntPtr header);
- [DllImport(LibraryName)]
- internal static extern int GdipGetHemfFromMetafile(HandleRef metafile, out IntPtr hEnhMetafile);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetHemfFromMetafile(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, out IntPtr hEnhMetafile);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateMetafileFromStream(IntPtr stream, IntPtr* metafile);
@@ -353,8 +942,12 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial int GdipRecordMetafileStreamI(IntPtr stream, IntPtr referenceHdc, EmfType emfType, Rectangle* frameRect, MetafileFrameUnit frameUnit, string? description, IntPtr* metafile);
- [DllImport(LibraryName)]
- internal static extern int GdipComment(HandleRef graphics, int sizeData, byte[] data);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipComment(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int sizeData, byte[] data);
[GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial int GdipCreateFontFromLogfontW(IntPtr hdc, ref Interop.User32.LOGFONT lf, out IntPtr font);
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 8fef9cbc472..8097957af5e 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/GdiplusNative.cs
@@ -5,6 +5,9 @@ using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+using System.Runtime.InteropServices.GeneratedMarshalling;
+#endif
namespace System.Drawing
{
@@ -15,230 +18,507 @@ namespace System.Drawing
internal static unsafe partial class Gdip
{
// Shared function imports (all platforms)
- [DllImport(LibraryName)]
- internal static extern int GdipBeginContainer(HandleRef graphics, ref RectangleF dstRect, ref RectangleF srcRect, GraphicsUnit unit, out int state);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipBeginContainer(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, ref RectangleF dstRect, ref RectangleF srcRect, GraphicsUnit unit, out int state);
- [DllImport(LibraryName)]
- internal static extern int GdipBeginContainer2(HandleRef graphics, out int state);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipBeginContainer2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int state);
- [DllImport(LibraryName)]
- internal static extern int GdipBeginContainerI(HandleRef graphics, ref Rectangle dstRect, ref Rectangle srcRect, GraphicsUnit unit, out int state);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipBeginContainerI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, ref Rectangle dstRect, ref Rectangle srcRect, GraphicsUnit unit, out int state);
- [DllImport(LibraryName)]
- internal static extern int GdipEndContainer(HandleRef graphics, int state);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipEndContainer(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int state);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateAdjustableArrowCap(float height, float width, bool isFilled, out IntPtr adjustableArrowCap);
- [DllImport(LibraryName)]
- internal static extern int GdipGetAdjustableArrowCapHeight(HandleRef adjustableArrowCap, out float height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetAdjustableArrowCapHeight(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef adjustableArrowCap, out float height);
- [DllImport(LibraryName)]
- internal static extern int GdipSetAdjustableArrowCapHeight(HandleRef adjustableArrowCap, float height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetAdjustableArrowCapHeight(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef adjustableArrowCap, float height);
- [DllImport(LibraryName)]
- internal static extern int GdipSetAdjustableArrowCapWidth(HandleRef adjustableArrowCap, float width);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetAdjustableArrowCapWidth(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef adjustableArrowCap, float width);
- [DllImport(LibraryName)]
- internal static extern int GdipGetAdjustableArrowCapWidth(HandleRef adjustableArrowCap, out float width);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetAdjustableArrowCapWidth(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef adjustableArrowCap, out float width);
- [DllImport(LibraryName)]
- internal static extern int GdipSetAdjustableArrowCapMiddleInset(HandleRef adjustableArrowCap, float middleInset);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetAdjustableArrowCapMiddleInset(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef adjustableArrowCap, float middleInset);
- [DllImport(LibraryName)]
- internal static extern int GdipGetAdjustableArrowCapMiddleInset(HandleRef adjustableArrowCap, out float middleInset);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetAdjustableArrowCapMiddleInset(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef adjustableArrowCap, out float middleInset);
- [DllImport(LibraryName)]
- internal static extern int GdipSetAdjustableArrowCapFillState(HandleRef adjustableArrowCap, bool fillState);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetAdjustableArrowCapFillState(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef adjustableArrowCap, bool fillState);
- [DllImport(LibraryName)]
- internal static extern int GdipGetAdjustableArrowCapFillState(HandleRef adjustableArrowCap, out bool fillState);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetAdjustableArrowCapFillState(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef adjustableArrowCap, out bool fillState);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetCustomLineCapType(IntPtr customCap, out CustomLineCapType capType);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateCustomLineCap(HandleRef fillpath, HandleRef strokepath, LineCap baseCap, float baseInset, out IntPtr customCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateCustomLineCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fillpath,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef strokepath, LineCap baseCap, float baseInset, out IntPtr customCap);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipDeleteCustomLineCap(IntPtr customCap);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteCustomLineCap(HandleRef customCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteCustomLineCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneCustomLineCap(HandleRef customCap, out IntPtr clonedCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneCustomLineCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, out IntPtr clonedCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetCustomLineCapStrokeCaps(HandleRef customCap, LineCap startCap, LineCap endCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetCustomLineCapStrokeCaps(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, LineCap startCap, LineCap endCap);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCustomLineCapStrokeCaps(HandleRef customCap, out LineCap startCap, out LineCap endCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCustomLineCapStrokeCaps(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, out LineCap startCap, out LineCap endCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetCustomLineCapStrokeJoin(HandleRef customCap, LineJoin lineJoin);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetCustomLineCapStrokeJoin(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, LineJoin lineJoin);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCustomLineCapStrokeJoin(HandleRef customCap, out LineJoin lineJoin);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCustomLineCapStrokeJoin(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, out LineJoin lineJoin);
- [DllImport(LibraryName)]
- internal static extern int GdipSetCustomLineCapBaseCap(HandleRef customCap, LineCap baseCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetCustomLineCapBaseCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, LineCap baseCap);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCustomLineCapBaseCap(HandleRef customCap, out LineCap baseCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCustomLineCapBaseCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, out LineCap baseCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetCustomLineCapBaseInset(HandleRef customCap, float inset);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetCustomLineCapBaseInset(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, float inset);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCustomLineCapBaseInset(HandleRef customCap, out float inset);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCustomLineCapBaseInset(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, out float inset);
- [DllImport(LibraryName)]
- internal static extern int GdipSetCustomLineCapWidthScale(HandleRef customCap, float widthScale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetCustomLineCapWidthScale(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, float widthScale);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCustomLineCapWidthScale(HandleRef customCap, out float widthScale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCustomLineCapWidthScale(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap, out float widthScale);
- [DllImport(LibraryName)]
- internal static extern int GdipCreatePathIter(out IntPtr pathIter, HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreatePathIter(out IntPtr pathIter,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipDeletePathIter(HandleRef pathIter);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeletePathIter(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterNextSubpath(HandleRef pathIter, out int resultCount, out int startIndex, out int endIndex, out bool isClosed);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterNextSubpath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int resultCount, out int startIndex, out int endIndex, out bool isClosed);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterNextSubpathPath(HandleRef pathIter, out int resultCount, HandleRef path, out bool isClosed);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterNextSubpathPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int resultCount,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, out bool isClosed);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterNextPathType(HandleRef pathIter, out int resultCount, out byte pathType, out int startIndex, out int endIndex);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterNextPathType(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int resultCount, out byte pathType, out int startIndex, out int endIndex);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterNextMarker(HandleRef pathIter, out int resultCount, out int startIndex, out int endIndex);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterNextMarker(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int resultCount, out int startIndex, out int endIndex);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterNextMarkerPath(HandleRef pathIter, out int resultCount, HandleRef path);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterNextMarkerPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int resultCount,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterGetCount(HandleRef pathIter, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterGetCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterGetSubpathCount(HandleRef pathIter, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterGetSubpathCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterHasCurve(HandleRef pathIter, out bool hasCurve);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterHasCurve(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out bool hasCurve);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterRewind(HandleRef pathIter);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterRewind(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterEnumerate(HandleRef pathIter, out int resultCount, PointF* points, byte* types, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterEnumerate(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int resultCount, PointF* points, byte* types, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipPathIterCopyData(HandleRef pathIter, out int resultCount, PointF* points, byte* types, int startIndex, int endIndex);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPathIterCopyData(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pathIter, out int resultCount, PointF* points, byte* types, int startIndex, int endIndex);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateHatchBrush(int hatchstyle, int forecol, int backcol, out IntPtr brush);
- [DllImport(LibraryName)]
- internal static extern int GdipGetHatchStyle(HandleRef brush, out int hatchstyle);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetHatchStyle(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int hatchstyle);
- [DllImport(LibraryName)]
- internal static extern int GdipGetHatchForegroundColor(HandleRef brush, out int forecol);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetHatchForegroundColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int forecol);
- [DllImport(LibraryName)]
- internal static extern int GdipGetHatchBackgroundColor(HandleRef brush, out int backcol);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetHatchBackgroundColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int backcol);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneBrush(HandleRef brush, out IntPtr clonebrush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneBrush(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out IntPtr clonebrush);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipCreateLineBrush(ref PointF point1, ref PointF point2, int color1, int color2, WrapMode wrapMode, out IntPtr lineGradient);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateLineBrush(ref PointF point1, ref PointF point2, int color1, int color2, WrapMode wrapMode, out IntPtr lineGradient);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateLineBrushI(ref Point point1, ref Point point2, int color1, int color2, WrapMode wrapMode, out IntPtr lineGradient);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateLineBrushI(ref Point point1, ref Point point2, int color1, int color2, WrapMode wrapMode, out IntPtr lineGradient);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateLineBrushFromRect(ref RectangleF rect, int color1, int color2, LinearGradientMode lineGradientMode, WrapMode wrapMode, out IntPtr lineGradient);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateLineBrushFromRect(ref RectangleF rect, int color1, int color2, LinearGradientMode lineGradientMode, WrapMode wrapMode, out IntPtr lineGradient);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateLineBrushFromRectI(ref Rectangle rect, int color1, int color2, LinearGradientMode lineGradientMode, WrapMode wrapMode, out IntPtr lineGradient);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateLineBrushFromRectI(ref Rectangle rect, int color1, int color2, LinearGradientMode lineGradientMode, WrapMode wrapMode, out IntPtr lineGradient);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateLineBrushFromRectWithAngle(ref RectangleF rect, int color1, int color2, float angle, bool isAngleScaleable, WrapMode wrapMode, out IntPtr lineGradient);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateLineBrushFromRectWithAngle(ref RectangleF rect, int color1, int color2, float angle, bool isAngleScaleable, WrapMode wrapMode, out IntPtr lineGradient);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateLineBrushFromRectWithAngleI(ref Rectangle rect, int color1, int color2, float angle, bool isAngleScaleable, WrapMode wrapMode, out IntPtr lineGradient);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateLineBrushFromRectWithAngleI(ref Rectangle rect, int color1, int color2, float angle, bool isAngleScaleable, WrapMode wrapMode, out IntPtr lineGradient);
- [DllImport(LibraryName)]
- internal static extern int GdipSetLineColors(HandleRef brush, int color1, int color2);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetLineColors(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int color1, int color2);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLineColors(HandleRef brush, int[] colors);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLineColors(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int[] colors);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLineRect(HandleRef brush, out RectangleF gprectf);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLineRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out RectangleF gprectf);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLineGammaCorrection(HandleRef brush, out bool useGammaCorrection);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLineGammaCorrection(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out bool useGammaCorrection);
- [DllImport(LibraryName)]
- internal static extern int GdipSetLineGammaCorrection(HandleRef brush, bool useGammaCorrection);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetLineGammaCorrection(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, bool useGammaCorrection);
- [DllImport(LibraryName)]
- internal static extern int GdipSetLineSigmaBlend(HandleRef brush, float focus, float scale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetLineSigmaBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float focus, float scale);
- [DllImport(LibraryName)]
- internal static extern int GdipSetLineLinearBlend(HandleRef brush, float focus, float scale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetLineLinearBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float focus, float scale);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLineBlendCount(HandleRef brush, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLineBlendCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLineBlend(HandleRef brush, IntPtr blend, IntPtr positions, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLineBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, IntPtr blend, IntPtr positions, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetLineBlend(HandleRef brush, IntPtr blend, IntPtr positions, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetLineBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, IntPtr blend, IntPtr positions, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLinePresetBlendCount(HandleRef brush, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLinePresetBlendCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLinePresetBlend(HandleRef brush, IntPtr blend, IntPtr positions, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLinePresetBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, IntPtr blend, IntPtr positions, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetLinePresetBlend(HandleRef brush, IntPtr blend, IntPtr positions, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetLinePresetBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, IntPtr blend, IntPtr positions, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetLineWrapMode(HandleRef brush, int wrapMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetLineWrapMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int wrapMode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLineWrapMode(HandleRef brush, out int wrapMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLineWrapMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int wrapMode);
- [DllImport(LibraryName)]
- internal static extern int GdipResetLineTransform(HandleRef brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipResetLineTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush);
- [DllImport(LibraryName)]
- internal static extern int GdipMultiplyLineTransform(HandleRef brush, HandleRef matrix, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipMultiplyLineTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLineTransform(HandleRef brush, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLineTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipSetLineTransform(HandleRef brush, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetLineTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslateLineTransform(HandleRef brush, float dx, float dy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslateLineTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float dx, float dy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipScaleLineTransform(HandleRef brush, float sx, float sy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipScaleLineTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float sx, float sy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipRotateLineTransform(HandleRef brush, float angle, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipRotateLineTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float angle, MatrixOrder order);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreatePathGradient(PointF* points, int count, WrapMode wrapMode, out IntPtr brush);
@@ -246,131 +526,315 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreatePathGradientI(Point* points, int count, WrapMode wrapMode, out IntPtr brush);
- [DllImport(LibraryName)]
- internal static extern int GdipCreatePathGradientFromPath(HandleRef path, out IntPtr brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreatePathGradientFromPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, out IntPtr brush);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientCenterColor(HandleRef brush, out int color);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientCenterColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int color);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientCenterColor(HandleRef brush, int color);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientCenterColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int color);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientSurroundColorsWithCount(HandleRef brush, int[] color, ref int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientSurroundColorsWithCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int[] color, ref int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientSurroundColorsWithCount(HandleRef brush, int[] argb, ref int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientSurroundColorsWithCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int[] argb, ref int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientCenterPoint(HandleRef brush, out PointF point);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientCenterPoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out PointF point);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientCenterPoint(HandleRef brush, ref PointF point);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientCenterPoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, ref PointF point);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientRect(HandleRef brush, out RectangleF gprectf);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out RectangleF gprectf);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientPointCount(HandleRef brush, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientPointCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientSurroundColorCount(HandleRef brush, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientSurroundColorCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientBlendCount(HandleRef brush, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientBlendCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientBlend(HandleRef brush, float[] blend, float[] positions, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float[] blend, float[] positions, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientBlend(HandleRef brush, IntPtr blend, IntPtr positions, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, IntPtr blend, IntPtr positions, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientPresetBlendCount(HandleRef brush, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientPresetBlendCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientPresetBlend(HandleRef brush, int[] blend, float[] positions, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientPresetBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int[] blend, float[] positions, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientPresetBlend(HandleRef brush, int[] blend, float[] positions, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientPresetBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int[] blend, float[] positions, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientSigmaBlend(HandleRef brush, float focus, float scale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientSigmaBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float focus, float scale);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientLinearBlend(HandleRef brush, float focus, float scale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientLinearBlend(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float focus, float scale);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientWrapMode(HandleRef brush, int wrapmode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientWrapMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int wrapmode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientWrapMode(HandleRef brush, out int wrapmode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientWrapMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int wrapmode);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientTransform(HandleRef brush, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientTransform(HandleRef brush, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipResetPathGradientTransform(HandleRef brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipResetPathGradientTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush);
- [DllImport(LibraryName)]
- internal static extern int GdipMultiplyPathGradientTransform(HandleRef brush, HandleRef matrix, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipMultiplyPathGradientTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslatePathGradientTransform(HandleRef brush, float dx, float dy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslatePathGradientTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float dx, float dy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipScalePathGradientTransform(HandleRef brush, float sx, float sy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipScalePathGradientTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float sx, float sy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipRotatePathGradientTransform(HandleRef brush, float angle, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipRotatePathGradientTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float angle, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPathGradientFocusScales(HandleRef brush, float[] xScale, float[] yScale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPathGradientFocusScales(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float[] xScale, float[] yScale);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPathGradientFocusScales(HandleRef brush, float xScale, float yScale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPathGradientFocusScales(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float xScale, float yScale);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateImageAttributes(out IntPtr imageattr);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneImageAttributes(HandleRef imageattr, out IntPtr cloneImageattr);
-
- [DllImport(LibraryName)]
- internal static extern int GdipDisposeImageAttributes(HandleRef imageattr);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneImageAttributes(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, out IntPtr cloneImageattr);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImageAttributesColorMatrix(HandleRef imageattr, ColorAdjustType type, bool enableFlag, ColorMatrix? colorMatrix, ColorMatrix? grayMatrix, ColorMatrixFlag flags);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDisposeImageAttributes(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImageAttributesThreshold(HandleRef imageattr, ColorAdjustType type, bool enableFlag, float threshold);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImageAttributesColorMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, ColorAdjustType type, bool enableFlag,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(ColorMatrix.PinningMarshaller))]
+#endif
+ ColorMatrix? colorMatrix,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(ColorMatrix.PinningMarshaller))]
+#endif
+ ColorMatrix? grayMatrix, ColorMatrixFlag flags);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImageAttributesGamma(HandleRef imageattr, ColorAdjustType type, bool enableFlag, float gamma);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImageAttributesThreshold(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, ColorAdjustType type, bool enableFlag, float threshold);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImageAttributesNoOp(HandleRef imageattr, ColorAdjustType type, bool enableFlag);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImageAttributesGamma(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, ColorAdjustType type, bool enableFlag, float gamma);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImageAttributesColorKeys(HandleRef imageattr, ColorAdjustType type, bool enableFlag, int colorLow, int colorHigh);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImageAttributesNoOp(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, ColorAdjustType type, bool enableFlag);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImageAttributesOutputChannel(HandleRef imageattr, ColorAdjustType type, bool enableFlag, ColorChannelFlag flags);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImageAttributesColorKeys(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, ColorAdjustType type, bool enableFlag, int colorLow, int colorHigh);
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipSetImageAttributesOutputChannelColorProfile(HandleRef imageattr, ColorAdjustType type, bool enableFlag, string colorProfileFilename);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImageAttributesOutputChannel(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, ColorAdjustType type, bool enableFlag, ColorChannelFlag flags);
+
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipSetImageAttributesOutputChannelColorProfile(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, ColorAdjustType type, bool enableFlag, string colorProfileFilename);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImageAttributesRemapTable(HandleRef imageattr, ColorAdjustType type, bool enableFlag, int mapSize, IntPtr map);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImageAttributesRemapTable(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, ColorAdjustType type, bool enableFlag, int mapSize, IntPtr map);
- [DllImport(LibraryName)]
- internal static extern int GdipSetImageAttributesWrapMode(HandleRef imageattr, int wrapmode, int argb, bool clamp);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetImageAttributesWrapMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, int wrapmode, int argb, bool clamp);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageAttributesAdjustedPalette(HandleRef imageattr, IntPtr palette, ColorAdjustType type);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageAttributesAdjustedPalette(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageattr, IntPtr palette, ColorAdjustType type);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetImageDecodersSize(out int numDecoders, out int size);
@@ -387,69 +851,169 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateSolidFill(int color, out IntPtr brush);
- [DllImport(LibraryName)]
- internal static extern int GdipSetSolidFillColor(HandleRef brush, int color);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetSolidFillColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int color);
- [DllImport(LibraryName)]
- internal static extern int GdipGetSolidFillColor(HandleRef brush, out int color);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetSolidFillColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int color);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateTexture(HandleRef bitmap, int wrapmode, out IntPtr texture);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateTexture(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap, int wrapmode, out IntPtr texture);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateTexture2(HandleRef bitmap, int wrapmode, float x, float y, float width, float height, out IntPtr texture);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateTexture2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap, int wrapmode, float x, float y, float width, float height, out IntPtr texture);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateTextureIA(HandleRef bitmap, HandleRef imageAttrib, float x, float y, float width, float height, out IntPtr texture);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateTextureIA(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageAttrib, float x, float y, float width, float height, out IntPtr texture);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateTexture2I(HandleRef bitmap, int wrapmode, int x, int y, int width, int height, out IntPtr texture);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateTexture2I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap, int wrapmode, int x, int y, int width, int height, out IntPtr texture);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateTextureIAI(HandleRef bitmap, HandleRef imageAttrib, int x, int y, int width, int height, out IntPtr texture);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateTextureIAI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageAttrib, int x, int y, int width, int height, out IntPtr texture);
- [DllImport(LibraryName)]
- internal static extern int GdipSetTextureTransform(HandleRef brush, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetTextureTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipGetTextureTransform(HandleRef brush, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetTextureTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipResetTextureTransform(HandleRef brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipResetTextureTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush);
- [DllImport(LibraryName)]
- internal static extern int GdipMultiplyTextureTransform(HandleRef brush, HandleRef matrix, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipMultiplyTextureTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslateTextureTransform(HandleRef brush, float dx, float dy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslateTextureTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float dx, float dy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipScaleTextureTransform(HandleRef brush, float sx, float sy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipScaleTextureTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float sx, float sy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipRotateTextureTransform(HandleRef brush, float angle, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipRotateTextureTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float angle, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipSetTextureWrapMode(HandleRef brush, int wrapMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetTextureWrapMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int wrapMode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetTextureWrapMode(HandleRef brush, out int wrapMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetTextureWrapMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out int wrapMode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetTextureImage(HandleRef brush, out IntPtr image);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetTextureImage(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, out IntPtr image);
- [DllImport(LibraryName)]
- internal static extern int GdipGetFontCollectionFamilyCount(HandleRef fontCollection, out int numFound);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetFontCollectionFamilyCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontCollection, out int numFound);
- [DllImport(LibraryName)]
- internal static extern int GdipGetFontCollectionFamilyList(HandleRef fontCollection, int numSought, IntPtr[] gpfamilies, out int numFound);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetFontCollectionFamilyList(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontCollection, int numSought, IntPtr[] gpfamilies, out int numFound);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCloneFontFamily(IntPtr fontfamily, out IntPtr clonefontfamily);
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipCreateFontFamilyFromName(string name, HandleRef fontCollection, out IntPtr FontFamily);
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipCreateFontFamilyFromName(string name,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontCollection, out IntPtr FontFamily);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetGenericFontFamilySansSerif(out IntPtr fontfamily);
@@ -460,26 +1024,54 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetGenericFontFamilyMonospace(out IntPtr fontfamily);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteFontFamily(HandleRef fontFamily);
-
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipGetFamilyName(HandleRef family, char* name, int language);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteFontFamily(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontFamily);
+
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipGetFamilyName(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef family, char* name, int language);
- [DllImport(LibraryName)]
- internal static extern int GdipIsStyleAvailable(HandleRef family, FontStyle style, out int isStyleAvailable);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsStyleAvailable(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef family, FontStyle style, out int isStyleAvailable);
- [DllImport(LibraryName)]
- internal static extern int GdipGetEmHeight(HandleRef family, FontStyle style, out int EmHeight);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetEmHeight(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef family, FontStyle style, out int EmHeight);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCellAscent(HandleRef family, FontStyle style, out int CellAscent);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCellAscent(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef family, FontStyle style, out int CellAscent);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCellDescent(HandleRef family, FontStyle style, out int CellDescent);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCellDescent(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef family, FontStyle style, out int CellDescent);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLineSpacing(HandleRef family, FontStyle style, out int LineSpaceing);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLineSpacing(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef family, FontStyle style, out int LineSpaceing);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipNewInstalledFontCollection(out IntPtr fontCollection);
@@ -490,266 +1082,654 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipDeletePrivateFontCollection(ref IntPtr fontCollection);
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipPrivateAddFontFile(HandleRef fontCollection, string filename);
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipPrivateAddFontFile(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontCollection, string filename);
- [DllImport(LibraryName)]
- internal static extern int GdipPrivateAddMemoryFont(HandleRef fontCollection, IntPtr memory, int length);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPrivateAddMemoryFont(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontCollection, IntPtr memory, int length);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateFont(HandleRef fontFamily, float emSize, FontStyle style, GraphicsUnit unit, out IntPtr font);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateFont(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef fontFamily, float emSize, FontStyle style, GraphicsUnit unit, out IntPtr font);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateFontFromDC(IntPtr hdc, ref IntPtr font);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneFont(HandleRef font, out IntPtr cloneFont);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneFont(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, out IntPtr cloneFont);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteFont(HandleRef font);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteFont(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font);
- [DllImport(LibraryName)]
- internal static extern int GdipGetFamily(HandleRef font, out IntPtr family);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetFamily(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, out IntPtr family);
- [DllImport(LibraryName)]
- internal static extern int GdipGetFontStyle(HandleRef font, out FontStyle style);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetFontStyle(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, out FontStyle style);
- [DllImport(LibraryName)]
- internal static extern int GdipGetFontSize(HandleRef font, out float size);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetFontSize(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, out float size);
- [DllImport(LibraryName)]
- internal static extern int GdipGetFontHeight(HandleRef font, HandleRef graphics, out float size);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetFontHeight(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out float size);
- [DllImport(LibraryName)]
- internal static extern int GdipGetFontHeightGivenDPI(HandleRef font, float dpi, out float size);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetFontHeightGivenDPI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, float dpi, out float size);
- [DllImport(LibraryName)]
- internal static extern int GdipGetFontUnit(HandleRef font, out GraphicsUnit unit);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetFontUnit(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, out GraphicsUnit unit);
- [DllImport(LibraryName)]
- internal static extern int GdipGetLogFontW(HandleRef font, HandleRef graphics, ref Interop.User32.LOGFONT lf);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetLogFontW(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, ref Interop.User32.LOGFONT lf);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreatePen1(int argb, float width, int unit, out IntPtr pen);
- [DllImport(LibraryName)]
- internal static extern int GdipCreatePen2(HandleRef brush, float width, int unit, out IntPtr pen);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreatePen2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float width, int unit, out IntPtr pen);
- [DllImport(LibraryName)]
- internal static extern int GdipClonePen(HandleRef pen, out IntPtr clonepen);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipClonePen(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out IntPtr clonepen);
- [DllImport(LibraryName)]
- internal static extern int GdipDeletePen(HandleRef Pen);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeletePen(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef Pen);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenMode(HandleRef pen, PenAlignment penAlign);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PenAlignment penAlign);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenMode(HandleRef pen, out PenAlignment penAlign);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out PenAlignment penAlign);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenWidth(HandleRef pen, float width);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenWidth(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float width);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenWidth(HandleRef pen, float[] width);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenWidth(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float[] width);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenLineCap197819(HandleRef pen, int startCap, int endCap, int dashCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenLineCap197819(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int startCap, int endCap, int dashCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenStartCap(HandleRef pen, int startCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenStartCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int startCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenEndCap(HandleRef pen, int endCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenEndCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int endCap);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenStartCap(HandleRef pen, out int startCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenStartCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int startCap);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenEndCap(HandleRef pen, out int endCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenEndCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int endCap);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenDashCap197819(HandleRef pen, out int dashCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenDashCap197819(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int dashCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenDashCap197819(HandleRef pen, int dashCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenDashCap197819(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int dashCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenLineJoin(HandleRef pen, int lineJoin);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenLineJoin(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int lineJoin);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenLineJoin(HandleRef pen, out int lineJoin);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenLineJoin(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int lineJoin);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenCustomStartCap(HandleRef pen, HandleRef customCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenCustomStartCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenCustomStartCap(HandleRef pen, out IntPtr customCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenCustomStartCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out IntPtr customCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenCustomEndCap(HandleRef pen, HandleRef customCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenCustomEndCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef customCap);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenCustomEndCap(HandleRef pen, out IntPtr customCap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenCustomEndCap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out IntPtr customCap);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenMiterLimit(HandleRef pen, float miterLimit);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenMiterLimit(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float miterLimit);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenMiterLimit(HandleRef pen, float[] miterLimit);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenMiterLimit(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float[] miterLimit);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenTransform(HandleRef pen, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenTransform(HandleRef pen, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipResetPenTransform(HandleRef brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipResetPenTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush);
- [DllImport(LibraryName)]
- internal static extern int GdipMultiplyPenTransform(HandleRef brush, HandleRef matrix, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipMultiplyPenTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslatePenTransform(HandleRef brush, float dx, float dy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslatePenTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float dx, float dy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipScalePenTransform(HandleRef brush, float sx, float sy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipScalePenTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float sx, float sy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipRotatePenTransform(HandleRef brush, float angle, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipRotatePenTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float angle, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenColor(HandleRef pen, int argb);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int argb);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenColor(HandleRef pen, out int argb);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenColor(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int argb);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenBrushFill(HandleRef pen, HandleRef brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenBrushFill(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenBrushFill(HandleRef pen, out IntPtr brush);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenBrushFill(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out IntPtr brush);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenFillType(HandleRef pen, out int pentype);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenFillType(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int pentype);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenDashStyle(HandleRef pen, out int dashstyle);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenDashStyle(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int dashstyle);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenDashStyle(HandleRef pen, int dashstyle);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenDashStyle(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int dashstyle);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenDashArray(HandleRef pen, HandleRef memorydash, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenDashArray(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef memorydash, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenDashOffset(HandleRef pen, float[] dashoffset);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenDashOffset(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float[] dashoffset);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenDashOffset(HandleRef pen, float dashoffset);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenDashOffset(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float dashoffset);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenDashCount(HandleRef pen, out int dashcount);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenDashCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int dashcount);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenDashArray(HandleRef pen, float[] memorydash, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenDashArray(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float[] memorydash, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenCompoundCount(HandleRef pen, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenCompoundCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPenCompoundArray(HandleRef pen, float[] array, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPenCompoundArray(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float[] array, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPenCompoundArray(HandleRef pen, float[] array, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPenCompoundArray(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float[] array, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetWorldTransform(HandleRef graphics, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetWorldTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipResetWorldTransform(HandleRef graphics);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipResetWorldTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics);
- [DllImport(LibraryName)]
- internal static extern int GdipMultiplyWorldTransform(HandleRef graphics, HandleRef matrix, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipMultiplyWorldTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslateWorldTransform(HandleRef graphics, float dx, float dy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslateWorldTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, float dx, float dy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipScaleWorldTransform(HandleRef graphics, float sx, float sy, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipScaleWorldTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, float sx, float sy, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipRotateWorldTransform(HandleRef graphics, float angle, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipRotateWorldTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, float angle, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipGetWorldTransform(HandleRef graphics, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetWorldTransform(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipSetCompositingMode(HandleRef graphics, CompositingMode compositingMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetCompositingMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, CompositingMode compositingMode);
- [DllImport(LibraryName)]
- internal static extern int GdipSetTextRenderingHint(HandleRef graphics, TextRenderingHint textRenderingHint);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetTextRenderingHint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, TextRenderingHint textRenderingHint);
- [DllImport(LibraryName)]
- internal static extern int GdipSetTextContrast(HandleRef graphics, int textContrast);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetTextContrast(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int textContrast);
- [DllImport(LibraryName)]
- internal static extern int GdipSetInterpolationMode(HandleRef graphics, InterpolationMode interpolationMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetInterpolationMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, InterpolationMode interpolationMode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCompositingMode(HandleRef graphics, out CompositingMode compositingMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCompositingMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out CompositingMode compositingMode);
- [DllImport(LibraryName)]
- internal static extern int GdipSetRenderingOrigin(HandleRef graphics, int x, int y);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetRenderingOrigin(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int x, int y);
- [DllImport(LibraryName)]
- internal static extern int GdipGetRenderingOrigin(HandleRef graphics, out int x, out int y);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetRenderingOrigin(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int x, out int y);
- [DllImport(LibraryName)]
- internal static extern int GdipSetCompositingQuality(HandleRef graphics, CompositingQuality quality);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetCompositingQuality(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, CompositingQuality quality);
- [DllImport(LibraryName)]
- internal static extern int GdipGetCompositingQuality(HandleRef graphics, out CompositingQuality quality);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetCompositingQuality(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out CompositingQuality quality);
- [DllImport(LibraryName)]
- internal static extern int GdipSetSmoothingMode(HandleRef graphics, SmoothingMode smoothingMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetSmoothingMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, SmoothingMode smoothingMode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetSmoothingMode(HandleRef graphics, out SmoothingMode smoothingMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetSmoothingMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out SmoothingMode smoothingMode);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPixelOffsetMode(HandleRef graphics, PixelOffsetMode pixelOffsetMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPixelOffsetMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, PixelOffsetMode pixelOffsetMode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPixelOffsetMode(HandleRef graphics, out PixelOffsetMode pixelOffsetMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPixelOffsetMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out PixelOffsetMode pixelOffsetMode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetTextRenderingHint(HandleRef graphics, out TextRenderingHint textRenderingHint);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetTextRenderingHint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out TextRenderingHint textRenderingHint);
- [DllImport(LibraryName)]
- internal static extern int GdipGetTextContrast(HandleRef graphics, out int textContrast);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetTextContrast(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int textContrast);
- [DllImport(LibraryName)]
- internal static extern int GdipGetInterpolationMode(HandleRef graphics, out InterpolationMode interpolationMode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetInterpolationMode(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out InterpolationMode interpolationMode);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPageUnit(HandleRef graphics, out GraphicsUnit unit);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPageUnit(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out GraphicsUnit unit);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPageScale(HandleRef graphics, out float scale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPageScale(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out float scale);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPageUnit(HandleRef graphics, GraphicsUnit unit);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPageUnit(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, GraphicsUnit unit);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPageScale(HandleRef graphics, float scale);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPageScale(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, float scale);
- [DllImport(LibraryName)]
- internal static extern int GdipGetDpiX(HandleRef graphics, out float dpi);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetDpiX(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out float dpi);
- [DllImport(LibraryName)]
- internal static extern int GdipGetDpiY(HandleRef graphics, out float dpi);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetDpiY(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out float dpi);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateMatrix(out IntPtr matrix);
@@ -757,80 +1737,154 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateMatrix2(float m11, float m12, float m21, float m22, float dx, float dy, out IntPtr matrix);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipCreateMatrix3(ref RectangleF rect, PointF* dstplg, out IntPtr matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateMatrix3(ref RectangleF rect, PointF* dstplg, out IntPtr matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateMatrix3I(ref Rectangle rect, Point* dstplg, out IntPtr matrix);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateMatrix3I(ref Rectangle rect, Point* dstplg, out IntPtr matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneMatrix(HandleRef matrix, out IntPtr cloneMatrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, out IntPtr cloneMatrix);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteMatrix(HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipSetMatrixElements(HandleRef matrix, float m11, float m12, float m21, float m22, float dx, float dy);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetMatrixElements(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, float m11, float m12, float m21, float m22, float dx, float dy);
- [DllImport(LibraryName)]
- internal static extern int GdipMultiplyMatrix(HandleRef matrix, HandleRef matrix2, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipMultiplyMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix2, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslateMatrix(HandleRef matrix, float offsetX, float offsetY, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslateMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, float offsetX, float offsetY, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipScaleMatrix(HandleRef matrix, float scaleX, float scaleY, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipScaleMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, float scaleX, float scaleY, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipRotateMatrix(HandleRef matrix, float angle, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipRotateMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, float angle, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipShearMatrix(HandleRef matrix, float shearX, float shearY, MatrixOrder order);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipShearMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, float shearX, float shearY, MatrixOrder order);
- [DllImport(LibraryName)]
- internal static extern int GdipInvertMatrix(HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipInvertMatrix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipTransformMatrixPoints(HandleRef matrix, PointF* pts, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTransformMatrixPoints(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, PointF* pts, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipTransformMatrixPointsI(HandleRef matrix, Point* pts, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTransformMatrixPointsI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, Point* pts, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipVectorTransformMatrixPoints(HandleRef matrix, PointF* pts, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipVectorTransformMatrixPoints(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, PointF* pts, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipVectorTransformMatrixPointsI(HandleRef matrix, Point* pts, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipVectorTransformMatrixPointsI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, Point* pts, int count);
- [DllImport(LibraryName)]
- internal static extern unsafe int GdipGetMatrixElements(HandleRef matrix, float* m);
+ [GeneratedDllImport(LibraryName)]
+ internal static unsafe partial int GdipGetMatrixElements(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, float* m);
- [DllImport(LibraryName)]
- internal static extern int GdipIsMatrixInvertible(HandleRef matrix, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsMatrixInvertible(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipIsMatrixIdentity(HandleRef matrix, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsMatrixIdentity(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipIsMatrixEqual(HandleRef matrix, HandleRef matrix2, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsMatrixEqual(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix2, out int boolean);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateRegion(out IntPtr region);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName)]
- internal static extern int GdipCreateRegionRect(ref RectangleF gprectf, out IntPtr region);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateRegionRect(ref RectangleF gprectf, out IntPtr region);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateRegionRectI(ref Rectangle gprect, out IntPtr region);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateRegionRectI(ref Rectangle gprect, out IntPtr region);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateRegionPath(HandleRef path, out IntPtr region);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateRegionPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, out IntPtr region);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateRegionRgnData(byte[] rgndata, int size, out IntPtr region);
@@ -838,140 +1892,400 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateRegionHrgn(IntPtr hRgn, out IntPtr region);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneRegion(HandleRef region, out IntPtr cloneregion);
-
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteRegion(HandleRef region);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, out IntPtr cloneregion);
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillRegion(HandleRef graphics, HandleRef brush, HandleRef region);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region);
- [DllImport(LibraryName)]
- internal static extern int GdipSetInfinite(HandleRef region);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetInfinite(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region);
- [DllImport(LibraryName)]
- internal static extern int GdipSetEmpty(HandleRef region);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetEmpty(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region);
- [DllImport(LibraryName)]
- internal static extern int GdipCombineRegionRect(HandleRef region, ref RectangleF gprectf, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCombineRegionRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, ref RectangleF gprectf, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipCombineRegionRectI(HandleRef region, ref Rectangle gprect, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCombineRegionRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, ref Rectangle gprect, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipCombineRegionPath(HandleRef region, HandleRef path, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCombineRegionPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipCombineRegionRegion(HandleRef region, HandleRef region2, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCombineRegionRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region2, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslateRegion(HandleRef region, float dx, float dy);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslateRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, float dx, float dy);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslateRegionI(HandleRef region, int dx, int dy);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslateRegionI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, int dx, int dy);
- [DllImport(LibraryName)]
- internal static extern int GdipTransformRegion(HandleRef region, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTransformRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipGetRegionBounds(HandleRef region, HandleRef graphics, out RectangleF gprectf);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetRegionBounds(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out RectangleF gprectf);
- [DllImport(LibraryName)]
- internal static extern int GdipGetRegionHRgn(HandleRef region, HandleRef graphics, out IntPtr hrgn);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetRegionHRgn(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out IntPtr hrgn);
- [DllImport(LibraryName)]
- internal static extern int GdipIsEmptyRegion(HandleRef region, HandleRef graphics, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsEmptyRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipIsInfiniteRegion(HandleRef region, HandleRef graphics, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsInfiniteRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipIsEqualRegion(HandleRef region, HandleRef region2, HandleRef graphics, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsEqualRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region2,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipGetRegionDataSize(HandleRef region, out int bufferSize);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetRegionDataSize(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, out int bufferSize);
- [DllImport(LibraryName)]
- internal static extern int GdipGetRegionData(HandleRef region, byte[] regionData, int bufferSize, out int sizeFilled);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetRegionData(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, byte[] regionData, int bufferSize, out int sizeFilled);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisibleRegionPoint(HandleRef region, float X, float Y, HandleRef graphics, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisibleRegionPoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, float X, float Y,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisibleRegionPointI(HandleRef region, int X, int Y, HandleRef graphics, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisibleRegionPointI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, int X, int Y,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisibleRegionRect(HandleRef region, float X, float Y, float width, float height, HandleRef graphics, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisibleRegionRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, float X, float Y, float width, float height,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisibleRegionRectI(HandleRef region, int X, int Y, int width, int height, HandleRef graphics, out int boolean);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisibleRegionRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, int X, int Y, int width, int height,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int boolean);
- [DllImport(LibraryName)]
- internal static extern int GdipGetRegionScansCount(HandleRef region, out int count, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetRegionScansCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, out int count,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
- [DllImport(LibraryName)]
- internal static extern int GdipGetRegionScans(HandleRef region, RectangleF* rects, out int count, HandleRef matrix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetRegionScans(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, RectangleF* rects, out int count,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef matrix);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateFromHDC(IntPtr hdc, out IntPtr graphics);
- [DllImport(LibraryName)]
- internal static extern int GdipSetClipGraphics(HandleRef graphics, HandleRef srcgraphics, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetClipGraphics(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef srcgraphics, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipSetClipRect(HandleRef graphics, float x, float y, float width, float height, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetClipRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, float x, float y, float width, float height, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipSetClipRectI(HandleRef graphics, int x, int y, int width, int height, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetClipRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int x, int y, int width, int height, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipSetClipPath(HandleRef graphics, HandleRef path, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetClipPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipSetClipRegion(HandleRef graphics, HandleRef region, CombineMode mode);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetClipRegion(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region, CombineMode mode);
- [DllImport(LibraryName)]
- internal static extern int GdipResetClip(HandleRef graphics);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipResetClip(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics);
- [DllImport(LibraryName)]
- internal static extern int GdipTranslateClip(HandleRef graphics, float dx, float dy);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTranslateClip(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, float dx, float dy);
- [DllImport(LibraryName)]
- internal static extern int GdipGetClip(HandleRef graphics, HandleRef region);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetClip(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef region);
- [DllImport(LibraryName)]
- internal static extern int GdipGetClipBounds(HandleRef graphics, out RectangleF rect);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetClipBounds(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out RectangleF rect);
- [DllImport(LibraryName)]
- internal static extern int GdipIsClipEmpty(HandleRef graphics, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsClipEmpty(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipGetVisibleClipBounds(HandleRef graphics, out RectangleF rect);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetVisibleClipBounds(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out RectangleF rect);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisibleClipEmpty(HandleRef graphics, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisibleClipEmpty(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisiblePoint(HandleRef graphics, float x, float y, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisiblePoint(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, float x, float y, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisiblePointI(HandleRef graphics, int x, int y, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisiblePointI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int x, int y, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisibleRect(HandleRef graphics, float x, float y, float width, float height, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisibleRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, float x, float y, float width, float height, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipIsVisibleRectI(HandleRef graphics, int x, int y, int width, int height, out bool result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipIsVisibleRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int x, int y, int width, int height, out bool result);
- [DllImport(LibraryName)]
- internal static extern int GdipFlush(HandleRef graphics, FlushIntention intention);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipFlush(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, FlushIntention intention);
- [DllImport(LibraryName)]
- internal static extern int GdipGetDC(HandleRef graphics, out IntPtr hdc);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetDC(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out IntPtr hdc);
- [DllImport(LibraryName)]
- internal static extern int GdipSetStringFormatMeasurableCharacterRanges(HandleRef format, int rangeCount, [In] [Out] CharacterRange[] range);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetStringFormatMeasurableCharacterRanges(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, int rangeCount, CharacterRange[] range);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateStringFormat(StringFormatFlags options, int language, out IntPtr format);
@@ -982,125 +2296,281 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipStringFormatGetGenericTypographic(out IntPtr format);
- [DllImport(LibraryName)]
- internal static extern int GdipDeleteStringFormat(HandleRef format);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDeleteStringFormat(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneStringFormat(HandleRef format, out IntPtr newFormat);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneStringFormat(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out IntPtr newFormat);
- [DllImport(LibraryName)]
- internal static extern int GdipSetStringFormatFlags(HandleRef format, StringFormatFlags options);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetStringFormatFlags(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, StringFormatFlags options);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatFlags(HandleRef format, out StringFormatFlags result);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatFlags(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out StringFormatFlags result);
- [DllImport(LibraryName)]
- internal static extern int GdipSetStringFormatAlign(HandleRef format, StringAlignment align);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetStringFormatAlign(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, StringAlignment align);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatAlign(HandleRef format, out StringAlignment align);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatAlign(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out StringAlignment align);
- [DllImport(LibraryName)]
- internal static extern int GdipSetStringFormatLineAlign(HandleRef format, StringAlignment align);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetStringFormatLineAlign(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, StringAlignment align);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatLineAlign(HandleRef format, out StringAlignment align);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatLineAlign(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out StringAlignment align);
- [DllImport(LibraryName)]
- internal static extern int GdipSetStringFormatHotkeyPrefix(HandleRef format, HotkeyPrefix hotkeyPrefix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetStringFormatHotkeyPrefix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, HotkeyPrefix hotkeyPrefix);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatHotkeyPrefix(HandleRef format, out HotkeyPrefix hotkeyPrefix);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatHotkeyPrefix(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out HotkeyPrefix hotkeyPrefix);
- [DllImport(LibraryName)]
- internal static extern int GdipSetStringFormatTabStops(HandleRef format, float firstTabOffset, int count, float[] tabStops);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetStringFormatTabStops(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, float firstTabOffset, int count, float[] tabStops);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatTabStops(HandleRef format, int count, out float firstTabOffset, [In] [Out] float[] tabStops);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatTabStops(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, int count, out float firstTabOffset, float[] tabStops);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatTabStopCount(HandleRef format, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatTabStopCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatMeasurableCharacterRangeCount(HandleRef format, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatMeasurableCharacterRangeCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipSetStringFormatTrimming(HandleRef format, StringTrimming trimming);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetStringFormatTrimming(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, StringTrimming trimming);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatTrimming(HandleRef format, out StringTrimming trimming);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatTrimming(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out StringTrimming trimming);
- [DllImport(LibraryName)]
- internal static extern int GdipSetStringFormatDigitSubstitution(HandleRef format, int langID, StringDigitSubstitute sds);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetStringFormatDigitSubstitution(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, int langID, StringDigitSubstitute sds);
- [DllImport(LibraryName)]
- internal static extern int GdipGetStringFormatDigitSubstitution(HandleRef format, out int langID, out StringDigitSubstitute sds);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetStringFormatDigitSubstitution(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef format, out int langID, out StringDigitSubstitute sds);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageDimension(HandleRef image, out float width, out float height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageDimension(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out float width, out float height);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageWidth(HandleRef image, out int width);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageWidth(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out int width);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageHeight(HandleRef image, out int height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageHeight(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out int height);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageHorizontalResolution(HandleRef image, out float horzRes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageHorizontalResolution(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out float horzRes);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageVerticalResolution(HandleRef image, out float vertRes);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageVerticalResolution(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out float vertRes);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageFlags(HandleRef image, out int flags);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageFlags(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out int flags);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageRawFormat(HandleRef image, ref Guid format);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageRawFormat(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, ref Guid format);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImagePixelFormat(HandleRef image, out PixelFormat format);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImagePixelFormat(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out PixelFormat format);
- [DllImport(LibraryName)]
- internal static extern int GdipImageGetFrameCount(HandleRef image, ref Guid dimensionID, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipImageGetFrameCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, ref Guid dimensionID, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipImageSelectActiveFrame(HandleRef image, ref Guid dimensionID, int frameIndex);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipImageSelectActiveFrame(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, ref Guid dimensionID, int frameIndex);
- [DllImport(LibraryName)]
- internal static extern int GdipImageRotateFlip(HandleRef image, int rotateFlipType);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipImageRotateFlip(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, int rotateFlipType);
- [DllImport(LibraryName)]
- internal static extern int GdipGetAllPropertyItems(HandleRef image, uint totalBufferSize, uint numProperties, PropertyItemInternal* allItems);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetAllPropertyItems(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, uint totalBufferSize, uint numProperties, PropertyItemInternal* allItems);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPropertyCount(HandleRef image, out uint numOfProperty);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPropertyCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out uint numOfProperty);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPropertyIdList(HandleRef image, uint numOfProperty, int* list);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPropertyIdList(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, uint numOfProperty, int* list);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPropertyItem(HandleRef image, int propid, uint propSize, PropertyItemInternal* buffer);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPropertyItem(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, int propid, uint propSize, PropertyItemInternal* buffer);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPropertyItemSize(HandleRef image, int propid, out uint size);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPropertyItemSize(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, int propid, out uint size);
- [DllImport(LibraryName)]
- internal static extern int GdipGetPropertySize(HandleRef image, out uint totalBufferSize, out uint numProperties);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetPropertySize(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out uint totalBufferSize, out uint numProperties);
- [DllImport(LibraryName)]
- internal static extern int GdipRemovePropertyItem(HandleRef image, int propid);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipRemovePropertyItem(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, int propid);
- [DllImport(LibraryName)]
- internal static extern int GdipSetPropertyItem(HandleRef image, PropertyItemInternal* item);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSetPropertyItem(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, PropertyItemInternal* item);
- [DllImport(LibraryName)]
- internal static extern int GdipGetImageType(HandleRef image, out int type);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetImageType(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out int type);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipGetImageType(IntPtr image, out int type);
- [DllImport(LibraryName)]
- internal static extern int GdipDisposeImage(HandleRef image);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipDisposeImage(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipDisposeImage(IntPtr image);
@@ -1114,8 +2584,12 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateBitmapFromScan0(int width, int height, int stride, int format, IntPtr scan0, out IntPtr bitmap);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateBitmapFromGraphics(int width, int height, HandleRef graphics, out IntPtr bitmap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateBitmapFromGraphics(int width, int height,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out IntPtr bitmap);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateBitmapFromHBITMAP(IntPtr hbitmap, IntPtr hpalette, out IntPtr bitmap);
@@ -1126,47 +2600,100 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateBitmapFromResource(IntPtr hresource, IntPtr name, out IntPtr bitmap);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateHBITMAPFromBitmap(HandleRef nativeBitmap, out IntPtr hbitmap, int argbBackground);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateHBITMAPFromBitmap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef nativeBitmap, out IntPtr hbitmap, int argbBackground);
- [DllImport(LibraryName)]
- internal static extern int GdipCreateHICONFromBitmap(HandleRef nativeBitmap, out IntPtr hicon);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateHICONFromBitmap(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef nativeBitmap, out IntPtr hicon);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneBitmapArea(float x, float y, float width, float height, int format, HandleRef srcbitmap, out IntPtr dstbitmap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneBitmapArea(float x, float y, float width, float height, int format,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef srcbitmap, out IntPtr dstbitmap);
- [DllImport(LibraryName)]
- internal static extern int GdipCloneBitmapAreaI(int x, int y, int width, int height, int format, HandleRef srcbitmap, out IntPtr dstbitmap);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCloneBitmapAreaI(int x, int y, int width, int height, int format,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef srcbitmap, out IntPtr dstbitmap);
- [DllImport(LibraryName)]
- internal static extern int GdipBitmapLockBits(HandleRef bitmap, ref Rectangle rect, ImageLockMode flags, PixelFormat format, [In] [Out] BitmapData lockedBitmapData);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipBitmapLockBits(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap, ref Rectangle rect, ImageLockMode flags, PixelFormat format,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(BitmapData.PinningMarshaller))]
+#endif
+ BitmapData lockedBitmapData);
- [DllImport(LibraryName)]
- internal static extern int GdipBitmapUnlockBits(HandleRef bitmap, BitmapData lockedBitmapData);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipBitmapUnlockBits(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(BitmapData.PinningMarshaller))]
+#endif
+ BitmapData lockedBitmapData);
- [DllImport(LibraryName)]
- internal static extern int GdipBitmapGetPixel(HandleRef bitmap, int x, int y, out int argb);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipBitmapGetPixel(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap, int x, int y, out int argb);
- [DllImport(LibraryName)]
- internal static extern int GdipBitmapSetPixel(HandleRef bitmap, int x, int y, int argb);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipBitmapSetPixel(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap, int x, int y, int argb);
- [DllImport(LibraryName)]
- internal static extern int GdipBitmapSetResolution(HandleRef bitmap, float dpix, float dpiy);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipBitmapSetResolution(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef bitmap, float dpix, float dpiy);
- [DllImport(LibraryName)]
- internal static extern int GdipImageGetFrameDimensionsCount(HandleRef image, out int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipImageGetFrameDimensionsCount(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, out int count);
- [DllImport(LibraryName)]
- internal static extern int GdipImageGetFrameDimensionsList(HandleRef image, Guid* dimensionIDs, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipImageGetFrameDimensionsList(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, Guid* dimensionIDs, int count);
[GeneratedDllImport(LibraryName)]
internal static partial int GdipCreateMetafileFromEmf(IntPtr hEnhMetafile, bool deleteEmf, out IntPtr metafile);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support non-blittable structs.
- [DllImport(LibraryName)]
- internal static extern int GdipCreateMetafileFromWmf(IntPtr hMetafile, bool deleteWmf, WmfPlaceableFileHeader wmfplacealbeHeader, out IntPtr metafile);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipCreateMetafileFromWmf(IntPtr hMetafile, bool deleteWmf,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(WmfPlaceableFileHeader.PinningMarshaller))]
+#endif
+ WmfPlaceableFileHeader wmfplacealbeHeader, out IntPtr metafile);
[GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial int GdipCreateMetafileFromFile(string file, out IntPtr metafile);
@@ -1174,212 +2701,734 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipRecordMetafile(IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipRecordMetafileI(IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipRecordMetafileI(IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, ref RectangleF frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
[GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial int GdipRecordMetafileFileName(string fileName, IntPtr referenceHdc, EmfType emfType, IntPtr pframeRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
-#pragma warning disable DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
- // TODO: [DllImportGenerator] Switch to use GeneratedDllImport once we support blittable structs defined in other assemblies.
- [DllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
- internal static extern int GdipRecordMetafileFileNameI(string fileName, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
-#pragma warning restore DLLIMPORTGENANALYZER015 // Use 'GeneratedDllImportAttribute' instead of 'DllImportAttribute' to generate P/Invoke marshalling code at compile time
-
- [DllImport(LibraryName)]
- internal static extern int GdipPlayMetafileRecord(HandleRef metafile, EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
-
- [DllImport(LibraryName)]
- internal static extern int GdipSaveGraphics(HandleRef graphics, out int state);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawArc(HandleRef graphics, HandleRef pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawArcI(HandleRef graphics, HandleRef pen, int x, int y, int width, int height, float startAngle, float sweepAngle);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawLinesI(HandleRef graphics, HandleRef pen, Point* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawBezier(HandleRef graphics, HandleRef pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawEllipse(HandleRef graphics, HandleRef pen, float x, float y, float width, float height);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawEllipseI(HandleRef graphics, HandleRef pen, int x, int y, int width, int height);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawLine(HandleRef graphics, HandleRef pen, float x1, float y1, float x2, float y2);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawLineI(HandleRef graphics, HandleRef pen, int x1, int y1, int x2, int y2);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawLines(HandleRef graphics, HandleRef pen, PointF* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawPath(HandleRef graphics, HandleRef pen, HandleRef path);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawPie(HandleRef graphics, HandleRef pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawPieI(HandleRef graphics, HandleRef pen, int x, int y, int width, int height, float startAngle, float sweepAngle);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawPolygon(HandleRef graphics, HandleRef pen, PointF* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawPolygonI(HandleRef graphics, HandleRef pen, Point* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillEllipse(HandleRef graphics, HandleRef brush, float x, float y, float width, float height);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillEllipseI(HandleRef graphics, HandleRef brush, int x, int y, int width, int height);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillPolygon(HandleRef graphics, HandleRef brush, PointF* points, int count, FillMode brushMode);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillPolygonI(HandleRef graphics, HandleRef brush, Point* points, int count, FillMode brushMode);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillRectangle(HandleRef graphics, HandleRef brush, float x, float y, float width, float height);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillRectangleI(HandleRef graphics, HandleRef brush, int x, int y, int width, int height);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillRectangles(HandleRef graphics, HandleRef brush, RectangleF* rects, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillRectanglesI(HandleRef graphics, HandleRef brush, Rectangle* rects, int count);
-
- [DllImport(LibraryName, CharSet = CharSet.Unicode, SetLastError = true)]
- internal static extern int GdipDrawString(HandleRef graphics, string textString, int length, HandleRef font, ref RectangleF layoutRect, HandleRef stringFormat, HandleRef brush);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImageRectI(HandleRef graphics, HandleRef image, int x, int y, int width, int height);
-
- [DllImport(LibraryName)]
- internal static extern int GdipGraphicsClear(HandleRef graphics, int argb);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawClosedCurve(HandleRef graphics, HandleRef pen, PointF* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawClosedCurveI(HandleRef graphics, HandleRef pen, Point* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawClosedCurve2(HandleRef graphics, HandleRef pen, PointF* points, int count, float tension);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawClosedCurve2I(HandleRef graphics, HandleRef pen, Point* points, int count, float tension);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawCurve(HandleRef graphics, HandleRef pen, PointF* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawCurveI(HandleRef graphics, HandleRef pen, Point* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawCurve2(HandleRef graphics, HandleRef pen, PointF* points, int count, float tension);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawCurve2I(HandleRef graphics, HandleRef pen, Point* points, int count, float tension);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawCurve3(HandleRef graphics, HandleRef pen, PointF* points, int count, int offset, int numberOfSegments, float tension);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawCurve3I(HandleRef graphics, HandleRef pen, Point* points, int count, int offset, int numberOfSegments, float tension);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillClosedCurve(HandleRef graphics, HandleRef brush, PointF* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillClosedCurveI(HandleRef graphics, HandleRef brush, Point* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillClosedCurve2(HandleRef graphics, HandleRef brush, PointF* points, int count, float tension, FillMode mode);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillClosedCurve2I(HandleRef graphics, HandleRef brush, Point* points, int count, float tension, FillMode mode);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillPie(HandleRef graphics, HandleRef brush, float x, float y, float width, float height, float startAngle, float sweepAngle);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipFillPieI(HandleRef graphics, HandleRef brush, int x, int y, int width, int height, float startAngle, float sweepAngle);
-
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipMeasureString(HandleRef graphics, string textString, int length, HandleRef font, ref RectangleF layoutRect, HandleRef stringFormat, ref RectangleF boundingBox, out int codepointsFitted, out int linesFilled);
-
- [DllImport(LibraryName, CharSet = CharSet.Unicode)]
- internal static extern int GdipMeasureCharacterRanges(HandleRef graphics, string textString, int length, HandleRef font, ref RectangleF layoutRect, HandleRef stringFormat, int characterCount, [In] [Out] IntPtr[] region);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImageI(HandleRef graphics, HandleRef image, int x, int y);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImage(HandleRef graphics, HandleRef image, float x, float y);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImagePoints(HandleRef graphics, HandleRef image, PointF* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImagePointsI(HandleRef graphics, HandleRef image, Point* points, int count);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImageRectRectI(HandleRef graphics, HandleRef image, int dstx, int dsty, int dstwidth, int dstheight, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort? callback, HandleRef callbackdata);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImagePointsRect(HandleRef graphics, HandleRef image, PointF* points, int count, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort? callback, HandleRef callbackdata);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImageRectRect(HandleRef graphics, HandleRef image, float dstx, float dsty, float dstwidth, float dstheight, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort? callback, HandleRef callbackdata);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImagePointsRectI(HandleRef graphics, HandleRef image, Point* points, int count, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit, HandleRef imageAttributes, Graphics.DrawImageAbort? callback, HandleRef callbackdata);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImageRect(HandleRef graphics, HandleRef image, float x, float y, float width, float height);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImagePointRect(HandleRef graphics, HandleRef image, float x, float y, float srcx, float srcy, float srcwidth, float srcheight, int srcunit);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawImagePointRectI(HandleRef graphics, HandleRef image, int x, int y, int srcx, int srcy, int srcwidth, int srcheight, int srcunit);
-
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawRectangle(HandleRef graphics, HandleRef pen, float x, float y, float width, float height);
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
+ internal static partial int GdipRecordMetafileFileNameI(string fileName, IntPtr referenceHdc, EmfType emfType, ref Rectangle frameRect, MetafileFrameUnit frameUnit, string? description, out IntPtr metafile);
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawRectangleI(HandleRef graphics, HandleRef pen, int x, int y, int width, int height);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipPlayMetafileRecord(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef metafile, EmfPlusRecordType recordType, int flags, int dataSize, byte[] data);
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawRectangles(HandleRef graphics, HandleRef pen, RectangleF* rects, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipSaveGraphics(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, out int state);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawArc(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawArcI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int x, int y, int width, int height, float startAngle, float sweepAngle);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawLinesI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Point* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawBezier(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawEllipse(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float x, float y, float width, float height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawEllipseI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int x, int y, int width, int height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawLine(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float x1, float y1, float x2, float y2);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawLineI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int x1, int y1, int x2, int y2);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawLines(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PointF* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawPath(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef path);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawPie(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float x, float y, float width, float height, float startAngle, float sweepAngle);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawPieI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int x, int y, int width, int height, float startAngle, float sweepAngle);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawPolygon(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PointF* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawPolygonI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Point* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillEllipse(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float x, float y, float width, float height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillEllipseI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int x, int y, int width, int height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillPolygon(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, PointF* points, int count, FillMode brushMode);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillPolygonI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, Point* points, int count, FillMode brushMode);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillRectangle(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float x, float y, float width, float height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillRectangleI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int x, int y, int width, int height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillRectangles(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, RectangleF* rects, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillRectanglesI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, Rectangle* rects, int count);
+
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, SetLastError = true)]
+ internal static partial int GdipDrawString(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, string textString, int length,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, ref RectangleF layoutRect,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef stringFormat,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImageRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, int x, int y, int width, int height);
- [DllImport(LibraryName, SetLastError = true)]
- internal static extern int GdipDrawRectanglesI(HandleRef graphics, HandleRef pen, Rectangle* rects, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGraphicsClear(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int argb);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawClosedCurve(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PointF* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawClosedCurveI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Point* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawClosedCurve2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PointF* points, int count, float tension);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawClosedCurve2I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Point* points, int count, float tension);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawCurve(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PointF* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawCurveI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Point* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawCurve2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PointF* points, int count, float tension);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawCurve2I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Point* points, int count, float tension);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawCurve3(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, PointF* points, int count, int offset, int numberOfSegments, float tension);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawCurve3I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Point* points, int count, int offset, int numberOfSegments, float tension);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillClosedCurve(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, PointF* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillClosedCurveI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, Point* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillClosedCurve2(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, PointF* points, int count, float tension, FillMode mode);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillClosedCurve2I(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, Point* points, int count, float tension, FillMode mode);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillPie(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, float x, float y, float width, float height, float startAngle, float sweepAngle);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipFillPieI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef brush, int x, int y, int width, int height, float startAngle, float sweepAngle);
+
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipMeasureString(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, string textString, int length,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, ref RectangleF layoutRect,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef stringFormat, ref RectangleF boundingBox, out int codepointsFitted, out int linesFilled);
+
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode)]
+ internal static partial int GdipMeasureCharacterRanges(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, string textString, int length,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef font, ref RectangleF layoutRect,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef stringFormat, int characterCount, IntPtr[] region);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImageI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, int x, int y);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImage(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, float x, float y);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImagePoints(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, PointF* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImagePointsI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, Point* points, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImageRectRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, int dstx, int dsty, int dstwidth, int dstheight, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageAttributes, Graphics.DrawImageAbort? callback,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef callbackdata);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImagePointsRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, PointF* points, int count, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcunit,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageAttributes, Graphics.DrawImageAbort? callback,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef callbackdata);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImageRectRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, float dstx, float dsty, float dstwidth, float dstheight, float srcx, float srcy, float srcwidth, float srcheight, GraphicsUnit srcunit,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageAttributes, Graphics.DrawImageAbort? callback,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef callbackdata);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImagePointsRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, Point* points, int count, int srcx, int srcy, int srcwidth, int srcheight, GraphicsUnit srcunit,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef imageAttributes, Graphics.DrawImageAbort? callback,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef callbackdata);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImageRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, float x, float y, float width, float height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImagePointRect(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, float x, float y, float srcx, float srcy, float srcwidth, float srcheight, int srcunit);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawImagePointRectI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, int x, int y, int srcx, int srcy, int srcwidth, int srcheight, int srcunit);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawRectangle(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, float x, float y, float width, float height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawRectangleI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, int x, int y, int width, int height);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawRectangles(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, RectangleF* rects, int count);
+
+ [GeneratedDllImport(LibraryName, SetLastError = true)]
+ internal static partial int GdipDrawRectanglesI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics,
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef pen, Rectangle* rects, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipTransformPoints(HandleRef graphics, int destSpace, int srcSpace, PointF* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTransformPoints(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int destSpace, int srcSpace, PointF* points, int count);
- [DllImport(LibraryName)]
- internal static extern int GdipTransformPointsI(HandleRef graphics, int destSpace, int srcSpace, Point* points, int count);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipTransformPointsI(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef graphics, int destSpace, int srcSpace, Point* points, int count);
[GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial int GdipLoadImageFromFileICM(string filename, out IntPtr image);
@@ -1387,36 +3436,46 @@ namespace System.Drawing
[GeneratedDllImport(LibraryName, CharSet = CharSet.Unicode, ExactSpelling = true)]
internal static partial int GdipLoadImageFromFile(string filename, out IntPtr image);
- [DllImport(LibraryName)]
- internal static extern int GdipGetEncoderParameterListSize(HandleRef image, ref Guid encoder, out int size);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetEncoderParameterListSize(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, ref Guid encoder, out int size);
- [DllImport(LibraryName)]
- internal static extern int GdipGetEncoderParameterList(HandleRef image, ref Guid encoder, int size, IntPtr buffer);
+ [GeneratedDllImport(LibraryName)]
+ internal static partial int GdipGetEncoderParameterList(
+#if NET7_0_OR_GREATER
+ [MarshalUsing(typeof(HandleRefMarshaller))]
+#endif
+ HandleRef image, ref Guid encoder, int size, IntPtr buffer);
}
[StructLayout(LayoutKind.Sequential)]
- internal struct StartupInput
+ internal struct StartupInputEx
{
- public int GdiplusVersion; // Must be 1
+ public int GdiplusVersion; // Must be 1 or 2
public IntPtr DebugEventCallback;
- public bool SuppressBackgroundThread; // FALSE unless you're prepared to call
+ public Interop.BOOL SuppressBackgroundThread; // FALSE unless you're prepared to call
// the hook/unhook functions properly
- public bool SuppressExternalCodecs; // FALSE unless you want GDI+ only to use
+ public Interop.BOOL SuppressExternalCodecs; // FALSE unless you want GDI+ only to use
// its internal image codecs.
+ public int StartupParameters;
- public static StartupInput GetDefault()
+ public static StartupInputEx GetDefault()
{
OperatingSystem os = Environment.OSVersion;
- StartupInput result = default;
+ StartupInputEx result = default;
// In Windows 7 GDI+1.1 story is different as there are different binaries per GDI+ version.
bool isWindows7 = os.Platform == PlatformID.Win32NT && os.Version.Major == 6 && os.Version.Minor == 1;
result.GdiplusVersion = isWindows7 ? 1 : 2;
- result.SuppressBackgroundThread = false;
- result.SuppressExternalCodecs = false;
+ result.SuppressBackgroundThread = Interop.BOOL.FALSE;
+ result.SuppressExternalCodecs = Interop.BOOL.FALSE;
+ result.StartupParameters = 0;
return result;
}
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs
index 124ce9f3a7b..43effdee1c1 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.Windows.NoCOMWrappers.cs
@@ -27,10 +27,11 @@ namespace System.Drawing
// OLE to do it for us.
PICTDESC pictdesc = PICTDESC.CreateIconPICTDESC(Handle);
Guid g = typeof(IPicture).GUID;
- IPicture picture = OleCreatePictureIndirect(pictdesc, ref g, false);
-
- if (picture != null)
+ IntPtr iPicturePtr = OleCreatePictureIndirect(pictdesc, ref g, false);
+ if (iPicturePtr != IntPtr.Zero)
{
+ IPicture picture = (IPicture)Marshal.GetObjectForIUnknown(iPicturePtr);
+ Marshal.Release(iPicturePtr);
try
{
ArgumentNullException.ThrowIfNull(outputStream);
@@ -45,8 +46,8 @@ namespace System.Drawing
}
}
- [DllImport(Interop.Libraries.Oleaut32, PreserveSig = false)]
- internal static extern IPicture OleCreatePictureIndirect(PICTDESC pictdesc, [In]ref Guid refiid, bool fOwn);
+ [GeneratedDllImport(Interop.Libraries.Oleaut32, PreserveSig = false)]
+ internal static partial IntPtr OleCreatePictureIndirect(in PICTDESC pictdesc, in Guid refiid, bool fOwn);
[ComImport]
[Guid("7BF80980-BF32-101A-8BBB-00AA00300CAB")]
@@ -92,7 +93,7 @@ namespace System.Drawing
}
[StructLayout(LayoutKind.Sequential)]
- internal sealed class PICTDESC
+ internal struct PICTDESC
{
internal int cbSizeOfStruct;
public int picType;
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/BitmapData.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/BitmapData.cs
index 3e4243351d4..c5a728914bc 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/BitmapData.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/BitmapData.cs
@@ -1,6 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
namespace System.Drawing.Imaging
{
public partial class BitmapData
@@ -91,5 +94,22 @@ namespace System.Drawing.Imaging
get { return _reserved; }
set { _reserved = value; }
}
+
+ internal ref int GetPinnableReference() => ref _width;
+
+#if NET7_0_OR_GREATER
+ internal unsafe struct PinningMarshaller
+ {
+ private readonly BitmapData _managed;
+ public PinningMarshaller(BitmapData managed)
+ {
+ _managed = managed;
+ }
+
+ public ref int GetPinnableReference() => ref (_managed is null ? ref Unsafe.NullRef<int>() : ref _managed.GetPinnableReference());
+
+ public void* Value => Unsafe.AsPointer(ref GetPinnableReference());
+ }
+#endif
}
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMatrix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMatrix.cs
index 62c4babfeea..707ff687216 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMatrix.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/ColorMatrix.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Drawing.Imaging
@@ -391,5 +392,22 @@ namespace System.Drawing.Imaging
SetMatrix(tempMatrix);
}
}
+
+ internal ref float GetPinnableReference() => ref _matrix00;
+
+#if NET7_0_OR_GREATER
+ internal unsafe struct PinningMarshaller
+ {
+ private readonly ColorMatrix _managed;
+ public PinningMarshaller(ColorMatrix managed)
+ {
+ _managed = managed;
+ }
+
+ public ref float GetPinnableReference() => ref (_managed is null ? ref Unsafe.NullRef<float>() : ref _managed.GetPinnableReference());
+
+ public void* Value => Unsafe.AsPointer(ref GetPinnableReference());
+ }
+#endif
}
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Unix.cs
index c44caf6e03f..d0ef6065bdd 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Unix.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Unix.cs
@@ -137,5 +137,7 @@ namespace System.Drawing.Imaging
get { return wmf.version; }
set { wmf.version = value; }
}
+
+ internal WmfMetaHeader GetNativeValue() => wmf;
}
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Windows.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Windows.cs
index 8e8cc9eefb7..f1a501314d9 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Windows.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetaHeader.Windows.cs
@@ -12,21 +12,30 @@ namespace System.Drawing.Imaging
// Extreme care should be taken if changing the layout of the corresponding managaed
// structures to minimize the risk of buffer overruns. The affected managed classes
// are the following: ENHMETAHEADER, MetaHeader, MetafileHeaderWmf, MetafileHeaderEmf.
- private short _type;
- private short _headerSize;
- private short _version;
- private int _size;
- private short _noObjects;
- private int _maxRecord;
- private short _noParameters;
+ private WmfMetaHeader _data;
+
+ public MetaHeader()
+ {
+ }
+
+ internal MetaHeader(WmfMetaHeader header)
+ {
+ _data._type = header._type;
+ _data._headerSize = header._headerSize;
+ _data._version = header._version;
+ _data._size = header._size;
+ _data._noObjects = header._noObjects;
+ _data._maxRecord = header._maxRecord;
+ _data._noParameters = header._noParameters;
+ }
/// <summary>
/// Represents the type of the associated <see cref='Metafile'/>.
/// </summary>
public short Type
{
- get { return _type; }
- set { _type = value; }
+ get { return _data._type; }
+ set { _data._type = value; }
}
/// <summary>
@@ -34,8 +43,8 @@ namespace System.Drawing.Imaging
/// </summary>
public short HeaderSize
{
- get { return _headerSize; }
- set { _headerSize = value; }
+ get { return _data._headerSize; }
+ set { _data._headerSize = value; }
}
/// <summary>
@@ -43,8 +52,8 @@ namespace System.Drawing.Imaging
/// </summary>
public short Version
{
- get { return _version; }
- set { _version = value; }
+ get { return _data._version; }
+ set { _data._version = value; }
}
/// <summary>
@@ -52,26 +61,40 @@ namespace System.Drawing.Imaging
/// </summary>
public int Size
{
- get { return _size; }
- set { _size = value; }
+ get { return _data._size; }
+ set { _data._size = value; }
}
public short NoObjects
{
- get { return _noObjects; }
- set { _noObjects = value; }
+ get { return _data._noObjects; }
+ set { _data._noObjects = value; }
}
public int MaxRecord
{
- get { return _maxRecord; }
- set { _maxRecord = value; }
+ get { return _data._maxRecord; }
+ set { _data._maxRecord = value; }
}
public short NoParameters
{
- get { return _noParameters; }
- set { _noParameters = value; }
+ get { return _data._noParameters; }
+ set { _data._noParameters = value; }
}
+
+ internal WmfMetaHeader GetNativeValue() => _data;
+ }
+
+ [StructLayout(LayoutKind.Sequential, Pack = 2)]
+ internal struct WmfMetaHeader
+ {
+ internal short _type;
+ internal short _headerSize;
+ internal short _version;
+ internal int _size;
+ internal short _noObjects;
+ internal int _maxRecord;
+ internal short _noParameters;
}
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderEmf.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderEmf.cs
index eb2c7f73a95..dfce8751ec4 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderEmf.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderEmf.cs
@@ -3,8 +3,12 @@
namespace System.Drawing.Imaging
{
+ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+#if NET7_0_OR_GREATER
+ [NativeMarshalling(typeof(PinningMarshaller))]
+#endif
[StructLayout(LayoutKind.Sequential)]
internal sealed class MetafileHeaderEmf
{
@@ -22,9 +26,26 @@ namespace System.Drawing.Imaging
public int Y;
public int Width;
public int Height;
- public SafeNativeMethods.ENHMETAHEADER? EmfHeader;
+ public SafeNativeMethods.ENHMETAHEADER EmfHeader;
public int EmfPlusHeaderSize;
public int LogicalDpiX;
public int LogicalDpiY;
+
+ internal ref byte GetPinnableReference() => ref Unsafe.As<MetafileType, byte>(ref type);
+
+#if NET7_0_OR_GREATER
+ internal unsafe struct PinningMarshaller
+ {
+ private readonly MetafileHeaderEmf _managed;
+ public PinningMarshaller(MetafileHeaderEmf managed)
+ {
+ _managed = managed;
+ }
+
+ public ref byte GetPinnableReference() => ref (_managed is null ? ref Unsafe.NullRef<byte>() : ref _managed.GetPinnableReference());
+
+ public void* Value => Unsafe.AsPointer(ref GetPinnableReference());
+ }
+#endif
}
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderWmf.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderWmf.cs
index 0e95dacbc83..6825f2d007b 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderWmf.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/MetafileHeaderWmf.cs
@@ -3,6 +3,8 @@
namespace System.Drawing.Imaging
{
+ using System.Diagnostics;
+ using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 8)]
@@ -51,5 +53,100 @@ namespace System.Drawing.Imaging
public int EmfPlusHeaderSize;
public int LogicalDpiX;
public int LogicalDpiY;
+
+#if NET7_0_OR_GREATER
+ internal unsafe struct InPlaceMarshaller
+ {
+ [StructLayout(LayoutKind.Sequential, Pack = 8)]
+ internal struct Native
+ {
+ /// The ENHMETAHEADER structure is defined natively as a union with WmfHeader.
+ /// Extreme care should be taken if changing the layout of the corresponding managed
+ /// structures to minimize the risk of buffer overruns. The affected managed classes
+ /// are the following: ENHMETAHEADER, MetaHeader, MetafileHeaderWmf, MetafileHeaderEmf.
+ internal MetafileType type;
+ internal int size;
+ internal int version;
+ internal EmfPlusFlags emfPlusFlags;
+ internal float dpiX;
+ internal float dpiY;
+ internal int X;
+ internal int Y;
+ internal int Width;
+ internal int Height;
+ internal WmfMetaHeader WmfHeader;
+ internal int dummy1;
+ internal int dummy2;
+ internal int dummy3;
+ internal int dummy4;
+ internal int dummy5;
+ internal int dummy6;
+ internal int dummy7;
+ internal int dummy8;
+ internal int dummy9;
+ internal int dummy10;
+ internal int dummy11;
+ internal int dummy12;
+ internal int dummy13;
+ internal int dummy14;
+ internal int dummy15;
+ internal int dummy16;
+ internal int EmfPlusHeaderSize;
+ internal int LogicalDpiX;
+ internal int LogicalDpiY;
+ }
+
+ private MetafileHeaderWmf _managed;
+ private Native _native;
+
+ public InPlaceMarshaller(MetafileHeaderWmf managed)
+ {
+ _managed = managed;
+ Unsafe.SkipInit(out _native);
+ _native.type = managed.type;
+ _native.size = managed.size;
+ _native.version = managed.version;
+ _native.emfPlusFlags = managed.emfPlusFlags;
+ _native.dpiX = managed.dpiX;
+ _native.dpiY = managed.dpiY;
+ _native.X = managed.X;
+ _native.Y = managed.Y;
+ _native.Width = managed.Width;
+ _native.Height = managed.Height;
+ _native.WmfHeader = managed.WmfHeader.GetNativeValue();
+ _native.dummy16 = managed.dummy16;
+ _native.EmfPlusHeaderSize = managed.EmfPlusHeaderSize;
+ _native.LogicalDpiX = managed.LogicalDpiX;
+ _native.LogicalDpiY = managed.LogicalDpiY;
+ }
+
+ public Native Value
+ {
+ get => _native;
+ set => _native = value;
+ }
+
+ public MetafileHeaderWmf ToManaged()
+ {
+ Debug.Assert(_managed is not null);
+ _managed.type = _native.type;
+ _managed.size = _native.size;
+ _managed.version = _native.version;
+ _managed.emfPlusFlags = _native.emfPlusFlags;
+ _managed.dpiX = _native.dpiX;
+ _managed.dpiY = _native.dpiY;
+ _managed.X = _native.X;
+ _managed.Y = _native.Y;
+ _managed.Width = _native.Width;
+ _managed.Height = _native.Height;
+ _managed.WmfHeader = new MetaHeader(_native.WmfHeader);
+ _managed.dummy16 = _native.dummy16;
+ _managed.EmfPlusHeaderSize = _native.EmfPlusHeaderSize;
+ _managed.LogicalDpiX = _native.LogicalDpiX;
+ _managed.LogicalDpiY = _native.LogicalDpiY;
+ return _managed;
+ }
+ }
+#endif
}
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/WmfPlaceableFileHeader.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/WmfPlaceableFileHeader.cs
index b36d964ecf7..ab26edfdb1a 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/WmfPlaceableFileHeader.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Imaging/WmfPlaceableFileHeader.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Drawing.Imaging
@@ -101,5 +102,22 @@ namespace System.Drawing.Imaging
get { return _checksum; }
set { _checksum = value; }
}
+
+ internal ref int GetPinnableReference() => ref _key;
+
+#if NET7_0_OR_GREATER
+ internal unsafe struct PinningMarshaller
+ {
+ private readonly WmfPlaceableFileHeader _managed;
+ public PinningMarshaller(WmfPlaceableFileHeader managed)
+ {
+ _managed = managed;
+ }
+
+ public ref int GetPinnableReference() => ref (_managed is null ? ref Unsafe.NullRef<int>() : ref _managed.GetPinnableReference());
+
+ public void* Value => Unsafe.AsPointer(ref GetPinnableReference());
+ }
+#endif
}
}
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs
index 3a8501cd0e1..a4a73646bd5 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/LibcupsNative.cs
@@ -32,10 +32,8 @@ namespace System.Drawing.Printing
[GeneratedDllImport(LibraryName)]
internal static partial void cupsFreeDests(int num_dests, IntPtr dests);
- [DllImport(LibraryName, CharSet = CharSet.Ansi)]
-#pragma warning disable CA1838 // not hot-path enough to worry about the overheads of StringBuilder marshaling
- internal static extern IntPtr cupsTempFd([Out] StringBuilder sb, int len);
-#pragma warning restore CA1838
+ [GeneratedDllImport(LibraryName, CharSet = CharSet.Ansi)]
+ internal static partial IntPtr cupsTempFd(sbyte[] sb, int len);
[GeneratedDllImport(LibraryName)]
internal static partial IntPtr cupsGetDefault();
diff --git a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs
index 6ccb314c060..e40a4a643fc 100644
--- a/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs
+++ b/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrintingServices.Unix.cs
@@ -859,11 +859,16 @@ namespace System.Drawing.Printing
string? name;
if (!settings.PrintToFile)
{
- StringBuilder sb = new StringBuilder(1024);
- int length = sb.Capacity;
- LibcupsNative.cupsTempFd(sb, length);
- name = sb.ToString();
- tmpfile = name;
+ sbyte[] buffer = new sbyte[1024];
+ int length = buffer.Length;
+ LibcupsNative.cupsTempFd(buffer, length);
+ unsafe
+ {
+ fixed (sbyte* ptr = buffer)
+ {
+ tmpfile = name = new string(ptr);
+ }
+ }
}
else
name = settings.PrintFileName!;
diff --git a/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj b/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj
index c34b54ed173..66827e87964 100644
--- a/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj
+++ b/src/libraries/System.IO.Compression.ZipFile/src/System.IO.Compression.ZipFile.csproj
@@ -11,6 +11,8 @@
<Compile Include="System\IO\Compression\ZipFileExtensions.ZipArchive.Create.cs" />
<Compile Include="System\IO\Compression\ZipFileExtensions.ZipArchive.Extract.cs" />
<Compile Include="System\IO\Compression\ZipFileExtensions.ZipArchiveEntry.Extract.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\IO\PathInternal.CaseSensitivity.cs"
Link="Common\System\IO\PathInternal.CaseSensitivity.cs" />
</ItemGroup>
diff --git a/src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj b/src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj
index 0a6a7088ace..94aa77c9c9a 100644
--- a/src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj
+++ b/src/libraries/System.IO.Compression.ZipFile/tests/System.IO.Compression.ZipFile.Tests.csproj
@@ -19,6 +19,8 @@
<Compile Include="ZipFileExtensions.ZipArchive.Create.cs" />
<Compile Include="ZipFileExtensions.ZipArchiveEntry.Extract.cs" />
<Compile Include="ZipFileExtensions.ZipArchive.Extract.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonTestPath)System\IO\TempFile.cs"
Link="Common\System\IO\TempFile.cs" />
<Compile Include="$(CommonTestPath)System\IO\TempDirectory.cs"
diff --git a/src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Unix.cs b/src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Unix.cs
index b743ddd77ef..1e50125b13e 100644
--- a/src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Unix.cs
+++ b/src/libraries/System.IO.Compression.ZipFile/tests/ZipFile.Unix.cs
@@ -9,7 +9,7 @@ using Xunit;
namespace System.IO.Compression.Tests
{
- public class ZipFile_Unix : ZipFileTestBase
+ public partial class ZipFile_Unix : ZipFileTestBase
{
[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/60581", TestPlatforms.iOS | TestPlatforms.tvOS)]
@@ -196,7 +196,7 @@ namespace System.IO.Compression.Tests
return expectedPermissions;
}
- [DllImport("libc", SetLastError = true)]
- private static extern int mkfifo(string path, int mode);
+ [GeneratedDllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
+ private static partial int mkfifo(string path, int mode);
}
}
diff --git a/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj b/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj
index 1277500ba61..e7a90eb3a6e 100644
--- a/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj
+++ b/src/libraries/System.IO.FileSystem.AccessControl/src/System.IO.FileSystem.AccessControl.csproj
@@ -10,6 +10,8 @@
</PropertyGroup>
<!-- Source includes -->
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Errors.cs"
Link="Common\Interop\Windows\Interop.Errors.cs" />
<Compile Include="$(CommonPath)System\NotImplemented.cs"
diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
index 2ae15035b5d..7cdd5006490 100644
--- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
+++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj
@@ -8,6 +8,8 @@
<Compile Include="System\IO\DriveInfo.cs" />
<Compile Include="System\IO\DriveNotFoundException.cs" />
<Compile Include="System\IO\DriveType.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\HResults.cs"
Link="Common\System\HResults.cs" />
<Compile Include="$(CommonPath)System\IO\PathInternal.CaseSensitivity.cs"
diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
index 591fd42da88..f8a57395aa6 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
+++ b/src/libraries/System.IO.FileSystem.Watcher/src/System.IO.FileSystem.Watcher.csproj
@@ -23,6 +23,8 @@
<Compile Include="System\IO\RenamedEventHandler.cs" />
<Compile Include="System\IO\WatcherChangeTypes.cs" />
<Compile Include="System\IO\WaitForChangedResult.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\IO\PathInternal.CaseSensitivity.cs"
Link="Common\System\IO\PathInternal.CaseSensitivity.cs" />
<Compile Include="$(CommonPath)System\IO\PathInternal.cs"
diff --git a/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Directory.NotifyFilter.cs b/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Directory.NotifyFilter.cs
index 51cce8f30b2..4d6be907dbf 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Directory.NotifyFilter.cs
+++ b/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.Directory.NotifyFilter.cs
@@ -8,11 +8,10 @@ using Xunit;
namespace System.IO.Tests
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/34583", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
- public class Directory_NotifyFilter_Tests : FileSystemWatcherTest
+ public partial class Directory_NotifyFilter_Tests : FileSystemWatcherTest
{
- [DllImport("advapi32.dll", EntryPoint = "SetNamedSecurityInfoW",
- CallingConvention = CallingConvention.Winapi, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
- private static extern uint SetSecurityInfoByHandle( string name, uint objectType, uint securityInformation,
+ [GeneratedDllImport("advapi32.dll", EntryPoint = "SetNamedSecurityInfoW", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
+ private static partial uint SetSecurityInfoByHandle( string name, uint objectType, uint securityInformation,
IntPtr owner, IntPtr group, IntPtr dacl, IntPtr sacl);
private const uint ERROR_SUCCESS = 0;
diff --git a/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.File.NotifyFilter.cs b/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.File.NotifyFilter.cs
index 92bd0b62728..f1aa1775a00 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.File.NotifyFilter.cs
+++ b/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.File.NotifyFilter.cs
@@ -10,11 +10,10 @@ using Xunit;
namespace System.IO.Tests
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/34583", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
- public class File_NotifyFilter_Tests : FileSystemWatcherTest
+ public partial class File_NotifyFilter_Tests : FileSystemWatcherTest
{
- [DllImport("advapi32.dll", EntryPoint = "SetNamedSecurityInfoW",
- CallingConvention = CallingConvention.Winapi, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
- private static extern uint SetSecurityInfoByHandle(string name, uint objectType, uint securityInformation,
+ [GeneratedDllImport("advapi32.dll", EntryPoint = "SetNamedSecurityInfoW", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)]
+ private static partial uint SetSecurityInfoByHandle(string name, uint objectType, uint securityInformation,
IntPtr owner, IntPtr group, IntPtr dacl, IntPtr sacl);
private const uint ERROR_SUCCESS = 0;
diff --git a/src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj b/src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj
index 9ebfaa1af53..7bbb9eb5986 100644
--- a/src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj
+++ b/src/libraries/System.IO.FileSystem.Watcher/tests/System.IO.FileSystem.Watcher.Tests.csproj
@@ -31,6 +31,8 @@
<!-- Helpers -->
<Compile Include="Utility\TestFileSystemWatcher.cs" />
<Compile Include="Utility\FileSystemWatcherTest.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonTestPath)System\IO\TempFile.cs"
Link="Common\System\IO\TempFile.cs" />
<Compile Include="$(CommonTestPath)System\IO\TempDirectory.cs"
diff --git a/src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj b/src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj
index 449a1c3cc2b..cefda710977 100644
--- a/src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj
+++ b/src/libraries/System.IO.FileSystem/tests/DisabledFileLockingTests/System.IO.FileSystem.DisabledFileLocking.Tests.csproj
@@ -19,6 +19,8 @@
<Compile Include="..\PortedCommon\DllImports.cs" />
<Compile Include="..\PortedCommon\IOInputs.cs" />
<Compile Include="..\PortedCommon\IOServices.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonTestPath)System\IO\PathFeatures.cs" Link="Common\System\IO\PathFeatures.cs" />
<Compile Include="$(CommonTestPath)TestUtilities\System\DisableParallelization.cs" Link="Common\TestUtilities\System\DisableParallelization.cs" />
</ItemGroup>
diff --git a/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Unix.cs b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Unix.cs
index 38c1b353c92..96b7c63f80a 100644
--- a/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Unix.cs
+++ b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Unix.cs
@@ -8,10 +8,10 @@ namespace System.IO.Tests
{
public abstract partial class FileSystemTest
{
- [DllImport("libc", SetLastError = true)]
- protected static extern int geteuid();
+ [GeneratedDllImport("libc", SetLastError = true)]
+ protected static partial int geteuid();
- [DllImport("libc", SetLastError = true)]
- protected static extern int mkfifo(string path, int mode);
+ [GeneratedDllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
+ protected static partial int mkfifo(string path, int mode);
}
}
diff --git a/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj b/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj
index 87184a69f66..6285027286b 100644
--- a/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj
+++ b/src/libraries/System.IO.MemoryMappedFiles/src/System.IO.MemoryMappedFiles.csproj
@@ -19,6 +19,8 @@
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedViewAccessor.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedViewStream.cs" />
<Compile Include="System\IO\MemoryMappedFiles\MemoryMappedFileRights.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="System\IO\MemoryMappedFiles\Interop.Windows.cs" />
diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Unix.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Unix.cs
index 8024754a921..89652ef5bd7 100644
--- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Unix.cs
+++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Unix.cs
@@ -31,11 +31,11 @@ namespace System.IO.MemoryMappedFiles.Tests
return pageSize;
});
- [DllImport("libc", SetLastError = true)]
- private static extern int sysconf(int name);
+ [GeneratedDllImport("libc", SetLastError = true)]
+ private static partial int sysconf(int name);
- [DllImport("libc", SetLastError = true)]
- protected static extern int mkfifo(string path, int mode);
+ [GeneratedDllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
+ protected static partial int mkfifo(string path, int mode);
/// <summary>Asserts that the handle's inheritability matches the specified value.</summary>
protected static void AssertInheritability(SafeHandle handle, HandleInheritability inheritability)
diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Windows.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Windows.cs
index 2460c15fd59..e521424a1d5 100644
--- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Windows.cs
+++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Windows.cs
@@ -20,13 +20,13 @@ namespace System.IO.MemoryMappedFiles.Tests
return pageSize;
});
- [DllImport("kernel32.dll")]
- private static extern bool GetHandleInformation(IntPtr hObject, out uint lpdwFlags);
+ [GeneratedDllImport("kernel32.dll")]
+ private static partial bool GetHandleInformation(IntPtr hObject, out uint lpdwFlags);
private const uint HANDLE_FLAG_INHERIT = 0x00000001;
- [DllImport("kernel32.dll")]
- private static extern void GetSystemInfo(out SYSTEM_INFO input);
+ [GeneratedDllImport("kernel32.dll")]
+ private static partial void GetSystemInfo(out SYSTEM_INFO input);
[StructLayout(LayoutKind.Sequential)]
private struct SYSTEM_INFO
diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/SafeMemoryMappedViewHandleTests.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/SafeMemoryMappedViewHandleTests.cs
index 3941ab7f8ad..c91d0604383 100644
--- a/src/libraries/System.IO.MemoryMappedFiles/tests/SafeMemoryMappedViewHandleTests.cs
+++ b/src/libraries/System.IO.MemoryMappedFiles/tests/SafeMemoryMappedViewHandleTests.cs
@@ -10,7 +10,7 @@ namespace System.IO.MemoryMappedFiles.Tests
/// <summary>
/// Tests for SafeMemoryMappedViewHandle
/// </summary>
- public class SafeMemoryMappedViewHandleTests : MemoryMappedFilesTestBase
+ public partial class SafeMemoryMappedViewHandleTests : MemoryMappedFilesTestBase
{
/// <summary>
/// Tests that external code can use SafeMemoryMappedViewHandle as the result of a P/Invoke on Windows.
@@ -66,7 +66,7 @@ namespace System.IO.MemoryMappedFiles.Tests
Assert.NotNull(handle);
}
- [DllImport("libc")]
- private static unsafe extern SafeMemoryMappedViewHandle mmap(IntPtr addr, nint lengthint, int prot, int flags, int fd, nuint offset);
+ [GeneratedDllImport("libc")]
+ private static unsafe partial SafeMemoryMappedViewHandle mmap(IntPtr addr, nint lengthint, int prot, int flags, int fd, nuint offset);
}
}
diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/System.IO.MemoryMappedFiles.Tests.csproj b/src/libraries/System.IO.MemoryMappedFiles/tests/System.IO.MemoryMappedFiles.Tests.csproj
index 9d75e10c13b..92042aa78f2 100644
--- a/src/libraries/System.IO.MemoryMappedFiles/tests/System.IO.MemoryMappedFiles.Tests.csproj
+++ b/src/libraries/System.IO.MemoryMappedFiles/tests/System.IO.MemoryMappedFiles.Tests.csproj
@@ -20,6 +20,8 @@
<Compile Include="$(CommonTestPath)System\IO\TempFile.cs" Link="Common\System\IO\TempFile.cs" />
<Compile Include="SafeMemoryMappedViewHandleTests.cs" />
<Compile Include="XunitAssemblyAttributes.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.BOOL.cs" Link="ProductionCode\Common\Interop\Windows\Interop.BOOL.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs" Link="ProductionCode\Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.CreateFileMapping.cs" Link="ProductionCode\Common\Interop\Windows\Kernel32\Interop.CreateFileMapping.cs" />
@@ -30,4 +32,4 @@
<ItemGroup>
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" />
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
index 55437bf7f69..0cf60c20c9a 100644
--- a/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
+++ b/src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
@@ -21,6 +21,8 @@
<Compile Include="System\IO\Pipes\PipeState.cs" />
<Compile Include="System\IO\Pipes\PipeStream.cs" />
<Compile Include="System\IO\Pipes\PipeTransmissionMode.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\Threading\Tasks\TaskToApm.cs"
Link="Common\System\Threading\Tasks\TaskToApm.cs" />
</ItemGroup>
diff --git a/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj b/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj
index efd034b6044..6dc6c00f09d 100644
--- a/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj
+++ b/src/libraries/System.IO.Ports/src/System.IO.Ports.csproj
@@ -36,6 +36,12 @@ System.IO.Ports.SerialPort</PackageDescription>
<Compile Include="System\IO\Ports\StopBits.cs" />
</ItemGroup>
+
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0')) and '$(TargetsAnyOS)' != 'true'">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
+
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true' and '$(TargetsWindows)' == 'true'">
<Compile Include="System\IO\Ports\SerialStream.Windows.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.DCB.cs"
@@ -90,7 +96,7 @@ System.IO.Ports.SerialPort</PackageDescription>
Link="Common\Interop\Windows\Interop.SECURITY_ATTRIBUTES.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Kernel32\Interop.FileTypes.cs"
Link="Common\Interop\Windows\Interop.FileTypes.cs" />
- <Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
+ <Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
Link="Common\System\Text\ValueStringBuilder.cs" />
<Compile Include="$(CommonPath)System\IO\PathInternal.Windows.cs"
Link="Common\System\IO\PathInternal.Windows.cs" />
diff --git a/src/libraries/System.Management/src/System.Management.csproj b/src/libraries/System.Management/src/System.Management.csproj
index d79acc744ac..e64ebcf61db 100644
--- a/src/libraries/System.Management/src/System.Management.csproj
+++ b/src/libraries/System.Management/src/System.Management.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);0618</NoWarn>
diff --git a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj
index bacef00d3e5..41d016898b1 100644
--- a/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj
+++ b/src/libraries/System.Net.Http.WinHttpHandler/src/System.Net.Http.WinHttpHandler.csproj
@@ -108,6 +108,11 @@ System.Net.Http.WinHttpHandler</PackageDescription>
Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0')) and '$(TargetsWindows)' == 'true'">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
+
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Collections" />
diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj
index bf7173a54c5..0792ba26c05 100644
--- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj
+++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj
@@ -137,6 +137,8 @@
<Compile Include="System\Net\Http\Headers\ViaHeaderValue.cs" />
<Compile Include="System\Net\Http\Headers\WarningHeaderValue.cs" />
<Compile Include="System\Net\Http\SocketsHttpHandler\SocketsHttpPlaintextStreamFilterContext.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\IO\DelegatingStream.cs"
Link="Common\System\IO\DelegatingStream.cs" />
<Compile Include="$(CommonPath)System\IO\ReadOnlyMemoryStream.cs"
@@ -246,10 +248,8 @@
Link="Common\System\Net\InternalException.cs" />
<Compile Include="$(CommonPath)System\Net\DebugSafeHandle.cs"
Link="Common\System\Net\DebugSafeHandle.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleMinusOneIsInvalid.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs" />
+ <Compile Include="$(CommonPath)System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs"
+ Link="Common\System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs" />
<Compile Include="$(CommonPath)System\Text\ValueStringBuilder.cs"
Link="Common\System\Text\ValueStringBuilder.cs" />
<Compile Include="$(CommonPath)Extensions\ValueStopwatch\ValueStopwatch.cs"
diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj
index d057f21b00f..1b4a5aa3769 100644
--- a/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj
+++ b/src/libraries/System.Net.Http/tests/FunctionalTests/System.Net.Http.Functional.Tests.csproj
@@ -32,6 +32,8 @@
</ItemGroup>
<ItemGroup>
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs" Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true'"
Link="Common\Interop\Unix\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs"
@@ -221,10 +223,8 @@
<Compile Include="$(CommonPath)System\Net\ExceptionCheck.cs"
Link="Common\System\Net\ExceptionCheck.cs" />
<!-- Add NTAuthentication -->
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleMinusOneIsInvalid.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs" />
+ <Compile Include="$(CommonPath)System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs"
+ Link="Common\System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs" />
<Compile Include="$(CommonPath)System\Collections\Generic\BidirectionalDictionary.cs"
Link="Common\System\Collections\Generic\BidirectionalDictionary.cs" />
<Compile Include="$(CommonPath)System\NotImplemented.cs"
diff --git a/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj b/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj
index 801ad4c0572..f676e0381bd 100644
--- a/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj
+++ b/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj
@@ -5,6 +5,7 @@
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Android</TargetFrameworks>
<Nullable>annotations</Nullable>
+ <EnableDllImportGenerator>true</EnableDllImportGenerator>
</PropertyGroup>
<!-- Do not reference these assemblies from the TargetingPack since we are building part of the source code for tests. -->
<ItemGroup>
diff --git a/src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj b/src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj
index fa03df3ba1a..1da319175f0 100644
--- a/src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj
+++ b/src/libraries/System.Net.HttpListener/src/System.Net.HttpListener.csproj
@@ -55,6 +55,8 @@
<Compile Include="System\Net\NetEventSource.HttpListener.cs" />
<Compile Include="System\Net\WebSockets\HttpListenerWebSocketContext.cs" />
<Compile Include="System\Net\WebSockets\HttpWebSocket.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\StringExtensions.cs"
Link="Common\System\StringExtensions.cs" />
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs"
@@ -159,10 +161,8 @@
<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeLocalAllocHandle.cs"
Link="Common\Microsoft\Win32\SafeHandles\SafeLocalAllocHandle.cs" />
<!-- Add NTAuthentication -->
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleMinusOneIsInvalid.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs" />
+ <Compile Include="$(CommonPath)System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs"
+ Link="Common\System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs" />
<Compile Include="$(CommonPath)System\Collections\Generic\BidirectionalDictionary.cs"
Link="Common\System\Collections\Generic\BidirectionalDictionary.cs" />
<Compile Include="$(CommonPath)System\NotImplemented.cs"
diff --git a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs
index 2be64de238d..577afdbf025 100644
--- a/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs
+++ b/src/libraries/System.Net.HttpListener/src/System/Net/Windows/HttpListener.Windows.cs
@@ -1020,7 +1020,7 @@ namespace System.Net
{
if (userContext != null)
{
- userContext.Close();
+ userContext.Dispose();
}
}
}
diff --git a/src/libraries/System.Net.Mail/src/System.Net.Mail.csproj b/src/libraries/System.Net.Mail/src/System.Net.Mail.csproj
index e47a78d8cad..c80216d012c 100644
--- a/src/libraries/System.Net.Mail/src/System.Net.Mail.csproj
+++ b/src/libraries/System.Net.Mail/src/System.Net.Mail.csproj
@@ -66,6 +66,8 @@
<Compile Include="System\Net\Mail\SmtpFailedRecipientsException.cs" />
<Compile Include="System\Net\Mail\SmtpStatusCode.cs" />
<Compile Include="System\Net\DelegatedStream.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\Net\LazyAsyncResult.cs"
Link="Common\System\Net\LazyAsyncResult.cs" />
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs"
@@ -96,10 +98,8 @@
<Compile Include="System\Net\Mail\NetEventSource.Mail.cs" />
<Compile Include="$(CommonPath)System\Net\ContextAwareResult.cs"
Link="Common\System\Net\ContextAwareResult.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleMinusOneIsInvalid.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs" />
+ <Compile Include="$(CommonPath)System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs"
+ Link="Common\System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs" />
<Compile Include="$(CommonPath)System\Net\DebugSafeHandle.cs"
Link="Common\System\Net\DebugSafeHandle.cs" />
<Compile Include="$(CommonPath)System\Net\TlsStream.cs"
diff --git a/src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj b/src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj
index 07166801690..400d614c0df 100644
--- a/src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj
+++ b/src/libraries/System.Net.Mail/tests/Unit/System.Net.Mail.Unit.Tests.csproj
@@ -112,6 +112,8 @@
Link="ProductionCode\MailHeaderInfo.cs" />
<Compile Include="..\..\src\System\Net\BufferBuilder.cs"
Link="ProductionCode\BufferBuilder.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\Net\TlsStream.cs"
Link="Common\System\Net\TlsStream.cs" />
<Compile Include="$(CommonPath)System\Net\InternalException.cs"
@@ -124,10 +126,8 @@
Link="Common\System\Net\SecurityProtocol.cs" />
<Compile Include="$(CommonPath)System\StringExtensions.cs"
Link="Common\System\StringExtensions.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleMinusOneIsInvalid.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs" />
+ <Compile Include="$(CommonPath)System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs"
+ Link="Common\System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs" />
<Compile Include="$(CommonPath)System\Net\DebugSafeHandle.cs"
Link="Common\System\Net\DebugSafeHandle.cs" />
<Compile Include="$(CommonPath)System\Net\ExceptionCheck.cs"
diff --git a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
index 13a17550284..66bcfce21b4 100644
--- a/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
+++ b/src/libraries/System.Net.NetworkInformation/src/System.Net.NetworkInformation.csproj
@@ -44,6 +44,8 @@
<Compile Include="System\Net\NetworkInformation\UnicastIPAddressInformation.cs" />
<Compile Include="System\Net\NetworkInformation\UnicastIPAddressInformationCollection.cs" />
<Compile Include="System\Net\NetworkInformation\InternalIPAddressCollection.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\NotImplemented.cs" Link="Common\System\NotImplemented.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\HostInformation.cs" Link="Common\System\Net\NetworkInformation\HostInformation.cs" />
<Compile Include="$(CommonPath)System\Net\NetworkInformation\NetworkInformationException.cs" Link="Common\System\Net\NetworkInformation\NetworkInformationException.cs" />
diff --git a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIcmpV6Statistics.cs b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIcmpV6Statistics.cs
index 778a925afc5..4bca899f3af 100644
--- a/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIcmpV6Statistics.cs
+++ b/src/libraries/System.Net.NetworkInformation/src/System/Net/NetworkInformation/SystemIcmpV6Statistics.cs
@@ -24,7 +24,7 @@ namespace System.Net.NetworkInformation
}
// ICMP statistics for Ipv6.
- internal sealed class SystemIcmpV6Statistics : IcmpV6Statistics
+ internal sealed unsafe class SystemIcmpV6Statistics : IcmpV6Statistics
{
private readonly Interop.IpHlpApi.MibIcmpInfoEx _stats;
diff --git a/src/libraries/System.Net.Ping/src/System.Net.Ping.csproj b/src/libraries/System.Net.Ping/src/System.Net.Ping.csproj
index 63e45d7e1cb..206fe170799 100644
--- a/src/libraries/System.Net.Ping/src/System.Net.Ping.csproj
+++ b/src/libraries/System.Net.Ping/src/System.Net.Ping.csproj
@@ -16,6 +16,9 @@
<Compile Include="System\Net\NetworkInformation\PingException.cs" />
<Compile Include="System\Net\NetworkInformation\PingOptions.cs" />
<Compile Include="System\Net\NetworkInformation\PingReply.cs" />
+ <!-- Common -->
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<!-- System.Net Common -->
<Compile Include="$(CommonPath)System\Net\IPAddressParserStatics.cs"
Link="Common\System\Net\IPAddressParserStatics.cs" />
diff --git a/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj b/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj
index 52825142299..b141b5ed3aa 100644
--- a/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj
+++ b/src/libraries/System.Net.Ping/tests/FunctionalTests/System.Net.Ping.Functional.Tests.csproj
@@ -15,6 +15,9 @@
<Compile Include="PingOptionsTest.cs" />
<Compile Include="TestSettings.cs" />
<Compile Include="UnixPingUtilityTests.cs" />
+ <!-- Common -->
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<!-- System.Net Common -->
<Compile Include="$(CommonTestPath)System\Net\Configuration.cs"
Link="SocketCommon\Configuration.cs" />
diff --git a/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj b/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
index 8069716509d..31e56528809 100644
--- a/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
+++ b/src/libraries/System.Net.Quic/src/System.Net.Quic.csproj
@@ -27,6 +27,9 @@
<Compile Include="System\Net\Quic\Implementations\MsQuic\Interop\SafeMsQuicListenerHandle.cs" />
<Compile Include="System\Net\Quic\Implementations\MsQuic\Interop\SafeMsQuicRegistrationHandle.cs" />
<Compile Include="System\Net\Quic\Implementations\MsQuic\Interop\SafeMsQuicStreamHandle.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs">
+ <Link>Common\DisableRuntimeMarshalling.cs</Link>
+ </Compile>
</ItemGroup>
<!-- System.Net common -->
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
@@ -104,7 +107,7 @@
<PackageReference Include="System.Net.MsQuic.Transport"
Version="$(SystemNetMsQuicTransportVersion)"
PrivateAssets="all"
- GeneratePathProperty="true"
+ GeneratePathProperty="true"
Condition="'$(DotNetBuildFromSource)' != 'true'" />
</ItemGroup>
diff --git a/src/libraries/System.Net.Security/src/System.Net.Security.csproj b/src/libraries/System.Net.Security/src/System.Net.Security.csproj
index d665d21b9ba..a71d01bc0b7 100644
--- a/src/libraries/System.Net.Security/src/System.Net.Security.csproj
+++ b/src/libraries/System.Net.Security/src/System.Net.Security.csproj
@@ -52,6 +52,9 @@
<Compile Include="System\Security\Authentication\ExtendedProtection\PolicyEnforcement.cs" />
<Compile Include="System\Security\Authentication\ExtendedProtection\ProtectionScenario.cs" />
<Compile Include="System\Security\Authentication\ExtendedProtection\ServiceNameCollection.cs" />
+ <!-- Common sources -->
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<!-- Logging -->
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs"
Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
@@ -62,10 +65,8 @@
<!-- Debug only -->
<Compile Include="$(CommonPath)System\Net\DebugSafeHandle.cs"
Link="Common\System\Net\DebugSafeHandle.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleMinusOneIsInvalid.cs" />
- <Compile Include="$(CommonPath)System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs"
- Link="Common\System\Net\DebugCriticalHandleZeroOrMinusOneIsInvalid.cs" />
+ <Compile Include="$(CommonPath)System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs"
+ Link="Common\System\Net\DebugSafeHandleZeroOrMinusOneIsInvalid.cs" />
<!-- System.Net common -->
<Compile Include="$(CommonPath)System\Net\ArrayBuffer.cs">
<Link>Common\System\Net\ArrayBuffer.cs</Link>
diff --git a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj
index 0a2f6aac79e..a437542c5ff 100644
--- a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj
+++ b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj
@@ -44,6 +44,9 @@
<Compile Include="System\Net\Sockets\UDPClient.cs" />
<Compile Include="System\Net\Sockets\UdpReceiveResult.cs" />
<Compile Include="System\Net\Sockets\UnixDomainSocketEndPoint.cs" />
+ <!-- Common sources -->
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<!-- Logging -->
<Compile Include="$(CommonPath)System\Net\Logging\NetEventSource.Common.cs"
Link="Common\System\Net\Logging\NetEventSource.Common.cs" />
diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs
index 923277fbb82..1cd0530a9d2 100644
--- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs
+++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/DynamicWinsockMethods.cs
@@ -54,7 +54,7 @@ namespace System.Net.Sockets
_protocolType = protocolType;
}
- private static T CreateDelegate<T>([NotNull] ref T? cache, SafeSocketHandle socketHandle, string guidString) where T: Delegate
+ private static T CreateDelegate<T>(Func<IntPtr, T> functionPointerWrapper, [NotNull] ref T? cache, SafeSocketHandle socketHandle, string guidString) where T: Delegate
{
Guid guid = new Guid(guidString);
IntPtr ptr;
@@ -79,30 +79,243 @@ namespace System.Net.Sockets
throw new SocketException();
}
- Interlocked.CompareExchange(ref cache, Marshal.GetDelegateForFunctionPointer<T>(ptr), null);
+ Interlocked.CompareExchange(ref cache, functionPointerWrapper(ptr), null);
return cache;
}
- internal AcceptExDelegate GetAcceptExDelegate(SafeSocketHandle socketHandle)
- => _acceptEx ?? CreateDelegate(ref _acceptEx, socketHandle, "b5367df1cbac11cf95ca00805f48a192");
+ internal unsafe AcceptExDelegate GetAcceptExDelegate(SafeSocketHandle socketHandle)
+ => _acceptEx ?? CreateDelegate(ptr => new SocketDelegateHelper(ptr).AcceptEx, ref _acceptEx, socketHandle, "b5367df1cbac11cf95ca00805f48a192");
- internal GetAcceptExSockaddrsDelegate GetGetAcceptExSockaddrsDelegate(SafeSocketHandle socketHandle)
- => _getAcceptExSockaddrs ?? CreateDelegate(ref _getAcceptExSockaddrs, socketHandle, "b5367df2cbac11cf95ca00805f48a192");
+ internal unsafe GetAcceptExSockaddrsDelegate GetGetAcceptExSockaddrsDelegate(SafeSocketHandle socketHandle)
+ => _getAcceptExSockaddrs ?? CreateDelegate<GetAcceptExSockaddrsDelegate>(ptr => new SocketDelegateHelper(ptr).GetAcceptExSockaddrs, ref _getAcceptExSockaddrs, socketHandle, "b5367df2cbac11cf95ca00805f48a192");
- internal ConnectExDelegate GetConnectExDelegate(SafeSocketHandle socketHandle)
- => _connectEx ?? CreateDelegate(ref _connectEx, socketHandle, "25a207b9ddf346608ee976e58c74063e");
+ internal unsafe ConnectExDelegate GetConnectExDelegate(SafeSocketHandle socketHandle)
+ => _connectEx ?? CreateDelegate(ptr => new SocketDelegateHelper(ptr).ConnectEx, ref _connectEx, socketHandle, "25a207b9ddf346608ee976e58c74063e");
- internal DisconnectExDelegate GetDisconnectExDelegate(SafeSocketHandle socketHandle)
- => _disconnectEx ?? CreateDelegate(ref _disconnectEx, socketHandle, "7fda2e118630436fa031f536a6eec157");
+ internal unsafe DisconnectExDelegate GetDisconnectExDelegate(SafeSocketHandle socketHandle)
+ => _disconnectEx ?? CreateDelegate(ptr => new SocketDelegateHelper(ptr).DisconnectEx, ref _disconnectEx, socketHandle, "7fda2e118630436fa031f536a6eec157");
- internal WSARecvMsgDelegate GetWSARecvMsgDelegate(SafeSocketHandle socketHandle)
- => _recvMsg ?? CreateDelegate(ref _recvMsg, socketHandle, "f689d7c86f1f436b8a53e54fe351c322");
+ internal unsafe WSARecvMsgDelegate GetWSARecvMsgDelegate(SafeSocketHandle socketHandle)
+ => _recvMsg ?? CreateDelegate(ptr => new SocketDelegateHelper(ptr).WSARecvMsg, ref _recvMsg, socketHandle, "f689d7c86f1f436b8a53e54fe351c322");
- internal TransmitPacketsDelegate GetTransmitPacketsDelegate(SafeSocketHandle socketHandle)
- => _transmitPackets ?? CreateDelegate(ref _transmitPackets, socketHandle, "d9689da01f9011d3997100c04f68c876");
+ internal unsafe TransmitPacketsDelegate GetTransmitPacketsDelegate(SafeSocketHandle socketHandle)
+ => _transmitPackets ?? CreateDelegate(ptr => new SocketDelegateHelper(ptr).TransmitPackets, ref _transmitPackets, socketHandle, "d9689da01f9011d3997100c04f68c876");
+
+ /// <summary>
+ /// The SocketDelegateHelper implements manual marshalling wrappers for the various delegates used for the dynamic Winsock methods.
+ /// These wrappers were generated with DllImportGenerator and then manually converted to use function pointers as the target instead of a P/Invoke.
+ /// </summary>
+ private struct SocketDelegateHelper
+ {
+ private readonly IntPtr _target;
+
+ public SocketDelegateHelper(IntPtr target)
+ {
+ _target = target;
+ }
+
+ internal unsafe bool AcceptEx(SafeSocketHandle listenSocketHandle, SafeSocketHandle acceptSocketHandle, IntPtr buffer, int len, int localAddressLength, int remoteAddressLength, out int bytesReceived, NativeOverlapped* overlapped)
+ {
+ IntPtr __listenSocketHandle_gen_native = default;
+ IntPtr __acceptSocketHandle_gen_native = default;
+ bytesReceived = default;
+ bool __retVal;
+ int __retVal_gen_native = default;
+ //
+ // Setup
+ //
+ bool listenSocketHandle__addRefd = false;
+ bool acceptSocketHandle__addRefd = false;
+ try
+ {
+ //
+ // Marshal
+ //
+ listenSocketHandle.DangerousAddRef(ref listenSocketHandle__addRefd);
+ __listenSocketHandle_gen_native = listenSocketHandle.DangerousGetHandle();
+ acceptSocketHandle.DangerousAddRef(ref acceptSocketHandle__addRefd);
+ __acceptSocketHandle_gen_native = acceptSocketHandle.DangerousGetHandle();
+ fixed (int* __bytesReceived_gen_native = &bytesReceived)
+ {
+ __retVal_gen_native = ((delegate* unmanaged<IntPtr, IntPtr, IntPtr, int, int, int, int*, NativeOverlapped*, int>)_target)(__listenSocketHandle_gen_native, __acceptSocketHandle_gen_native, buffer, len, localAddressLength, remoteAddressLength, __bytesReceived_gen_native, overlapped);
+ }
+ Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
+ //
+ // Unmarshal
+ //
+ __retVal = __retVal_gen_native != 0;
+ }
+ finally
+ {
+ //
+ // Cleanup
+ //
+ if (listenSocketHandle__addRefd)
+ listenSocketHandle.DangerousRelease();
+ if (acceptSocketHandle__addRefd)
+ acceptSocketHandle.DangerousRelease();
+ }
+
+ return __retVal;
+ }
+ internal unsafe void GetAcceptExSockaddrs(IntPtr buffer, int receiveDataLength, int localAddressLength, int remoteAddressLength, out IntPtr localSocketAddress, out int localSocketAddressLength, out IntPtr remoteSocketAddress, out int remoteSocketAddressLength)
+ {
+ localSocketAddress = default;
+ localSocketAddressLength = default;
+ remoteSocketAddress = default;
+ remoteSocketAddressLength = default;
+ fixed (IntPtr* __localSocketAddress_gen_native = &localSocketAddress)
+ fixed (int* __localSocketAddressLength_gen_native = &localSocketAddressLength)
+ fixed (IntPtr* __remoteSocketAddress_gen_native = &remoteSocketAddress)
+ fixed (int* __remoteSocketAddressLength_gen_native = &remoteSocketAddressLength)
+ {
+ ((delegate* unmanaged<IntPtr, int, int, int, IntPtr*, int*, IntPtr*, int*, void>)_target)(buffer, receiveDataLength, localAddressLength, remoteAddressLength, __localSocketAddress_gen_native, __localSocketAddressLength_gen_native, __remoteSocketAddress_gen_native, __remoteSocketAddressLength_gen_native);
+ }
+ Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
+
+ }
+ internal unsafe bool ConnectEx(SafeSocketHandle socketHandle, IntPtr socketAddress, int socketAddressSize, IntPtr buffer, int dataLength, out int bytesSent, NativeOverlapped* overlapped)
+ {
+ IntPtr __socketHandle_gen_native = default;
+ bytesSent = default;
+ bool __retVal;
+ int __retVal_gen_native = default;
+ //
+ // Setup
+ //
+ bool socketHandle__addRefd = false;
+ try
+ {
+ //
+ // Marshal
+ //
+ socketHandle.DangerousAddRef(ref socketHandle__addRefd);
+ __socketHandle_gen_native = socketHandle.DangerousGetHandle();
+ fixed (int* __bytesSent_gen_native = &bytesSent)
+ {
+ __retVal_gen_native = ((delegate* unmanaged<IntPtr, IntPtr, int, IntPtr, int, int*, NativeOverlapped*, int>)_target)(__socketHandle_gen_native, socketAddress, socketAddressSize, buffer, dataLength, __bytesSent_gen_native, overlapped);
+ }
+ Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
+ //
+ // Unmarshal
+ //
+ __retVal = __retVal_gen_native != 0;
+ }
+ finally
+ {
+ //
+ // Cleanup
+ //
+ if (socketHandle__addRefd)
+ socketHandle.DangerousRelease();
+ }
+
+ return __retVal;
+ }
+ internal unsafe bool DisconnectEx(SafeSocketHandle socketHandle, NativeOverlapped* overlapped, int flags, int reserved)
+ {
+ IntPtr __socketHandle_gen_native;
+ bool __retVal;
+ int __retVal_gen_native;
+ //
+ // Setup
+ //
+ bool socketHandle__addRefd = false;
+ try
+ {
+ //
+ // Marshal
+ //
+ socketHandle.DangerousAddRef(ref socketHandle__addRefd);
+ __socketHandle_gen_native = socketHandle.DangerousGetHandle();
+ __retVal_gen_native = ((delegate* unmanaged<IntPtr, NativeOverlapped*, int, int, int>)_target)(__socketHandle_gen_native, overlapped, flags, reserved);
+ Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
+ //
+ // Unmarshal
+ //
+ __retVal = __retVal_gen_native != 0;
+ }
+ finally
+ {
+ //
+ // Cleanup
+ //
+ if (socketHandle__addRefd)
+ socketHandle.DangerousRelease();
+ }
+
+ return __retVal;
+ }
+ internal unsafe SocketError WSARecvMsg(SafeSocketHandle socketHandle, IntPtr msg, out int bytesTransferred, NativeOverlapped* overlapped, IntPtr completionRoutine)
+ {
+ IntPtr __socketHandle_gen_native = default;
+ bytesTransferred = default;
+ SocketError __retVal;
+ //
+ // Setup
+ //
+ bool socketHandle__addRefd = false;
+ try
+ {
+ //
+ // Marshal
+ //
+ socketHandle.DangerousAddRef(ref socketHandle__addRefd);
+ __socketHandle_gen_native = socketHandle.DangerousGetHandle();
+ fixed (int* __bytesTransferred_gen_native = &bytesTransferred)
+ {
+ __retVal = ((delegate* unmanaged<IntPtr, IntPtr, int *, NativeOverlapped*, IntPtr, SocketError>)_target)(__socketHandle_gen_native, msg, __bytesTransferred_gen_native, overlapped, completionRoutine);
+ }
+ Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
+ }
+ finally
+ {
+ //
+ // Cleanup
+ //
+ if (socketHandle__addRefd)
+ socketHandle.DangerousRelease();
+ }
+
+ return __retVal;
+ }
+ internal unsafe bool TransmitPackets(SafeSocketHandle socketHandle, IntPtr packetArray, int elementCount, int sendSize, NativeOverlapped* overlapped, TransmitFileOptions flags)
+ {
+ IntPtr __socketHandle_gen_native;
+ bool __retVal;
+ int __retVal_gen_native;
+ //
+ // Setup
+ //
+ bool socketHandle__addRefd = false;
+ try
+ {
+ //
+ // Marshal
+ //
+ socketHandle.DangerousAddRef(ref socketHandle__addRefd);
+ __socketHandle_gen_native = socketHandle.DangerousGetHandle();
+ __retVal_gen_native = ((delegate* unmanaged<IntPtr, IntPtr, int, int, NativeOverlapped*, TransmitFileOptions, int>)_target)(__socketHandle_gen_native, packetArray, elementCount, sendSize, overlapped, flags);
+ Marshal.SetLastPInvokeError(Marshal.GetLastSystemError());
+ //
+ // Unmarshal
+ //
+ __retVal = __retVal_gen_native != 0;
+ }
+ finally
+ {
+ //
+ // Cleanup
+ //
+ if (socketHandle__addRefd)
+ socketHandle.DangerousRelease();
+ }
+
+ return __retVal;
+ }
+ }
}
- [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal unsafe delegate bool AcceptExDelegate(
SafeSocketHandle listenSocketHandle,
SafeSocketHandle acceptSocketHandle,
@@ -113,7 +326,6 @@ namespace System.Net.Sockets
out int bytesReceived,
NativeOverlapped* overlapped);
- [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal delegate void GetAcceptExSockaddrsDelegate(
IntPtr buffer,
int receiveDataLength,
@@ -124,8 +336,6 @@ namespace System.Net.Sockets
out IntPtr remoteSocketAddress,
out int remoteSocketAddressLength);
-
- [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal unsafe delegate bool ConnectExDelegate(
SafeSocketHandle socketHandle,
IntPtr socketAddress,
@@ -135,14 +345,12 @@ namespace System.Net.Sockets
out int bytesSent,
NativeOverlapped* overlapped);
- [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal unsafe delegate bool DisconnectExDelegate(
SafeSocketHandle socketHandle,
NativeOverlapped* overlapped,
int flags,
int reserved);
- [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal unsafe delegate SocketError WSARecvMsgDelegate(
SafeSocketHandle socketHandle,
IntPtr msg,
@@ -150,7 +358,6 @@ namespace System.Net.Sockets
NativeOverlapped* overlapped,
IntPtr completionRoutine);
- [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal unsafe delegate bool TransmitPacketsDelegate(
SafeSocketHandle socketHandle,
IntPtr packetArray,
diff --git a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs
index 1722de1aaab..05ec85840fd 100644
--- a/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs
+++ b/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketPal.Windows.cs
@@ -667,7 +667,7 @@ namespace System.Net.Sockets
handle,
SocketOptionLevel.IPv6,
optionName,
- ref ipmr,
+ ipmr,
Interop.Winsock.IPv6MulticastRequest.Size);
return errorCode == SocketError.SocketError ? GetLastSocketError() : SocketError.Success;
}
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 321e2c0477e..857caebab61 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -1202,6 +1202,9 @@
<Compile Include="$(CommonPath)Interop\Windows\Normaliz\Interop.Normalization.cs">
<Link>Common\Interop\Windows\Normaliz\Interop.Normalization.cs</Link>
</Compile>
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs">
+ <Link>Common\DisableRuntimeMarshalling.cs</Link>
+ </Compile>
<Compile Include="$(CommonPath)SkipLocalsInit.cs">
<Link>Common\SkipLocalsInit.cs</Link>
</Compile>
@@ -2372,4 +2375,4 @@
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryNegationOperators.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\IUnaryPlusOperators.cs" />
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs
index ce477e02c9e..ee456befca9 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs
@@ -135,9 +135,9 @@ namespace System.Diagnostics.Tracing
/// reason the ETW Register call failed a NotSupported exception will be thrown.
/// </summary>
// <SecurityKernel Critical="True" Ring="0">
- // <CallsSuppressUnmanagedCode Name="Interop.Advapi32.EventRegister(System.Guid&,Microsoft.Win32.Interop.Advapi32+EtwEnableCallback,System.Void*,System.Int64&):System.UInt32" />
+ // <CallsSuppressUnmanagedCode Name="Interop.Advapi32.EventRegister(System.Guid*,Microsoft.Win32.Interop.Advapi32+EtwEnableCallback,System.Void*,System.Int64&):System.UInt32" />
// <SatisfiesLinkDemand Name="Win32Exception..ctor(System.Int32)" />
- // <ReferencesCritical Name="Method: EtwEnableCallBack(Guid&, Int32, Byte, Int64, Int64, Void*, Void*):Void" Ring="1" />
+ // <ReferencesCritical Name="Method: EtwEnableCallBack(Guid*, Int32, Byte, Int64, Int64, Void*, Void*):Void" Ring="1" />
// </SecurityKernel>
internal unsafe void Register(EventSource eventSource)
{
@@ -234,7 +234,7 @@ namespace System.Diagnostics.Tracing
// <UsesUnsafeCode Name="Parameter callbackContext of type: Void*" />
// </SecurityKernel>
private unsafe void EtwEnableCallBack(
- in System.Guid sourceId,
+ System.Guid* sourceId,
int controlCode,
byte setLevel,
long anyKeyword,
diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
index 1ed1959ebd1..b15601da421 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/Loader/AssemblyDependencyResolver.cs
@@ -43,7 +43,7 @@ namespace System.Runtime.Loader
{
// Setup error writer for this thread. This makes the hostpolicy redirect all error output
// to the writer specified. Have to store the previous writer to set it back once this is done.
- var errorWriter = new Interop.HostPolicy.corehost_error_writer_fn(message => errorMessage.AppendLine(message));
+ var errorWriter = new Interop.HostPolicy.corehost_error_writer_fn(message => errorMessage.AppendLine(Marshal.PtrToStringAuto(message)));
IntPtr errorWriterPtr = Marshal.GetFunctionPointerForDelegate(errorWriter);
IntPtr previousErrorWriterPtr = Interop.HostPolicy.corehost_set_error_writer(errorWriterPtr);
@@ -56,9 +56,9 @@ namespace System.Runtime.Loader
componentAssemblyPath,
(assemblyPaths, nativeSearchPaths, resourceSearchPaths) =>
{
- assemblyPathsList = assemblyPaths;
- nativeSearchPathsList = nativeSearchPaths;
- resourceSearchPathsList = resourceSearchPaths;
+ assemblyPathsList = Marshal.PtrToStringAuto(assemblyPaths);
+ nativeSearchPathsList = Marshal.PtrToStringAuto(nativeSearchPaths);
+ resourceSearchPathsList = Marshal.PtrToStringAuto(resourceSearchPaths);
});
}
finally
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs
index 9a3c33326d4..00abe866653 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Analyzers/ManualTypeMarshallingAnalyzer.cs
@@ -206,14 +206,12 @@ namespace Microsoft.Interop.Analyzers
private void PrepareForAnalysis(CompilationStartAnalysisContext context)
{
INamedTypeSymbol? generatedMarshallingAttribute = context.Compilation.GetTypeByMetadataName(TypeNames.GeneratedMarshallingAttribute);
- INamedTypeSymbol? blittableTypeAttribute = context.Compilation.GetTypeByMetadataName(TypeNames.BlittableTypeAttribute);
INamedTypeSymbol? nativeMarshallingAttribute = context.Compilation.GetTypeByMetadataName(TypeNames.NativeMarshallingAttribute);
INamedTypeSymbol? marshalUsingAttribute = context.Compilation.GetTypeByMetadataName(TypeNames.MarshalUsingAttribute);
INamedTypeSymbol? genericContiguousCollectionMarshallerAttribute = context.Compilation.GetTypeByMetadataName(TypeNames.GenericContiguousCollectionMarshallerAttribute);
INamedTypeSymbol? spanOfByte = context.Compilation.GetTypeByMetadataName(TypeNames.System_Span_Metadata)!.Construct(context.Compilation.GetSpecialType(SpecialType.System_Byte));
if (generatedMarshallingAttribute is not null
- && blittableTypeAttribute is not null
&& nativeMarshallingAttribute is not null
&& marshalUsingAttribute is not null
&& genericContiguousCollectionMarshallerAttribute is not null
@@ -221,7 +219,6 @@ namespace Microsoft.Interop.Analyzers
{
var perCompilationAnalyzer = new PerCompilationAnalyzer(
generatedMarshallingAttribute,
- blittableTypeAttribute,
nativeMarshallingAttribute,
marshalUsingAttribute,
genericContiguousCollectionMarshallerAttribute,
@@ -236,7 +233,6 @@ namespace Microsoft.Interop.Analyzers
private class PerCompilationAnalyzer
{
private readonly INamedTypeSymbol _generatedMarshallingAttribute;
- private readonly INamedTypeSymbol _blittableTypeAttribute;
private readonly INamedTypeSymbol _nativeMarshallingAttribute;
private readonly INamedTypeSymbol _marshalUsingAttribute;
private readonly INamedTypeSymbol _genericContiguousCollectionMarshallerAttribute;
@@ -244,7 +240,6 @@ namespace Microsoft.Interop.Analyzers
private readonly INamedTypeSymbol _structLayoutAttribute;
public PerCompilationAnalyzer(INamedTypeSymbol generatedMarshallingAttribute,
- INamedTypeSymbol blittableTypeAttribute,
INamedTypeSymbol nativeMarshallingAttribute,
INamedTypeSymbol marshalUsingAttribute,
INamedTypeSymbol genericContiguousCollectionMarshallerAttribute,
@@ -252,7 +247,6 @@ namespace Microsoft.Interop.Analyzers
INamedTypeSymbol structLayoutAttribute)
{
_generatedMarshallingAttribute = generatedMarshallingAttribute;
- _blittableTypeAttribute = blittableTypeAttribute;
_nativeMarshallingAttribute = nativeMarshallingAttribute;
_marshalUsingAttribute = marshalUsingAttribute;
_genericContiguousCollectionMarshallerAttribute = genericContiguousCollectionMarshallerAttribute;
@@ -264,8 +258,6 @@ namespace Microsoft.Interop.Analyzers
{
INamedTypeSymbol type = (INamedTypeSymbol)context.Symbol;
- AttributeData? blittableTypeAttributeData = null;
- AttributeData? nativeMarshallingAttributeData = null;
foreach (AttributeData attr in type.GetAttributes())
{
if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, _generatedMarshallingAttribute))
@@ -274,45 +266,12 @@ namespace Microsoft.Interop.Analyzers
// we let the source generator handle error checking.
return;
}
- else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, _blittableTypeAttribute))
- {
- blittableTypeAttributeData = attr;
- }
else if (SymbolEqualityComparer.Default.Equals(attr.AttributeClass, _nativeMarshallingAttribute))
{
- nativeMarshallingAttributeData = attr;
+ AnalyzeNativeMarshalerType(context, type, attr, isNativeMarshallingAttribute: true);
+ return;
}
}
-
- if (HasMultipleMarshallingAttributes(blittableTypeAttributeData, nativeMarshallingAttributeData))
- {
- context.ReportDiagnostic(
- blittableTypeAttributeData!.CreateDiagnostic(
- CannotHaveMultipleMarshallingAttributesRule,
- type.ToDisplayString()));
- }
- else if (blittableTypeAttributeData is not null && (!type.HasOnlyBlittableFields() || type.IsAutoLayout(_structLayoutAttribute)))
- {
- context.ReportDiagnostic(
- blittableTypeAttributeData.CreateDiagnostic(
- BlittableTypeMustBeBlittableRule,
- type.ToDisplayString()));
- }
- else if (nativeMarshallingAttributeData is not null)
- {
- AnalyzeNativeMarshalerType(context, type, nativeMarshallingAttributeData, isNativeMarshallingAttribute: true);
- }
- }
-
- private bool HasMultipleMarshallingAttributes(AttributeData? blittableTypeAttributeData, AttributeData? nativeMarshallingAttributeData)
- {
- return (blittableTypeAttributeData, nativeMarshallingAttributeData) switch
- {
- (null, null) => false,
- (not null, null) => false,
- (null, not null) => false,
- _ => true
- };
}
public void AnalyzeElement(SymbolAnalysisContext context)
@@ -545,7 +504,7 @@ namespace Microsoft.Interop.Analyzers
// This ensures that marshalling via pinning the managed value and marshalling via the default marshaller will have the same ABI.
if (!valuePropertyIsRefReturn // Ref returns are already reported above as invalid, so don't issue another warning here about them
&& nativeType is not (
- IPointerTypeSymbol _ or
+ IPointerTypeSymbol or
{ SpecialType: SpecialType.System_IntPtr } or
{ SpecialType: SpecialType.System_UIntPtr }))
{
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs
index 2987b174a56..35b40c41967 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportGenerator.cs
@@ -464,7 +464,10 @@ namespace Microsoft.Interop
dllImportStub.Environment,
dllImportStub.StubContext.ElementTypeInformation,
dllImportStub.DllImportData.SetLastError && !options.GenerateForwarders,
- (elementInfo, ex) => diagnostics.ReportMarshallingNotSupported(originalSyntax, elementInfo, ex.NotSupportedDetails),
+ (elementInfo, ex) =>
+ {
+ diagnostics.ReportMarshallingNotSupported(originalSyntax, elementInfo, ex.NotSupportedDetails);
+ },
dllImportStub.StubContext.GeneratorFactory);
// Check if the generator should produce a forwarder stub - regular DllImport.
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs
index 28136ba47c7..69da1c04c06 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/DllImportStubContext.cs
@@ -199,11 +199,27 @@ namespace Microsoft.Interop
}
else
{
- generatorFactory = new DefaultMarshallingGeneratorFactory(options);
- IMarshallingGeneratorFactory elementFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, options);
+ if (env.TargetFramework != TargetFramework.Net || env.TargetFrameworkVersion.Major < 7)
+ {
+ // If we're using our downstream support, fall back to the Forwarder marshaller when the TypePositionInfo is unhandled.
+ generatorFactory = new ForwarderMarshallingGeneratorFactory();
+ }
+ else
+ {
+ // If we're in a "supported" scenario, then emit a diagnostic as our final fallback.
+ generatorFactory = new UnsupportedMarshallingFactory();
+ }
+
+ generatorFactory = new MarshalAsMarshallingGeneratorFactory(options, generatorFactory);
+
+ IAssemblySymbol coreLibraryAssembly = env.Compilation.GetSpecialType(SpecialType.System_Object).ContainingAssembly;
+ ITypeSymbol disabledRuntimeMarshallingAttributeType = coreLibraryAssembly.GetTypeByMetadataName(TypeNames.System_Runtime_CompilerServices_DisableRuntimeMarshallingAttribute);
+ bool runtimeMarshallingDisabled = env.Compilation.Assembly.GetAttributes().Any(attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, disabledRuntimeMarshallingAttributeType));
+
+ IMarshallingGeneratorFactory elementFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, new AttributedMarshallingModelOptions(options, runtimeMarshallingDisabled));
// We don't need to include the later generator factories for collection elements
// as the later generator factories only apply to parameters or to the synthetic return value for PreserveSig support.
- generatorFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, elementFactory, options);
+ generatorFactory = new AttributedMarshallingModelGeneratorFactory(generatorFactory, elementFactory, new AttributedMarshallingModelOptions(options, runtimeMarshallingDisabled));
if (!dllImportData.PreserveSig)
{
// Create type info for native out param
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs
index 744f1b611be..a8c33b93818 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs
@@ -511,6 +511,15 @@ namespace Microsoft.Interop {
}
/// <summary>
+ /// Looks up a localized string similar to .
+ /// </summary>
+ internal static string RuntimeMarshallingMustBeDisabled {
+ get {
+ return ResourceManager.GetString("RuntimeMarshallingMustBeDisabled", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to An abstract type derived from &apos;SafeHandle&apos; cannot be marshalled by reference. The provided type must be concrete..
/// </summary>
internal static string SafeHandleByRefMustBeConcrete {
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx
index c3f3d9694fc..8a9d0f5b7e1 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx
@@ -268,6 +268,9 @@
<data name="RefValuePropertyUnsupportedMessage" xml:space="preserve">
<value>The 'Value' property on the native type '{0}' must not be a 'ref' or 'readonly ref' property.</value>
</data>
+ <data name="RuntimeMarshallingMustBeDisabled" xml:space="preserve">
+ <value />
+ </data>
<data name="SafeHandleByRefMustBeConcrete" xml:space="preserve">
<value>An abstract type derived from 'SafeHandle' cannot be marshalled by reference. The provided type must be concrete.</value>
</data>
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs
index cb3f7dbe62d..f0cd91ae0a0 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/InteropGenerationOptions.cs
@@ -7,5 +7,5 @@ using System.Text;
namespace Microsoft.Interop
{
- public record InteropGenerationOptions(bool UseMarshalType, bool UseInternalUnsafeType);
+ public readonly record struct InteropGenerationOptions(bool UseMarshalType, bool UseInternalUnsafeType);
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs
index 844899ef7f2..3484e427130 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/AttributedMarshallingModelGeneratorFactory.cs
@@ -9,6 +9,8 @@ using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
namespace Microsoft.Interop
{
+ public readonly record struct AttributedMarshallingModelOptions(InteropGenerationOptions InteropOptions, bool RuntimeMarshallingDisabled);
+
public class AttributedMarshallingModelGeneratorFactory : IMarshallingGeneratorFactory
{
private static readonly BlittableMarshaller s_blittable = new BlittableMarshaller();
@@ -19,7 +21,7 @@ namespace Microsoft.Interop
public AttributedMarshallingModelGeneratorFactory(
IMarshallingGeneratorFactory innerMarshallingGenerator,
- InteropGenerationOptions options)
+ AttributedMarshallingModelOptions options)
{
Options = options;
_innerMarshallingGenerator = innerMarshallingGenerator;
@@ -30,7 +32,7 @@ namespace Microsoft.Interop
public AttributedMarshallingModelGeneratorFactory(
IMarshallingGeneratorFactory innerMarshallingGenerator,
IMarshallingGeneratorFactory elementMarshallingGenerator,
- InteropGenerationOptions options)
+ AttributedMarshallingModelOptions options)
{
Options = options;
_innerMarshallingGenerator = innerMarshallingGenerator;
@@ -38,14 +40,21 @@ namespace Microsoft.Interop
_elementMarshallingGenerator = elementMarshallingGenerator;
}
- public InteropGenerationOptions Options { get; }
+ private AttributedMarshallingModelOptions Options { get; }
public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext context)
{
return info.MarshallingAttributeInfo switch
{
- NativeMarshallingAttributeInfo marshalInfo => CreateCustomNativeTypeMarshaller(info, context, marshalInfo),
- BlittableTypeAttributeInfo => s_blittable,
+ NativeMarshallingAttributeInfo marshalInfo when Options.RuntimeMarshallingDisabled => CreateCustomNativeTypeMarshaller(info, context, marshalInfo),
+ NativeMarshallingAttributeInfo { ValuePropertyType: SpecialTypeInfo specialType } marshalInfo when specialType.SpecialType.IsAlwaysBlittable() => CreateCustomNativeTypeMarshaller(info, context, marshalInfo),
+ NativeMarshallingAttributeInfo { ValuePropertyType: PointerTypeInfo } marshalInfo => CreateCustomNativeTypeMarshaller(info, context, marshalInfo),
+ UnmanagedBlittableMarshallingInfo when Options.RuntimeMarshallingDisabled => s_blittable,
+ UnmanagedBlittableMarshallingInfo or NativeMarshallingAttributeInfo when !Options.RuntimeMarshallingDisabled =>
+ throw new MarshallingNotSupportedException(info, context)
+ {
+ NotSupportedDetails = Resources.RuntimeMarshallingMustBeDisabled
+ },
GeneratedNativeMarshallingAttributeInfo => s_forwarder,
MissingSupportMarshallingInfo => s_forwarder,
_ => _innerMarshallingGenerator.Create(info, context)
@@ -286,7 +295,7 @@ namespace Microsoft.Interop
new CustomNativeTypeMarshallingGenerator(marshallingStrategy, enableByValueContentsMarshalling: true),
elementType,
isBlittable,
- Options);
+ Options.InteropOptions);
}
IMarshallingGenerator marshallingGenerator = new CustomNativeTypeMarshallingGenerator(marshallingStrategy, enableByValueContentsMarshalling: false);
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs
index 1d36a8789c9..169911c3c92 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ByValueContentsMarshalKindValidator.cs
@@ -26,6 +26,12 @@ namespace Microsoft.Interop
private static IMarshallingGenerator ValidateByValueMarshalKind(TypePositionInfo info, StubCodeContext context, IMarshallingGenerator generator)
{
+ if (generator is Forwarder)
+ {
+ // Forwarder allows everything since it just forwards to a P/Invoke.
+ return generator;
+ }
+
if (info.IsByRef && info.ByValueContentsMarshalKind != ByValueContentsMarshalKind.Default)
{
throw new MarshallingNotSupportedException(info, context)
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs
index 931fccaf161..92533d72003 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/Forwarder.cs
@@ -37,12 +37,35 @@ namespace Microsoft.Interop
return true;
}
- if (info.MarshallingAttributeInfo is NativeContiguousCollectionMarshallingInfo collectionMarshalling
- && collectionMarshalling.UseDefaultMarshalling
- && collectionMarshalling.ElementCountInfo is NoCountInfo or SizeAndParamIndexInfo
- && collectionMarshalling.ElementMarshallingInfo is NoMarshallingInfo or MarshalAsInfo { UnmanagedType: not UnmanagedType.CustomMarshaler }
- && info.ManagedType is IArrayTypeSymbol)
+ if (info.ManagedType is SzArrayType)
{
+ CountInfo countInfo;
+ MarshallingInfo elementMarshallingInfo;
+ if (info.MarshallingAttributeInfo is NativeContiguousCollectionMarshallingInfo collectionMarshalling
+ && collectionMarshalling.UseDefaultMarshalling
+ && collectionMarshalling.ElementCountInfo is NoCountInfo or SizeAndParamIndexInfo
+ && collectionMarshalling.ElementMarshallingInfo is NoMarshallingInfo or MarshalAsInfo { UnmanagedType: not UnmanagedType.CustomMarshaler }
+ )
+ {
+ countInfo = collectionMarshalling.ElementCountInfo;
+ elementMarshallingInfo = collectionMarshalling.ElementMarshallingInfo;
+ }
+ else if (info.MarshallingAttributeInfo is MissingSupportCollectionMarshallingInfo missingSupport)
+ {
+ countInfo = missingSupport.CountInfo;
+ elementMarshallingInfo = missingSupport.ElementMarshallingInfo;
+ }
+ else
+ {
+ // This condition can be hit in two ways:
+ // 1. User uses the MarshalUsing attribute to provide count info or element marshalling information.
+ // Since the MarshalUsing attribute doesn't exist on downlevel platforms where we don't support arrays,
+ // this case is unlikely to come in supported scenarios, but could come up with a custom CoreLib implementation
+ // 2. User provides a MarsalAs attribute with the ArraySubType field set to UnmanagedType.CustomMarshaler
+ // As mentioned above, we don't support ICustomMarshaler in the generator so we fail to forward the attribute instead of partially fowarding it.
+ return false;
+ }
+
List<AttributeArgumentSyntax> marshalAsArguments = new List<AttributeArgumentSyntax>
{
AttributeArgument(
@@ -51,17 +74,17 @@ namespace Microsoft.Interop
Literal((int)UnmanagedType.LPArray))))
};
- if (collectionMarshalling.ElementCountInfo is SizeAndParamIndexInfo countInfo)
+ if (countInfo is SizeAndParamIndexInfo sizeParamIndex)
{
- if (countInfo.ConstSize != SizeAndParamIndexInfo.UnspecifiedConstSize)
+ if (sizeParamIndex.ConstSize != SizeAndParamIndexInfo.UnspecifiedConstSize)
{
marshalAsArguments.Add(
AttributeArgument(NameEquals("SizeConst"), null,
LiteralExpression(SyntaxKind.NumericLiteralExpression,
- Literal(countInfo.ConstSize)))
+ Literal(sizeParamIndex.ConstSize)))
);
}
- if (countInfo.ParamAtIndex is { ManagedIndex: int paramIndex })
+ if (sizeParamIndex.ParamAtIndex is { ManagedIndex: int paramIndex })
{
marshalAsArguments.Add(
AttributeArgument(NameEquals("SizeParamIndex"), null,
@@ -71,7 +94,7 @@ namespace Microsoft.Interop
}
}
- if (collectionMarshalling.ElementMarshallingInfo is MarshalAsInfo elementMarshalAs)
+ if (elementMarshallingInfo is MarshalAsInfo elementMarshalAs)
{
marshalAsArguments.Add(
AttributeArgument(NameEquals("ArraySubType"), null,
@@ -94,9 +117,23 @@ namespace Microsoft.Interop
.WithModifiers(TokenList(Token(info.RefKindSyntax)))
.WithType(info.ManagedType.Syntax);
+ List<AttributeSyntax> rehydratedAttributes = new();
if (TryRehydrateMarshalAsAttribute(info, out AttributeSyntax marshalAsAttribute))
{
- param = param.AddAttributeLists(AttributeList(SingletonSeparatedList(marshalAsAttribute)));
+ rehydratedAttributes.Add(marshalAsAttribute);
+ }
+ if (info.ByValueContentsMarshalKind.HasFlag(ByValueContentsMarshalKind.In))
+ {
+ rehydratedAttributes.Add(Attribute(IdentifierName(TypeNames.System_Runtime_InteropServices_InAttribute)));
+ }
+ if (info.ByValueContentsMarshalKind.HasFlag(ByValueContentsMarshalKind.Out))
+ {
+ rehydratedAttributes.Add(Attribute(IdentifierName(TypeNames.System_Runtime_InteropServices_OutAttribute)));
+ }
+
+ if (rehydratedAttributes.Count > 0)
+ {
+ param = param.AddAttributeLists(AttributeList(SeparatedList(rehydratedAttributes)));
}
return param;
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/IMarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/IMarshallingGeneratorFactory.cs
new file mode 100644
index 00000000000..faab7391260
--- /dev/null
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/IMarshallingGeneratorFactory.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using Microsoft.CodeAnalysis;
+
+namespace Microsoft.Interop
+{
+ public interface IMarshallingGeneratorFactory
+ {
+ /// <summary>
+ /// Create an <see cref="IMarshallingGenerator"/> instance for marshalling the supplied type in the given position.
+ /// </summary>
+ /// <param name="info">Type details</param>
+ /// <param name="context">Metadata about the stub the type is associated with</param>
+ /// <returns>A <see cref="IMarshallingGenerator"/> instance.</returns>
+ public IMarshallingGenerator Create(
+ TypePositionInfo info,
+ StubCodeContext context);
+ }
+}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshalAsMarshallingGeneratorFactory.cs
index 2170b4978b9..ca61227661f 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshalAsMarshallingGeneratorFactory.cs
@@ -6,20 +6,7 @@ using Microsoft.CodeAnalysis;
namespace Microsoft.Interop
{
- public interface IMarshallingGeneratorFactory
- {
- /// <summary>
- /// Create an <see cref="IMarshallingGenerator"/> instance for marshalling the supplied type in the given position.
- /// </summary>
- /// <param name="info">Type details</param>
- /// <param name="context">Metadata about the stub the type is associated with</param>
- /// <returns>A <see cref="IMarshallingGenerator"/> instance.</returns>
- public IMarshallingGenerator Create(
- TypePositionInfo info,
- StubCodeContext context);
- }
-
- public sealed class DefaultMarshallingGeneratorFactory : IMarshallingGeneratorFactory
+ public sealed class MarshalAsMarshallingGeneratorFactory : IMarshallingGeneratorFactory
{
private static readonly ByteBoolMarshaller s_byteBool = new();
private static readonly WinBoolMarshaller s_winBool = new();
@@ -36,10 +23,12 @@ namespace Microsoft.Interop
private static readonly DelegateMarshaller s_delegate = new();
private static readonly SafeHandleMarshaller s_safeHandle = new();
private InteropGenerationOptions Options { get; }
+ private IMarshallingGeneratorFactory InnerFactory { get; }
- public DefaultMarshallingGeneratorFactory(InteropGenerationOptions options)
+ public MarshalAsMarshallingGeneratorFactory(InteropGenerationOptions options, IMarshallingGeneratorFactory inner)
{
Options = options;
+ InnerFactory = inner;
}
/// <summary>
@@ -123,7 +112,7 @@ namespace Microsoft.Interop
return s_forwarder;
default:
- throw new MarshallingNotSupportedException(info, context);
+ return InnerFactory.Create(info, context);
}
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/UnsupportedMarshallingFactory.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/UnsupportedMarshallingFactory.cs
new file mode 100644
index 00000000000..a12f702e1f7
--- /dev/null
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/UnsupportedMarshallingFactory.cs
@@ -0,0 +1,18 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Runtime.InteropServices;
+using Microsoft.CodeAnalysis;
+
+namespace Microsoft.Interop
+{
+ public sealed class UnsupportedMarshallingFactory : IMarshallingGeneratorFactory
+ {
+ public IMarshallingGenerator Create(
+ TypePositionInfo info,
+ StubCodeContext context)
+ {
+ throw new MarshallingNotSupportedException(info, context);
+ }
+ }
+}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs
index d1f659d125b..c151607c972 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/MarshallingAttributeInfo.cs
@@ -49,12 +49,7 @@ namespace Microsoft.Interop
/// An indication of "missing support" will trigger the fallback logic, which is
/// the forwarder marshaler.
/// </remarks>
- public sealed record MissingSupportMarshallingInfo : MarshallingInfo
- {
- public static readonly MarshallingInfo Instance = new MissingSupportMarshallingInfo();
-
- private MissingSupportMarshallingInfo() { }
- }
+ public record MissingSupportMarshallingInfo : MarshallingInfo;
/// <summary>
/// Character encoding enumeration.
@@ -85,11 +80,9 @@ namespace Microsoft.Interop
}
/// <summary>
- /// User-applied System.Runtime.InteropServices.BlittableTypeAttribute
- /// or System.Runtime.InteropServices.GeneratedMarshallingAttribute on a blittable type
- /// in source in this compilation.
+ /// The provided type was determined to be an "unmanaged" type that can be passed as-is to native code.
/// </summary>
- public sealed record BlittableTypeAttributeInfo : MarshallingInfo;
+ public sealed record UnmanagedBlittableMarshallingInfo : MarshallingInfo;
[Flags]
public enum CustomMarshallingFeatures
@@ -170,6 +163,18 @@ namespace Microsoft.Interop
UseDefaultMarshalling
);
+
+ /// <summary>
+ /// Marshalling information is lacking because of support not because it is
+ /// unknown or non-existent. Includes information about element types in case
+ /// we need to rehydrate the marshalling info into an attribute for the fallback marshaller.
+ /// </summary>
+ /// <remarks>
+ /// An indication of "missing support" will trigger the fallback logic, which is
+ /// the forwarder marshaler.
+ /// </remarks>
+ public sealed record MissingSupportCollectionMarshallingInfo(CountInfo CountInfo, MarshallingInfo ElementMarshallingInfo) : MissingSupportMarshallingInfo;
+
public sealed class MarshallingAttributeInfoParser
{
private readonly Compilation _compilation;
@@ -288,16 +293,7 @@ namespace Microsoft.Interop
{
INamedTypeSymbol attributeClass = typeAttribute.AttributeClass!;
- if (SymbolEqualityComparer.Default.Equals(_compilation.GetTypeByMetadataName(TypeNames.BlittableTypeAttribute), attributeClass))
- {
- // If type is generic, then we need to re-evaluate that it is blittable at usage time.
- if (type is INamedTypeSymbol { IsGenericType: false } || type.HasOnlyBlittableFields())
- {
- return new BlittableTypeAttributeInfo();
- }
- break;
- }
- else if (SymbolEqualityComparer.Default.Equals(_compilation.GetTypeByMetadataName(TypeNames.NativeMarshallingAttribute), attributeClass))
+ if (attributeClass.ToDisplayString() == TypeNames.NativeMarshallingAttribute)
{
return CreateNativeMarshallingInfo(
type,
@@ -309,9 +305,9 @@ namespace Microsoft.Interop
inspectedElements,
ref maxIndirectionLevelUsed);
}
- else if (SymbolEqualityComparer.Default.Equals(_compilation.GetTypeByMetadataName(TypeNames.GeneratedMarshallingAttribute), attributeClass))
+ else if (attributeClass.ToDisplayString() == TypeNames.GeneratedMarshallingAttribute)
{
- return type.IsConsideredBlittable() ? new BlittableTypeAttributeInfo() : new GeneratedNativeMarshallingAttributeInfo(null! /* TODO: determine naming convention */);
+ return type.IsConsideredBlittable() ? GetBlittableMarshallingInfo(type) : new GeneratedNativeMarshallingAttributeInfo(null! /* TODO: determine naming convention */);
}
}
@@ -329,15 +325,6 @@ namespace Microsoft.Interop
return infoMaybe;
}
- // No marshalling info was computed, but a character encoding was provided.
- // If the type is a character or string then pass on these details.
- if (_defaultInfo.CharEncoding != CharEncoding.Undefined
- && (type.SpecialType == SpecialType.System_Char
- || type.SpecialType == SpecialType.System_String))
- {
- return new MarshallingInfoStringSupport(_defaultInfo.CharEncoding);
- }
-
return NoMarshallingInfo.Instance;
}
@@ -563,7 +550,7 @@ namespace Microsoft.Interop
if (arrayMarshaller is null)
{
// If the array marshaler type is not available, then we cannot marshal arrays but indicate it is missing.
- return MissingSupportMarshallingInfo.Instance;
+ return new MissingSupportCollectionMarshallingInfo(arraySizeInfo, elementMarshallingInfo);
}
ITypeSymbol? valuePropertyType = ManualTypeMarshallingHelper.FindValueProperty(arrayMarshaller)?.Type;
@@ -724,25 +711,30 @@ namespace Microsoft.Interop
out MarshallingInfo marshallingInfo)
{
// Check for an implicit SafeHandle conversion.
- CodeAnalysis.Operations.CommonConversion conversion = _compilation.ClassifyCommonConversion(type, _compilation.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_SafeHandle)!);
- if (conversion.Exists
- && conversion.IsImplicit
- && (conversion.IsReference || conversion.IsIdentity))
- {
- bool hasAccessibleDefaultConstructor = false;
- if (type is INamedTypeSymbol named && !named.IsAbstract && named.InstanceConstructors.Length > 0)
+ // The SafeHandle type might not be defined if we're using one of the test CoreLib implementations used for NativeAOT.
+ ITypeSymbol? safeHandleType = _compilation.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_SafeHandle);
+ if (safeHandleType is not null)
+ {
+ CodeAnalysis.Operations.CommonConversion conversion = _compilation.ClassifyCommonConversion(type, safeHandleType);
+ if (conversion.Exists
+ && conversion.IsImplicit
+ && (conversion.IsReference || conversion.IsIdentity))
{
- foreach (IMethodSymbol ctor in named.InstanceConstructors)
+ bool hasAccessibleDefaultConstructor = false;
+ if (type is INamedTypeSymbol named && !named.IsAbstract && named.InstanceConstructors.Length > 0)
{
- if (ctor.Parameters.Length == 0)
+ foreach (IMethodSymbol ctor in named.InstanceConstructors)
{
- hasAccessibleDefaultConstructor = _compilation.IsSymbolAccessibleWithin(ctor, _contextSymbol.ContainingType);
- break;
+ if (ctor.Parameters.Length == 0)
+ {
+ hasAccessibleDefaultConstructor = _compilation.IsSymbolAccessibleWithin(ctor, _contextSymbol.ContainingType);
+ break;
+ }
}
}
+ marshallingInfo = new SafeHandleMarshallingInfo(hasAccessibleDefaultConstructor, type.IsAbstract);
+ return true;
}
- marshallingInfo = new SafeHandleMarshallingInfo(hasAccessibleDefaultConstructor, type.IsAbstract);
- return true;
}
if (type is IArrayTypeSymbol { ElementType: ITypeSymbol elementType })
@@ -761,7 +753,7 @@ namespace Microsoft.Interop
if (arrayMarshaller is null)
{
// If the array marshaler type is not available, then we cannot marshal arrays but indicate it is missing.
- marshallingInfo = MissingSupportMarshallingInfo.Instance;
+ marshallingInfo = new MissingSupportCollectionMarshallingInfo(parsedCountInfo, GetMarshallingInfo(elementType, useSiteAttributes, indirectionLevel + 1, inspectedElements, ref maxIndirectionLevelUsed));
return true;
}
@@ -778,12 +770,20 @@ namespace Microsoft.Interop
return true;
}
- if (type is INamedTypeSymbol { IsValueType: true } valueType
- && !valueType.IsExposedOutsideOfCurrentCompilation()
- && valueType.IsConsideredBlittable())
+ // No marshalling info was computed, but a character encoding was provided.
+ // If the type is a character or string then pass on these details.
+ if (_defaultInfo.CharEncoding != CharEncoding.Undefined
+ && (type.SpecialType == SpecialType.System_Char
+ || type.SpecialType == SpecialType.System_String))
+ {
+ marshallingInfo = new MarshallingInfoStringSupport(_defaultInfo.CharEncoding);
+ return true;
+ }
+
+ if (type is INamedTypeSymbol { IsUnmanagedType: true } unmanagedType
+ && unmanagedType.IsConsideredBlittable())
{
- // Allow implicit [BlittableType] on internal value types.
- marshallingInfo = new BlittableTypeAttributeInfo();
+ marshallingInfo = GetBlittableMarshallingInfo(type);
return true;
}
@@ -791,6 +791,28 @@ namespace Microsoft.Interop
return false;
}
+ private MarshallingInfo GetBlittableMarshallingInfo(ITypeSymbol type)
+ {
+ if (type.TypeKind is TypeKind.Enum or TypeKind.Pointer or TypeKind.FunctionPointer
+ || type.SpecialType.IsAlwaysBlittable()
+ || type.SpecialType == SpecialType.System_Boolean)
+ {
+ // Treat primitive types and enums as having no marshalling info.
+ // They are supported in configurations where runtime marshalling is enabled.
+ return NoMarshallingInfo.Instance;
+ }
+
+ else if (_compilation.GetTypeByMetadataName(TypeNames.System_Runtime_CompilerServices_DisableRuntimeMarshallingAttribute) is null)
+ {
+ // If runtime marshalling cannot be disabled, then treat this as a "missing support" scenario so we can gracefully fall back to using the fowarder downlevel.
+ return new MissingSupportMarshallingInfo();
+ }
+ else
+ {
+ return new UnmanagedBlittableMarshallingInfo();
+ }
+ }
+
private bool TryGetAttributeIndirectionLevel(AttributeData attrData, out int indirectionLevel)
{
if (SymbolEqualityComparer.Default.Equals(attrData.AttributeClass, _marshalAsAttribute))
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.Designer.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.Designer.cs
index 1d254e29a5c..499ffc63bca 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.Designer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.Designer.cs
@@ -304,6 +304,15 @@ namespace Microsoft.Interop {
}
/// <summary>
+ /// Looks up a localized string similar to Runtime marshalling must be disabled in this project by applying the &apos;System.Runtime.InteropServices.DisableRuntimeMarshallingAttribute&apos; to the assembly to enable marshalling this type..
+ /// </summary>
+ internal static string RuntimeMarshallingMustBeDisabled {
+ get {
+ return ResourceManager.GetString("RuntimeMarshallingMustBeDisabled", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to An abstract type derived from &apos;SafeHandle&apos; cannot be marshalled by reference. The provided type must be concrete..
/// </summary>
internal static string SafeHandleByRefMustBeConcrete {
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.resx b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.resx
index 544a1ea46a2..3b0e3a12521 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.resx
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Resources.resx
@@ -219,4 +219,7 @@
<data name="ConstantAndElementCountInfoDisallowed" xml:space="preserve">
<value>Only one of 'ConstantElementCount' or 'ElementCountInfo' may be used in a 'MarshalUsingAttribute' for a given 'ElementIndirectionLevel'</value>
</data>
+ <data name="RuntimeMarshallingMustBeDisabled" xml:space="preserve">
+ <value>Runtime marshalling must be disabled in this project by applying the 'System.Runtime.InteropServices.DisableRuntimeMarshallingAttribute' to the assembly to enable marshalling this type.</value>
+ </data>
</root> \ No newline at end of file
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs
index 1925d2ece51..8111b0787bc 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeNames.cs
@@ -16,8 +16,6 @@ namespace Microsoft.Interop
public const string GeneratedMarshallingAttribute = "System.Runtime.InteropServices.GeneratedMarshallingAttribute";
- public const string BlittableTypeAttribute = "System.Runtime.InteropServices.BlittableTypeAttribute";
-
public const string NativeMarshallingAttribute = "System.Runtime.InteropServices.NativeMarshallingAttribute";
public const string MarshalUsingAttribute = "System.Runtime.InteropServices.MarshalUsingAttribute";
@@ -75,5 +73,7 @@ namespace Microsoft.Interop
{
return options.UseInternalUnsafeType ? Internal_Runtime_CompilerServices_Unsafe : System_Runtime_CompilerServices_Unsafe;
}
+
+ public const string System_Runtime_CompilerServices_DisableRuntimeMarshallingAttribute = "System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute";
}
}
diff --git a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs
index 4f5aaf0cc7d..c03e880f124 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/TypeSymbolExtensions.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Immutable;
+using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis;
@@ -18,9 +19,8 @@ namespace Microsoft.Interop
{
if (seenTypes.Contains(type))
{
- // A recursive struct type isn't blittable.
- // It's also illegal in C#, but I believe that source generators run
- // before that is detected, so we check here to avoid a stack overflow.
+ // A recursive struct type is illegal in C#, but source generators run before that is detected,
+ // so we check here to avoid a stack overflow.
return false;
}
@@ -30,14 +30,10 @@ namespace Microsoft.Interop
{
bool fieldBlittable = field switch
{
- { Type: { IsReferenceType: true } } => false,
- { Type: IPointerTypeSymbol ptr } => true,
- { Type: IFunctionPointerTypeSymbol } => true,
- not { Type: { SpecialType: SpecialType.None } } => IsSpecialTypeBlittable(field.Type.SpecialType),
// Assume that type parameters that can be blittable are blittable.
// We'll re-evaluate blittability for generic fields of generic types at instantation time.
- { Type: ITypeParameterSymbol } => true,
- { Type: { IsValueType: false } } => false,
+ { Type: ITypeParameterSymbol { IsReferenceType: false } } => true,
+ { Type.IsUnmanagedType: false } => false,
_ => IsConsideredBlittable(field.Type, seenTypes.Add(type))
};
@@ -51,107 +47,42 @@ namespace Microsoft.Interop
return true;
}
- private static bool IsSpecialTypeBlittable(SpecialType specialType)
- => specialType switch
- {
- SpecialType.System_Void
- or SpecialType.System_SByte
- or SpecialType.System_Byte
- or SpecialType.System_Int16
- or SpecialType.System_UInt16
- or SpecialType.System_Int32
- or SpecialType.System_UInt32
- or SpecialType.System_Int64
- or SpecialType.System_UInt64
- or SpecialType.System_Single
- or SpecialType.System_Double
- or SpecialType.System_IntPtr
- or SpecialType.System_UIntPtr => true,
- _ => false
- };
-
public static bool IsConsideredBlittable(this ITypeSymbol type) => IsConsideredBlittable(type, ImmutableHashSet.Create<ITypeSymbol>(SymbolEqualityComparer.Default));
private static bool IsConsideredBlittable(this ITypeSymbol type, ImmutableHashSet<ITypeSymbol> seenTypes)
{
- if (type.SpecialType != SpecialType.None)
- {
- return IsSpecialTypeBlittable(type.SpecialType);
- }
-
- if (type.TypeKind is TypeKind.FunctionPointer or TypeKind.Pointer)
- {
- return true;
- }
-
- if (type.IsReferenceType)
+ if (!type.IsUnmanagedType || type.IsAutoLayout())
{
return false;
}
- if (type is INamedTypeSymbol { TypeKind: TypeKind.Enum, EnumUnderlyingType: ITypeSymbol underlyingType })
- {
- return underlyingType.IsConsideredBlittable(seenTypes);
- }
-
- bool hasNativeMarshallingAttribute = false;
- bool hasGeneratedMarshallingAttribute = false;
- // [TODO]: Match attributes on full name or symbol, not just on type name.
foreach (AttributeData attr in type.GetAttributes())
{
if (attr.AttributeClass is null)
{
continue;
}
- if (attr.AttributeClass.Name == "BlittableTypeAttribute")
+ else if (attr.AttributeClass.ToDisplayString() == "System.Runtime.InteropServices.GeneratedMarshallingAttribute")
{
- if (type is INamedTypeSymbol { IsGenericType: true } generic)
- {
- // If the type is generic, we inspect the fields again
- // to determine blittability of this instantiation
- // since we are guaranteed that if a type has generic fields,
- // they will be present in the contract assembly to ensure
- // that recursive structs can be identified at build time.
- return generic.HasOnlyBlittableFields(seenTypes);
- }
- return true;
- }
- else if (attr.AttributeClass.Name == "GeneratedMarshallingAttribute")
- {
- hasGeneratedMarshallingAttribute = true;
+ // If we have generated struct marshalling,
+ // then the generated marshalling will be non-blittable when one of the fields is not unmanaged.
+ return type.HasOnlyBlittableFields(seenTypes);
}
- else if (attr.AttributeClass.Name == "NativeMarshallingAttribute")
+ else if (attr.AttributeClass.ToDisplayString() == "System.Runtime.InteropServices.NativeMarshallingAttribute")
{
- hasNativeMarshallingAttribute = true;
+ return false;
}
}
-
- if (hasGeneratedMarshallingAttribute && !hasNativeMarshallingAttribute)
- {
- // The struct type has generated marshalling via a source generator.
- // We can't guarantee that we can see the results of the struct source generator,
- // so we re-calculate if the type is blittable here.
- return type.HasOnlyBlittableFields(seenTypes);
- }
-
- if (type is INamedTypeSymbol namedType
- && namedType.DeclaringSyntaxReferences.Length != 0
- && !namedType.IsExposedOutsideOfCurrentCompilation())
- {
- // If a type is declared in the current compilation and not exposed outside of it,
- // we will allow it to be considered blittable if its fields are considered blittable.
- return type.HasOnlyBlittableFields(seenTypes);
- }
- return false;
+ return true;
}
- public static bool IsAutoLayout(this INamedTypeSymbol type, ITypeSymbol structLayoutAttributeType)
+ public static bool IsAutoLayout(this ITypeSymbol type)
{
foreach (AttributeData attr in type.GetAttributes())
{
- if (SymbolEqualityComparer.Default.Equals(structLayoutAttributeType, attr.AttributeClass))
+ if (attr.AttributeClass.ToDisplayString() == "System.Runtime.InteropServices.StructLayoutAttribute")
{
- return (LayoutKind)(int)attr.ConstructorArguments[0].Value! == LayoutKind.Auto;
+ return attr.ConstructorArguments.Length == 1 && (LayoutKind)(int)attr.ConstructorArguments[0].Value! == LayoutKind.Auto;
}
}
return type.IsReferenceType;
@@ -164,9 +95,7 @@ namespace Microsoft.Interop
public static bool IsIntegralType(this SpecialType type)
{
- return type switch
- {
- SpecialType.System_SByte
+ return type is SpecialType.System_SByte
or SpecialType.System_Byte
or SpecialType.System_Int16
or SpecialType.System_UInt16
@@ -175,23 +104,24 @@ namespace Microsoft.Interop
or SpecialType.System_Int64
or SpecialType.System_UInt64
or SpecialType.System_IntPtr
- or SpecialType.System_UIntPtr => true,
- _ => false
- };
+ or SpecialType.System_UIntPtr;
}
- public static bool IsExposedOutsideOfCurrentCompilation(this INamedTypeSymbol type)
+ public static bool IsAlwaysBlittable(this SpecialType type)
{
- for (; type is not null; type = type.ContainingType)
- {
- Accessibility accessibility = type.DeclaredAccessibility;
-
- if (accessibility is Accessibility.Internal or Accessibility.ProtectedAndInternal or Accessibility.Private or Accessibility.Friend or Accessibility.ProtectedAndFriend)
- {
- return false;
- }
- }
- return true;
+ return type is SpecialType.System_Void
+ or SpecialType.System_SByte
+ or SpecialType.System_Byte
+ or SpecialType.System_Int16
+ or SpecialType.System_UInt16
+ or SpecialType.System_Int32
+ or SpecialType.System_UInt32
+ or SpecialType.System_Int64
+ or SpecialType.System_UInt64
+ or SpecialType.System_IntPtr
+ or SpecialType.System_UIntPtr
+ or SpecialType.System_Single
+ or SpecialType.System_Double;
}
}
}
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj
index 94877b6888c..5fdc0af1b96 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/DllImportGenerator.Tests.csproj
@@ -10,6 +10,11 @@
</PropertyGroup>
<ItemGroup>
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
+
+ <ItemGroup>
<PackageReference Include="coverlet.collector" Version="$(CoverletCollectorVersion)">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs
index 4f05e0e568e..a12cdd2245a 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.Tests/SetLastErrorTests.cs
@@ -8,7 +8,6 @@ using Xunit;
namespace DllImportGenerator.IntegrationTests
{
- [BlittableType]
public struct SetLastErrorMarshaller
{
public int val;
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AdditionalAttributesOnStub.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AdditionalAttributesOnStub.cs
index 803904a9f98..640ee220f08 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AdditionalAttributesOnStub.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AdditionalAttributesOnStub.cs
@@ -17,7 +17,9 @@ namespace DllImportGenerator.UnitTests
public async Task SkipLocalsInitAdded()
{
string source = @"
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+[assembly:DisableRuntimeMarshalling]
partial class C
{
[GeneratedDllImportAttribute(""DoesNotExist"")]
@@ -66,7 +68,7 @@ partial class C
{
yield return new object[] { TestTargetFramework.Net, true };
yield return new object[] { TestTargetFramework.Net6, true };
- yield return new object[] { TestTargetFramework.Net5, false };
+ yield return new object[] { TestTargetFramework.Net5, true };
yield return new object[] { TestTargetFramework.Core, false };
yield return new object[] { TestTargetFramework.Standard, false };
yield return new object[] { TestTargetFramework.Framework, false };
@@ -79,28 +81,10 @@ partial class C
string source = $@"
using System.Runtime.InteropServices;
{CodeSnippets.GeneratedDllImportAttributeDeclaration}
-namespace System.Runtime.InteropServices
-{{
- sealed class NativeMarshallingAttribute : System.Attribute
- {{
- public NativeMarshallingAttribute(System.Type nativeType) {{ }}
- }}
-}}
partial class C
{{
[GeneratedDllImportAttribute(""DoesNotExist"")]
- public static partial S Method();
-}}
-
-[NativeMarshalling(typeof(Native))]
-struct S
-{{
-}}
-
-struct Native
-{{
- public Native(S s) {{ }}
- public S ToManaged() {{ return default; }}
+ public static partial bool Method();
}}";
Compilation comp = await TestUtils.CreateCompilation(source, targetFramework);
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AttributeForwarding.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AttributeForwarding.cs
index 70090ee6dcb..978bf1c4ca8 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AttributeForwarding.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/AttributeForwarding.cs
@@ -3,9 +3,12 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
+using Microsoft.Interop;
using System;
using System.Collections.Generic;
+using System.Collections.Immutable;
using System.Linq;
+using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Xunit;
@@ -20,7 +23,9 @@ namespace DllImportGenerator.UnitTests
public async Task KnownParameterlessAttribute(string attributeSourceName, string attributeMetadataName)
{
string source = @$"
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+[assembly:DisableRuntimeMarshalling]
partial class C
{{
[{attributeSourceName}]
@@ -59,7 +64,9 @@ struct Native
{
string source = @"
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+[assembly:DisableRuntimeMarshalling]
partial class C
{
[UnmanagedCallConv(CallConvs = new Type[0])]
@@ -102,6 +109,7 @@ struct Native
string source = @"
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+[assembly:DisableRuntimeMarshalling]
partial class C
{
[UnmanagedCallConv(CallConvs = new[]{typeof(CallConvStdcall)})]
@@ -148,6 +156,7 @@ struct Native
string source = @"
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+[assembly:DisableRuntimeMarshalling]
partial class C
{
[UnmanagedCallConv(CallConvs = new[]{typeof(CallConvStdcall), typeof(CallConvSuppressGCTransition)})]
@@ -197,7 +206,9 @@ struct Native
{
string source = @"
using System;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
+[assembly:DisableRuntimeMarshalling]
class OtherAttribute : Attribute {}
@@ -235,6 +246,108 @@ struct Native
attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, attributeType));
}
+ [ConditionalFact]
+ public async Task InOutAttributes_Forwarded_To_ForwardedParameter()
+ {
+ string source = @"
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+partial class C
+{
+ [GeneratedDllImportAttribute(""DoesNotExist"")]
+ public static partial bool Method1([In, Out] int[] a);
+}
+" + CodeSnippets.GeneratedDllImportAttributeDeclaration;
+ Compilation origComp = await TestUtils.CreateCompilation(source, TestTargetFramework.Standard);
+ Compilation newComp = TestUtils.RunGenerators(origComp, out _, new Microsoft.Interop.DllImportGenerator());
+
+ IMethodSymbol targetMethod = GetGeneratedPInvokeTargetFromCompilation(newComp);
+
+ INamedTypeSymbol marshalAsAttribute = newComp.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_MarshalAsAttribute)!;
+ INamedTypeSymbol inAttribute = newComp.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_InAttribute)!;
+ INamedTypeSymbol outAttribute = newComp.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_OutAttribute)!;
+ Assert.Collection(targetMethod.Parameters,
+ param => Assert.Collection(param.GetAttributes(),
+ attr =>
+ {
+ Assert.Equal(marshalAsAttribute, attr.AttributeClass, SymbolEqualityComparer.Default);
+ Assert.Equal(UnmanagedType.LPArray, (UnmanagedType)attr.ConstructorArguments[0].Value!);
+ Assert.Empty(attr.NamedArguments);
+ },
+ attr =>
+ {
+ Assert.Equal(inAttribute, attr.AttributeClass, SymbolEqualityComparer.Default);
+ Assert.Empty(attr.ConstructorArguments);
+ Assert.Empty(attr.NamedArguments);
+ },
+ attr =>
+ {
+ Assert.Equal(outAttribute, attr.AttributeClass, SymbolEqualityComparer.Default);
+ Assert.Empty(attr.ConstructorArguments);
+ Assert.Empty(attr.NamedArguments);
+ }));
+ }
+
+ [ConditionalFact]
+ public async Task MarshalAsAttribute_Forwarded_To_ForwardedParameter()
+ {
+ string source = @"
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+partial class C
+{
+ [GeneratedDllImportAttribute(""DoesNotExist"")]
+ public static partial bool Method1([MarshalAs(UnmanagedType.I2)] int a);
+}
+" + CodeSnippets.GeneratedDllImportAttributeDeclaration;
+ Compilation origComp = await TestUtils.CreateCompilation(source, TestTargetFramework.Standard);
+ Compilation newComp = TestUtils.RunGenerators(origComp, out _, new Microsoft.Interop.DllImportGenerator());
+
+ IMethodSymbol targetMethod = GetGeneratedPInvokeTargetFromCompilation(newComp);
+
+ INamedTypeSymbol marshalAsAttribute = newComp.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_MarshalAsAttribute)!;
+ Assert.Collection(targetMethod.Parameters,
+ param => Assert.Collection(param.GetAttributes(),
+ attr =>
+ {
+ Assert.Equal(marshalAsAttribute, attr.AttributeClass, SymbolEqualityComparer.Default);
+ Assert.Equal(UnmanagedType.I2, (UnmanagedType)attr.ConstructorArguments[0].Value!);
+ Assert.Empty(attr.NamedArguments);
+ }));
+ }
+
+ [ConditionalFact]
+ public async Task MarshalAsAttribute_Forwarded_To_ForwardedParameter_Array()
+ {
+ string source = @"
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+partial class C
+{
+ [GeneratedDllImportAttribute(""DoesNotExist"")]
+ public static partial bool Method1([MarshalAs(UnmanagedType.LPArray, SizeConst = 10, SizeParamIndex = 1, ArraySubType = UnmanagedType.I4)] int[] a, int b);
+}
+" + CodeSnippets.GeneratedDllImportAttributeDeclaration;
+ Compilation origComp = await TestUtils.CreateCompilation(source, TestTargetFramework.Standard);
+ Compilation newComp = TestUtils.RunGenerators(origComp, out _, new Microsoft.Interop.DllImportGenerator());
+
+ IMethodSymbol targetMethod = GetGeneratedPInvokeTargetFromCompilation(newComp);
+
+ INamedTypeSymbol marshalAsAttribute = newComp.GetTypeByMetadataName(TypeNames.System_Runtime_InteropServices_MarshalAsAttribute)!;
+ Assert.Collection(targetMethod.Parameters,
+ param => Assert.Collection(param.GetAttributes(),
+ attr =>
+ {
+ Assert.Equal(marshalAsAttribute, attr.AttributeClass, SymbolEqualityComparer.Default);
+ Assert.Equal(UnmanagedType.LPArray, (UnmanagedType)attr.ConstructorArguments[0].Value!);
+ var namedArgs = attr.NamedArguments.ToImmutableDictionary();
+ Assert.Equal(10, namedArgs["SizeConst"].Value);
+ Assert.Equal((short)1, namedArgs["SizeParamIndex"].Value);
+ Assert.Equal(UnmanagedType.I4, (UnmanagedType)namedArgs["ArraySubType"].Value!);
+ }),
+ param => Assert.Equal(SpecialType.System_Int32, param.Type.SpecialType));
+ }
+
private static IMethodSymbol GetGeneratedPInvokeTargetFromCompilation(Compilation newComp)
{
// The last syntax tree is the generated code
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs
index 79fb731628f..6f13bf6f10a 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CodeSnippets.cs
@@ -327,6 +327,8 @@ partial class Test
}
";
+ public static readonly string DisableRuntimeMarshalling = "[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]";
+
/// <summary>
/// Declaration with parameters with <see cref="CharSet"/> set.
/// </summary>
@@ -366,8 +368,9 @@ partial class Test
/// <summary>
/// Declaration with parameters.
/// </summary>
- public static string BasicParametersAndModifiersNoRef(string typeName) => @$"
+ public static string BasicParametersAndModifiersNoRef(string typeName, string preDeclaration = "") => @$"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -380,8 +383,9 @@ partial class Test
/// <summary>
/// Declaration with parameters and unsafe.
/// </summary>
- public static string BasicParametersAndModifiersUnsafe(string typeName) => @$"
+ public static string BasicParametersAndModifiersUnsafe(string typeName, string preDeclaration = "") => @$"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -397,8 +401,9 @@ partial class Test
/// <summary>
/// Declaration with [In, Out] style attributes on a by-value parameter.
/// </summary>
- public static string ByValueParameterWithModifier(string typeName, string attributeName) => @$"
+ public static string ByValueParameterWithModifier(string typeName, string attributeName, string preDeclaration = "") => @$"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -406,7 +411,7 @@ partial class Test
[{attributeName}] {typeName} p);
}}";
- public static string ByValueParameterWithModifier<T>(string attributeName) => ByValueParameterWithModifier(typeof(T).ToString(), attributeName);
+ public static string ByValueParameterWithModifier<T>(string attributeName, string preDeclaration = "") => ByValueParameterWithModifier(typeof(T).ToString(), attributeName, preDeclaration);
/// <summary>
/// Declaration with by-value parameter with custom name.
@@ -529,13 +534,13 @@ delegate int MyDelegate(int a);";
private void* vptr;
}}";
- public static string BlittableStructParametersAndModifiers = BasicParametersAndModifiers("MyStruct") + $@"
-[BlittableType]
+ public static string BlittableStructParametersAndModifiers = BasicParametersAndModifiers("MyStruct", DisableRuntimeMarshalling) + $@"
{BlittableMyStruct()}
";
- public static string MarshalAsArrayParametersAndModifiers(string elementType) => $@"
+ public static string MarshalAsArrayParametersAndModifiers(string elementType, string preDeclaration = "") => $@"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -550,10 +555,11 @@ partial class Test
);
}}";
- public static string MarshalAsArrayParametersAndModifiers<T>() => MarshalAsArrayParametersAndModifiers(typeof(T).ToString());
+ public static string MarshalAsArrayParametersAndModifiers<T>(string preDeclaration = "") => MarshalAsArrayParametersAndModifiers(typeof(T).ToString(), preDeclaration);
public static string MarshalAsArrayParameterWithSizeParam(string sizeParamType, bool isByRef) => $@"
using System.Runtime.InteropServices;
+{DisableRuntimeMarshalling}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -566,8 +572,9 @@ partial class Test
public static string MarshalAsArrayParameterWithSizeParam<T>(bool isByRef) => MarshalAsArrayParameterWithSizeParam(typeof(T).ToString(), isByRef);
- public static string MarshalAsArrayParameterWithNestedMarshalInfo(string elementType, UnmanagedType nestedMarshalInfo) => $@"
+ public static string MarshalAsArrayParameterWithNestedMarshalInfo(string elementType, UnmanagedType nestedMarshalInfo, string preDeclaration = "") => $@"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -576,10 +583,11 @@ partial class Test
);
}}";
- public static string MarshalAsArrayParameterWithNestedMarshalInfo<T>(UnmanagedType nestedMarshalType) => MarshalAsArrayParameterWithNestedMarshalInfo(typeof(T).ToString(), nestedMarshalType);
+ public static string MarshalAsArrayParameterWithNestedMarshalInfo<T>(UnmanagedType nestedMarshalType, string preDeclaration = "") => MarshalAsArrayParameterWithNestedMarshalInfo(typeof(T).ToString(), nestedMarshalType, preDeclaration);
- public static string ArrayPreserveSigFalse(string elementType) => $@"
+ public static string ArrayPreserveSigFalse(string elementType, string preDeclaration = "") => $@"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"", PreserveSig = false)]
@@ -591,13 +599,14 @@ partial class Test
public static partial {elementType}[] Method2(int i);
}}";
- public static string ArrayPreserveSigFalse<T>() => ArrayPreserveSigFalse(typeof(T).ToString());
+ public static string ArrayPreserveSigFalse<T>(string preDeclaration = "") => ArrayPreserveSigFalse(typeof(T).ToString(), preDeclaration);
/// <summary>
/// Declaration with parameters with MarshalAs.
/// </summary>
- public static string MarshalUsingParametersAndModifiers(string typeName, string nativeTypeName) => @$"
+ public static string MarshalUsingParametersAndModifiers(string typeName, string nativeTypeName, string preDeclaration = "") => @$"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -610,7 +619,7 @@ partial class Test
}}
";
- public static string CustomStructMarshallingParametersAndModifiers = BasicParametersAndModifiers("S") + @"
+ public static string CustomStructMarshallingParametersAndModifiers = BasicParametersAndModifiers("S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
struct S
{
@@ -629,7 +638,7 @@ struct Native
}
";
- public static string CustomStructMarshallingMarshalUsingParametersAndModifiers = MarshalUsingParametersAndModifiers("S", "Native") + @"
+ public static string CustomStructMarshallingMarshalUsingParametersAndModifiers = MarshalUsingParametersAndModifiers("S", "Native", DisableRuntimeMarshalling) + @"
struct S
{
public bool b;
@@ -647,7 +656,7 @@ struct Native
}
";
- public static string CustomStructMarshallingStackallocParametersAndModifiersNoRef = BasicParametersAndModifiersNoRef("S") + @"
+ public static string CustomStructMarshallingStackallocParametersAndModifiersNoRef = BasicParametersAndModifiersNoRef("S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
struct S
{
@@ -667,7 +676,7 @@ struct Native
public const int BufferSize = 1;
}
";
- public static string CustomStructMarshallingStackallocOnlyRefParameter = BasicParameterWithByRefModifier("ref", "S") + @"
+ public static string CustomStructMarshallingStackallocOnlyRefParameter = BasicParameterWithByRefModifier("ref", "S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
struct S
{
@@ -688,7 +697,7 @@ struct Native
public const bool RequiresStackBuffer = false;
}
";
- public static string CustomStructMarshallingOptionalStackallocParametersAndModifiers = BasicParametersAndModifiers("S") + @"
+ public static string CustomStructMarshallingOptionalStackallocParametersAndModifiers = BasicParametersAndModifiers("S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
struct S
{
@@ -714,7 +723,7 @@ struct Native
}
";
- public static string CustomStructMarshallingStackallocValuePropertyParametersAndModifiersNoRef = BasicParametersAndModifiersNoRef("S") + @"
+ public static string CustomStructMarshallingStackallocValuePropertyParametersAndModifiersNoRef = BasicParametersAndModifiersNoRef("S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
struct S
{
@@ -735,7 +744,7 @@ struct Native
public const int BufferSize = 1;
}
";
- public static string CustomStructMarshallingValuePropertyParametersAndModifiers = BasicParametersAndModifiers("S") + @"
+ public static string CustomStructMarshallingValuePropertyParametersAndModifiers = BasicParametersAndModifiers("S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
struct S
{
@@ -754,7 +763,7 @@ struct Native
public int Value { get; set; }
}
";
- public static string CustomStructMarshallingPinnableParametersAndModifiers = BasicParametersAndModifiers("S") + @"
+ public static string CustomStructMarshallingPinnableParametersAndModifiers = BasicParametersAndModifiers("S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
class S
{
@@ -786,6 +795,8 @@ unsafe struct Native
using System.Runtime.InteropServices;
using System;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
+
[NativeMarshalling(typeof(Native))]
class S
{
@@ -842,7 +853,7 @@ partial class Test
}
";
- public static string CustomStructMarshallingByRefValueProperty = BasicParametersAndModifiers("S") + @"
+ public static string CustomStructMarshallingByRefValueProperty = BasicParametersAndModifiers("S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
class S
{
@@ -862,8 +873,9 @@ unsafe struct Native
}
";
- public static string BasicParameterWithByRefModifier(string byRefKind, string typeName) => @$"
+ public static string BasicParameterWithByRefModifier(string byRefKind, string typeName, string preDeclaration = "") => @$"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -871,8 +883,9 @@ partial class Test
{byRefKind} {typeName} p);
}}";
- public static string BasicParameterByValue(string typeName) => @$"
+ public static string BasicParameterByValue(string typeName, string preDeclaration = "") => @$"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -880,15 +893,16 @@ partial class Test
{typeName} p);
}}";
- public static string BasicReturnType(string typeName) => @$"
+ public static string BasicReturnType(string typeName, string preDeclaration = "") => @$"
using System.Runtime.InteropServices;
+{preDeclaration}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
public static partial {typeName} Method();
}}";
- public static string CustomStructMarshallingManagedToNativeOnlyOutParameter => BasicParameterWithByRefModifier("out", "S") + @"
+ public static string CustomStructMarshallingManagedToNativeOnlyOutParameter => BasicParameterWithByRefModifier("out", "S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
[StructLayout(LayoutKind.Sequential)]
struct S
@@ -906,7 +920,7 @@ struct Native
}
";
- public static string CustomStructMarshallingManagedToNativeOnlyReturnValue => BasicReturnType("S") + @"
+ public static string CustomStructMarshallingManagedToNativeOnlyReturnValue => BasicReturnType("S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
[StructLayout(LayoutKind.Sequential)]
struct S
@@ -924,7 +938,7 @@ struct Native
}
";
- public static string CustomStructMarshallingNativeToManagedOnlyInParameter => BasicParameterWithByRefModifier("in", "S") + @"
+ public static string CustomStructMarshallingNativeToManagedOnlyInParameter => BasicParameterWithByRefModifier("in", "S", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Native))]
struct S
{
@@ -939,7 +953,7 @@ struct Native
}
";
- public static string ArrayMarshallingWithCustomStructElementWithValueProperty => MarshalAsArrayParametersAndModifiers("IntStructWrapper") + @"
+ public static string ArrayMarshallingWithCustomStructElementWithValueProperty => MarshalAsArrayParametersAndModifiers("IntStructWrapper", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(IntStructWrapperNative))]
public struct IntStructWrapper
{
@@ -959,7 +973,7 @@ public struct IntStructWrapperNative
}
";
- public static string ArrayMarshallingWithCustomStructElement => MarshalAsArrayParametersAndModifiers("IntStructWrapper") + @"
+ public static string ArrayMarshallingWithCustomStructElement => MarshalAsArrayParametersAndModifiers("IntStructWrapper", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(IntStructWrapperNative))]
public struct IntStructWrapper
{
@@ -1057,8 +1071,7 @@ partial class Test
public static int Foo() => throw null;
}}";
- public static string MaybeBlittableGenericTypeParametersAndModifiers(string typeArgument) => BasicParametersAndModifiers($"Generic<{typeArgument}>") + @"
-[BlittableType]
+ public static string MaybeBlittableGenericTypeParametersAndModifiers(string typeArgument) => BasicParametersAndModifiers($"Generic<{typeArgument}>", DisableRuntimeMarshalling) + @"
struct Generic<T>
{
#pragma warning disable CS0649
@@ -1069,30 +1082,13 @@ struct Generic<T>
public static string MaybeBlittableGenericTypeParametersAndModifiers<T>() =>
MaybeBlittableGenericTypeParametersAndModifiers(typeof(T).ToString());
- public static string ImplicitlyBlittableStructParametersAndModifiers(string visibility = "") => BasicParametersAndModifiers("MyStruct") + $@"
-// Implicitly blittable
-{BlittableMyStruct(visibility)}
-";
-
- public static string ImplicitlyBlittableGenericTypeParametersAndModifiers(string typeArgument, string visibility = "") => BasicParametersAndModifiers($"Generic<{typeArgument}>") + $@"
-{visibility} struct Generic<T>
-{{
-#pragma warning disable CS0649
-#pragma warning disable CS0169
- public T field;
-}}
-";
-
- public static string ImplicitlyBlittableGenericTypeParametersAndModifiers<T>(string visibility = "") =>
- ImplicitlyBlittableGenericTypeParametersAndModifiers(typeof(T).ToString(), visibility);
-
- public static string RecursiveImplicitlyBlittableStruct => BasicParametersAndModifiers("RecursiveStruct") + @"
+ public static string RecursiveImplicitlyBlittableStruct => BasicParametersAndModifiers("RecursiveStruct", DisableRuntimeMarshalling) + @"
struct RecursiveStruct
{
RecursiveStruct s;
int i;
}";
- public static string MutuallyRecursiveImplicitlyBlittableStruct => BasicParametersAndModifiers("RecursiveStruct1") + @"
+ public static string MutuallyRecursiveImplicitlyBlittableStruct => BasicParametersAndModifiers("RecursiveStruct1", DisableRuntimeMarshalling) + @"
struct RecursiveStruct1
{
RecursiveStruct2 s;
@@ -1105,7 +1101,7 @@ struct RecursiveStruct2
int i;
}";
- public static string CollectionByValue(string elementType) => BasicParameterByValue($"TestCollection<{elementType}>") + @"
+ public static string CollectionByValue(string elementType) => BasicParameterByValue($"TestCollection<{elementType}>", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Marshaller<>))]
class TestCollection<T> {}
@@ -1123,6 +1119,7 @@ ref struct Marshaller<T>
public static string MarshalUsingCollectionCountInfoParametersAndModifiers(string collectionType) => $@"
using System.Runtime.InteropServices;
+{DisableRuntimeMarshalling}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1163,6 +1160,7 @@ ref struct Marshaller<T>
public static string MarshalUsingCollectionParametersAndModifiers(string collectionType, string marshallerType) => $@"
using System.Runtime.InteropServices;
+{DisableRuntimeMarshalling}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1183,6 +1181,7 @@ partial class Test
public static string MarshalUsingCollectionReturnValueLength(string collectionType, string marshallerType) => $@"
using System.Runtime.InteropServices;
+{DisableRuntimeMarshalling}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1197,6 +1196,7 @@ partial class Test
public static string MarshalUsingArrayParameterWithSizeParam(string sizeParamType, bool isByRef) => $@"
using System.Runtime.InteropServices;
+{DisableRuntimeMarshalling}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1210,6 +1210,7 @@ partial class Test
public static string MarshalUsingCollectionWithConstantAndElementCount => $@"
using System.Runtime.InteropServices;
+{DisableRuntimeMarshalling}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1221,6 +1222,7 @@ partial class Test
public static string MarshalUsingCollectionWithNullElementName => $@"
using System.Runtime.InteropServices;
+{DisableRuntimeMarshalling}
partial class Test
{{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1230,7 +1232,7 @@ partial class Test
);
}}";
- public static string GenericCollectionMarshallingArityMismatch => BasicParameterByValue("TestCollection<int>") + @"
+ public static string GenericCollectionMarshallingArityMismatch => BasicParameterByValue("TestCollection<int>", DisableRuntimeMarshalling) + @"
[NativeMarshalling(typeof(Marshaller<,>))]
class TestCollection<T> {}
@@ -1246,6 +1248,7 @@ ref struct Marshaller<T, U>
public static string GenericCollectionWithCustomElementMarshalling => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1271,6 +1274,7 @@ struct IntWrapper
public static string GenericCollectionWithCustomElementMarshallingDuplicateElementIndirectionLevel => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1288,6 +1292,7 @@ struct IntWrapper
public static string GenericCollectionWithCustomElementMarshallingUnusedElementIndirectionLevel => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1305,6 +1310,7 @@ struct IntWrapper
public static string MarshalAsAndMarshalUsingOnReturnValue => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1316,6 +1322,7 @@ partial class Test
public static string RecursiveCountElementNameOnReturnValue => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1326,6 +1333,7 @@ partial class Test
public static string RecursiveCountElementNameOnParameter => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1336,6 +1344,7 @@ partial class Test
";
public static string MutuallyRecursiveCountElementNameOnParameter => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1347,6 +1356,7 @@ partial class Test
";
public static string MutuallyRecursiveSizeParamIndexOnParameter => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
@@ -1359,6 +1369,7 @@ partial class Test
public static string CollectionsOfCollectionsStress => @"
using System.Runtime.InteropServices;
+[assembly:System.Runtime.CompilerServices.DisableRuntimeMarshalling]
partial class Test
{
[GeneratedDllImport(""DoesNotExist"")]
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs
index a69af456627..48b35d68f66 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/CompileFails.cs
@@ -63,19 +63,19 @@ namespace DllImportGenerator.UnitTests
// No size information for array marshalling from unmanaged to managed
// * return, out, ref
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<byte[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<sbyte[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<short[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<ushort[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<int[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<uint[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<long[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<ulong[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<float[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<double[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<bool[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<IntPtr[]>(), 3, 0 };
- yield return new object[] { CodeSnippets.BasicParametersAndModifiers<UIntPtr[]>(), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<byte[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<sbyte[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<short[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<ushort[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<int[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<uint[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<long[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<ulong[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<float[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<double[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<bool[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<IntPtr[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
+ yield return new object[] { CodeSnippets.BasicParametersAndModifiers<UIntPtr[]>(CodeSnippets.DisableRuntimeMarshalling), 3, 0 };
// Collection with non-integer size param
yield return new object[] { CodeSnippets.MarshalAsArrayParameterWithSizeParam<float>(isByRef: false), 1, 0 };
@@ -96,15 +96,6 @@ namespace DllImportGenerator.UnitTests
// Abstract SafeHandle type by reference
yield return new object[] { CodeSnippets.BasicParameterWithByRefModifier("ref", "System.Runtime.InteropServices.SafeHandle"), 1, 0 };
- // Non-blittable instantiation of generic type
- yield return new object[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers<bool>(), 5, 0 };
-
- // No marshalling annotations
-
- yield return new object[] { CodeSnippets.ImplicitlyBlittableStructParametersAndModifiers("public"), 5, 0 };
- yield return new object[] { CodeSnippets.ImplicitlyBlittableGenericTypeParametersAndModifiers<bool>(), 5, 0 };
- yield return new object[] { CodeSnippets.ImplicitlyBlittableGenericTypeParametersAndModifiers<int>("public"), 5, 0 };
-
// Collection with constant and element size parameter
yield return new object[] { CodeSnippets.MarshalUsingCollectionWithConstantAndElementCount, 2, 0 };
@@ -145,8 +136,8 @@ namespace DllImportGenerator.UnitTests
public static IEnumerable<object[]> CodeSnippetsToCompile_InvalidCode()
{
- yield return new object[] { CodeSnippets.RecursiveImplicitlyBlittableStruct, 5, 1 };
- yield return new object[] { CodeSnippets.MutuallyRecursiveImplicitlyBlittableStruct, 5, 2 };
+ yield return new object[] { CodeSnippets.RecursiveImplicitlyBlittableStruct, 0, 1 };
+ yield return new object[] { CodeSnippets.MutuallyRecursiveImplicitlyBlittableStruct, 0, 2 };
}
[ConditionalTheory]
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs
index 0572d1dd207..ca59b242e36 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/Compiles.cs
@@ -102,8 +102,8 @@ namespace DllImportGenerator.UnitTests
// [In, Out] attributes
// By value non-blittable array
- yield return new[] { CodeSnippets.ByValueParameterWithModifier<bool[]>("Out") };
- yield return new[] { CodeSnippets.ByValueParameterWithModifier<bool[]>("In, Out") };
+ yield return new[] { CodeSnippets.ByValueParameterWithModifier<bool[]>("Out", CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ByValueParameterWithModifier<bool[]>("In, Out", CodeSnippets.DisableRuntimeMarshalling) };
// Enums
yield return new[] { CodeSnippets.EnumParameters };
@@ -161,19 +161,19 @@ namespace DllImportGenerator.UnitTests
yield return new[] { CodeSnippets.PreserveSigFalse<IntPtr>() };
yield return new[] { CodeSnippets.PreserveSigFalse<UIntPtr>() };
yield return new[] { CodeSnippets.PreserveSigFalse("Microsoft.Win32.SafeHandles.SafeFileHandle") };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<byte>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<sbyte>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<short>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<ushort>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<int>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<uint>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<long>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<ulong>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<float>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<double>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<bool>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<IntPtr>() };
- yield return new[] { CodeSnippets.ArrayPreserveSigFalse<UIntPtr>() };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<byte>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<sbyte>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<short>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<ushort>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<int>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<uint>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<long>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<ulong>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<float>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<double>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<bool>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<IntPtr>(CodeSnippets.DisableRuntimeMarshalling) };
+ yield return new[] { CodeSnippets.ArrayPreserveSigFalse<UIntPtr>(CodeSnippets.DisableRuntimeMarshalling) };
// Custom type marshalling
yield return new[] { CodeSnippets.CustomStructMarshallingParametersAndModifiers };
@@ -206,12 +206,6 @@ namespace DllImportGenerator.UnitTests
yield return new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers<IntPtr>() };
yield return new[] { CodeSnippets.MaybeBlittableGenericTypeParametersAndModifiers<UIntPtr>() };
- // Implicit blittable types
- yield return new[] { CodeSnippets.ImplicitlyBlittableStructParametersAndModifiers() };
- yield return new[] { CodeSnippets.ImplicitlyBlittableStructParametersAndModifiers("internal") };
- yield return new[] { CodeSnippets.ImplicitlyBlittableGenericTypeParametersAndModifiers<int>() };
- yield return new[] { CodeSnippets.ImplicitlyBlittableGenericTypeParametersAndModifiers<int>("internal") };
-
// Custom collection marshalling
yield return new[] { CodeSnippets.CollectionByValue<byte>() };
yield return new[] { CodeSnippets.CollectionByValue<sbyte>() };
@@ -480,7 +474,7 @@ namespace DllImportGenerator.UnitTests
{
yield return new object[] { new[] { CodeSnippets.BasicParametersAndModifiers<int>(), CodeSnippets.MarshalAsParametersAndModifiers<bool>(UnmanagedType.Bool) } };
yield return new object[] { new[] { CodeSnippets.BasicParametersAndModifiersWithCharSet<int>(CharSet.Unicode), CodeSnippets.MarshalAsParametersAndModifiers<bool>(UnmanagedType.Bool) } };
- yield return new object[] { new[] { CodeSnippets.BasicParameterByValue("int[]"), CodeSnippets.BasicParameterWithByRefModifier("ref", "int") } };
+ yield return new object[] { new[] { CodeSnippets.BasicParameterByValue("int[]", CodeSnippets.DisableRuntimeMarshalling), CodeSnippets.BasicParameterWithByRefModifier("ref", "int") } };
}
[ConditionalTheory]
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.Unit.Tests.csproj b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.Unit.Tests.csproj
index 1220cd23315..8c11a8c5bdd 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.Unit.Tests.csproj
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/DllImportGenerator.Unit.Tests.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
diff --git a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ManualTypeMarshallingAnalyzerTests.cs b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ManualTypeMarshallingAnalyzerTests.cs
index 240805071a1..793629f99a2 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ManualTypeMarshallingAnalyzerTests.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/DllImportGenerator.UnitTests/ManualTypeMarshallingAnalyzerTests.cs
@@ -15,172 +15,6 @@ namespace DllImportGenerator.UnitTests
[ActiveIssue("https://github.com/dotnet/runtime/issues/60650", TestRuntimes.Mono)]
public class ManualTypeMarshallingAnalyzerTests
{
- public static IEnumerable<object[]> NonBlittableTypeMarkedBlittable_ReportsDiagnostic_TestData {
- get
- {
- yield return new object[]
- {
- @"
-using System.Runtime.InteropServices;
-
-[{|#0:BlittableType|}]
-struct S
-{
- public bool field;
-}
-"
- };
- yield return new object[]
- {
- @"
-using System.Runtime.InteropServices;
-
-[{|#0:BlittableType|}]
-struct S
-{
- public char field;
-}
-"
- };
- yield return new object[]
- {
-
-@"
-using System.Runtime.InteropServices;
-
-[{|#0:BlittableType|}]
-struct S
-{
- public string field;
-}
-"
- };
- }
- }
-
- [MemberData(nameof(NonBlittableTypeMarkedBlittable_ReportsDiagnostic_TestData))]
- [ConditionalTheory]
- public async Task NonBlittableTypeMarkedBlittable_ReportsDiagnostic(string source)
- {
- var diagnostic = VerifyCS.Diagnostic(BlittableTypeMustBeBlittableRule).WithLocation(0).WithArguments("S");
- await VerifyCS.VerifyAnalyzerAsync(source, diagnostic);
- }
-
- [ConditionalFact]
- public async Task BlittablePrimitiveFields_MarkedBlittable_NoDiagnostic()
- {
-
- string source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct S
-{
- public int field;
-}
-";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task BlittableEnumFields_MarkedBlittable_NoDiagnostic()
- {
-
- string source = @"
-using System.Runtime.InteropServices;
-
-enum E { Zero, One, Two }
-
-[BlittableType]
-struct S
-{
- public E field;
-}
-";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task BlittableStructFields_MarkedBlittable_NoDiagnostic()
- {
- string source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct S
-{
- public T field;
-}
-
-[BlittableType]
-struct T
-{
- public int field;
-}
-";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task NonBlittableFields_MarkedBlittable_ReportDiagnosticOnFieldTypeDefinition()
- {
- string source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct S
-{
- public T field;
-}
-
-[{|#0:BlittableType|}]
-struct T
-{
- public bool field;
-}
-";
- var diagnostic = VerifyCS.Diagnostic(BlittableTypeMustBeBlittableRule).WithLocation(0).WithArguments("T");
- await VerifyCS.VerifyAnalyzerAsync(source, diagnostic);
- }
-
- [ConditionalFact]
- public async Task NonUnmanagedTypeMarkedBlittable_ReportsDiagnosticOnStructType()
- {
- string source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct S
-{
- public T field;
-}
-
-[{|#0:BlittableType|}]
-struct T
-{
- public string field;
-}
-";
- await VerifyCS.VerifyAnalyzerAsync(source,
- VerifyCS.Diagnostic(BlittableTypeMustBeBlittableRule).WithLocation(0).WithArguments("T"));
- }
-
- [ConditionalFact]
- public async Task BlittableTypeWithNonBlittableStaticField_DoesNotReportDiagnostic()
- {
- string source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct S
-{
- public static string Static;
- public int instance;
-}
-";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
[ConditionalFact]
public async Task NullNativeType_ReportsDiagnostic()
{
@@ -280,7 +114,6 @@ struct S
public string s;
}
-[BlittableType]
struct Native
{
private IntPtr value;
@@ -309,7 +142,6 @@ struct S
public string s;
}
-[BlittableType]
struct Native
{
private IntPtr value;
@@ -399,9 +231,9 @@ using System.Runtime.InteropServices;
[NativeMarshalling(typeof(Native))]
class S
{
- public char c;
+ public string s;
- public ref char {|#0:GetPinnableReference|}() => ref c;
+ public ref string {|#0:GetPinnableReference|}() => ref s;
}
unsafe struct Native
@@ -658,7 +490,6 @@ class S
public byte c;
}
-[BlittableType]
unsafe struct Native
{
private byte value;
@@ -688,7 +519,6 @@ class S
public byte c;
}
-[BlittableType]
unsafe struct Native
{
private byte value;
@@ -707,21 +537,6 @@ unsafe struct Native
}
[ConditionalFact]
- public async Task BlittableValueTypeWithNoFields_DoesNotReportDiagnostic()
- {
- string source = @"
-using System;
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct S
-{
-}";
-
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
public async Task NativeTypeWithNoMarshallingMethods_ReportsDiagnostic()
{
string source = @"
@@ -734,7 +549,6 @@ class S
public byte c;
}
-[BlittableType]
struct {|#0:Native|}
{
}";
@@ -947,7 +761,6 @@ class S
public byte c;
}
-[BlittableType]
struct Native
{
public Native(S s) {}
@@ -969,7 +782,6 @@ class S
public byte c;
}
-[BlittableType]
struct Native
{
public S ToManaged() => new S();
@@ -991,7 +803,6 @@ class S
public byte c;
}
-[BlittableType]
struct {|#0:Native|}
{
public Native(S s, Span<byte> buffer) {}
@@ -1091,7 +902,6 @@ struct S
public string s;
}
-[BlittableType]
struct Native
{
private IntPtr value;
@@ -1405,201 +1215,6 @@ struct Native<T>
}
[ConditionalFact]
- public async Task ValueTypeContainingPointers_DoesNotReportDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-unsafe struct S
-{
- private int* intPtr;
- private bool* boolPtr;
-}";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task BlittableValueTypeContainingPointerToSelf_DoesNotReportDiagnostic()
- {
-
- var source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-unsafe struct S
-{
- private int fld;
- private S* ptr;
-}";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task NonBlittableValueTypeContainingPointerToSelf_ReportsDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-[{|#0:BlittableType|}]
-unsafe struct S
-{
- private bool fld;
- private S* ptr;
-}";
- await VerifyCS.VerifyAnalyzerAsync(source,
- VerifyCS.Diagnostic(BlittableTypeMustBeBlittableRule).WithLocation(0).WithArguments("S"));
- }
-
- [ConditionalFact]
- public async Task BlittableTypeContainingFunctionPointer_DoesNotReportDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-unsafe struct S
-{
- private delegate*<int> ptr;
-}";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task BlittableGenericTypeInBlittableType_DoesNotReportDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct G<T>
-{
- T fld;
-}
-
-[BlittableType]
-unsafe struct S
-{
- private G<int> field;
-}";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task NonBlittableGenericTypeInBlittableType_ReportsDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct G<T>
-{
- T fld;
-}
-
-[{|#0:BlittableType|}]
-unsafe struct S
-{
- private G<string> field;
-}";
- await VerifyCS.VerifyAnalyzerAsync(source,
- VerifyCS.Diagnostic(BlittableTypeMustBeBlittableRule).WithLocation(0).WithArguments("S"));
- }
-
- [ConditionalFact]
- public async Task BlittableGenericTypeTypeParameterReferenceType_ReportsDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-[{|#0:BlittableType|}]
-struct G<T> where T : class
-{
- T fld;
-}";
- await VerifyCS.VerifyAnalyzerAsync(source,
- VerifyCS.Diagnostic(BlittableTypeMustBeBlittableRule).WithLocation(0).WithArguments("G<T>"));
- }
-
- [ConditionalFact]
- public async Task BlittableGenericTypeContainingGenericType_DoesNotReportDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct G<T>
-{
- T fld;
-}
-
-[BlittableType]
-struct F<T>
-{
- G<T> fld;
-}
-";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task BlittableNestedGenericType_DoesNotReportDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-struct C<T>
-{
- [BlittableType]
- public struct G
- {
- T fld;
- }
-}
-
-[BlittableType]
-struct S
-{
- C<int>.G g;
-}
-";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
- public async Task BlittableNestedGenericTypeWithReferenceTypeGenericParameter_DoesNotReportDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-struct C<T> where T : class
-{
- [{|#0:BlittableType|}]
- struct G
- {
- T fld;
- }
-}
-";
- await VerifyCS.VerifyAnalyzerAsync(source,
- VerifyCS.Diagnostic(BlittableTypeMustBeBlittableRule).WithLocation(0).WithArguments("C<T>.G"));
- }
-
- [ConditionalFact]
- public async Task BlittableGenericTypeWithReferenceTypeParameterNotUsedInFieldType_DoesNotReportDiagnostic()
- {
- var source = @"
-using System.Runtime.InteropServices;
-
-[BlittableType]
-struct G<T, U> where U : class
-{
- T fld;
-}";
- await VerifyCS.VerifyAnalyzerAsync(source);
- }
-
- [ConditionalFact]
public async Task NativeTypeWithStackallocConstructorWithoutBufferSize_ReportsDiagnostic()
{
string source = @"
@@ -1612,7 +1227,6 @@ class S
public byte c;
}
-[BlittableType]
struct Native
{
public Native(S s) {}
diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/Blittable.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/Blittable.cs
index fc25816928f..5a1f08b17f7 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/Blittable.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/Blittable.cs
@@ -6,7 +6,6 @@ using System.Runtime.InteropServices;
namespace SharedTypes
{
- [BlittableType]
public struct IntFields
{
public int a;
@@ -14,7 +13,6 @@ namespace SharedTypes
public int c;
}
- [BlittableType]
public unsafe struct PointerFields
{
public int* i;
diff --git a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/NonBlittable.cs b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/NonBlittable.cs
index 94d35ace34a..3f8e4747c2f 100644
--- a/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/NonBlittable.cs
+++ b/src/libraries/System.Runtime.InteropServices/tests/TestAssets/SharedTypes/NonBlittable.cs
@@ -16,7 +16,6 @@ namespace SharedTypes
public string str2;
}
- [BlittableType]
public struct StringContainerNative
{
public IntPtr str1;
@@ -70,7 +69,6 @@ namespace SharedTypes
public bool b3;
}
- [BlittableType]
public struct BoolStructNative
{
public byte b1;
diff --git a/src/libraries/System.Security.AccessControl/src/System.Security.AccessControl.csproj b/src/libraries/System.Security.AccessControl/src/System.Security.AccessControl.csproj
index 2b95d0edcd4..98ab4777d2f 100644
--- a/src/libraries/System.Security.AccessControl/src/System.Security.AccessControl.csproj
+++ b/src/libraries/System.Security.AccessControl/src/System.Security.AccessControl.csproj
@@ -25,6 +25,8 @@
<Compile Include="System\Security\Policy\Evidence.cs" />
<Compile Include="System\Security\Policy\EvidenceBase.cs" />
<!-- PInvoke sources -->
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\NotImplemented.cs"
Link="Common\System\NotImplemented.cs" />
<Compile Include="$(CommonPath)Microsoft\Win32\SafeHandles\SafeTokenHandle.cs"
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/DecryptorPalWindows.Decrypt.cs b/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/DecryptorPalWindows.Decrypt.cs
index 8ab01da453d..9490231825a 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/DecryptorPalWindows.Decrypt.cs
+++ b/src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/Pal/Windows/DecryptorPalWindows.Decrypt.cs
@@ -162,21 +162,34 @@ namespace Internal.Cryptography.Pal.Windows
}
}
- private Exception? TryDecryptTrans(KeyTransRecipientInfo recipientInfo, SafeProvOrNCryptKeyHandle hKey, CryptKeySpec keySpec)
+ private unsafe Exception? TryDecryptTrans(KeyTransRecipientInfo recipientInfo, SafeProvOrNCryptKeyHandle hKey, CryptKeySpec keySpec)
{
KeyTransRecipientInfoPalWindows pal = (KeyTransRecipientInfoPalWindows)(recipientInfo.Pal);
- CMSG_CTRL_DECRYPT_PARA decryptPara;
- decryptPara.cbSize = Marshal.SizeOf<CMSG_CTRL_DECRYPT_PARA>();
- decryptPara.hKey = hKey;
- decryptPara.dwKeySpec = keySpec;
- decryptPara.dwRecipientIndex = pal.Index;
+ bool keyAddRefd = false;
- bool success = Interop.Crypt32.CryptMsgControl(_hCryptMsg, 0, MsgControlType.CMSG_CTRL_DECRYPT, ref decryptPara);
- if (!success)
- return Marshal.GetHRForLastWin32Error().ToCryptographicException();
+ try
+ {
+ CMSG_CTRL_DECRYPT_PARA decryptPara;
+ decryptPara.cbSize = sizeof(CMSG_CTRL_DECRYPT_PARA);
+ hKey.DangerousAddRef(ref keyAddRefd);
+ decryptPara.hKey = hKey.DangerousGetHandle();
+ decryptPara.dwKeySpec = keySpec;
+ decryptPara.dwRecipientIndex = pal.Index;
- return null;
+ bool success = Interop.Crypt32.CryptMsgControl(_hCryptMsg, 0, MsgControlType.CMSG_CTRL_DECRYPT, ref decryptPara);
+ if (!success)
+ return Marshal.GetHRForLastWin32Error().ToCryptographicException();
+
+ return null;
+ }
+ finally
+ {
+ if (keyAddRefd)
+ {
+ hKey.DangerousRelease();
+ }
+ }
}
private Exception? TryDecryptAgree(KeyAgreeRecipientInfo keyAgreeRecipientInfo, SafeProvOrNCryptKeyHandle hKey, CryptKeySpec keySpec, X509Certificate2Collection originatorCerts, X509Certificate2Collection extraStore)
@@ -187,46 +200,58 @@ namespace Internal.Cryptography.Pal.Windows
return pal.WithCmsgCmsRecipientInfo<Exception?>(
delegate (CMSG_KEY_AGREE_RECIPIENT_INFO* pKeyAgreeRecipientInfo)
{
- CMSG_CTRL_KEY_AGREE_DECRYPT_PARA decryptPara = default(CMSG_CTRL_KEY_AGREE_DECRYPT_PARA);
- decryptPara.cbSize = Marshal.SizeOf<CMSG_CTRL_KEY_AGREE_DECRYPT_PARA>();
- decryptPara.hProv = hKey;
- decryptPara.dwKeySpec = keySpec;
- decryptPara.pKeyAgree = pKeyAgreeRecipientInfo;
- decryptPara.dwRecipientIndex = pal.Index;
- decryptPara.dwRecipientEncryptedKeyIndex = pal.SubIndex;
- CMsgKeyAgreeOriginatorChoice originatorChoice = pKeyAgreeRecipientInfo->dwOriginatorChoice;
- switch (originatorChoice)
+ bool keyAddRefd = false;
+ try
{
- case CMsgKeyAgreeOriginatorChoice.CMSG_KEY_AGREE_ORIGINATOR_CERT:
- {
- X509Certificate2Collection candidateCerts = new X509Certificate2Collection();
- candidateCerts.AddRange(PkcsHelpers.GetStoreCertificates(StoreName.AddressBook, StoreLocation.CurrentUser, openExistingOnly: true));
- candidateCerts.AddRange(PkcsHelpers.GetStoreCertificates(StoreName.AddressBook, StoreLocation.LocalMachine, openExistingOnly: true));
- candidateCerts.AddRange(originatorCerts);
- candidateCerts.AddRange(extraStore);
- SubjectIdentifier originatorId = pKeyAgreeRecipientInfo->OriginatorCertId.ToSubjectIdentifier();
- X509Certificate2? originatorCert = candidateCerts.TryFindMatchingCertificate(originatorId);
- if (originatorCert == null)
- return ErrorCode.CRYPT_E_NOT_FOUND.ToCryptographicException();
- using (SafeCertContextHandle hCertContext = originatorCert.CreateCertContextHandle())
+ CMSG_CTRL_KEY_AGREE_DECRYPT_PARA decryptPara = default(CMSG_CTRL_KEY_AGREE_DECRYPT_PARA);
+ decryptPara.cbSize = sizeof(CMSG_CTRL_KEY_AGREE_DECRYPT_PARA);
+ hKey.DangerousAddRef(ref keyAddRefd);
+ decryptPara.hProv = hKey.DangerousGetHandle();
+ decryptPara.dwKeySpec = keySpec;
+ decryptPara.pKeyAgree = pKeyAgreeRecipientInfo;
+ decryptPara.dwRecipientIndex = pal.Index;
+ decryptPara.dwRecipientEncryptedKeyIndex = pal.SubIndex;
+ CMsgKeyAgreeOriginatorChoice originatorChoice = pKeyAgreeRecipientInfo->dwOriginatorChoice;
+ switch (originatorChoice)
+ {
+ case CMsgKeyAgreeOriginatorChoice.CMSG_KEY_AGREE_ORIGINATOR_CERT:
{
- CERT_CONTEXT* pOriginatorCertContext = hCertContext.DangerousGetCertContext();
- decryptPara.OriginatorPublicKey = pOriginatorCertContext->pCertInfo->SubjectPublicKeyInfo.PublicKey;
+ X509Certificate2Collection candidateCerts = new X509Certificate2Collection();
+ candidateCerts.AddRange(PkcsHelpers.GetStoreCertificates(StoreName.AddressBook, StoreLocation.CurrentUser, openExistingOnly: true));
+ candidateCerts.AddRange(PkcsHelpers.GetStoreCertificates(StoreName.AddressBook, StoreLocation.LocalMachine, openExistingOnly: true));
+ candidateCerts.AddRange(originatorCerts);
+ candidateCerts.AddRange(extraStore);
+ SubjectIdentifier originatorId = pKeyAgreeRecipientInfo->OriginatorCertId.ToSubjectIdentifier();
+ X509Certificate2? originatorCert = candidateCerts.TryFindMatchingCertificate(originatorId);
+ if (originatorCert == null)
+ return ErrorCode.CRYPT_E_NOT_FOUND.ToCryptographicException();
+ using (SafeCertContextHandle hCertContext = originatorCert.CreateCertContextHandle())
+ {
+ CERT_CONTEXT* pOriginatorCertContext = hCertContext.DangerousGetCertContext();
+ decryptPara.OriginatorPublicKey = pOriginatorCertContext->pCertInfo->SubjectPublicKeyInfo.PublicKey;
- // Do not factor this call out of the switch statement as leaving this "using" block will free up
- // native memory that decryptPara points to.
- return TryExecuteDecryptAgree(ref decryptPara);
+ // Do not factor this call out of the switch statement as leaving this "using" block will free up
+ // native memory that decryptPara points to.
+ return TryExecuteDecryptAgree(ref decryptPara);
+ }
}
- }
- case CMsgKeyAgreeOriginatorChoice.CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY:
- {
- decryptPara.OriginatorPublicKey = pKeyAgreeRecipientInfo->OriginatorPublicKeyInfo.PublicKey;
- return TryExecuteDecryptAgree(ref decryptPara);
- }
+ case CMsgKeyAgreeOriginatorChoice.CMSG_KEY_AGREE_ORIGINATOR_PUBLIC_KEY:
+ {
+ decryptPara.OriginatorPublicKey = pKeyAgreeRecipientInfo->OriginatorPublicKeyInfo.PublicKey;
+ return TryExecuteDecryptAgree(ref decryptPara);
+ }
- default:
- return new CryptographicException(SR.Format(SR.Cryptography_Cms_Invalid_Originator_Identifier_Choice, originatorChoice));
+ default:
+ return new CryptographicException(SR.Format(SR.Cryptography_Cms_Invalid_Originator_Identifier_Choice, originatorChoice));
+ }
+ }
+ finally
+ {
+ if (keyAddRefd)
+ {
+ hKey.DangerousRelease();
+ }
}
});
}
diff --git a/src/libraries/System.Security.Cryptography.Pkcs/src/System.Security.Cryptography.Pkcs.csproj b/src/libraries/System.Security.Cryptography.Pkcs/src/System.Security.Cryptography.Pkcs.csproj
index 4b46896972c..4c0f530d5fa 100644
--- a/src/libraries/System.Security.Cryptography.Pkcs/src/System.Security.Cryptography.Pkcs.csproj
+++ b/src/libraries/System.Security.Cryptography.Pkcs/src/System.Security.Cryptography.Pkcs.csproj
@@ -66,6 +66,10 @@ System.Security.Cryptography.Pkcs.EnvelopedCms</PackageDescription>
<Compile Include="$(CommonPath)System\HexConverter.cs"
Link="Common\System\HexConverter.cs" />
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
<!-- Internal types (platform: AnyOS) -->
<ItemGroup Condition="'$(IsPartialFacadeAssembly)' != 'true'">
<AsnXml Include="$(CommonPath)System\Security\Cryptography\Asn1\Pkcs7\ContentInfoAsn.xml">
diff --git a/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj b/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj
index 7307e2d836b..4880ca0aa09 100644
--- a/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj
+++ b/src/libraries/System.Security.Cryptography.ProtectedData/src/System.Security.Cryptography.ProtectedData.csproj
@@ -39,6 +39,10 @@ System.Security.Cryptography.ProtectedData</PackageDescription>
<Compile Include="$(CommonPath)System\HResults.cs"
Link="Common\System\HResults.cs" />
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0')) and '$(TargetsWindows)' == 'true'">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<Reference Include="System.Resources.ResourceManager" />
<Reference Include="System.Runtime" />
@@ -52,4 +56,4 @@ System.Security.Cryptography.ProtectedData</PackageDescription>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Reference Include="System.Security" />
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/tests/System.Security.Cryptography.X509Certificates.Tests.csproj b/src/libraries/System.Security.Cryptography.X509Certificates/tests/System.Security.Cryptography.X509Certificates.Tests.csproj
index 6499e5c2e94..2155c7384ef 100644
--- a/src/libraries/System.Security.Cryptography.X509Certificates/tests/System.Security.Cryptography.X509Certificates.Tests.csproj
+++ b/src/libraries/System.Security.Cryptography.X509Certificates/tests/System.Security.Cryptography.X509Certificates.Tests.csproj
@@ -76,6 +76,8 @@
<Compile Include="ECDsaOther.cs" />
<Compile Include="RSAOther.cs" />
<Compile Include="TestDataGenerator.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true' and '$(UseAndroidCrypto)' != 'true' and '$(UseAppleCrypto)' != 'true'">
<Compile Include="X509FilesystemTests.Unix.cs" />
diff --git a/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj b/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj
index 0e12e3d1b3d..24dce978068 100644
--- a/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj
+++ b/src/libraries/System.Security.Cryptography/src/System.Security.Cryptography.csproj
@@ -20,6 +20,8 @@
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1\AsnXml.targets" Condition="'$(GeneratePlatformNotSupportedAssemblyMessage)' == ''" />
<Import Project="$(CommonPath)System\Security\Cryptography\Asn1Reader\System.Security.Cryptography.Asn1Reader.Shared.projitems" Condition="'$(GeneratePlatformNotSupportedAssemblyMessage)' == ''" />
<ItemGroup Condition="'$(GeneratePlatformNotSupportedAssemblyMessage)' == ''">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Internal\Cryptography\AsymmetricAlgorithmHelpers.Der.cs"
Link="Common\Internal\Cryptography\AsymmetricAlgorithmHelpers.Der.cs" />
<Compile Include="$(CommonPath)Internal\Cryptography\BasicSymmetricCipher.cs"
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CapiHelper.Windows.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CapiHelper.Windows.cs
index b40e7c67f55..358cb210182 100644
--- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CapiHelper.Windows.cs
+++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/CapiHelper.Windows.cs
@@ -87,7 +87,7 @@ namespace System.Security.Cryptography
throw GetErrorCode().ToCryptographicException();
}
//allocate memory for the provider name
- StringBuilder providerName = new StringBuilder((int)sizeofProviderName);
+ char[] providerName = new char[sizeofProviderName];
//Now call the function CryptGetDefaultProvider again to get the name of the provider
if (!Interop.Advapi32.CryptGetDefaultProvider(dwType, IntPtr.Zero,
@@ -98,7 +98,7 @@ namespace System.Security.Cryptography
}
// check to see if there are upgrades available for the requested CSP
- string providerNameString = providerName.ToString();
+ string providerNameString = new string(providerName.AsSpan().Slice(0, providerName.AsSpan().IndexOf('\0')));
string? wszUpgrade = null;
if (dwType == (int)ProviderType.PROV_RSA_FULL)
{
diff --git a/src/libraries/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj b/src/libraries/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj
index 831490db6c4..f99bbc68881 100644
--- a/src/libraries/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj
+++ b/src/libraries/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj
@@ -24,6 +24,8 @@
<Compile Include="System\Security\Principal\Win32.cs" />
<Compile Include="System\Security\Principal\WindowsIdentity.cs" />
<Compile Include="System\Security\Principal\WindowsPrincipal.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.BOOL.cs"
diff --git a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs
index 56f9ffaef77..5ad1fee85d7 100644
--- a/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs
+++ b/src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs
@@ -132,10 +132,9 @@ namespace System.Security.Principal
{
if (!Interop.Advapi32.AllocateLocallyUniqueId(&sourceContext.SourceIdentifier))
throw new SecurityException(new Win32Exception().Message);
- }
- sourceContext.SourceName = new byte[TOKEN_SOURCE.TOKEN_SOURCE_LENGTH];
- Buffer.BlockCopy(sourceName, 0, sourceContext.SourceName, 0, sourceName.Length);
+ sourceName.AsSpan().CopyTo(new Span<byte>(sourceContext.SourceName, TOKEN_SOURCE.TOKEN_SOURCE_LENGTH));
+ }
if (sUserPrincipalName == null)
throw new ArgumentNullException(nameof(sUserPrincipalName));
@@ -179,13 +178,13 @@ namespace System.Security.Principal
int ntStatus = Interop.SspiCli.LsaLogonUser(
lsaHandle,
- ref lsaOriginName,
+ lsaOriginName,
SECURITY_LOGON_TYPE.Network,
packageId,
authenticationInfo.DangerousGetHandle(),
authenticationInfoLength,
IntPtr.Zero,
- ref sourceContext,
+ sourceContext,
out SafeLsaReturnBufferHandle profileBuffer,
out int profileBufferLength,
out LUID logonId,
diff --git a/src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.TestService/System.ServiceProcess.ServiceController.TestService.csproj b/src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.TestService/System.ServiceProcess.ServiceController.TestService.csproj
index fe1302370b3..8b0d078026b 100644
--- a/src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.TestService/System.ServiceProcess.ServiceController.TestService.csproj
+++ b/src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.TestService/System.ServiceProcess.ServiceController.TestService.csproj
@@ -15,6 +15,9 @@
</Compile>
<Compile Include="..\..\src\Microsoft\Win32\SafeHandles\SafeServiceHandle.cs"
Link="Microsoft\Win32\SafeHandles\SafeServiceHandle.cs" />
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs"
+ Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<Compile Include="$(CommonPath)Interop\Windows\Interop.Libraries.cs"
Link="Common\Interop\Windows\Interop.Libraries.cs" />
<Compile Include="$(CommonPath)Interop\Windows\Advapi32\Interop.ServiceProcessOptions.cs"
@@ -44,4 +47,4 @@
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<Reference Include="System.ServiceProcess" />
</ItemGroup>
-</Project> \ No newline at end of file
+</Project>
diff --git a/src/libraries/System.Speech/src/System.Speech.csproj b/src/libraries/System.Speech/src/System.Speech.csproj
index bf696506ec7..7003b449eff 100644
--- a/src/libraries/System.Speech/src/System.Speech.csproj
+++ b/src/libraries/System.Speech/src/System.Speech.csproj
@@ -221,6 +221,10 @@ System.Speech.Recognition.SpeechRecognizer</PackageDescription>
<Compile Include="$(CommonPath)Interop\Windows\WinMm\Interop.waveOutWrite.cs"
Link="Common\Interop\Windows\WinMm\Interop.waveOutWrite.cs" />
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0')) and '$(TargetsWindows)' == 'true'">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<EmbeddedResource Include="Resources\Strings.resx">
<Visible>true</Visible>
diff --git a/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj b/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj
index 2266de2c947..b2de19721e3 100644
--- a/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj
+++ b/src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj
@@ -12,7 +12,7 @@ System.Security.Cryptography.X509Certificates.X509Certificate2UI
System.Security.Cryptography.X509Certificates.X509SelectionFlag</PackageDescription>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
- <PropertyGroup Condition="'$(TargetsWindows)' != 'true'">
+ <PropertyGroup Condition="'$(TargetsWindows)' != 'true'">
<GeneratePlatformNotSupportedAssemblyMessage>SR.PlatformNotSupported_System_Windows_Extensions</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
@@ -82,6 +82,10 @@ System.Security.Cryptography.X509Certificates.X509SelectionFlag</PackageDescript
<Compile Include="System\Media\SystemSounds.cs" />
<Compile Include="System\Xaml\Permissions\XamlAccessLevel.cs" />
</ItemGroup>
+ <ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0')) and '$(TargetsAnyOS)' != 'true'">
+ <Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
+ Link="Common\DisableRuntimeMarshalling.cs" />
+ </ItemGroup>
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)System.Drawing.Common\src\System.Drawing.Common.csproj" />
<Reference Include="System.Buffers" />
diff --git a/src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs b/src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs
index 18c09a79879..a6b90e6f034 100644
--- a/src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs
+++ b/src/libraries/System.Windows.Extensions/src/System/Security/Cryptography/X509Certificates/X509Certificate2UI.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Win32.SafeHandles;
+using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace System.Security.Cryptography.X509Certificates
@@ -37,7 +38,7 @@ namespace System.Security.Cryptography.X509Certificates
return SelectFromCollectionHelper(certificates, title, message, selectionFlag, hwndParent);
}
- private static void DisplayX509Certificate(X509Certificate2 certificate, IntPtr hwndParent)
+ private static unsafe void DisplayX509Certificate(X509Certificate2 certificate, IntPtr hwndParent)
{
using (SafeCertContextHandle safeCertContext = X509Utils.DuplicateCertificateContext(certificate))
{
@@ -47,8 +48,12 @@ namespace System.Security.Cryptography.X509Certificates
int dwErrorCode = ERROR_SUCCESS;
// Initialize view structure.
- Interop.CryptUI.CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo = new Interop.CryptUI.CRYPTUI_VIEWCERTIFICATE_STRUCTW();
- ViewInfo.dwSize = (uint)Marshal.SizeOf(ViewInfo);
+ Interop.CryptUI.CRYPTUI_VIEWCERTIFICATE_STRUCTW ViewInfo = default;
+#if NET7_0_OR_GREATER
+ ViewInfo.dwSize = (uint)sizeof(Interop.CryptUI.CRYPTUI_VIEWCERTIFICATE_STRUCTW.Native);
+#else
+ ViewInfo.dwSize = (uint)Marshal.SizeOf<Interop.CryptUI.CRYPTUI_VIEWCERTIFICATE_STRUCTW>();
+#endif
ViewInfo.hwndParent = hwndParent;
ViewInfo.dwFlags = 0;
ViewInfo.szTitle = null;
@@ -104,10 +109,18 @@ namespace System.Security.Cryptography.X509Certificates
if (safeCertStoreHandle == null || safeCertStoreHandle.IsInvalid)
throw new CryptographicException(Marshal.GetLastWin32Error());
- Interop.CryptUI.CRYPTUI_SELECTCERTIFICATE_STRUCTW csc = new Interop.CryptUI.CRYPTUI_SELECTCERTIFICATE_STRUCTW();
+ Interop.CryptUI.CRYPTUI_SELECTCERTIFICATE_STRUCTW csc = default;
// Older versions of CRYPTUI do not check the size correctly,
// so always force it to the oldest version of the structure.
+#if NET7_0_OR_GREATER
+ // Declare a local for Native to enable us to get the managed byte offset
+ // without having a null check cause a failure.
+ Interop.CryptUI.CRYPTUI_SELECTCERTIFICATE_STRUCTW.Native native;
+ Unsafe.SkipInit(out native);
+ csc.dwSize = (uint)Unsafe.ByteOffset(ref Unsafe.As<Interop.CryptUI.CRYPTUI_SELECTCERTIFICATE_STRUCTW.Native, byte>(ref native), ref Unsafe.As<IntPtr, byte>(ref native.hSelectedCertStore));
+#else
csc.dwSize = (uint)Marshal.OffsetOf(typeof(Interop.CryptUI.CRYPTUI_SELECTCERTIFICATE_STRUCTW), "hSelectedCertStore");
+#endif
csc.hwndParent = hwndParent;
csc.dwFlags = (uint)selectionFlags;
csc.szTitle = title;
@@ -125,7 +138,7 @@ namespace System.Security.Cryptography.X509Certificates
csc.rgPropSheetPages = IntPtr.Zero;
csc.hSelectedCertStore = safeCertStoreHandle.DangerousGetHandle();
- SafeCertContextHandle safeCertContextHandle = Interop.CryptUI.CryptUIDlgSelectCertificateW(csc);
+ SafeCertContextHandle safeCertContextHandle = Interop.CryptUI.CryptUIDlgSelectCertificateW(ref csc);
if (safeCertContextHandle != null && !safeCertContextHandle.IsInvalid)
{
diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c
index 901c854cc79..d2823dbb024 100644
--- a/src/mono/mono/mini/method-to-ir.c
+++ b/src/mono/mono/mini/method-to-ir.c
@@ -7185,7 +7185,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
* FIXME: This is very slow, need to create a wrapper at JIT time
* instead based on the signature.
*/
- EMIT_NEW_IMAGECONST (cfg, args [0], m_class_get_image (method->klass));
+ EMIT_NEW_IMAGECONST (cfg, args [0], ((MonoDynamicMethod*)method)->assembly->image);
EMIT_NEW_PCONST (cfg, args [1], fsig);
args [2] = addr;
// FIXME tailcall?
diff --git a/src/tests/Common/CoreCLRTestLibrary/HostPolicyMock.cs b/src/tests/Common/CoreCLRTestLibrary/HostPolicyMock.cs
index 31a304a8d84..ec8096d80a3 100644
--- a/src/tests/Common/CoreCLRTestLibrary/HostPolicyMock.cs
+++ b/src/tests/Common/CoreCLRTestLibrary/HostPolicyMock.cs
@@ -126,7 +126,18 @@ namespace TestLibrary
else
{
Delegate d = Marshal.GetDelegateForFunctionPointer(errorWriterPtr, _corehost_error_writer_fnType);
- return (string message) => { d.DynamicInvoke(message); };
+ return (string message) =>
+ {
+ IntPtr messagePtr = Marshal.StringToCoTaskMemAuto(message);
+ try
+ {
+ d.DynamicInvoke(messagePtr);
+ }
+ finally
+ {
+ Marshal.FreeCoTaskMem(messagePtr);
+ }
+ };
}
}
}