2002-09-05 01:32:19 +02:00
|
|
|
/*
|
2003-07-19 05:07:41 +02:00
|
|
|
* IQueryAssociations object and helper functions
|
2002-09-05 01:32:19 +02:00
|
|
|
*
|
|
|
|
* Copyright 2002 Jon Griffiths
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-09-05 01:32:19 +02:00
|
|
|
*/
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2008-10-11 08:34:04 +02:00
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
#include "windef.h"
|
2003-08-20 20:22:31 +02:00
|
|
|
#include "winbase.h"
|
2002-09-05 01:32:19 +02:00
|
|
|
#include "winnls.h"
|
|
|
|
#include "winreg.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "objbase.h"
|
2002-09-05 01:32:19 +02:00
|
|
|
#include "shlguid.h"
|
|
|
|
#include "shlwapi.h"
|
2008-10-14 03:15:54 +02:00
|
|
|
#include "ver.h"
|
2008-10-11 08:34:04 +02:00
|
|
|
#include "wine/unicode.h"
|
2002-09-05 01:32:19 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
|
|
|
|
2003-07-19 05:07:41 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations {SHLWAPI}
|
|
|
|
*
|
|
|
|
* DESCRIPTION
|
|
|
|
* This object provides a layer of abstraction over the system registry in
|
|
|
|
* order to simplify the process of parsing associations between files.
|
|
|
|
* Associations in this context means the registry entries that link (for
|
|
|
|
* example) the extension of a file with its description, list of
|
|
|
|
* applications to open the file with, and actions that can be performed on it
|
|
|
|
* (the shell displays such information in the context menu of explorer
|
|
|
|
* when you right-click on a file).
|
|
|
|
*
|
|
|
|
* HELPERS
|
2005-02-25 15:07:56 +01:00
|
|
|
* You can use this object transparently by calling the helper functions
|
2003-07-19 05:07:41 +02:00
|
|
|
* AssocQueryKeyA(), AssocQueryStringA() and AssocQueryStringByKeyA(). These
|
|
|
|
* create an IQueryAssociations object, perform the requested actions
|
|
|
|
* and then dispose of the object. Alternatively, you can create an instance
|
|
|
|
* of the object using AssocCreate() and call the following methods on it:
|
|
|
|
*
|
|
|
|
* METHODS
|
|
|
|
*/
|
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
/* Default IQueryAssociations::Init() flags */
|
|
|
|
#define SHLWAPI_DEF_ASSOCF (ASSOCF_INIT_BYEXENAME|ASSOCF_INIT_DEFAULTTOSTAR| \
|
|
|
|
ASSOCF_INIT_DEFAULTTOFOLDER)
|
|
|
|
|
2003-07-19 05:07:41 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2005-06-06 21:50:35 +02:00
|
|
|
const IQueryAssociationsVtbl *lpVtbl;
|
2003-07-19 05:07:41 +02:00
|
|
|
LONG ref;
|
2003-09-11 04:56:15 +02:00
|
|
|
HKEY hkeySource;
|
|
|
|
HKEY hkeyProgID;
|
2003-07-19 05:07:41 +02:00
|
|
|
} IQueryAssociationsImpl;
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IQueryAssociationsVtbl IQueryAssociations_vtbl;
|
2003-07-19 05:07:41 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_Constructor [internal]
|
|
|
|
*
|
|
|
|
* Construct a new IQueryAssociations object.
|
2002-09-05 01:32:19 +02:00
|
|
|
*/
|
2003-07-19 05:07:41 +02:00
|
|
|
static IQueryAssociations* IQueryAssociations_Constructor(void)
|
2002-09-05 01:32:19 +02:00
|
|
|
{
|
2003-07-19 05:07:41 +02:00
|
|
|
IQueryAssociationsImpl* iface;
|
|
|
|
|
2004-07-04 02:06:29 +02:00
|
|
|
iface = HeapAlloc(GetProcessHeap(),0,sizeof(IQueryAssociationsImpl));
|
2003-07-19 05:07:41 +02:00
|
|
|
iface->lpVtbl = &IQueryAssociations_vtbl;
|
|
|
|
iface->ref = 1;
|
2003-09-11 04:56:15 +02:00
|
|
|
iface->hkeySource = NULL;
|
|
|
|
iface->hkeyProgID = NULL;
|
2003-07-19 05:07:41 +02:00
|
|
|
|
|
|
|
TRACE("Returning IQueryAssociations* %p\n", iface);
|
|
|
|
return (IQueryAssociations*)iface;
|
2002-09-05 01:32:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* SHLWAPI_ParamAToW
|
|
|
|
*
|
|
|
|
* Internal helper function: Convert ASCII parameter to Unicode.
|
|
|
|
*/
|
|
|
|
static BOOL SHLWAPI_ParamAToW(LPCSTR lpszParam, LPWSTR lpszBuff, DWORD dwLen,
|
|
|
|
LPWSTR* lpszOut)
|
|
|
|
{
|
|
|
|
if (lpszParam)
|
|
|
|
{
|
2004-07-04 02:06:29 +02:00
|
|
|
DWORD dwStrLen = MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, NULL, 0);
|
2002-09-05 01:32:19 +02:00
|
|
|
|
|
|
|
if (dwStrLen < dwLen)
|
|
|
|
{
|
|
|
|
*lpszOut = lpszBuff; /* Use Buffer, it is big enough */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Create a new buffer big enough for the string */
|
2004-07-04 02:06:29 +02:00
|
|
|
*lpszOut = HeapAlloc(GetProcessHeap(), 0,
|
|
|
|
dwStrLen * sizeof(WCHAR));
|
2002-09-05 01:32:19 +02:00
|
|
|
if (!*lpszOut)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-07-04 02:06:29 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszParam, -1, *lpszOut, dwStrLen);
|
2002-09-05 01:32:19 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*lpszOut = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* AssocCreate [SHLWAPI.@]
|
2002-09-05 01:32:19 +02:00
|
|
|
*
|
|
|
|
* Create a new IQueryAssociations object.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* clsid [I] CLSID of object
|
|
|
|
* refiid [I] REFIID of interface
|
|
|
|
* lpInterface [O] Destination for the created IQueryAssociations object
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-07-19 05:07:41 +02:00
|
|
|
* Success: S_OK. lpInterface contains the new object.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
2009-07-30 03:30:22 +02:00
|
|
|
* clsid must be equal to CLSID_QueryAssociations and
|
|
|
|
* refiid must be equal to IID_IQueryAssociations, IID_IUnknown or this function will fail
|
2002-09-05 01:32:19 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI AssocCreate(CLSID clsid, REFIID refiid, void **lpInterface)
|
|
|
|
{
|
|
|
|
HRESULT hRet;
|
|
|
|
IQueryAssociations* lpAssoc;
|
|
|
|
|
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_guid(&clsid), debugstr_guid(refiid),
|
|
|
|
lpInterface);
|
|
|
|
|
|
|
|
if (!lpInterface)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*(DWORD*)lpInterface = 0;
|
|
|
|
|
2009-07-30 03:30:22 +02:00
|
|
|
if (!IsEqualGUID(&clsid, &CLSID_QueryAssociations))
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
2002-09-05 01:32:19 +02:00
|
|
|
|
|
|
|
lpAssoc = IQueryAssociations_Constructor();
|
|
|
|
|
|
|
|
if (!lpAssoc)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hRet = IQueryAssociations_QueryInterface(lpAssoc, refiid, lpInterface);
|
|
|
|
IQueryAssociations_Release(lpAssoc);
|
2009-07-30 03:30:22 +02:00
|
|
|
|
|
|
|
if(hRet == E_NOINTERFACE)
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* AssocQueryKeyW [SHLWAPI.@]
|
2002-09-05 01:32:19 +02:00
|
|
|
*
|
|
|
|
* See AssocQueryKeyA.
|
|
|
|
*/
|
2003-07-19 05:07:41 +02:00
|
|
|
HRESULT WINAPI AssocQueryKeyW(ASSOCF cfFlags, ASSOCKEY assockey, LPCWSTR pszAssoc,
|
2002-09-05 01:32:19 +02:00
|
|
|
LPCWSTR pszExtra, HKEY *phkeyOut)
|
|
|
|
{
|
|
|
|
HRESULT hRet;
|
|
|
|
IQueryAssociations* lpAssoc;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags, assockey, debugstr_w(pszAssoc),
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_w(pszExtra), phkeyOut);
|
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
lpAssoc = IQueryAssociations_Constructor();
|
|
|
|
|
|
|
|
if (!lpAssoc)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2003-07-19 05:07:41 +02:00
|
|
|
cfFlags &= SHLWAPI_DEF_ASSOCF;
|
|
|
|
hRet = IQueryAssociations_Init(lpAssoc, cfFlags, pszAssoc, NULL, NULL);
|
2002-09-05 01:32:19 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hRet))
|
2003-07-19 05:07:41 +02:00
|
|
|
hRet = IQueryAssociations_GetKey(lpAssoc, cfFlags, assockey, pszExtra, phkeyOut);
|
2002-09-05 01:32:19 +02:00
|
|
|
|
|
|
|
IQueryAssociations_Release(lpAssoc);
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* AssocQueryKeyA [SHLWAPI.@]
|
2002-09-05 01:32:19 +02:00
|
|
|
*
|
|
|
|
* Get a file association key from the registry.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:07:41 +02:00
|
|
|
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
|
|
|
* assockey [I] Type of key to get
|
2002-09-05 01:32:19 +02:00
|
|
|
* pszAssoc [I] Key name to search below
|
|
|
|
* pszExtra [I] Extra information about the key location
|
|
|
|
* phkeyOut [O] Destination for the association key
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-07-19 05:07:41 +02:00
|
|
|
* Success: S_OK. phkeyOut contains the key.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
2002-09-05 01:32:19 +02:00
|
|
|
*/
|
2003-07-19 05:07:41 +02:00
|
|
|
HRESULT WINAPI AssocQueryKeyA(ASSOCF cfFlags, ASSOCKEY assockey, LPCSTR pszAssoc,
|
2002-09-05 01:32:19 +02:00
|
|
|
LPCSTR pszExtra, HKEY *phkeyOut)
|
|
|
|
{
|
|
|
|
WCHAR szAssocW[MAX_PATH], *lpszAssocW = NULL;
|
|
|
|
WCHAR szExtraW[MAX_PATH], *lpszExtraW = NULL;
|
|
|
|
HRESULT hRet = E_OUTOFMEMORY;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(0x%8x,0x%8x,%s,%s,%p)\n", cfFlags, assockey, debugstr_a(pszAssoc),
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_a(pszExtra), phkeyOut);
|
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
if (SHLWAPI_ParamAToW(pszAssoc, szAssocW, MAX_PATH, &lpszAssocW) &&
|
|
|
|
SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
|
|
|
|
{
|
2003-07-19 05:07:41 +02:00
|
|
|
hRet = AssocQueryKeyW(cfFlags, assockey, lpszAssocW, lpszExtraW, phkeyOut);
|
2002-09-05 01:32:19 +02:00
|
|
|
}
|
|
|
|
|
2006-06-07 10:55:33 +02:00
|
|
|
if (lpszAssocW != szAssocW)
|
2002-09-05 01:32:19 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszAssocW);
|
|
|
|
|
2006-06-07 10:55:33 +02:00
|
|
|
if (lpszExtraW != szExtraW)
|
2002-09-05 01:32:19 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszExtraW);
|
|
|
|
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* AssocQueryStringW [SHLWAPI.@]
|
2002-09-05 01:32:19 +02:00
|
|
|
*
|
|
|
|
* See AssocQueryStringA.
|
|
|
|
*/
|
2003-07-19 05:07:41 +02:00
|
|
|
HRESULT WINAPI AssocQueryStringW(ASSOCF cfFlags, ASSOCSTR str, LPCWSTR pszAssoc,
|
2002-09-05 01:32:19 +02:00
|
|
|
LPCWSTR pszExtra, LPWSTR pszOut, DWORD *pcchOut)
|
|
|
|
{
|
|
|
|
HRESULT hRet;
|
|
|
|
IQueryAssociations* lpAssoc;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(0x%8x,0x%8x,%s,%s,%p,%p)\n", cfFlags, str, debugstr_w(pszAssoc),
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_w(pszExtra), pszOut, pcchOut);
|
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
if (!pcchOut)
|
2008-10-11 07:21:25 +02:00
|
|
|
return E_UNEXPECTED;
|
2002-09-05 01:32:19 +02:00
|
|
|
|
|
|
|
lpAssoc = IQueryAssociations_Constructor();
|
|
|
|
|
|
|
|
if (!lpAssoc)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2003-07-19 05:07:41 +02:00
|
|
|
hRet = IQueryAssociations_Init(lpAssoc, cfFlags & SHLWAPI_DEF_ASSOCF,
|
2002-12-02 19:10:57 +01:00
|
|
|
pszAssoc, NULL, NULL);
|
2002-09-05 01:32:19 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hRet))
|
2003-07-19 05:07:41 +02:00
|
|
|
hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra,
|
2002-09-05 01:32:19 +02:00
|
|
|
pszOut, pcchOut);
|
|
|
|
|
|
|
|
IQueryAssociations_Release(lpAssoc);
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* AssocQueryStringA [SHLWAPI.@]
|
2002-09-05 01:32:19 +02:00
|
|
|
*
|
|
|
|
* Get a file association string from the registry.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:07:41 +02:00
|
|
|
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
|
|
|
* str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
|
2002-09-05 01:32:19 +02:00
|
|
|
* pszAssoc [I] Key name to search below
|
|
|
|
* pszExtra [I] Extra information about the string location
|
|
|
|
* pszOut [O] Destination for the association string
|
|
|
|
* pcchOut [O] Length of pszOut
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-07-19 05:07:41 +02:00
|
|
|
* Success: S_OK. pszOut contains the string, pcchOut contains its length.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
2002-09-05 01:32:19 +02:00
|
|
|
*/
|
2003-07-19 05:07:41 +02:00
|
|
|
HRESULT WINAPI AssocQueryStringA(ASSOCF cfFlags, ASSOCSTR str, LPCSTR pszAssoc,
|
2002-09-05 01:32:19 +02:00
|
|
|
LPCSTR pszExtra, LPSTR pszOut, DWORD *pcchOut)
|
|
|
|
{
|
|
|
|
WCHAR szAssocW[MAX_PATH], *lpszAssocW = NULL;
|
|
|
|
WCHAR szExtraW[MAX_PATH], *lpszExtraW = NULL;
|
|
|
|
HRESULT hRet = E_OUTOFMEMORY;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(0x%8x,0x%8x,%s,%s,%p,%p)\n", cfFlags, str, debugstr_a(pszAssoc),
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_a(pszExtra), pszOut, pcchOut);
|
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
if (!pcchOut)
|
2008-10-11 07:21:25 +02:00
|
|
|
hRet = E_UNEXPECTED;
|
2002-09-05 01:32:19 +02:00
|
|
|
else if (SHLWAPI_ParamAToW(pszAssoc, szAssocW, MAX_PATH, &lpszAssocW) &&
|
|
|
|
SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
|
|
|
|
{
|
|
|
|
WCHAR szReturnW[MAX_PATH], *lpszReturnW = szReturnW;
|
|
|
|
DWORD dwLenOut = *pcchOut;
|
|
|
|
|
|
|
|
if (dwLenOut >= MAX_PATH)
|
2004-07-04 02:06:29 +02:00
|
|
|
lpszReturnW = HeapAlloc(GetProcessHeap(), 0,
|
2002-09-05 01:32:19 +02:00
|
|
|
(dwLenOut + 1) * sizeof(WCHAR));
|
2008-10-17 16:36:59 +02:00
|
|
|
else
|
|
|
|
dwLenOut = sizeof(szReturnW) / sizeof(szReturnW[0]);
|
2002-09-05 01:32:19 +02:00
|
|
|
|
|
|
|
if (!lpszReturnW)
|
|
|
|
hRet = E_OUTOFMEMORY;
|
|
|
|
else
|
|
|
|
{
|
2003-07-19 05:07:41 +02:00
|
|
|
hRet = AssocQueryStringW(cfFlags, str, lpszAssocW, lpszExtraW,
|
2002-09-05 01:32:19 +02:00
|
|
|
lpszReturnW, &dwLenOut);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hRet))
|
2008-10-17 16:36:59 +02:00
|
|
|
dwLenOut = WideCharToMultiByte(CP_ACP, 0, lpszReturnW, -1,
|
|
|
|
pszOut, *pcchOut, NULL, NULL);
|
2002-09-05 01:32:19 +02:00
|
|
|
|
2008-10-17 16:36:59 +02:00
|
|
|
*pcchOut = dwLenOut;
|
2006-06-07 10:55:33 +02:00
|
|
|
if (lpszReturnW != szReturnW)
|
2002-09-05 01:32:19 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszReturnW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-07 10:55:33 +02:00
|
|
|
if (lpszAssocW != szAssocW)
|
2002-09-05 01:32:19 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszAssocW);
|
2006-06-07 10:55:33 +02:00
|
|
|
if (lpszExtraW != szExtraW)
|
2002-09-05 01:32:19 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszExtraW);
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* AssocQueryStringByKeyW [SHLWAPI.@]
|
2002-09-05 01:32:19 +02:00
|
|
|
*
|
|
|
|
* See AssocQueryStringByKeyA.
|
|
|
|
*/
|
2003-07-19 05:07:41 +02:00
|
|
|
HRESULT WINAPI AssocQueryStringByKeyW(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc,
|
2002-09-05 01:32:19 +02:00
|
|
|
LPCWSTR pszExtra, LPWSTR pszOut,
|
|
|
|
DWORD *pcchOut)
|
|
|
|
{
|
|
|
|
HRESULT hRet;
|
|
|
|
IQueryAssociations* lpAssoc;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc,
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_w(pszExtra), pszOut, pcchOut);
|
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
lpAssoc = IQueryAssociations_Constructor();
|
|
|
|
|
|
|
|
if (!lpAssoc)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2003-07-19 05:07:41 +02:00
|
|
|
cfFlags &= SHLWAPI_DEF_ASSOCF;
|
|
|
|
hRet = IQueryAssociations_Init(lpAssoc, cfFlags, 0, hkAssoc, NULL);
|
2002-09-05 01:32:19 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hRet))
|
2003-07-19 05:07:41 +02:00
|
|
|
hRet = IQueryAssociations_GetString(lpAssoc, cfFlags, str, pszExtra,
|
2002-09-05 01:32:19 +02:00
|
|
|
pszOut, pcchOut);
|
|
|
|
|
|
|
|
IQueryAssociations_Release(lpAssoc);
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2003-09-11 04:56:15 +02:00
|
|
|
* AssocQueryStringByKeyA [SHLWAPI.@]
|
2002-09-05 01:32:19 +02:00
|
|
|
*
|
|
|
|
* Get a file association string from the registry, given a starting key.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 05:07:41 +02:00
|
|
|
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
2002-09-05 01:32:19 +02:00
|
|
|
* str [I] Type of string to get
|
|
|
|
* hkAssoc [I] Key to search below
|
|
|
|
* pszExtra [I] Extra information about the string location
|
|
|
|
* pszOut [O] Destination for the association string
|
|
|
|
* pcchOut [O] Length of pszOut
|
|
|
|
*
|
|
|
|
* RETURNS
|
2003-07-19 05:07:41 +02:00
|
|
|
* Success: S_OK. pszOut contains the string, pcchOut contains its length.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
2002-09-05 01:32:19 +02:00
|
|
|
*/
|
2003-07-19 05:07:41 +02:00
|
|
|
HRESULT WINAPI AssocQueryStringByKeyA(ASSOCF cfFlags, ASSOCSTR str, HKEY hkAssoc,
|
2002-09-05 01:32:19 +02:00
|
|
|
LPCSTR pszExtra, LPSTR pszOut,
|
|
|
|
DWORD *pcchOut)
|
|
|
|
{
|
2007-01-20 18:29:29 +01:00
|
|
|
WCHAR szExtraW[MAX_PATH], *lpszExtraW = szExtraW;
|
2002-09-05 01:32:19 +02:00
|
|
|
WCHAR szReturnW[MAX_PATH], *lpszReturnW = szReturnW;
|
|
|
|
HRESULT hRet = E_OUTOFMEMORY;
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(0x%8x,0x%8x,%p,%s,%p,%p)\n", cfFlags, str, hkAssoc,
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_a(pszExtra), pszOut, pcchOut);
|
|
|
|
|
2002-09-05 01:32:19 +02:00
|
|
|
if (!pcchOut)
|
|
|
|
hRet = E_INVALIDARG;
|
|
|
|
else if (SHLWAPI_ParamAToW(pszExtra, szExtraW, MAX_PATH, &lpszExtraW))
|
|
|
|
{
|
|
|
|
DWORD dwLenOut = *pcchOut;
|
|
|
|
if (dwLenOut >= MAX_PATH)
|
2004-07-04 02:06:29 +02:00
|
|
|
lpszReturnW = HeapAlloc(GetProcessHeap(), 0,
|
2002-09-05 01:32:19 +02:00
|
|
|
(dwLenOut + 1) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
if (lpszReturnW)
|
|
|
|
{
|
2003-07-19 05:07:41 +02:00
|
|
|
hRet = AssocQueryStringByKeyW(cfFlags, str, hkAssoc, lpszExtraW,
|
2002-09-05 01:32:19 +02:00
|
|
|
lpszReturnW, &dwLenOut);
|
|
|
|
|
|
|
|
if (SUCCEEDED(hRet))
|
|
|
|
WideCharToMultiByte(CP_ACP,0,szReturnW,-1,pszOut,dwLenOut,0,0);
|
|
|
|
*pcchOut = dwLenOut;
|
|
|
|
|
|
|
|
if (lpszReturnW != szReturnW)
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpszReturnW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-07 10:55:33 +02:00
|
|
|
if (lpszExtraW != szExtraW)
|
2002-09-05 01:32:19 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszExtraW);
|
|
|
|
return hRet;
|
|
|
|
}
|
2003-07-19 05:07:41 +02:00
|
|
|
|
2003-07-22 01:42:24 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* AssocIsDangerous (SHLWAPI.@)
|
2004-02-10 03:22:17 +01:00
|
|
|
*
|
|
|
|
* Determine if a file association is dangerous (potentially malware).
|
|
|
|
*
|
|
|
|
* PARAMS
|
2004-03-02 21:55:57 +01:00
|
|
|
* lpszAssoc [I] Name of file or file extension to check.
|
2004-02-10 03:22:17 +01:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE, if lpszAssoc may potentially be malware (executable),
|
|
|
|
* FALSE, Otherwise.
|
2003-07-22 01:42:24 +02:00
|
|
|
*/
|
2004-02-10 03:22:17 +01:00
|
|
|
BOOL WINAPI AssocIsDangerous(LPCWSTR lpszAssoc)
|
2003-07-22 01:42:24 +02:00
|
|
|
{
|
2004-02-10 03:22:17 +01:00
|
|
|
FIXME("%s\n", debugstr_w(lpszAssoc));
|
|
|
|
return FALSE;
|
2003-07-22 01:42:24 +02:00
|
|
|
}
|
|
|
|
|
2003-07-19 05:07:41 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_QueryInterface {SHLWAPI}
|
|
|
|
*
|
|
|
|
* See IUnknown_QueryInterface.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IQueryAssociations_fnQueryInterface(
|
|
|
|
IQueryAssociations* iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppvObj)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
2003-07-19 05:07:41 +02:00
|
|
|
|
|
|
|
TRACE("(%p,%s,%p)\n",This, debugstr_guid(riid), ppvObj);
|
|
|
|
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IQueryAssociations))
|
|
|
|
{
|
2009-01-22 09:52:44 +01:00
|
|
|
*ppvObj = This;
|
2003-07-19 05:07:41 +02:00
|
|
|
|
|
|
|
IQueryAssociations_AddRef((IQueryAssociations*)*ppvObj);
|
|
|
|
TRACE("Returning IQueryAssociations (%p)\n", *ppvObj);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
TRACE("Returning E_NOINTERFACE\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_AddRef {SHLWAPI}
|
|
|
|
*
|
|
|
|
* See IUnknown_AddRef.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations *iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
2005-01-12 20:29:43 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n",This, refCount - 1);
|
2003-07-19 05:07:41 +02:00
|
|
|
|
2005-01-12 20:29:43 +01:00
|
|
|
return refCount;
|
2003-07-19 05:07:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_Release {SHLWAPI}
|
|
|
|
*
|
|
|
|
* See IUnknown_Release.
|
|
|
|
*/
|
|
|
|
static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations *iface)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
2005-01-12 20:29:43 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
2003-07-19 05:07:41 +02:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n",This, refCount + 1);
|
2003-07-19 05:07:41 +02:00
|
|
|
|
2005-01-12 20:29:43 +01:00
|
|
|
if (!refCount)
|
2003-07-19 05:07:41 +02:00
|
|
|
{
|
|
|
|
TRACE("Destroying IQueryAssociations (%p)\n", This);
|
2008-10-11 08:34:23 +02:00
|
|
|
RegCloseKey(This->hkeySource);
|
|
|
|
RegCloseKey(This->hkeyProgID);
|
2003-07-19 05:07:41 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2005-01-12 20:29:43 +01:00
|
|
|
|
|
|
|
return refCount;
|
2003-07-19 05:07:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_Init {SHLWAPI}
|
|
|
|
*
|
|
|
|
* Initialise an IQueryAssociations object.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-09-11 04:56:15 +02:00
|
|
|
* iface [I] IQueryAssociations interface to initialise
|
|
|
|
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
2008-07-06 20:04:34 +02:00
|
|
|
* pszAssoc [I] String for the root key name, or NULL if hkeyProgid is given
|
2003-09-11 04:56:15 +02:00
|
|
|
* hkeyProgid [I] Handle for the root key, or NULL if pszAssoc is given
|
|
|
|
* hWnd [I] Reserved, must be NULL.
|
2003-07-19 05:07:41 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. iface is initialised with the parameters given.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IQueryAssociations_fnInit(
|
|
|
|
IQueryAssociations *iface,
|
|
|
|
ASSOCF cfFlags,
|
|
|
|
LPCWSTR pszAssoc,
|
2003-09-11 04:56:15 +02:00
|
|
|
HKEY hkeyProgid,
|
2003-07-19 05:07:41 +02:00
|
|
|
HWND hWnd)
|
|
|
|
{
|
2003-09-11 04:56:15 +02:00
|
|
|
static const WCHAR szProgID[] = {'P','r','o','g','I','D',0};
|
2004-09-06 22:34:29 +02:00
|
|
|
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
2008-10-11 07:21:25 +02:00
|
|
|
LONG ret;
|
2003-09-11 04:56:15 +02:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
TRACE("(%p)->(%d,%s,%p,%p)\n", iface,
|
2003-09-11 04:56:15 +02:00
|
|
|
cfFlags,
|
|
|
|
debugstr_w(pszAssoc),
|
|
|
|
hkeyProgid,
|
|
|
|
hWnd);
|
|
|
|
if (hWnd != NULL)
|
|
|
|
FIXME("hwnd != NULL not supported\n");
|
|
|
|
if (cfFlags != 0)
|
2006-10-06 12:43:28 +02:00
|
|
|
FIXME("unsupported flags: %x\n", cfFlags);
|
2003-09-11 04:56:15 +02:00
|
|
|
if (pszAssoc != NULL)
|
|
|
|
{
|
2008-10-11 07:21:25 +02:00
|
|
|
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT,
|
|
|
|
pszAssoc,
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&This->hkeySource);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
return E_FAIL;
|
2003-09-11 04:56:15 +02:00
|
|
|
/* if this is not a prog id */
|
|
|
|
if ((*pszAssoc == '.') || (*pszAssoc == '{'))
|
|
|
|
{
|
2008-10-11 07:21:25 +02:00
|
|
|
RegOpenKeyExW(This->hkeySource,
|
|
|
|
szProgID,
|
|
|
|
0,
|
|
|
|
KEY_READ,
|
|
|
|
&This->hkeyProgID);
|
2003-09-11 04:56:15 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
This->hkeyProgID = This->hkeySource;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else if (hkeyProgid != NULL)
|
|
|
|
{
|
|
|
|
This->hkeyProgID = hkeyProgid;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
2008-10-11 07:21:25 +02:00
|
|
|
return E_INVALIDARG;
|
2003-07-19 05:07:41 +02:00
|
|
|
}
|
|
|
|
|
2008-10-11 08:34:04 +02:00
|
|
|
static HRESULT ASSOC_GetValue(HKEY hkey, WCHAR ** pszText)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
LONG ret;
|
|
|
|
|
|
|
|
assert(pszText);
|
|
|
|
ret = RegQueryValueExW(hkey, NULL, 0, NULL, NULL, &len);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
|
|
|
if (!len)
|
|
|
|
return E_FAIL;
|
|
|
|
*pszText = HeapAlloc(GetProcessHeap(), 0, len);
|
|
|
|
if (!*pszText)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
ret = RegQueryValueExW(hkey, NULL, 0, NULL, (LPBYTE)*pszText,
|
|
|
|
&len);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, *pszText);
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-20 17:19:21 +01:00
|
|
|
static HRESULT ASSOC_GetCommand(IQueryAssociationsImpl *This,
|
|
|
|
LPCWSTR pszExtra, WCHAR **ppszCommand)
|
2008-10-14 03:07:15 +02:00
|
|
|
{
|
|
|
|
HKEY hkeyCommand;
|
|
|
|
HKEY hkeyFile;
|
|
|
|
HKEY hkeyShell;
|
|
|
|
HKEY hkeyVerb;
|
|
|
|
HRESULT hr;
|
|
|
|
LONG ret;
|
2008-10-15 00:13:44 +02:00
|
|
|
WCHAR * pszExtraFromReg = NULL;
|
2008-10-14 03:07:15 +02:00
|
|
|
WCHAR * pszFileType;
|
|
|
|
static const WCHAR commandW[] = { 'c','o','m','m','a','n','d',0 };
|
|
|
|
static const WCHAR shellW[] = { 's','h','e','l','l',0 };
|
|
|
|
|
|
|
|
hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pszFileType);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
|
|
|
|
|
|
|
ret = RegOpenKeyExW(hkeyFile, shellW, 0, KEY_READ, &hkeyShell);
|
|
|
|
RegCloseKey(hkeyFile);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
|
|
|
|
|
|
|
if (!pszExtra)
|
|
|
|
{
|
|
|
|
hr = ASSOC_GetValue(hkeyShell, &pszExtraFromReg);
|
2008-10-14 16:32:33 +02:00
|
|
|
/* if no default action */
|
|
|
|
if (hr == E_FAIL || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND))
|
|
|
|
{
|
|
|
|
DWORD rlen;
|
|
|
|
ret = RegQueryInfoKeyW(hkeyShell, 0, 0, 0, 0, &rlen, 0, 0, 0, 0, 0, 0);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
RegCloseKey(hkeyShell);
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
|
|
|
}
|
|
|
|
rlen++;
|
|
|
|
pszExtraFromReg = HeapAlloc(GetProcessHeap(), 0, rlen * sizeof(WCHAR));
|
|
|
|
if (!pszExtraFromReg)
|
|
|
|
{
|
|
|
|
RegCloseKey(hkeyShell);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
ret = RegEnumKeyExW(hkeyShell, 0, pszExtraFromReg, &rlen, 0, NULL, NULL, NULL);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
RegCloseKey(hkeyShell);
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FAILED(hr))
|
2008-10-14 03:07:15 +02:00
|
|
|
{
|
|
|
|
RegCloseKey(hkeyShell);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = RegOpenKeyExW(hkeyShell, pszExtra ? pszExtra : pszExtraFromReg, 0,
|
|
|
|
KEY_READ, &hkeyVerb);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pszExtraFromReg);
|
|
|
|
RegCloseKey(hkeyShell);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
|
|
|
|
|
|
|
ret = RegOpenKeyExW(hkeyVerb, commandW, 0, KEY_READ, &hkeyCommand);
|
|
|
|
RegCloseKey(hkeyVerb);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
2009-01-20 17:19:21 +01:00
|
|
|
hr = ASSOC_GetValue(hkeyCommand, ppszCommand);
|
2008-10-14 03:07:15 +02:00
|
|
|
RegCloseKey(hkeyCommand);
|
2009-01-20 17:19:21 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ASSOC_GetExecutable(IQueryAssociationsImpl *This,
|
|
|
|
LPCWSTR pszExtra, LPWSTR path,
|
|
|
|
DWORD pathlen, DWORD *len)
|
|
|
|
{
|
|
|
|
WCHAR *pszCommand;
|
|
|
|
WCHAR *pszStart;
|
|
|
|
WCHAR *pszEnd;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
assert(len);
|
|
|
|
|
|
|
|
hr = ASSOC_GetCommand(This, pszExtra, &pszCommand);
|
2008-10-14 03:07:15 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
/* cleanup pszCommand */
|
|
|
|
if (pszCommand[0] == '"')
|
|
|
|
{
|
|
|
|
pszStart = pszCommand + 1;
|
|
|
|
pszEnd = strchrW(pszStart, '"');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pszStart = pszCommand;
|
|
|
|
pszEnd = strchrW(pszStart, ' ');
|
|
|
|
}
|
|
|
|
if (pszEnd)
|
|
|
|
*pszEnd = 0;
|
|
|
|
|
|
|
|
*len = SearchPathW(NULL, pszStart, NULL, pathlen, path, NULL);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pszCommand);
|
|
|
|
if (!*len)
|
|
|
|
return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-14 03:09:28 +02:00
|
|
|
static HRESULT ASSOC_ReturnData(LPWSTR out, DWORD *outlen, LPCWSTR data,
|
|
|
|
DWORD datalen)
|
|
|
|
{
|
|
|
|
assert(outlen);
|
|
|
|
|
|
|
|
if (out)
|
|
|
|
{
|
|
|
|
if (*outlen < datalen)
|
|
|
|
{
|
|
|
|
*outlen = datalen;
|
|
|
|
return E_POINTER;
|
|
|
|
}
|
|
|
|
*outlen = datalen;
|
|
|
|
lstrcpynW(out, data, datalen);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*outlen = datalen;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-19 05:07:41 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_GetString {SHLWAPI}
|
|
|
|
*
|
|
|
|
* Get a file association string from the registry.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* iface [I] IQueryAssociations interface to query
|
|
|
|
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
|
|
|
* str [I] Type of string to get (ASSOCSTR enum from "shlwapi.h")
|
|
|
|
* pszExtra [I] Extra information about the string location
|
|
|
|
* pszOut [O] Destination for the association string
|
|
|
|
* pcchOut [I/O] Length of pszOut
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. pszOut contains the string, pcchOut contains its length.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IQueryAssociations_fnGetString(
|
|
|
|
IQueryAssociations *iface,
|
|
|
|
ASSOCF cfFlags,
|
|
|
|
ASSOCSTR str,
|
|
|
|
LPCWSTR pszExtra,
|
|
|
|
LPWSTR pszOut,
|
|
|
|
DWORD *pcchOut)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
2008-10-11 08:34:04 +02:00
|
|
|
const ASSOCF cfUnimplemented = ~(0);
|
2008-10-14 03:07:15 +02:00
|
|
|
DWORD len = 0;
|
2008-10-11 08:34:04 +02:00
|
|
|
HRESULT hr;
|
|
|
|
WCHAR path[MAX_PATH];
|
|
|
|
|
|
|
|
TRACE("(%p,0x%8x,0x%8x,%s,%p,%p)\n", This, cfFlags, str,
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_w(pszExtra), pszOut, pcchOut);
|
2008-10-11 08:34:04 +02:00
|
|
|
|
|
|
|
if (cfFlags & cfUnimplemented)
|
|
|
|
FIXME("%08x: unimplemented flags!\n", cfFlags & cfUnimplemented);
|
|
|
|
|
|
|
|
if (!pcchOut)
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
|
|
|
|
switch (str)
|
|
|
|
{
|
2009-01-20 17:19:21 +01:00
|
|
|
case ASSOCSTR_COMMAND:
|
|
|
|
{
|
|
|
|
WCHAR *command;
|
|
|
|
hr = ASSOC_GetCommand(This, pszExtra, &command);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = ASSOC_ReturnData(pszOut, pcchOut, command, strlenW(command) + 1);
|
|
|
|
HeapFree(GetProcessHeap(), 0, command);
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-10-11 08:34:04 +02:00
|
|
|
case ASSOCSTR_EXECUTABLE:
|
|
|
|
{
|
2008-10-14 03:07:15 +02:00
|
|
|
hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len);
|
2008-10-11 08:34:04 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
len++;
|
2008-10-14 03:09:28 +02:00
|
|
|
return ASSOC_ReturnData(pszOut, pcchOut, path, len);
|
2008-10-11 08:34:04 +02:00
|
|
|
}
|
|
|
|
|
2009-01-19 17:32:43 +01:00
|
|
|
case ASSOCSTR_FRIENDLYDOCNAME:
|
|
|
|
{
|
|
|
|
WCHAR *pszFileType;
|
|
|
|
DWORD ret;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
size = 0;
|
|
|
|
ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WCHAR *docName = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (docName)
|
|
|
|
{
|
|
|
|
ret = RegGetValueW(HKEY_CLASSES_ROOT, pszFileType, NULL, RRF_RT_REG_SZ, NULL, docName, &size);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
hr = ASSOC_ReturnData(pszOut, pcchOut, docName, strlenW(docName) + 1);
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(ret);
|
|
|
|
HeapFree(GetProcessHeap(), 0, docName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(ret);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pszFileType);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-10-14 03:15:54 +02:00
|
|
|
case ASSOCSTR_FRIENDLYAPPNAME:
|
|
|
|
{
|
|
|
|
PVOID verinfoW = NULL;
|
|
|
|
DWORD size, retval = 0;
|
|
|
|
UINT flen;
|
|
|
|
WCHAR *bufW;
|
|
|
|
static const WCHAR translationW[] = {
|
|
|
|
'\\','V','a','r','F','i','l','e','I','n','f','o',
|
|
|
|
'\\','T','r','a','n','s','l','a','t','i','o','n',0
|
|
|
|
};
|
|
|
|
static const WCHAR fileDescFmtW[] = {
|
|
|
|
'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
|
|
|
|
'\\','%','0','4','x','%','0','4','x',
|
|
|
|
'\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0
|
|
|
|
};
|
|
|
|
WCHAR fileDescW[41];
|
|
|
|
|
|
|
|
hr = ASSOC_GetExecutable(This, pszExtra, path, MAX_PATH, &len);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
retval = GetFileVersionInfoSizeW(path, &size);
|
|
|
|
if (!retval)
|
|
|
|
goto get_friendly_name_fail;
|
|
|
|
verinfoW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, retval);
|
|
|
|
if (!verinfoW)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
if (!GetFileVersionInfoW(path, 0, retval, verinfoW))
|
|
|
|
goto get_friendly_name_fail;
|
|
|
|
if (VerQueryValueW(verinfoW, translationW, (LPVOID *)&bufW, &flen))
|
|
|
|
{
|
2008-11-12 21:22:09 +01:00
|
|
|
UINT i;
|
2008-10-14 03:15:54 +02:00
|
|
|
DWORD *langCodeDesc = (DWORD *)bufW;
|
|
|
|
for (i = 0; i < flen / sizeof(DWORD); i++)
|
|
|
|
{
|
|
|
|
sprintfW(fileDescW, fileDescFmtW, LOWORD(langCodeDesc[i]),
|
|
|
|
HIWORD(langCodeDesc[i]));
|
|
|
|
if (VerQueryValueW(verinfoW, fileDescW, (LPVOID *)&bufW, &flen))
|
|
|
|
{
|
|
|
|
/* Does strlenW(bufW) == 0 mean we use the filename? */
|
|
|
|
len = strlenW(bufW) + 1;
|
|
|
|
TRACE("found FileDescription: %s\n", debugstr_w(bufW));
|
|
|
|
return ASSOC_ReturnData(pszOut, pcchOut, bufW, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
get_friendly_name_fail:
|
|
|
|
PathRemoveExtensionW(path);
|
|
|
|
PathStripPathW(path);
|
|
|
|
TRACE("using filename: %s\n", debugstr_w(path));
|
|
|
|
return ASSOC_ReturnData(pszOut, pcchOut, path, strlenW(path) + 1);
|
|
|
|
}
|
|
|
|
|
2009-01-18 13:25:08 +01:00
|
|
|
case ASSOCSTR_CONTENTTYPE:
|
|
|
|
{
|
|
|
|
static const WCHAR Content_TypeW[] = {'C','o','n','t','e','n','t',' ','T','y','p','e',0};
|
|
|
|
WCHAR *contentType;
|
|
|
|
DWORD ret;
|
|
|
|
DWORD size;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
ret = RegGetValueW(This->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, NULL, &size);
|
|
|
|
if (ret != ERROR_SUCCESS)
|
|
|
|
return HRESULT_FROM_WIN32(ret);
|
|
|
|
contentType = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (contentType != NULL)
|
|
|
|
{
|
|
|
|
ret = RegGetValueW(This->hkeySource, NULL, Content_TypeW, RRF_RT_REG_SZ, NULL, contentType, &size);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
hr = ASSOC_ReturnData(pszOut, pcchOut, contentType, strlenW(contentType) + 1);
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(ret);
|
|
|
|
HeapFree(GetProcessHeap(), 0, contentType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2009-01-19 17:32:43 +01:00
|
|
|
case ASSOCSTR_DEFAULTICON:
|
|
|
|
{
|
|
|
|
static const WCHAR DefaultIconW[] = {'D','e','f','a','u','l','t','I','c','o','n',0};
|
|
|
|
WCHAR *pszFileType;
|
|
|
|
DWORD ret;
|
|
|
|
DWORD size;
|
|
|
|
HKEY hkeyFile;
|
|
|
|
|
|
|
|
hr = ASSOC_GetValue(This->hkeySource, &pszFileType);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
ret = RegOpenKeyExW(HKEY_CLASSES_ROOT, pszFileType, 0, KEY_READ, &hkeyFile);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
size = 0;
|
|
|
|
ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, NULL, &size);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WCHAR *icon = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
if (icon)
|
|
|
|
{
|
|
|
|
ret = RegGetValueW(hkeyFile, DefaultIconW, NULL, RRF_RT_REG_SZ, NULL, icon, &size);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
hr = ASSOC_ReturnData(pszOut, pcchOut, icon, strlenW(icon) + 1);
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(ret);
|
|
|
|
HeapFree(GetProcessHeap(), 0, icon);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(ret);
|
|
|
|
RegCloseKey(hkeyFile);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hr = HRESULT_FROM_WIN32(ret);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pszFileType);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-10-11 08:34:04 +02:00
|
|
|
default:
|
|
|
|
FIXME("assocstr %d unimplemented!\n", str);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2003-07-19 05:07:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_GetKey {SHLWAPI}
|
|
|
|
*
|
|
|
|
* Get a file association key from the registry.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* iface [I] IQueryAssociations interface to query
|
|
|
|
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
|
|
|
* assockey [I] Type of key to get (ASSOCKEY enum from "shlwapi.h")
|
|
|
|
* pszExtra [I] Extra information about the key location
|
|
|
|
* phkeyOut [O] Destination for the association key
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. phkeyOut contains a handle to the key.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IQueryAssociations_fnGetKey(
|
|
|
|
IQueryAssociations *iface,
|
|
|
|
ASSOCF cfFlags,
|
|
|
|
ASSOCKEY assockey,
|
|
|
|
LPCWSTR pszExtra,
|
|
|
|
HKEY *phkeyOut)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
2003-07-19 05:07:41 +02:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
FIXME("(%p,0x%8x,0x%8x,%s,%p)-stub!\n", This, cfFlags, assockey,
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_w(pszExtra), phkeyOut);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_GetData {SHLWAPI}
|
|
|
|
*
|
|
|
|
* Get the data for a file association key from the registry.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* iface [I] IQueryAssociations interface to query
|
|
|
|
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
|
|
|
* assocdata [I] Type of data to get (ASSOCDATA enum from "shlwapi.h")
|
|
|
|
* pszExtra [I] Extra information about the data location
|
|
|
|
* pvOut [O] Destination for the association key
|
|
|
|
* pcbOut [I/O] Size of pvOut
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. pszOut contains the data, pcbOut contains its length.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IQueryAssociations_fnGetData(
|
|
|
|
IQueryAssociations *iface,
|
|
|
|
ASSOCF cfFlags,
|
|
|
|
ASSOCDATA assocdata,
|
|
|
|
LPCWSTR pszExtra,
|
|
|
|
LPVOID pvOut,
|
|
|
|
DWORD *pcbOut)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
2003-07-19 05:07:41 +02:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
FIXME("(%p,0x%8x,0x%8x,%s,%p,%p)-stub!\n", This, cfFlags, assocdata,
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_w(pszExtra), pvOut, pcbOut);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IQueryAssociations_GetEnum {SHLWAPI}
|
|
|
|
*
|
|
|
|
* Not yet implemented in native Win32.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* iface [I] IQueryAssociations interface to query
|
|
|
|
* cfFlags [I] ASSOCF_ flags from "shlwapi.h"
|
|
|
|
* assocenum [I] Type of enum to get (ASSOCENUM enum from "shlwapi.h")
|
|
|
|
* pszExtra [I] Extra information about the enum location
|
|
|
|
* riid [I] REFIID to look for
|
|
|
|
* ppvOut [O] Destination for the interface.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK.
|
|
|
|
* Failure: An HRESULT error code indicating the error.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Presumably this function returns an enumerator object.
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IQueryAssociations_fnGetEnum(
|
|
|
|
IQueryAssociations *iface,
|
|
|
|
ASSOCF cfFlags,
|
|
|
|
ASSOCENUM assocenum,
|
|
|
|
LPCWSTR pszExtra,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppvOut)
|
|
|
|
{
|
2004-09-06 22:34:29 +02:00
|
|
|
IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface;
|
2003-07-19 05:07:41 +02:00
|
|
|
|
2006-10-06 12:43:28 +02:00
|
|
|
FIXME("(%p,0x%8x,0x%8x,%s,%s,%p)-stub!\n", This, cfFlags, assocenum,
|
2003-07-19 05:07:41 +02:00
|
|
|
debugstr_w(pszExtra), debugstr_guid(riid), ppvOut);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2005-06-06 21:50:35 +02:00
|
|
|
static const IQueryAssociationsVtbl IQueryAssociations_vtbl =
|
2003-07-19 05:07:41 +02:00
|
|
|
{
|
|
|
|
IQueryAssociations_fnQueryInterface,
|
|
|
|
IQueryAssociations_fnAddRef,
|
|
|
|
IQueryAssociations_fnRelease,
|
|
|
|
IQueryAssociations_fnInit,
|
|
|
|
IQueryAssociations_fnGetString,
|
|
|
|
IQueryAssociations_fnGetKey,
|
|
|
|
IQueryAssociations_fnGetData,
|
|
|
|
IQueryAssociations_fnGetEnum
|
|
|
|
};
|