Handling Errors

team lib

It is a well-known fact that COM interface methods return HRESULT s to indicate status. If you want to return more information than is encapsulated in the standard set of COM HRESULT sthe ones you can find in < winerror.h > you should implement the ISupportErrorInfo interface, and then use the AtlReportError function or the CComCoClass <> ::Error methods to report errors.

The support_error_info attribute is used to implement rich error handling in ATL classes. It can be included in a project by checking the appropriate box in the ATL Object Wizard, and you can also add it by hand to manually written code. The attribute takes as its argument the name of the interface for which error support is to be generated. You can add more than one support_error_info attribute if you want to provide rich error information for more than one interface. This will result in the implementation of InterfaceSupportsErrorInfo , which contains details of all the interfaces youve named in support_error_info attributes. The following example will add rich error support for both the IOne and ITwo interfaces:

 [coclass, support_error_info("IFoo"), support_error_info("IFoo2") ] classMyClass { //... }; 
 
team lib


COM Programming with Microsoft .NET
COM Programming with Microsoft .NET
ISBN: 0735618755
EAN: 2147483647
Year: 2006
Pages: 140

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net