c# – 在Windows 8 Pro Tablet中使用WinAPI引发AccessViolationE
发布时间:2020-12-15 17:47:45 所属栏目:百科 来源:网络整理
导读:我正在尝试使用Magnification API为32位 Windows 8 Pro平板电脑编写一个可访问性应用程序.应用程序可以完全放大和缩小全屏,但是当放大时,点击事件会发送到未屏幕屏幕的错误位置,因此用户不能直接触摸他所看到的内容. 为了解决这个问题,我试过MagSetInputTran
我正在尝试使用Magnification API为32位
Windows 8 Pro平板电脑编写一个可访问性应用程序.应用程序可以完全放大和缩小全屏,但是当放大时,点击事件会发送到未屏幕屏幕的错误位置,因此用户不能直接触摸他所看到的内容.
为了解决这个问题,我试过MagSetInputTransform(fSetInputTransform,rcSource,rcDest).它适用于64位Windows 8桌面,但是当我在平板电脑上测试时,我会收到以下错误: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at GTZoom.WinAPIMethods.MagSetInputTransform(Boolean fEnabled,RECT prcSource,RECT prcDest) at GTZoom.ZoomControl.SetInput(IntPtr hwndDlg,Boolean fSetInputTransform) in c:UsersAlpayKDesktopGTMagnifyGTMagnifyZoomControl.cs:line 113 at GTZoom.ZoomControl.trackBar1_Scroll(Object sender,EventArgs e) in c:UsersAlpayKDesktopGTMagnifyGTMagnifyZoomControl.cs:line 37 at System.Windows.Forms.TrackBar.OnScroll(EventArgs e) at System.Windows.Forms.TrackBar.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 当我尝试编译x86目标平台的项目并在64位机器下测试时,获得了完全相同的错误. 总结一下 Target platform x64 -> Tested under 64bit Windows 8 Desktop OK Target platform x86 -> Tested under 64bit Windows 8 Desktop ERROR Target platform x64 -> Tested under 64bit Windows 8 Tablet ERROR Target platform x86 -> Tested under 32bit Windows 8 Tablet ERROR ? 如何在32位Windows 8平板电脑中使用此WinAPI功能? EDIT1 这是产生错误的方法: void SetInput(IntPtr hwndDlg,bool fSetInputTransform) { bool fContinue = true; RECT rcSource = new RECT(); RECT rcDest = new RECT(); // MagSetInputTransform() is used to adjust pen and touch input to account for the current magnification. // The "Source" and "Destination" rectangles supplied to MagSetInputTransform() are from the perspective // of the currently magnified visuals. The source rectangle is the portion of the screen that is // currently being magnified,and the destination rectangle is the area on the screen which shows the // magnified results. // If we're setting an input transform,base the transform on the current fullscreen magnification. if (fSetInputTransform) { // Assume here the touch and pen input is going to the primary monitor. rcDest.Right = screenWidth; rcDest.Bottom = screenHeight; float magnificationFactor = 0; int xOffset = 0; int yOffset = 0; // Get the currently active magnification. if (WinAPIMethods.MagGetFullscreenTransform(ref magnificationFactor,ref xOffset,ref yOffset)) { // Determine the area of the screen being magnified. rcSource.Left = xOffset; rcSource.Top = yOffset; rcSource.Right = rcSource.Left + (int)(rcDest.Right / magnificationFactor); rcSource.Bottom = rcSource.Top + (int)(rcDest.Bottom / magnificationFactor); } else { // An unexpected error occurred trying to get the current magnification. fContinue = false; } } if (fContinue) { // Now set the input transform as required. if (!WinAPIMethods.MagSetInputTransform(fSetInputTransform,rcDest)) { MessageBox.Show("Err"); } } } EDIT2 以下是pinvoke签名: [DllImport("Magnification.dll",CallingConvention = CallingConvention.StdCall)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool MagGetFullscreenTransform(ref float magLevel,ref int xOffset,ref int yOffset); [DllImport("Magnification.dll",CallingConvention = CallingConvention.StdCall)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool MagSetInputTransform(bool fEnabled,RECT prcDest); 而this是我的RECT架构如何. 解决方法WinAPIMethods.MagSetInputTransform(fSetInputTransform,rcDest) WinAPIMethods.MagSetInputTransform(fSetInputTransform,ref rcSource,ref rcDest) 和pinvoke public static extern bool MagSetInputTransform(bool fEnabled,RECT prcDest); public static extern bool MagSetInputTransform(bool fEnabled,ref RECT prcSource,ref RECT prcDest); MagSetInputTransform采用LPRECT,而不是RECT 我不能解释为什么它在一台机器上工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 设计模式系列之单例模式(Singleton Pattern)——确保对象的
- ruby-on-rails – openid.ui.mode使用rails的openid_authen
- C#把UNICODE编码转换为GB编码的实例
- ajax中同步和异步的区别
- Sqlite:如何从C绑定和插入日期?
- Blazeds StreamingAMFChannel error for HTTP 1.0 protocol
- 使用ruby或python在文件中查找
- c# – 确定是否从用户输入发生了更改事件
- 在ListView的onItemClick里面操作list_item.xml里面的控件
- CefSharp.Wpf 添加flash与cookie支持