• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 587
  • Last Modified:

Import dll at runtime - 500pts

I need to be able to import a dll at runtime and call functions contained within it.

For example:
The user inputs the path and name of the dll.  I need to take that string and use it to import the dll at that location and then call a function (and catch the return value).

something like:
dim x as new ("mydll.dll")
  • 3
  • 2
1 Solution
I had a similar problem:


let me know if you want any more feedback
TRUENEUTRALAuthor Commented:
That basically works, but I was really looking for a way to get around that interface class
TRUENEUTRALAuthor Commented:
S-Twilley, I would really like more feedback.

You are using an interface.  I was looking for a way to avoid that.
Ok, im not sure how safe this is, but it worked for me:


        Dim obj As Object
        Dim DevAss As Reflection.Assembly = Reflection.Assembly.LoadFrom("D:\My Documents\Visual Studio Projects\TestLibrary\bin\TestLibrary.dll")
        Dim DevType As System.Type = DevAss.GetTypes()(0) 'Assumes device class is first object

        obj = DevAss.CreateInstance(DevType.FullName)
        Dim ret As Object = DevType.InvokeMember("Test", Reflection.BindingFlags.InvokeMethod, Nothing, obj, Nothing)


Code in TestLibrary.Dll

Public Class Class1
    Public Function Test() As String
        Return "This is the value returned from Test()"
    End Function
End Class


There might be a better way of doing it, but thats what i just came up with now
TRUENEUTRALAuthor Commented:
Thanks, that is what I was looking for.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now