Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem calling VB6 forms from .NET app

Status
Not open for further replies.

ashishraj14

Programmer
Mar 1, 2005
92
0
0
AU
I have a VB6 application which I want to use in .NET application. I have created a public class in VB6 app which has following public method on it and compiled my VB6 app as ActiveX.exe

Public Function GetFormFrameHwnd() As Long
Dim frm As New frmCompany
GetFormFrameHwnd = frm.Frame2.hWnd

End Function

The above method returns window handle for frmCompany.Frame2 which is displayed in .NET Widnows Form using SetParent API call as follows

private void Form1_Load(object sender, EventArgs e)
{
Project1.Class1Class obj = new Project1.Class1Class();
SetParent(new IntPtr(obj.GetFrameHandle()), this.Handle);
}

I am facing two problems here. When .NET application is closed the VB6 keeps running in the back ground and doesn’t get destroyed (i can see it in Task List). Secondly controls doesn’t get populated with data and neither of the buttons work.

Could please suggest what I am doing wrong. Is there any other better way of calling VB6 forms from .NET app.

Thanks
 
While I haven't done any detailed testing of the ins and outs of the possible ramifications of your architecture, I believe the problem is that you're using an ActiveX EXE. This means that the class is running in a different process from the host .Net form. Since you have a form in it, it's pretty similar to creating a VB6 program, compiling it, and running it with a shell command from your .Net context. Just because you sever the link between your .Net process and the vb6 process, that doesn't mean that the latter automatically shuts down. It simply takes on a life of its own.

If you want to keep it as an exe, you might want to create a shutdown method and call it when you shut down the .Net app. Alternatively, you may want to create it as an ActiveX DLL. As such, it will run in the same process space as your .Net program, and the form ought to unload when you shut down.

HTH

Bob
 
I can't compile it as ActiveX DLL as it is a MDI app and contains plently of End statement. ActiveX DLL doesn't suppport either.

I'll try out the other trick (shut down method)
 
Aha. By the way, I wouldn't use the End statement in general. Hope the other trick works for you!

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top