COM Interoperability in .NET Part 2

Generating a Type Library

After compiling the project we have to create a type library file. So that only most unmanaged application development tools require a type library before you can make references to external types.

COM states that all server application that is programmed to share their features with other applications is to be register at a common location. The client needs to determine the exposed methods, properties and events. This is done via the libraries. The client reads the registry; determine the properties, methods, and event s of the object. COM requires up information such as CLSIDs, IIDs, and ProgIDs etc. But we know the assemblies are not registered.

.NET framework does not depend on the registry and uses metadata for this information. Hence, we have to produce the COM-compatible registry entries for our managed server so that the COM runtime could instantiate our server. The .NET framework provides a couple of tools for this. You can use the Type Library Exporter utility (TLBEXP.exe) or the Assembly Registration Utility (Regasm.exe), both of which you'll find in the Bin directory of your .NET SDK installation.

REGASM is a superset of the TLBEXP utility in that it also does much more than generating a type library. It's also used to register the assembly, so that the appropriate registry entries are made to smooth the progress of the COM runtime and the .NET runtime to fastener up the COM aware client to the .NET component.

Usually a type library can be generated from an assembly using the regasm.exe utility. The regasm.exe utility not only registers an assembly and it also creates the required type library file, as shown here.

regasm Server.dll /tlb:Netserver.tlb

After creating the type library file you have to add a reference this to your project. For example, with Visual Basic 6.0, you can reference the .tlb file or dll file from the Project/References dialog. In Visual C++ 6.0, you can use the #import statement to import the type definitions from the type library directly into C++. Once the reference to the type library is added to the project, the types defined within that library can be referenced from unmanaged code.

Installing the Assembly

In order to actually create managed types from unmanaged code, the assembly needs to be installed in the global assembly cache (GAC) and registered for use from COM.

You can install an assembly in the global assembly cache using gacutil.exe utility. Assemblies can be uninstalled using the /u option.

gacutil /i simpleserver.dll

You might also like...

Comments

About the author

G.Gnana Arun Ganesh

G.Gnana Arun Ganesh India

G.Gnana Arun Ganesh is the Administrator and the Founder of ARUN MICRO SYSTEMS (www.arunmicrosystems.netfirms.com). He has been programming in C++, Visual Basic, COM, Java and Microsoft Technolo...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Every language has an optimization operator. In C++ that operator is ‘//’”