I'm pretty much new to dlls and was wondering dlls work great for plugins which I want my current program to allow for but I don't want to have to recompile my main program then recreate the distribution disks just to load the new dll for a plugin.

So my question is can you create a function in the main program to automatically loads plugins that are found in a sub directory?

Is this too much work or would implementing such a feature be not worth the problems and where can I find more information or code?

Thanks ahead!
Posted on 2001-11-01 21:02:56 by JamesE
Loading DLL's dynamically is easy. Take a look at the LoadLibrary and GetProcAddress functions. Here's an example:

.model flat,stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\kernel32.lib


mymsg db "Hello World!",0
dllfile db "User32.dll",0
procname db "MessageBoxA",0


invoke LoadLibrary,addr dllfile
invoke GetProcAddress,eax,addr procname

push 0
push offset mymsg
push offset mymsg
push 0
call eax ; Call MessageBoxA

invoke ExitProcess,0
end start

That shows how to load the function MessageBoxA from User32 and call it.
Posted on 2001-11-01 21:09:34 by Eagle17
So would it be posible with a little planning a head of time create an ini file listing all functions in the dll then in the main program, simply search for all the ini files and read through them placing the function names in an array then load the dll.

What I would like to acheive is simple dragin'drop plugin adding to my current software so I don't need to recompile, from the code above you have to recompile just to add another dll to load.
Posted on 2001-11-01 21:30:01 by JamesE
The code above was just an example to show you how to load a DLL if you don't have it in your imports :) But about the .INI thing, that may be a little hard, it's definitely possible but i wouldn't recommend it. I recommend you make a function like "AppLoadPlugin" in each plugin DLL and when your app wants to load a plugin it can just call this function. I think i've done this before and it worked pretty well.. anyway, just an idea good luck :alright:
Posted on 2001-11-01 21:41:15 by Eagle17
Thanks great idea:alright:

Thats way better than a crummy text file
Posted on 2001-11-01 21:54:19 by JamesE
Check the winamp plugin approach.
Download the sdk and toy with it.
Winamp expects you to dump your dll in some specific directory and all it wants is your dll to export a function whose name is well known.
This function is later used as a callback during winamp's execution.
Pretty simple :)

Posted on 2001-11-02 08:53:45 by latigo