CreateProcess succeeds, but GetLastError() returns access denied

拜拜、爱过 提交于 2019-12-01 12:46:01

From the documentation of 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]

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

GetLastError is only meaningful when the documentation states it is meaningful.

GetLastError returns the Win32 thread last error set with SetLastError. Since functions are only supposed to set or clear the last error when it is documented that they do so, if that hasn't happened, the last error may well contain an earlier error which is not relevant.

It is documented that CreateProcess will set the last error if it fails, not if it succeeds. So you should ignore it.

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