Raising an error to VB, setting Err.Number 
Author Message
 Raising an error to VB, setting Err.Number

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);

Quote:
}



Sun, 11 Jul 2004 08:14:22 GMT  
 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);
> }



Sun, 11 Jul 2004 15:36:33 GMT  
 Raising an error to VB, setting Err.Number
See AtlReportError() function in MSDN.



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);
> }



Sun, 11 Jul 2004 18:03:47 GMT  
 Raising an error to VB, setting Err.Number
There is also an alternative to ATL, called Comet, that allows you to throw
C++ exceptions from your COM components, which automagically get translated
into COM errors -- http://www.lambdasoft.dk/comet/.

-------------------------------------------------
Automate your software builds with Visual Build
http://www.kinook.com


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);
> }



Sun, 11 Jul 2004 22:31:19 GMT  
 Raising an error to VB, setting Err.Number
The error should be a negative number - you pass zero = S_OK.
Pass a real failure code there like E_FAIL for example...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

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);
> }



Mon, 12 Jul 2004 03:02:54 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Catching err.raise of a VB control in an MFC app

2. Trouble Catching Exception In MFC From A VB Err.Raise

3. Passing Err.Number to VB from C++

4. Raising Errors from VC++ created DLL to VB client - help needed

5. Raising Errors to VB

6. Err.Raise equivalent?

7. Help: Setting a cooking is raising a exception error

8. ATL Component: Err object in VB???

9. Error number translation from HRESULTs to VB

10. I need a dll for VB that raise some events from a second thread

11. catch events raised by VB in C++

12. Raise a VB event from a C++ dll

 

 
Powered by phpBB® Forum Software