kernel32: Check for already loaded module also for LOAD_LIBRARY_AS_DATAFILE.

This commit is contained in:
Alexandre Julliard 2007-05-16 16:58:51 +02:00
parent 306d71c3fe
commit 8530cb0aec
2 changed files with 18 additions and 5 deletions

View File

@ -844,24 +844,37 @@ static HMODULE load_library( const UNICODE_STRING *libname, DWORD flags )
HMODULE hModule; HMODULE hModule;
WCHAR *load_path; WCHAR *load_path;
load_path = MODULE_get_dll_load_path( flags & LOAD_WITH_ALTERED_SEARCH_PATH ? libname->Buffer : NULL );
if (flags & LOAD_LIBRARY_AS_DATAFILE) if (flags & LOAD_LIBRARY_AS_DATAFILE)
{ {
ULONG magic;
LdrLockLoaderLock( 0, NULL, &magic );
if (!(nts = LdrGetDllHandle( load_path, flags, libname, &hModule )))
{
LdrAddRefDll( 0, hModule );
LdrUnlockLoaderLock( 0, magic );
goto done;
}
LdrUnlockLoaderLock( 0, magic );
/* The method in load_library_as_datafile allows searching for the /* The method in load_library_as_datafile allows searching for the
* 'native' libraries only * 'native' libraries only
*/ */
if (load_library_as_datafile( libname->Buffer, &hModule )) return hModule; if (load_library_as_datafile( libname->Buffer, &hModule )) goto done;
flags |= DONT_RESOLVE_DLL_REFERENCES; /* Just in case */ flags |= DONT_RESOLVE_DLL_REFERENCES; /* Just in case */
/* Fallback to normal behaviour */ /* Fallback to normal behaviour */
} }
load_path = MODULE_get_dll_load_path( flags & LOAD_WITH_ALTERED_SEARCH_PATH ? libname->Buffer : NULL );
nts = LdrLoadDll( load_path, flags, libname, &hModule ); nts = LdrLoadDll( load_path, flags, libname, &hModule );
HeapFree( GetProcessHeap(), 0, load_path );
if (nts != STATUS_SUCCESS) if (nts != STATUS_SUCCESS)
{ {
hModule = 0; hModule = 0;
SetLastError( RtlNtStatusToDosError( nts ) ); SetLastError( RtlNtStatusToDosError( nts ) );
} }
done:
HeapFree( GetProcessHeap(), 0, load_path );
return hModule; return hModule;
} }

View File

@ -424,14 +424,14 @@ START_TEST(loader)
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
hlib_as_data_file = LoadLibraryEx(dll_name, 0, LOAD_LIBRARY_AS_DATAFILE); hlib_as_data_file = LoadLibraryEx(dll_name, 0, LOAD_LIBRARY_AS_DATAFILE);
ok(hlib_as_data_file != 0, "LoadLibraryEx error %u\n", GetLastError()); ok(hlib_as_data_file != 0, "LoadLibraryEx error %u\n", GetLastError());
todo_wine ok(hlib_as_data_file == hlib, "hlib_as_file and hlib are different\n"); ok(hlib_as_data_file == hlib, "hlib_as_file and hlib are different\n");
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ok(FreeLibrary(hlib), "FreeLibrary error %d\n", GetLastError()); ok(FreeLibrary(hlib), "FreeLibrary error %d\n", GetLastError());
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
hlib = GetModuleHandle(dll_name); hlib = GetModuleHandle(dll_name);
todo_wine ok(hlib != 0, "GetModuleHandle error %u\n", GetLastError()); ok(hlib != 0, "GetModuleHandle error %u\n", GetLastError());
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ok(FreeLibrary(hlib_as_data_file), "FreeLibrary error %d\n", GetLastError()); ok(FreeLibrary(hlib_as_data_file), "FreeLibrary error %d\n", GetLastError());