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