2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Registry namespace extension
4 * FILE: dll/win32/shell32/extracticon.c
5 * PURPOSE: Icon extraction
7 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org)
12 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
21 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
22 public IDefaultExtractIconInit
,
29 struct IconLocation defaultIcon
;
30 struct IconLocation normalIcon
;
31 struct IconLocation openIcon
;
32 struct IconLocation shortcutIcon
;
37 // IDefaultExtractIconInit
38 virtual HRESULT STDMETHODCALLTYPE
SetDefaultIcon(LPCWSTR pszFile
, int iIcon
);
39 virtual HRESULT STDMETHODCALLTYPE
SetFlags(UINT uFlags
);
40 virtual HRESULT STDMETHODCALLTYPE
SetKey(HKEY hkey
);
41 virtual HRESULT STDMETHODCALLTYPE
SetNormalIcon(LPCWSTR pszFile
, int iIcon
);
42 virtual HRESULT STDMETHODCALLTYPE
SetOpenIcon(LPCWSTR pszFile
, int iIcon
);
43 virtual HRESULT STDMETHODCALLTYPE
SetShortcutIcon(LPCWSTR pszFile
, int iIcon
);
46 virtual HRESULT STDMETHODCALLTYPE
GetIconLocation(UINT uFlags
, LPWSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
);
47 virtual HRESULT STDMETHODCALLTYPE
Extract(LPCWSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
);
50 virtual HRESULT STDMETHODCALLTYPE
GetIconLocation(UINT uFlags
, LPSTR szIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
);
51 virtual HRESULT STDMETHODCALLTYPE
Extract(LPCSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
);
54 virtual HRESULT STDMETHODCALLTYPE
GetClassID(CLSID
*pClassID
);
55 virtual HRESULT STDMETHODCALLTYPE
IsDirty();
58 virtual HRESULT STDMETHODCALLTYPE
Load(LPCOLESTR pszFileName
, DWORD dwMode
);
59 virtual HRESULT STDMETHODCALLTYPE
Save(LPCOLESTR pszFileName
, BOOL fRemember
);
60 virtual HRESULT STDMETHODCALLTYPE
SaveCompleted(LPCOLESTR pszFileName
);
61 virtual HRESULT STDMETHODCALLTYPE
GetCurFile(LPOLESTR
*ppszFileName
);
63 BEGIN_COM_MAP(CExtractIcon
)
64 COM_INTERFACE_ENTRY_IID(IID_IDefaultExtractIconInit
, IDefaultExtractIconInit
)
65 COM_INTERFACE_ENTRY_IID(IID_IExtractIconW
, IExtractIconW
)
66 COM_INTERFACE_ENTRY_IID(IID_IExtractIconA
, IExtractIconA
)
67 COM_INTERFACE_ENTRY_IID(IID_IPersist
, IPersist
)
68 COM_INTERFACE_ENTRY_IID(IID_IPersistFile
, IPersistFile
)
79 CoTaskMemFree(*Destination
);
81 cb
= (wcslen(Source
) + 1) * sizeof(WCHAR
);
82 *Destination
= (LPWSTR
)CoTaskMemAlloc(cb
);
85 CopyMemory(*Destination
, Source
, cb
);
88 CExtractIcon::CExtractIcon()
91 memset(&defaultIcon
, 0, sizeof(defaultIcon
));
92 memset(&normalIcon
, 0, sizeof(normalIcon
));
93 memset(&openIcon
, 0, sizeof(openIcon
));
94 memset(&shortcutIcon
, 0, sizeof(shortcutIcon
));
97 CExtractIcon::~CExtractIcon()
99 if (defaultIcon
.file
) CoTaskMemFree(defaultIcon
.file
);
100 if (normalIcon
.file
) CoTaskMemFree(normalIcon
.file
);
101 if (openIcon
.file
) CoTaskMemFree(openIcon
.file
);
102 if (shortcutIcon
.file
) CoTaskMemFree(shortcutIcon
.file
);
105 HRESULT STDMETHODCALLTYPE
CExtractIcon::SetDefaultIcon(
109 TRACE("(%p, %s, %d)\n", this, debugstr_w(pszFile
), iIcon
);
111 DuplicateString(pszFile
, &defaultIcon
.file
);
112 if (!defaultIcon
.file
)
113 return E_OUTOFMEMORY
;
114 defaultIcon
.index
= iIcon
;
118 HRESULT STDMETHODCALLTYPE
CExtractIcon::SetFlags(
121 TRACE("(%p, 0x%x)\n", this, uFlags
);
127 HRESULT STDMETHODCALLTYPE
CExtractIcon::SetKey(
130 FIXME("(%p, %p)\n", this, hkey
);
135 HRESULT STDMETHODCALLTYPE
CExtractIcon::SetNormalIcon(
139 TRACE("(%p, %s, %d)\n", this, debugstr_w(pszFile
), iIcon
);
141 DuplicateString(pszFile
, &normalIcon
.file
);
142 if (!normalIcon
.file
)
143 return E_OUTOFMEMORY
;
144 normalIcon
.index
= iIcon
;
148 HRESULT STDMETHODCALLTYPE
CExtractIcon::SetOpenIcon(
152 TRACE("(%p, %s, %d)\n", this, debugstr_w(pszFile
), iIcon
);
154 DuplicateString(pszFile
, &openIcon
.file
);
156 return E_OUTOFMEMORY
;
157 openIcon
.index
= iIcon
;
161 HRESULT STDMETHODCALLTYPE
CExtractIcon::SetShortcutIcon(
165 TRACE("(%p, %s, %d)\n", this, debugstr_w(pszFile
), iIcon
);
167 DuplicateString(pszFile
, &shortcutIcon
.file
);
168 if (!shortcutIcon
.file
)
169 return E_OUTOFMEMORY
;
170 shortcutIcon
.index
= iIcon
;
174 HRESULT STDMETHODCALLTYPE
CExtractIcon::GetIconLocation(
181 const struct IconLocation
*icon
= NULL
;
184 TRACE("(%p, 0x%x, %s, 0x%x, %p, %p)\n", this, uFlags
, debugstr_w(szIconFile
), cchMax
, piIndex
, pwFlags
);
186 if (!piIndex
|| !pwFlags
)
189 if (uFlags
& GIL_DEFAULTICON
)
190 icon
= defaultIcon
.file
? &defaultIcon
: &normalIcon
;
191 else if (uFlags
& GIL_FORSHORTCUT
)
192 icon
= shortcutIcon
.file
? &shortcutIcon
: &normalIcon
;
193 else if (uFlags
& GIL_OPENICON
)
194 icon
= openIcon
.file
? &openIcon
: &normalIcon
;
201 cb
= wcslen(icon
->file
) + 1;
202 if (cchMax
< (UINT
)cb
)
204 CopyMemory(szIconFile
, icon
->file
, cb
* sizeof(WCHAR
));
205 *piIndex
= icon
->index
;
210 HRESULT STDMETHODCALLTYPE
CExtractIcon::Extract(
217 TRACE("(%p, %s, %u, %p, %p, %u)\n", this, debugstr_w(pszFile
), nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
219 /* Nothing to do, ExtractIconW::GetIconLocation should be enough */
223 HRESULT STDMETHODCALLTYPE
CExtractIcon::GetIconLocation(
230 LPWSTR szIconFileW
= NULL
;
235 szIconFileW
= (LPWSTR
)CoTaskMemAlloc(cchMax
* sizeof(WCHAR
));
237 return E_OUTOFMEMORY
;
240 hr
= GetIconLocation(
241 uFlags
, szIconFileW
, cchMax
, piIndex
, pwFlags
);
242 if (SUCCEEDED(hr
) && cchMax
> 0)
243 if (0 == WideCharToMultiByte(CP_ACP
, 0, szIconFileW
, cchMax
, szIconFile
, cchMax
, NULL
, NULL
))
247 CoTaskMemFree(szIconFileW
);
251 HRESULT STDMETHODCALLTYPE
CExtractIcon::Extract(
258 LPWSTR pszFileW
= NULL
;
265 nLength
= MultiByteToWideChar(CP_ACP
, 0, pszFile
, -1, NULL
, 0);
268 pszFileW
= (LPWSTR
)CoTaskMemAlloc(nLength
* sizeof(WCHAR
));
270 return E_OUTOFMEMORY
;
271 if (!MultiByteToWideChar(CP_ACP
, 0, pszFile
, nLength
, pszFileW
, nLength
))
273 CoTaskMemFree(pszFileW
);
278 hr
= Extract(pszFileW
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
281 CoTaskMemFree(pszFileW
);
285 HRESULT STDMETHODCALLTYPE
CExtractIcon::GetClassID(
288 TRACE("(%p, %p)\n", this, pClassID
);
293 *pClassID
= GUID_NULL
;
297 HRESULT STDMETHODCALLTYPE
CExtractIcon::IsDirty()
299 FIXME("(%p)\n", this);
304 HRESULT STDMETHODCALLTYPE
CExtractIcon::Load(
305 LPCOLESTR pszFileName
,
308 FIXME("(%p, %s, %u)\n", this, debugstr_w(pszFileName
), dwMode
);
313 HRESULT STDMETHODCALLTYPE
CExtractIcon::Save(
314 LPCOLESTR pszFileName
,
317 FIXME("(%p, %s, %d)\n", this, debugstr_w(pszFileName
), fRemember
);
322 HRESULT STDMETHODCALLTYPE
CExtractIcon::SaveCompleted(
323 LPCOLESTR pszFileName
)
325 FIXME("(%p, %s)\n", this, debugstr_w(pszFileName
));
330 HRESULT STDMETHODCALLTYPE
CExtractIcon::GetCurFile(
331 LPOLESTR
*ppszFileName
)
333 FIXME("(%p, %p)\n", this, ppszFileName
);
338 HRESULT WINAPI
SHCreateDefaultExtractIcon(REFIID riid
, void **ppv
)
340 return ShellObjectCreator
<CExtractIcon
>(riid
, ppv
);