Article ID: 139073 - View products that this article applies to. This article was previously published under Q139073 SUMMARYDispInvoke will fill the EXCEPINFO parameter of IDispatch::Invoke if theproperty or method implementation returns a failure HRESULT and usesSetErrorInfo() to provide rich error information. MORE INFORMATIONAn automation client that uses late-binding or id-binding to an automationserver will use IDispatch::Invoke to invoke the server's property ormethod. Such a client will typically pass an EXCEPINFO structure as aparameter to IDispatch::Invoke to obtain rich error information on failure.The server will fill the EXCEPINFO structure on failure. A typicalIDispatch::Invoke implementation in the server calls DispInvoke. ThenDispInvoke calls the appropriate property or method implementation.Consequently, the property or method implementation doesn't have access tothe EXCEPINFO parameter of IDispatch::Invoke to provide rich errorinformation on failure. The solution is to return a failure HRESULT from the property or methodimplementation and use SetErrorInfo in the property or methodimplementation. DispInvoke will check if the property or method returned afailure HRESULT. If so, it will fill the EXCEPINFO parameter using theinformation that the property or method provided with SetErrorInfo. DispInvoke will not fill out the EXCEPINFO parameter if the return typeof the property or method is not HRESULT. Therefore, this method is bestsuited for a dual interface, which requires HRESULT to be the returntype for its methods and properties. Note that an id-binding or late-binding client will see the type of the parameter with the retvalattibute as the return type. For example, in the following code, the server implements IDispatch::Invokein CServer::Invoke by using DispInvoke. If the client passes the DISPID ofthe Test method, DispInvoke will call CServer::Test - whose address isprovided in the vtbl that is the first parameter of DispInvoke. Note thatCServer::Test does not have direct access to the EXCEPINFO parameter.DispInvoke will fill the EXCEPINFO parameter using the information thatCServer::Test provides using SetErrorInfo - if Test returns a failureHRESULT.
NOTE: Documention of SetErrorInfo and related interfaces can be found inChapter 10 of the OLE Programmer's Reference, Volume 2, second edition. Forinformation on how to obtain the second edition of this book, please seethe following article in the Microsoft Knowledge Base: 124385 SAMPLE: OLE Automation '94 Documentation and Samples PropertiesArticle ID: 139073 - Last Review: March 16, 2005 - Revision: 3.3 APPLIES TO
|
联系客服