Local database reading edition

What is HRESULT in COM?

Reconstructed from database records, not a captured original forum layout. Dates and display names are retained as recorded; timezone and real-world identity are not inferred. Historical advice, contact details and offers are not current. Original markup is shown as inert text.

Forum index · Visual C++ Programming

Opening post

skpradhan · 2001-02-24 03:44:33

COM uses HRESULT for reporting success / failure status of COM methods to clients. For example, COM methods like QueryInterface(), CoCreateInstance(), etc.., all returns an HRESULT. Well from its name it is obvious to think that an HRESULT is a "Handle to a Result". But it's not, instead of thinking it as a "Handle to Result", just think it as "Here's the Result". So HRESULT is a 32-bit value with a specific format (divided into 3 different fields, shown below) is interpreted as a result. -------------------------------------------- |31|30-16(Facility code)|15-0( Return code | -------------------------------------------- The most significant bit (31st bit) reports whether the function call succeeded or failed.The right most 16 bits contains the return code what the function returs, and the middle 15 bits contains more information about the type and origin of the return code. This is also called as Facility code. It is important to note here that this special design of HRESULT allows to return multiple success as well as multiple failure codes. By convention, successful return codes begin with an S_, while failure codes begin with an E_.Some of the commonly used return codes are given and described below. S_OK : This means function succeeded and a boolean true is returned. But S_OK is defined 0,in contrary to traditional c/c++ programming principles. S_FALSE : This means function failed and a boolean false is returned. But S_FALSE is defined 1. E_UNEXPECTED : Unexpected failure. E_NOTIMPL : Method is not implemented. E_NOINTERFACE : Generally QueryInterface() returns this when a requested interface is not supported by the component. E_OUTOFMEMORY : Component can not allocate required memory. E_FAIL : Unspecified failure. The facility code identifies the part of the operating system that can return the return code.The currently defined facility codes are listed below: FACILITY_WINDOWS 8 FACILITY_STORAGE 3 FACILITY_SSPI 9 FACILITY_RPC 1 FACILITY_WIN32 7 FACILITY_CONTROL 10 FACILITY_NULL 0 FACILITY_ITF 4 FACILITY_DISPATCH 2 FACILITY_CART 11 All the facility codes except FACILITY_ITF identify return codes that are defined by COM and are universal. FACILITY_ITF identify return codes that are specific to the interface that returns the code. Santanu Kumar Pradhan

Source notes

MyCommunity/nandighosha.org.zip!/forum/tools/snitz_forums_2000.mdb
Table: FORUM_TOPICS + FORUM_REPLY · record IDs: 46