Library tutorials & articles
COM Interoperability in .NET Part 2
- Introduction
- The managed code
- Generating a Type Library
- The unmanaged code
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
Related articles
Related discussion
-
VS.NET/sql server installation problem
by daspeac (4 replies)
-
Unable to access AxInterop.AcoPdflib.dll on 64 bit OS
by Shaila14041981 (0 replies)
-
connect to .dbf files
by daspeac (5 replies)
-
Binary Studio | software development outsourcing Ukraine
by shane124 (4 replies)
-
Research topic in software
by reachsangeethamathew (0 replies)
Related podcasts
-
More jQuery in ASP.NET
In this episode Chris Brandsma, Rick Strahl, Dave Ward, Bertrand Le Roy, and Scott Koon conclude their discussion of Microsoft's jQuery in ASP.NET announcement1.This episode of the Alt.NET Podcast is brought to you by LLBLGen Pro, the most mature O/R mapper and code generator out there.Are ...
Events coming up
-
Dec
9
GL.net Group Meeting - December 2009
Gloucester, United Kingdom
The beginning of this year holiday season will belong to mocks. Ronnie and Stephen will take us for a tour around exciting world of unit testing.
I AM A CHINESE,THIS IS MY FIRST TIME TO VISIT THIS WEB SITE~~~~
I MAJOR IN COMPUTER,SOFTWARE,BEING A SOPHIMORE ,I AM SO DESIRABLE TO MAKE A FRIENDS WITH DIFFERENT COUNTRIES~~~~~
I LIKE SPORTS,ESPECIALLY BASKETBALL,AND MUSIC,PLAYING GUITAR~~~~~~
I LOOK FORWARD TO RECEIVING YOUR MESSAGE,MY EMAIL:CHARLES_ANDREW@163.COM
THANKS ,A FRIEND FROM CHINA
Hello, good news!!!
I just figured out what was missing in what was reported in previous comment.
In the Properties Pages of the .NET project, choosing "Configuration Properties" on the left panel, and then "Build", there is a switch labelled "Register for COM Interop", and of course it has to be set "ON", for all this to work as expected!!!!
Well, let's keep working.!!!!
Be well!!!!!
Hello, G.Gnana Arun:
Hi, good day, greetings from Mexico City.
Well, this post is to commet I just tried your implementation, I created a .NET DLL with VB.NET, then followed the .TLB file, just as you specify in your article, but at the moment of using the library in a VB 6.0 project, using the reference to the .TLB file, as you dictate, just when the object is to be instantiated, I receive a Num 429 error, "ActiveX Object can“t be created". I include here the code for the class in VB.NET:
Public
Class cDotNetUtilsVB60 Public Shared Function IsPositiveInfinity(ByVal pdblNum As Double) As Boolean Dim lnuNumTem As Double Return lnuNumTem.IsPositiveInfinity(pdblNum) End Function Public Shared Function IsNegativeInfinity(ByVal pdblNum As Double) As Boolean Dim lnuNumTem As Double Return lnuNumTem.IsNegativeInfinity(pdblNum) End FunctionEnd
ClassCan you figure out what I'm doing wrong???????
Thanks in advance, be well
Roberto Gutierrez R.
This thread is for discussions of COM Interoperability in .NET Part 2.