Updated Information About UseDLL() Dependancy Load Order

Updated Information About UseDLL() Dependancy Load Order

Summary

This article presents some information on the UseDLL() function

Synopsis

The UseDLL() function is explained in the InstallShield help document. However this knowledge base article will explain in further detail, how you can force the UseDLL() function to bypass it's default load order and use a specific path to search for dependancy files.

Discussion

If your .dll and dependency files are located in the same folder, then using the ChangeDirectory() call to set the current folder to this path should allow the UseDLL() to load the dependency files as expected. However, the UseDLL() function goes through a load order, as explained in the following MSDN article Dynamic-Link Library Search Order. In short, UseDLL() will first check the Windows Systems folders for the dependancy files, before it checks the current directory.

NOTE: It's bad practice to include any dependancy system files and you should remove these files if you are doing so.

So if you are including a third party dependancy.dll, which can also be found in the Windows System folder, then due to the load order the copy found in thw Windows System folder will always be used. The information below will show you how to bypass this load order and force UseDLL() to load dependency files from a specific path.

Workaround

You have two options to handle this.

1.) Calling the UseDLL() function multiple times.
This option basically means that you will first call the UseDLL() function to load all dependancy files into memory before calling the UseDLL() function on your actual .dll file. This approach should avoid load order issues, while still allowing you to use the specific dependency files you want.

2.) Use SetDllDirectory() API.
This option will make use of the SetDllDirectory() API to force the search path for dependency files...

prototype BOOL Kernel32.SetDllDirectory(BYREF WSTRING);

So if you call SetDllDirectory() before your UseDLL() call like so...

SetDllDirectory(szMyDirPath);
dllPath=szMyDirPath^"upgrade.dll";
nResult = UseDLL(dllPath);

...it will bypass the default search path and go to szMyDirPath to load any dependent files.

Now this API call will affect the search order on the system, so you will need to reset the default search order bay passing in NULL to the SetDllDirectory() api. To do so, you can take a look at the help document Using Null-Delimited Strings and basically set (szDirectory = "\0") as \0 is the escape sequence for a null character.
Was this article helpful? Yes No
No ratings
Version history
Revision #:
1 of 1
Last update:
‎Jul 09, 2018 10:11 PM
Updated by: