Okay I'm trying to set up an open file dialog to grab a dll of my choice, then inject it into the application. I know how to use my own custom DLLs, but I also want the ability to make DLLs then use them without modifying the source after run time.

My idea was to use the DLLImport but that didn't work... It turns out that this will be a little more complicated than I thought. I'm not very far into my C# studies so this is very new to me. DLLs in particular are a completely new universe. I just began trying to bring them into my programming. Below is my current source code, the only thing I have done so far is open the dialog.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace DLLOpen
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        void button1_Click(object sender, EventArgs e)
        {
            oFD.ShowDialog();
        }
    }
}

So can anyone help me with this?

DLLImport is for DLLs that are not created for managed code (C#, F#, C++ managed, etc.)

What it sounds like you want to do is to create a plug-in type system. These can be very complicated to do as there are many things to consider (that I'm not going into right now).

The easiest way to do what you want is Assembly.LoadFrom(filename).

P.S. I've been considering writing a plug-in tutorial, maybe this will motivate me :)

Making a plugin is simple, however allowing the user to make one then open it into your program as a new form, that is difficult.

To create a plugin:

Create a forms application, then once you've programed it, go to properties and change it from forms application to class library and build it.

Finally add it to the references of the project you're using as the main application, then make sure you create a new instance before showing the plugin.


using pluginName;

pluginName.Form1 myForm = new pluginName.Form1();
myForm.Show();

Edited 5 Years Ago by lxXTaCoXxl: n/a

Well then do me a favor. :D Make a tutorial that way I don't get confused anymore. :)

This article has been dead for over six months. Start a new discussion instead.