From a6d396046ab327281e5a436b8d525f0b51d2ce0c Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 3 Oct 2022 19:54:32 -0700 Subject: [PATCH] Fix Interop.Gdi32.StartDoc p/invoke (#76569) StartDoc takes a pointer to a DOCINFO struct. We had DOCINFO defined as a class on the managed side such that built-in marshalling would marshal it as a pointer. With the switch to custom marshalling via NativeMarshalling, we ended up marshalling the struct that is the native representation rather than a pointer to it. This switches the DOCINFO to a struct and updates the parameter to StartDoc to be in, such that it should be marshalled as a pointer to the struct by both generated and built-in marshalling. --- .../src/Interop/Windows/Interop.Gdi32.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs index 8b754d321fa26..192cc9b591fac 100644 --- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs +++ b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs @@ -52,7 +52,7 @@ internal static partial int StartDoc( #if NET7_0_OR_GREATER [MarshalUsing(typeof(HandleRefMarshaller))] #endif - HandleRef hDC, DOCINFO lpDocInfo); + HandleRef hDC, in DOCINFO lpDocInfo); [LibraryImport(Libraries.Gdi32, SetLastError = true)] internal static partial int StartPage( @@ -179,7 +179,7 @@ internal unsafe struct BITMAPINFO_FLAT [NativeMarshalling(typeof(Marshaller))] #endif [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] - internal sealed class DOCINFO + internal struct DOCINFO { internal int cbSize = 20; internal string? lpszDocName; @@ -187,6 +187,8 @@ internal sealed class DOCINFO internal string? lpszDatatype; internal int fwType; + public DOCINFO() { } + #if NET7_0_OR_GREATER [CustomMarshaller(typeof(DOCINFO), MarshalMode.ManagedToUnmanagedIn, typeof(Marshaller))] public static class Marshaller