
Raising an error to VB, setting Err.Number
u can use following code sample which i implemented in my components
Here "SetErrorInfo" function sets the error information object for the
current thread of execution.
HRESULT CError::SetComErrorInfo()
{
START_ERROR_CATCH
ICreateErrorInfo *pcerrinfo;
IErrorInfo *perrinfo;
HRESULT hResult = CreateErrorInfo( &pcerrinfo );
pcerrinfo->SetDescription( GetDescription() );
pcerrinfo->SetHelpContext( GetHelpContext() );
pcerrinfo->SetHelpFile( GetHelpFile() );
pcerrinfo->SetSource( GetSource() );
pcerrinfo->SetGUID( GetGUID() );
hResult = pcerrinfo->QueryInterface( IID_IErrorInfo, (LPVOID FAR*)
&perrinfo );
if ( SUCCEEDED( hResult ) )
{
SetErrorInfo( 0, perrinfo );
perrinfo->Release();
}
pcerrinfo->Release();
END_ERROR_CATCH
return m_hErrorCode; // from GetErrorCode();
Quote:
}
with best wishes
Arun Devadiga
Quote:
> How do you raise an error so that VB has it's Err.Number set?
> Presently I am using
> STDMETHODIMP MyClass::Go()
> {
> return Error("Something really bad happened!", IID_IMyClass, 0);
> }