Exforsys
+ Reply to Thread
Results 1 to 2 of 2

.NET objects to COM objects

This is a discussion on .NET objects to COM objects within the Microsoft .NET forums, part of the Programming Talk category; Hi All, Can any one help me how can i expose my .NET objects to COM objects. Is that possible? ...

  1. #1
    jazzlearner is offline Junior Member Array
    Join Date
    Nov 2008
    Answers
    1

    .NET objects to COM objects

    Hi All,
    Can any one help me how can i expose my .NET objects to COM objects. Is that possible?

    Thanks in Advance!

    Jazz

    Last edited by jazzlearner; 11-15-2008 at 07:07 AM.

  2. #2
    techvinny is offline Moderator Array
    Join Date
    Dec 2010
    Answers
    56
    Yes, it is possible through COM Interop...The assembly information of a .net assembly needs to be exported as a type library and this type library could then be referenced as a COM type library in any of the COM applications.

    Method 1
    You will have to use the utility, tlbexp.exe (comes with the .net framework). This command-line utility takes as input the name of an assembly DLL file to be converted to a Type Library. You can also specify the name of a Type Library file to be created.

    Code:
    tlbexp MyDotNetDLLExposeAsCOM.DLL /out:MyDotNetDLLAsCOM.tlb
    Once a Type Library has been created, it can be referenced by a COM client to obtain the information necessary for the COM client to bind to the interfaces of the COM class and activate the COM class at runtime.

    Method 2
    There's another utility that could also be used, regasm.exe. In addition to creating a Type Library, this utility also creates the Windows Registry entries necessary for making the assembly visible as a COM object to clients, as shown below.

    Code:
    regasm MyDotNetDLLExposeAsCOM.DLL /out:MyDotNetDLLAsRegisteredCOM.tlb
    Method 3
    This method is probably the easiest one as this means just turning ON one of the properties for your assembly within the VS.NET IDE. On the Project properties, there is a property Register for COM Interop. Setting this property to True instructs the IDE to automatically register the assembly for COM Interop each time you build it, so you don't have to perform this step manually.

    HTH!!!


Latest Article

Network Security Risk Assessment and Measurement

Read More...