Exposing .Net Assembly to COM

G

Guest

I would like to use a .Net packaged dll with unmanaged code, ie VB6 or
Access. The class I would like to use is System.Web.dll located in
C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705. From my research my
understanding is the I need to create a "wrapper" by creating a new .Net
class library project and when compiling it click on the register for Com
property in the configuration.

My questions are #1 is this the correct approach? and #2 how do I ensure
that all the functionality of the assembly is retained in COM. For example,
COM cannot accept parameterized constructors....If the assembly has them, how
do I create the class library to code around this.... and most importantly
#3, how do I expose all the properties, methods, and events of the underlying
assembly.

My understanding on interfaces is limited, and I guess that this is the
approach. If someone could provide a basic example it would be greatly
appreciated.

Thanks
 
N

Nicholas Paldino [.NET/C# MVP]

Chris,

In order to do this, you would first have to register the assembly to be
used as a COM assembly. For example, for System.Web.dll, you would have to
go to the framework directory that it is in, and then run the REGASM utility
to register the assembly with COM. You will want to pass the tlb flag to
the utility, so that you can generate a TLB that you can use from COM.

Here is the catch, when I tried to do it, it only exported two
interfaces, so you are probably going to have to do a lot of work to export
these types (since they probably reference other types which aren't in that
assembly).

If anything, you should create wrapper methods to do the work that you
want, and then expose those to COM, abiding by the guidelines for creating
types exportable to COM.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top