Introduction:
In this article i am going to explain about how to use legacy COM components using runtime callable wrappers(RCW)
‘s early and late bindings.
Main:
I hope,you all learners will accept,before using COM Components we need know the methods and properties in that
component.
There are two different techniques that client programs can use to determine this information,”Early Biding” “Late Binding”.
Early binding allows clients to obtain compile-time type information from the component’s type library. This allows for stronger type checking during compile time.
A .Net application does not communicate directly with a COM component.it works through manager wrapper of the component.This wrapper, known as a Runtime-Callable Wrapper (RCW), acts like a managed proxy to the unmanaged COM component. It is able to handle the calling of methods on the component, and pass back any return
values in a form suitable for the CLR.
We can create the RCW into the following two ways,
1.using TlbImp.exe utility
2.From within visual studio .NET
Creating a wrapper using TlbImp exe:
TlbImp is shorthand for Type Library Importer. When you execute this program against a COM DLL, it interrogates the COM DLL’s type library and translates the information therein into a .NET format, converting COM standard data types into those recognized by .NET. Once you’ve run TlbImp.exe against a COM DLL, the output
DLL can be referenced in the usual way like any other assembly by using the /r: compiler option.
Creating a wrapper using Visual Studio.NET
To generate a managed metadata wrapper from Visual Studio .NET, you need to use the References dialog, which is available from the Add Reference… option on the
Project menu. The COM tab displays a list of the components that are registered as COM components on the local machine, and allows us to import COM components to
use in our .NET project. The Browse button allows you to search the file system for the COM DLL that your .NET project needs.
How to use TlbImp exe,
Goto Visual studio Commandline,
type tlbimp
The verbose option really allows us to display the full download,After created the dll we need to add into com tab for better performance,
Now i hope you all understood about early binding,its the time we need to talk about late binding,
Late binding allows us to get the COM info at runtime,For trying late binding,please refer system.Reflection namespace.
we must know late binding is really dangerous,
when you late bind a COM component in asp.net application,you call the GetTypeFromProgID() static method of the Type class to instantiate an object representing
the COM object’s type. The Type class is a member of the System namespace class
For ex,
Type SampleType;
SampleType = Type.GetTypeFromProgID("Component.Method");
Type SampleType; SampleType = Type.GetTypeFromProgID("Component.Method"); |
Once you have a Type object encapsulating the COM object’s type information, you use it to create an instance of the COM object itself. This is accomplished
by passing the Type object to the CreateInstance() static method of the Activator class. CreateInstance() instantiates the COM object and returns a late-bound
instance to it, which you can store in an object reference.
object objSample;
objSample = Activator.CreateInstance(SampleType);
object objSample; objSample = Activator.CreateInstance(SampleType); |
we can’t invoke methods directly on the object reference. Instead, to talk to the COM object, you have to rely on the InvokeMember() method of the Type object
that you first created. When you call InvokeMember(), you pass it a reference to the COM object, along with the name of the COM method that you are invoking and
an object array of any input arguments to that method.
For ex,
object[] aryInputArgs = new object[] {number}; //input parameter for particular method,
object objResult = factorialType.InvokeMember("WelcomeString", //Method name
BindingFlags.InvokeMethod,
null,
objSample,
aryInputArgs);
For releasing COM objects,
Marshal.ReleaseComObject(Objsample);
Conclusion:
Hope this helps,
Happy Coding.
object[] aryInputArgs = new object[] {number}; //input parameter for particular method, object objResult = factorialType.InvokeMember("WelcomeString", //Method name BindingFlags.InvokeMethod, null, objSample, aryInputArgs); For releasing COM objects, Marshal.ReleaseComObject(Objsample); |
Hope this helps,
Happy Coding.

Hey admin, very informative blog post! Pleasee continue this awesome work..
Thanks very good for report, I follow your blog:-)
Wow!, this was a top quality post. In theory I’d like to write like this too – taking time and real effort to make a good article… but what can I say… I procrastinate a lot and never seem to achieve anything
This might be some thing I may certainly look into.
Thanks for sharing. I enjoyed reading your article!
Thanks for sharing information with us. it is very useful to me.
Good brief and this enter helped me alot in my college assignement. Gratefulnes.
I truly loved this brilliant article. Please continue this awesome work. Regards, Duyq.
This blog seems to get a great deal of visitors. How do you promote it? It offers a nice individual twist on things. I guess having something real or substantial to post about is the most important thing.
Grover says that this is a good find, He’s going to invite all of his friends.
very nice article