diff --git a/Directory.Build.targets b/Directory.Build.targets
index f59955242b29f0..541cdfb59f27f9 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -26,6 +26,10 @@
$(ProductVersion)-$(VersionSuffix)
+
+
+
+
/// Return the IUnknown* for an Object if the current context is the one
@@ -698,32 +696,48 @@ public static object BindToMoniker(string monikerName)
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 43754434469343..b38f3563d62f33 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 @@ internal enum ClassLibFunctionId
IDynamicCastableGetInterfaceImplementation = 9,
}
- internal static class InternalCalls
+ internal static partial class InternalCalls
{
//
// internalcalls for System.GC.
@@ -59,8 +59,9 @@ internal static void RhCollect(int generation, InternalGCCollectionMode mode)
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 @@ internal static long RhGetGcTotalMemory()
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 @@ internal static extern unsafe bool RhpCallFilterFunclet(
// 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 00000000000000..969312264b5b31
--- /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
+{
+ ///
+ /// Provides an equivalent to for native
+ /// functions declared in .NET.
+ ///
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
+ public sealed class UnmanagedCallConvAttribute : Attribute
+ {
+ public UnmanagedCallConvAttribute()
+ {
+ }
+
+ ///
+ /// Types indicating calling conventions for the unmanaged target.
+ ///
+ ///
+ /// If null, the semantics are identical to CallingConvention.Winapi.
+ ///
+ 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 53860b7cdaba04..84accea33ddd3b 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 @@
namespace System.Runtime
{
- internal static class RuntimeExports
+ internal static partial class RuntimeExports
{
//
// internal calls for allocation
@@ -301,8 +301,9 @@ public static unsafe int RhGetCurrentThreadStackTrace(IntPtr[] outputBuffer)
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 b0d2fad5792f37..6caa27646b3823 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 @@ internal static void RhReRegisterForFinalize(object obj)
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 @@ internal static void RhWaitForPendingFinalizers(bool allowReentrantWait)
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 @@ internal static void RhWaitForPendingFinalizers(bool allowReentrantWait)
[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 @@ internal static unsafe void RhUnbox(object? obj, ref byte data, EETypePtr pUnbox
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 @@ internal static IntPtr RhGetModuleSection(TypeManagerHandle module, ReadyToRunSe
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 @@ internal struct ConservativelyReportedRegionDesc
[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 bcf47e47fc5ca2..a4785f4d8643c5 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 @@ internal static unsafe object RhNewObject(EETypePtr pEEType)
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 29a54764b2f69b..3f602c8f677cee 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 @@
false
false
netstandard2.0
+ true
+
+ $(NoWarn);DLLIMPORTGEN003
FEATURE_GC_STRESS;$(DefineConstants)
@@ -184,6 +189,9 @@
System\Runtime\InteropServices\LayoutKind.cs
+
+ System\Runtime\InteropServices\UnmanagedCallConvAttribute.cs
+
System\Runtime\InteropServices\UnmanagedCallersOnlyAttribute.cs
diff --git a/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs b/src/coreclr/tools/Common/TypeSystem/Interop/IL/MarshalHelpers.cs
index e9a889f8233e10..4c11c0570637dc 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 @@ private static MarshallerKind GetArrayElementMarshallerKind(
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 3a35a8e108fa45..35446a502ae958 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 5a071c2b9f8f99..81ae1ab78468f7 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 00000000000000..9a6bc544e558f1
--- /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 b5e3a2109f4ae8..d808de7bea1f63 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 c62e99f4b4f285..a48640d1e46197 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 @@ internal sealed class Luid
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 @@ internal sealed class SEC_WINNT_AUTH_IDENTITY_EX
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 @@ internal enum ResultAll
}
[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() : ref _managed.bv_len);
+
+ public void* Value => Unsafe.AsPointer(ref GetPinnableReference());
+ }
+#endif
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
@@ -138,13 +198,64 @@ internal sealed class LdapControl
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(_native.query) : null,
+ notify = _native.notify != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer(_native.notify) : null,
+ dereference = _native.dereference != IntPtr.Zero ? Marshal.GetDelegateForFunctionPointer(_native.dereference) : null
+ };
+ }
+
+ public void FreeNative() => GC.KeepAlive(_managed);
+ }
+#else
+ public static readonly unsafe int Size = Marshal.SizeOf();
+#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 0b30095146989e..cad9bcab346841 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.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 ODBC32.SQLRETURN SQLAllocHandle(
/*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 ODBC32.SQLRETURN SQLBindCol(
/*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 ODBC32.SQLRETURN SQLBindCol(
/*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 ODBC32.SQLRETURN SQLGetDescFieldW(
/*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 ODBC32.SQLRETURN SQLSetConnectAttrW(
/*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 468b73fe4962c7..2521b4082e78ef 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 Ldap
[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 8a8d3b01b0bdf8..263d49c91e2af5 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 @@ static Ldap()
[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 @@ static Ldap()
[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 @@ static Ldap()
[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 @@ static Ldap()
[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 @@ static Ldap()
[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 @@ static Ldap()
[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 8157ef8c9a5b1c..51cf2ac16b7ace 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 struct AttrList
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 8d73184ca4d50a..3b113c29c945c8 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 3d040c31545840..c8abb85f00b226 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 6fd3ab2bba6aed..a6ccd9121d84f6 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 a1e4d94149b6ff..69d57113aeac3d 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 afc91ab8a733cb..464dc333e07651 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 cecbaca6de6619..b948e77edef081 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 startAddress, IntPtr parameter);
+ [GeneratedDllImport(Libraries.SystemNative, EntryPoint = "SystemNative_CreateThread")]
+ internal static unsafe partial bool CreateThread(IntPtr stackSize, delegate* unmanaged 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 f3344792900117..844d5c967cbafe 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 int Copy(byte[] destination, int offset)
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 byte[] ToByteArray()
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 @@ public void Dispose()
}
#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() == 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 18668ca9c76595..d599fe7ecf7372 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 unsafe int SslSetAlpnProtos(SafeSslHandle ssl, Span serial
}
}
- [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 ee31cd67ab52ed..cadacc56ce09c3 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 99a82e00cc90a1..92d048b9be0652 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 enum GetDefaultProviderFlags : int
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 07cfaf95a3dfaf..8d140920cc2400 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 struct EVENT_FILTER_DESCRIPTOR
}
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 9490c198b02d37..cd7ccb56d29b8a 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 1cc64001df4719..c7f7e75640416f 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 1e4c0309a09d97..f2ada1ff4f4439 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 extern uint LsaLookupNames2(
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 99c920e611ba03..db2d80bcc72d3a 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 Crypt32
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 99a60f60786e07..7c57d09b713f28 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 Crypt32
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 6bd86b24e18e25..1be46df625564f 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 a82ac99918aeba..e98d1aeb621cd6 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 sealed class CRYPTUI_VIEWCERTIFICATE_STRUCTW
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 sealed class CRYPTUI_SELECTCERTIFICATE_STRUCTW
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 8768fd8493be71..b9147cf1631ee3 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 b3c412c4b8cbf0..def17790cb7ae7 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 struct IpAddrString
}
[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 struct MibIfRow2 // MIB_IF_ROW2
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 struct MibIfRow2 // MIB_IF_ROW2
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 struct MibIcmpInfoEx
}
[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 unsafe partial uint GetAdaptersAddresses(
[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 unsafe partial uint GetAdaptersAddresses(
[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 c0a0a2aeb5fbec..538e5bc43df5ea 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 af50326e9771de..ff363379595b3c 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 4ebdc93faf9e62..13865d75fe3a37 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 293a9c0ee49743..c3146abb588916 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 97e3349aef8784..b0b6d90baaeb1e 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 232ac6b8f678fc..95cc4f1e1f806f 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 1e80b3733688e7..004ca3a43763e1 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 static unsafe void RaiseFailFastException(uint faultCode, IntPtr pExAdd
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 a7d9abdaf47b2c..d68aa0f19d2253 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 pfnwk, IntPtr pv, IntPtr pcbe);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial IntPtr CreateThreadpoolWork(delegate* unmanaged 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 pfnwa, IntPtr pv, IntPtr pcbe);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial IntPtr CreateThreadpoolWait(delegate* unmanaged 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 7dd7435c6a826b..a0dda79bdf270f 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 pfnio, IntPtr context, IntPtr pcbe);
+ [GeneratedDllImport(Libraries.Kernel32, SetLastError = true)]
+ internal static unsafe partial SafeThreadPoolIOHandle CreateThreadpoolIo(SafeHandle fl, delegate* unmanaged 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 19f4987d14f6f9..1fcf7da5583135 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 pfnti, IntPtr pv, IntPtr pcbe);
+ [GeneratedDllImport(Libraries.Kernel32)]
+ internal static unsafe partial IntPtr CreateThreadpoolTimer(delegate* unmanaged 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 fec2251f01e180..0b7c745008097d 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 f79f17e3ec6373..e2cc05f757852c 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 01abd6333c8940..970bd32f46ea56 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 enum APTTYPEQUALIFIER : uint
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 851878a81554d6..af00fce67e3c1b 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 7be311659cab48..394b935685c334 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 Ole32
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 2e92ce2a113f37..c19f3774d26026 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 1d266d08596ff2..e6208dc3fa6185 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 struct PerfCounterSetInstanceStruct
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 5b3eaba1d14c4e..7e5bf2718ee756 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 Shell32
{
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 6be3ad7e6dd8e8..83efbbaab90e35 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 84e30b45ef9ae7..7fd660cb2ba6c7 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 unsafe partial int DecryptMessage(
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 SECURITY_STATUS SspiEncodeStringsAsAuthIdentity(
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 abee3daa3b3b17..130497fd917c98 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 daee2bf32eb177..375be2c949b845 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 User32
{
[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 962ccd2e2be1b8..157e12f845f9d4 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 User32
{
[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 9fa455f0b57bf1..401e1bc56833f1 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 User32
{
[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 aff7ee11a381b8..26c0dd93fd3bc6 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 struct CloseBuffer
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 554d62ab1601aa..f545dcf7ba56ab 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 68c10a704cb74a..5d93d76f2638e3 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 ccd5084c430185..165551fa6f9972 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 @@ public static partial SafeWinHttpHandle WinHttpOpenRequest(
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 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 @@ public static partial bool WinHttpSetTimeouts(
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 99bcc38f0a7159..47f105b6c3fc11 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 @@ public delegate void WINHTTP_STATUS_CALLBACK(
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 @@ public struct WINHTTP_AUTOPROXY_OPTIONS
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 2508a98bc2f9db..67757a5ef6f47a 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 72dc40f2aa4584..28478031eb38fd 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 struct TimeValue
// 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();
+ 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();
+ 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(dest, MulticastAddressLength));
+ }
+ _interfaceIndex = managed.InterfaceIndex;
+ }
+
+ public IPv6MulticastRequest ToManaged()
+ {
+ IPv6MulticastRequest managed = new()
+ {
+ MulticastAddress = new byte[MulticastAddressLength],
+ InterfaceIndex = _interfaceIndex
+ };
+ fixed (void* src = _multicastAddress)
+ {
+ new Span(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 047d46b484e891..f9885d46f63073 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 SocketError getsockopt(
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 2aeb51a0c4d21d..a8eb5adc0d29e0 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 SocketError setsockopt(
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 5ca47f48b28613..34fe73e8984c55 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 Ldap
[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 4a6469602e908e..84eb36ca7768b6 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 Ldap
[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 Ldap
[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 Ldap
[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 Ldap
[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 23c0a2886290b4..11350ed5b46d18 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 a45ebf30491561..6620f9c774bda3 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 ad3e9ab20f3899..00000000000000
--- 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
similarity index 75%
rename from src/libraries/Common/src/System/Net/DebugCriticalHandleMinusOneIsInvalid.cs
rename to src/libraries/Common/src/System/Net/DebugSafeHandleZeroOrMinusOneIsInvalid.cs
index bab71d17367eb0..6afe348639ab6d 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 4f4c9951a72ed3..754ef64c05540c 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 @@
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 a1b99ab9223774..7dfa067b001035 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 d27ed6f642322f..c594fa3e7b754e 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 @@ sealed class GeneratedMarshallingAttribute : Attribute
{
}
- [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 00000000000000..5278e31ae0e2cf
--- /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 882394c96aac24..d1308100580327 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);CA1823
+
true
+
-
\ No newline at end of file
+
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 0ccd62c3f8c3a0..86e6af7fdab5b5 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
+
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 2cee04edc073d0..c3f9bd89c5a3fe 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 @@ public static IntPtr CreateTimer(int interval)
}
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 @@ private void Dispose()
{
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 @@ private static void EnsureRegisteredSessionNotification()
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 @@ public static void InvokeOnEventsThread(Delegate method)
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 @@ public static void InvokeOnEventsThread(Delegate method)
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);
}
///
@@ -787,8 +795,9 @@ public static void KillTimer(IntPtr timerId)
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 @@ private static void Shutdown()
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 4088dda76c070d..db9d0fb39fb742 100644
--- a/src/libraries/System.Console/src/System.Console.csproj
+++ b/src/libraries/System.Console/src/System.Console.csproj
@@ -21,6 +21,8 @@
+
diff --git a/src/libraries/System.Console/tests/CancelKeyPress.Unix.cs b/src/libraries/System.Console/tests/CancelKeyPress.Unix.cs
index 2a8bc01fcf2b45..69aa37b679495d 100644
--- a/src/libraries/System.Console/tests/CancelKeyPress.Unix.cs
+++ b/src/libraries/System.Console/tests/CancelKeyPress.Unix.cs
@@ -134,11 +134,11 @@ private unsafe static bool IsSignalIgnored(int signal)
}
}
- [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 8a116f50c00585..32363397a71be2 100644
--- a/src/libraries/System.Console/tests/ConsoleEncoding.Windows.cs
+++ b/src/libraries/System.Console/tests/ConsoleEncoding.Windows.cs
@@ -67,9 +67,9 @@ public void OutputEncoding_SetUnicodeEncoding_SilentlyIgnoredInternally()
}).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 3c83ac5db2f9ea..4418da53021a70 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 @@
+
+
+
+
+
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 a15469babaf3d2..25f8aef9faaef4 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 @@ protected override bool ReleaseHandle()
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 @@ internal ODBC32.SQLRETURN GetDiagnosticField(out string sqlState)
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 7e3cf5c3a8f8f6..ff915761659221 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
+
+
+
-
+
+
+
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 1011901493d917..f571f0246ae021 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 @@ internal enum EvtLoginClass
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 @@ internal struct EvtRpcLogin
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 @@ internal static partial bool EvtRender(
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 @@ internal struct EvtStringVariant
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 @@ internal static extern bool EvtFormatMessage(
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 @@ internal static partial bool EvtFormatMessageBuffer(
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 a03f4dea580489..9898d2491cafc5 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 @@
+
-
\ No newline at end of file
+
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 918384304526b6..fae2dee2392256 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 @@
- SR.DiagnosticsFileVersionInfo_PlatformNotSupported
+ SR.DiagnosticsFileVersionInfo_PlatformNotSupported
+
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 5ebf58e40c57e6..f90314643f412b 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
+
+
+
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 2521808c43c2da..8a41187ffa5cb9 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 @@
+
+
+
+
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 23ef181e99bfd2..64fcab520bf431 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 @@ public static int ADsOpenObject(string path, string userName, string password, i
{
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 0a92754626c1fc..366ab1b31854d2 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 @@
+
+ Common\DisableRuntimeMarshalling.cs
+
Common\Interop\Interop.Ldap.cs
+
+ Common\Interop\Windows\Interop.BOOL.cs
+
@@ -102,6 +109,7 @@
+
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 586bcd7d39a2cf..8d0d6bf93a822f 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 @@ internal static class BerPal
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 329237f10b3065..cb4423b53d603b 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 @@ internal static int GetLastErrorFromConnection(ConnectionHandle ldapHandle)
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 ddceb9b39f9783..f914f707883b67 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 @@ internal static int ExtendedDirectoryOperation(ConnectionHandle ldapHandle, stri
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 f47dc518a13d4d..829a3abdc25338 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 @@ private int InternalConnectToServer()
}
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(), 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 fb2a71e51ed1bc..c0e9780ad478f3 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 @@ public enum SecurityProtocol
[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 @@ internal SecurityPackageContextConnectionInformation()
public int KeyExchangeAlgorithm => _keyExchangeAlgorithm;
public int ExchangeStrength => _exchangeStrength;
+
+ internal ref readonly byte GetPinnableReference() => ref Unsafe.As(ref _securityProtocol);
}
public sealed class ReferralCallback
@@ -127,7 +130,7 @@ public partial class LdapSessionOptions
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 @@ private void ProcessCallBackRoutine(ReferralCallback tempCallback)
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 @@ private int ProcessQueryConnection(IntPtr PrimaryConnection, IntPtr ReferralFrom
}
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 @@ private int ProcessQueryConnection(IntPtr PrimaryConnection, IntPtr ReferralFrom
}
}
- 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 @@ private int ProcessQueryConnection(IntPtr PrimaryConnection, IntPtr ReferralFrom
bool success = AddLdapHandleRef(con);
if (success)
{
- ConnectionToUse = con._ldapHandle.DangerousGetHandle();
+ *ConnectionToUse = con._ldapHandle.DangerousGetHandle();
}
}
@@ -931,7 +934,7 @@ private int ProcessQueryConnection(IntPtr PrimaryConnection, IntPtr ReferralFrom
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 @@ private bool ProcessNotifyConnection(IntPtr primaryConnection, IntPtr referralFr
}
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 @@ private bool ProcessNotifyConnection(IntPtr primaryConnection, IntPtr referralFr
}
}
- 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 @@ private bool ProcessNotifyConnection(IntPtr primaryConnection, IntPtr referralFr
}
}
- 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 @@ private int ProcessDereferenceConnection(IntPtr PrimaryConnection, IntPtr Connec
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 @@ private bool ProcessServerCertificate(IntPtr connection, IntPtr serverCert)
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 7b4922c71fece9..53cf23eb0d8ec2 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 @@ internal static class UnsafeNativeMethods
{
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 71c695235a69e3..9f4bbc7733bedf 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
+
GetObject(hObject, sizeof(Interop.User32.LOGFONT), ref lp);
[StructLayout(LayoutKind.Sequential)]
@@ -100,6 +175,9 @@ internal unsafe struct BITMAPINFO_FLAT
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 sealed class DOCINFO
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 @@ public override string ToString()
}
}
}
-}
\ 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 57d2b9171783ba..5332459af64b2e 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 IntPtr GlobalAlloc(int uFlags, uint dwBytes)
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 8122f6234cc8ae..a15f358ccc26a6 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 dc485e0bab512f..95a82c34ddad47 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 struct ICONINFO
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 1b11a3fa45a8b9..cc8ced8e126347 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 Winspool
[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 2870372f9730df..5a34aa4d3ada00 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
+
placeholder.ico
+
+
+
+
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 512dd06f3bfb02..743a41ad51790c 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 @@ static Gdip()
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 cb74840b78e7b0..3cd50a6818683b 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.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 @@ private static void PlatformInitialize()
}
// 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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ internal static partial int GdipLoadImageFromDelegate_linux(StreamGetHeaderDeleg
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 @@ internal static partial int GdipGetMetafileHeaderFromDelegate_linux(StreamGetHea
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 129416828600aa..2e246f79ec7d07 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.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 @@ private static void PlatformInitialize()
}
// 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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 @@ private static void PlatformInitialize()
[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 8fef9cbc472b25..8097957af5e9ce 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.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 @@ internal static partial class SafeNativeMethods
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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 @@ internal static unsafe partial class Gdip
[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 124ce9f3a7bda1..43effdee1c1b3b 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 @@ public void Save(Stream outputStream)
// 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 @@ public void Save(Stream outputStream)
}
}
- [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 @@ int SaveAsFile([In, MarshalAs(UnmanagedType.Interface)] Interop.Ole32.IStream ps
}
[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 3e4243351d407d..c5a728914bcfe8 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 @@ public int Reserved
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() : 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 62c4babfeeafce..707ff68721669b 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 @@ internal float[][] GetMatrix()
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() : 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 c44caf6e03f82d..d0ef6065bdde42 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 @@ public short Version
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 8e8cc9eefb71d0..f1a501314d921e 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 @@ public sealed class MetaHeader
// 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;
+ }
///
/// Represents the type of the associated .
///
public short Type
{
- get { return _type; }
- set { _type = value; }
+ get { return _data._type; }
+ set { _data._type = value; }
}
///
@@ -34,8 +43,8 @@ public short Type
///
public short HeaderSize
{
- get { return _headerSize; }
- set { _headerSize = value; }
+ get { return _data._headerSize; }
+ set { _data._headerSize = value; }
}
///
@@ -43,8 +52,8 @@ public short HeaderSize
///
public short Version
{
- get { return _version; }
- set { _version = value; }
+ get { return _data._version; }
+ set { _data._version = value; }
}
///
@@ -52,26 +61,40 @@ public short Version
///
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 eb2c7f73a95338..dfce8751ec4d20 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 @@ internal sealed class MetafileHeaderEmf
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(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() : 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 0e95dacbc831eb..6825f2d007b1e2 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 @@ internal sealed class MetafileHeaderWmf
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 b36d964ecf72b0..ab26edfdb1a481 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 @@ public short Checksum
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() : 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 3a8501cd0e1865..a4a73646bd5142 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 @@ internal static IntPtr LoadLibcups()
[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 6ccb314c06078c..e40a4a643fc9a1 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 @@ internal static IntPtr CreateGraphicsContext(PrinterSettings settings, PageSetti
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 c34b54ed173f93..66827e87964fbf 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 @@
+
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 0a6a7088ace395..94aa77c9c9a6ef 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 @@
+
+
+
+
+
+
diff --git a/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Unix.cs b/src/libraries/System.IO.FileSystem/tests/FileSystemTest.Unix.cs
index 38c1b353c9207c..96b7c63f80a1ef 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 87184a69f66fb1..6285027286b7c7 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 @@
+
diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Unix.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFilesTestsBase.Unix.cs
index 8024754a921da6..89652ef5bd7016 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 @@ public abstract partial class MemoryMappedFilesTestBase : FileCleanupTestBase
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);
/// Asserts that the handle's inheritability matches the specified value.
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 2460c15fd59851..e521424a1d5855 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 @@ public abstract partial class MemoryMappedFilesTestBase : FileCleanupTestBase
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 3941ab7f8adacf..c91d0604383fcd 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
///
/// Tests for SafeMemoryMappedViewHandle
///
- public class SafeMemoryMappedViewHandleTests : MemoryMappedFilesTestBase
+ public partial class SafeMemoryMappedViewHandleTests : MemoryMappedFilesTestBase
{
///
/// Tests that external code can use SafeMemoryMappedViewHandle as the result of a P/Invoke on Windows.
@@ -66,7 +66,7 @@ public void SafeMemoryMappedViewHandle_CanUseInPInvoke_Unix()
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 9d75e10c13bd6c..92042aa78f2d36 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 @@
+
@@ -30,4 +32,4 @@
-
\ No newline at end of file
+
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 55437bf7f69bea..0cf60c20c9a1c5 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 @@
+
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 efd034b6044424..6dc6c00f09d760 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
+
+
+
+
+
Link="Common\Interop\Windows\Interop.SECURITY_ATTRIBUTES.cs" />
-
diff --git a/src/libraries/System.Management/src/System.Management.csproj b/src/libraries/System.Management/src/System.Management.csproj
index d79acc744ac2f9..e64ebcf61db51e 100644
--- a/src/libraries/System.Management/src/System.Management.csproj
+++ b/src/libraries/System.Management/src/System.Management.csproj
@@ -1,4 +1,4 @@
-
+
true
$(NoWarn);0618
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 bacef00d3e5d03..41d016898b1a25 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
Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
+
+
+
+
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 bf7173a54c53ad..0792ba26c05514 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 @@
+
-
-
+
+
-
-
+
true
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Android
annotations
+ true
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 fa03df3ba1a2f3..1da319175f0d29 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 @@
+
-
-
+
+
-
-
+
+
-
-
+
+
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 778a925afc5a5c..4bca899f3afb05 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 @@ internal enum IcmpV6StatType
}
// 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 63e45d7e1cbd8e..206fe170799c15 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 @@
+
+
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 52825142299cd6..b141b5ed3aab1d 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 @@
+
+
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 8069716509de41..31e565288099df 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 @@
+
+ Common\DisableRuntimeMarshalling.cs
+
@@ -104,7 +107,7 @@
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 d665d21b9ba06f..a71d01bc0b7943 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 @@
+
+
@@ -62,10 +65,8 @@
-
-
+
Common\System\Net\ArrayBuffer.cs
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 0a2f6aac79ea96..a437542c5ffe1f 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 @@
+
+
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 923277fbb82209..1cd0530a9d22dd 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 @@ private DynamicWinsockMethods(AddressFamily addressFamily, SocketType socketType
_protocolType = protocolType;
}
- private static T CreateDelegate([NotNull] ref T? cache, SafeSocketHandle socketHandle, string guidString) where T: Delegate
+ private static T CreateDelegate(Func functionPointerWrapper, [NotNull] ref T? cache, SafeSocketHandle socketHandle, string guidString) where T: Delegate
{
Guid guid = new Guid(guidString);
IntPtr ptr;
@@ -79,30 +79,243 @@ private static T CreateDelegate([NotNull] ref T? cache, SafeSocketHandle sock
throw new SocketException();
}
- Interlocked.CompareExchange(ref cache, Marshal.GetDelegateForFunctionPointer(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(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");
+
+ ///
+ /// 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.
+ ///
+ 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)_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)_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)_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)_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)_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)_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 @@ internal unsafe delegate bool AcceptExDelegate(
out int bytesReceived,
NativeOverlapped* overlapped);
- [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal delegate void GetAcceptExSockaddrsDelegate(
IntPtr buffer,
int receiveDataLength,
@@ -124,8 +336,6 @@ internal delegate void GetAcceptExSockaddrsDelegate(
out IntPtr remoteSocketAddress,
out int remoteSocketAddressLength);
-
- [UnmanagedFunctionPointer(CallingConvention.StdCall, SetLastError = true)]
internal unsafe delegate bool ConnectExDelegate(
SafeSocketHandle socketHandle,
IntPtr socketAddress,
@@ -135,14 +345,12 @@ internal unsafe delegate bool ConnectExDelegate(
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 @@ internal unsafe delegate SocketError WSARecvMsgDelegate(
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 1722de1aaabf3c..05ec85840fd082 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 @@ public static SocketError SetIPv6MulticastOption(SafeSocketHandle handle, Socket
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 321e2c0477ea87..857caebab61028 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 @@
Common\Interop\Windows\Normaliz\Interop.Normalization.cs
+
+ Common\DisableRuntimeMarshalling.cs
+
Common\SkipLocalsInit.cs
@@ -2372,4 +2375,4 @@
-
\ No newline at end of file
+
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 ce477e02c9ef7f..ee456befca94d5 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 @@ internal EventProvider(EventProviderType providerType)
/// reason the ETW Register call failed a NotSupported exception will be thrown.
///
//
- //
+ //
//
- //
+ //
//
internal unsafe void Register(EventSource eventSource)
{
@@ -234,7 +234,7 @@ public virtual void Close()
//
//
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 1ed1959ebd1261..b15601da4214f3 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 @@ public AssemblyDependencyResolver(string componentAssemblyPath!!)
{
// 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 @@ public AssemblyDependencyResolver(string componentAssemblyPath!!)
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 9a3c33326d44bf..00abe866653b7e 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 @@ public override void Initialize(AnalysisContext context)
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 @@ private void PrepareForAnalysis(CompilationStartAnalysisContext context)
{
var perCompilationAnalyzer = new PerCompilationAnalyzer(
generatedMarshallingAttribute,
- blittableTypeAttribute,
nativeMarshallingAttribute,
marshalUsingAttribute,
genericContiguousCollectionMarshallerAttribute,
@@ -236,7 +233,6 @@ private void PrepareForAnalysis(CompilationStartAnalysisContext context)
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 @@ private class PerCompilationAnalyzer
private readonly INamedTypeSymbol _structLayoutAttribute;
public PerCompilationAnalyzer(INamedTypeSymbol generatedMarshallingAttribute,
- INamedTypeSymbol blittableTypeAttribute,
INamedTypeSymbol nativeMarshallingAttribute,
INamedTypeSymbol marshalUsingAttribute,
INamedTypeSymbol genericContiguousCollectionMarshallerAttribute,
@@ -252,7 +247,6 @@ public PerCompilationAnalyzer(INamedTypeSymbol generatedMarshallingAttribute,
INamedTypeSymbol structLayoutAttribute)
{
_generatedMarshallingAttribute = generatedMarshallingAttribute;
- _blittableTypeAttribute = blittableTypeAttribute;
_nativeMarshallingAttribute = nativeMarshallingAttribute;
_marshalUsingAttribute = marshalUsingAttribute;
_genericContiguousCollectionMarshallerAttribute = genericContiguousCollectionMarshallerAttribute;
@@ -264,8 +258,6 @@ public void AnalyzeTypeDefinition(SymbolAnalysisContext context)
{
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 @@ public void AnalyzeTypeDefinition(SymbolAnalysisContext context)
// 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 @@ private void AnalyzeNativeMarshalerType(SymbolAnalysisContext context, ITypeSymb
// 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 2987b174a564a7..35b40c4196703e 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 @@ private static IncrementalStubGenerationContext CalculateStubInformation(IMethod
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 28136ba47c7b3e..69da1c04c06af5 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 @@ private static (ImmutableArray, IMarshallingGeneratorFactory)
}
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 744f1b611be697..a8c33b93818ec0 100644
--- a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs
+++ b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.Designer.cs
@@ -510,6 +510,15 @@ internal static string RefValuePropertyUnsupportedMessage {
}
}
+ ///
+ /// Looks up a localized string similar to .
+ ///
+ internal static string RuntimeMarshallingMustBeDisabled {
+ get {
+ return ResourceManager.GetString("RuntimeMarshallingMustBeDisabled", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to An abstract type derived from 'SafeHandle' cannot be marshalled by reference. The provided type must be concrete..
///
diff --git a/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx b/src/libraries/System.Runtime.InteropServices/gen/DllImportGenerator/Resources.resx
index c3f3d9694fc5a5..8a9d0f5b7e12e7 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 @@
The 'Value' property on the native type '{0}' must not be a 'ref' or 'readonly ref' property.
+
+
+
An abstract type derived from 'SafeHandle' cannot be marshalled by reference. The provided type must be concrete.
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 cb3f7dbe62ddb5..f0cd91ae0a01ce 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 @@
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 844899ef7f247f..3484e427130155 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 @@
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 @@ public class AttributedMarshallingModelGeneratorFactory : IMarshallingGeneratorF
public AttributedMarshallingModelGeneratorFactory(
IMarshallingGeneratorFactory innerMarshallingGenerator,
- InteropGenerationOptions options)
+ AttributedMarshallingModelOptions options)
{
Options = options;
_innerMarshallingGenerator = innerMarshallingGenerator;
@@ -30,7 +32,7 @@ public AttributedMarshallingModelGeneratorFactory(
public AttributedMarshallingModelGeneratorFactory(
IMarshallingGeneratorFactory innerMarshallingGenerator,
IMarshallingGeneratorFactory elementMarshallingGenerator,
- InteropGenerationOptions options)
+ AttributedMarshallingModelOptions options)
{
Options = options;
_innerMarshallingGenerator = innerMarshallingGenerator;
@@ -38,14 +40,21 @@ public AttributedMarshallingModelGeneratorFactory(
_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 @@ private IMarshallingGenerator CreateNativeCollectionMarshaller(
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 1d36a8789c9258..169911c3c92c35 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 @@ public IMarshallingGenerator Create(TypePositionInfo info, StubCodeContext conte
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 931fccaf1616ed..92533d720031e9 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 @@ private bool TryRehydrateMarshalAsAttribute(TypePositionInfo info, out Attribute
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 marshalAsArguments = new List
{
AttributeArgument(
@@ -51,17 +74,17 @@ private bool TryRehydrateMarshalAsAttribute(TypePositionInfo info, out Attribute
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 @@ private bool TryRehydrateMarshalAsAttribute(TypePositionInfo info, out Attribute
}
}
- if (collectionMarshalling.ElementMarshallingInfo is MarshalAsInfo elementMarshalAs)
+ if (elementMarshallingInfo is MarshalAsInfo elementMarshalAs)
{
marshalAsArguments.Add(
AttributeArgument(NameEquals("ArraySubType"), null,
@@ -94,9 +117,23 @@ public ParameterSyntax AsParameter(TypePositionInfo info)
.WithModifiers(TokenList(Token(info.RefKindSyntax)))
.WithType(info.ManagedType.Syntax);
+ List 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 00000000000000..faab7391260df1
--- /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
+ {
+ ///
+ /// Create an instance for marshalling the supplied type in the given position.
+ ///
+ /// Type details
+ /// Metadata about the stub the type is associated with
+ /// A instance.
+ 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
similarity index 93%
rename from src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshallingGeneratorFactory.cs
rename to src/libraries/System.Runtime.InteropServices/gen/Microsoft.Interop.SourceGeneration/Marshalling/MarshalAsMarshallingGeneratorFactory.cs
index 2170b4978b9d16..ca61227661f00b 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 @@
namespace Microsoft.Interop
{
- public interface IMarshallingGeneratorFactory
- {
- ///
- /// Create an instance for marshalling the supplied type in the given position.
- ///
- /// Type details
- /// Metadata about the stub the type is associated with
- /// A instance.
- 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 @@ public sealed class DefaultMarshallingGeneratorFactory : IMarshallingGeneratorFa
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;
}
///
@@ -123,7 +112,7 @@ public IMarshallingGenerator Create(
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 00000000000000..a12f702e1f7f40
--- /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 d1f659d125bb88..c151607c9721d6 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 @@ private NoMarshallingInfo() { }
/// An indication of "missing support" will trigger the fallback logic, which is
/// the forwarder marshaler.
///
- public sealed record MissingSupportMarshallingInfo : MarshallingInfo
- {
- public static readonly MarshallingInfo Instance = new MissingSupportMarshallingInfo();
-
- private MissingSupportMarshallingInfo() { }
- }
+ public record MissingSupportMarshallingInfo : MarshallingInfo;
///
/// Character encoding enumeration.
@@ -85,11 +80,9 @@ public sealed record MarshalAsInfo(
}
///
- /// 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.
///
- public sealed record BlittableTypeAttributeInfo : MarshallingInfo;
+ public sealed record UnmanagedBlittableMarshallingInfo : MarshallingInfo;
[Flags]
public enum CustomMarshallingFeatures
@@ -170,6 +163,18 @@ public sealed record NativeContiguousCollectionMarshallingInfo(
UseDefaultMarshalling
);
+
+ ///
+ /// 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.
+ ///
+ ///
+ /// An indication of "missing support" will trigger the fallback logic, which is
+ /// the forwarder marshaler.
+ ///
+ public sealed record MissingSupportCollectionMarshallingInfo(CountInfo CountInfo, MarshallingInfo ElementMarshallingInfo) : MissingSupportMarshallingInfo;
+
public sealed class MarshallingAttributeInfoParser
{
private readonly Compilation _compilation;
@@ -288,16 +293,7 @@ private MarshallingInfo GetMarshallingInfo(
{
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 @@ private MarshallingInfo GetMarshallingInfo(
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 @@ private MarshallingInfo GetMarshallingInfo(
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 @@ private MarshallingInfo CreateInfoFromMarshalAs(
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 @@ private bool TryCreateTypeBasedMarshallingInfo(
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 @@ private bool TryCreateTypeBasedMarshallingInfo(
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 @@ private bool TryCreateTypeBasedMarshallingInfo(
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 @@ private bool TryCreateTypeBasedMarshallingInfo(
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 1d254e29a5c230..499ffc63bca17e 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
@@ -303,6 +303,15 @@ internal static string RefValuePropertyUnsupportedMessage {
}
}
+ ///
+ /// Looks up a localized string similar to Runtime marshalling must be disabled in this project by applying the 'System.Runtime.InteropServices.DisableRuntimeMarshallingAttribute' to the assembly to enable marshalling this type..
+ ///
+ internal static string RuntimeMarshallingMustBeDisabled {
+ get {
+ return ResourceManager.GetString("RuntimeMarshallingMustBeDisabled", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to An abstract type derived from 'SafeHandle' cannot be marshalled by reference. The provided type must be concrete..
///
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 544a1ea46a212a..3b0e3a125213a9 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 @@
Only one of 'ConstantElementCount' or 'ElementCountInfo' may be used in a 'MarshalUsingAttribute' for a given 'ElementIndirectionLevel'
+
+ Runtime marshalling must be disabled in this project by applying the 'System.Runtime.InteropServices.DisableRuntimeMarshallingAttribute' to the assembly to enable marshalling this type.
+
\ 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 1925d2ece51bbf..8111b0787bc88a 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 @@ public static class TypeNames
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 @@ public static string Unsafe(InteropGenerationOptions options)
{
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 4f5aaf0cc7d7fc..c03e880f124b66 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 @@ private static bool HasOnlyBlittableFields(this ITypeSymbol type, ImmutableHashS
{
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 @@ private static bool HasOnlyBlittableFields(this ITypeSymbol type, ImmutableHashS
{
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 @@ private static bool HasOnlyBlittableFields(this ITypeSymbol type, ImmutableHashS
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(SymbolEqualityComparer.Default));
private static bool IsConsideredBlittable(this ITypeSymbol type, ImmutableHashSet 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 @@ public static TypeSyntax AsTypeSyntax(this ITypeSymbol type)
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 @@ or SpecialType.System_UInt32
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 94877b6888cce9..5fdc0af1b9630d 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
@@ -9,6 +9,11 @@
false
+
+
+
+
runtime; build; native; contentfiles; analyzers; buildtransitive
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 4f05e0e568e88c..a12cdd2245a309 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 @@
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 803904a9f98818..640ee220f088bf 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 @@ public class AdditionalAttributesOnStub
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 @@ public static IEnumerable
+
+
+
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 7307e2d836b798..4880ca0aa094d8 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
+
+
+
@@ -52,4 +56,4 @@ System.Security.Cryptography.ProtectedData
-
\ No newline at end of file
+
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 6499e5c2e944d2..2155c7384eff53 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 @@
+
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 0e12e3d1b3def2..24dce97806880f 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 @@
+
+
(sourceContext.SourceName, TOKEN_SOURCE.TOKEN_SOURCE_LENGTH));
+ }
if (sUserPrincipalName == null)
throw new ArgumentNullException(nameof(sUserPrincipalName));
@@ -179,13 +178,13 @@ public WindowsIdentity(string sUserPrincipalName)
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 fe1302370b388d..8b0d078026b8bb 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 @@
+
-
\ No newline at end of file
+
diff --git a/src/libraries/System.Speech/src/System.Speech.csproj b/src/libraries/System.Speech/src/System.Speech.csproj
index bf696506ec7eeb..7003b449eff78d 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
+
+
+
true
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 2266de2c9476d6..b2de19721e30a7 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
-
+
SR.PlatformNotSupported_System_Windows_Extensions
@@ -82,6 +82,10 @@ System.Security.Cryptography.X509Certificates.X509SelectionFlag
+
+
+
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 18c09a798794cd..a6b90e6f034d2d 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 @@ public static X509Certificate2Collection SelectFromCollection(X509Certificate2Co
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 @@ private static void DisplayX509Certificate(X509Certificate2 certificate, IntPtr
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();
+#endif
ViewInfo.hwndParent = hwndParent;
ViewInfo.dwFlags = 0;
ViewInfo.szTitle = null;
@@ -104,10 +109,18 @@ private static unsafe SafeCertStoreHandle SelectFromStore(SafeCertStoreHandle sa
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(ref native), ref Unsafe.As(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 @@ private static unsafe SafeCertStoreHandle SelectFromStore(SafeCertStoreHandle sa
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 291e226521e07e..67204f55feb047 100644
--- a/src/mono/mono/mini/method-to-ir.c
+++ b/src/mono/mono/mini/method-to-ir.c
@@ -7180,7 +7180,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 31a304a8d845e6..ec8096d80a3873 100644
--- a/src/tests/Common/CoreCLRTestLibrary/HostPolicyMock.cs
+++ b/src/tests/Common/CoreCLRTestLibrary/HostPolicyMock.cs
@@ -126,7 +126,18 @@ public Action LastSetErrorWriter
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);
+ }
+ };
}
}
}