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