SIGN UP MEMBER LOGIN:    
ARTICLE

Host an OCX control within a .Net windows application-.Net and COM part IV

Posted by Bechir Bejaoui Articles | COM Interop November 03, 2008
In this article I will explain how to host an OCX control within a .Net application.
Reader Level:
Download Files:
 

I invite you to follow those steps to perform that.

Walkthrough

  1. Create an OCX customized control, either using Visual C++6.0 or Visual Basic 6.0 or download one from the internet, any one because the purpose here is to step through the manner of hosting it within a given Windows .Net application. (In my case, I ran the research on local machine for a given OCX and I have chosen the MSFlexGrid.ocx control and a testing control.

  2. Copy and paste your control in the root drive say the C:\ 
     
  3. Open the command prompt by browsing to Start>All programs>Accessory>Command prompt then type those couple of lines as bellow:

      

    The aximp that stands for ActiveX Control Importer is used in this case. It does the conversion type definitions according to COM type library for an OCX control into a standard Windows Forms control. Because Windows Forms can only host Windows Forms controls and not any other control types at any cases including the OCX ones, Of Corse. Aximp.exe generates a wrapper like the RCW the runtime callable wrapper class for an ActiveX control that can be hosted on a Windows Form. This is the only way that allows the OCX use.

    As the figure above shows, there is a new generated dll called MSFlexGridLib.dll located in C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin.

  4. Create a new Windows application project.

  5. Add a reference to this dll by going to the solution explorer, right clicking on the project and selecting Add reference menu item.



    Figure 1

  6. Select browse tab as follow :



    Figure 2

  7. As you can remark, the reference to your new generated dll is added.



    Figure 3

  8. Now, add the namespace using AxMSFlexGridLib; then add this couple of code within the load event handler
    stub as under:

    private
    void Form1_Load(object sender, EventArgs e)
        {
            AxMSFlexGrid oGrid = new AxMSFlexGrid();
            oGrid.Visible = true;
            oGrid.Parent = this;
            oGrid.Dock = DockStyle.Fill;
            oGrid.CellBackColor = Color.Bisque;
            oGrid.Cols = 7;
            oGrid.Rows = 30;
        }

  9. Finally, run the application.



    Figure 4
That's it
Good Dotneting !!!







 

Login to add your contents and source code to this article
share this article :
post comment
 

Not at all youre welcome

Posted by Bechir Bejaoui Aug 30, 2010

Thanks, It's a very nice way to host OCX file in window application

Posted by Sachin Kumar Aug 30, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Become a Sponsor