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