[英]PeekNamedPipe fails, but GetLastError returns 0
I'm confused by the Windows API. 我对Windows API感到困惑。 I try to see if there are bytes left in an anonymous pipe using
PeekNamedPipe
. 我尝试使用
PeekNamedPipe
来查看匿名管道中是否还有字节。 This function fails, but GetLastError()
does not return an error. 该函数失败,但是
GetLastError()
不会返回错误。
The relevant part of my code is 我的代码的相关部分是
if( !PeekNamedPipe( handle, NULL, 0, NULL, &numBytesAvailable, NULL ) )
throw PeekNamedPipeException( "GetLastError() returned " + std::to_string( GetLastError() ) );
This throws an error, generating the following message: 这将引发错误,并生成以下消息:
terminate called after throwing an instance of 'PeekNamedPipeException'
what(): GetLastError() returned 0
But if PeekNamedPipe
fails, GetLastError
should not return 0 ( == ERROR_SUCCESS
), right? 但是,如果
PeekNamedPipe
失败,则GetLastError
不应返回0( == ERROR_SUCCESS
),对吗?
Thank you for your help! 谢谢您的帮助!
It's probably because more system functions are called (behind the scenes) between the PeekNamedPipe
and your call to GetLastError
. 可能是因为在
PeekNamedPipe
和您对GetLastError
的调用之间(在幕后)调用了更多的系统功能。
Store the value from GetLastError
in a temporary variable, and use that when constructing the string. 将
GetLastError
中的值存储在一个临时变量中,并在构造字符串时使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.