Hi - I've done a bit of VB.net programming but am still learning ..
I want to create a .net DLL which I will call from another application (NS Teststand).
When I call the Dll -
1. I will need to pass a string to it,
2. It must show a form,
3. display the string in the form
4. then ask a user to type something into a text box ( also on the form) and click an OK button.
5. when the Ok button is clicked the form should close and return the data in the text box.

I can setup the dlll - with a form inside ....textbox ., buttons etc... but am not sure how to call the dll and how to open the form inside the dll, then pass the string to it and return the textbox text from it ..back to the Dll caller.
Also, I've seen a earlier post here with a similiar issue I am having ..this is, the events inside the form in the DLL don't seem to work ... but there was no resolution to that post

Does anyone have any sample code I could look at ?
appreciate your help in advance.
B.

Provided the DLL references appropriate assemblies for your presentation (WinForms or WPF), displaying a form and returning the result is a no-brainer. The key will be deciding how you want your application to call into the DLL. It can be as simple as exposing a public dialog form and doing this:

Using dlg As New MyDialog(initStr)
    If dlg.ShowDialog = DialogResult.OK Then
        TextBox1.Text = dlg.Result
    End If
End Using

That's actually how I'd do it, and how I've usually chosen to do it before (I've done this a lot since extensions and customizations through plugin DLLs are something I do often) because it cleanly separates responsibility.

many thanks deceptikon for your reply,
your reply is maybe a bit beyond my knowledge at present.
I guess I should make it simple for myself for a start... and use a vb.net exe to call the dll to start with.

do you have any sample Dll code that might do something I'm looking for and show how you call them ?
thanks

Here's a simple class that can be compiled as a dll. Add a reference to System.Windows.Forms first. I included a sample of an event handler as well:

Imports System.Windows.Forms
Public Class NewDLLForm
    Inherits Form
    Public Sub New(Caption As String)
        Text = Caption
        AddHandler Me.Click, AddressOf Me_Click
    End Sub
    Private Sub Me_Click(sender As Object, e As EventArgs)
        MessageBox.Show(Text)
    End Sub
End Class

Once you build this, in the project's bin/Debug folder add the .dll file there as a reference to your forms project. Import the dll to the form file.

Imports VBDLLForm

Public Class Form1        
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim NewForm As New NewDLLForm("Test this string")
        NewForm.Show()
    End Sub
End Class

When you run the form with a button on it named Button1, clicking the button will open the new form with the text set to the string. When you click on the form a messagebox will pop up showing the same string..

thanks very much - I think thats what I'm looking for

regards

I was looking at this further ... This code seems to create a new form.
Can I have a form already created inside the Dll and just call that form ( and pass parameters into and out of it ?
( instead of creating a new form )
thanks

Add the default properties to the dll. You can specify which properties you want changed in the constructor. You can also add any controls that you want. Creating a new instance of the form allows the calling process to also have control and make any further changes. You also have the option to restrict changes by making some aspects private.

The sample from my previous answer sets the Text property. Any of the properties can be preset there.

This question has already been answered. Start a new discussion instead.