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

Alexandre Julliard julliard at wine.codeweavers.com
Tue Feb 6 15:23:11 CST 2007


Module: wine
Branch: master
Commit: a09cd1b88a321751ce9dcf9a7050d2818e1b964a
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=a09cd1b88a321751ce9dcf9a7050d2818e1b964a

Author: Huw Davies <huw at codeweavers.com>
Date:   Tue Feb  6 14:01:37 2007 +0000

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

For builtin dlls prepend the system directory.

---

 dlls/oleaut32/typelib.c |   49 ++++++++++++++++++++++++++--------------------
 1 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/dlls/oleaut32/typelib.c b/dlls/oleaut32/typelib.c
index 9525ee8..4970f23 100644
--- a/dlls/oleaut32/typelib.c
+++ b/dlls/oleaut32/typelib.c
@@ -2214,37 +2214,41 @@ static int TLB_ReadTypeLib(LPCWSTR pszFi
     int ret = TYPE_E_CANTLOADLIBRARY;
     INT index = 1;
     HINSTANCE hinstDLL;
+    LPWSTR index_str, file = (LPWSTR)pszFileName;
 
     *ppTypeLib = NULL;
 
-    lstrcpynW(pszPath, pszFileName, cchPath);
-
-    /* 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)
+    index_str = strrchrW(pszFileName, '\\');
+    if(index_str && *++index_str != '\0')
     {
-        /* it may have been specified with resource index appended to the
-         * path, so remove it and try again */
-        const WCHAR *pIndexStr = strrchrW(pszFileName, '\\');
-        if(pIndexStr && pIndexStr != pszFileName && *++pIndexStr != '\0')
+        LPWSTR end_ptr;
+        long idx = strtolW(index_str, &end_ptr, 10);
+        if(*end_ptr == '\0')
         {
-            index = atoiW(pIndexStr);
-            pszPath[pIndexStr - pszFileName - 1] = '\0';
-
-            hinstDLL = LoadLibraryExW(pszPath, 0, DONT_RESOLVE_DLL_REFERENCES |
-                    LOAD_LIBRARY_AS_DATAFILE | LOAD_WITH_ALTERED_SEARCH_PATH);
+            int str_len = index_str - pszFileName - 1;
+            index = idx;
+            file = HeapAlloc(GetProcessHeap(), 0, (str_len + 1) * sizeof(WCHAR));
+            memcpy(file, pszFileName, str_len * sizeof(WCHAR));
+            file[str_len] = 0;
         }
     }
 
-    /* get the path to the specified typelib file */
-    if (!hinstDLL)
+    if(!SearchPathW(NULL, file, NULL, cchPath, pszPath, NULL))
     {
-        /* otherwise, try loading as a regular file */
-        if (!SearchPathW(NULL, pszFileName, NULL, cchPath, pszPath, NULL))
-            return TYPE_E_CANTLOADLIBRARY;
+        if(strchrW(file, '\\'))
+        {
+            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);
 
     /* 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 pszFi
             *ppTypeLib = (ITypeLib2*)entry;
             ITypeLib_AddRef(*ppTypeLib);
             LeaveCriticalSection(&cache_section);
-            FreeLibrary(hinstDLL);
             return S_OK;
         }
     }
     LeaveCriticalSection(&cache_section);
 
     /* 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)
     {
         static const WCHAR TYPELIBW[] = {'T','Y','P','E','L','I','B',0};




More information about the wine-cvs mailing list