From 720e0ec5c6f64809f0d4f4263ec9942b013f415c Mon Sep 17 00:00:00 2001 From: hangy Date: Thu, 27 Oct 2022 18:15:37 +0200 Subject: [PATCH 1/7] Move Library names to Common directory --- .../Common/src/Interop/Windows/Interop.Libraries.cs | 4 ++++ .../src/Interop/Unix/Interop.Libraries.cs | 10 ---------- .../src/Interop/Windows/Interop.Libraries.cs | 13 ------------- .../src/System.Drawing.Common.csproj | 1 - 4 files changed, 4 insertions(+), 24 deletions(-) delete mode 100644 src/libraries/System.Drawing.Common/src/Interop/Unix/Interop.Libraries.cs delete mode 100644 src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Libraries.cs diff --git a/src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs index bc10bf0bea2c1..af66c1f796edc 100644 --- a/src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/Windows/Interop.Libraries.cs @@ -47,5 +47,9 @@ internal static partial class Libraries internal const string HostPolicy = "hostpolicy"; internal const string Ucrtbase = "ucrtbase.dll"; internal const string Xolehlp = "xolehlp.dll"; + internal const string Comdlg32 = "comdlg32.dll"; + internal const string Gdiplus = "gdiplus.dll"; + internal const string Oleaut32 = "oleaut32.dll"; + internal const string Winspool = "winspool.drv"; } } diff --git a/src/libraries/System.Drawing.Common/src/Interop/Unix/Interop.Libraries.cs b/src/libraries/System.Drawing.Common/src/Interop/Unix/Interop.Libraries.cs deleted file mode 100644 index b8330fee528b7..0000000000000 --- a/src/libraries/System.Drawing.Common/src/Interop/Unix/Interop.Libraries.cs +++ /dev/null @@ -1,10 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -internal static partial class Interop -{ - internal static partial class Libraries - { - internal const string Gdiplus = "gdiplus"; - } -} diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Libraries.cs b/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Libraries.cs deleted file mode 100644 index 9d7c8110206f1..0000000000000 --- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Libraries.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -internal static partial class Interop -{ - internal static partial class Libraries - { - internal const string Comdlg32 = "comdlg32.dll"; - internal const string Gdiplus = "gdiplus.dll"; - internal const string Oleaut32 = "oleaut32.dll"; - internal const string Winspool = "winspool.drv"; - } -} 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 df9c7ef864aed..10828f58e5118 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -217,7 +217,6 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con - From a672bf0defc0d8eacf60b877666ea6e59a723238 Mon Sep 17 00:00:00 2001 From: hangy Date: Thu, 27 Oct 2022 18:43:36 +0200 Subject: [PATCH 2/7] Move ExtractAssociatedIcon P/Invoke to Interop.ExtractAssociatedIcon.cs --- .../Interop/Windows/Shell32/Interop.ExtractAssociatedIcon.cs} | 0 .../System.Drawing.Common/src/System.Drawing.Common.csproj | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) rename src/libraries/{System.Drawing.Common/src/Interop/Windows/Interop.Shell32.cs => Common/src/Interop/Windows/Shell32/Interop.ExtractAssociatedIcon.cs} (100%) diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Shell32.cs b/src/libraries/Common/src/Interop/Windows/Shell32/Interop.ExtractAssociatedIcon.cs similarity index 100% rename from src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Shell32.cs rename to src/libraries/Common/src/Interop/Windows/Shell32/Interop.ExtractAssociatedIcon.cs 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 10828f58e5118..dedbc09829066 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -217,7 +217,6 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con - @@ -285,6 +284,8 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con Link="Common\Interop\Windows\Ole32\Interop.STATFLAG.cs" /> + Date: Thu, 27 Oct 2022 19:12:31 +0200 Subject: [PATCH 3/7] Move PrintDlg P/Invoke to Interop.PrintDlg.cs --- .../src/Interop/Windows/Comdlg32/Interop.PrintDlg.cs} | 0 .../System.Drawing.Common/src/System.Drawing.Common.csproj | 3 ++- 2 files changed, 2 insertions(+), 1 deletion(-) rename src/libraries/{System.Drawing.Common/src/Interop/Windows/Interop.Comdlg32.cs => Common/src/Interop/Windows/Comdlg32/Interop.PrintDlg.cs} (100%) diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Comdlg32.cs b/src/libraries/Common/src/Interop/Windows/Comdlg32/Interop.PrintDlg.cs similarity index 100% rename from src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Comdlg32.cs rename to src/libraries/Common/src/Interop/Windows/Comdlg32/Interop.PrintDlg.cs 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 dedbc09829066..87f35713ed1f7 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -214,7 +214,6 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con - @@ -224,6 +223,8 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con Link="Common\Interop\Windows\Interop.BOOL.cs" /> + Date: Thu, 27 Oct 2022 19:37:34 +0200 Subject: [PATCH 4/7] Move Kernel32 P/Invoke to Interop.*.cs --- .../Kernel32/Interop.GetSystemDefaultLCID.cs | 13 +++++++++++++ .../Windows/Kernel32/Interop.GlobalAlloc.cs | 19 +++++++++++++++++++ .../Windows/Kernel32/Interop.SelectObject.cs} | 11 ----------- .../src/System.Drawing.Common.csproj | 7 ++++++- 4 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetSystemDefaultLCID.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GlobalAlloc.cs rename src/libraries/{System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs => Common/src/Interop/Windows/Kernel32/Interop.SelectObject.cs} (58%) diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetSystemDefaultLCID.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetSystemDefaultLCID.cs new file mode 100644 index 0000000000000..968f87ac8eaaa --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GetSystemDefaultLCID.cs @@ -0,0 +1,13 @@ +// 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; + +internal static partial class Interop +{ + internal static partial class Kernel32 + { + [LibraryImport(Libraries.Kernel32, SetLastError = true)] + public static partial int GetSystemDefaultLCID(); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GlobalAlloc.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GlobalAlloc.cs new file mode 100644 index 0000000000000..9e25a94365b88 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.GlobalAlloc.cs @@ -0,0 +1,19 @@ +// 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 Kernel32 + { + [LibraryImport(Libraries.Kernel32, EntryPoint = "GlobalAlloc", SetLastError = true)] + internal static partial IntPtr IntGlobalAlloc(int uFlags, UIntPtr dwBytes); // size should be 32/64bits compatible + + internal static IntPtr GlobalAlloc(int uFlags, uint dwBytes) + { + return IntGlobalAlloc(uFlags, new UIntPtr(dwBytes)); + } + } +} diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SelectObject.cs similarity index 58% rename from src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs rename to src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SelectObject.cs index 42d5a7c50230f..efcc90a00fb25 100644 --- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Kernel32.cs +++ b/src/libraries/Common/src/Interop/Windows/Kernel32/Interop.SelectObject.cs @@ -11,17 +11,6 @@ internal static partial class Interop { internal static partial class Kernel32 { - [LibraryImport(Libraries.Kernel32, SetLastError = true)] - public static partial int GetSystemDefaultLCID(); - - [LibraryImport(Libraries.Kernel32, EntryPoint = "GlobalAlloc", SetLastError = true)] - internal static partial IntPtr IntGlobalAlloc(int uFlags, UIntPtr dwBytes); // size should be 32/64bits compatible - - internal static IntPtr GlobalAlloc(int uFlags, uint dwBytes) - { - return IntGlobalAlloc(uFlags, new UIntPtr(dwBytes)); - } - [LibraryImport(Libraries.Gdi32, SetLastError = true)] internal static partial IntPtr SelectObject( #if NET7_0_OR_GREATER 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 87f35713ed1f7..17c71811c752a 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -215,7 +215,6 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con - @@ -271,10 +270,16 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con Link="Common\Interop\Windows\Gdi32\Interop.SaveDC.cs" /> + + + Date: Thu, 27 Oct 2022 19:57:21 +0200 Subject: [PATCH 5/7] Move Winspool P/Invoke to Interop.*.cs --- .../Winspool/Interop.DeviceCapabilities.cs | 14 ++++++++++++++ .../Winspool/Interop.DocumentProperties.cs} | 6 ------ .../Windows/Winspool/Interop.EnumPrinters.cs | 17 +++++++++++++++++ .../src/System.Drawing.Common.csproj | 7 ++++++- 4 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Windows/Winspool/Interop.DeviceCapabilities.cs rename src/libraries/{System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs => Common/src/Interop/Windows/Winspool/Interop.DocumentProperties.cs} (71%) create mode 100644 src/libraries/Common/src/Interop/Windows/Winspool/Interop.EnumPrinters.cs diff --git a/src/libraries/Common/src/Interop/Windows/Winspool/Interop.DeviceCapabilities.cs b/src/libraries/Common/src/Interop/Windows/Winspool/Interop.DeviceCapabilities.cs new file mode 100644 index 0000000000000..5b2208f239d3f --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Winspool/Interop.DeviceCapabilities.cs @@ -0,0 +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 Winspool + { + [LibraryImport(Libraries.Winspool, EntryPoint = "DeviceCapabilitiesW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] + internal static partial int DeviceCapabilities(string pDevice, string pPort, short fwCapabilities, IntPtr pOutput, IntPtr /*DEVMODE*/ pDevMode); + } +} diff --git a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs b/src/libraries/Common/src/Interop/Windows/Winspool/Interop.DocumentProperties.cs similarity index 71% rename from src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs rename to src/libraries/Common/src/Interop/Windows/Winspool/Interop.DocumentProperties.cs index 60b611dd63f32..bf54cfb1b5b90 100644 --- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Winspool.cs +++ b/src/libraries/Common/src/Interop/Windows/Winspool/Interop.DocumentProperties.cs @@ -11,9 +11,6 @@ internal static partial class Interop { internal static partial class Winspool { - [LibraryImport(Libraries.Winspool, EntryPoint = "DeviceCapabilitiesW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] - internal static partial int DeviceCapabilities(string pDevice, string pPort, short fwCapabilities, IntPtr pOutput, IntPtr /*DEVMODE*/ pDevMode); - [LibraryImport(Libraries.Winspool, EntryPoint = "DocumentPropertiesW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] internal static partial int DocumentProperties( #if NET7_0_OR_GREATER @@ -39,8 +36,5 @@ internal static partial int DocumentProperties( [MarshalUsing(typeof(HandleRefMarshaller))] #endif HandleRef hPrinter, string pDeviceName, IntPtr /*DEVMODE*/ pDevModeOutput, IntPtr /*DEVMODE*/ pDevModeInput, int fMode); - - [LibraryImport(Libraries.Winspool, EntryPoint = "EnumPrintersW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] - internal static partial int EnumPrinters(int flags, string? name, int level, IntPtr pPrinterEnum/*buffer*/, int cbBuf, out int pcbNeeded, out int pcReturned); } } diff --git a/src/libraries/Common/src/Interop/Windows/Winspool/Interop.EnumPrinters.cs b/src/libraries/Common/src/Interop/Windows/Winspool/Interop.EnumPrinters.cs new file mode 100644 index 0000000000000..ca967e11d16d8 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Winspool/Interop.EnumPrinters.cs @@ -0,0 +1,17 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Winspool + { + [LibraryImport(Libraries.Winspool, EntryPoint = "EnumPrintersW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] + internal static partial int EnumPrinters(int flags, string? name, int level, IntPtr pPrinterEnum/*buffer*/, int cbBuf, out int pcbNeeded, out int pcReturned); + } +} 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 17c71811c752a..20bae83430e4d 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -216,7 +216,6 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con - @@ -304,6 +303,12 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con Link="Common\Interop\Windows\User32\Interop.NONCLIENTMETRICS.cs" /> + + + Date: Thu, 27 Oct 2022 20:28:04 +0200 Subject: [PATCH 6/7] Move User32 P/Invoke to Interop.*.cs --- .../Windows/User32/Interop.CopyImage.cs | 21 +++++ .../Interop.CreateIconFromResourceEx.cs | 17 +++++ .../Windows/User32/Interop.DestroyIcon.cs | 22 ++++++ .../Windows/User32/Interop.DrawIconEx.cs | 30 ++++++++ .../Windows/User32/Interop.GetIconInfo.cs | 32 ++++++++ .../User32/Interop.GetSystemMetrics.cs | 17 +++++ .../Windows/User32/Interop.LoadIcon.cs | 21 +++++ .../src/Interop/Windows/Interop.User32.cs | 76 ------------------- .../src/System.Drawing.Common.csproj | 15 +++- 9 files changed, 174 insertions(+), 77 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Windows/User32/Interop.CopyImage.cs create mode 100644 src/libraries/Common/src/Interop/Windows/User32/Interop.CreateIconFromResourceEx.cs create mode 100644 src/libraries/Common/src/Interop/Windows/User32/Interop.DestroyIcon.cs create mode 100644 src/libraries/Common/src/Interop/Windows/User32/Interop.DrawIconEx.cs create mode 100644 src/libraries/Common/src/Interop/Windows/User32/Interop.GetIconInfo.cs create mode 100644 src/libraries/Common/src/Interop/Windows/User32/Interop.GetSystemMetrics.cs create mode 100644 src/libraries/Common/src/Interop/Windows/User32/Interop.LoadIcon.cs delete mode 100644 src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.User32.cs diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.CopyImage.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.CopyImage.cs new file mode 100644 index 0000000000000..4211c156c3655 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.CopyImage.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; +using System.Runtime.InteropServices; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class User32 + { + [LibraryImport(Libraries.User32, 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); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.CreateIconFromResourceEx.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.CreateIconFromResourceEx.cs new file mode 100644 index 0000000000000..a295619f2ac4a --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.CreateIconFromResourceEx.cs @@ -0,0 +1,17 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class User32 + { + [LibraryImport(Libraries.User32, SetLastError = true)] + internal static unsafe partial IntPtr CreateIconFromResourceEx(byte* pbIconBits, uint cbIconBits, [MarshalAs(UnmanagedType.Bool)] bool fIcon, int dwVersion, int csDesired, int cyDesired, int flags); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.DestroyIcon.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.DestroyIcon.cs new file mode 100644 index 0000000000000..1528c6ae181eb --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.DestroyIcon.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. + +using System; +using System.Runtime.InteropServices; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class User32 + { + [LibraryImport(Libraries.User32, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool DestroyIcon( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hIcon); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.DrawIconEx.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.DrawIconEx.cs new file mode 100644 index 0000000000000..6ac69016bde60 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.DrawIconEx.cs @@ -0,0 +1,30 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class User32 + { + [LibraryImport(Libraries.User32, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + 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); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.GetIconInfo.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.GetIconInfo.cs new file mode 100644 index 0000000000000..e97f54e2e8f6e --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.GetIconInfo.cs @@ -0,0 +1,32 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class User32 + { + [LibraryImport(Libraries.User32, SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool GetIconInfo( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hIcon, ref ICONINFO info); + + [StructLayout(LayoutKind.Sequential)] + internal struct ICONINFO + { + internal uint fIcon; + internal uint xHotspot; + internal uint yHotspot; + internal IntPtr hbmMask; + internal IntPtr hbmColor; + } + } +} diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.GetSystemMetrics.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.GetSystemMetrics.cs new file mode 100644 index 0000000000000..761e69a4a2c82 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.GetSystemMetrics.cs @@ -0,0 +1,17 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class User32 + { + [LibraryImport(Libraries.User32, SetLastError = true)] + public static partial int GetSystemMetrics(int nIndex); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/User32/Interop.LoadIcon.cs b/src/libraries/Common/src/Interop/Windows/User32/Interop.LoadIcon.cs new file mode 100644 index 0000000000000..f391366d89b12 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/User32/Interop.LoadIcon.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; +using System.Runtime.InteropServices; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class User32 + { + [LibraryImport(Libraries.User32, EntryPoint = "LoadIconW", SetLastError = true)] + internal static partial IntPtr LoadIcon( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hInst, IntPtr iconId); + } +} 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 deleted file mode 100644 index 52ecb5f1ddde3..0000000000000 --- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.User32.cs +++ /dev/null @@ -1,76 +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 System; -using System.Runtime.InteropServices; -#if NET7_0_OR_GREATER -using System.Runtime.InteropServices.Marshalling; -#endif - -internal static partial class Interop -{ - internal static partial class User32 - { - [LibraryImport(Libraries.User32, EntryPoint = "LoadIconW", SetLastError = true)] - internal static partial IntPtr LoadIcon( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hInst, IntPtr iconId); - - [LibraryImport(Libraries.User32, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool DestroyIcon( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hIcon); - - [LibraryImport(Libraries.User32, 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); - - [LibraryImport(Libraries.User32, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - internal static partial bool GetIconInfo( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hIcon, ref ICONINFO info); - - [LibraryImport(Libraries.User32, SetLastError = true)] - public static partial int GetSystemMetrics(int nIndex); - - [LibraryImport(Libraries.User32, SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - 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); - - [LibraryImport(Libraries.User32, SetLastError = true)] - internal static unsafe partial IntPtr CreateIconFromResourceEx(byte* pbIconBits, uint cbIconBits, [MarshalAs(UnmanagedType.Bool)] bool fIcon, int dwVersion, int csDesired, int cyDesired, int flags); - - [StructLayout(LayoutKind.Sequential)] - internal struct ICONINFO - { - internal uint fIcon; - internal uint xHotspot; - internal uint yHotspot; - internal IntPtr hbmMask; - internal IntPtr hbmColor; - } - } -} 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 20bae83430e4d..dbf954dceb76a 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -215,7 +215,6 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con - @@ -291,8 +290,22 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con Link="Common\Interop\Windows\Ole32\Interop.STGM.cs" /> + + + + + + + Date: Thu, 27 Oct 2022 21:31:55 +0200 Subject: [PATCH 7/7] Move Gdi32 P/Invoke to Interop.*.cs --- .../Interop/Windows/Gdi32/Interop.AbortDoc.cs | 20 ++ .../Gdi32/Interop.AddFontResourceEx.cs | 19 ++ .../Windows/Gdi32/Interop.BITMAPINFO_FLAT.cs | 30 ++ .../Gdi32/Interop.CreateCompatibleBitmap.cs | 21 ++ .../Windows/Gdi32/Interop.CreateDIBSection.cs | 21 ++ .../Interop/Windows/Gdi32/Interop.DEVMODE.cs | 96 ++++++ .../Interop/Windows/Gdi32/Interop.EndDoc.cs | 20 ++ .../Interop/Windows/Gdi32/Interop.EndPage.cs | 20 ++ .../Windows/Gdi32/Interop.ExtEscape.cs | 31 ++ .../Windows/Gdi32/Interop.GetDIBits.cs | 26 ++ .../Windows/Gdi32/Interop.GetObject.cs | 47 +++ .../Gdi32/Interop.GetPaletteEntries.cs | 20 ++ .../Gdi32/Interop.IntersectClipRect.cs | 21 ++ .../Interop/Windows/Gdi32/Interop.ResetDC.cs | 25 ++ .../Interop/Windows/Gdi32/Interop.StartDoc.cs | 70 ++++ .../Windows/Gdi32/Interop.StartPage.cs | 20 ++ .../src/Interop/Windows/Interop.Gdi32.cs | 309 ------------------ .../src/System.Drawing.Common.csproj | 33 +- 18 files changed, 539 insertions(+), 310 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.AbortDoc.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.AddFontResourceEx.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.BITMAPINFO_FLAT.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateCompatibleBitmap.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateDIBSection.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.DEVMODE.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.EndDoc.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.EndPage.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.ExtEscape.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetDIBits.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetObject.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetPaletteEntries.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.IntersectClipRect.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.ResetDC.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.StartDoc.cs create mode 100644 src/libraries/Common/src/Interop/Windows/Gdi32/Interop.StartPage.cs delete mode 100644 src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.AbortDoc.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.AbortDoc.cs new file mode 100644 index 0000000000000..cca83bef74b6a --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.AbortDoc.cs @@ -0,0 +1,20 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial int AbortDoc( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.AddFontResourceEx.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.AddFontResourceEx.cs new file mode 100644 index 0000000000000..10aa264b72938 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.AddFontResourceEx.cs @@ -0,0 +1,19 @@ +// 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 Gdi32 + { + [LibraryImport(Libraries.Gdi32, EntryPoint = "AddFontResourceExW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] + internal static partial int AddFontResourceEx(string lpszFilename, int fl, IntPtr pdv); + + internal static int AddFontFile(string fileName) + { + return AddFontResourceEx(fileName, /*FR_PRIVATE*/ 0x10, IntPtr.Zero); + } + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.BITMAPINFO_FLAT.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.BITMAPINFO_FLAT.cs new file mode 100644 index 0000000000000..9cce923687de8 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.BITMAPINFO_FLAT.cs @@ -0,0 +1,30 @@ +// 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; + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + internal const int BITMAPINFO_MAX_COLORSIZE = 256; + + [StructLayout(LayoutKind.Sequential)] + internal unsafe struct BITMAPINFO_FLAT + { + public int bmiHeader_biSize; // = sizeof(BITMAPINFOHEADER) + public int bmiHeader_biWidth; + public int bmiHeader_biHeight; + public short bmiHeader_biPlanes; + public short bmiHeader_biBitCount; + public int bmiHeader_biCompression; + public int bmiHeader_biSizeImage; + public int bmiHeader_biXPelsPerMeter; + public int bmiHeader_biYPelsPerMeter; + public int bmiHeader_biClrUsed; + public int bmiHeader_biClrImportant; + + public fixed byte bmiColors[BITMAPINFO_MAX_COLORSIZE * 4]; // RGBQUAD structs... Blue-Green-Red-Reserved, repeat... + } + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateCompatibleBitmap.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateCompatibleBitmap.cs new file mode 100644 index 0000000000000..e051d8f8d7005 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateCompatibleBitmap.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; +using System.Runtime.InteropServices; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial IntPtr CreateCompatibleBitmap( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC, int width, int height); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateDIBSection.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateDIBSection.cs new file mode 100644 index 0000000000000..ca024801b4287 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.CreateDIBSection.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; +using System.Runtime.InteropServices; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial IntPtr CreateDIBSection( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hdc, ref BITMAPINFO_FLAT bmi, int iUsage, ref IntPtr ppvBits, IntPtr hSection, int dwOffset); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.DEVMODE.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.DEVMODE.cs new file mode 100644 index 0000000000000..aa26afa85665f --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.DEVMODE.cs @@ -0,0 +1,96 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + public sealed class DEVMODE + { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string? dmDeviceName; + public short dmSpecVersion; + public short dmDriverVersion; + public short dmSize; + public short dmDriverExtra; + public int dmFields; + public short dmOrientation; + public short dmPaperSize; + public short dmPaperLength; + public short dmPaperWidth; + public short dmScale; + public short dmCopies; + public short dmDefaultSource; + public short dmPrintQuality; + public short dmColor; + public short dmDuplex; + public short dmYResolution; + public short dmTTOption; + public short dmCollate; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] + public string? dmFormName; + public short dmLogPixels; + public int dmBitsPerPel; + public int dmPelsWidth; + public int dmPelsHeight; + public int dmDisplayFlags; + public int dmDisplayFrequency; + public int dmICMMethod; + public int dmICMIntent; + public int dmMediaType; + public int dmDitherType; + public int dmICCManufacturer; + public int dmICCModel; + public int dmPanningWidth; + public int dmPanningHeight; + + + public override string ToString() + { + return "[DEVMODE: " + + "dmDeviceName=" + dmDeviceName + + ", dmSpecVersion=" + dmSpecVersion + + ", dmDriverVersion=" + dmDriverVersion + + ", dmSize=" + dmSize + + ", dmDriverExtra=" + dmDriverExtra + + ", dmFields=" + dmFields + + ", dmOrientation=" + dmOrientation + + ", dmPaperSize=" + dmPaperSize + + ", dmPaperLength=" + dmPaperLength + + ", dmPaperWidth=" + dmPaperWidth + + ", dmScale=" + dmScale + + ", dmCopies=" + dmCopies + + ", dmDefaultSource=" + dmDefaultSource + + ", dmPrintQuality=" + dmPrintQuality + + ", dmColor=" + dmColor + + ", dmDuplex=" + dmDuplex + + ", dmYResolution=" + dmYResolution + + ", dmTTOption=" + dmTTOption + + ", dmCollate=" + dmCollate + + ", dmFormName=" + dmFormName + + ", dmLogPixels=" + dmLogPixels + + ", dmBitsPerPel=" + dmBitsPerPel + + ", dmPelsWidth=" + dmPelsWidth + + ", dmPelsHeight=" + dmPelsHeight + + ", dmDisplayFlags=" + dmDisplayFlags + + ", dmDisplayFrequency=" + dmDisplayFrequency + + ", dmICMMethod=" + dmICMMethod + + ", dmICMIntent=" + dmICMIntent + + ", dmMediaType=" + dmMediaType + + ", dmDitherType=" + dmDitherType + + ", dmICCManufacturer=" + dmICCManufacturer + + ", dmICCModel=" + dmICCModel + + ", dmPanningWidth=" + dmPanningWidth + + ", dmPanningHeight=" + dmPanningHeight + + "]"; + } + } + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.EndDoc.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.EndDoc.cs new file mode 100644 index 0000000000000..b65d8106b3439 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.EndDoc.cs @@ -0,0 +1,20 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial int EndDoc( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.EndPage.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.EndPage.cs new file mode 100644 index 0000000000000..f09232b01fbac --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.EndPage.cs @@ -0,0 +1,20 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial int EndPage( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.ExtEscape.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.ExtEscape.cs new file mode 100644 index 0000000000000..449ba1b934b33 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.ExtEscape.cs @@ -0,0 +1,31 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + internal const int QUERYESCSUPPORT = 8; + internal const int CHECKJPEGFORMAT = 4119; + internal const int CHECKPNGFORMAT = 4120; + + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial int ExtEscape( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC, int nEscape, int cbInput, ref int inData, int cbOutput, out int outData); + + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial int ExtEscape( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC, int nEscape, int cbInput, byte[] inData, int cbOutput, out int outData); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetDIBits.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetDIBits.cs new file mode 100644 index 0000000000000..03cbc74a846d5 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetDIBits.cs @@ -0,0 +1,26 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32)] + internal static partial int GetDIBits( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hdc, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hbm, int arg1, int arg2, IntPtr arg3, ref BITMAPINFO_FLAT bmi, int arg5); + + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetObject.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetObject.cs new file mode 100644 index 0000000000000..83fcfa6f9d235 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetObject.cs @@ -0,0 +1,47 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, EntryPoint = "GetObjectW", SetLastError = true)] + internal static partial int GetObject( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hObject, int nSize, ref BITMAP bm); + + [LibraryImport(Libraries.Gdi32, EntryPoint = "GetObjectW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] + internal static partial int GetObject( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hObject, int nSize, ref Interop.User32.LOGFONT lf); + + internal static unsafe int GetObject( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hObject, ref Interop.User32.LOGFONT lp) + => GetObject(hObject, sizeof(Interop.User32.LOGFONT), ref lp); + + [StructLayout(LayoutKind.Sequential)] + public struct BITMAP + { + public uint bmType; + public uint bmWidth; + public uint bmHeight; + public uint bmWidthBytes; + public ushort bmPlanes; + public ushort bmBitsPixel; + public IntPtr bmBits; + } + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetPaletteEntries.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetPaletteEntries.cs new file mode 100644 index 0000000000000..4f2f2ed803591 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.GetPaletteEntries.cs @@ -0,0 +1,20 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32)] + internal static partial uint GetPaletteEntries( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hpal, int iStartIndex, int nEntries, byte[] lppe); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.IntersectClipRect.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.IntersectClipRect.cs new file mode 100644 index 0000000000000..a82d6c5514ed2 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.IntersectClipRect.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; +using System.Runtime.InteropServices; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial int IntersectClipRect( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC, int x1, int y1, int x2, int y2); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.ResetDC.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.ResetDC.cs new file mode 100644 index 0000000000000..3737f3f46699b --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.ResetDC.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. + +using System; +using System.Runtime.InteropServices; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, EntryPoint = "ResetDCW", SetLastError = true)] + internal static partial IntPtr /*HDC*/ ResetDC( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC, +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef /*DEVMODE*/ lpDevMode); + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.StartDoc.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.StartDoc.cs new file mode 100644 index 0000000000000..c62da1844b8e6 --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.StartDoc.cs @@ -0,0 +1,70 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, EntryPoint = "StartDocW", SetLastError = true)] + internal static partial int StartDoc( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC, in DOCINFO lpDocInfo); + +#if NET7_0_OR_GREATER + [NativeMarshalling(typeof(Marshaller))] +#endif + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] + internal struct DOCINFO + { + internal int cbSize = 20; + internal string? lpszDocName; + internal string? lpszOutput; + internal string? lpszDatatype; + internal int fwType; + + public DOCINFO() { } + +#if NET7_0_OR_GREATER + [CustomMarshaller(typeof(DOCINFO), MarshalMode.ManagedToUnmanagedIn, typeof(Marshaller))] + public static class Marshaller + { + public static Native ConvertToUnmanaged(DOCINFO managed) => new(managed); + public static void Free(Native native) => native.FreeNative(); + + 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 + } + } +} diff --git a/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.StartPage.cs b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.StartPage.cs new file mode 100644 index 0000000000000..00ecc844d7e8a --- /dev/null +++ b/src/libraries/Common/src/Interop/Windows/Gdi32/Interop.StartPage.cs @@ -0,0 +1,20 @@ +// 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; +#if NET7_0_OR_GREATER +using System.Runtime.InteropServices.Marshalling; +#endif + +internal static partial class Interop +{ + internal static partial class Gdi32 + { + [LibraryImport(Libraries.Gdi32, SetLastError = true)] + internal static partial int StartPage( +#if NET7_0_OR_GREATER + [MarshalUsing(typeof(HandleRefMarshaller))] +#endif + HandleRef hDC); + } +} 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 deleted file mode 100644 index 192cc9b591fac..0000000000000 --- a/src/libraries/System.Drawing.Common/src/Interop/Windows/Interop.Gdi32.cs +++ /dev/null @@ -1,309 +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 System; -using System.Runtime.InteropServices; -#if NET7_0_OR_GREATER -using System.Runtime.InteropServices.Marshalling; -#endif - -internal static partial class Interop -{ - internal static partial class Gdi32 - { - internal const int QUERYESCSUPPORT = 8; - internal const int CHECKJPEGFORMAT = 4119; - internal const int CHECKPNGFORMAT = 4120; - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial IntPtr CreateCompatibleBitmap( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC, int width, int height); - - [LibraryImport(Libraries.Gdi32)] - internal static partial int GetDIBits( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hdc, -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hbm, int arg1, int arg2, IntPtr arg3, ref BITMAPINFO_FLAT bmi, int arg5); - - [LibraryImport(Libraries.Gdi32)] - internal static partial uint GetPaletteEntries( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hpal, int iStartIndex, int nEntries, byte[] lppe); - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial IntPtr CreateDIBSection( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hdc, ref BITMAPINFO_FLAT bmi, int iUsage, ref IntPtr ppvBits, IntPtr hSection, int dwOffset); - - [LibraryImport(Libraries.Gdi32, EntryPoint = "StartDocW", SetLastError = true)] - internal static partial int StartDoc( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC, in DOCINFO lpDocInfo); - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial int StartPage( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC); - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial int EndPage( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC); - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial int AbortDoc( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC); - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial int EndDoc( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC); - - [LibraryImport(Libraries.Gdi32, EntryPoint = "ResetDCW", SetLastError = true)] - internal static partial IntPtr /*HDC*/ ResetDC( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC, -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef /*DEVMODE*/ lpDevMode); - - [LibraryImport(Libraries.Gdi32, EntryPoint = "AddFontResourceExW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] - internal static partial int AddFontResourceEx(string lpszFilename, int fl, IntPtr pdv); - - internal static int AddFontFile(string fileName) - { - return AddFontResourceEx(fileName, /*FR_PRIVATE*/ 0x10, IntPtr.Zero); - } - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial int ExtEscape( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC, int nEscape, int cbInput, ref int inData, int cbOutput, out int outData); - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial int ExtEscape( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC, int nEscape, int cbInput, byte[] inData, int cbOutput, out int outData); - - [LibraryImport(Libraries.Gdi32, SetLastError = true)] - internal static partial int IntersectClipRect( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hDC, int x1, int y1, int x2, int y2); - - [LibraryImport(Libraries.Gdi32, EntryPoint = "GetObjectW", SetLastError = true)] - internal static partial int GetObject( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hObject, int nSize, ref BITMAP bm); - - [LibraryImport(Libraries.Gdi32, EntryPoint = "GetObjectW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] - internal static partial int GetObject( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hObject, int nSize, ref Interop.User32.LOGFONT lf); - - internal static unsafe int GetObject( -#if NET7_0_OR_GREATER - [MarshalUsing(typeof(HandleRefMarshaller))] -#endif - HandleRef hObject, ref Interop.User32.LOGFONT lp) - => GetObject(hObject, sizeof(Interop.User32.LOGFONT), ref lp); - - [StructLayout(LayoutKind.Sequential)] - public struct BITMAP - { - public uint bmType; - public uint bmWidth; - public uint bmHeight; - public uint bmWidthBytes; - public ushort bmPlanes; - public ushort bmBitsPixel; - public IntPtr bmBits; - } - - internal const int BITMAPINFO_MAX_COLORSIZE = 256; - - [StructLayout(LayoutKind.Sequential)] - internal unsafe struct BITMAPINFO_FLAT - { - public int bmiHeader_biSize; // = sizeof(BITMAPINFOHEADER) - public int bmiHeader_biWidth; - public int bmiHeader_biHeight; - public short bmiHeader_biPlanes; - public short bmiHeader_biBitCount; - public int bmiHeader_biCompression; - public int bmiHeader_biSizeImage; - public int bmiHeader_biXPelsPerMeter; - public int bmiHeader_biYPelsPerMeter; - public int bmiHeader_biClrUsed; - public int bmiHeader_biClrImportant; - - public fixed byte bmiColors[BITMAPINFO_MAX_COLORSIZE * 4]; // RGBQUAD structs... Blue-Green-Red-Reserved, repeat... - } - -#if NET7_0_OR_GREATER - [NativeMarshalling(typeof(Marshaller))] -#endif - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] - internal struct DOCINFO - { - internal int cbSize = 20; - internal string? lpszDocName; - internal string? lpszOutput; - internal string? lpszDatatype; - internal int fwType; - - public DOCINFO() { } - -#if NET7_0_OR_GREATER - [CustomMarshaller(typeof(DOCINFO), MarshalMode.ManagedToUnmanagedIn, typeof(Marshaller))] - public static class Marshaller - { - public static Native ConvertToUnmanaged(DOCINFO managed) => new(managed); - public static void Free(Native native) => native.FreeNative(); - - 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)] - public sealed class DEVMODE - { - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] - public string? dmDeviceName; - public short dmSpecVersion; - public short dmDriverVersion; - public short dmSize; - public short dmDriverExtra; - public int dmFields; - public short dmOrientation; - public short dmPaperSize; - public short dmPaperLength; - public short dmPaperWidth; - public short dmScale; - public short dmCopies; - public short dmDefaultSource; - public short dmPrintQuality; - public short dmColor; - public short dmDuplex; - public short dmYResolution; - public short dmTTOption; - public short dmCollate; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] - public string? dmFormName; - public short dmLogPixels; - public int dmBitsPerPel; - public int dmPelsWidth; - public int dmPelsHeight; - public int dmDisplayFlags; - public int dmDisplayFrequency; - public int dmICMMethod; - public int dmICMIntent; - public int dmMediaType; - public int dmDitherType; - public int dmICCManufacturer; - public int dmICCModel; - public int dmPanningWidth; - public int dmPanningHeight; - - - public override string ToString() - { - return "[DEVMODE: " - + "dmDeviceName=" + dmDeviceName - + ", dmSpecVersion=" + dmSpecVersion - + ", dmDriverVersion=" + dmDriverVersion - + ", dmSize=" + dmSize - + ", dmDriverExtra=" + dmDriverExtra - + ", dmFields=" + dmFields - + ", dmOrientation=" + dmOrientation - + ", dmPaperSize=" + dmPaperSize - + ", dmPaperLength=" + dmPaperLength - + ", dmPaperWidth=" + dmPaperWidth - + ", dmScale=" + dmScale - + ", dmCopies=" + dmCopies - + ", dmDefaultSource=" + dmDefaultSource - + ", dmPrintQuality=" + dmPrintQuality - + ", dmColor=" + dmColor - + ", dmDuplex=" + dmDuplex - + ", dmYResolution=" + dmYResolution - + ", dmTTOption=" + dmTTOption - + ", dmCollate=" + dmCollate - + ", dmFormName=" + dmFormName - + ", dmLogPixels=" + dmLogPixels - + ", dmBitsPerPel=" + dmBitsPerPel - + ", dmPelsWidth=" + dmPelsWidth - + ", dmPelsHeight=" + dmPelsHeight - + ", dmDisplayFlags=" + dmDisplayFlags - + ", dmDisplayFrequency=" + dmDisplayFrequency - + ", dmICMMethod=" + dmICMMethod - + ", dmICMIntent=" + dmICMIntent - + ", dmMediaType=" + dmMediaType - + ", dmDitherType=" + dmDitherType - + ", dmICCManufacturer=" + dmICCManufacturer - + ", dmICCModel=" + dmICCModel - + ", dmPanningWidth=" + dmPanningWidth - + ", dmPanningHeight=" + dmPanningHeight - + "]"; - } - } - } -} 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 dbf954dceb76a..c800556093959 100644 --- a/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj +++ b/src/libraries/System.Drawing.Common/src/System.Drawing.Common.csproj @@ -214,7 +214,6 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con - @@ -222,12 +221,22 @@ Since .NET 7, non-Windows platforms are not supported, even with the runtime con Link="Common\Interop\Windows\Interop.Libraries.cs" /> + + + + + + + + + + + + + + + +