Show VB6 Form from .NET - How to ?

A

Antonio Paglia

I would wish to be able to open an existing VB6 Form from my VB.NET
application.

All VB6 forms are in COM dll. My COM dll expose a Public Class with a method
that return an instance of my VB6 form.

I have used tlbimp.exe utility to generate a RCW.(wrapper). The wrapper name
is SecurityNet

Dim objApplication As New SecurityNet.Application
Dim FormVB6 As Object
Dim FormNET As Form

FormVB6 = objApplication.GetMDIChild("frmUsers")
FormNET = CType(FVB6, Form) ---------------------------------> I get an
error: Conversion is not valid
FormNET.Show

Any help will be appreciated
TIA
Antonio
 
P

Patrice

The "Form" datatype is likely for now System.Windows.Forms.Form and not the
usual VB6 Form datatype hence this error...

You may want to add the correct namespace whatever you called it (or you
could keep late binding if you don't have anything else to do than showing
the form).

If you intended to "cast" your VB6 Form to System.Windows.Forms.Form, it
will not work (they are not "compatible" and in particular this is not the
same data type).

Patrice
 
A

Antonio Paglia

This means that COM Interop works fine only for classes but does not with
Forms ? There is a way to reuse my olds VB6 forms from NET applications ?
Antonio
 
P

Patrice

I meant that the problem is that you have likely a confusion between Form
(the VB6 datatype) and System.Windows.Forms.Form (which is something
different).

Here it looks like you are doing :

AWindows.Forms.Form variable = a VB6 Form Variable...

It won't work. The fact that the VB6 type and the .NET type are using the
same name doesn't make them the same type...

Unless you need to do extensive Form manipulation you could use here :

FormVB6.Show()

else see wiht the object browser what is exported by the VB6 DLL. If this is
the Form type yo(ull have to indicate the full name space to avoid a
confusuion with the .NET Form type).

Patrice


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top