且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

CreateProcess成功,但是GetLastError()返回拒绝访问

更新时间:2023-02-16 20:07:54

来自GetLastError

文档中用于设置最后一个错误代码的每个函数的返回值"部分都记录了该函数设置最后一个错误代码的条件.设置线程最后错误代码的大多数函数都会在失败时对其进行设置.但是,某些函数在成功时还会设置最后一个错误代码. [强调我的]

The Return Value section of the documentation for each function that sets the last-error code notes the conditions under which the function sets the last-error code. Most functions that set the thread's last-error code set it when they fail. However, some functions also set the last-error code when they succeed. [emphasis mine]

我认为您获得了有经验的结果,因为成功完成CreateProcess并没有设置错误值GetLastError返回.相反,您对GetLastError的调用会返回由另一个先前调用的函数设置的错误

I think you get the experienced outcome because, uppon success, CreateProcess does not set the error value GetLastError returns. Instead your call to GetLastError returns an error set by another function called earlier