RichardL wrote:My understanding is that when a library is opened without a complete path name the OS looks in two places; (1) the directory the program was launched from and (2) in the System32 directory. Does anyone know if there is a fixed order for this, or alternatively is there a way of finding out which directory the DLL was launched from.
Correct, program folder (as far as I know) then fallback to system folder.
However, if the dll is allready loaded (by the system or some other program)
and in memory, then windows will use that instead.
That dll could either be one in system folder or in some other programs folder.
My advice is that unless the dll is only used by your program alone,
(in which case call it something really unique filename wise to avoid any conflict with similary named dll's)
then make a small dll installer using
http://nsis.sourceforge.net/ or similar,
that way you can be sure the user has the latest (your installer will install if the user has a old, or skip if the user has a more recent version).
As far as getting the dll path, I think the method is similar/same to that of exe's.
Code: Select all
;name$ contains the name of the module (either a .dll or .exe file).
;If the file name extension is omitted, the default library extension
;.dll is appended. The file name string can include a trailing point
;character (.) to indicate that the module name has no extension.
;The string does not have to specify a path. When specifying a path,
;be sure to use backslashes (\), not forward slashes (/).
;The name is compared (case independently) to the names of modules currently
;mapped into the address space of the calling process.
Procedure.s GetModuleFilePath(name$)
path$=Space(#MAX_PATH)
hndl=GetModuleHandle_(name$)
If hndl
If GetModuleFileName_(hndl,@path$,#MAX_PATH)>0
path$=GetPathPart(path$)
EndIf
EndIf
ProcedureReturn Trim(path$)
EndProcedure
;Returns the path or "" if failed!
Debug GetModuleFilePath("kernel32.dll")
EDIT: This should let you know where/what the loaded dll was "found" by the system.
PS! should also work with executables, read PSDK/MSDN for more info on these API calls.
NOTE! Only dll's or exe's in your process memory space will be found, anything not loaded/mapped into your programs memory space will just return ""