Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

COM and .NET Interop

Hi people,

I'm really sorry if there is an easy answer to this (a duh! moment) and I've wasted your time. Anyhoo, on with the question:

I'm trying to write a .NET assembly (in VB.NET) and access it via COM interop from Visual Basic 6 (don't ask why, its a thought in progress at the moment!). I've managed to create a class and reference the resulting DLL (well, TLB) from Visual Basic 6. Groovy. But, there are no methods or properties available. All I can do is create a new class and destroy it, I can't access the myriad of cool functions I've put in there.

What am I doing wrong?
Cheers,
Dan Alexander...

Dan Alexander
Tuesday, October 08, 2002

You can't see your methods in Intellisence listbox, but you can call them easily.
If you want to see them in Intellisence - try to define interface and implement it in your class

Mikhail Andronov
Tuesday, October 08, 2002

I'm not sure if its just intellisense that isn't picking them up though. I've had a look through the object browser and there's nothing there. Also I've looked at the TLB with "OLE View" that comes with Visual Studio 6 and there's nothing there either... its all very bizarre!

Dan Alexander
Tuesday, October 08, 2002

Read the book  'Professional Visual Basic Interoperability: COM and VB6 to .NET.  Chapter 3: 'Using .NET Assemblies from COM' will answer all your questions.

Perhaps you have some sample code that could assist us in helping you along further.  I don't want to post examples from the entire chapter if you are only missing one piece.

Regards,

Jason Watts
Tuesday, October 08, 2002

Hi Dan,

If you want the VB6 object browser and Intellisense to see the .NET class methods and properties, you can add a ClassInterface attribute to the .NET class, with the interface type set to AutoDual.

By default, regasm sets the interface type to AutoDispatch, which only allows late-bound clients - hence the lack of method visibility.

However, AutoDual has its own nasty problems with COM versioning. The best way to do this is to create a separate interface-only class, then implement this class inside your assembly. The interface class can be left with the default AutoDispatch, the implementation's interface type should be set to None.

Sorry, but I don't have the code available at the office here. It's all laid out in gory detail in my upcoming book :)

Regards,

Mark

Debugging VB .NET Development
http://www.apress.com/book/bookDisplay.html?bID=128

Mark Pearce
Tuesday, October 08, 2002

>The best way to do this is to create a separate interface-
>only class, then implement this class inside your
>assembly. The interface class can be left with the default
>AutoDispatch, the implementation's interface type should
>be set to None.

Exactly. Also make sure to set the ComVisibility attribute to
true on both the interface and the class (although I believe
that's the default). You should then have both early (tlb) and late binding working, and you shopuld see everything
in both the object browser and intellisense.

One problem I've run into (and if anyone has an
explanation, I'd appreciate it): fi you have a base interface and a derived one, and if your class implements the derived
interface, then the base methods/properties aren't directly
available to the derived class's instance unless it's
explicitly cast to the base interface type.  This seems to be
\the case for both VC++ 6  and VB6 COM clients...

Mike Zukerman
Saturday, October 12, 2002

Hi Mike,

>> fi you have a base interface and a derived one, and if your class implements the derived interface, then the base methods/properties aren't directly available to the derived class's instance unless it's explicitly cast to the base interface type. <<

I believe this is because COM doesn't understand implementation inheritance, so you need to be specific about which type you're actually using.

Regards,

Mark

Mark Pearce
Saturday, October 12, 2002

*  Recent Topics

*  Fog Creek Home