From: alibabouin on
Hi,

I'm trying to load a function (fixed name) from a dll whose name is
known only at runtime.
For example:
Private Declare Function Init_Plugin Lib "plugin.dll" () As Long
Where "plugin.dll" can be named foo_plugin.dll or whatever.

Thanks in advance.
From: Auric__ on
On Wed, 25 Jun 2008 13:25:54 GMT, wrote:

> I'm trying to load a function (fixed name) from a dll whose name is
> known only at runtime.
> For example:
> Private Declare Function Init_Plugin Lib "plugin.dll" () As Long
> Where "plugin.dll" can be named foo_plugin.dll or whatever.

You need to play with a few API calls. Load the DLL using
LoadLibrary. GetProcAddress and CallWindowProc to access the
functions in the DLL. FreeLibrary when you're done. (Don't leave out
FreeLibrary!)

This page describes LoadLibrary, and links to some sample code:
http://allapi.mentalis.org/apilist/LoadLibrary.shtml

For loading an unknown number of plugins, try something like this
(untested air code):

declare function LoadLibrary 'etc
declare function GetProcAddress 'etc
declare function CallWindowProc 'etc
declare function FreeLibrary 'etc

type plugin
name as string
number as long
end type
dim plugins() as plugin

function loadPlugins() as long
chdir plugInDir$
libs& = -1
do
l$ = dir$("*.dll")
if not len(dir$) then exit do
libs& = libs& + 1
redim preserve plugins(libs&)
with plugins(libs&)
.name = l$
.number = LoadLibrary(l$)
tmp& = GetProcAddress(.number, "Plugin_Start")
end with
CallWindowProc tmp&, me.hwnd, "", 0&, 0&
loop
' return the number of plugins loaded
loadPlugins = (libs& + 1)
end sub

sub unloadPlugins()
' do this when you exit the app
' (or are otherwise done with the plugins)
for libs& = ubound(plugins) to 0 step -1
tmp& = FreeLibrary(plugins(libs&).number)
next
end sub

--
Moo! Moo!! Mooo!!! I am voodoo cursing you!