1
votes

I have a VB6 project compiled as a VB6 exe.

It has a simple form as its startup object.

It launches a .NET modal form via a regasm'd .NET dll, passing it an implementation of a callback COM interface (IHandler).

.NET calls back to the IHandler implementation in VB6.

VB6 tries to show a new form using vbModal. The VB6 form is blocked from interaction because of the modal .NET form which is still visible.

Is there any way around this or a suggested approach?

I tried calling back to VB6 on a new (STA) (managed) thread, but when it tries to do MyCallbackForm.Show vbModal, I get "Invalid procedure call or argument."...which I assume has to do with the fact that I'm calling back on a new thread...


Update: I WAS able to successfully make a callback on the new thread and show my VB6 form modally IF I set my VB6 project type to ActiveX exe...but once I did that, I seemed to lose the thread on the callback - making subsequent calls from VB6 to .NET resulted in a cross threading exception. I'm guessing this has to do with the threading model when using ActiveX exe....

2

2 Answers

0
votes

You can display the form with the .NET control modeless in your VB6 application, but, then you'll have to do this:

  • create a .NET usercontrol which contains all the content that should be on the form.
  • Use the MS InteropToolkit to easily create a COM visible usercontrol, and let that control inherit from the usercontrol (you can also skip the first step, and make the usercontrol directly com-visible)
  • create a new form in your VB6 project, and add the COMVisible .NET usercontrol to it.
0
votes

You could split your VB6 EXE project into two projects.
Project one is the current VB6 project minus the subform you want to be able to display from your .Net DLL. Project two is a VB6 ActiveX DLL project that should contain the subform(s) that you want to be able to display from your .Net dll.

So, instead of doing: 1. VB6.exe project calls .Net DLL passing IHandler 2. .Net project calls function in IHandler 3. IHandler (VB6 implementation) tries to show a subform, no luck.

You do: 1. VB6.exe project calls .Net DLL passing whatever data the subform(s) need from the main project 2. .Net project calls "ShowYourSelf" function in ActiveX DLL containing the subform(s) and passes whatever data is neccessary.