Introduction:
In this article I cover the area how to use a COM server in a .NET client. Existing COM components are precious resources to your managed applications. So now let us observe how you can build a .NET Client that uses a COM Server.
The steps involved in the build process are as follows:
-
Write and compile
the unmanaged code.
-
Generate an assembly
containing definitions of the COM types using the tlbimp.exe utility so that
allow the .NET client to interact with the exposed types.
-
Install the assembly in the
global assembly cache. (Optional).
- Write and compile the .NET client code that reference the assembly containing the COM type definitions.
1.Write and compile the
unmanaged code.
Open an ActiveX DLL
project workspace in VB 6.0 and put the below code in code window and name the
project as VBServer and Class to Add.
Public Function Add(ByVal x As Integer, ByVal y As Integer) As Integer
Add = x
+ y
End Function
Finally save your workspace and compile the VBServer to VBServer.dll.
Now let us see the VBServer.dll in the OLE viewer.

In the OLE/COM Object Viewer we can see the name of default custom interface(Add) as well as a number of other COM interfaces implemented by VB.
2.Importing the Type Library:
The .NET Framework needs metadata for individual COM types at both compile time and run time. Your choice for generating metadata is the Type Library Importer (TlbImp.exe) utility generates an assembly containing metadata. When you carry out this tool on a type library it generates a standard runtime callable wrapper, based on the contents of the type library.
tlbimp VBServer.dll /out:NetClient.dll.
Join the conversation! Your thoughts help the community grow.