[英]WinAPI AttachConsole?
I have the following code and I'm not sure if it should be == TRUE
or != FALSE
. 我有以下代码,但不确定是否应该
== TRUE
或!= FALSE
。
This is the code now: 这是现在的代码:
void AttachConsole() {
bool has_console = ::AttachConsole(ATTACH_PARENT_PROCESS) == TRUE;
if (!has_console) {
// We weren't launched from a console, so just return.
// We could alloc our own console, but meh:
// has_console = AllocConsole() == TRUE;
has_console_attached_ = false;
return;
}
has_console_attached_ = true;
}
I think it should be != FALSE
but I'm not sure? 我认为应该是
!= FALSE
但不确定吗?
The return value is documented only as being 0 for failure or non-zero for success. 返回值仅记录为0(表示失败)或非零(表示成功)。
So yes, you could use != FALSE
or you could just use: 所以是的,您可以使用
!= FALSE
或仅使用:
bool has_console = ::AttachConsole(ATTACH_PARENT_PROCESS);
The conversion from BOOL (really an integer) to bool
will convert 0 to false
, and anything else to true
--exactly what you want. 从布尔(真的是一个整数)的转换
bool
将0转换为false
,并且还有别的事情要true
--exactly你想要什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.