Load wintun.dll from the application directory only
Do not attempt to load it from the System32 directory. See !294 (comment 755651565).
Different versions of wintun.dll or wintun.sys float around in system directories. In my case, a C:\Windows\System32\wintun.sys had been left behind for some reason, and was being loaded at startup, taking precedence over the wintun.dll bundled with OpenConnect. Unfortunately, different versions are not compatible, at least not entirely, while OpenConnect is being tested with the bundled wintun.dll only.
To avoid this DLL hell, we shall load exclusively the bundled version of wintun.dll from the application directory, and disregard any wintun.dll or wintun.sys installed in system directories by other software.
An application can specify the directories to search for a single LoadLibraryEx call by using the LOAD_LIBRARY_SEARCH_* flags. If more than one LOAD_LIBRARY_SEARCH flag is specified, the directories are searched in the following order:
- The directory that contains the DLL (LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR). This directory is searched only for dependencies of the DLL to be loaded.
- The application directory (LOAD_LIBRARY_SEARCH_APPLICATION_DIR).
- Paths explicitly added to the application search path with the AddDllDirectory function (LOAD_LIBRARY_SEARCH_USER_DIRS) or the SetDllDirectory function. If more than one path has been added, the order in which the paths are searched is unspecified.
- The System32 directory (LOAD_LIBRARY_SEARCH_SYSTEM32).