• 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")
msgbox(x.test)
0
TRUENEUTRAL
Asked:
TRUENEUTRAL
  • 3
  • 2
1 Solution
 
S-TwilleyCommented:
I had a similar problem:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21314576.html

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

You are using an interface.  I was looking for a way to avoid that.
0
 
S-TwilleyCommented:
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)
        MsgBox(ret.ToString)

========================================================

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
0
 
TRUENEUTRALAuthor Commented:
Thanks, that is what I was looking for.
0

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