From f03cb346f96b7df49902e1fb211399903a069e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=98=E9=9B=85=E7=9A=84=E6=AF=8D=E9=B8=A1?= <710521324@qq.com> Date: Fri, 30 Aug 2024 09:42:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8LibraryImport?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 鼠标连点器/MainWindow.xaml.cs | 26 ++++++++++++++------------ 鼠标连点器/鼠标连点器.csproj | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/鼠标连点器/MainWindow.xaml.cs b/鼠标连点器/MainWindow.xaml.cs index 36c75b9..bf6073e 100644 --- a/鼠标连点器/MainWindow.xaml.cs +++ b/鼠标连点器/MainWindow.xaml.cs @@ -26,11 +26,13 @@ namespace 鼠标连点器 private const int VK_F8 = 0x77; // Virtual key code for F8 // Importing necessary Windows API functions - [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] - public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); + [LibraryImport("user32.dll", EntryPoint = "mouse_event")] + [UnmanagedCallConv(CallConvs = new Type[] { typeof(System.Runtime.CompilerServices.CallConvStdcall) })] + private static partial void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); - [DllImport("user32.dll")] - static extern bool GetCursorPos(out POINT lpPoint); + [LibraryImport("user32.dll", EntryPoint = "GetCursorPos")] + [return: MarshalAs(UnmanagedType.Bool)] + private static partial bool GetCursorPos(out POINT lpPoint); [StructLayout(LayoutKind.Sequential)] public struct POINT @@ -39,18 +41,18 @@ namespace 鼠标连点器 public int Y; } - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); + [LibraryImport("user32.dll", EntryPoint = "SetWindowsHookExW", SetLastError = true)] + private static partial IntPtr SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, IntPtr hMod, uint dwThreadId); - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + [LibraryImport("user32.dll", EntryPoint = "UnhookWindowsHookEx", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - private static extern bool UnhookWindowsHookEx(IntPtr hhk); + private static partial bool UnhookWindowsHookEx(IntPtr hhk); - [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] - private static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); + [LibraryImport("user32.dll", EntryPoint = "CallNextHookEx", SetLastError = true)] + private static partial IntPtr CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); - [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] - private static extern IntPtr GetModuleHandle(string lpModuleName); + [LibraryImport("kernel32.dll", EntryPoint = "GetModuleHandleW", SetLastError = true, StringMarshalling = StringMarshalling.Custom, StringMarshallingCustomType = typeof(System.Runtime.InteropServices.Marshalling.AnsiStringMarshaller))] + private static partial IntPtr GetModuleHandle(string lpModuleName); // Delegate for low-level keyboard proc private delegate IntPtr LowLevelKeyboardProc(int nCode, IntPtr wParam, IntPtr lParam); diff --git a/鼠标连点器/鼠标连点器.csproj b/鼠标连点器/鼠标连点器.csproj index e3e33e3..77662c5 100644 --- a/鼠标连点器/鼠标连点器.csproj +++ b/鼠标连点器/鼠标连点器.csproj @@ -6,6 +6,7 @@ enable enable true + true