Article ID: 139073 - Last Review: March 16, 2005 - Revision: 3.3 How to Fill EXCEPINFO in IDispatch ImplementationThis article was previously published under Q139073 SUMMARY
DispInvoke will fill the EXCEPINFO parameter of IDispatch::Invoke if the
property or method implementation returns a failure HRESULT and uses
SetErrorInfo() to provide rich error information.
MORE INFORMATION
An automation client that uses late-binding or id-binding to an automation
server will use IDispatch::Invoke to invoke the server's property or
method. Such a client will typically pass an EXCEPINFO structure as a
parameter to IDispatch::Invoke to obtain rich error information on failure.
The server will fill the EXCEPINFO structure on failure. A typical
IDispatch::Invoke implementation in the server calls DispInvoke. Then
DispInvoke calls the appropriate property or method implementation.
Consequently, the property or method implementation doesn't have access to
the EXCEPINFO parameter of IDispatch::Invoke to provide rich error
information on failure. The solution is to return a failure HRESULT from the property or method implementation and use SetErrorInfo in the property or method implementation. DispInvoke will check if the property or method returned a failure HRESULT. If so, it will fill the EXCEPINFO parameter using the information that the property or method provided with SetErrorInfo. DispInvoke will not fill out the EXCEPINFO parameter if the return type of the property or method is not HRESULT. Therefore, this method is best suited for a dual interface, which requires HRESULT to be the return type for its methods and properties. Note that an id-binding or late- binding client will see the type of the parameter with the retval attibute as the return type. For example, in the following code, the server implements IDispatch::Invoke in CServer::Invoke by using DispInvoke. If the client passes the DISPID of the Test method, DispInvoke will call CServer::Test - whose address is provided in the vtbl that is the first parameter of DispInvoke. Note that CServer::Test does not have direct access to the EXCEPINFO parameter. DispInvoke will fill the EXCEPINFO parameter using the information that CServer::Test provides using SetErrorInfo - if Test returns a failure HRESULT. NOTE: Documention of SetErrorInfo and related interfaces can be found in Chapter 10 of the OLE Programmer's Reference, Volume 2, second edition. For information on how to obtain the second edition of this book, please see the following article in the Microsoft Knowledge Base: 124385
(http://support.microsoft.com/kb/124385/EN-US/
)
SAMPLE: OLE Automation '94 Documentation and Samples
| Article Translations
|
Back to the top
