diff options
| author | Isaac Marovitz <42140194+IsaacMarovitz@users.noreply.github.com> | 2022-12-15 12:07:31 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-15 18:07:31 +0100 |
| commit | 0fbcd630bc57885d6b94fd3c4b3546493e09059e (patch) | |
| tree | 8e1f74775d3393d85e86a845c119a43907459884 /Ryujinx.Ava/Ui/Controls | |
| parent | f4d731ae2094128dcd1dc4a4be60b068047a77a7 (diff) | |
Replace `DllImport` usage with `LibraryImport` (#4084)
* Replace usage of `DllImport` with `LibraryImport`
* Mark methods as `partial`
* Marshalling
* More `partial` & marshalling
* More `partial` and marshalling
* More partial and marshalling
* Update GdiPlusHelper to LibraryImport
* Unicorn
* More Partial
* Marshal
* Specify EntryPoint
* Specify EntryPoint
* Change GlobalMemoryStatusEx to LibraryImport
* Change RegisterClassEx to LibraryImport
* Define EntryPoints
* Update Ryujinx.Ava/Ui/Controls/Win32NativeInterop.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Move return mashal
* Remove calling convention specification
* Remove calling conventions
* Update Ryujinx.Common/SystemInfo/WindowsSystemInfo.cs
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
* Update Ryujinx/Modules/Updater/Updater.cs
Co-authored-by: Mary-nyan <thog@protonmail.com>
* Update Ryujinx.Ava/Modules/Updater/Updater.cs
Co-authored-by: Mary-nyan <thog@protonmail.com>
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
Co-authored-by: Mary-nyan <thog@protonmail.com>
Diffstat (limited to 'Ryujinx.Ava/Ui/Controls')
| -rw-r--r-- | Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs | 8 | ||||
| -rw-r--r-- | Ryujinx.Ava/Ui/Controls/Win32NativeInterop.cs | 52 |
2 files changed, 28 insertions, 32 deletions
diff --git a/Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs b/Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs index 26007591..05b2cc5b 100644 --- a/Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs +++ b/Ryujinx.Ava/Ui/Controls/EmbeddedWindow.cs @@ -125,9 +125,9 @@ namespace Ryujinx.Ava.Ui.Controls { cbSize = Marshal.SizeOf<WNDCLASSEX>(), hInstance = GetModuleHandle(null), - lpfnWndProc = _wndProcDelegate, + lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_wndProcDelegate), style = ClassStyles.CS_OWNDC, - lpszClassName = _className, + lpszClassName = Marshal.StringToHGlobalUni(_className), hCursor = LoadCursor(IntPtr.Zero, (IntPtr)Cursors.IDC_ARROW) }; @@ -148,7 +148,9 @@ namespace Ryujinx.Ava.Ui.Controls IntPtr.Zero); WindowHandle = handle; - + + Marshal.FreeHGlobal(wndClassEx.lpszClassName); + return new PlatformHandle(WindowHandle, "HWND"); } diff --git a/Ryujinx.Ava/Ui/Controls/Win32NativeInterop.cs b/Ryujinx.Ava/Ui/Controls/Win32NativeInterop.cs index 124536d9..81e2fee9 100644 --- a/Ryujinx.Ava/Ui/Controls/Win32NativeInterop.cs +++ b/Ryujinx.Ava/Ui/Controls/Win32NativeInterop.cs @@ -5,7 +5,7 @@ using System.Runtime.Versioning; namespace Ryujinx.Ava.Ui.Controls { [SupportedOSPlatform("windows")] - internal class Win32NativeInterop + internal partial class Win32NativeInterop { [Flags] public enum ClassStyles : uint @@ -48,58 +48,52 @@ namespace Ryujinx.Ava.Ui.Controls [UnmanagedFunctionPointer(CallingConvention.Winapi)] internal delegate IntPtr WindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam); - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] + [StructLayout(LayoutKind.Sequential)] public struct WNDCLASSEX { public int cbSize; public ClassStyles style; - [MarshalAs(UnmanagedType.FunctionPtr)] - public WindowProc lpfnWndProc; // not WndProc + public IntPtr lpfnWndProc; // not WndProc public int cbClsExtra; public int cbWndExtra; public IntPtr hInstance; public IntPtr hIcon; public IntPtr hCursor; public IntPtr hbrBackground; - [MarshalAs(UnmanagedType.LPWStr)] - public string lpszMenuName; - [MarshalAs(UnmanagedType.LPWStr)] - public string lpszClassName; + public IntPtr lpszMenuName; + public IntPtr lpszClassName; public IntPtr hIconSm; - public static WNDCLASSEX Create() + public WNDCLASSEX() { - return new WNDCLASSEX - { - cbSize = Marshal.SizeOf<WNDCLASSEX>() - }; + cbSize = Marshal.SizeOf<WNDCLASSEX>(); } } - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - public static extern ushort RegisterClassEx(ref WNDCLASSEX param); + [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "RegisterClassExW")] + public static partial ushort RegisterClassEx(ref WNDCLASSEX param); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - public static extern short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance); + [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "UnregisterClassW")] + public static partial short UnregisterClass([MarshalAs(UnmanagedType.LPWStr)] string lpClassName, IntPtr instance); - [DllImport("user32.dll", CharSet = CharSet.Unicode)] - public static extern IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam); + [LibraryImport("user32.dll", EntryPoint = "DefWindowProcW")] + public static partial IntPtr DefWindowProc(IntPtr hWnd, WindowsMessages msg, IntPtr wParam, IntPtr lParam); - [DllImport("kernel32.dll")] - public static extern IntPtr GetModuleHandle(string lpModuleName); + [LibraryImport("kernel32.dll", EntryPoint = "GetModuleHandleA")] + public static partial IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPStr)] string lpModuleName); - [DllImport("user32.dll", SetLastError = true)] + [LibraryImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool DestroyWindow(IntPtr hwnd); + public static partial bool DestroyWindow(IntPtr hwnd); - [DllImport("user32.dll", SetLastError = true)] - public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName); + [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "LoadCursorA")] + public static partial IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] - public static extern IntPtr CreateWindowEx( + [LibraryImport("user32.dll", SetLastError = true, EntryPoint = "CreateWindowExW")] + public static partial IntPtr CreateWindowEx( uint dwExStyle, - string lpClassName, - string lpWindowName, + [MarshalAs(UnmanagedType.LPWStr)] string lpClassName, + [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, WindowStyles dwStyle, int x, int y, |
