Fog Creek Software
Discussion Board

COM to .Net Interop question

I am making a COM DLL that will be used in .Net, VB6, and possibly other languages that can use COM (but mainly .Net + VB6).  The DLL is being built in VB6.

I have not dedicated serious time to learning .Net yet, so I'm wondering if anyone can tell me if theres anything that I should look out for (regarding how .Net uses public interfaces of Interopped COM objects).

For instance, are there any datatypes that I should avoid exposing, or any techniques that just don't work in .Net (like ParamArray or Optional arguments, _NewEnum, etc.)?


Friday, January 30, 2004

Avoid optional arguments.  They usually cause more headaches than they are worth.

.NET doesn't support optional arguments, you have to use System.Type.Missing when invoking methods you don't want to supply all the parameters for.

Rob Walker
Friday, January 30, 2004

Here is something that might help.

I also highly recomend browsing (no human being is able to actualy *read* that brick) the excelent book on COM Interop by Adam Nathan.

It has a chapter called 'Designing Great COM components to be used from .NET' or something like that. Great, great book.

And regarding the optional parameters thing, I am not sure (I am a C# guy), but I think that Visual Basic .NET is compatible with methods that use optional and default parameters.

Disclaimer: I know that .NET does not support optional parameters at the CLR level, mailnly because they collide with the idea of method overloads, but I once read that VB.NET does a good job on backwards compatibility with optional and default parameters at the language level.

If you will be using VB6 components from .NET I recomend VB.NET. (If not, stay away from that crapy language!! <g>).

.NET Developer
Friday, January 30, 2004

How about returning a Type or a Variant Array from a public function?

I usually don't use Types in the public interfaces because you can't get to them from MS Script, I'm just curious.

Also, what about having an object who's instancing is set to Global?  Will it work the same in .Net?

Friday, January 30, 2004

VB.NET DOES support optional arguments

Sunday, February 1, 2004

*  Recent Topics

*  Fog Creek Home