|
-
Dec 18th, 2004, 10:25 PM
#1
Thread Starter
Lively Member
Dynamically loading DLLs? (Plug-Ins)
Hi guys, this is not something I'm dealing with right now, but just planning ahead for my next project and would appreciate if someone could help me think this trough.
The basic idea is that I'm creating a C# app that will need something like plug-in support. The main program will start, look in the \Plugins directory which will contain a number of .dll files, take each one of those files, get information about each plug-in (name, version, description, some other stuff...), and then when needed call some functions from them.
So the first question is, of course, how do I go about doing this? More specifically, how can I take a string which contains the path to a dll file, load that file at run-time and then execute code from it? All the plug-ins will have a similar structure, so the interface will be the same. The only difference will be in what they do underneath.
If you have some ideas or even examples on the topic, please share them. As I said, this is just thinking forward, so I don't think I can give much more details, but if you have some experience with this type of thing, please give me some pointers (get it... pointers? oh god why did they have to go )
-
Dec 19th, 2004, 06:19 AM
#2
<?="Moderator"?>
Re: Dynamically loading DLLs? (Plug-Ins)
Heres a thread about dynamicly loading DLLs also has an example of how to do it.
http://www.vbforums.com/showthread.p...hlight=Plugins
Hope that helps
-
Dec 21st, 2004, 09:15 PM
#3
Thread Starter
Lively Member
Re: Dynamically loading DLLs? (Plug-Ins)
Thanks for your reply, I've looked over that example and it's not exactly what I need. It is impressive how you can compile code at run time, but what I'm more interested in is running code that was already compiled just separately. It seems like every way of doing this that I found so far involves the step where the new code is put into a string and then compiled, whereas I need to skip this step and go right to the execution part of it. Furthermore, I need the main code to be able to interact with this newly introduced code and do things like pass objects to the functions defined within that new code.
Update: Well I've actually been successful at creating a very simply dll which was only made up of a module and a single public function which showed a msgbox. Then I was able to use the assembly type to load that file, and execute that one function. The problem is that I now need to transfer this over to doing the same for classes. That seems to be a little more tricky, but it looks like I'm on the right track
Last edited by MXK; Dec 21st, 2004 at 09:52 PM.
-
Dec 21st, 2004, 09:55 PM
#4
Frenzied Member
Re: Dynamically loading DLLs? (Plug-Ins)
how can I take a string which contains the path to a dll file, load that file at run-time and then execute code from it?
That's one way to go about it, but depending on what your needs are, might not be the best. Another option is to discover plugins at run time, without the need to hard-code or have the end user add a line to your config file.
If you search this forum for "plugin" or maybe "plug-in", you find some limited discussion. By far the best I've read on this subject is this article
That article rocks.
Mike
-
Dec 21st, 2004, 09:59 PM
#5
Thread Starter
Lively Member
Re: Dynamically loading DLLs? (Plug-Ins)
Well I'm obviously not going to hard code the plug-in paths or have a config file. Like I said before, I have a folder named "Plugins", so at run time I will have a Directory object give me an array of all the files in that dir and then I will take each path one by one and load it up into my main app.
I will take a look at that article, maybe it'll help me out some more
-
Dec 21st, 2004, 10:11 PM
#6
Frenzied Member
Re: Dynamically loading DLLs? (Plug-Ins)
Yes. Read that article, and whatever else information you can find, and then decide what works best for you. This is the thing - it may be easier to specify in a config file the plugins you want to load, but that's only if your end user doesn't have to mess with it.
The down side of dynamically loading assemblies in this method is that it is impossible to know, before you load it, if it actually implements your interface. Once you load it, there is no way to unload it. That article discusses the work around, but the amount of time you feel like spending on this work around is up to you.
In my implementation, I've taken a short cut. That is, I pretty much assume that only my (good) dll's exist in my plugin directory.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|