Подтвердить что ты не робот

AccessViolationException выбрано с помощью WinAPI в Windows 8 Pro Tablet

Я пытаюсь написать приложение для доступа к 32-разрядному планшетному ПК с Windows 8 Pro, используя API увеличения. Приложение может полностью масштабировать и изменять масштаб экрана в полноэкранном режиме, но при увеличении масштаба события щелчка отправляются в неправильные места экрана без указания причины, поэтому пользователь не может точно понять, что он видит.

Чтобы решить эту проблему, я попробовал MagSetInputTransform(fSetInputTransform, rcSource, rcDest). Он работает на 64-битной Windows 8 desktop, но когда я тестирую его на планшете, я получаю следующую ошибку:

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:\Users\AlpayK\Desktop\GTMagnify\GTMagnify\ZoomControl.cs:line 113
   at GTZoom.ZoomControl.trackBar1_Scroll(Object sender, EventArgs e) in c:\Users\AlpayK\Desktop\GTMagnify\GTMagnify\ZoomControl.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 ?

Как я могу использовать эту функцию WinAPI в 32-разрядном планшете Windows 8?

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, rcSource, rcDest))
                {
                    MessageBox.Show("Err");
                }
            }
        }

EDIT2

Вот сигнатуры пинвокей:

[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 prcSource, RECT prcDest);

И это, как выглядит моя структура RECT.

4b9b3361

Ответ 1

WinAPIMethods.MagSetInputTransform(fSetInputTransform, rcSource, rcDest)
WinAPIMethods.MagSetInputTransform(fSetInputTransform, ref rcSource, ref rcDest)

и pinvoke

public static extern bool MagSetInputTransform(bool fEnabled, RECT prcSource, RECT prcDest);
public static extern bool MagSetInputTransform(bool fEnabled, ref RECT prcSource, ref RECT prcDest);

MagSetInputTransform принимает LPRECT s, а не RECT s

Я не могу объяснить, почему он работал на одной машине.