Many times we need to use ActiveX controls (ocx) developed in VB6 or C++ in our .NET applications. As you might aware of that, we can't directly use ActiveX components in .NET application. So, we need to create wrapper assemblies around the ActiveX components which we call Runtime Callable Wrappers as I have already talked about that in my previous posts. I am not going to discuss details of RCW, but I will show how to generate the RCWs.
You can generate RCW in two ways
1. Using Visual Studio
2. Using Tools TlbImp.exe and AxImp.exe.
Using Visual Studio to generate RCW:
This is the simplest way of generating RCWs. Then in your project, open the toolbar, right click on it and select 'Choose controls'. Browse the .ocx file and click OK.
Now open the 'obj' folder present inside the project folder and you will see two interop dlls are generated namely AxInterop.<FileName>.dll and <FileName>.dll. For example, if the control name is MyControl.OCX then generated assemblies will be AxMyControls.dll and MyControls.dll. The prior one contains the visible components of the user control that can be placed on the form. And later one contains the types.
Using Tools to generate RCW:
Above method of generating RCW fulfils most of the times. However, if you want to have some control over how the interops are generated like default namespace, strong naming etc., you can't do much with Visual Studio. However, for that you can use framework tools to generate RCW yourself.
AxImp.exe and TlbImp.exe are two such tools that ship with NET Framework SDK. In fact AxImp.exe alone is sufficient to generate required interops. We will how that works now. Suppose you have an ActiveX control called MyControl.OCX. Open the visual studio command prompt, change the directory to the folder where MyControl.ocx resides and run the below command.
AXIMP MyControl.OCX
This will generate two interops AxMyControl.dll and MyControl.dll. The default namespace in the prior one will be AxMyControl and default namespace in MyControl.dll will be MyControl. If you want to change the out putfile name to AxInterop.MyControl.dll, you can run the below command,
AXIMP MyControl.OCX /OUT:AxInterop.MyControl.dll
AXIMP MyControl.OCX /OUT:AxInterop.MyControl.dll
This will generate AxInterop.MyControl.dll and MyControl.dll. You can see that when using AXIMP tool, you do not have any control over other interop dll i.e. MyControl.dll. You also do not have control over default namespace name. So, if I want to give your own names say AxInterop.MyControl.dll and Interop.MyControl.dll with custom namespaces say LegacyControls, then I will do it as below:
First generate the interop assembly containign type definitions using TLBIMP tool as below,
TLBIMP MyControl.OCX /OUT:Interop.MyControl.dll /namespace:LegacyControls
TLBIMP MyControl.OCX /OUT:Interop.MyControl.dll /namespace:LegacyControls
If you want the generated assembly to be strong named, you can supply the strong name key file to above command (as below)
TLBIMP MyControl.OCX ... /KEYFILE:MyCompanyKey.snk
TLBIMP MyControl.OCX ... /KEYFILE:MyCompanyKey.snk
Now generate the ActiveX interop using AXIMP tool using the above generated RCW,
AXIMP MyControl.OCX /OUT:AxInterop.MyControl.dll /RCW:Interop.MyControl.dll
AXIMP MyControl.OCX /OUT:AxInterop.MyControl.dll /RCW:Interop.MyControl.dll
and of course you can sign this assembly just like as explained before.
Now you have generated the two interops AxInterop.MyControl.dll and Interop.MyControl.dll with having namespace AxLegacyControls and LegacyControls respectively.
Note: You must register the OCX before you can use the generated interops.
Nice article! Is there any method to create AxInterop dll without OCX registration, because I don't have deny to modify it on special computer, but I have to create a wrapper dll.
ReplyDeletenice information..
ReplyDeleteasp.net training in Lucknow
I read your blog. It’s very useful for me. I have some new idea to share with you .
ReplyDeletephp training company in Ahmedabad
php live project training in ahmedabad
live project training in Ahmedabad
Very useful post. I have tried this but I get below error. I am using Window 10 SDK and Dotnet framework 4.6.1.
ReplyDeleteAxImp Error: API restriction: The assembly '' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.
I have tried this but I get below error. I am using Window 10 SDK and Dotnet framework 4.6.1.
ReplyDeleteAxImp Error: API restriction: The assembly '' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.
anyways thanks..
SAP training in Lucknow
SAP FICO training in Lucknow
Fire and safety training in Lucknow
NDT training in Lucknow
PHP Training in Lucknow
JAVA Training in Lucknow
Android Training in Lucknow
HR Training in Lucknow
AutoCAD Training in Lucknow
Nice blog..! Really very informative and creative contents. This concept is a good way to enhance the knowledge. Please do visit my website hope you'll like it:
ReplyDeleteWebsite Development Company in Lucknow
It is usefull post and well explained very points.Thank you for shairing
ReplyDeletebig data certification course in Bangalore
big data certification bangalore
big data hadoop certification training in Bangalore
SIPL TRAINING
ReplyDeleteIt is very helpfull plugin code thank you so much for sharing this..
SAP training in lucknow
HVAC training in lucknow
Revit Mep training in lucknow
Digital Marketing training in lucknow
Python training in lucknow
.Net training in lucknow
Popup WordPress plugin is an easy an intuive way to create to create all kind of popups. Download it now for free only in a few clicks.
ReplyDeleteDid you know there's a 12 word sentence you can speak to your crush... that will trigger intense feelings of love and impulsive appeal for you deep within his heart?
ReplyDeleteBecause deep inside these 12 words is a "secret signal" that triggers a man's impulse to love, worship and care for you with all his heart...
=====> 12 Words That Fuel A Man's Love Instinct
This impulse is so built-in to a man's genetics that it will make him work harder than before to build your relationship stronger.
In fact, triggering this influential impulse is so important to having the best ever relationship with your man that the second you send your man one of the "Secret Signals"...
...You'll instantly notice him expose his heart and soul to you in such a way he's never expressed before and he'll recognize you as the only woman in the world who has ever truly interested him.
Great Post...Such a informative blog...Thanks for sharing with us...
ReplyDeleteBest IT and Non-IT Course Training Institute in Bangalore
AxImp Error: API restriction: The assembly '' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.
ReplyDeleteIf you met this, check the path specified in /rcw: is an absolute file path instead of relative one
Nice post. thank's for sharing this post. your information is very helpful. If you are finding cheap assignment writing services visit at.
ReplyDeleteassignment expert
assignment expert uk
Essay Writing Services
Dissertation Help
Assignment Help singapore