哪个 HRESULT 文字常量将使 SUCCEEDED() 宏失败?
SUCCEEDED() 的定义: #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
背景:当单击对话框上的“确定”按钮时,我需要返回一个HRESULT
值 hr
使得 SUCCEEDED(hr)
为 true。如果单击“取消”按钮,我需要返回一个负值。我本可以使用布尔值,但这会破坏现有模式(通常 hr 值来自系统 dll 的深度)。所以,我知道我可以在“确定”时返回 S_OK
,但在“取消”时返回什么?我可以return (HRESULT)-1;
,但一定有更好的方法 - 一些具有负值并代表一般失败的 HRESULT 文字常量。 S_FALSE
不是,因为它的值定义为1L
。
请帮我找到正确的常数。
Definition of SUCCEEDED(): #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
Background: When an Ok button is clicked on a dialog, I need to return an HRESULT
value hr
such that SUCCEEDED(hr)
is true. If Cancel button is clicked, I need to return a negative value. I could have used bools, but that would break the existing pattern (usually the hr values come from depths of system dlls). So, I know I can return S_OK
on Ok, but what do I return on Cancel? I could just return (HRESULT)-1;
, but there must be a better way - some HRESULT literal constant which has negative value and represents a generic failure. S_FALSE
is not it, for it's value is defined as 1L
.
Please help me find the right constant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
E_FAIL
或E_ABORT
。但是,这只会带来一个更大的问题,如果您只想检查S_OK
,则永远不应该使用SUCCEEDED(hr)
。E_FAIL
orE_ABORT
. However, this just brings up a larger issue which is you should never useSUCCEEDED(hr)
if you just want to check againstS_OK
.也许E_ABORT
Perhaps E_ABORT
典型值如下所示:
http://msdn.microsoft.com/en-us /library/aa378137(VS.85).aspx
E_FAIL 或 E_ABORT 似乎是最明显的。
Typical values are shown here:
http://msdn.microsoft.com/en-us/library/aa378137(VS.85).aspx
E_FAIL or E_ABORT seem the most obvious.
正如凯尔·阿隆斯所说,< code>E_ABORT(或
E_FAIL
)可能适合您的目的,或者您可以使用MAKE_HRESULT()
宏或HRESULT_FROM_WIN32() 自行设计
如果存在与您想要指示的内容相匹配的 Win32 错误代码。也许
HRESULT_FROM_WIN32(ERROR_CANCELLED)
?As Kyle Alons said,
E_ABORT
(orE_FAIL
) might work well for your purpose or you can devise your own using theMAKE_HRESULT()
macro orHRESULT_FROM_WIN32()
if there's a Win32 error code that matches what you want to indicate.Maybe
HRESULT_FROM_WIN32( ERROR_CANCELLED)
?