Not 100% about the part changing METAHEADERDISK.filename type. Can apps access it directly and barf if they find WCHAR instead of CHAR? And is the length set to 0x100 for binary compatibility? Changelog: Get rid of W->A calls for metafiles. Vincent
Index: dlls/gdi/mfdrv/init.c =================================================================== RCS file: /home/wine/wine/dlls/gdi/mfdrv/init.c,v retrieving revision 1.26 diff -u -r1.26 init.c --- dlls/gdi/mfdrv/init.c 5 Nov 2003 01:43:57 -0000 1.26 +++ dlls/gdi/mfdrv/init.c 8 Nov 2003 17:20:24 -0000 @@ -28,6 +28,8 @@ #include "wownt32.h" #include "mfdrv/metafiledrv.h" #include "wine/debug.h" +#include "winreg.h" +#include "winternl.h" WINE_DEFAULT_DEBUG_CHANNEL(metafile); @@ -212,7 +214,7 @@ /********************************************************************** - * CreateMetaFileA (GDI32.@) + * CreateMetaFileW (GDI32.@) * * Create a new DC and associate it with a metafile. Pass a filename * to create a disk-based metafile, NULL to create a memory metafile. @@ -220,14 +222,14 @@ * RETURNS * A handle to the metafile DC if successful, NULL on failure. */ -HDC WINAPI CreateMetaFileA( LPCSTR filename ) /* [in] Filename of disk metafile */ +HDC WINAPI CreateMetaFileW( LPCWSTR filename ) /* [in] Filename of disk metafile */ { HDC ret; DC *dc; METAFILEDRV_PDEVICE *physDev; HANDLE hFile; - TRACE("'%s'\n", filename ); + TRACE("'%s'\n", debugstr_w(filename) ); if (!(dc = MFDRV_AllocMetaFile())) return 0; physDev = (METAFILEDRV_PDEVICE *)dc->physDev; @@ -235,7 +237,7 @@ if (filename) /* disk based metafile */ { physDev->mh->mtType = METAFILE_DISK; - if ((hFile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, + if ((hFile = CreateFileW(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { MFDRV_DeleteDC( dc->physDev ); return 0; @@ -259,25 +261,18 @@ return ret; } + /********************************************************************** - * CreateMetaFileW (GDI32.@) + * CreateMetaFileA (GDI32.@) */ -HDC WINAPI CreateMetaFileW(LPCWSTR filename) +HDC WINAPI CreateMetaFileA( LPCSTR filename ) /* [in] Filename of disk metafile */ { - LPSTR filenameA; - DWORD len; + UNICODE_STRING filenameW; HDC hReturnDC; - if (!filename) return CreateMetaFileA(NULL); - - len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL ); - filenameA = HeapAlloc( GetProcessHeap(), 0, len ); - WideCharToMultiByte( CP_ACP, 0, filename, -1, filenameA, len, NULL, NULL ); - - hReturnDC = CreateMetaFileA(filenameA); - - HeapFree( GetProcessHeap(), 0, filenameA ); - + RtlCreateUnicodeStringFromAsciiz( &filenameW, filename ); + hReturnDC = CreateMetaFileW( filenameW.Buffer ); + RtlFreeUnicodeString( &filenameW ); return hReturnDC; } Index: include/gdi.h =================================================================== RCS file: /home/wine/wine/include/gdi.h,v retrieving revision 1.86 diff -u -r1.86 gdi.h --- include/gdi.h 5 Nov 2003 01:43:57 -0000 1.86 +++ include/gdi.h 8 Nov 2003 17:20:25 -0000 @@ -517,7 +517,7 @@ /* metafile.c */ extern HMETAFILE MF_Create_HMETAFILE(METAHEADER *mh); extern HMETAFILE16 MF_Create_HMETAFILE16(METAHEADER *mh); -extern METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mr, LPCSTR filename); +extern METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mr, LPCWSTR filename); /* region.c */ extern BOOL REGION_FrameRgn( HRGN dest, HRGN src, INT x, INT y ); Index: objects/metafile.c =================================================================== RCS file: /home/wine/wine/objects/metafile.c,v retrieving revision 1.58 diff -u -r1.58 metafile.c --- objects/metafile.c 11 May 2003 03:07:03 -0000 1.58 +++ objects/metafile.c 8 Nov 2003 17:20:25 -0000 @@ -50,10 +50,13 @@ #include "wine/winbase16.h" #include "wine/wingdi16.h" +#include "wine/unicode.h" #include "bitmap.h" #include "global.h" #include "wownt32.h" #include "wine/debug.h" +#include "winreg.h" +#include "winternl.h" WINE_DEFAULT_DEBUG_CHANNEL(metafile); @@ -62,7 +65,7 @@ { DWORD dw1, dw2, dw3; WORD w4; - CHAR filename[0x100]; + WCHAR filename[0x80]; } METAHEADERDISK; #include "poppack.h" @@ -352,7 +355,7 @@ } mhd = (METAHEADERDISK *)((char *)mh + sizeof(METAHEADER)); - if((hfile = CreateFileA(mhd->filename, GENERIC_READ, FILE_SHARE_READ, NULL, + if((hfile = CreateFileW(mhd->filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) { WARN("Can't open file of disk based metafile\n"); return NULL; @@ -368,7 +371,7 @@ * Take a memory based METAHEADER and change it to a disk based METAHEADER * assosiated with filename. Note: Trashes contents of old one. */ -METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mh, LPCSTR filename) +METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mh, LPCWSTR filename) { METAHEADERDISK *mhd; DWORD size; @@ -378,7 +381,7 @@ mh->mtType = METAFILE_DISK; size = HeapSize( GetProcessHeap(), 0, mh ); mhd = (METAHEADERDISK *)((char *)mh + sizeof(METAHEADER)); - strcpy(mhd->filename, filename); + strcpyW(mhd->filename, filename); return mh; } @@ -387,6 +390,7 @@ */ HMETAFILE16 WINAPI CopyMetaFile16( HMETAFILE16 hSrcMetaFile, LPCSTR lpFilename) { + UNICODE_STRING lpFilenameW; METAHEADER *mh = MF_GetMetaHeader16( hSrcMetaFile ); METAHEADER *mh2 = NULL; HANDLE hFile; @@ -411,7 +415,9 @@ } WriteFile(hFile, mh2, mh2->mtSize * 2, NULL, NULL); CloseHandle(hFile); - mh2 = MF_CreateMetaHeaderDisk(mh2, lpFilename); + RtlCreateUnicodeStringFromAsciiz(&lpFilenameW, lpFilename); + mh2 = MF_CreateMetaHeaderDisk(mh2, lpFilenameW.Buffer); + RtlFreeUnicodeString(&lpFilenameW); } return MF_Create_HMETAFILE16( mh2 ); @@ -419,7 +425,7 @@ /****************************************************************** - * CopyMetaFileA (GDI32.@) + * CopyMetaFileW (GDI32.@) * * Copies the metafile corresponding to hSrcMetaFile to either * a disk file, if a filename is given, or to a new memory based @@ -433,15 +439,15 @@ * * Copying to disk returns NULL even if successful. */ -HMETAFILE WINAPI CopyMetaFileA( +HMETAFILE WINAPI CopyMetaFileW( HMETAFILE hSrcMetaFile, /* [in] handle of metafile to copy */ - LPCSTR lpFilename /* [in] filename if copying to a file */ + LPCWSTR lpFilename /* [in] filename if copying to a file */ ) { METAHEADER *mh = MF_GetMetaHeader( hSrcMetaFile ); METAHEADER *mh2 = NULL; HANDLE hFile; - TRACE("(%p,%s)\n", hSrcMetaFile, lpFilename); + TRACE("(%p,%s)\n", hSrcMetaFile, debugstr_w(lpFilename)); if(!mh) return 0; @@ -453,7 +459,7 @@ } if(lpFilename) { /* disk based metafile */ - if((hFile = CreateFileA(lpFilename, GENERIC_WRITE, 0, NULL, + if((hFile = CreateFileW(lpFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { HeapFree( GetProcessHeap(), 0, mh2 ); return 0; @@ -468,21 +474,18 @@ /****************************************************************** - * CopyMetaFileW (GDI32.@) + * CopyMetaFileA (GDI32.@) */ -HMETAFILE WINAPI CopyMetaFileW( HMETAFILE hSrcMetaFile, - LPCWSTR lpFilename ) -{ +HMETAFILE WINAPI CopyMetaFileA( + HMETAFILE hSrcMetaFile, /* [in] handle of metafile to copy */ + LPCSTR lpFilename /* [in] filename if copying to a file */ +) { + UNICODE_STRING lpFilenameW; HMETAFILE ret = 0; - DWORD len = WideCharToMultiByte( CP_ACP, 0, lpFilename, -1, NULL, 0, NULL, NULL ); - LPSTR p = HeapAlloc( GetProcessHeap(), 0, len ); - if (p) - { - WideCharToMultiByte( CP_ACP, 0, lpFilename, -1, p, len, NULL, NULL ); - ret = CopyMetaFileA( hSrcMetaFile, p ); - HeapFree( GetProcessHeap(), 0, p ); - } + RtlCreateUnicodeStringFromAsciiz( &lpFilenameW, lpFilename ); + ret = CopyMetaFileW ( hSrcMetaFile, lpFilenameW.Buffer ); + RtlFreeUnicodeString( &lpFilenameW ); return ret; }