Add SHDefExtractIcon{AW} function.
[wine] / dlls / shell32 / shellole.c
1 /*
2  *      handling of SHELL32.DLL OLE-Objects
3  *
4  *      Copyright 1997  Marcus Meissner
5  *      Copyright 1998  Juergen Schmied  <juergen.schmied@metronet.de>
6  *
7  * 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
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include "shellapi.h"
28 #include "shlobj.h"
29 #include "shlguid.h"
30 #include "winreg.h"
31 #include "winerror.h"
32
33 #include "undocshell.h"
34 #include "wine/unicode.h"
35 #include "shell32_main.h"
36
37 #include "wine/debug.h"
38 #include "shlwapi.h"
39 #include "winuser.h"
40 #include "debughlp.h"
41 #include "wine/obj_dragdrophelper.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(shell);
44
45 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id);
46 extern HRESULT WINAPI IFSFolder_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
47
48 const WCHAR sShell32[12] = {'S','H','E','L','L','3','2','.','D','L','L','\0'};
49 const WCHAR sOLE32[10] = {'O','L','E','3','2','.','D','L','L','\0'};
50
51 HINSTANCE hShellOle32 = 0;
52 /**************************************************************************
53  * Default ClassFactory types
54  */
55 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
56 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
57
58 /* this table contains all CLSID's of shell32 objects */
59 struct {
60         REFIID                  riid;
61         LPFNCREATEINSTANCE      lpfnCI;
62 } InterfaceTable[6] = {
63         {&CLSID_ShellFSFolder,  &IFSFolder_Constructor},
64         {&CLSID_MyComputer,     &ISF_MyComputer_Constructor},
65         {&CLSID_ShellDesktop,   &ISF_Desktop_Constructor},
66         {&CLSID_ShellLink,      &IShellLink_Constructor},
67         {&CLSID_DragDropHelper, &IDropTargetHelper_Constructor},
68         {NULL,NULL}
69 };
70
71 /*************************************************************************
72  * __CoCreateInstance [internal]
73  *
74  * NOTES
75  *   wraper for late bound call to OLE32.DLL
76  *
77  */
78 HRESULT (WINAPI *pCoCreateInstance)(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv) = NULL;
79
80 void * __GetExternalFunc(HMODULE * phModule, LPCWSTR szModuleName, LPCSTR szProcName)
81 {
82         if (!*phModule) *phModule = GetModuleHandleW(szModuleName);
83         if (!*phModule) *phModule = LoadLibraryW(szModuleName);
84         if (*phModule) return GetProcAddress(*phModule, szProcName);
85         return NULL;
86 }
87
88 HRESULT  __CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
89 {
90         if(!pCoCreateInstance) pCoCreateInstance = __GetExternalFunc(&hShellOle32, sOLE32, "CoCreateInstance");
91         if(!pCoCreateInstance) return E_FAIL;
92         return pCoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, ppv);
93 }
94
95 /*************************************************************************
96  * SHCoCreateInstance [SHELL32.102]
97  *
98  * NOTES
99  *     exported by ordinal
100  */
101
102 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
103
104 DWORD WINAPI __SHGUIDToStringW (REFGUID guid, LPWSTR str)
105 {
106     WCHAR sFormat[52] = {'{','%','0','8','l','x','-','%','0','4',
107                          'x','-','%','0','4','x','-','%','0','2',
108                          'x','%','0','2','x','-','%','0','2','x',
109                          '%','0','2','x','%','0','2','x','%','0',
110                          '2','x','%','0','2','x','%','0','2','x',
111                          '}','\0'};
112
113     return wsprintfW ( str, sFormat,
114              guid->Data1, guid->Data2, guid->Data3,
115              guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
116              guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
117
118 }
119
120 /************************************************************************/
121
122 LRESULT WINAPI SHCoCreateInstance(
123         LPCSTR aclsid,
124         REFCLSID clsid,
125         LPUNKNOWN pUnkOuter,
126         REFIID refiid,
127         LPVOID *ppv)
128 {
129         DWORD   hres;
130         IID     iid;
131         CLSID * myclsid = (CLSID*)clsid;
132         WCHAR   sKeyName[MAX_PATH];
133         const   WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
134         WCHAR   sClassID[60];
135         const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
136         const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
137         WCHAR   sDllPath[MAX_PATH];
138         HKEY    hKey;
139         DWORD   dwSize;
140         BOOLEAN bLoadFromShell32 = FALSE;
141         BOOLEAN bLoadWithoutCOM = FALSE;
142         IClassFactory * pcf = NULL;
143
144         if(!ppv) return E_POINTER;
145         *ppv=NULL;
146
147         /* if the clsid is a string, convert it */
148         if (!clsid)
149         {
150           if (!aclsid) return REGDB_E_CLASSNOTREG;
151           SHCLSIDFromStringA(aclsid, &iid);
152           myclsid = &iid;
153         }
154
155         TRACE("(%p,%s,unk:%p,%s,%p)\n",
156                 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
157
158         /* we look up the dll path in the registry */
159         __SHGUIDToStringW(myclsid, sClassID);
160         lstrcpyW(sKeyName, sCLSID);
161         lstrcatW(sKeyName, sClassID);
162         lstrcatW(sKeyName, sInProcServer32);
163
164         if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey)) {
165             dwSize = sizeof(sDllPath);
166             SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
167
168             /* if a special registry key is set, we load a shell extension without help of OLE32 */
169             bLoadWithoutCOM = (ERROR_SUCCESS == SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0));
170
171             /* if the com object is inside shell32, omit use of ole32 */
172             bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));
173
174             RegCloseKey (hKey);
175         } else {
176             /* since we can't find it in the registry we try internally */
177             bLoadFromShell32 = TRUE;
178         }
179
180         TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);
181
182         /* now we create a instance */
183         if (bLoadFromShell32) {
184             if (! SUCCEEDED(SHELL32_DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf))) {
185                 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid));
186             }
187         } else if (bLoadWithoutCOM) {
188
189             /* load a external dll without ole32 */
190             HANDLE hLibrary;
191             typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
192             DllGetClassObjectFunc DllGetClassObject;
193
194             if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
195                 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
196                 hres = E_ACCESSDENIED;
197                 goto end;
198             } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
199                 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
200                 FreeLibrary( hLibrary );
201                 hres = E_ACCESSDENIED;
202                 goto end;
203             } else if (! SUCCEEDED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
204                     TRACE("GetClassObject failed 0x%08lx\n", hres);
205                     goto end;
206             }
207
208         } else {
209
210             /* load a external dll in the usual way */
211             hres = __CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
212             goto end;
213         }
214
215         /* here we should have a ClassFactory */
216         if (!pcf) return E_ACCESSDENIED;
217
218         hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
219         IClassFactory_Release(pcf);
220 end:
221         if(hres!=S_OK)
222         {
223           ERR("failed (0x%08lx) to create CLSID:%s IID:%s\n",
224               hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
225           ERR("class not found in registry\n");
226         }
227
228         TRACE("-- instance: %p\n",*ppv);
229         return hres;
230 }
231
232 /*************************************************************************
233  * DllGetClassObject   [SHELL32.128]
234  */
235 HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
236 {
237         HRESULT hres = E_OUTOFMEMORY;
238         IClassFactory * pcf = NULL;
239         int i;
240
241         TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
242
243         if (!ppv) return E_INVALIDARG;
244         *ppv = NULL;
245
246         /* search our internal interface table */
247         for(i=0;InterfaceTable[i].riid;i++) {
248             if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
249                 TRACE("index[%u]\n", i);
250                 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
251             }
252         }
253
254         if (!pcf) {
255             FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
256             return CLASS_E_CLASSNOTAVAILABLE;
257         }
258
259         hres = IClassFactory_QueryInterface(pcf, iid, ppv);
260         IClassFactory_Release(pcf);
261
262         TRACE("-- pointer to class factory: %p\n",*ppv);
263         return hres;
264 }
265
266 /*************************************************************************
267  * SHCLSIDFromString                            [SHELL32.147]
268  *
269  * NOTES
270  *     exported by ordinal
271  */
272 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
273 {
274     WCHAR buffer[40];
275     TRACE("(%p(%s) %p)\n", clsid, clsid, id);
276     if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
277         return CO_E_CLASSSTRING;
278     return CLSIDFromString( buffer, id );
279 }
280 DWORD WINAPI SHCLSIDFromStringW (LPWSTR clsid, CLSID *id)
281 {
282         TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
283         return CLSIDFromString(clsid, id);
284 }
285 DWORD WINAPI SHCLSIDFromStringAW (LPVOID clsid, CLSID *id)
286 {
287         if (SHELL_OsIsUnicode())
288           return SHCLSIDFromStringW (clsid, id);
289         return SHCLSIDFromStringA (clsid, id);
290 }
291
292 /*************************************************************************
293  *      Shell Memory Allocator
294  */
295
296 /* set the vtable later */
297 extern ICOM_VTABLE(IMalloc) VT_Shell_IMalloc32;
298
299 /* this is the static object instance */
300 typedef struct {
301         ICOM_VFIELD(IMalloc);
302         DWORD dummy;
303 } _ShellMalloc;
304
305 _ShellMalloc Shell_Malloc = { &VT_Shell_IMalloc32,1};
306
307 /* this is the global allocator of shell32 */
308 IMalloc * ShellTaskAllocator = NULL;
309
310 /******************************************************************************
311  *              IShellMalloc_QueryInterface        [VTABLE]
312  */
313 static HRESULT WINAPI IShellMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid, LPVOID *obj)
314 {
315         TRACE("(%s,%p)\n",shdebugstr_guid(refiid),obj);
316         if (IsEqualIID(refiid, &IID_IUnknown) || IsEqualIID(refiid, &IID_IMalloc)) {
317                 *obj = (LPMALLOC) &Shell_Malloc;
318                 return S_OK;
319         }
320         return E_NOINTERFACE;
321 }
322
323 /******************************************************************************
324  *              IShellMalloc_AddRefRelease        [VTABLE]
325  */
326 static ULONG WINAPI IShellMalloc_fnAddRefRelease(LPMALLOC iface)
327 {
328         return 1;
329 }
330
331 /******************************************************************************
332  *              IShellMalloc_Alloc [VTABLE]
333  */
334 static LPVOID WINAPI IShellMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
335 {
336         LPVOID addr;
337
338         addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
339         TRACE("(%p,%ld);\n",addr,cb);
340         return addr;
341 }
342
343 /******************************************************************************
344  *              IShellMalloc_Realloc [VTABLE]
345  */
346 static LPVOID WINAPI IShellMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
347 {
348         LPVOID addr;
349
350         if (pv) {
351                 if (cb) {
352                         addr = (LPVOID) LocalReAlloc((HANDLE) pv, cb, GMEM_ZEROINIT | GMEM_MOVEABLE);
353                 } else {
354                         LocalFree((HANDLE) pv);
355                         addr = NULL;
356                 }
357         } else {
358                 if (cb) {
359                         addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
360                 } else {
361                         addr = NULL;
362                 }
363         }
364
365         TRACE("(%p->%p,%ld)\n",pv,addr,cb);
366         return addr;
367 }
368
369 /******************************************************************************
370  *              IShellMalloc_Free [VTABLE]
371  */
372 static VOID WINAPI IShellMalloc_fnFree(LPMALLOC iface, LPVOID pv)
373 {
374         TRACE("(%p)\n",pv);
375         LocalFree((HANDLE) pv);
376 }
377
378 /******************************************************************************
379  *              IShellMalloc_GetSize [VTABLE]
380  */
381 static DWORD WINAPI IShellMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
382 {
383         DWORD cb = (DWORD) LocalSize((HANDLE)pv);
384         TRACE("(%p,%ld)\n", pv, cb);
385         return cb;
386 }
387
388 /******************************************************************************
389  *              IShellMalloc_DidAlloc [VTABLE]
390  */
391 static INT WINAPI IShellMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
392 {
393         TRACE("(%p)\n",pv);
394         return -1;
395 }
396
397 /******************************************************************************
398  *              IShellMalloc_HeapMinimize [VTABLE]
399  */
400 static VOID WINAPI IShellMalloc_fnHeapMinimize(LPMALLOC iface)
401 {
402         TRACE("()\n");
403 }
404
405 static ICOM_VTABLE(IMalloc) VT_Shell_IMalloc32 =
406 {
407         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
408         IShellMalloc_fnQueryInterface,
409         IShellMalloc_fnAddRefRelease,
410         IShellMalloc_fnAddRefRelease,
411         IShellMalloc_fnAlloc,
412         IShellMalloc_fnRealloc,
413         IShellMalloc_fnFree,
414         IShellMalloc_fnGetSize,
415         IShellMalloc_fnDidAlloc,
416         IShellMalloc_fnHeapMinimize
417 };
418
419 /*************************************************************************
420  *                       SHGetMalloc                    [SHELL32.@]
421  * returns the interface to shell malloc.
422  *
423  * NOTES
424  *  uses OLE32.CoGetMalloc if OLE32.DLL is already loaded.
425  *  if not it uses a internal implementations as fallback.
426  */
427 DWORD WINAPI SHGetMalloc(LPMALLOC *lpmal)
428 {
429         HRESULT (WINAPI *pCoGetMalloc)(DWORD,LPMALLOC *);
430         HMODULE hOle32;
431
432         TRACE("(%p)\n", lpmal);
433
434         if (!ShellTaskAllocator)
435         {
436                 hOle32 = GetModuleHandleA("OLE32.DLL");
437                 if(hOle32) {
438                         pCoGetMalloc = (void*) GetProcAddress(hOle32, "CoGetMalloc");
439                         if (pCoGetMalloc) pCoGetMalloc(MEMCTX_TASK, &ShellTaskAllocator);
440                         TRACE("got ole32 IMalloc\n");
441                 }
442                 if(!ShellTaskAllocator) {
443                         ShellTaskAllocator = (IMalloc* ) &Shell_Malloc;
444                         TRACE("use fallback allocator\n");
445                 }
446         }
447         *lpmal = ShellTaskAllocator;
448         return  S_OK;
449 }
450
451 /*************************************************************************
452  * SHAlloc                                      [SHELL32.196]
453  *
454  * NOTES
455  *     exported by ordinal
456  */
457 LPVOID WINAPI SHAlloc(DWORD len)
458 {
459         IMalloc * ppv;
460         LPBYTE ret;
461
462         if (!ShellTaskAllocator) SHGetMalloc(&ppv);
463
464         ret = (LPVOID) IMalloc_Alloc(ShellTaskAllocator, len);
465         TRACE("%lu bytes at %p\n",len, ret);
466         return (LPVOID)ret;
467 }
468
469 /*************************************************************************
470  * SHFree                                       [SHELL32.195]
471  *
472  * NOTES
473  *     exported by ordinal
474  */
475 void WINAPI SHFree(LPVOID pv)
476 {
477         IMalloc * ppv;
478
479         TRACE("%p\n",pv);
480         if (!ShellTaskAllocator) SHGetMalloc(&ppv);
481         IMalloc_Free(ShellTaskAllocator, pv);
482 }
483
484 /*************************************************************************
485  * SHGetDesktopFolder                   [SHELL32.@]
486  */
487 DWORD WINAPI SHGetDesktopFolder(IShellFolder **psf)
488 {
489         HRESULT hres = S_OK;
490         TRACE("\n");
491
492         if(!psf) return E_INVALIDARG;
493         *psf = NULL;
494         hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
495
496         TRACE("-- %p->(%p)\n",psf, *psf);
497         return hres;
498 }
499 /**************************************************************************
500  * Default ClassFactory Implementation
501  *
502  * SHCreateDefClassObject
503  *
504  * NOTES
505  *  helper function for dll's without a own classfactory
506  *  a generic classfactory is returned
507  *  when the CreateInstance of the cf is called the callback is executed
508  */
509
510 typedef struct
511 {
512     ICOM_VFIELD(IClassFactory);
513     DWORD                       ref;
514     CLSID                       *rclsid;
515     LPFNCREATEINSTANCE          lpfnCI;
516     const IID *                 riidInst;
517     ULONG *                     pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
518 } IDefClFImpl;
519
520 static ICOM_VTABLE(IClassFactory) dclfvt;
521
522 /**************************************************************************
523  *  IDefClF_fnConstructor
524  */
525
526 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
527 {
528         IDefClFImpl* lpclf;
529
530         lpclf = (IDefClFImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
531         lpclf->ref = 1;
532         ICOM_VTBL(lpclf) = &dclfvt;
533         lpclf->lpfnCI = lpfnCI;
534         lpclf->pcRefDll = pcRefDll;
535
536         if (pcRefDll) InterlockedIncrement(pcRefDll);
537         lpclf->riidInst = riidInst;
538
539         TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
540         return (LPCLASSFACTORY)lpclf;
541 }
542 /**************************************************************************
543  *  IDefClF_fnQueryInterface
544  */
545 static HRESULT WINAPI IDefClF_fnQueryInterface(
546   LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
547 {
548         ICOM_THIS(IDefClFImpl,iface);
549
550         TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
551
552         *ppvObj = NULL;
553
554         if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
555           *ppvObj = This;
556           InterlockedIncrement(&This->ref);
557           return S_OK;
558         }
559
560         TRACE("-- E_NOINTERFACE\n");
561         return E_NOINTERFACE;
562 }
563 /******************************************************************************
564  * IDefClF_fnAddRef
565  */
566 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
567 {
568         ICOM_THIS(IDefClFImpl,iface);
569         TRACE("(%p)->(count=%lu)\n",This,This->ref);
570
571         return InterlockedIncrement(&This->ref);
572 }
573 /******************************************************************************
574  * IDefClF_fnRelease
575  */
576 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
577 {
578         ICOM_THIS(IDefClFImpl,iface);
579         TRACE("(%p)->(count=%lu)\n",This,This->ref);
580
581         if (!InterlockedDecrement(&This->ref))
582         {
583           if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
584
585           TRACE("-- destroying IClassFactory(%p)\n",This);
586           HeapFree(GetProcessHeap(),0,This);
587           return 0;
588         }
589         return This->ref;
590 }
591 /******************************************************************************
592  * IDefClF_fnCreateInstance
593  */
594 static HRESULT WINAPI IDefClF_fnCreateInstance(
595   LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
596 {
597         ICOM_THIS(IDefClFImpl,iface);
598
599         TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
600
601         *ppvObject = NULL;
602
603         if ( This->riidInst==NULL ||
604              IsEqualCLSID(riid, This->riidInst) ||
605              IsEqualCLSID(riid, &IID_IUnknown) )
606         {
607           return This->lpfnCI(pUnkOuter, riid, ppvObject);
608         }
609
610         ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
611         return E_NOINTERFACE;
612 }
613 /******************************************************************************
614  * IDefClF_fnLockServer
615  */
616 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
617 {
618         ICOM_THIS(IDefClFImpl,iface);
619         TRACE("%p->(0x%x), not implemented\n",This, fLock);
620         return E_NOTIMPL;
621 }
622
623 static ICOM_VTABLE(IClassFactory) dclfvt =
624 {
625     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
626     IDefClF_fnQueryInterface,
627     IDefClF_fnAddRef,
628   IDefClF_fnRelease,
629   IDefClF_fnCreateInstance,
630   IDefClF_fnLockServer
631 };
632
633 /******************************************************************************
634  * SHCreateDefClassObject                       [SHELL32.70]
635  */
636 HRESULT WINAPI SHCreateDefClassObject(
637         REFIID  riid,
638         LPVOID* ppv,
639         LPFNCREATEINSTANCE lpfnCI,      /* [in] create instance callback entry */
640         LPDWORD pcRefDll,               /* [in/out] ref count of the dll */
641         REFIID  riidInst)               /* [in] optional interface to the instance */
642 {
643         IClassFactory * pcf;
644
645         TRACE("%s %p %p %p %s\n",
646               shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
647
648         if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
649         if (! (pcf = IDefClF_fnConstructor(lpfnCI, pcRefDll, riidInst))) return E_OUTOFMEMORY;
650         *ppv = pcf;
651         return NOERROR;
652 }
653
654 /*************************************************************************
655  *  DragAcceptFiles             [SHELL32.54]
656  */
657 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
658 {
659         LONG exstyle;
660
661         if( !IsWindow(hWnd) ) return;
662         exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
663         if (b)
664           exstyle |= WS_EX_ACCEPTFILES;
665         else
666           exstyle &= ~WS_EX_ACCEPTFILES;
667         SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
668 }
669
670 /*************************************************************************
671  * DragFinish           [SHELL32.80]
672  */
673 void WINAPI DragFinish(HDROP h)
674 {
675         TRACE("\n");
676         GlobalFree((HGLOBAL)h);
677 }
678
679 /*************************************************************************
680  * DragQueryPoint               [SHELL32.135]
681  */
682 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
683 {
684         DROPFILES *lpDropFileStruct;
685         BOOL bRet;
686
687         TRACE("\n");
688
689         lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
690
691         *p = lpDropFileStruct->pt;
692         bRet = lpDropFileStruct->fNC;
693
694         GlobalUnlock(hDrop);
695         return bRet;
696 }
697
698 /*************************************************************************
699  *  DragQueryFile               [SHELL32.81]
700  *  DragQueryFileA              [SHELL32.82]
701  */
702 UINT WINAPI DragQueryFileA(
703         HDROP hDrop,
704         UINT lFile,
705         LPSTR lpszFile,
706         UINT lLength)
707 {
708         LPSTR lpDrop;
709         UINT i = 0;
710         DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
711
712         TRACE("(%p, %x, %p, %u)\n",     hDrop,lFile,lpszFile,lLength);
713
714         if(!lpDropFileStruct) goto end;
715
716         lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
717
718         if(lpDropFileStruct->fWide == TRUE) {
719             LPWSTR lpszFileW = NULL;
720
721             if(lpszFile) {
722                 lpszFileW = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
723                 if(lpszFileW == NULL) {
724                     goto end;
725                 }
726             }
727             i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
728
729             if(lpszFileW) {
730                 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
731                 HeapFree(GetProcessHeap(), 0, lpszFileW);
732             }
733             goto end;
734         }
735
736         while (i++ < lFile)
737         {
738           while (*lpDrop++); /* skip filename */
739           if (!*lpDrop)
740           {
741             i = (lFile == 0xFFFFFFFF) ? i : 0;
742             goto end;
743           }
744         }
745
746         i = strlen(lpDrop);
747         i++;
748         if (!lpszFile ) goto end;   /* needed buffer size */
749         i = (lLength > i) ? i : lLength;
750         lstrcpynA (lpszFile,  lpDrop,  i);
751 end:
752         GlobalUnlock(hDrop);
753         return i;
754 }
755
756 /*************************************************************************
757  *  DragQueryFileW              [SHELL32.133]
758  */
759 UINT WINAPI DragQueryFileW(
760         HDROP hDrop,
761         UINT lFile,
762         LPWSTR lpszwFile,
763         UINT lLength)
764 {
765         LPWSTR lpwDrop;
766         UINT i = 0;
767         DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
768
769         TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
770
771         if(!lpDropFileStruct) goto end;
772
773         lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
774
775         if(lpDropFileStruct->fWide == FALSE) {
776             LPSTR lpszFileA = NULL;
777
778             if(lpszwFile) {
779                 lpszFileA = (LPSTR) HeapAlloc(GetProcessHeap(), 0, lLength);
780                 if(lpszFileA == NULL) {
781                     goto end;
782                 }
783             }
784             i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
785
786             if(lpszFileA) {
787                 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
788                 HeapFree(GetProcessHeap(), 0, lpszFileA);
789             }
790             goto end;
791         }
792
793         i = 0;
794         while (i++ < lFile)
795         {
796           while (*lpwDrop++); /* skip filename */
797           if (!*lpwDrop)
798           {
799             i = (lFile == 0xFFFFFFFF) ? i : 0;
800             goto end;
801           }
802         }
803
804         i = strlenW(lpwDrop);
805         i++;
806         if ( !lpszwFile) goto end;   /* needed buffer size */
807
808         i = (lLength > i) ? i : lLength;
809         lstrcpynW (lpszwFile, lpwDrop, i);
810 end:
811         GlobalUnlock(hDrop);
812         return i;
813 }