Home  >  Q&A  >  body text

c++ - getthreadcontext 返回值:87,请问如何解决

在windows7 x64平台,调用getthreadcontext 返回值:87, 请问如何解决,windbg调试该内核API吗?
关键代码:

CONTEXT cxt;
SuspendThread(hThread);

ZeroMemory(&cxt, sizeof(cxt));
cxt.ContextFlags = CONTEXT_FULL;
if (!GetThreadContext(hThread, &cxt)) {
    printf("GetThreadContext getlasterror: %d", GetLastError());
    goto finish;
}

//hThread是有效的句柄,vs2015可以跟踪代码执行到printf出错的位置,然后就返回87了

高洛峰高洛峰2714 days ago735

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 14:50:18

    Turn off domestic security software such as 360.

    reply
    0
  • 阿神

    阿神2017-04-17 14:50:18

    getThreadContextIf an error occurs, 0 is returned. Here printf prints the error code.
    Regarding the error code, the relevant meaning is here https://msdn.microsoft.com/en-us/library/ms681382(v=vs.85).aspx.aspx)

    The cause of error code 87 (that is, 0x57) is 参数错误.
    You did not check whether SuspendThread suspending the thread was successful. You can check it now.
    And when you open the thread, do you have query permission (THREAD_GET_CONTEXT/WOW64THREAD_QUERY_INFORMATION)

    If you are compiling a 64-bit program, should you use Wow64SuspendThread/Wow64GetThreadContext

    reply
    0
  • Cancelreply