C# COM Events in VB6

Mike Andrews <[email protected]> Fri, 26 Jun 2009 08:45:30 -0500
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <[email protected]>
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