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

We develop activex controls in VB that we use in an MFC
dialog. We try to find how to handle errors in the VB
control so that we can trap them in the MFC app.

First we thought of using Err.Raise in the VB control. If
we use that statement in the code of a method or property
in the VB control then we thought we could catch the error
in C++ with a try/catch construct because the call and the
error are synchronous but the error is caught before in an
MFC routine and it pops a messagebox.

Then if we call err.raise in an asych method (in the
onclick of a button of the control or in a timer event)
then the error seem to be displayed by the VB runtime and
after the messagebox the control becomes hatched and
diasabled.

We then thought of using an event to report such async
errors with a name like OnError().

So is there a standard way of managing errors in activex
controls?

Is there a way to catch errors for sych method calls or
must we always use an event?

Is OnError a valid event name or is there a defacto
standard name for such an event?

Thanks.



Mon, 28 Feb 2005 20:53:36 GMT  
 Catching err.raise of a VB control in an MFC app
First, let me point out that your question has nothing to do with
ATL. A better place to discuss it would be microsoft.public.vc.mfcole

For the control methods/properties Err.Raise is AFAIK the correct
mechanism. It is translated by the VB runtime to a failure HRESULT
and rich eception information which are then intercepted in MFC's
COleDispatchDriver and converted into COleException* which you
are in turn supposed to catch in your code. I don't know a great
deal about VB and MFc, so you may want to ask in the respective
newsgroups.

For asynchronous errors, add the stock event OnError with DISPID
of DISPID_ERROREVENT (defined in olectl.h):

#define DISPID_ERROREVENT               (-608)

You'll have to handle it in MFC and act accordingly. For more
information you'll probably want to ask in the VB newsgroups.

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

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

Quote:

> We develop activex controls in VB that we use in an MFC
> dialog. We try to find how to handle errors in the VB
> control so that we can trap them in the MFC app.

> First we thought of using Err.Raise in the VB control. If
> we use that statement in the code of a method or property
> in the VB control then we thought we could catch the error
> in C++ with a try/catch construct because the call and the
> error are synchronous but the error is caught before in an
> MFC routine and it pops a messagebox.

> Then if we call err.raise in an asych method (in the
> onclick of a button of the control or in a timer event)
> then the error seem to be displayed by the VB runtime and
> after the messagebox the control becomes hatched and
> diasabled.

> We then thought of using an event to report such async
> errors with a name like OnError().

> So is there a standard way of managing errors in activex
> controls?

> Is there a way to catch errors for sych method calls or
> must we always use an event?

> Is OnError a valid event name or is there a defacto
> standard name for such an event?

> Thanks.



Tue, 01 Mar 2005 06:10:18 GMT  
 
 [ 2 post ] 

 Relevant Pages 

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

2. Raising an error to VB, setting Err.Number

3. catch events raised by VB in C++

4. Question: Catching errors from a VB ActiveX control in Visual C++ using MFC

5. Err.Raise equivalent?

6. catching divide by zero errors in C Dll used by VB app

7. Drag drop from VB app to MFC app problem

8. Catching a VB error in an MFC application

9. VB(app.path) VB C#(app.path) HOW-TO

10. Catch block get executed w/ no error raised.

11. Raising and catching event within an object hierachy

12. CDialog based MFC app: how to catch WM_QUERYENDSESSION?

 

 
Powered by phpBB® Forum Software