Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The simple COM App --> .NET Form --> COM function --> COM Form scenario can work using the <a href="http://www.microsoft.com/en-us/download/details.aspx?id=3264" rel="nofollow">InteropForms Toolkit 2.1</a>. Here is some code that does it, without using delegates or <code>AddressOf</code>.</p> <p>First, we have our COM library which I'll call ComLibrary. We have the following code:</p> <p><strong>SimpleForm.frm:</strong></p> <pre><code>Option Explicit Private Sub Form_Load() MsgBox "In SimpleForm_Load" End Sub Private Sub OkButton_Click() Unload Me End Sub Private Sub TalkButton_Click() MsgBox "Hello" End Sub </code></pre> <p><strong>SimpleClass.cls:</strong></p> <pre><code>Option Explicit Public Function ShowTheDialog() As Long Dim f As SimpleForm Set f = New SimpleForm f.Show vbModal ShowTheDialog = 1 End Function </code></pre> <p>Compile this to a .dll so that we can reference it in our .NET library.</p> <p>Next, we'll create our .NET forms library. I did this using the "VB6 InteropForms Library" project template using the default project name of InteropFormsLibrary1. I added a reference to the ComLibrary project. The form has a single button named "CallComFunction."</p> <p><strong>InteropForm1.vb:</strong></p> <pre><code>Imports Microsoft.InteropFormTools &lt;InteropForm()&gt; _ Public Class InteropForm1 Private Sub CallComFunction_Click(sender As System.Object, e As System.EventArgs) Handles CallComFunction.Click Dim sc As ComLibrary.SimpleClass sc = New ComLibrary.SimpleClass Dim result As Integer result = sc.ShowTheDialog() End Sub End Class </code></pre> <p>Before compiling this, we need to create the InteropForms wrapper classes per the toolkit documentation. Do this by accessing the Tools > Generator InteropForms Wrapper Classes menu.</p> <p>Finally, we create the VB6 host app.</p> <p><strong>Form1.frm:</strong></p> <pre><code>Option Explicit Private Sub DialogButton_Click() Dim f As InteropFormLibrary1.InteropForm1 Set f = New InteropForm1 f.Show vbModal End Sub </code></pre> <p>When I run the host application in the VB6 IDE, I can click the button the VB6 form which then displays the VB.NET form. From there, I click another button which uses an instance of SimpleClass to display SimpleForm. The <code>MsgBox</code> statements in the form load event and the button click handlers work. And everything works when compiling the VB6 host app as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload