Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Okay I am working on a project that is requiring us to submit dll's for calls.

Currently all the calls are made from the exe file that was written in VB6, yes we are upgrading. I have been playing around with creating dll's and actually have that part of it down just doing basic things for practice.

The realization is that the current program calls other forms to open for the different tasks. the different forms need to be called when that task is selected.

I have created a small program, it just does math functions. The main form lets you select what math function you want to perform. that calls another form that lets you enter the data. clicking on a a button calls the dll to perform the function. pretty simple.

What I would like to do is have the main form call the dll which will open the form for input and do the calculation. Which is on the idea of what we are going to have to do for the other program eventually.

The call from the Main form:

VB
Private Sub btnAdd_click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        frmadd.ShowDialog() ' calls the add 
    End Sub


Inputting data form: Input 2 numbers button click adds(this is where the dll is called) them and a close button to close form.

VB
Imports Multiply1
Public Class frmadd

Private Sub frmadd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

        Dim Adding As New Multiply1.MyAdd

        txtAddAns.Text = Adding.AddMyValues(CDbl(txtbox1.Text), CDbl(txtbox2.Text)).ToString
    End Sub

    Private Sub btndone_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndone.Click
        Me.Close()

    End Sub
End Class


This the code for dll

VB
Public Class MyAdd

    Public Function AddMyValues(ByVal Value1 As Double, ByVal Value2 As Double)

        Dim Result As Double

        Result = Value1 + Value2

        Return Result

    End Function

End Class


I have read several different articles but the one thing they don't do is show how to create the form then have have the dll call it. Maybe I am missing something easy but I just can't see it.

Scott
Posted
Updated 2-Oct-15 9:23am
v2
Comments
Philippe Mori 8-Oct-15 12:30pm    
Very long question... But hard to see what is your problem. Sample code does not seems to match question as second form (in application) appears to use the DLL and not the other way (a function in the DLL want to create a form in the application as the question seems to imply).

If the form is defined in the application, then you cannot directly create it from the DLL.

On the other hand, your code seem to call the DLL function to do the addition from the second form which is directly supported provide that you add the appropriate reference to your application project.

By the way a DLL can directly create forms it defined or any public forms in assemblies it reference directly.

And you can also indirectly create forms by passing information to the DLL (interface, callback function...) or by using reflection or some other means like Unity application block[^]
 
Share this answer
 
Well since I got a down check and have had to do even more extensive research on this question and it wasn't an easy answer to find but after all the research I have had to perform one would think that 1 person here could come up with the answer.

The answer is it doesn't appear to be possible to call a dll and open an form called in the dll. A form can another form or even a dll but the dll can't show a form. Not from what I have found out.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900