The information in this article applies to:
SUMMARYUsing #import to create your client application introduces exception handling through the _com_error exception class when a wrapper for an object's method encounters a failed HRESULT. You might have valid reasons to replace this mechanism with your own implementation. MORE INFORMATION
There are two ways to use #import and not have it raise exceptions for
failed HRESULTS. The first is to use the raw_interfaces_only clause with
the #import statement. However, this negates some of the advantages of the
wrapper classes that #import provides.
This function is declared but not implemented in the COMDEF.H file. If you
provide your own implementation in an .OBJ, the linker uses that as opposed
to bringing it in from COMSUPP.LIB. _com_raise_error exists in its own
object in COMSUPP.LIB just so it can be easily replaced by your code.
Below is an example of implementation of #import's exception raising function: Note:This code attempts to open an ADO connection object without providing any valid connection information. By replacing _com_raise_error, you prevented the _com_error from being raised. However, just because you have replaced this function, you may still need to trap for exceptions. Consider the code snippet below.
In this case, Conn1 is not a valid object and the interface pointer to this
non-existent object is NULL, resulting in _com_raise_erro being called.
However, the overloaded -> operator method will return a null interface, on
which the compiler then attempts to invoke the Open() method, resulting in
a Win32 exception. Testing Conn1 for NULL first before calling Open() would
prevent this exception.
Additional query words:
Keywords : kbADO kbDatabase kbMDAC kbGrpVCDB kbGrpMDAC kbDSupport |
Last Reviewed: November 4, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |