One burning question I have at this point is the relative merits of using RtlCreateUnicodeStringFromAsciiz vs MultiByteToWideChar
Change Log: convert MF_CreateMetaHeaderDisk to unicode and W->A clean up
Files Changed: objects/metafile.c dlls/gdi/mfdrv/init.c
--
Tony Lambregts
Index: objects/metafile.c =================================================================== RCS file: /home/wine/wine/objects/metafile.c,v retrieving revision 1.57 diff -u -r1.57 metafile.c --- objects/metafile.c 27 Feb 2003 21:09:45 -0000 1.57 +++ objects/metafile.c 24 Mar 2003 00:49:27 -0000 @@ -54,6 +54,9 @@ #include "global.h" #include "wownt32.h" #include "wine/debug.h" +#include "file.h" +#include "winternl.h" +#include "wine/unicode.h" WINE_DEFAULT_DEBUG_CHANNEL(metafile); @@ -62,7 +65,7 @@ { DWORD dw1, dw2, dw3; WORD w4; - CHAR filename[0x100]; + WCHAR filename[MAX_PATHNAME_LEN]; } METAHEADERDISK; #include "poppack.h" @@ -350,9 +353,9 @@ ERR("Not a disk based metafile\n"); return NULL; } - mhd = (METAHEADERDISK *)((char *)mh + sizeof(METAHEADER)); + mhd = (METAHEADERDISK *)((WCHAR *)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; @@ -377,8 +380,8 @@ sizeof(METAHEADER) + sizeof(METAHEADERDISK)); mh->mtType = METAFILE_DISK; size = HeapSize( GetProcessHeap(), 0, mh ); - mhd = (METAHEADERDISK *)((char *)mh + sizeof(METAHEADER)); - strcpy(mhd->filename, filename); + mhd = (METAHEADERDISK *)((WCHAR *)mh + sizeof(METAHEADER)); + strcpyW(mhd->filename, filename); return mh; } @@ -390,6 +393,7 @@ METAHEADER *mh = MF_GetMetaHeader16( hSrcMetaFile ); METAHEADER *mh2 = NULL; HANDLE hFile; + UNICODE_STRING FilenameW; TRACE("(%08x,%s)\n", hSrcMetaFile, lpFilename); @@ -404,14 +408,15 @@ MF_ReleaseMetaHeader16( hSrcMetaFile ); if(lpFilename) { /* disk based metafile */ - if((hFile = CreateFileA(lpFilename, GENERIC_WRITE, 0, NULL, - CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { + RtlCreateUnicodeStringFromAsciiz(&FilenameW, lpFilename); + if((hFile = CreateFileW(FilenameW.Buffer, GENERIC_WRITE, 0, NULL, + CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { HeapFree( GetProcessHeap(), 0, mh2 ); return 0; } WriteFile(hFile, mh2, mh2->mtSize * 2, NULL, NULL); CloseHandle(hFile); - mh2 = MF_CreateMetaHeaderDisk(mh2, lpFilename); + mh2 = MF_CreateMetaHeaderDisk(mh2, FilenameW.Buffer); } return MF_Create_HMETAFILE16( mh2 ); @@ -419,7 +424,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 +438,15 @@ * * Copying to disk returns NULL even if successful. */ -HMETAFILE WINAPI CopyMetaFileA( - HMETAFILE hSrcMetaFile, /* [in] handle of metafile to copy */ - LPCSTR lpFilename /* [in] filename if copying to a file */ +HMETAFILE WINAPI CopyMetaFileW( + HMETAFILE hSrcMetaFile, /* [in] handle of metafile to copy */ + 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 +458,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,20 +473,19 @@ /****************************************************************** - * CopyMetaFileW (GDI32.@) + * CopyMetaFileA (GDI32.@) */ -HMETAFILE WINAPI CopyMetaFileW( HMETAFILE hSrcMetaFile, - LPCWSTR lpFilename ) +HMETAFILE WINAPI CopyMetaFileA( HMETAFILE hSrcMetaFile, + LPCSTR lpFilename ) { + UNICODE_STRING FilenameW; HMETAFILE ret = 0; - DWORD len = WideCharToMultiByte( CP_ACP, 0, lpFilename, -1, NULL, 0, NULL, NULL ); - LPSTR p = HeapAlloc( GetProcessHeap(), 0, len ); - if (p) + if(lpFilename) { - WideCharToMultiByte( CP_ACP, 0, lpFilename, -1, p, len, NULL, NULL ); - ret = CopyMetaFileA( hSrcMetaFile, p ); - HeapFree( GetProcessHeap(), 0, p ); + RtlCreateUnicodeStringFromAsciiz(&FilenameW, lpFilename); + ret = CopyMetaFileW( hSrcMetaFile, FilenameW.Buffer); + RtlFreeUnicodeString(&FilenameW); } return ret; } Index: dlls/gdi/mfdrv/init.c =================================================================== RCS file: /home/wine/wine/dlls/gdi/mfdrv/init.c,v retrieving revision 1.16 diff -u -r1.16 init.c --- dlls/gdi/mfdrv/init.c 12 Feb 2003 01:17:25 -0000 1.16 +++ dlls/gdi/mfdrv/init.c 24 Mar 2003 00:49:27 -0000 @@ -205,7 +205,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. @@ -213,14 +213,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; @@ -228,8 +228,8 @@ if (filename) /* disk based metafile */ { physDev->mh->mtType = METAFILE_DISK; - if ((hFile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, - CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { + if ((hFile = CreateFileW(filename, GENERIC_WRITE, 0, NULL, + CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { MFDRV_DeleteDC( dc->physDev ); return 0; } @@ -253,25 +253,15 @@ } /********************************************************************** - * CreateMetaFileW (GDI32.@) + * CreateMetaFileA (GDI32.@) */ -HDC WINAPI CreateMetaFileW(LPCWSTR filename) +HDC WINAPI CreateMetaFileA(LPCSTR filename) { - LPSTR filenameA; - DWORD len; - HDC hReturnDC; - - 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 ); - - return hReturnDC; + WCHAR filenameW[MAX_PATH]; + + MultiByteToWideChar(CP_ACP, 0, filename, -1, filenameW, MAX_PATH); + return CreateMetaFileW(filenameW); } - /********************************************************************** * MFDRV_CloseMetaFile