diff --git a/dlls/gdi/gdi_private.h b/dlls/gdi/gdi_private.h index 98eb5802aad..fed7aaeeea1 100644 --- a/dlls/gdi/gdi_private.h +++ b/dlls/gdi/gdi_private.h @@ -356,7 +356,7 @@ extern BOOL GDI_hdc_not_using_object(HGDIOBJ obj, HDC hdc); /* 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, LPCVOID filename, BOOL unicode ); /* path.c */ diff --git a/dlls/gdi/mfdrv/init.c b/dlls/gdi/mfdrv/init.c index 7e358cf2dca..239628d476e 100644 --- a/dlls/gdi/mfdrv/init.c +++ b/dlls/gdi/mfdrv/init.c @@ -222,7 +222,7 @@ static BOOL MFDRV_DeleteDC( PHYSDEV dev ) /********************************************************************** - * 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. @@ -230,14 +230,14 @@ static BOOL MFDRV_DeleteDC( PHYSDEV dev ) * 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; @@ -245,12 +245,12 @@ HDC WINAPI CreateMetaFileA( LPCSTR filename ) /* [in] Filename of disk metafile 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; } - if (!WriteFile( hFile, (LPSTR)physDev->mh, sizeof(*physDev->mh), NULL, + if (!WriteFile( hFile, physDev->mh, sizeof(*physDev->mh), NULL, NULL )) { MFDRV_DeleteDC( dc->physDev ); return 0; @@ -258,7 +258,7 @@ HDC WINAPI CreateMetaFileA( LPCSTR filename ) /* [in] Filename of disk metafile physDev->hFile = hFile; /* Grow METAHEADER to include filename */ - physDev->mh = MF_CreateMetaHeaderDisk(physDev->mh, filename); + physDev->mh = MF_CreateMetaHeaderDisk(physDev->mh, filename, TRUE); } else /* memory based metafile */ physDev->mh->mtType = METAFILE_MEMORY; @@ -270,23 +270,23 @@ HDC WINAPI CreateMetaFileA( LPCSTR filename ) /* [in] Filename of disk metafile } /********************************************************************** - * CreateMetaFileW (GDI32.@) + * CreateMetaFileA (GDI32.@) */ -HDC WINAPI CreateMetaFileW(LPCWSTR filename) +HDC WINAPI CreateMetaFileA(LPCSTR filename) { - LPSTR filenameA; + LPWSTR filenameW; DWORD len; HDC hReturnDC; - if (!filename) return CreateMetaFileA(NULL); + if (!filename) return CreateMetaFileW(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 ); + len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 ); + filenameW = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, filename, -1, filenameW, len ); - hReturnDC = CreateMetaFileA(filenameA); + hReturnDC = CreateMetaFileW(filenameW); - HeapFree( GetProcessHeap(), 0, filenameA ); + HeapFree( GetProcessHeap(), 0, filenameW ); return hReturnDC; } diff --git a/objects/metafile.c b/objects/metafile.c index 1c8e70c4b0c..a94f0f9c739 100644 --- a/objects/metafile.c +++ b/objects/metafile.c @@ -370,7 +370,7 @@ static METAHEADER *MF_LoadDiskBasedMetaFile(METAHEADER *mh) * 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, LPCVOID filename, BOOL uni ) { METAHEADERDISK *mhd; DWORD size; @@ -380,7 +380,12 @@ METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mh, LPCSTR filename) mh->mtType = METAFILE_DISK; size = HeapSize( GetProcessHeap(), 0, mh ); mhd = (METAHEADERDISK *)((char *)mh + sizeof(METAHEADER)); - strcpy(mhd->filename, filename); + + if( uni ) + WideCharToMultiByte(CP_ACP, 0, filename, -1, + mhd->filename, sizeof mhd->filename, NULL, NULL); + else + lstrcpynA( mhd->filename, filename, sizeof mhd->filename ); return mh; } @@ -413,7 +418,7 @@ HMETAFILE16 WINAPI CopyMetaFile16( HMETAFILE16 hSrcMetaFile, LPCSTR lpFilename) } WriteFile(hFile, mh2, mh2->mtSize * 2, NULL, NULL); CloseHandle(hFile); - mh2 = MF_CreateMetaHeaderDisk(mh2, lpFilename); + mh2 = MF_CreateMetaHeaderDisk(mh2, lpFilename, FALSE); } return MF_Create_HMETAFILE16( mh2 ); @@ -455,8 +460,6 @@ HMETAFILE WINAPI CopyMetaFileW( } if(lpFilename) { /* disk based metafile */ - DWORD len; - LPSTR lpFilenameA; if((hFile = CreateFileW(lpFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { HeapFree( GetProcessHeap(), 0, mh2 ); @@ -464,11 +467,7 @@ HMETAFILE WINAPI CopyMetaFileW( } WriteFile(hFile, mh2, mh2->mtSize * 2, NULL, NULL); CloseHandle(hFile); - len = WideCharToMultiByte(CP_ACP, 0, lpFilename, -1, NULL, 0, NULL, NULL); - lpFilenameA = HeapAlloc(GetProcessHeap(), 0, len); - WideCharToMultiByte(CP_ACP, 0, lpFilename, -1, lpFilenameA, len, NULL, NULL); - mh2 = MF_CreateMetaHeaderDisk(mh2, lpFilenameA); - HeapFree(GetProcessHeap(), 0, lpFilenameA); + mh2 = MF_CreateMetaHeaderDisk(mh2, lpFilename, TRUE); } return MF_Create_HMETAFILE( mh2 );