切换增强指针精度

我们基本上是在创建一个控制面板小程序。 我们需要在鼠标属性中切换“增强指针精度”。
为此,我们需要使用SPI_GETMOUSE调用SystemParametersInfo 。 它有一个由3个元素组成的数组作为其第三个参数。 我是PInvoke的新手,我尝试了许多签名,但到目前为止还没有运气。 这是我为签名尝试的内容:

 [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool SystemParametersInfo(uint uiAction, uint uiParam, [MarshalAs(UnmanagedType.LPArray)] ref long[] vparam, SPIF fWinIni); static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref long[] vparam, SPIF fWinIni); 

以上都没有为我工作,这是我得到的例外:
System.AccessViolationException :尝试读取或写入受保护的内存。 这通常表明其他内存已损坏。
在搜索时我想出了这个在VB中。

解决方案:感谢GWLlosa的回答 ,我想出了解决方案:

 [DllImport("user32.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)] public static extern bool SystemParametersInfoGet(uint action, uint param, IntPtr vparam, SPIF fWinIni); public const UInt32 SPI_GETMOUSE = 0x0003; [DllImport("user32.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)] public static extern bool SystemParametersInfoSet(uint action, uint param, IntPtr vparam, SPIF fWinIni); public const UInt32 SPI_SETMOUSE = 0x0004; public static bool ToggleEnhancePointerPrecision(bool b) { int[] mouseParams = new int[3]; // Get the current values. SystemParametersInfoGet(SPI_GETMOUSE, 0, GCHandle.Alloc(mouseParams, GCHandleType.Pinned).AddrOfPinnedObject(), 0); // Modify the acceleration value as directed. mouseParams[2] = b ? 1 : 0; // Update the system setting. return SystemParametersInfoSet(SPI_SETMOUSE, 0, GCHandle.Alloc(mouseParams, GCHandleType.Pinned).AddrOfPinnedObject(), SPIF.SPIF_SENDCHANGE); } 

此文档也certificate是有用的。

你有没有尝试过:

 [DllImport("user32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] static extern bool SystemParametersInfo(SPI uiAction, uint uiParam, IntPtr pvParam, SPIF fWinIni); 

无耻地解除了:

http://www.pinvoke.net/default.aspx/user32/SystemParametersInfo.html