Wednesday, June 04, 2008

Use VB.NET user control as Active X (ocx) control in VB6

Writing post after long time. This seems to be a very common problem. When you are having a existing VB6 application that is going to be upgrading to VB.NET application but you need to go step by step. So most of new development is done using VB.NET and then you integrate that your VB6 application. There are two scenarios here:
1. You write business logic/data layer in VB.NET which is basically a ".dll" file. This file you can use in your VB6 code by using "regasm" for registering the DLL and creating "Type Library". Add this as reference to your project and use classes/methods and properties in your VB6 code.

2. You develop a user control or form in VB.NET and now you want to use in VB6. Now here lies the problem, VB6 only knows .OCX extensions for user control, it doesn't understand ".dll" extension for user controls. While searching on how this can be done without to much of effort I came across a really nice and easy solutions to this problem.

Interop Forms Toolkit provides solution for building VB.NET forms, controls and then using it easily in your VB6 code. It provides with excellent help on how to use the toolkit. Only thing what I found difficult was "How to deploy the application?"
Though there is help provided for that, I had lot of problems while deploying the application. I'll research more on this and will get back in my next post as in what are easy ways to deploy the application using this tool.

3 comments:

Angrez Singh said...

One more way to use VB6 control is described over here:

http://bytes.com/forum/thread398225.html

Easy but doesn't give you the freedom to load the control at design time.

Anonymous said...

HI Angrez,
I have a problem. I am able to attach a JS window that opens and redirect input to it. The window accepts an input and closes itself on the button click. Now inputs are not redirected to original window. Pls help.
@ie1=@ie.attach(:url, "http://125.63.90.43/portal/template/vi_add_booking_ref.vm/action/VIPurchaseDetailsAction/eventsubmit_doperfomoperation/doPerfomoperation")
@ie1.text_field(:name,"bookingRef").set "19"
@ie1.button(:name,"btn1").click
@ie1.close
sleep 5
@ie.select_list(:name,"miscOperations").select("Apply Booking Ref")

Andrew Stevenson said...

VB.NET uses managed code (code without pointers), and thus cannot generate an Active X control, which requires pointers.
ASP.NET Development Company