Commit d55061b9 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

shell32: Prepare QueryAssociations helper functions to work on non LPWSTR data.

parent ed416733
...@@ -215,27 +215,28 @@ static HRESULT WINAPI IQueryAssociations_fnInit( ...@@ -215,27 +215,28 @@ static HRESULT WINAPI IQueryAssociations_fnInit(
return E_INVALIDARG; return E_INVALIDARG;
} }
static HRESULT ASSOC_GetValue(HKEY hkey, WCHAR ** pszText) static HRESULT ASSOC_GetValue(HKEY hkey, const WCHAR *name, void **data, DWORD *data_size)
{ {
DWORD len; DWORD size;
LONG ret; LONG ret;
assert(pszText); assert(data);
ret = RegQueryValueExW(hkey, NULL, 0, NULL, NULL, &len); ret = RegQueryValueExW(hkey, name, 0, NULL, NULL, &size);
if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS)
return HRESULT_FROM_WIN32(ret); return HRESULT_FROM_WIN32(ret);
if (!len) if (!size)
return E_FAIL; return E_FAIL;
*pszText = HeapAlloc(GetProcessHeap(), 0, len); *data = HeapAlloc(GetProcessHeap(), 0, size);
if (!*pszText) if (!*data)
return E_OUTOFMEMORY; return E_OUTOFMEMORY;
ret = RegQueryValueExW(hkey, NULL, 0, NULL, (LPBYTE)*pszText, ret = RegQueryValueExW(hkey, name, 0, NULL, (LPBYTE)*data, &size);
&len);
if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS)
{ {
HeapFree(GetProcessHeap(), 0, *pszText); HeapFree(GetProcessHeap(), 0, *data);
return HRESULT_FROM_WIN32(ret); return HRESULT_FROM_WIN32(ret);
} }
if(data_size)
*data_size = size;
return S_OK; return S_OK;
} }
...@@ -253,7 +254,7 @@ static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This, ...@@ -253,7 +254,7 @@ static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This,
static const WCHAR commandW[] = { 'c','o','m','m','a','n','d',0 }; static const WCHAR commandW[] = { 'c','o','m','m','a','n','d',0 };
static const WCHAR shellW[] = { 's','h','e','l','l',0 }; static const WCHAR shellW[] = { 's','h','e','l','l',0 };
hr = ASSOC_GetValue(This->hkeySource, &pszFileType); hr = ASSOC_GetValue(This->hkeySource, NULL, (void**)&pszFileType, NULL);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile); ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
...@@ -268,7 +269,7 @@ static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This, ...@@ -268,7 +269,7 @@ static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This,
if (!pszExtra) if (!pszExtra)
{ {
hr = ASSOC_GetValue(hkeyShell, &pszExtraFromReg); hr = ASSOC_GetValue(hkeyShell, NULL, (void**)&pszExtraFromReg, NULL);
/* if no default action */ /* if no default action */
if (hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) if (hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
{ {
...@@ -311,7 +312,7 @@ static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This, ...@@ -311,7 +312,7 @@ static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This,
RegCloseKey(hkeyVerb); RegCloseKey(hkeyVerb);
if (ret != ERROR_SUCCESS) if (ret != ERROR_SUCCESS)
return HRESULT_FROM_WIN32(ret); return HRESULT_FROM_WIN32(ret);
hr = ASSOC_GetValue(hkeyCommand, ppszCommand); hr = ASSOC_GetValue(hkeyCommand, NULL, (void**)ppszCommand, NULL);
RegCloseKey(hkeyCommand); RegCloseKey(hkeyCommand);
return hr; return hr;
} }
...@@ -361,7 +362,7 @@ static HRESULT ASSOC_GetExecutable(IQueryAssociationsImpl *This, ...@@ -361,7 +362,7 @@ static HRESULT ASSOC_GetExecutable(IQueryAssociationsImpl *This,
return S_OK; return S_OK;
} }
static HRESULT ASSOC_ReturnData(LPWSTR out, DWORD *outlen, LPCWSTR data, static HRESULT ASSOC_ReturnData(void *out, DWORD *outlen, const void *data,
DWORD datalen) DWORD datalen)
{ {
assert(outlen); assert(outlen);
...@@ -374,7 +375,7 @@ static HRESULT ASSOC_ReturnData(LPWSTR out, DWORD *outlen, LPCWSTR data, ...@@ -374,7 +375,7 @@ static HRESULT ASSOC_ReturnData(LPWSTR out, DWORD *outlen, LPCWSTR data,
return E_POINTER; return E_POINTER;
} }
*outlen = datalen; *outlen = datalen;
lstrcpynW(out, data, datalen); memcpy(out, data, datalen);
return S_OK; return S_OK;
} }
else else
...@@ -384,6 +385,19 @@ static HRESULT ASSOC_ReturnData(LPWSTR out, DWORD *outlen, LPCWSTR data, ...@@ -384,6 +385,19 @@ static HRESULT ASSOC_ReturnData(LPWSTR out, DWORD *outlen, LPCWSTR data,
} }
} }
static HRESULT ASSOC_ReturnString(LPWSTR out, DWORD *outlen, LPCWSTR data,
DWORD datalen)
{
HRESULT hres;
assert(outlen);
*outlen *= sizeof(WCHAR);
hres = ASSOC_ReturnData(out, outlen, data, datalen*sizeof(WCHAR));
*outlen /= sizeof(WCHAR);
return hres;
}
/************************************************************************** /**************************************************************************
* IQueryAssociations_GetString * IQueryAssociations_GetString
* *
...@@ -432,7 +446,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString( ...@@ -432,7 +446,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
hr = ASSOC_GetCommand(This, pszExtra, &command); hr = ASSOC_GetCommand(This, pszExtra, &command);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = ASSOC_ReturnData(pszOut, pcchOut, command, strlenW(command) + 1); hr = ASSOC_ReturnString(pszOut, pcchOut, command, strlenW(command) + 1);
HeapFree(GetProcessHeap(), 0, command); HeapFree(GetProcessHeap(), 0, command);
} }
return hr; return hr;
...@@ -444,7 +458,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString( ...@@ -444,7 +458,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
len++; len++;
return ASSOC_ReturnData(pszOut, pcchOut, path, len); return ASSOC_ReturnString(pszOut, pcchOut, path, len);
} }
case ASSOCSTR_FRIENDLYDOCNAME: case ASSOCSTR_FRIENDLYDOCNAME:
...@@ -453,7 +467,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString( ...@@ -453,7 +467,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
DWORD ret; DWORD ret;
DWORD size; DWORD size;
hr = ASSOC_GetValue(This->hkeySource, &pszFileType); hr = ASSOC_GetValue(This->hkeySource, NULL, (void**)&pszFileType, NULL);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
size = 0; size = 0;
...@@ -465,7 +479,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString( ...@@ -465,7 +479,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
{ {
ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, docName, &size); ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, docName, &size);
if (ret == ERROR_SUCCESS) if (ret == ERROR_SUCCESS)
hr = ASSOC_ReturnData(pszOut, pcchOut, docName, strlenW(docName) + 1); hr = ASSOC_ReturnString(pszOut, pcchOut, docName, strlenW(docName) + 1);
else else
hr = HRESULT_FROM_WIN32(ret); hr = HRESULT_FROM_WIN32(ret);
HeapFree(GetProcessHeap(), 0, docName); HeapFree(GetProcessHeap(), 0, docName);
...@@ -521,7 +535,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString( ...@@ -521,7 +535,7 @@ static HRESULT WINAPI IQueryAssociations_fnGetString(
/* Does strlenW(bufW) == 0 mean we use the filename? */ /* Does strlenW(bufW) == 0 mean we use the filename? */
len = strlenW(bufW) + 1; len = strlenW(bufW) + 1;
TRACE("found FileDescription: %s\n", debugstr_w(bufW)); TRACE("found FileDescription: %s\n", debugstr_w(bufW));
hr = ASSOC_ReturnData(pszOut, pcchOut, bufW, len); hr = ASSOC_ReturnString(pszOut, pcchOut, bufW, len);
HeapFree(GetProcessHeap(), 0, verinfoW); HeapFree(GetProcessHeap(), 0, verinfoW);
return hr; return hr;
} }
...@@ -531,7 +545,7 @@ get_friendly_name_fail: ...@@ -531,7 +545,7 @@ get_friendly_name_fail:
PathRemoveExtensionW(path); PathRemoveExtensionW(path);
PathStripPathW(path); PathStripPathW(path);
TRACE("using filename: %s\n", debugstr_w(path)); TRACE("using filename: %s\n", debugstr_w(path));
hr = ASSOC_ReturnData(pszOut, pcchOut, path, strlenW(path) + 1); hr = ASSOC_ReturnString(pszOut, pcchOut, path, strlenW(path) + 1);
HeapFree(GetProcessHeap(), 0, verinfoW); HeapFree(GetProcessHeap(), 0, verinfoW);
return hr; return hr;
} }
...@@ -552,7 +566,7 @@ get_friendly_name_fail: ...@@ -552,7 +566,7 @@ get_friendly_name_fail:
{ {
ret = RegGetValueW(This->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, contentType, &size); ret = RegGetValueW(This->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, contentType, &size);
if (ret == ERROR_SUCCESS) if (ret == ERROR_SUCCESS)
hr = ASSOC_ReturnData(pszOut, pcchOut, contentType, strlenW(contentType) + 1); hr = ASSOC_ReturnString(pszOut, pcchOut, contentType, strlenW(contentType) + 1);
else else
hr = HRESULT_FROM_WIN32(ret); hr = HRESULT_FROM_WIN32(ret);
HeapFree(GetProcessHeap(), 0, contentType); HeapFree(GetProcessHeap(), 0, contentType);
...@@ -570,7 +584,7 @@ get_friendly_name_fail: ...@@ -570,7 +584,7 @@ get_friendly_name_fail:
DWORD size; DWORD size;
HKEY hkeyFile; HKEY hkeyFile;
hr = ASSOC_GetValue(This->hkeySource, &pszFileType); hr = ASSOC_GetValue(This->hkeySource, NULL, (void**)&pszFileType, NULL);
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile); ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
...@@ -585,7 +599,7 @@ get_friendly_name_fail: ...@@ -585,7 +599,7 @@ get_friendly_name_fail:
{ {
ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, icon, &size); ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, icon, &size);
if (ret == ERROR_SUCCESS) if (ret == ERROR_SUCCESS)
hr = ASSOC_ReturnData(pszOut, pcchOut, icon, strlenW(icon) + 1); hr = ASSOC_ReturnString(pszOut, pcchOut, icon, strlenW(icon) + 1);
else else
hr = HRESULT_FROM_WIN32(ret); hr = HRESULT_FROM_WIN32(ret);
HeapFree(GetProcessHeap(), 0, icon); HeapFree(GetProcessHeap(), 0, icon);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment