[SHELL32] -Simplify some coe in CShellLink.cpp

svn path=/trunk/; revision=75597
This commit is contained in:
Giannis Adamopoulos 2017-08-17 16:46:15 +00:00
parent 9d8fe6f238
commit e8f24951d6

View file

@ -1690,28 +1690,31 @@ HRESULT STDMETHODCALLTYPE CShellLink::GetIconLocation(LPWSTR pszIconPath, INT cc
return S_OK; return S_OK;
} }
static HRESULT SHELL_PidlGetIconLocationW(IShellFolder* psf, LPCITEMIDLIST pidl, static HRESULT SHELL_PidlGetIconLocationW(PCIDLIST_ABSOLUTE pidl,
UINT uFlags, PWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags) UINT uFlags, PWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
{ {
LPCITEMIDLIST pidlLast; LPCITEMIDLIST pidlLast;
CComPtr<IShellFolder> psf;
HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast); HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlLast);
if (SUCCEEDED(hr)) if (FAILED_UNEXPECTEDLY(hr))
{
CComPtr<IExtractIconW> pei;
hr = psf->GetUIObjectOf(0, 1, &pidlLast, IID_NULL_PPV_ARG(IExtractIconW, &pei));
if (SUCCEEDED(hr))
hr = pei->GetIconLocation(uFlags, pszIconFile, cchMax, piIndex, pwFlags);
psf->Release();
}
return hr; return hr;
CComPtr<IExtractIconW> pei;
hr = psf->GetUIObjectOf(0, 1, &pidlLast, IID_NULL_PPV_ARG(IExtractIconW, &pei));
if (FAILED_UNEXPECTEDLY(hr))
return hr;
hr = pei->GetIconLocation(uFlags, pszIconFile, cchMax, piIndex, pwFlags);
if (FAILED_UNEXPECTEDLY(hr))
return hr;
return S_OK;
} }
HRESULT STDMETHODCALLTYPE CShellLink::GetIconLocation(UINT uFlags, PWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags) HRESULT STDMETHODCALLTYPE CShellLink::GetIconLocation(UINT uFlags, PWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
{ {
HRESULT hr;
/* /*
* It is possible for a shell link to point to another shell link, * It is possible for a shell link to point to another shell link,
* and in particular there is the possibility to point to itself. * and in particular there is the possibility to point to itself.
@ -1731,15 +1734,10 @@ HRESULT STDMETHODCALLTYPE CShellLink::GetIconLocation(UINT uFlags, PWSTR pszIcon
uFlags |= GIL_FORSHORTCUT; uFlags |= GIL_FORSHORTCUT;
if (m_pPidl || m_sPath) if (m_pPidl || m_sPath)
{
CComPtr<IShellFolder> pdsk;
HRESULT hr = SHGetDesktopFolder(&pdsk);
if (SUCCEEDED(hr))
{ {
/* first look for an icon using the PIDL (if present) */ /* first look for an icon using the PIDL (if present) */
if (m_pPidl) if (m_pPidl)
hr = SHELL_PidlGetIconLocationW(pdsk, m_pPidl, uFlags, pszIconFile, cchMax, piIndex, pwFlags); hr = SHELL_PidlGetIconLocationW(m_pPidl, uFlags, pszIconFile, cchMax, piIndex, pwFlags);
else else
hr = E_FAIL; hr = E_FAIL;
@ -1748,17 +1746,19 @@ HRESULT STDMETHODCALLTYPE CShellLink::GetIconLocation(UINT uFlags, PWSTR pszIcon
if (FAILED(hr) && m_sPath) if (FAILED(hr) && m_sPath)
{ {
LPITEMIDLIST pidl; LPITEMIDLIST pidl;
CComPtr<IShellFolder> pdsk;
hr = SHGetDesktopFolder(&pdsk);
/* LPITEMIDLIST pidl = ILCreateFromPathW(sPath); */ /* LPITEMIDLIST pidl = ILCreateFromPathW(sPath); */
hr = pdsk->ParseDisplayName(0, NULL, m_sPath, NULL, &pidl, NULL); hr = pdsk->ParseDisplayName(0, NULL, m_sPath, NULL, &pidl, NULL);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = SHELL_PidlGetIconLocationW(pdsk, pidl, uFlags, pszIconFile, cchMax, piIndex, pwFlags); hr = SHELL_PidlGetIconLocationW(pidl, uFlags, pszIconFile, cchMax, piIndex, pwFlags);
SHFree(pidl); SHFree(pidl);
} }
} }
#endif #endif
}
return hr; return hr;
} }