Andrew Nguyen : oleaut32: Convert file URLs to DOS paths for special handling in OleLoadPicturePath.

Alexandre Julliard julliard at winehq.org
Thu May 20 11:03:03 CDT 2010


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

Author: Andrew Nguyen <anguyen at codeweavers.com>
Date:   Wed May 19 22:29:42 2010 -0500

oleaut32: Convert file URLs to DOS paths for special handling in OleLoadPicturePath.

File URLs cannot be used in the moniker code path, as binding to the IStream interface is not possible.

---

 dlls/oleaut32/olepicture.c       |   28 ++++++++++---
 dlls/oleaut32/tests/olepicture.c |   80 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 101 insertions(+), 7 deletions(-)

diff --git a/dlls/oleaut32/olepicture.c b/dlls/oleaut32/olepicture.c
index d9d488f..07d4dde 100644
--- a/dlls/oleaut32/olepicture.c
+++ b/dlls/oleaut32/olepicture.c
@@ -2263,7 +2263,7 @@ HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
 		DWORD dwReserved, OLE_COLOR clrReserved, REFIID riid,
 		LPVOID *ppvRet )
 {
-  static const WCHAR file[] = { 'f','i','l','e',':','/','/',0 };
+  static const WCHAR file[] = { 'f','i','l','e',':',0 };
   IPicture *ipicture;
   HANDLE hFile;
   DWORD dwFileSize;
@@ -2273,6 +2273,8 @@ HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
   BOOL bRead;
   IPersistStream *pStream;
   HRESULT hRes;
+  WCHAR *file_candidate;
+  WCHAR path_buf[MAX_PATH];
 
   TRACE("(%s,%p,%d,%08x,%s,%p): stub\n",
         debugstr_w(szURLorPath), punkCaller, dwReserved, clrReserved,
@@ -2283,13 +2285,25 @@ HRESULT WINAPI OleLoadPicturePath( LPOLESTR szURLorPath, LPUNKNOWN punkCaller,
 
   *ppvRet = NULL;
 
-  if (strncmpW(szURLorPath, file, 7) == 0) {	    
-      szURLorPath += 7;
-  
-      hFile = CreateFileW(szURLorPath, GENERIC_READ, 0, NULL, OPEN_EXISTING,
-				   0, NULL);
+  /* Convert file URLs to DOS paths. */
+  if (strncmpW(szURLorPath, file, 5) == 0) {
+      DWORD size;
+      hRes = CoInternetParseUrl(szURLorPath, PARSE_PATH_FROM_URL, 0, path_buf,
+                                sizeof(path_buf)/sizeof(WCHAR), &size, 0);
+      if (FAILED(hRes))
+          return hRes;
+
+      file_candidate = path_buf;
+  }
+  else
+      file_candidate = szURLorPath;
+
+  /* Handle candidate DOS paths separately. */
+  if (file_candidate[1] == ':') {
+      hFile = CreateFileW(file_candidate, GENERIC_READ, 0, NULL, OPEN_EXISTING,
+                          0, NULL);
       if (hFile == INVALID_HANDLE_VALUE)
-	  return E_UNEXPECTED;
+          return E_UNEXPECTED;
 
       dwFileSize = GetFileSize(hFile, NULL);
       if (dwFileSize != INVALID_FILE_SIZE )
diff --git a/dlls/oleaut32/tests/olepicture.c b/dlls/oleaut32/tests/olepicture.c
index 2874804..6bf3c44 100644
--- a/dlls/oleaut32/tests/olepicture.c
+++ b/dlls/oleaut32/tests/olepicture.c
@@ -745,6 +745,12 @@ static void test_OleLoadPicturePath(void)
     IPicture *pic;
     HRESULT hres;
     int i;
+    char temp_path[MAX_PATH];
+    char temp_file[MAX_PATH];
+    WCHAR temp_fileW[MAX_PATH + 5] = {'f','i','l','e',':','/','/','/'};
+    HANDLE file;
+    DWORD size;
+    WCHAR *ptr;
 
     const struct
     {
@@ -794,6 +800,80 @@ static void test_OleLoadPicturePath(void)
        "Expected OleLoadPicturePath to return INET_E_UNKNOWN_PROTOCOL, got 0x%08x\n", hres);
     ok(pic == NULL,
        "Expected the output interface pointer to be NULL, got %p\n", pic);
+
+    /* Create a local temporary image file for testing. */
+    GetTempPathA(sizeof(temp_path), temp_path);
+    GetTempFileNameA(temp_path, "bmp", 0, temp_file);
+    file = CreateFileA(temp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
+                       FILE_ATTRIBUTE_NORMAL, NULL);
+    WriteFile(file, bmpimage, sizeof(bmpimage), &size, NULL);
+    CloseHandle(file);
+
+    MultiByteToWideChar(CP_ACP, 0, temp_file, -1, temp_fileW + 8, sizeof(temp_fileW)/sizeof(WCHAR) - 8);
+
+    /* Try a normal DOS path. */
+    hres = OleLoadPicturePath(temp_fileW + 8, NULL, 0, 0, &IID_IPicture, (void **)&pic);
+    todo_wine
+    ok(hres == S_OK ||
+       broken(hres == E_UNEXPECTED), /* NT4/Win95 */
+       "Expected OleLoadPicturePath to return S_OK, got 0x%08x\n", hres);
+    if (pic)
+        IPicture_Release(pic);
+
+    /* Try a DOS path with tacked on "file:". */
+    hres = OleLoadPicturePath(temp_fileW, NULL, 0, 0, &IID_IPicture, (void **)&pic);
+    todo_wine
+    ok(hres == S_OK ||
+       broken(hres == E_UNEXPECTED), /* NT4/Win95 */
+       "Expected OleLoadPicturePath to return S_OK, got 0x%08x\n", hres);
+    if (pic)
+        IPicture_Release(pic);
+
+    DeleteFileA(temp_file);
+
+    /* Try with a non-existent file. */
+    hres = OleLoadPicturePath(temp_fileW + 8, NULL, 0, 0, &IID_IPicture, (void **)&pic);
+    ok(hres == INET_E_RESOURCE_NOT_FOUND || /* XP+ */
+       hres == E_UNEXPECTED || /* NT4/Win95 */
+       hres == E_FAIL, /* Win9x/Win2k */
+       "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres);
+
+    hres = OleLoadPicturePath(temp_fileW, NULL, 0, 0, &IID_IPicture, (void **)&pic);
+    ok(hres == INET_E_RESOURCE_NOT_FOUND || /* XP+ */
+       hres == E_UNEXPECTED || /* NT4/Win95 */
+       hres == E_FAIL, /* Win9x/Win2k */
+       "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres);
+
+    file = CreateFileA(temp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
+                       FILE_ATTRIBUTE_NORMAL, NULL);
+    WriteFile(file, bmpimage, sizeof(bmpimage), &size, NULL);
+    CloseHandle(file);
+
+    /* Try a "file:" URL with slash separators. */
+    ptr = temp_fileW + 8;
+    while (*ptr)
+    {
+        if (*ptr == '\\')
+            *ptr = '/';
+        ptr++;
+    }
+
+    hres = OleLoadPicturePath(temp_fileW, NULL, 0, 0, &IID_IPicture, (void **)&pic);
+    todo_wine
+    ok(hres == S_OK ||
+       broken(hres == E_UNEXPECTED), /* NT4/Win95 */
+       "Expected OleLoadPicturePath to return S_OK, got 0x%08x\n", hres);
+    if (pic)
+        IPicture_Release(pic);
+
+    DeleteFileA(temp_file);
+
+    /* Try with a non-existent file. */
+    hres = OleLoadPicturePath(temp_fileW, NULL, 0, 0, &IID_IPicture, (void **)&pic);
+    ok(hres == INET_E_RESOURCE_NOT_FOUND || /* XP+ */
+       hres == E_UNEXPECTED || /* NT4/Win95 */
+       hres == E_FAIL, /* Win9x/Win2k */
+       "Expected OleLoadPicturePath to return INET_E_RESOURCE_NOT_FOUND, got 0x%08x\n", hres);
 }
 
 START_TEST(olepicture)




More information about the wine-cvs mailing list