Commit a09cd1b8 authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

oleaut32: Call SearchPath before LoadLibrary so that we get the full path of native exes and dlls.

For builtin dlls prepend the system directory.
parent 12e3d642
...@@ -2214,37 +2214,41 @@ static int TLB_ReadTypeLib(LPCWSTR pszFileName, LPWSTR pszPath, UINT cchPath, IT ...@@ -2214,37 +2214,41 @@ static int TLB_ReadTypeLib(LPCWSTR pszFileName, LPWSTR pszPath, UINT cchPath, IT
int ret = TYPE_E_CANTLOADLIBRARY; int ret = TYPE_E_CANTLOADLIBRARY;
INT index = 1; INT index = 1;
HINSTANCE hinstDLL; HINSTANCE hinstDLL;
LPWSTR index_str, file = (LPWSTR)pszFileName;
*ppTypeLib = NULL; *ppTypeLib = NULL;
lstrcpynW(pszPath, pszFileName, cchPath); index_str = strrchrW(pszFileName, '\\');
if(index_str && *++index_str != '\0')
/* first try loading as a dll and access the typelib as a resource */
hinstDLL = LoadLibraryExW(pszFileName, 0, DONT_RESOLVE_DLL_REFERENCES |
LOAD_LIBRARY_AS_DATAFILE | LOAD_WITH_ALTERED_SEARCH_PATH);
if (!hinstDLL)
{ {
/* it may have been specified with resource index appended to the LPWSTR end_ptr;
* path, so remove it and try again */ long idx = strtolW(index_str, &end_ptr, 10);
const WCHAR *pIndexStr = strrchrW(pszFileName, '\\'); if(*end_ptr == '\0')
if(pIndexStr && pIndexStr != pszFileName && *++pIndexStr != '\0')
{ {
index = atoiW(pIndexStr); int str_len = index_str - pszFileName - 1;
pszPath[pIndexStr - pszFileName - 1] = '\0'; index = idx;
file = HeapAlloc(GetProcessHeap(), 0, (str_len + 1) * sizeof(WCHAR));
hinstDLL = LoadLibraryExW(pszPath, 0, DONT_RESOLVE_DLL_REFERENCES | memcpy(file, pszFileName, str_len * sizeof(WCHAR));
LOAD_LIBRARY_AS_DATAFILE | LOAD_WITH_ALTERED_SEARCH_PATH); file[str_len] = 0;
} }
} }
/* get the path to the specified typelib file */ if(!SearchPathW(NULL, file, NULL, cchPath, pszPath, NULL))
if (!hinstDLL)
{ {
/* otherwise, try loading as a regular file */ if(strchrW(file, '\\'))
if (!SearchPathW(NULL, pszFileName, NULL, cchPath, pszPath, NULL)) {
return TYPE_E_CANTLOADLIBRARY; lstrcpyW(pszPath, file);
}
else
{
int len = GetSystemDirectoryW(pszPath, cchPath);
pszPath[len] = '\\';
memcpy(pszPath + len + 1, file, (strlenW(file) + 1) * sizeof(WCHAR));
}
} }
if(file != pszFileName) HeapFree(GetProcessHeap(), 0, file);
TRACE_(typelib)("File %s index %d\n", debugstr_w(pszPath), index); TRACE_(typelib)("File %s index %d\n", debugstr_w(pszPath), index);
/* We look the path up in the typelib cache. If found, we just addref it, and return the pointer. */ /* We look the path up in the typelib cache. If found, we just addref it, and return the pointer. */
...@@ -2257,13 +2261,16 @@ static int TLB_ReadTypeLib(LPCWSTR pszFileName, LPWSTR pszPath, UINT cchPath, IT ...@@ -2257,13 +2261,16 @@ static int TLB_ReadTypeLib(LPCWSTR pszFileName, LPWSTR pszPath, UINT cchPath, IT
*ppTypeLib = (ITypeLib2*)entry; *ppTypeLib = (ITypeLib2*)entry;
ITypeLib_AddRef(*ppTypeLib); ITypeLib_AddRef(*ppTypeLib);
LeaveCriticalSection(&cache_section); LeaveCriticalSection(&cache_section);
FreeLibrary(hinstDLL);
return S_OK; return S_OK;
} }
} }
LeaveCriticalSection(&cache_section); LeaveCriticalSection(&cache_section);
/* now actually load and parse the typelib */ /* now actually load and parse the typelib */
hinstDLL = LoadLibraryExW(pszPath, 0, DONT_RESOLVE_DLL_REFERENCES |
LOAD_LIBRARY_AS_DATAFILE | LOAD_WITH_ALTERED_SEARCH_PATH);
if (hinstDLL) if (hinstDLL)
{ {
static const WCHAR TYPELIBW[] = {'T','Y','P','E','L','I','B',0}; static const WCHAR TYPELIBW[] = {'T','Y','P','E','L','I','B',0};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment