SDL_LoadObject on Windows now calls LoadLibrary a second time in its EX form whenever the first load fails. This second call uses the "altered" search path for DLL dependencies, which includes searching the directory that the DLL itself lives in.
authorSam Lantinga <slouken@libsdl.org>
Sat, 28 Sep 2013 14:06:31 -0700
changeset 7757572546fa1c9b
parent 7756 f45660a4974c
child 7758 54c0acdf9c8e
SDL_LoadObject on Windows now calls LoadLibrary a second time in its EX form whenever the first load fails. This second call uses the "altered" search path for DLL dependencies, which includes searching the directory that the DLL itself lives in.
src/loadso/windows/SDL_sysloadso.c
     1.1 --- a/src/loadso/windows/SDL_sysloadso.c	Sat Sep 28 14:06:20 2013 -0700
     1.2 +++ b/src/loadso/windows/SDL_sysloadso.c	Sat Sep 28 14:06:31 2013 -0700
     1.3 @@ -34,6 +34,19 @@
     1.4  {
     1.5      LPTSTR tstr = WIN_UTF8ToString(sofile);
     1.6      void *handle = (void *) LoadLibrary(tstr);
     1.7 +
     1.8 +	/* By default LoadLibrary uses the current working directory 
     1.9 +	* as the first item on the search path for implicit dependencies
    1.10 +	* of whatever it's loading. That is somewhat inconsistent with
    1.11 +	* what dlopen does on other platforms, so we will try again
    1.12 +	* with LoadLibraryEx and a slightly different search path. This
    1.13 +	* causes Windows to search for dependencies in the directory 
    1.14 +	* that the module itself lives in. */
    1.15 +	if(handle == NULL)
    1.16 +	{
    1.17 +		handle = (void *) LoadLibraryEx(tstr, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
    1.18 +	}
    1.19 +
    1.20      SDL_free(tstr);
    1.21  
    1.22      /* Generate an error message if all loads failed */