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