blob: dc4a3b397196144c77b3dd78271f5a34a1b83268 [file] [log] [blame]
Alexandre Julliard85ed45e1998-08-22 19:03:56 +00001/*
Juergen Schmiedcd390f31998-12-14 14:51:27 +00002 * handling of SHELL32.DLL OLE-Objects
Alexandre Julliard85ed45e1998-08-22 19:03:56 +00003 *
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
6 *
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
Jonathan Ernst360a3f92006-05-18 14:49:52 +020019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000020 */
21
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +000022#include "config.h"
23
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000024#include <stdarg.h>
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000025#include <stdlib.h>
26#include <string.h>
Juergen Schmied8e7cb4d1999-03-25 10:57:12 +000027
Francois Gouget486d0202004-10-07 03:06:48 +000028#define COBJMACROS
29
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000030#include "windef.h"
31#include "winbase.h"
François Gougetdea3d782001-01-02 21:00:46 +000032#include "shellapi.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000033#include "wingdi.h"
34#include "winuser.h"
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +000035#include "shlobj.h"
Juergen Schmiedba28ba11999-01-23 14:12:48 +000036#include "shlguid.h"
Juergen Schmied8e7cb4d1999-03-25 10:57:12 +000037#include "winreg.h"
38#include "winerror.h"
Marcus Meissner317af321999-02-17 13:51:06 +000039
Alexandre Julliard39541172001-08-16 18:49:56 +000040#include "undocshell.h"
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +000041#include "wine/unicode.h"
Juergen Schmied8e7cb4d1999-03-25 10:57:12 +000042#include "shell32_main.h"
43
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000044#include "wine/debug.h"
Juergen Schmied23b80872002-07-02 02:05:17 +000045#include "shlwapi.h"
Juergen Schmied1e5ec882002-07-24 01:56:03 +000046#include "debughlp.h"
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +000047
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000048WINE_DEFAULT_DEBUG_CHANNEL(shell);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000049
Alexandre Julliard366fcaf2008-12-03 12:09:17 +010050extern INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax); /* shlwapi.24 */
Juergen Schmied23b80872002-07-02 02:05:17 +000051
Juergen Schmied23b80872002-07-02 02:05:17 +000052/**************************************************************************
53 * Default ClassFactory types
54 */
55typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
Andrew Talbotdfe3d5b2007-02-06 22:05:10 +000056static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
Juergen Schmied23b80872002-07-02 02:05:17 +000057
58/* this table contains all CLSID's of shell32 objects */
Alexandre Julliard7a0396a2006-06-12 13:44:21 +020059static const struct {
Juergen Schmied23b80872002-07-02 02:05:17 +000060 REFIID riid;
61 LPFNCREATEINSTANCE lpfnCI;
Martin Fuchsdd46d6d2004-03-27 01:42:22 +000062} InterfaceTable[] = {
Andrew Talbot93f656b2008-07-06 13:00:42 +010063 {&CLSID_ShellFSFolder, IFSFolder_Constructor},
64 {&CLSID_MyComputer, ISF_MyComputer_Constructor},
65 {&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
66 {&CLSID_ShellDesktop, ISF_Desktop_Constructor},
Vincent Povirke69c6632009-02-18 12:32:32 -060067 {&CLSID_ShellItem, IShellItem_Constructor},
Andrew Talbot93f656b2008-07-06 13:00:42 +010068 {&CLSID_ShellLink, IShellLink_Constructor},
69 {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
70 {&CLSID_ControlPanel, IControlPanel_Constructor},
71 {&CLSID_AutoComplete, IAutoComplete_Constructor},
72 {&CLSID_UnixFolder, UnixFolder_Constructor},
73 {&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
74 {&CLSID_FolderShortcut, FolderShortcut_Constructor},
75 {&CLSID_MyDocuments, MyDocuments_Constructor},
76 {&CLSID_RecycleBin, RecycleBin_Constructor},
Alexandre Julliard4d413292009-08-25 11:13:26 +020077 {&CLSID_QueryAssociations, QueryAssociations_Constructor},
Juergen Schmied23b80872002-07-02 02:05:17 +000078 {NULL,NULL}
79};
80
Juergen Schmied23b80872002-07-02 02:05:17 +000081
Juergen Schmied23b80872002-07-02 02:05:17 +000082
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +020083/*************************************************************************
84 * SHCoCreateInstance [SHELL32.102]
85 *
86 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
87 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
88 * SHLoadOLE for details.
89 *
90 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
91 * shell32.dll the function will load the object manually without the help of ole32
92 *
93 * NOTES
94 * exported by ordinal
95 *
96 * SEE ALSO
97 * CoCreateInstace, SHLoadOLE
98 */
Vincent Béron6c644d62004-10-19 23:55:15 +000099HRESULT WINAPI SHCoCreateInstance(
Alexandre Julliard72ecbb02004-01-06 20:42:47 +0000100 LPCWSTR aclsid,
101 const CLSID *clsid,
Juergen Schmied23b80872002-07-02 02:05:17 +0000102 LPUNKNOWN pUnkOuter,
Juergen Schmied61adb761999-07-10 11:48:15 +0000103 REFIID refiid,
104 LPVOID *ppv)
105{
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000106 DWORD hres;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000107 IID iid;
Andrew Talbot2f4bb7b2006-11-14 22:13:36 +0000108 const CLSID * myclsid = clsid;
Juergen Schmied23b80872002-07-02 02:05:17 +0000109 WCHAR sKeyName[MAX_PATH];
110 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
111 WCHAR sClassID[60];
112 const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
113 const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
114 WCHAR sDllPath[MAX_PATH];
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200115 HKEY hKey = 0;
Juergen Schmied23b80872002-07-02 02:05:17 +0000116 DWORD dwSize;
Juergen Schmied23b80872002-07-02 02:05:17 +0000117 IClassFactory * pcf = NULL;
Vincent Béron9a624912002-05-31 23:06:46 +0000118
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000119 if(!ppv) return E_POINTER;
120 *ppv=NULL;
121
Juergen Schmied23b80872002-07-02 02:05:17 +0000122 /* if the clsid is a string, convert it */
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000123 if (!clsid)
124 {
125 if (!aclsid) return REGDB_E_CLASSNOTREG;
Alexandre Julliard72ecbb02004-01-06 20:42:47 +0000126 SHCLSIDFromStringW(aclsid, &iid);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000127 myclsid = &iid;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000128 }
Juergen Schmied61adb761999-07-10 11:48:15 +0000129
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000130 TRACE("(%p,%s,unk:%p,%s,%p)\n",
131 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000132
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200133 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
134 {
135 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
136 IClassFactory_Release(pcf);
137 goto end;
138 }
139
Juergen Schmied23b80872002-07-02 02:05:17 +0000140 /* we look up the dll path in the registry */
Alexandre Julliard366fcaf2008-12-03 12:09:17 +0100141 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
Juergen Schmied23b80872002-07-02 02:05:17 +0000142 lstrcpyW(sKeyName, sCLSID);
143 lstrcatW(sKeyName, sClassID);
144 lstrcatW(sKeyName, sInProcServer32);
145
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200146 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
147 return E_ACCESSDENIED;
Juergen Schmied23b80872002-07-02 02:05:17 +0000148
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200149 /* if a special registry key is set, we load a shell extension without help of OLE32 */
150 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
151 {
Francois Gouget93416cd2005-03-23 13:15:18 +0000152 /* load an external dll without ole32 */
Juergen Schmied23b80872002-07-02 02:05:17 +0000153 HANDLE hLibrary;
154 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
155 DllGetClassObjectFunc DllGetClassObject;
156
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200157 dwSize = sizeof(sDllPath);
158 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
159
Juergen Schmied23b80872002-07-02 02:05:17 +0000160 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
161 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
162 hres = E_ACCESSDENIED;
163 goto end;
164 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
165 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
166 FreeLibrary( hLibrary );
167 hres = E_ACCESSDENIED;
168 goto end;
Michael Stefaniucf6baf972008-10-08 01:32:38 +0200169 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
Hans Leidekker89e1d292006-10-07 20:18:14 +0200170 TRACE("GetClassObject failed 0x%08x\n", hres);
Juergen Schmied23b80872002-07-02 02:05:17 +0000171 goto end;
172 }
173
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200174 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
175 IClassFactory_Release(pcf);
Juergen Schmied23b80872002-07-02 02:05:17 +0000176 } else {
177
Francois Gouget93416cd2005-03-23 13:15:18 +0000178 /* load an external dll in the usual way */
Robert Shearman77b7f952004-06-18 00:23:38 +0000179 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
Juergen Schmied23b80872002-07-02 02:05:17 +0000180 }
181
Juergen Schmied23b80872002-07-02 02:05:17 +0000182end:
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200183 if (hKey) RegCloseKey(hKey);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000184 if(hres!=S_OK)
185 {
Hans Leidekker89e1d292006-10-07 20:18:14 +0200186 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000187 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
Juergen Schmiedafe53ed1999-11-23 22:31:18 +0000188 ERR("class not found in registry\n");
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000189 }
190
Juergen Schmiedafe53ed1999-11-23 22:31:18 +0000191 TRACE("-- instance: %p\n",*ppv);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000192 return hres;
193}
194
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000195/*************************************************************************
Francois Gougetd3aa2312006-02-07 21:18:12 +0100196 * DllGetClassObject [SHELL32.@]
197 * SHDllGetClassObject [SHELL32.128]
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000198 */
Alexandre Julliardd37f0ab2005-08-08 17:35:28 +0000199HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
Juergen Schmied23b80872002-07-02 02:05:17 +0000200{
201 HRESULT hres = E_OUTOFMEMORY;
202 IClassFactory * pcf = NULL;
203 int i;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000204
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000205 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
Vincent Béron9a624912002-05-31 23:06:46 +0000206
Juergen Schmied23b80872002-07-02 02:05:17 +0000207 if (!ppv) return E_INVALIDARG;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000208 *ppv = NULL;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000209
Juergen Schmied23b80872002-07-02 02:05:17 +0000210 /* search our internal interface table */
211 for(i=0;InterfaceTable[i].riid;i++) {
212 if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
213 TRACE("index[%u]\n", i);
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000214 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
Juergen Schmied23b80872002-07-02 02:05:17 +0000215 }
216 }
Juergen Schmiedcd390f31998-12-14 14:51:27 +0000217
Juergen Schmied23b80872002-07-02 02:05:17 +0000218 if (!pcf) {
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000219 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
Juergen Schmied23b80872002-07-02 02:05:17 +0000220 return CLASS_E_CLASSNOTAVAILABLE;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000221 }
Juergen Schmied23b80872002-07-02 02:05:17 +0000222
223 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
224 IClassFactory_Release(pcf);
225
Alexandre Julliarda099a551999-06-12 15:45:58 +0000226 TRACE("-- pointer to class factory: %p\n",*ppv);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000227 return hres;
228}
229
230/*************************************************************************
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000231 * SHCLSIDFromString [SHELL32.147]
232 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200233 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
234 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
235 *
236 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
237 *
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000238 * NOTES
239 * exported by ordinal
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200240 *
241 * SEE ALSO
242 * CLSIDFromString, SHLoadOLE
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000243 */
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +0000244DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000245{
Alexandre Julliard91791032000-06-23 16:13:33 +0000246 WCHAR buffer[40];
247 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
248 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
249 return CO_E_CLASSSTRING;
250 return CLSIDFromString( buffer, id );
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000251}
Alexandre Julliard72ecbb02004-01-06 20:42:47 +0000252DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000253{
254 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
Mikhail Maroukhinef930c872010-03-26 23:59:50 +0600255 return CLSIDFromString(clsid, id);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000256}
Andrew Talbotc289a332007-09-13 09:42:50 +0100257DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000258{
Alexandre Julliardd586dc92000-08-14 14:35:01 +0000259 if (SHELL_OsIsUnicode())
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000260 return SHCLSIDFromStringW (clsid, id);
261 return SHCLSIDFromStringA (clsid, id);
262}
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000263
264/*************************************************************************
Patrik Stridvall8b216b32001-06-19 18:20:47 +0000265 * SHGetMalloc [SHELL32.@]
Jon Griffithscd4234a2003-03-18 18:35:48 +0000266 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200267 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
268 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
269 * see SHLoadOLE for details.
Jon Griffithscd4234a2003-03-18 18:35:48 +0000270 *
271 * PARAMS
272 * lpmal [O] Destination for IMalloc interface.
273 *
274 * RETURNS
275 * Success: S_OK. lpmal contains the shells IMalloc interface.
276 * Failure. An HRESULT error code.
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000277 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200278 * SEE ALSO
279 * CoGetMalloc, SHLoadOLE
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000280 */
Dimitrie O. Paundfa6b122003-01-03 03:07:21 +0000281HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000282{
283 TRACE("(%p)\n", lpmal);
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200284 return CoGetMalloc(MEMCTX_TASK, lpmal);
Juergen Schmied23b80872002-07-02 02:05:17 +0000285}
286
287/*************************************************************************
288 * SHAlloc [SHELL32.196]
289 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200290 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
291 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
292 * see SHLoadOLE for details.
293 *
Juergen Schmied23b80872002-07-02 02:05:17 +0000294 * NOTES
295 * exported by ordinal
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200296 *
297 * SEE ALSO
298 * CoTaskMemAlloc, SHLoadOLE
Juergen Schmied23b80872002-07-02 02:05:17 +0000299 */
300LPVOID WINAPI SHAlloc(DWORD len)
301{
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200302 LPVOID ret;
Juergen Schmied23b80872002-07-02 02:05:17 +0000303
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200304 ret = CoTaskMemAlloc(len);
Hans Leidekker89e1d292006-10-07 20:18:14 +0200305 TRACE("%u bytes at %p\n",len, ret);
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200306 return ret;
Juergen Schmied23b80872002-07-02 02:05:17 +0000307}
308
309/*************************************************************************
310 * SHFree [SHELL32.195]
311 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200312 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
313 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
314 * see SHLoadOLE for details.
315 *
Juergen Schmied23b80872002-07-02 02:05:17 +0000316 * NOTES
317 * exported by ordinal
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200318 *
319 * SEE ALSO
320 * CoTaskMemFree, SHLoadOLE
Juergen Schmied23b80872002-07-02 02:05:17 +0000321 */
322void WINAPI SHFree(LPVOID pv)
323{
Juergen Schmied23b80872002-07-02 02:05:17 +0000324 TRACE("%p\n",pv);
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200325 CoTaskMemFree(pv);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000326}
327
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000328/*************************************************************************
Patrik Stridvall8b216b32001-06-19 18:20:47 +0000329 * SHGetDesktopFolder [SHELL32.@]
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000330 */
Ge van Geldorpc390bb22004-06-28 20:32:53 +0000331HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000332{
Nikolay Sivov0f794f92010-03-21 04:42:59 +0300333 HRESULT hres;
334
335 TRACE("(%p)\n", psf);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000336
Juergen Schmied23b80872002-07-02 02:05:17 +0000337 if(!psf) return E_INVALIDARG;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000338
Nikolay Sivov0f794f92010-03-21 04:42:59 +0300339 *psf = NULL;
340 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
341
342 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000343 return hres;
344}
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000345/**************************************************************************
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000346 * Default ClassFactory Implementation
347 *
348 * SHCreateDefClassObject
349 *
350 * NOTES
Francois Gouget93416cd2005-03-23 13:15:18 +0000351 * Helper function for dlls without their own classfactory.
352 * A generic classfactory is returned.
353 * When the CreateInstance of the cf is called the callback is executed.
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000354 */
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000355
356typedef struct
357{
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +0000358 const IClassFactoryVtbl *lpVtbl;
Mike McCormacke28c0142005-07-03 12:03:35 +0000359 LONG ref;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000360 CLSID *rclsid;
361 LPFNCREATEINSTANCE lpfnCI;
362 const IID * riidInst;
Mike McCormacke28c0142005-07-03 12:03:35 +0000363 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000364} IDefClFImpl;
365
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +0000366static const IClassFactoryVtbl dclfvt;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000367
368/**************************************************************************
369 * IDefClF_fnConstructor
370 */
371
Andrew Talbotdfe3d5b2007-02-06 22:05:10 +0000372static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000373{
374 IDefClFImpl* lpclf;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000375
Mike McCormack17c31062005-03-21 11:25:13 +0000376 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000377 lpclf->ref = 1;
Alexandre Julliardc2ebe1f2003-04-10 18:17:34 +0000378 lpclf->lpVtbl = &dclfvt;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000379 lpclf->lpfnCI = lpfnCI;
380 lpclf->pcRefDll = pcRefDll;
381
Juergen Schmiedd6509032000-04-28 20:19:03 +0000382 if (pcRefDll) InterlockedIncrement(pcRefDll);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000383 lpclf->riidInst = riidInst;
384
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000385 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000386 return (LPCLASSFACTORY)lpclf;
387}
388/**************************************************************************
389 * IDefClF_fnQueryInterface
390 */
391static HRESULT WINAPI IDefClF_fnQueryInterface(
392 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
393{
Alexandre Julliard314b99c2004-09-09 20:17:07 +0000394 IDefClFImpl *This = (IDefClFImpl *)iface;
Alexandre Julliard681c75b2000-01-18 05:09:49 +0000395
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000396 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000397
398 *ppvObj = NULL;
399
Juergen Schmied23b80872002-07-02 02:05:17 +0000400 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
401 *ppvObj = This;
402 InterlockedIncrement(&This->ref);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000403 return S_OK;
404 }
Juergen Schmied23b80872002-07-02 02:05:17 +0000405
406 TRACE("-- E_NOINTERFACE\n");
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000407 return E_NOINTERFACE;
Vincent Béron9a624912002-05-31 23:06:46 +0000408}
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000409/******************************************************************************
410 * IDefClF_fnAddRef
411 */
412static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
413{
Alexandre Julliard314b99c2004-09-09 20:17:07 +0000414 IDefClFImpl *This = (IDefClFImpl *)iface;
James Hawkinsba92d292005-01-14 16:02:20 +0000415 ULONG refCount = InterlockedIncrement(&This->ref);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000416
Hans Leidekker89e1d292006-10-07 20:18:14 +0200417 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
James Hawkinsba92d292005-01-14 16:02:20 +0000418
419 return refCount;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000420}
421/******************************************************************************
422 * IDefClF_fnRelease
423 */
424static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
425{
Alexandre Julliard314b99c2004-09-09 20:17:07 +0000426 IDefClFImpl *This = (IDefClFImpl *)iface;
James Hawkinsba92d292005-01-14 16:02:20 +0000427 ULONG refCount = InterlockedDecrement(&This->ref);
428
Hans Leidekker89e1d292006-10-07 20:18:14 +0200429 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000430
James Hawkinsba92d292005-01-14 16:02:20 +0000431 if (!refCount)
Vincent Béron9a624912002-05-31 23:06:46 +0000432 {
Juergen Schmiedd6509032000-04-28 20:19:03 +0000433 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000434
435 TRACE("-- destroying IClassFactory(%p)\n",This);
436 HeapFree(GetProcessHeap(),0,This);
437 return 0;
438 }
James Hawkinsba92d292005-01-14 16:02:20 +0000439 return refCount;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000440}
441/******************************************************************************
442 * IDefClF_fnCreateInstance
443 */
444static HRESULT WINAPI IDefClF_fnCreateInstance(
445 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
446{
Alexandre Julliard314b99c2004-09-09 20:17:07 +0000447 IDefClFImpl *This = (IDefClFImpl *)iface;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000448
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000449 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000450
451 *ppvObject = NULL;
Vincent Béron9a624912002-05-31 23:06:46 +0000452
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000453 if ( This->riidInst==NULL ||
454 IsEqualCLSID(riid, This->riidInst) ||
455 IsEqualCLSID(riid, &IID_IUnknown) )
456 {
457 return This->lpfnCI(pUnkOuter, riid, ppvObject);
458 }
459
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000460 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000461 return E_NOINTERFACE;
462}
463/******************************************************************************
464 * IDefClF_fnLockServer
465 */
466static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
467{
Alexandre Julliard314b99c2004-09-09 20:17:07 +0000468 IDefClFImpl *This = (IDefClFImpl *)iface;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000469 TRACE("%p->(0x%x), not implemented\n",This, fLock);
470 return E_NOTIMPL;
471}
472
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +0000473static const IClassFactoryVtbl dclfvt =
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000474{
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000475 IDefClF_fnQueryInterface,
476 IDefClF_fnAddRef,
477 IDefClF_fnRelease,
478 IDefClF_fnCreateInstance,
479 IDefClF_fnLockServer
480};
481
482/******************************************************************************
483 * SHCreateDefClassObject [SHELL32.70]
484 */
485HRESULT WINAPI SHCreateDefClassObject(
Vincent Béron9a624912002-05-31 23:06:46 +0000486 REFIID riid,
487 LPVOID* ppv,
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000488 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +0000489 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000490 REFIID riidInst) /* [in] optional interface to the instance */
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000491{
Juergen Schmied23b80872002-07-02 02:05:17 +0000492 IClassFactory * pcf;
493
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000494 TRACE("%s %p %p %p %s\n",
495 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000496
Juergen Schmied23b80872002-07-02 02:05:17 +0000497 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
Mike McCormackeafa6662005-08-22 09:26:53 +0000498 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
Juergen Schmied23b80872002-07-02 02:05:17 +0000499 *ppv = pcf;
500 return NOERROR;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000501}
502
Juergen Schmiedd6509032000-04-28 20:19:03 +0000503/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000504 * DragAcceptFiles [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000505 */
506void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
507{
508 LONG exstyle;
Vincent Béron9a624912002-05-31 23:06:46 +0000509
Juergen Schmiedd6509032000-04-28 20:19:03 +0000510 if( !IsWindow(hWnd) ) return;
511 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
512 if (b)
513 exstyle |= WS_EX_ACCEPTFILES;
514 else
515 exstyle &= ~WS_EX_ACCEPTFILES;
516 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
517}
518
519/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000520 * DragFinish [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000521 */
522void WINAPI DragFinish(HDROP h)
523{
524 TRACE("\n");
Michael Stefaniuc6c54ad32009-02-18 22:46:39 +0100525 GlobalFree(h);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000526}
527
528/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000529 * DragQueryPoint [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000530 */
531BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
532{
Alexandre Julliard60e17522000-09-25 23:56:41 +0000533 DROPFILES *lpDropFileStruct;
Juergen Schmiedd6509032000-04-28 20:19:03 +0000534 BOOL bRet;
535
536 TRACE("\n");
537
Michael Stefaniucb7de2662008-11-05 23:00:50 +0100538 lpDropFileStruct = GlobalLock(hDrop);
Alexandre Julliard60e17522000-09-25 23:56:41 +0000539
540 *p = lpDropFileStruct->pt;
541 bRet = lpDropFileStruct->fNC;
Vincent Béron9a624912002-05-31 23:06:46 +0000542
Juergen Schmiedd6509032000-04-28 20:19:03 +0000543 GlobalUnlock(hDrop);
544 return bRet;
545}
546
547/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000548 * DragQueryFileA [SHELL32.@]
Markus Amsler671738d2005-11-10 11:15:22 +0000549 * DragQueryFile [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000550 */
551UINT WINAPI DragQueryFileA(
552 HDROP hDrop,
553 UINT lFile,
554 LPSTR lpszFile,
555 UINT lLength)
556{
557 LPSTR lpDrop;
558 UINT i = 0;
Michael Stefaniucb7de2662008-11-05 23:00:50 +0100559 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
Vincent Béron9a624912002-05-31 23:06:46 +0000560
Johan Dahlin991fd852002-11-21 23:56:42 +0000561 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
Vincent Béron9a624912002-05-31 23:06:46 +0000562
Juergen Schmiedd6509032000-04-28 20:19:03 +0000563 if(!lpDropFileStruct) goto end;
564
Alexandre Julliard60e17522000-09-25 23:56:41 +0000565 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
Juergen Schmiedd6509032000-04-28 20:19:03 +0000566
Alexandre Julliardebe3c522004-12-09 14:07:59 +0000567 if(lpDropFileStruct->fWide) {
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000568 LPWSTR lpszFileW = NULL;
569
570 if(lpszFile) {
Mike McCormack17c31062005-03-21 11:25:13 +0000571 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000572 if(lpszFileW == NULL) {
573 goto end;
574 }
575 }
576 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
577
578 if(lpszFileW) {
579 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
580 HeapFree(GetProcessHeap(), 0, lpszFileW);
581 }
582 goto end;
583 }
584
Juergen Schmiedd6509032000-04-28 20:19:03 +0000585 while (i++ < lFile)
586 {
587 while (*lpDrop++); /* skip filename */
Vincent Béron9a624912002-05-31 23:06:46 +0000588 if (!*lpDrop)
Juergen Schmiedd6509032000-04-28 20:19:03 +0000589 {
Vincent Béron9a624912002-05-31 23:06:46 +0000590 i = (lFile == 0xFFFFFFFF) ? i : 0;
Juergen Schmiedd6509032000-04-28 20:19:03 +0000591 goto end;
592 }
593 }
Vincent Béron9a624912002-05-31 23:06:46 +0000594
Alexandre Julliardd586dc92000-08-14 14:35:01 +0000595 i = strlen(lpDrop);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000596 if (!lpszFile ) goto end; /* needed buffer size */
Damjan Jovanovic1d5575b2007-07-06 07:27:56 +0200597 lstrcpynA (lpszFile, lpDrop, lLength);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000598end:
599 GlobalUnlock(hDrop);
600 return i;
601}
602
603/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000604 * DragQueryFileW [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000605 */
606UINT WINAPI DragQueryFileW(
607 HDROP hDrop,
608 UINT lFile,
609 LPWSTR lpszwFile,
610 UINT lLength)
611{
612 LPWSTR lpwDrop;
613 UINT i = 0;
Michael Stefaniucb7de2662008-11-05 23:00:50 +0100614 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
Vincent Béron9a624912002-05-31 23:06:46 +0000615
Johan Dahlin991fd852002-11-21 23:56:42 +0000616 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
Vincent Béron9a624912002-05-31 23:06:46 +0000617
Juergen Schmiedd6509032000-04-28 20:19:03 +0000618 if(!lpDropFileStruct) goto end;
619
Sander van Leeuwenb7828ac2002-06-02 21:23:45 +0000620 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000621
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000622 if(lpDropFileStruct->fWide == FALSE) {
623 LPSTR lpszFileA = NULL;
Juergen Schmied23b80872002-07-02 02:05:17 +0000624
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000625 if(lpszwFile) {
Mike McCormack17c31062005-03-21 11:25:13 +0000626 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000627 if(lpszFileA == NULL) {
628 goto end;
629 }
630 }
631 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
632
633 if(lpszFileA) {
634 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
635 HeapFree(GetProcessHeap(), 0, lpszFileA);
636 }
637 goto end;
638 }
639
Juergen Schmiedd6509032000-04-28 20:19:03 +0000640 i = 0;
641 while (i++ < lFile)
642 {
643 while (*lpwDrop++); /* skip filename */
Vincent Béron9a624912002-05-31 23:06:46 +0000644 if (!*lpwDrop)
Juergen Schmiedd6509032000-04-28 20:19:03 +0000645 {
Vincent Béron9a624912002-05-31 23:06:46 +0000646 i = (lFile == 0xFFFFFFFF) ? i : 0;
Juergen Schmiedd6509032000-04-28 20:19:03 +0000647 goto end;
648 }
649 }
Vincent Béron9a624912002-05-31 23:06:46 +0000650
Alexandre Julliard60e17522000-09-25 23:56:41 +0000651 i = strlenW(lpwDrop);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000652 if ( !lpszwFile) goto end; /* needed buffer size */
Damjan Jovanovic1d5575b2007-07-06 07:27:56 +0200653 lstrcpynW (lpszwFile, lpwDrop, lLength);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000654end:
655 GlobalUnlock(hDrop);
656 return i;
657}