Which HRESULT literal constant will fail the SUCCEEDED() macro?
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 - s开发者_JAVA百科ome 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.
E_FAIL
or E_ABORT
. However, this just brings up a larger issue which is you should never use SUCCEEDED(hr)
if you just want to check against S_OK
.
Perhaps 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.
As Kyle Alons said, E_ABORT
(or E_FAIL
) might work well for your purpose or you can devise your own using the MAKE_HRESULT()
macro or HRESULT_FROM_WIN32()
if there's a Win32 error code that matches what you want to indicate.
Maybe HRESULT_FROM_WIN32( ERROR_CANCELLED)
?
精彩评论