[PATCH] Fix bug in CURSORICON_LoadFromFile

Sergey Khodych khodych at gmail.com
Thu Mar 6 14:44:03 CST 2008


---
 dlls/user32/cursoricon.c       |   21 +++++++++++++++++++--
 dlls/user32/tests/cursoricon.c |    5 -----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c
index aa1bdf5..5a9990b 100644
--- a/dlls/user32/cursoricon.c
+++ b/dlls/user32/cursoricon.c
@@ -925,8 +925,25 @@ static HICON CURSORICON_LoadFromFile( LPCWSTR filename,
     if ( entry->dwDIBOffset + entry->dwDIBSize > filesize )
         goto end;
 
-    hIcon = CreateIconFromResourceEx( &bits[entry->dwDIBOffset], entry->dwDIBSize,
-                                      !fCursor, 0x00030000, width, height, loadflags );
+    if ( fCursor )
+    {
+        POINT16 *pt;
+        LPBYTE dib = HeapAlloc( GetProcessHeap(), 0, entry->dwDIBSize + sizeof( POINT16 ) );
+        if ( !dib )
+            goto end;
+        pt = (POINT16 *)dib;
+        pt->x = entry->xHotspot;
+        pt->y = entry->yHotspot;
+        CopyMemory( pt+1, &bits[entry->dwDIBOffset], entry->dwDIBSize );
+        hIcon = CreateIconFromResourceEx( dib, entry->dwDIBSize,
+                                          !fCursor, 0x00030000, width, height, loadflags );
+        HeapFree( GetProcessHeap(), 0, dib );
+    }
+    else
+    {
+        hIcon = CreateIconFromResourceEx( &bits[entry->dwDIBOffset], entry->dwDIBSize,
+                                          !fCursor, 0x00030000, width, height, loadflags );
+    }
 end:
     TRACE("loaded %s -> %p\n", debugstr_w( filename ), hIcon );
     UnmapViewOfFile( bits );
diff --git a/dlls/user32/tests/cursoricon.c b/dlls/user32/tests/cursoricon.c
index 023a3a5..9e9cb9e 100644
--- a/dlls/user32/tests/cursoricon.c
+++ b/dlls/user32/tests/cursoricon.c
@@ -636,7 +636,6 @@ static void test_LoadImage(void)
     /* Test loading an icon as a cursor. */
     SetLastError(0xdeadbeef);
     handle = LoadImageA(NULL, "icon.ico", IMAGE_CURSOR, 0, 0, LR_LOADFROMFILE);
-    todo_wine
     ok(handle != NULL, "LoadImage() failed.\n");
     error = GetLastError();
     ok(error == 0, "Last error: %u\n", error);
@@ -644,23 +643,19 @@ static void test_LoadImage(void)
     /* Test the icon information. */
     SetLastError(0xdeadbeef);
     ret = GetIconInfo(handle, &icon_info);
-    todo_wine
     ok(ret, "GetIconInfo() failed.\n");
     error = GetLastError();
     ok(error == 0xdeadbeef, "Last error: %u\n", error);
 
-    todo_wine {
     ok(icon_info.fIcon == FALSE, "fIcon != FALSE.\n");
     ok(icon_info.xHotspot == 1, "xHotspot is %u.\n", icon_info.xHotspot);
     ok(icon_info.yHotspot == 1, "yHotspot is %u.\n", icon_info.yHotspot);
     ok(icon_info.hbmColor != NULL, "No hbmColor!\n");
-    }
     ok(icon_info.hbmMask != NULL, "No hbmMask!\n");
 
     /* Clean up. */
     SetLastError(0xdeadbeef);
     ret = DestroyCursor(handle);
-    todo_wine
     ok(ret, "DestroyCursor() failed.\n");
     error = GetLastError();
     ok(error == 0xdeadbeef, "Last error: %u\n", error);
-- 
1.5.3.3


--------------070201070509020108020501--



More information about the wine-patches mailing list