From 760a5fbb46e7db1506d2f0e1d9c568db5ce851d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Sun, 8 Aug 2004 21:15:48 +0000 Subject: [PATCH] Sync to Wine-20040716: Mike McCormack - Fix memory allocation problems. Marcus Meissner - Do not assign to casted values. Alexandre Julliard - Implemented GetUIVersion (based on a patch by Stefan Leichter). Stefan Leichter - Removed the crosscalls (unicode to ascii) from GetAcceptLanguagesW. - Removed todo_wine from GetAcceptLanguagesA tests. - Added tests for GetAcceptLanguagesA. Henning Gerhardt - Translated some English resource files into German. Hajime Segawa - Added some Japanese translations. svn path=/trunk/; revision=10434 --- reactos/lib/shlwapi/assoc.c | 14 +-- reactos/lib/shlwapi/msgbox.c | 4 +- reactos/lib/shlwapi/ordinal.c | 182 ++++++++++++++++-------------- reactos/lib/shlwapi/reg.c | 8 +- reactos/lib/shlwapi/shlwapi.rc | 2 + reactos/lib/shlwapi/shlwapi.spec | 2 +- reactos/lib/shlwapi/shlwapi_De.rc | 35 ++++++ reactos/lib/shlwapi/shlwapi_Ja.rc | 35 ++++++ reactos/lib/shlwapi/url.c | 10 +- 9 files changed, 191 insertions(+), 101 deletions(-) create mode 100644 reactos/lib/shlwapi/shlwapi_De.rc create mode 100644 reactos/lib/shlwapi/shlwapi_Ja.rc diff --git a/reactos/lib/shlwapi/assoc.c b/reactos/lib/shlwapi/assoc.c index 4a8b1326930..4f6e4035430 100644 --- a/reactos/lib/shlwapi/assoc.c +++ b/reactos/lib/shlwapi/assoc.c @@ -75,7 +75,7 @@ static IQueryAssociations* IQueryAssociations_Constructor(void) { IQueryAssociationsImpl* iface; - iface =(IQueryAssociationsImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl)); + iface = HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl)); iface->lpVtbl = &IQueryAssociations_vtbl; iface->ref = 1; iface->hkeySource = NULL; @@ -95,7 +95,7 @@ static BOOL SHLWAPI_ParamAToW(LPCSTR lpszParam, LPWSTR lpszBuff, DWORD dwLen, { if (lpszParam) { - DWORD dwStrLen = lstrlenA(lpszParam); + DWORD dwStrLen = MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, NULL, 0); if (dwStrLen < dwLen) { @@ -104,12 +104,12 @@ static BOOL SHLWAPI_ParamAToW(LPCSTR lpszParam, LPWSTR lpszBuff, DWORD dwLen, else { /* Create a new buffer big enough for the string */ - *lpszOut = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, - (dwStrLen + 1) * sizeof(WCHAR)); + *lpszOut = HeapAlloc(GetProcessHeap(), 0, + dwStrLen * sizeof(WCHAR)); if (!*lpszOut) return FALSE; } - MultiByteToWideChar(0, 0, lpszParam, -1, *lpszOut, -1); + MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, *lpszOut, dwStrLen); } else *lpszOut = NULL; @@ -298,7 +298,7 @@ HRESULT WINAPI AssocQueryStringA(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc, DWORD dwLenOut = *pcchOut; if (dwLenOut >= MAX_PATH) - lpszReturnW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + lpszReturnW = HeapAlloc(GetProcessHeap(), 0, (dwLenOut + 1) * sizeof(WCHAR)); if (!lpszReturnW) @@ -389,7 +389,7 @@ HRESULT WINAPI AssocQueryStringByKeyA(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc { DWORD dwLenOut = *pcchOut; if (dwLenOut >= MAX_PATH) - lpszReturnW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, + lpszReturnW = HeapAlloc(GetProcessHeap(), 0, (dwLenOut + 1) * sizeof(WCHAR)); if (lpszReturnW) diff --git a/reactos/lib/shlwapi/msgbox.c b/reactos/lib/shlwapi/msgbox.c index d61c5f9815d..1f92ffb0aa2 100644 --- a/reactos/lib/shlwapi/msgbox.c +++ b/reactos/lib/shlwapi/msgbox.c @@ -84,11 +84,11 @@ static INT_PTR CALLBACK SHDlgProcEx(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM switch (LOWORD(wParam)) { case IDYES: - LOWORD(wParam) = IDOK; + wParam = MAKELONG(IDOK, HIWORD(wParam)); /* Fall through ... */ case IDNO: if (LOWORD(wParam) == IDNO) - LOWORD(wParam) = IDCANCEL; + wParam = MAKELONG(IDCANCEL, HIWORD(wParam)); /* Fall through ... */ case IDOK: case IDCANCEL: diff --git a/reactos/lib/shlwapi/ordinal.c b/reactos/lib/shlwapi/ordinal.c index b376f21f948..10bb801bf4b 100644 --- a/reactos/lib/shlwapi/ordinal.c +++ b/reactos/lib/shlwapi/ordinal.c @@ -518,109 +518,99 @@ RegisterDefaultAcceptHeaders_Exit: } /************************************************************************* - * @ [SHLWAPI.14] + * @ [SHLWAPI.15] * * Get Explorers "AcceptLanguage" setting. * * PARAMS * langbuf [O] Destination for language string * buflen [I] Length of langbuf + * [0] Success: used length of langbuf * * RETURNS * Success: S_OK. langbuf is set to the language string found. * Failure: E_FAIL, If any arguments are invalid, error occurred, or Explorer * does not contain the setting. + * E_INVALIDARG, If the buffer is not big enough */ -HRESULT WINAPI GetAcceptLanguagesA( - LPSTR langbuf, - LPDWORD buflen) +HRESULT WINAPI GetAcceptLanguagesW( LPWSTR langbuf, LPDWORD buflen) { - CHAR *mystr; - DWORD mystrlen, mytype; - HKEY mykey; - LCID mylcid; + static const WCHAR szkeyW[] = { + 'S','o','f','t','w','a','r','e','\\', + 'M','i','c','r','o','s','o','f','t','\\', + 'I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','\\', + 'I','n','t','e','r','n','a','t','i','o','n','a','l',0}; + static const WCHAR valueW[] = { + 'A','c','c','e','p','t','L','a','n','g','u','a','g','e',0}; + static const WCHAR enusW[] = {'e','n','-','u','s',0}; + DWORD mystrlen, mytype; + HKEY mykey; + HRESULT retval; + LCID mylcid; + WCHAR *mystr; - mystrlen = (*buflen > 6) ? *buflen : 6; - mystr = (CHAR*)HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, mystrlen); - RegOpenKeyA(HKEY_CURRENT_USER, - "Software\\Microsoft\\Internet Explorer\\International", - &mykey); - if (RegQueryValueExA(mykey, "AcceptLanguage", - 0, &mytype, (PBYTE)mystr, &mystrlen)) { - /* Did not find value */ - mylcid = GetUserDefaultLCID(); - /* somehow the mylcid translates into "en-us" - * this is similar to "LOCALE_SABBREVLANGNAME" - * which could be gotten via GetLocaleInfo. - * The only problem is LOCALE_SABBREVLANGUAGE" is - * a 3 char string (first 2 are country code and third is - * letter for "sublanguage", which does not come close to - * "en-us" - */ - lstrcpyA(mystr, "en-us"); - mystrlen = lstrlenA(mystr); - } - else { - /* handle returned string */ - FIXME("missing code\n"); - } - if (mystrlen > *buflen) - lstrcpynA(langbuf, mystr, *buflen); - else { - lstrcpyA(langbuf, mystr); - *buflen = lstrlenA(langbuf); - } - RegCloseKey(mykey); - HeapFree(GetProcessHeap(), 0, mystr); - TRACE("language is %s\n", debugstr_a(langbuf)); - return 0; + if(!langbuf || !buflen || !*buflen) + return E_FAIL; + + mystrlen = (*buflen > 20) ? *buflen : 20 ; + mystr = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * mystrlen); + RegOpenKeyW(HKEY_CURRENT_USER, szkeyW, &mykey); + if(RegQueryValueExW(mykey, valueW, 0, &mytype, (PBYTE)mystr, &mystrlen)) { + /* Did not find value */ + mylcid = GetUserDefaultLCID(); + /* somehow the mylcid translates into "en-us" + * this is similar to "LOCALE_SABBREVLANGNAME" + * which could be gotten via GetLocaleInfo. + * The only problem is LOCALE_SABBREVLANGUAGE" is + * a 3 char string (first 2 are country code and third is + * letter for "sublanguage", which does not come close to + * "en-us" + */ + lstrcpyW(mystr, enusW); + mystrlen = lstrlenW(mystr); + } else { + /* handle returned string */ + FIXME("missing code\n"); + } + memcpy( langbuf, mystr, min(*buflen,strlenW(mystr)+1)*sizeof(WCHAR) ); + + if(*buflen > lstrlenW(mystr)) { + *buflen = lstrlenW(mystr); + retval = S_OK; + } else { + *buflen = 0; + retval = E_INVALIDARG; + SetLastError(ERROR_INSUFFICIENT_BUFFER); + } + RegCloseKey(mykey); + HeapFree(GetProcessHeap(), 0, mystr); + return retval; } /************************************************************************* - * @ [SHLWAPI.15] + * @ [SHLWAPI.14] * - * Unicode version of GetAcceptLanguagesA. + * Ascii version of GetAcceptLanguagesW. */ -HRESULT WINAPI GetAcceptLanguagesW( - LPWSTR langbuf, - LPDWORD buflen) +HRESULT WINAPI GetAcceptLanguagesA( LPSTR langbuf, LPDWORD buflen) { - CHAR *mystr; - DWORD mystrlen, mytype; - HKEY mykey; - LCID mylcid; + WCHAR *langbufW; + DWORD buflenW, convlen; + HRESULT retval; - mystrlen = (*buflen > 6) ? *buflen : 6; - mystr = (CHAR*)HeapAlloc(GetProcessHeap(), - HEAP_ZERO_MEMORY, mystrlen); - RegOpenKeyA(HKEY_CURRENT_USER, - "Software\\Microsoft\\Internet Explorer\\International", - &mykey); - if (RegQueryValueExA(mykey, "AcceptLanguage", - 0, &mytype, (PBYTE)mystr, &mystrlen)) { - /* Did not find value */ - mylcid = GetUserDefaultLCID(); - /* somehow the mylcid translates into "en-us" - * this is similar to "LOCALE_SABBREVLANGNAME" - * which could be gotten via GetLocaleInfo. - * The only problem is LOCALE_SABBREVLANGUAGE" is - * a 3 char string (first 2 are country code and third is - * letter for "sublanguage", which does not come close to - * "en-us" - */ - lstrcpyA(mystr, "en-us"); - mystrlen = lstrlenA(mystr); - } - else { - /* handle returned string */ - FIXME("missing code\n"); - } - RegCloseKey(mykey); - *buflen = MultiByteToWideChar(0, 0, mystr, -1, langbuf, (*buflen)-1); - HeapFree(GetProcessHeap(), 0, mystr); - TRACE("language is %s\n", debugstr_w(langbuf)); - return 0; + if(!langbuf || !buflen || !*buflen) return E_FAIL; + + buflenW = *buflen; + langbufW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * buflenW); + retval = GetAcceptLanguagesW(langbufW, &buflenW); + + /* FIXME: this is wrong, the string may not be null-terminated */ + convlen = WideCharToMultiByte(CP_ACP, 0, langbufW, -1, langbuf, + *buflen, NULL, NULL); + *buflen = buflenW ? convlen : 0; + + if(langbufW) HeapFree(GetProcessHeap(), 0, langbufW); + return retval; } /************************************************************************* @@ -3965,3 +3955,31 @@ HRESULT WINAPI SKGetValueW(DWORD a, LPWSTR b, LPWSTR c, DWORD d, DWORD e, DWORD FIXME("(%lx, %s, %s, %lx, %lx, %lx): stub\n", a, debugstr_w(b), debugstr_w(c), d, e, f); return E_FAIL; } + +typedef HRESULT (WINAPI *DllGetVersion_func)(DLLVERSIONINFO *); + +/*********************************************************************** + * GetUIVersion (SHLWAPI.452) + */ +DWORD WINAPI GetUIVersion(void) +{ + static DWORD version; + + if (!version) + { + DllGetVersion_func pDllGetVersion; + HMODULE dll = LoadLibraryA("shell32.dll"); + if (!dll) return 0; + + pDllGetVersion = (DllGetVersion_func)GetProcAddress(dll, "DllGetVersion"); + if (pDllGetVersion) + { + DLLVERSIONINFO dvi; + dvi.cbSize = sizeof(DLLVERSIONINFO); + if (pDllGetVersion(&dvi) == S_OK) version = dvi.dwMajorVersion; + } + FreeLibrary( dll ); + if (!version) version = 3; /* old shell dlls don't have DllGetVersion */ + } + return version; +} diff --git a/reactos/lib/shlwapi/reg.c b/reactos/lib/shlwapi/reg.c index 440991f90ec..4f81c5af32b 100644 --- a/reactos/lib/shlwapi/reg.c +++ b/reactos/lib/shlwapi/reg.c @@ -1204,8 +1204,8 @@ DWORD WINAPI SHQueryValueExA( HKEY hKey, LPCSTR lpszValue, } else { - nBytesToAlloc = lstrlenA(pvData) * sizeof (CHAR); - szData = (LPSTR) LocalAlloc(GMEM_ZEROINIT, nBytesToAlloc + 1); + nBytesToAlloc = (lstrlenA(pvData)+1) * sizeof (CHAR); + szData = (LPSTR) LocalAlloc(GMEM_ZEROINIT, nBytesToAlloc ); lstrcpyA(szData, pvData); dwExpDataLen = ExpandEnvironmentStringsA(szData, pvData, *pcbData / sizeof(CHAR)); if (dwExpDataLen > *pcbData) dwRet = ERROR_MORE_DATA; @@ -1265,8 +1265,8 @@ DWORD WINAPI SHQueryValueExW(HKEY hKey, LPCWSTR lpszValue, } else { - nBytesToAlloc = lstrlenW(pvData) * sizeof(WCHAR); - szData = (LPWSTR) LocalAlloc(GMEM_ZEROINIT, nBytesToAlloc + 1); + nBytesToAlloc = (lstrlenW(pvData) + 1) * sizeof(WCHAR); + szData = (LPWSTR) LocalAlloc(GMEM_ZEROINIT, nBytesToAlloc ); lstrcpyW(szData, pvData); dwExpDataLen = ExpandEnvironmentStringsW(szData, pvData, *pcbData/sizeof(WCHAR) ); if (dwExpDataLen > *pcbData) dwRet = ERROR_MORE_DATA; diff --git a/reactos/lib/shlwapi/shlwapi.rc b/reactos/lib/shlwapi/shlwapi.rc index 6e663615ff0..95abe908275 100644 --- a/reactos/lib/shlwapi/shlwapi.rc +++ b/reactos/lib/shlwapi/shlwapi.rc @@ -23,5 +23,7 @@ #include "winuser.h" #include "resource.h" +#include "shlwapi_De.rc" #include "shlwapi_En.rc" #include "shlwapi_Es.rc" +#include "shlwapi_Ja.rc" diff --git a/reactos/lib/shlwapi/shlwapi.spec b/reactos/lib/shlwapi/shlwapi.spec index 934b24cec18..f504538cdad 100644 --- a/reactos/lib/shlwapi/shlwapi.spec +++ b/reactos/lib/shlwapi/shlwapi.spec @@ -535,7 +535,7 @@ 539 stub -noname IUnknown_ShowBrowserBar 540 stub -noname SHInvokeCommandOnContextMenu 541 stub -noname SHInvokeCommandsOnContextMen -542 stub -noname GetUIVersion +542 stdcall -noname GetUIVersion() 543 stub -noname CreateColorSpaceWrapW 544 stub -noname QuerySourceCreateFromKey 545 stub -noname SHForwardContextMenuMsg diff --git a/reactos/lib/shlwapi/shlwapi_De.rc b/reactos/lib/shlwapi/shlwapi_De.rc new file mode 100644 index 00000000000..1087514d0ba --- /dev/null +++ b/reactos/lib/shlwapi/shlwapi_De.rc @@ -0,0 +1,35 @@ +/* + * German resources for shlwapi + * + * Copyright 2004 Henning Gerhardt + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +LANGUAGE LANG_GERMAN, SUBLANG_DEFAULT + +IDD_ERR_DIALOG DIALOG MOVEABLE DISCARDABLE 0, 0, 220, 60 +STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "Fehler!" +FONT 8, "MS Shell Dlg" +{ + LTEXT "", IDS_ERR_USER_MSG2, 15, 5, 28, 20 + LTEXT "", IDS_ERR_USER_MSG, 15, 5, 210, 8 + CHECKBOX "&Diesen Dialog nicht mehr anzeigen", IDC_ERR_DONT_SHOW, 5, 20, 210, 10, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&OK" IDOK, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Abbrechen" IDCANCEL, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Ja" IDYES, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&Nein" IDNO, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP +} diff --git a/reactos/lib/shlwapi/shlwapi_Ja.rc b/reactos/lib/shlwapi/shlwapi_Ja.rc new file mode 100644 index 00000000000..0f4da46bf61 --- /dev/null +++ b/reactos/lib/shlwapi/shlwapi_Ja.rc @@ -0,0 +1,35 @@ +/* + * Japanese resources for shlwapi + * + * Copyright 2004 Hajime Segawa + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT + +IDD_ERR_DIALOG DIALOG MOVEABLE DISCARDABLE 0, 0, 220, 60 +STYLE DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU +CAPTION "エラー!" +FONT 9, "MS UI Gothic" +{ + LTEXT "", IDS_ERR_USER_MSG2, 15, 5, 28, 20 + LTEXT "", IDS_ERR_USER_MSG, 15, 5, 210, 8 + CHECKBOX "今後はこのメッセージを表示しない(&i)", IDC_ERR_DONT_SHOW, 5, 20, 210, 10, BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP + PUSHBUTTON L"&OK" IDOK, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"キャンセル(&C)" IDCANCEL, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"はい(&Y)" IDYES, 105, 40, 50, 14, WS_GROUP | WS_TABSTOP + PUSHBUTTON L"いいえ(&N)" IDNO, 160, 40, 50, 14, WS_GROUP | WS_TABSTOP +} diff --git a/reactos/lib/shlwapi/url.c b/reactos/lib/shlwapi/url.c index 7bd2a124c59..ad70791064a 100644 --- a/reactos/lib/shlwapi/url.c +++ b/reactos/lib/shlwapi/url.c @@ -369,8 +369,8 @@ DWORD WINAPI ParseURLW(LPCWSTR x, UNKNOWN_SHLWAPI_2 *y) /* see if known scheme and return indicator number */ len = WideCharToMultiByte(0, 0, y->ap1, y->sizep1, 0, 0, 0, 0); - cmpstr = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len+1); - WideCharToMultiByte(0, 0, y->ap1, y->sizep1, cmpstr, len+1, 0, 0); + cmpstr = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len); + WideCharToMultiByte(0, 0, y->ap1, y->sizep1, cmpstr, len, 0, 0); y->fcncde = URL_SCHEME_UNKNOWN; inet_pro = shlwapi_schemes; while (inet_pro->scheme_name) { @@ -422,7 +422,7 @@ HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized, if(!pszUrl || !pszCanonicalized || !pcchCanonicalized) return E_INVALIDARG; - base = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, + base = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR)); canonical = base + INTERNET_MAX_URL_LENGTH; @@ -1482,7 +1482,7 @@ HRESULT WINAPI UrlApplySchemeA(LPCSTR pszIn, LPSTR pszOut, LPDWORD pcchOut, DWOR TRACE("(in %s, out size %ld, flags %08lx) using W version\n", debugstr_a(pszIn), *pcchOut, dwFlags); - in = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, + in = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR)); out = in + INTERNET_MAX_URL_LENGTH; @@ -1968,7 +1968,7 @@ HRESULT WINAPI UrlGetPartA(LPCSTR pszIn, LPSTR pszOut, LPDWORD pcchOut, LPWSTR in, out; DWORD ret, len, len2; - in = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, + in = HeapAlloc(GetProcessHeap(), 0, (2*INTERNET_MAX_URL_LENGTH) * sizeof(WCHAR)); out = in + INTERNET_MAX_URL_LENGTH;