Article ID: 175784
Article Last Modified on 12/30/2005
void __stdcall _com_raise_error(HRESULT hr, IErrorInfo* perrinfo = 0)
throw(_com_error);
void __stdcall
_com_raise_error(HRESULT hr, IErrorInfo* perrinfo ) throw(_com_error)
{
throw _com_error(hr, perrinfo);
}
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. Note: Currently our compiler ignores a function exception-specification
and generates the warning:
void __stdcall
_com_raise_error(HRESULT hr, IErrorInfo* perrinfo ) throw(_com_error)
{
//this message box is for demonstration purpose only
AfxMessageBox( "_com_raise_error (HRESULT, IErrorInfo*)" );
//your own error handling code or just an abort
}
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "adoEOF" )
_bstr_t bstrEmpty(L"");
_ConnectionPtr Conn1 = NULL;
Conn1.CreateInstance( __uuidof( Connection ) );
Conn1->Open( bstrEmpty, bstrEmpty, bstrEmpty,0 );
#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "adoEOF" )
_ConnectionPtr Conn1 = NULL;
// Conn1.CreateInstance( __uuidof( Connection ) );
Conn1->Open( bstrEmpty, bstrEmpty, bstrEmpty ,0);
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. Keywords: kbhowto kbinfo kbdatabase KB175784