Alexandre Julliard : user.exe: Prepend a valid bitmap header when copying a bitmap resource to a file.

Alexandre Julliard julliard at winehq.org
Wed Dec 30 10:18:12 CST 2009


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Dec 29 21:55:59 2009 +0100

user.exe: Prepend a valid bitmap header when copying a bitmap resource to a file.

---

 dlls/user.exe16/user.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/dlls/user.exe16/user.c b/dlls/user.exe16/user.c
index 6b0f09a..7521c54 100644
--- a/dlls/user.exe16/user.c
+++ b/dlls/user.exe16/user.c
@@ -2009,13 +2009,22 @@ HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type, INT16 c
         HBITMAP ret = 0;
         char *ptr;
         static const WCHAR prefixW[] = {'b','m','p',0};
+        BITMAPFILEHEADER header;
         WCHAR path[MAX_PATH], filename[MAX_PATH];
         HANDLE file;
+        DWORD size;
 
         filename[0] = 0;
         if (!(hRsrc = FindResource16( hinst, name, (LPCSTR)RT_BITMAP ))) return 0;
         if (!(handle = LoadResource16( hinst, hRsrc ))) return 0;
         if (!(ptr = LockResource16( handle ))) goto done;
+        size = SizeofResource16( hinst, hRsrc );
+
+        header.bfType = 0x4d42; /* 'BM' */
+        header.bfReserved1 = 0;
+        header.bfReserved2 = 0;
+        header.bfSize = sizeof(header) + size;
+        header.bfOffBits = 0;  /* not used by the 32-bit loading code */
 
         if (!GetTempPathW( MAX_PATH, path )) goto done;
         if (!GetTempFileNameW( path, prefixW, 0, filename )) goto done;
@@ -2023,8 +2032,10 @@ HANDLE16 WINAPI LoadImage16(HINSTANCE16 hinst, LPCSTR name, UINT16 type, INT16 c
         file = CreateFileW( filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
         if (file != INVALID_HANDLE_VALUE)
         {
-            DWORD written, size = SizeofResource16( hinst, hRsrc );
-            BOOL ok = WriteFile( file, ptr, size, &written, NULL ) && (written == size);
+            DWORD written;
+            BOOL ok;
+            ok = WriteFile( file, &header, sizeof(header), &written, NULL ) && (written == sizeof(header));
+            if (ok) ok = WriteFile( file, ptr, size, &written, NULL ) && (written == size);
             CloseHandle( file );
             if (ok) ret = LoadImageW( 0, filename, IMAGE_BITMAP, cx, cy, flags | LR_LOADFROMFILE );
         }




More information about the wine-cvs mailing list