Error 998 (Invalid access to memory location) for when calling GetPointerFrameTouchInfo [duplicate]

浪尽此生 提交于 2021-02-17 05:52:25

问题


I am trying to call the GetPointerFrameTouchInfo function to get the pointer count but the function seems to fail with

Error 998 (Invalid access to memory location).

Any idea why that is happening and how I can resolve it?
I am trying to call the same inside the hook procedure GetMsgProc as mentioned below:

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);
}

回答1:


You're declaring pointer variables but never setting them to point to anything. You should just declare ordinary variables, and pass the addresses to the function.

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

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

It's not necessary to use & for pointerTouchInfo; since it's an array, it automatically decays to a pointer when used as a function argument.



来源:https://stackoverflow.com/questions/48652286/error-998-invalid-access-to-memory-location-for-when-calling-getpointerframeto

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!