Import dll at runtime - 500pts

Posted on 2005-04-11
Last Modified: 2008-01-09
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")
    LVL 12

    Expert Comment

    I had a similar problem:

    let me know if you want any more feedback
    LVL 5

    Author Comment

    That basically works, but I was really looking for a way to get around that interface class
    LVL 5

    Author Comment

    S-Twilley, I would really like more feedback.

    You are using an interface.  I was looking for a way to avoid that.
    LVL 12

    Accepted Solution

    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
    LVL 5

    Author Comment

    Thanks, that is what I was looking for.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now