描述:
高手请指教:HRESULT 中的设备代码 是干什么用的? 特别是FACILITY_ITF 是什么? 设备代码与返回代码有什么关系?
解决方案1:
HRESULT 是32位的(0~31),最高位(31)代表着严重程度,也就是操作的成功与否。30-29是保留位。28-16是操作码,15-0是信息码。操作码对应于采用的技术,信息码代表着精确的结果值。你说的设备代码应该是操作码。对于用户自定义的hresult,此时facility_itf是唯一合法的操作码。
设备代码(操作码)是返回代码的一部分。
From MSDN:
HRESULT is a data type that is a 32-bit error or warning code.
Syntax
typedef LONG HRESULT;
Comments
An HRESULT is made up of a 1-bit severity flag, an 11-bit handle, a 4-bit facility code indicating status code (SCODE) group, and a 16-bit SCODE information code. A value of zero for the severity flag indicates the success of the operation for which the HRESULT was returned.
A HRESULT type returned as an error code for a function can provide the application that called the function information on the error and how to recover from it. To obtain this information, the application uses the handle of the HRESULT. The HRESULT and SCODE types are not equivalent. OLE includes functions and macros to convert between error codes of these two types. To create an HRESULT code from an SCODE code, use ResultFromScode(SCODE). To convert an SCODE code to HRESULT form, use GetScode(HRESULT). For details about ResultFromScode and GetScode and for faster ways of making the conversions just mentioned, see OLE Programmer's Reference, Volume One. . For a description of the OLE implementation of HRESULT, see Inside OLE, Second Edition, by Kraig Brockschmidt.