Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenextracticon.cpp
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS Registry namespace extension 00004 * FILE: dll/win32/shell32/extracticon.c 00005 * PURPOSE: Icon extraction 00006 * 00007 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.org) 00008 */ 00009 00010 #include <precomp.h> 00011 00012 WINE_DEFAULT_DEBUG_CHANNEL(shell); 00013 00014 struct IconLocation 00015 { 00016 LPWSTR file; 00017 UINT index; 00018 }; 00019 00020 class IconExtraction : 00021 public CComObjectRootEx<CComMultiThreadModelNoCS>, 00022 public IDefaultExtractIconInit, 00023 public IExtractIconW, 00024 public IExtractIconA, 00025 public IPersistFile 00026 { 00027 private: 00028 UINT flags; 00029 struct IconLocation defaultIcon; 00030 struct IconLocation normalIcon; 00031 struct IconLocation openIcon; 00032 struct IconLocation shortcutIcon; 00033 public: 00034 IconExtraction(); 00035 ~IconExtraction(); 00036 00037 // IDefaultExtractIconInit 00038 virtual HRESULT STDMETHODCALLTYPE SetDefaultIcon(LPCWSTR pszFile, int iIcon); 00039 virtual HRESULT STDMETHODCALLTYPE SetFlags(UINT uFlags); 00040 virtual HRESULT STDMETHODCALLTYPE SetKey(HKEY hkey); 00041 virtual HRESULT STDMETHODCALLTYPE SetNormalIcon(LPCWSTR pszFile, int iIcon); 00042 virtual HRESULT STDMETHODCALLTYPE SetOpenIcon(LPCWSTR pszFile, int iIcon); 00043 virtual HRESULT STDMETHODCALLTYPE SetShortcutIcon(LPCWSTR pszFile, int iIcon); 00044 00045 // IExtractIconW 00046 virtual HRESULT STDMETHODCALLTYPE GetIconLocation(UINT uFlags, LPWSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags); 00047 virtual HRESULT STDMETHODCALLTYPE Extract(LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize); 00048 00049 // IExtractIconA 00050 virtual HRESULT STDMETHODCALLTYPE GetIconLocation(UINT uFlags, LPSTR szIconFile, UINT cchMax, int *piIndex, UINT *pwFlags); 00051 virtual HRESULT STDMETHODCALLTYPE Extract(LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize); 00052 00053 // IPersist 00054 virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID); 00055 virtual HRESULT STDMETHODCALLTYPE IsDirty(); 00056 00057 // IPersistFile 00058 virtual HRESULT STDMETHODCALLTYPE Load(LPCOLESTR pszFileName, DWORD dwMode); 00059 virtual HRESULT STDMETHODCALLTYPE Save(LPCOLESTR pszFileName, BOOL fRemember); 00060 virtual HRESULT STDMETHODCALLTYPE SaveCompleted(LPCOLESTR pszFileName); 00061 virtual HRESULT STDMETHODCALLTYPE GetCurFile(LPOLESTR *ppszFileName); 00062 00063 BEGIN_COM_MAP(IconExtraction) 00064 COM_INTERFACE_ENTRY_IID(IID_IDefaultExtractIconInit, IDefaultExtractIconInit) 00065 COM_INTERFACE_ENTRY_IID(IID_IExtractIconW, IExtractIconW) 00066 COM_INTERFACE_ENTRY_IID(IID_IExtractIconA, IExtractIconA) 00067 COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist) 00068 COM_INTERFACE_ENTRY_IID(IID_IPersistFile, IPersistFile) 00069 END_COM_MAP() 00070 }; 00071 00072 VOID DuplicateString( 00073 LPCWSTR Source, 00074 LPWSTR *Destination) 00075 { 00076 SIZE_T cb; 00077 00078 if (*Destination) 00079 CoTaskMemFree(*Destination); 00080 00081 cb = (wcslen(Source) + 1) * sizeof(WCHAR); 00082 *Destination = (LPWSTR)CoTaskMemAlloc(cb); 00083 if (!*Destination) 00084 return; 00085 CopyMemory(*Destination, Source, cb); 00086 } 00087 00088 IconExtraction::IconExtraction() 00089 { 00090 flags = 0; 00091 memset(&defaultIcon, 0, sizeof(defaultIcon)); 00092 memset(&normalIcon, 0, sizeof(normalIcon)); 00093 memset(&openIcon, 0, sizeof(openIcon)); 00094 memset(&shortcutIcon, 0, sizeof(shortcutIcon)); 00095 } 00096 00097 IconExtraction::~IconExtraction() 00098 { 00099 if (defaultIcon.file) CoTaskMemFree(defaultIcon.file); 00100 if (normalIcon.file) CoTaskMemFree(normalIcon.file); 00101 if (openIcon.file) CoTaskMemFree(openIcon.file); 00102 if (shortcutIcon.file) CoTaskMemFree(shortcutIcon.file); 00103 } 00104 00105 HRESULT STDMETHODCALLTYPE IconExtraction::SetDefaultIcon( 00106 LPCWSTR pszFile, 00107 int iIcon) 00108 { 00109 TRACE("(%p, %s, %d)\n", this, debugstr_w(pszFile), iIcon); 00110 00111 DuplicateString(pszFile, &defaultIcon.file); 00112 if (!defaultIcon.file) 00113 return E_OUTOFMEMORY; 00114 defaultIcon.index = iIcon; 00115 return S_OK; 00116 } 00117 00118 HRESULT STDMETHODCALLTYPE IconExtraction::SetFlags( 00119 UINT uFlags) 00120 { 00121 TRACE("(%p, 0x%x)\n", this, uFlags); 00122 00123 flags = uFlags; 00124 return S_OK; 00125 } 00126 00127 HRESULT STDMETHODCALLTYPE IconExtraction::SetKey( 00128 HKEY hkey) 00129 { 00130 FIXME("(%p, %p)\n", this, hkey); 00131 UNIMPLEMENTED; 00132 return E_NOTIMPL; 00133 } 00134 00135 HRESULT STDMETHODCALLTYPE IconExtraction::SetNormalIcon( 00136 LPCWSTR pszFile, 00137 int iIcon) 00138 { 00139 TRACE("(%p, %s, %d)\n", this, debugstr_w(pszFile), iIcon); 00140 00141 DuplicateString(pszFile, &normalIcon.file); 00142 if (!normalIcon.file) 00143 return E_OUTOFMEMORY; 00144 normalIcon.index = iIcon; 00145 return S_OK; 00146 } 00147 00148 HRESULT STDMETHODCALLTYPE IconExtraction::SetOpenIcon( 00149 LPCWSTR pszFile, 00150 int iIcon) 00151 { 00152 TRACE("(%p, %s, %d)\n", this, debugstr_w(pszFile), iIcon); 00153 00154 DuplicateString(pszFile, &openIcon.file); 00155 if (!openIcon.file) 00156 return E_OUTOFMEMORY; 00157 openIcon.index = iIcon; 00158 return S_OK; 00159 } 00160 00161 HRESULT STDMETHODCALLTYPE IconExtraction::SetShortcutIcon( 00162 LPCWSTR pszFile, 00163 int iIcon) 00164 { 00165 TRACE("(%p, %s, %d)\n", this, debugstr_w(pszFile), iIcon); 00166 00167 DuplicateString(pszFile, &shortcutIcon.file); 00168 if (!shortcutIcon.file) 00169 return E_OUTOFMEMORY; 00170 shortcutIcon.index = iIcon; 00171 return S_OK; 00172 } 00173 00174 HRESULT STDMETHODCALLTYPE IconExtraction::GetIconLocation( 00175 UINT uFlags, 00176 LPWSTR szIconFile, 00177 UINT cchMax, 00178 int *piIndex, 00179 UINT *pwFlags) 00180 { 00181 const struct IconLocation *icon = NULL; 00182 SIZE_T cb; 00183 00184 TRACE("(%p, 0x%x, %s, 0x%x, %p, %p)\n", this, uFlags, debugstr_w(szIconFile), cchMax, piIndex, pwFlags); 00185 00186 if (!piIndex || !pwFlags) 00187 return E_POINTER; 00188 00189 if (uFlags & GIL_DEFAULTICON) 00190 icon = defaultIcon.file ? &defaultIcon : &normalIcon; 00191 else if (uFlags & GIL_FORSHORTCUT) 00192 icon = shortcutIcon.file ? &shortcutIcon : &normalIcon; 00193 else if (uFlags & GIL_OPENICON) 00194 icon = openIcon.file ? &openIcon : &normalIcon; 00195 else 00196 icon = &normalIcon; 00197 00198 if (!icon->file) 00199 return E_FAIL; 00200 00201 cb = wcslen(icon->file) + 1; 00202 if (cchMax < (UINT)cb) 00203 return E_FAIL; 00204 CopyMemory(szIconFile, icon->file, cb * sizeof(WCHAR)); 00205 *piIndex = icon->index; 00206 *pwFlags = flags; 00207 return S_OK; 00208 } 00209 00210 HRESULT STDMETHODCALLTYPE IconExtraction::Extract( 00211 LPCWSTR pszFile, 00212 UINT nIconIndex, 00213 HICON *phiconLarge, 00214 HICON *phiconSmall, 00215 UINT nIconSize) 00216 { 00217 TRACE("(%p, %s, %u, %p, %p, %u)\n", this, debugstr_w(pszFile), nIconIndex, phiconLarge, phiconSmall, nIconSize); 00218 00219 /* Nothing to do, ExtractIconW::GetIconLocation should be enough */ 00220 return S_FALSE; 00221 } 00222 00223 HRESULT STDMETHODCALLTYPE IconExtraction::GetIconLocation( 00224 UINT uFlags, 00225 LPSTR szIconFile, 00226 UINT cchMax, 00227 int *piIndex, 00228 UINT *pwFlags) 00229 { 00230 LPWSTR szIconFileW = NULL; 00231 HRESULT hr; 00232 00233 if (cchMax > 0) 00234 { 00235 szIconFileW = (LPWSTR)CoTaskMemAlloc(cchMax * sizeof(WCHAR)); 00236 if (!szIconFileW) 00237 return E_OUTOFMEMORY; 00238 } 00239 00240 hr = GetIconLocation( 00241 uFlags, szIconFileW, cchMax, piIndex, pwFlags); 00242 if (SUCCEEDED(hr) && cchMax > 0) 00243 if (0 == WideCharToMultiByte(CP_ACP, 0, szIconFileW, cchMax, szIconFile, cchMax, NULL, NULL)) 00244 hr = E_FAIL; 00245 00246 if (szIconFileW) 00247 CoTaskMemFree(szIconFileW); 00248 return hr; 00249 } 00250 00251 HRESULT STDMETHODCALLTYPE IconExtraction::Extract( 00252 LPCSTR pszFile, 00253 UINT nIconIndex, 00254 HICON *phiconLarge, 00255 HICON *phiconSmall, 00256 UINT nIconSize) 00257 { 00258 LPWSTR pszFileW = NULL; 00259 HRESULT hr; 00260 00261 if (pszFile) 00262 { 00263 int nLength; 00264 00265 nLength = MultiByteToWideChar(CP_ACP, 0, pszFile, -1, NULL, 0); 00266 if (nLength == 0) 00267 return E_FAIL; 00268 pszFileW = (LPWSTR)CoTaskMemAlloc(nLength * sizeof(WCHAR)); 00269 if (!pszFileW) 00270 return E_OUTOFMEMORY; 00271 if (!MultiByteToWideChar(CP_ACP, 0, pszFile, nLength, pszFileW, nLength)) 00272 { 00273 CoTaskMemFree(pszFileW); 00274 return E_FAIL; 00275 } 00276 } 00277 00278 hr = Extract(pszFileW, nIconIndex, phiconLarge, phiconSmall, nIconSize); 00279 00280 if (pszFileW) 00281 CoTaskMemFree(pszFileW); 00282 return hr; 00283 } 00284 00285 HRESULT STDMETHODCALLTYPE IconExtraction::GetClassID( 00286 CLSID *pClassID) 00287 { 00288 TRACE("(%p, %p)\n", this, pClassID); 00289 00290 if (!pClassID) 00291 return E_POINTER; 00292 00293 *pClassID = GUID_NULL; 00294 return S_OK; 00295 } 00296 00297 HRESULT STDMETHODCALLTYPE IconExtraction::IsDirty() 00298 { 00299 FIXME("(%p)\n", this); 00300 UNIMPLEMENTED; 00301 return E_NOTIMPL; 00302 } 00303 00304 HRESULT STDMETHODCALLTYPE IconExtraction::Load( 00305 LPCOLESTR pszFileName, 00306 DWORD dwMode) 00307 { 00308 FIXME("(%p, %s, %u)\n", this, debugstr_w(pszFileName), dwMode); 00309 UNIMPLEMENTED; 00310 return E_NOTIMPL; 00311 } 00312 00313 HRESULT STDMETHODCALLTYPE IconExtraction::Save( 00314 LPCOLESTR pszFileName, 00315 BOOL fRemember) 00316 { 00317 FIXME("(%p, %s, %d)\n", this, debugstr_w(pszFileName), fRemember); 00318 UNIMPLEMENTED; 00319 return E_NOTIMPL; 00320 } 00321 00322 HRESULT STDMETHODCALLTYPE IconExtraction::SaveCompleted( 00323 LPCOLESTR pszFileName) 00324 { 00325 FIXME("(%p, %s)\n", this, debugstr_w(pszFileName)); 00326 UNIMPLEMENTED; 00327 return E_NOTIMPL; 00328 } 00329 00330 HRESULT STDMETHODCALLTYPE IconExtraction::GetCurFile( 00331 LPOLESTR *ppszFileName) 00332 { 00333 FIXME("(%p, %p)\n", this, ppszFileName); 00334 UNIMPLEMENTED; 00335 return E_NOTIMPL; 00336 } 00337 00338 HRESULT WINAPI SHCreateDefaultExtractIcon(REFIID riid, void **ppv) 00339 { 00340 CComObject<IconExtraction> *theExtractor; 00341 CComPtr<IUnknown> result; 00342 HRESULT hResult; 00343 00344 if (ppv == NULL) 00345 return E_POINTER; 00346 *ppv = NULL; 00347 ATLTRY (theExtractor = new CComObject<IconExtraction>); 00348 if (theExtractor == NULL) 00349 return E_OUTOFMEMORY; 00350 hResult = theExtractor->QueryInterface (riid, (void **)&result); 00351 if (FAILED (hResult)) 00352 { 00353 delete theExtractor; 00354 return hResult; 00355 } 00356 *ppv = result.Detach (); 00357 return S_OK; 00358 } Generated on Sun May 27 2012 04:26:19 for ReactOS by
1.7.6.1
|