I believe this is not possible to do.
However, you can add a directory to the process DLL search path using the function AddDllDirectory
, but as it is is a recent API, if you are using a version inferior to Windows 8, it will be necessary to install a patch.
The signature of the function is:
Imports System.Runtime.InteropServices
'
<DllImport("kernel32", SetLastError:=True, CharSet:=CharSet.Unicode)> _
Public Function AddDllDirectory(NewDirectory As String) As Integer
End Function
If you want to modify the default search path, use the function SetDllDirectory
.
An article that may be useful to read is Dynamic-Link Library Search Order that mentions:
Before the system searches for a DLL, it scans the following:
- If a DLL with the same name of the module is already loaded in memory, the system uses the DLL loaded, no matter which directory
which is found. The system is not searching for the DLL.
- If the DLL is in the list of known Dlls for the version of Windows on which the application runs, the system uses its
copy of DLL known (and DLLS dependent on the known DLL, if
exists). The system does not search for the DLL.
To get a dll list
known in the current system, see the following registry key:
HKEY_LOCAL_MACHINE
⇢ SYSTEM
⇢ CurrentControlSet
⇢ Control
⇢ Session
Manager
⇢ KnownDLLs
.
In a passage further down the value is still mentioned SafeDllSearchMode
which is kept in the register.
If SafeDllSearchMode
is enabled in Winxp it is disabled
by default, the search order is as follows:
- The directory from which the application was loaded.
- The system directory. Use the function
GetSystemDirectory
to get the path to that directory.
- The system directory of 16 bits. There is no function that gets the path from this directory, but it is searched.
- The Windows directory. Use the function
GetWindowsDirectory
to get the path to that directory.
- The current directory.
- The directories listed in the environment variable
PATH
.
Note that this does not include the path per application specified by the registration key App Paths
.
If the paths absolute of the DLL are different, but the paths relative are equal, you can use a constant expression.
– dcastro
It will be different paths, it may be that in a micro a dll stay in C:, in another stay in the system32 or windows folder. That’s why I need to reference in a variable, ouu...?
– Felipe S
And the name of dll? It is constant?
– dcastro
No, neither name nor path, only functions.
– Felipe S