From 193cf50a09d724995f273acea623404276e98ec4 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard <julliard@winehq.org> Date: Tue, 1 Jan 2002 00:24:30 +0000 Subject: [PATCH] Removed some of the calls to HEAP_strdup* functions. --- dlls/ddraw/main.c | 23 ++++++++---- dlls/mpr/wnet.c | 11 ++++-- dlls/ole32/compobj.c | 44 +++++++++++++++------- dlls/oleaut32/hash.c | 9 +++-- dlls/oleaut32/olefont.c | 24 ++++++------ dlls/user/exticon.c | 15 ++++---- dlls/user/resource.c | 25 +++++++------ files/change.c | 16 +++++--- graphics/enhmetafiledrv/init.c | 10 +++-- graphics/metafiledrv/init.c | 6 ++- loader/pe_resource.c | 6 ++- misc/registry.c | 40 +------------------- objects/metafile.c | 14 +++++-- ole/ole2nls.c | 8 +--- win32/file.c | 9 +++-- win32/newfns.c | 13 +++++-- windows/cursoricon.c | 11 ++++-- windows/mdi.c | 5 ++- windows/nonclient.c | 68 ++++++++++++++++------------------ windows/user.c | 36 ++++++++++-------- windows/win.c | 7 +++- windows/winhelp.c | 20 +++++++--- 22 files changed, 226 insertions(+), 194 deletions(-) diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c index 54af18841e8..d309d9bbd5e 100644 --- a/dlls/ddraw/main.c +++ b/dlls/ddraw/main.c @@ -14,15 +14,15 @@ #include <string.h> #include <stdlib.h> +#include "winnls.h" #include "winerror.h" -#include "debugtools.h" -#include "heap.h" #include "ddraw.h" #include "d3d.h" /* This for all the enumeration and creation of D3D-related objects */ #include "ddraw_private.h" +#include "debugtools.h" #define MAX_DDRAW_DRIVERS 3 static const ddraw_driver* DDRAW_drivers[MAX_DDRAW_DRIVERS]; @@ -93,14 +93,21 @@ static BOOL CALLBACK DirectDrawEnumerateExProcW( GUID *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm) { + INT len; + BOOL bResult; + LPWSTR lpDriverDescriptionW, lpDriverNameW; DirectDrawEnumerateProcData *pEPD = (DirectDrawEnumerateProcData*)lpContext; - LPWSTR lpDriverDescriptionW = - HEAP_strdupAtoW(GetProcessHeap(), 0, lpDriverDescription); - LPWSTR lpDriverNameW = - HEAP_strdupAtoW(GetProcessHeap(), 0, lpDriverName); - BOOL bResult = (*(LPDDENUMCALLBACKEXW *) pEPD->lpCallback)( - lpGUID, lpDriverDescriptionW, lpDriverNameW, pEPD->lpContext, hm); + len = MultiByteToWideChar( CP_ACP, 0, lpDriverDescription, -1, NULL, 0 ); + lpDriverDescriptionW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, lpDriverDescription, -1, lpDriverDescriptionW, len ); + + len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 ); + lpDriverNameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, lpDriverNameW, len ); + + bResult = (*(LPDDENUMCALLBACKEXW *) pEPD->lpCallback)(lpGUID, lpDriverDescriptionW, + lpDriverNameW, pEPD->lpContext, hm); HeapFree(GetProcessHeap(), 0, lpDriverDescriptionW); HeapFree(GetProcessHeap(), 0, lpDriverNameW); diff --git a/dlls/mpr/wnet.c b/dlls/mpr/wnet.c index 0297c088c3a..3b7e799fe6f 100644 --- a/dlls/mpr/wnet.c +++ b/dlls/mpr/wnet.c @@ -9,8 +9,8 @@ #include <unistd.h> #include "winbase.h" +#include "winnls.h" #include "winnetwk.h" -#include "heap.h" #include "debugtools.h" DEFAULT_DEBUG_CHANNEL(mpr); @@ -369,9 +369,12 @@ DWORD WINAPI WNetGetConnectionW( LPCWSTR lpLocalName, LPWSTR lpRemoteName, LPDWORD lpBufferSize ) { CHAR buf[200]; - DWORD x = sizeof(buf); - LPSTR lnA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpLocalName ); - DWORD ret = WNetGetConnectionA( lnA, buf, &x ); + DWORD ret, x = sizeof(buf); + INT len = WideCharToMultiByte( CP_ACP, 0, lpLocalName, -1, NULL, 0, NULL, NULL ); + LPSTR lnA = HeapAlloc( GetProcessHeap(), 0, len ); + + WideCharToMultiByte( CP_ACP, 0, lpLocalName, -1, lnA, len, NULL, NULL ); + ret = WNetGetConnectionA( lnA, buf, &x ); HeapFree( GetProcessHeap(), 0, lnA ); if (ret == WN_SUCCESS) { diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 5ec5868d57a..6095ac58a28 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -24,7 +24,7 @@ #include "winreg.h" #include "wownt32.h" #include "wtypes.h" - +#include "wine/unicode.h" #include "wine/obj_base.h" #include "wine/obj_clientserver.h" #include "wine/obj_misc.h" @@ -33,7 +33,6 @@ #include "wine/winbase16.h" #include "compobj_private.h" #include "ifs.h" -#include "heap.h" #include "debugtools.h" @@ -538,12 +537,14 @@ HRESULT WINAPI CoCreateGuid( */ HRESULT WINAPI CLSIDFromString( LPCOLESTR idstr, /* [in] string representation of GUID */ - CLSID *id /* [out] GUID represented by above string */ -) { - LPOLESTR16 xid = HEAP_strdupWtoA(GetProcessHeap(),0,idstr); - HRESULT ret = CLSIDFromString16(xid,id); + CLSID *id ) /* [out] GUID represented by above string */ +{ + char xid[40]; + HRESULT ret; - HeapFree(GetProcessHeap(),0,xid); + if (!WideCharToMultiByte( CP_ACP, 0, idstr, -1, xid, sizeof(xid), NULL, NULL )) + return CO_E_CLASSSTRING; + ret = CLSIDFromString16(xid,id); if(ret != S_OK) { /* It appears a ProgID is also valid */ ret = CLSIDFromProgID(idstr, id); } @@ -774,13 +775,30 @@ HRESULT WINAPI CLSIDFromProgID16( */ HRESULT WINAPI CLSIDFromProgID( LPCOLESTR progid, /* [in] program id as found in registry */ - LPCLSID riid /* [out] associated CLSID */ -) { - LPOLESTR16 pid = HEAP_strdupWtoA(GetProcessHeap(),0,progid); - HRESULT ret = CLSIDFromProgID16(pid,riid); + LPCLSID riid ) /* [out] associated CLSID */ +{ + static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 }; + char buf2[80]; + DWORD buf2len = sizeof(buf2); + HKEY xhkey; - HeapFree(GetProcessHeap(),0,pid); - return ret; + WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) ); + strcpyW( buf, progid ); + strcatW( buf, clsidW ); + if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey)) + { + HeapFree(GetProcessHeap(),0,buf); + return CO_E_CLASSSTRING; + } + HeapFree(GetProcessHeap(),0,buf); + + if (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) + { + RegCloseKey(xhkey); + return CO_E_CLASSSTRING; + } + RegCloseKey(xhkey); + return CLSIDFromString16(buf2,riid); } diff --git a/dlls/oleaut32/hash.c b/dlls/oleaut32/hash.c index c0adf4e8c70..949aea818b8 100644 --- a/dlls/oleaut32/hash.c +++ b/dlls/oleaut32/hash.c @@ -10,10 +10,10 @@ #include "winbase.h" #include "wingdi.h" #include "winuser.h" -#include "debugtools.h" +#include "winnls.h" #include "ole2.h" #include "olectl.h" -#include "heap.h" +#include "debugtools.h" DEFAULT_DEBUG_CHANNEL(ole); @@ -233,9 +233,12 @@ ULONG WINAPI LHashValOfNameSys( SYSKIND skind, LCID lcid, LPCOLESTR str) { LPSTR strA; ULONG res; + INT len; if (!str) return 0; - strA = HEAP_strdupWtoA(GetProcessHeap(), 0, str); + len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL ); + strA = HeapAlloc( GetProcessHeap(), 0, len ); + WideCharToMultiByte( CP_ACP, 0, str, -1, strA, len, NULL, NULL ); res = LHashValOfNameSysA(skind, lcid, strA); HeapFree(GetProcessHeap(), 0, strA); return res; diff --git a/dlls/oleaut32/olefont.c b/dlls/oleaut32/olefont.c index 556db6cc6fc..cbab75fe1de 100644 --- a/dlls/oleaut32/olefont.c +++ b/dlls/oleaut32/olefont.c @@ -20,7 +20,6 @@ #include "ole2.h" #include "olectl.h" #include "debugtools.h" -#include "heap.h" #include "connpt.h" /* for CreateConnectionPoint */ DEFAULT_DEBUG_CHANNEL(ole); @@ -1335,6 +1334,7 @@ static HRESULT WINAPI OLEFontImpl_Load( BYTE bVersion; BYTE bAttributes; BYTE bStringSize; + INT len; _ICOM_THIS_From_IPersistStream(OLEFontImpl, iface); @@ -1393,7 +1393,6 @@ static HRESULT WINAPI OLEFontImpl_Load( if (cbRead!=1) return E_FAIL; - memset(readBuffer, 0, 0x100); IStream_Read(pLoadStream, readBuffer, bStringSize, &cbRead); if (cbRead!=bStringSize) @@ -1402,9 +1401,10 @@ static HRESULT WINAPI OLEFontImpl_Load( if (this->description.lpstrName!=0) HeapFree(GetProcessHeap(), 0, this->description.lpstrName); - this->description.lpstrName = HEAP_strdupAtoW(GetProcessHeap(), - HEAP_ZERO_MEMORY, - readBuffer); + len = MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, NULL, 0 ); + this->description.lpstrName = HeapAlloc( GetProcessHeap(), 0, (len+1) * sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, readBuffer, bStringSize, this->description.lpstrName, len ); + this->description.lpstrName[len] = 0; return S_OK; } @@ -1482,7 +1482,8 @@ static HRESULT WINAPI OLEFontImpl_Save( * FontName */ if (this->description.lpstrName!=0) - bStringSize = lstrlenW(this->description.lpstrName); + bStringSize = WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName, + strlenW(this->description.lpstrName), NULL, 0, NULL, NULL ); else bStringSize = 0; @@ -1493,15 +1494,12 @@ static HRESULT WINAPI OLEFontImpl_Save( if (bStringSize!=0) { - writeBuffer = HEAP_strdupWtoA(GetProcessHeap(), - HEAP_ZERO_MEMORY, - this->description.lpstrName); - - if (writeBuffer==0) - return E_OUTOFMEMORY; + if (!(writeBuffer = HeapAlloc( GetProcessHeap(), 0, bStringSize ))) return E_OUTOFMEMORY; + WideCharToMultiByte( CP_ACP, 0, this->description.lpstrName, + strlenW(this->description.lpstrName), + writeBuffer, bStringSize, NULL, NULL ); IStream_Write(pOutStream, writeBuffer, bStringSize, &cbWritten); - HeapFree(GetProcessHeap(), 0, writeBuffer); if (cbWritten!=bStringSize) diff --git a/dlls/user/exticon.c b/dlls/user/exticon.c index 1000a03c2ce..d24695d2543 100644 --- a/dlls/user/exticon.c +++ b/dlls/user/exticon.c @@ -20,7 +20,6 @@ #include "winuser.h" #include "wine/winbase16.h" #include "cursoricon.h" -#include "heap.h" #include "debugtools.h" DEFAULT_DEBUG_CHANNEL(icon); @@ -572,8 +571,10 @@ HRESULT WINAPI PrivateExtractIconsA ( DWORD y ) /* [in] NOTE: 0x80 */ { DWORD ret; - LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile); - + INT len = MultiByteToWideChar( CP_ACP, 0, lpstrFile, -1, NULL, 0 ); + LPWSTR lpwstrFile = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); + + MultiByteToWideChar( CP_ACP, 0, lpstrFile, -1, lpwstrFile, len ); ret = PrivateExtractIconsW( lpwstrFile, nIndex, sizeX, sizeY, phicon, w, nIcons, y ); @@ -649,13 +650,13 @@ HRESULT WINAPI PrivateExtractIconExA ( UINT nIcons ) { DWORD ret; - LPWSTR lpwstrFile = HEAP_strdupAtoW(GetProcessHeap(), 0, lpstrFile); + INT len = MultiByteToWideChar( CP_ACP, 0, lpstrFile, -1, NULL, 0 ); + LPWSTR lpwstrFile = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); - TRACE("%s 0x%08lx %p %p 0x%08x\n", - lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons); + TRACE("%s 0x%08lx %p %p 0x%08x\n", lpstrFile, nIndex, phIconLarge, phIconSmall, nIcons); + MultiByteToWideChar( CP_ACP, 0, lpstrFile, -1, lpwstrFile, len ); ret = PrivateExtractIconExW(lpwstrFile,nIndex,phIconLarge, phIconSmall, nIcons); - HeapFree(GetProcessHeap(), 0, lpwstrFile); return ret; } diff --git a/dlls/user/resource.c b/dlls/user/resource.c index 8d819e609e0..6669f94d3dd 100644 --- a/dlls/user/resource.c +++ b/dlls/user/resource.c @@ -11,8 +11,6 @@ #include "winnls.h" #include "wine/winbase16.h" #include "wine/winuser16.h" - -#include "heap.h" #include "debugtools.h" DEFAULT_DEBUG_CHANNEL(resource); @@ -99,15 +97,20 @@ HACCEL WINAPI LoadAcceleratorsW(HINSTANCE instance,LPCWSTR lpTableName) */ HACCEL WINAPI LoadAcceleratorsA(HINSTANCE instance,LPCSTR lpTableName) { - LPWSTR uni; - HACCEL result; - if (HIWORD(lpTableName)) - uni = HEAP_strdupAtoW( GetProcessHeap(), 0, lpTableName ); - else - uni = (LPWSTR)lpTableName; - result = LoadAcceleratorsW(instance,uni); - if (HIWORD(uni)) HeapFree( GetProcessHeap(), 0, uni); - return result; + INT len; + LPWSTR uni; + HACCEL result = 0; + + if (!HIWORD(lpTableName)) return LoadAcceleratorsW( instance, (LPCWSTR)lpTableName ); + + len = MultiByteToWideChar( CP_ACP, 0, lpTableName, -1, NULL, 0 ); + if ((uni = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) + { + MultiByteToWideChar( CP_ACP, 0, lpTableName, -1, uni, len ); + result = LoadAcceleratorsW(instance,uni); + HeapFree( GetProcessHeap(), 0, uni); + } + return result; } /********************************************************************** diff --git a/files/change.c b/files/change.c index 1137cbbfea2..a7a4cd09715 100644 --- a/files/change.c +++ b/files/change.c @@ -16,7 +16,6 @@ #include <time.h> #include "winbase.h" #include "winerror.h" -#include "heap.h" #include "wine/server.h" #include "debugtools.h" @@ -49,10 +48,17 @@ HANDLE WINAPI FindFirstChangeNotificationW( LPCWSTR lpPathName, BOOL bWatchSubtree, DWORD dwNotifyFilter) { - LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpPathName ); - HANDLE ret = FindFirstChangeNotificationA( nameA, bWatchSubtree, - dwNotifyFilter ); - if (nameA) HeapFree( GetProcessHeap(), 0, nameA ); + HANDLE ret = INVALID_HANDLE_VALUE; + + FIXME("this is not supported yet (non-trivial).\n"); + + SERVER_START_REQ( create_change_notification ) + { + req->subtree = bWatchSubtree; + req->filter = dwNotifyFilter; + if (!wine_server_call_err( req )) ret = reply->handle; + } + SERVER_END_REQ; return ret; } diff --git a/graphics/enhmetafiledrv/init.c b/graphics/enhmetafiledrv/init.c index fceee3ca991..2ef4444129b 100644 --- a/graphics/enhmetafiledrv/init.c +++ b/graphics/enhmetafiledrv/init.c @@ -9,7 +9,6 @@ #include "windef.h" #include "wingdi.h" #include "gdi.h" -#include "heap.h" #include "enhmetafiledrv.h" #include "debugtools.h" @@ -212,9 +211,12 @@ HDC WINAPI CreateEnhMetaFileA( HDC hReturnDC; DWORD len1, len2, total; - if(filename) - filenameW = HEAP_strdupAtoW( GetProcessHeap(), 0, filename ); - + if(filename) + { + total = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 ); + filenameW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, filename, -1, filenameW, total ); + } if(description) { len1 = strlen(description); len2 = strlen(description + len1 + 1); diff --git a/graphics/metafiledrv/init.c b/graphics/metafiledrv/init.c index bde28d9baa0..797a26befd8 100644 --- a/graphics/metafiledrv/init.c +++ b/graphics/metafiledrv/init.c @@ -7,7 +7,6 @@ #include "windef.h" #include "wine/winbase16.h" #include "gdi.h" -#include "heap.h" #include "metafile.h" #include "metafiledrv.h" #include "debugtools.h" @@ -241,9 +240,12 @@ HDC WINAPI CreateMetaFileA( HDC WINAPI CreateMetaFileW(LPCWSTR filename) { LPSTR filenameA; + DWORD len; HDC hReturnDC; - filenameA = HEAP_strdupWtoA( GetProcessHeap(), 0, filename ); + 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); diff --git a/loader/pe_resource.c b/loader/pe_resource.c index 4fac376e961..12f14557cd9 100644 --- a/loader/pe_resource.c +++ b/loader/pe_resource.c @@ -20,7 +20,6 @@ #include "winnls.h" #include "winerror.h" #include "module.h" -#include "heap.h" #include "stackframe.h" #include "debugtools.h" @@ -143,6 +142,7 @@ static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_nameA( const IMAGE_RESOURCE { const IMAGE_RESOURCE_DIRECTORY *ret = NULL; LPWSTR nameW; + INT len; if (!HIWORD(name)) return find_entry_by_id( dir, LOWORD(name), root ); if (name[0] == '#') @@ -150,8 +150,10 @@ static const IMAGE_RESOURCE_DIRECTORY *find_entry_by_nameA( const IMAGE_RESOURCE return find_entry_by_id( dir, atoi(name+1), root ); } - if ((nameW = HEAP_strdupAtoW( GetProcessHeap(), 0, name ))) + len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 ); + if ((nameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) { + MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, len ); ret = find_entry_by_nameW( dir, nameW, root ); HeapFree( GetProcessHeap(), 0, nameW ); } diff --git a/misc/registry.c b/misc/registry.c index 4cfed5d000b..a6e397cfb84 100644 --- a/misc/registry.c +++ b/misc/registry.c @@ -38,10 +38,10 @@ #include "winreg.h" #include "wine/winbase16.h" +#include "wine/server.h" +#include "wine/unicode.h" #include "file.h" -#include "heap.h" #include "options.h" -#include "wine/server.h" #include "debugtools.h" @@ -1603,42 +1603,6 @@ LONG WINAPI RegUnLoadKeyA( HKEY hkey, LPCSTR lpSubKey ) } -/****************************************************************************** - * RegRestoreKeyW [ADVAPI32.@] - * - * PARAMS - * hkey [I] Handle of key where restore begins - * lpFile [I] Address of filename containing saved tree - * dwFlags [I] Optional flags - */ -LONG WINAPI RegRestoreKeyW( HKEY hkey, LPCWSTR lpFile, DWORD dwFlags ) -{ - TRACE("(%x,%s,%ld)\n",hkey,debugstr_w(lpFile),dwFlags); - - /* It seems to do this check before the hkey check */ - if (!lpFile || !*lpFile) - return ERROR_INVALID_PARAMETER; - - FIXME("(%x,%s,%ld): stub\n",hkey,debugstr_w(lpFile),dwFlags); - - /* Check for file existence */ - - return ERROR_SUCCESS; -} - - -/****************************************************************************** - * RegRestoreKeyA [ADVAPI32.@] - */ -LONG WINAPI RegRestoreKeyA( HKEY hkey, LPCSTR lpFile, DWORD dwFlags ) -{ - LPWSTR lpFileW = HEAP_strdupAtoW( GetProcessHeap(), 0, lpFile ); - LONG ret = RegRestoreKeyW( hkey, lpFileW, dwFlags ); - HeapFree( GetProcessHeap(), 0, lpFileW ); - return ret; -} - - /****************************************************************************** * RegReplaceKeyA [ADVAPI32.@] */ diff --git a/objects/metafile.c b/objects/metafile.c index b6b917a703e..ffa003f1aa9 100644 --- a/objects/metafile.c +++ b/objects/metafile.c @@ -39,7 +39,6 @@ #include "wine/wingdi16.h" #include "bitmap.h" #include "global.h" -#include "heap.h" #include "metafile.h" #include "debugtools.h" @@ -436,9 +435,16 @@ HMETAFILE WINAPI CopyMetaFileA( HMETAFILE WINAPI CopyMetaFileW( HMETAFILE hSrcMetaFile, LPCWSTR lpFilename ) { - LPSTR p = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFilename ); - HMETAFILE ret = CopyMetaFileA( hSrcMetaFile, p ); - HeapFree( GetProcessHeap(), 0, p ); + 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 ); + } return ret; } diff --git a/ole/ole2nls.c b/ole/ole2nls.c index c34ecca8126..0f2a0f29f90 100644 --- a/ole/ole2nls.c +++ b/ole/ole2nls.c @@ -17,7 +17,6 @@ #include "wingdi.h" #include "winuser.h" #include "wine/unicode.h" -#include "heap.h" #include "options.h" #include "winver.h" #include "winnls.h" @@ -2243,12 +2242,9 @@ INT WINAPI LCMapStringW( returned_len = wcstombs(src_native, srcstr_libc, src_native_len) + 1; if(returned_len == 0) { - LPSTR srcstr_ascii = (LPSTR)HEAP_strdupWtoA(GetProcessHeap(), - 0, srcstr); - ERR("wcstombs failed. The string specified (%s) may contains an " - "invalid character.\n", srcstr_ascii); + ERR("wcstombs failed. The string specified (%s) may contain an invalid character.\n", + debugstr_w(srcstr)); SetLastError(ERROR_INVALID_PARAMETER); - if(srcstr_ascii) HeapFree(GetProcessHeap(), 0, srcstr_ascii); if(srcstr_libc) HeapFree(GetProcessHeap(), 0, srcstr_libc); if(src_native) HeapFree(GetProcessHeap(), 0, src_native); setlocale(LC_COLLATE, lc_collate_default); diff --git a/win32/file.c b/win32/file.c index c0a4591e00f..d390be1ac50 100644 --- a/win32/file.c +++ b/win32/file.c @@ -27,7 +27,6 @@ #include "wine/winbase16.h" #include "file.h" -#include "heap.h" #include "debugtools.h" @@ -106,8 +105,12 @@ BOOL WINAPI SetFileAttributesA(LPCSTR lpFileName, DWORD attributes) */ BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD attributes) { - LPSTR afn = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName ); - BOOL res = SetFileAttributesA( afn, attributes ); + BOOL res; + DWORD len = WideCharToMultiByte( CP_ACP, 0, lpFileName, -1, NULL, 0, NULL, NULL ); + LPSTR afn = HeapAlloc( GetProcessHeap(), 0, len ); + + WideCharToMultiByte( CP_ACP, 0, lpFileName, -1, afn, len, NULL, NULL ); + res = SetFileAttributesA( afn, attributes ); HeapFree( GetProcessHeap(), 0, afn ); return res; } diff --git a/win32/newfns.c b/win32/newfns.c index ea50508ca4f..8b92062d302 100644 --- a/win32/newfns.c +++ b/win32/newfns.c @@ -12,8 +12,9 @@ at a later date. */ #include <sys/time.h> #include <unistd.h> #include "windef.h" +#include "winbase.h" +#include "winnls.h" #include "winerror.h" -#include "heap.h" #include "debugtools.h" DEFAULT_DEBUG_CHANNEL(win32); @@ -268,9 +269,13 @@ DWORD WINAPI GetCompressedFileSizeW( */ BOOL WINAPI SetComputerNameA( LPCSTR lpComputerName ) { - LPWSTR lpComputerNameW = HEAP_strdupAtoW(GetProcessHeap(),0,lpComputerName); - BOOL ret = SetComputerNameW(lpComputerNameW); - HeapFree(GetProcessHeap(),0,lpComputerNameW); + BOOL ret; + DWORD len = MultiByteToWideChar( CP_ACP, 0, lpComputerName, -1, NULL, 0 ); + LPWSTR nameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); + + MultiByteToWideChar( CP_ACP, 0, lpComputerName, -1, nameW, len ); + ret = SetComputerNameW( nameW ); + HeapFree( GetProcessHeap(), 0, nameW ); return ret; } diff --git a/windows/cursoricon.c b/windows/cursoricon.c index df082e12760..86a692cee03 100644 --- a/windows/cursoricon.c +++ b/windows/cursoricon.c @@ -37,7 +37,6 @@ #include "wine/winbase16.h" #include "wine/winuser16.h" #include "wine/exception.h" -#include "heap.h" #include "palette.h" #include "bitmap.h" #include "cursoricon.h" @@ -2191,9 +2190,13 @@ HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type, HANDLE res; LPWSTR u_name; + if (!HIWORD(name)) + return LoadImageW(hinst, (LPWSTR)name, type, desiredx, desiredy, loadflags); + __TRY { - if (HIWORD(name)) u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, name); - else u_name=(LPWSTR)name; + DWORD len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 ); + u_name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, name, -1, u_name, len ); } __EXCEPT(page_fault) { SetLastError( ERROR_INVALID_PARAMETER ); @@ -2201,7 +2204,7 @@ HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type, } __ENDTRY res = LoadImageW(hinst, u_name, type, desiredx, desiredy, loadflags); - if (HIWORD(name)) HeapFree(GetProcessHeap(), 0, u_name); + HeapFree(GetProcessHeap(), 0, u_name); return res; } diff --git a/windows/mdi.c b/windows/mdi.c index db2137efd8c..ba54a2bdb13 100644 --- a/windows/mdi.c +++ b/windows/mdi.c @@ -77,7 +77,6 @@ #include "winuser.h" #include "wine/unicode.h" #include "win.h" -#include "heap.h" #include "nonclient.h" #include "controls.h" #include "user.h" @@ -1459,7 +1458,9 @@ LRESULT WINAPI DefFrameProcA( HWND hwnd, HWND hwndMDIClient, { case WM_SETTEXT: { - LPWSTR text = HEAP_strdupAtoW( GetProcessHeap(), 0, (LPSTR)lParam ); + DWORD len = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, NULL, 0 ); + LPWSTR text = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); + MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, text, len ); MDI_UpdateFrameText(hwnd, hwndMDIClient, MDI_REPAINTFRAME, text ); HeapFree( GetProcessHeap(), 0, text ); } diff --git a/windows/nonclient.c b/windows/nonclient.c index ac8952900be..36bcc8f0433 100644 --- a/windows/nonclient.c +++ b/windows/nonclient.c @@ -11,7 +11,6 @@ #include "version.h" #include "win.h" #include "user.h" -#include "heap.h" #include "dce.h" #include "controls.h" #include "cursoricon.h" @@ -259,22 +258,38 @@ DrawCaption (HWND hwnd, HDC hdc, const RECT *lpRect, UINT uFlags) /*********************************************************************** * DrawCaptionTempA (USER32.@) - * - * PARAMS - * - * RETURNS - * Success: - * Failure: */ +BOOL WINAPI DrawCaptionTempA (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, + HICON hIcon, LPCSTR str, UINT uFlags) +{ + LPWSTR strW; + INT len; + BOOL ret = FALSE; -BOOL WINAPI -DrawCaptionTempA (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, - HICON hIcon, LPCSTR str, UINT uFlags) + if (!(uFlags & DC_TEXT) || !str) + return DrawCaptionTempW( hwnd, hdc, rect, hFont, hIcon, NULL, uFlags ); + + len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 ); + if ((strW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) + { + MultiByteToWideChar( CP_ACP, 0, str, -1, strW, len ); + ret = DrawCaptionTempW (hwnd, hdc, rect, hFont, hIcon, strW, uFlags); + HeapFree( GetProcessHeap (), 0, strW ); + } + return ret; +} + + +/*********************************************************************** + * DrawCaptionTempW (USER32.@) + */ +BOOL WINAPI DrawCaptionTempW (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, + HICON hIcon, LPCWSTR str, UINT uFlags) { RECT rc = *rect; - TRACE("(%08x,%08x,%p,%08x,%08x,\"%s\",%08x)\n", - hwnd, hdc, rect, hFont, hIcon, str, uFlags); + TRACE("(%08x,%08x,%p,%08x,%08x,%s,%08x)\n", + hwnd, hdc, rect, hFont, hIcon, debugstr_w(str), uFlags); /* drawing background */ if (uFlags & DC_INBUTTON) { @@ -332,13 +347,13 @@ DrawCaptionTempA (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, } if (str) - DrawTextA (hdc, str, -1, &rc, + DrawTextW (hdc, str, -1, &rc, DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT); else { - CHAR szText[128]; + WCHAR szText[128]; INT nLen; - nLen = GetWindowTextA (hwnd, szText, 128); - DrawTextA (hdc, szText, nLen, &rc, + nLen = GetWindowTextW (hwnd, szText, 128); + DrawTextW (hdc, szText, nLen, &rc, DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_LEFT); } @@ -356,27 +371,6 @@ DrawCaptionTempA (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, } -/*********************************************************************** - * DrawCaptionTempW (USER32.@) - * - * PARAMS - * - * RETURNS - * Success: - * Failure: - */ - -BOOL WINAPI -DrawCaptionTempW (HWND hwnd, HDC hdc, const RECT *rect, HFONT hFont, - HICON hIcon, LPCWSTR str, UINT uFlags) -{ - LPSTR p = HEAP_strdupWtoA (GetProcessHeap (), 0, str); - BOOL res = DrawCaptionTempA (hwnd, hdc, rect, hFont, hIcon, p, uFlags); - HeapFree (GetProcessHeap (), 0, p); - return res; -} - - /*********************************************************************** * AdjustWindowRect (USER.102) */ diff --git a/windows/user.c b/windows/user.c index 32441f5ff48..7385dd08bc8 100644 --- a/windows/user.c +++ b/windows/user.c @@ -12,7 +12,6 @@ #include "wingdi.h" #include "winuser.h" #include "wine/winuser16.h" -#include "heap.h" #include "user.h" #include "win.h" #include "controls.h" @@ -364,21 +363,26 @@ BOOL WINAPI EnumDisplaySettingsA( /*********************************************************************** * EnumDisplaySettingsW (USER32.@) */ -BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) { - LPSTR nameA = HEAP_strdupWtoA(GetProcessHeap(),0,name); - DEVMODEA devmodeA; - BOOL ret = EnumDisplaySettingsA(nameA,n,&devmodeA); - - if (ret) { - devmode->dmBitsPerPel = devmodeA.dmBitsPerPel; - devmode->dmPelsHeight = devmodeA.dmPelsHeight; - devmode->dmPelsWidth = devmodeA.dmPelsWidth; - devmode->dmDisplayFlags = devmodeA.dmDisplayFlags; - devmode->dmDisplayFrequency = devmodeA.dmDisplayFrequency; - /* FIXME: convert rest too, if they are ever returned */ - } - HeapFree(GetProcessHeap(),0,nameA); - return ret; +BOOL WINAPI EnumDisplaySettingsW(LPCWSTR name,DWORD n,LPDEVMODEW devmode) +{ + DEVMODEA devmodeA; + BOOL ret; + DWORD len = WideCharToMultiByte( CP_ACP, 0, name, -1, NULL, 0, NULL, NULL ); + LPSTR nameA = HeapAlloc( GetProcessHeap(), 0, len ); + + WideCharToMultiByte( CP_ACP, 0, name, -1, nameA, len, NULL, NULL ); + ret = EnumDisplaySettingsA(nameA,n,&devmodeA); + if (ret) + { + devmode->dmBitsPerPel = devmodeA.dmBitsPerPel; + devmode->dmPelsHeight = devmodeA.dmPelsHeight; + devmode->dmPelsWidth = devmodeA.dmPelsWidth; + devmode->dmDisplayFlags = devmodeA.dmDisplayFlags; + devmode->dmDisplayFrequency = devmodeA.dmDisplayFrequency; + /* FIXME: convert rest too, if they are ever returned */ + } + HeapFree(GetProcessHeap(),0,nameA); + return ret; } /*********************************************************************** diff --git a/windows/win.c b/windows/win.c index 8f8404407fe..6348963cdb0 100644 --- a/windows/win.c +++ b/windows/win.c @@ -13,7 +13,6 @@ #include "wine/server.h" #include "wine/unicode.h" #include "win.h" -#include "heap.h" #include "user.h" #include "dce.h" #include "controls.h" @@ -1602,6 +1601,7 @@ HWND WINAPI FindWindowExA( HWND parent, HWND child, ATOM atom = 0; LPWSTR buffer; HWND hwnd; + INT len; if (className) { @@ -1613,8 +1613,11 @@ HWND WINAPI FindWindowExA( HWND parent, HWND child, return 0; } } + if (!title) return WIN_FindWindow( parent, child, atom, NULL ); - buffer = HEAP_strdupAtoW( GetProcessHeap(), 0, title ); + len = MultiByteToWideChar( CP_ACP, 0, title, -1, NULL, 0 ); + if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0; + MultiByteToWideChar( CP_ACP, 0, title, -1, buffer, len ); hwnd = WIN_FindWindow( parent, child, atom, buffer ); HeapFree( GetProcessHeap(), 0, buffer ); return hwnd; diff --git a/windows/winhelp.c b/windows/winhelp.c index c0e2d667474..009e21a0b26 100644 --- a/windows/winhelp.c +++ b/windows/winhelp.c @@ -12,7 +12,6 @@ #include "wine/winuser16.h" #include "wine/winbase16.h" #include "win.h" -#include "heap.h" DEFAULT_DEBUG_CHANNEL(win); @@ -144,11 +143,20 @@ BOOL WINAPI WinHelpA( HWND hWnd, LPCSTR lpHelpFile, UINT wCommand, /********************************************************************** * WinHelpW (USER32.@) */ -BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command, - DWORD dwData ) +BOOL WINAPI WinHelpW( HWND hWnd, LPCWSTR helpFile, UINT command, DWORD dwData ) { - LPSTR file = HEAP_strdupWtoA( GetProcessHeap(), 0, helpFile ); - BOOL ret = WinHelpA( hWnd, file, command, dwData ); - HeapFree( GetProcessHeap(), 0, file ); + INT len; + LPSTR file; + BOOL ret = FALSE; + + if (!helpFile) return WinHelpA( hWnd, NULL, command, dwData ); + + len = WideCharToMultiByte( CP_ACP, 0, helpFile, -1, NULL, 0, NULL, NULL ); + if ((file = HeapAlloc( GetProcessHeap(), 0, len ))) + { + WideCharToMultiByte( CP_ACP, 0, helpFile, -1, file, len, NULL, NULL ); + ret = WinHelpA( hWnd, file, command, dwData ); + HeapFree( GetProcessHeap(), 0, file ); + } return ret; } -- GitLab