Access DLL Function (Variable path)

cubix30
12-28-2007, 01:27 PM
Does anyone know how to access a function in a dll (not an ActiveX dll) when the path is variable? Usually, I know where the dll I want to access resides, so use code of the form:

Private Declare Function <VBfunction> Lib "<nameofdll.dll>" Alias "<DllFunctionname>" () As Long

The problem with this is that the <nameofdll.dll> part must be a constant, when I want it to be variable as I will not know where the dll is until after the program has started. :(

Any ideas?


(BTW, I have used so called 'late-binding' with ActiveX dlls where the path is variable, and it works great. However, I'm not really sure how to use late-binding in this case).

dilettante
12-28-2007, 01:39 PM
I'm not sure why the location would slosh around.

Windows has two standard DLL-search algorithms that go as described here: Dynamic-Link Library Search Order (http://msdn2.microsoft.com/en-us/library/ms682586.aspx). These can be overridden by use of either DLL redirection or the newer side-by-side manifest methods.

Though not described at the link above (oops, I'm wrong, it does describe them), unsupported versions of Windows (i.e. pre-Win2K SP4) used something very similar to the "SafeDLLSearchMode disabled" sequence of checks.

The same article talks about LoadLibraryEx() and SetDLLDirectory(), but I imagine only the first of these might apply in a VB6 program.

I haven't played with this myself, but I know I've seen a few people describe the use of LoadLibrary() calls in VB6 programs. Maybe they'll have something useful to say about this. You could try a search here too.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum