【问题标题】:Error 998 (Invalid access to memory location) for when calling GetPointerFrameTouchInfo [duplicate]调用 GetPointerFrameTouchInfo 时出现错误 998(对内存位置的访问无效)[重复]
【发布时间】:2018-02-07 05:41:33
【问题描述】:

我正在尝试调用GetPointerFrameTouchInfo 函数来获取指针计数,但该函数似乎失败了

错误 998(对内存位置的访问无效)。

知道为什么会发生这种情况以及如何解决吗?
我正在尝试在钩子程序GetMsgProc 中调用相同的方法,如下所述:

LRESULT WINAPI GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    LPMSG lpMsg = (LPMSG)lParam;
    UINT32 pointerId = GET_POINTERID_WPARAM(lpMsg->wParam);
    switch (lpMsg->message)
    {
    case WM_POINTERUPDATE:
        UINT32 *pointerCount;
        POINTER_TOUCH_INFO *pointerTouchInfo;
        TCHAR outputLogTouchTst[100];

        if (GetPointerFrameTouchInfo(pointerId, pointerCount, pointerTouchInfo) == 0)
        {
            _stprintf(outputLogTouchTst, _T("Hook: The error code for proc is %d"), GetLastError());
            OutputDebugString(outputLogTouchTst);
            return CallNextHookEx(NULL, nCode, wParam, lParam);
        }

        _stprintf(outputLogTouchTst, _T("Hook: The count of pointers is %d"), pointerCount);
        OutputDebugString(outputLogTouchTst);
        return CallNextHookEx(NULL, nCode, wParam, lParam);
    }
    return CallNextHookEx(getmsghook, nCode, wParam, lParam);
}

【问题讨论】:

  • 您从未为pointerCountpointerTouchInfo 分配任何内存。

标签: c++ winapi hook


【解决方案1】:

您正在声明指针变量,但从未将它们设置为指向任何东西。您应该只声​​明普通变量,并将地址传递给函数。

constexpr maxpointers = 32;
UINT32 pointerCount = maxpointers;
POINTER_TOUCH_INFO pointerTouchInfo[maxpointers];

if (GetPointerFrameTouchInfo(pointerId, &pointerCount, pointerTouchInfo) == 0)

pointerTouchInfo 不必使用&;因为它是一个数组,所以当它用作函数参数时,它会自动衰减为一个指针。

【讨论】:

  • 我在这样做时遇到另一个错误,即列表迭代器不可递减
  • 这是您所提问题的答案
  • @Wolverine 你贴的代码中没有列表迭代,一定是不相关的代码。
  • @Barmar:抱歉,我收回了。我得到 WM_POINTERDOWN 的“列表迭代器不可递减”。我收到 WM_POINTERUPDATE 的错误代码 5(拒绝访问),这是我们当前的问题。
  • @DavidHeffernan 我的目标是成功运行函数 GetPointerFrameTouchInfo() 以获取指针计数,如问题中所述。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-10-16
  • 1970-01-01
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
  • 2017-11-05
  • 1970-01-01
相关资源
最近更新 更多