Discussion:
C# COM Events in VB6
Mike Andrews
2009-06-26 13:45:30 UTC
Permalink
I'm having a real tough time here with the COM interop with VB6.
I know that the instances where VB6 COM interop is needed is dropped
dramatically, but here at this company some production code is still VB6.
So I have to make this work. I'm trying desperately to get C# events to be
raised correctly in VB6. I have had some measure of success with it but I'm
running into some difficulties.

The event arguments I have are detailed and have several layers of
hierarchy. That hierarchy I have duplicated with COM interfaces and
implemented those interfaces on the specific objects. When I try to use the
event in VB6 by declaring the variable WithEvents, I get the error message:
"User-Defined Type Not Defined". Yet, when I view the objects via the
object browser they display correctly and there is no property (or method
parameter) with the data type of "<Undefined Variant Type>".

I do have an event interface defined. I also have it specified in the
ComSourceInterfacesAttribute attribute on the class that has the events. I
have delegates defined that match the method signatures in the event
interface. I do use those delegates when defining the events. I have a
ClassInterfaceAttribute defined on the class that has the events and it's
set to ClassInterfaceType.None. I have GuidAttribute on everything that is
utilized via COM - classes and interfaces. I've specified the
DispIdAttribute on methods and properties in the interfaces. I've also
utilized the ProgIdAttribute on the classes as well.

Another problem arises when I try to use a standard EventArgs in the event.
It works for getting VB6 to not cry with a "User-Defined Type Not Defined"
error message, but when the event is raised it causes an exception to occur
in the .NET code; something to the effect of "I don't know what this event
is"; it's a COM exception.

This is really driving me crazy.

Any suggestions?

Thanks,
Mike

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives
Mark Hurd
2009-06-27 03:08:57 UTC
Permalink
On Fri, Jun 26, 2009 at 11:15 PM, Mike
Post by Mike Andrews
I'm having a real tough time here with the COM interop with VB6.
I know that the instances where VB6 COM interop is needed is dropped
dramatically, but here at this company some production code is still VB6.
So I have to make this work.  I'm trying desperately to get C# events to be
raised correctly in VB6.  I have had some measure of success with it but I'm
running into some difficulties.
The event arguments I have are detailed and have several layers of
hierarchy.  That hierarchy I have duplicated with COM interfaces and
implemented those interfaces on the specific objects.
I assume the code is proprietary and/or too complex to post somewhere,
so you'll have to start with (or reduce to project down to) something
simpler and see if you can either reproduce the problem, and then post
it here, or it will work and you can add (back) more functionality
until it breaks.
--
Regards,
Mark Hurd, B.Sc.(Ma.)(Hons.)

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives
Mike Andrews
2009-06-29 14:58:13 UTC
Permalink
I finally figured it out.
It turns out that in order for VB6 to show the correct event arguments you
cannot prepend an underscore to the interface name. Once I remove the
underscores from the event argument interfaces all was well in VB6.

I took your advice and finally found the answer.

Thanks,
Mike
Post by Mark Hurd
On Fri, Jun 26, 2009 at 11:15 PM, Mike
Post by Mike Andrews
I'm having a real tough time here with the COM interop with VB6.
I know that the instances where VB6 COM interop is needed is dropped
dramatically, but here at this company some production code is still VB6.
So I have to make this work. I'm trying desperately to get C# events to
be
Post by Mike Andrews
raised correctly in VB6. I have had some measure of success with it but
I'm
Post by Mike Andrews
running into some difficulties.
The event arguments I have are detailed and have several layers of
hierarchy. That hierarchy I have duplicated with COM interfaces and
implemented those interfaces on the specific objects.
I assume the code is proprietary and/or too complex to post somewhere,
so you'll have to start with (or reduce to project down to) something
simpler and see if you can either reproduce the problem, and then post
it here, or it will work and you can add (back) more functionality
until it breaks.
--
Regards,
Mark Hurd, B.Sc.(Ma.)(Hons.)
===================================
View archives and manage your subscription(s) at
http://peach.ease.lsoft.com/archives
===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives
Loading...