Using ActiveX Control in .Net

ActiveX control is a special type of COM component that supports a User Interface. Using ActiveX Control in your .Net Project is even easier than using COM component. They are bundled usually in .ocx files. Again a proxy assembly is made by .Net utility AxImp.exe (which we will see shortly) which your application (or client) uses as if it is a .Net control or assembly.
• Making Proxy Assembly For ActiveX Control: First, a proxy assembly is made using AxImp.exe (acronym for ActiveX Import) by writing following command on Command Prompt:

C:>AxImp C:MyProjectsMyControl.ocx
This command will make two dlls, e.g., in case of above command
MyControl.dll
AxMyControl.dll

The first file MyControl.dll is a .Net assembly proxy, which allows you to reference the ActiveX as if it were non-graphical object.
The second file AxMyControl.dll is the Windows Control, which allows u to use the graphical aspects of activex control and use it in the Windows Form Project.
• Adding Reference of ActiveX Proxy Assembly in your Project Settings: To add a reference of ActiveX Proxy Assembly in our Project, do this:
o Select ProjectàAdd Reference… (Select Add Reference from Project Menu).
o This will show you a dialog box, select .Net tab from the top of window.
o Click Browse… button on the top right of window.
o Select the dll file for your ActiveX Proxy Assembly (which is MyControl.dll) and click OK
o Your selected component is now shown in the ‘Selected Component’ List Box. Click OK again
Some More On Using COM or ActiveX in .Net
• .Net only provides wrapper class or proxy assembly (Runtime Callable Wrapper or RCW) for COM or activeX control. In the background, it is actually delegating the tasks to the original COM, so it does not convert your COM/activeX but just imports them.
• A good thing about .Net is that when it imports a component, it also imports the components that are publically referenced by that component. So, if your component, say MyDataAcsess.dll references ADODB.dll then .Net will automatically import that COM component too!
• The Visual Studio.NET does surprise you in a great deal when u see that it is applying its intellisense (showing methods, classes, interfaces, properties when placing dot) even on your imported COM components!!!! Isn’t it a magic or what?
• When accessing thru RCW, .Net client has no knowledge that it is using COM component, it is presented just as another C# assembly.
• U can also import COM component thru command prompt (for reference see Professional C# by Wrox)
• U can also use your .Net components in COM, i.e., export your .net components (for reference see Professional C# by Wrox)

Showing Answers 1 - 1 of 1 Answers

samiksc

  • Jan 13th, 2006
 

ActiveX control is actually a COM component. For using a COM component in a .net project you can follow one of the following two procedures --

  1. For private COM components -- In the .net project click Add reference and navigate to COM tab. Select the COM component, which will create a proxy for the component which is conforming to .net. This proxy is called Runtime Callable Wrapper (RCW)
  2. For shared COM components -- Use the command line utility 'tlbimp' to create a RCW from COM component. Using this utility allows you to give the RCW a name, specify namespace and other advanced settings. Then add a reference to the imported DLL from your .Net project as usual.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions