Ben Voigt [C++ MVP]
6/15/2007 3:04:00 AM
"JerryWEC" <JerryWEC@newsgroups.nospam> wrote in message
news:ePU0XeprHHA.1864@TK2MSFTNGP04.phx.gbl...
> Ben, thanks for responding!!
>
> A B C
>
> _____VB6___ _________________same dll
> assembly_______________
>
> ************ **************** ******************
> * VB6 Client * -----> * .net Wrapper * ---------> * .net
> class with main *
> * App * * object to expose * * code.
> *
> ************ * to COM VB * ******************
> ***************
>
> ************ ******************** ********************
> * * * Event from main code * * <-
> Event Raised here *
> * * * rcvd event and * *
> *
> * * * reraises another event * *
> *
> * * * to VB6 app and * *
> *
> * * * At this point the error * *
> *
> * * * occurs goes to a error * *
> *
> * * * catch block. * *
> *
> ************ ******************** *********************
>
> I don't understand how switching roles occurs. I am only sending events
> from one .net wrapper class to the VB6 application.
> My VB6 application contains an instantance of the .net object (dll) and is
Ok, that's reasonable.
> receiving events from the object to VB6. As far as
Not really. You don't receive events. When you use a component from VB, a
control or such, you have an interface pointer to that object, through which
you can call its methods and properties. A component that has events
declares a second interface but does not implement it. Instead, the user
(in your case VB) adds that interface to one of its objects, called an event
sink, and gives the interface pointer to the component, the event source.
Now the component holds the pointer to the user. Thus the normal roles are
reversed.
> I know I'm not destorying any of my objects. My main object in VB6 is
> created and I have a global variable holding it until
> the application ends. This is an RPC error and I'm not doing anything
> with the object like setting it to Nothing in VB. I am settting another
> object to it like Set WM = WMGirth then maybe later Set WM = WMSeal.
> WMGirth and WMSeal are my main objects in
Both of these have a long lifetime that you know has not ended? Have you
put logging code in the destructor (I think it's called Terminate in VB)?
> VB6 but they are the objects from may .net assembly that are exposed to
> COM using COM InterOP attributes. The objects
> in VB6 are declared using With Events. I have other events that are being
> raised with no issues. Originally the event seem to work
> fine using buttons. But now I'm trying to system testing using Timers and
> PLC interfaces that may be using cpu time and interrupts, etc...
That suggests a threading problem. Perhaps your .NET component and VB
aren't agreed on whether the objects are single-threaded,
apartment-threaded, or free-threaded? Try using Control.Invoke in .NET to
raise the message.
> Now I'm getting the error message in debug mode and when not in debug
> (attached) events seem to take a long time.
>
> This happens right at the point I'm raising the event to COM from my .net
> wrapper class that has the COM attributes.
>
> I'm using traditional good programming techiques in VB6 and should be
> doing what I need to on the .net side. I just don't understand
> how you raise an event from .net to COM and it blows up???
>
> One other thing the point where I raise the event in my main code is in an
> event handler from a TCP/IP communication object (.net). When this error
> happens I handle the error to record it and then the original event
> handler is called again.
>
> I'm sorry I'm really lost. The VB6 client application is creating these
> WMGrith and WMSeal object using early binding and I'm not destorying them
How about the object declaring WithEvents references? Is that a code module
or a class module? Does an instance of the VB class possibly get destroyed.
It is decidedly *not* the .NET instances that are dying, it is the VB object
that is inaccessible when the .NET code tries to call the event handlers.
> until the end. I believe the .net object is running in-process but I'm
> not sure. When you embed a .net object in VB6 does it not run in-process?
>
> JerryM
>