tags:

views:

376

answers:

2

hello all,

We are currently working on porting an old VB6 application to WPF. The plan, in phase one, is to port several key forms and not all the application. Its been brought up that we might try and open some of the old VB6 form from within the WPF application (as modal forms), thus providing greater functionality then intended for the first phase.

My question for you friends, first of all, is this kind of abomination :) even possible? Can VB6 forms can be opened from a WPF application?

Thanks, Shahaf.

A: 

Yes this is possible; depending on how hard you're willing to work. The key scenarios that are supported are as follows (note: there are other supported scenarios but these are the key ones):

  1. WPF -> WinForms
  2. WinForms -> WPF

Given that with VB6 your objects are all COM objects, you can host them in WPF via WinForms. This is the location on MSDN where I'd recommend you start:

There are also a couple of really good books on WPF that cover interop with WPF (both directions), in order of preference on this topic:

  • WPF Unleashed (Adam Nathan)
  • Programming WPF (Chris Sells and Ian Griffiths)

I hope this helps.

PaulJ
A: 

What you need to do is package the forms into an ActiveX DLL and expose classes that can setup the initial values, bring up the forms, and return whatever values they modify.

For example in my own CAD/CAM applications we have the Forms, then a layer that consists nothing of Command Objects (classes that implement the Command Design Pattern) that modify the model, and the model all written in VB6.

Some of the Commands call dialogs that are VB6 Forms. Some are simple and other are complex. The first phase of our conversion project was to rip off the top form layer and replace it with a .NET equivalent. The new .NET forms referenced the Active DLLs containing the Command Object.

It worked fine. There were some visual differences between the .NET look and the look of a VB6 form but other than the command dialogs ran just as they did under the VB6 executable.

One note of caution is that if you are continuing to modify the original ActiveX DLLs during this process then building the .NET program becomes a bit of pain. Unlike VB6, .NET isn't as automatic when it comes to updated references to newer versions of a referenced ActiveX library. The solution is simple, you drop the original reference and then add the new reference.

RS Conley
Are your .NET forms WPF or WinForms?
MarkJ
I have done this with both.
RS Conley