Set the dll search path to the location specified in configure
[wine/multimedia.git] / dlls / shell32 / shellole.c
bloba743871c9be795c3cd4d96d4e173d6287a3c4d47
1 /*
2 * handling of SHELL32.DLL OLE-Objects
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
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.
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.
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
22 #include "config.h"
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
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"
38 #include "undocshell.h"
39 #include "wine/unicode.h"
40 #include "shell32_main.h"
42 #include "wine/debug.h"
43 #include "shlwapi.h"
44 #include "debughlp.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(shell);
48 extern HRESULT WINAPI IFSFolder_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
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'};
53 HINSTANCE hShellOle32 = 0;
54 /**************************************************************************
55 * Default ClassFactory types
57 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
58 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
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}
73 /*************************************************************************
74 * __CoCreateInstance [internal]
76 * NOTES
77 * wraper for late bound call to OLE32.DLL
80 HRESULT (WINAPI *pCoCreateInstance)(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv) = NULL;
82 void * __GetExternalFunc(HMODULE * phModule, LPCWSTR szModuleName, LPCSTR szProcName)
84 if (!*phModule) *phModule = GetModuleHandleW(szModuleName);
85 if (!*phModule) *phModule = LoadLibraryW(szModuleName);
86 if (*phModule) return GetProcAddress(*phModule, szProcName);
87 return NULL;
90 HRESULT __CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
92 if(!pCoCreateInstance) pCoCreateInstance = __GetExternalFunc(&hShellOle32, sOLE32, "CoCreateInstance");
93 if(!pCoCreateInstance) return E_FAIL;
94 return pCoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, ppv);
97 /*************************************************************************
98 * SHCoCreateInstance [SHELL32.102]
100 * NOTES
101 * exported by ordinal
104 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
106 DWORD WINAPI __SHGUIDToStringW (REFGUID guid, LPWSTR str)
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'};
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] );
122 /************************************************************************/
124 LRESULT WINAPI SHCoCreateInstance(
125 LPCSTR aclsid,
126 REFCLSID clsid,
127 LPUNKNOWN pUnkOuter,
128 REFIID refiid,
129 LPVOID *ppv)
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;
146 if(!ppv) return E_POINTER;
147 *ppv=NULL;
149 /* if the clsid is a string, convert it */
150 if (!clsid)
152 if (!aclsid) return REGDB_E_CLASSNOTREG;
153 SHCLSIDFromStringA(aclsid, &iid);
154 myclsid = &iid;
157 TRACE("(%p,%s,unk:%p,%s,%p)\n",
158 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
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);
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 );
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));
173 /* if the com object is inside shell32, omit use of ole32 */
174 bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));
176 RegCloseKey (hKey);
177 } else {
178 /* since we can't find it in the registry we try internally */
179 bLoadFromShell32 = TRUE;
182 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);
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));
189 } else if (bLoadWithoutCOM) {
191 /* load a external dll without ole32 */
192 HANDLE hLibrary;
193 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
194 DllGetClassObjectFunc DllGetClassObject;
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;
210 } else {
212 /* load a external dll in the usual way */
213 hres = __CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
214 goto end;
217 /* here we should have a ClassFactory */
218 if (!pcf) return E_ACCESSDENIED;
220 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
221 IClassFactory_Release(pcf);
222 end:
223 if(hres!=S_OK)
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");
230 TRACE("-- instance: %p\n",*ppv);
231 return hres;
234 /*************************************************************************
235 * DllGetClassObject [SHELL32.128]
237 HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
239 HRESULT hres = E_OUTOFMEMORY;
240 IClassFactory * pcf = NULL;
241 int i;
243 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
245 if (!ppv) return E_INVALIDARG;
246 *ppv = NULL;
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);
256 if (!pcf) {
257 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
258 return CLASS_E_CLASSNOTAVAILABLE;
261 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
262 IClassFactory_Release(pcf);
264 TRACE("-- pointer to class factory: %p\n",*ppv);
265 return hres;
268 /*************************************************************************
269 * SHCLSIDFromString [SHELL32.147]
271 * NOTES
272 * exported by ordinal
274 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
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 );
282 DWORD WINAPI SHCLSIDFromStringW (LPWSTR clsid, CLSID *id)
284 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
285 return CLSIDFromString(clsid, id);
287 DWORD WINAPI SHCLSIDFromStringAW (LPVOID clsid, CLSID *id)
289 if (SHELL_OsIsUnicode())
290 return SHCLSIDFromStringW (clsid, id);
291 return SHCLSIDFromStringA (clsid, id);
294 /*************************************************************************
295 * Shell Memory Allocator
298 /* set the vtable later */
299 extern ICOM_VTABLE(IMalloc) VT_Shell_IMalloc32;
301 /* this is the static object instance */
302 typedef struct {
303 ICOM_VFIELD(IMalloc);
304 DWORD dummy;
305 } _ShellMalloc;
307 _ShellMalloc Shell_Malloc = { &VT_Shell_IMalloc32,1};
309 /* this is the global allocator of shell32 */
310 IMalloc * ShellTaskAllocator = NULL;
312 /******************************************************************************
313 * IShellMalloc_QueryInterface [VTABLE]
315 static HRESULT WINAPI IShellMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid, LPVOID *obj)
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;
322 return E_NOINTERFACE;
325 /******************************************************************************
326 * IShellMalloc_AddRefRelease [VTABLE]
328 static ULONG WINAPI IShellMalloc_fnAddRefRelease(LPMALLOC iface)
330 return 1;
333 /******************************************************************************
334 * IShellMalloc_Alloc [VTABLE]
336 static LPVOID WINAPI IShellMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
338 LPVOID addr;
340 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
341 TRACE("(%p,%ld);\n",addr,cb);
342 return addr;
345 /******************************************************************************
346 * IShellMalloc_Realloc [VTABLE]
348 static LPVOID WINAPI IShellMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
350 LPVOID addr;
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;
359 } else {
360 if (cb) {
361 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
362 } else {
363 addr = NULL;
367 TRACE("(%p->%p,%ld)\n",pv,addr,cb);
368 return addr;
371 /******************************************************************************
372 * IShellMalloc_Free [VTABLE]
374 static VOID WINAPI IShellMalloc_fnFree(LPMALLOC iface, LPVOID pv)
376 TRACE("(%p)\n",pv);
377 LocalFree((HANDLE) pv);
380 /******************************************************************************
381 * IShellMalloc_GetSize [VTABLE]
383 static DWORD WINAPI IShellMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
385 DWORD cb = (DWORD) LocalSize((HANDLE)pv);
386 TRACE("(%p,%ld)\n", pv, cb);
387 return cb;
390 /******************************************************************************
391 * IShellMalloc_DidAlloc [VTABLE]
393 static INT WINAPI IShellMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
395 TRACE("(%p)\n",pv);
396 return -1;
399 /******************************************************************************
400 * IShellMalloc_HeapMinimize [VTABLE]
402 static VOID WINAPI IShellMalloc_fnHeapMinimize(LPMALLOC iface)
404 TRACE("()\n");
407 static ICOM_VTABLE(IMalloc) VT_Shell_IMalloc32 =
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
421 /*************************************************************************
422 * SHGetMalloc [SHELL32.@]
424 * Return the shell IMalloc interface.
426 * PARAMS
427 * lpmal [O] Destination for IMalloc interface.
429 * RETURNS
430 * Success: S_OK. lpmal contains the shells IMalloc interface.
431 * Failure. An HRESULT error code.
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.
437 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
439 HRESULT (WINAPI *pCoGetMalloc)(DWORD,LPMALLOC *);
440 HMODULE hOle32;
442 TRACE("(%p)\n", lpmal);
444 if (!ShellTaskAllocator)
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");
452 if(!ShellTaskAllocator) {
453 ShellTaskAllocator = (IMalloc* ) &Shell_Malloc;
454 TRACE("use fallback allocator\n");
457 *lpmal = ShellTaskAllocator;
458 return S_OK;
461 /*************************************************************************
462 * SHAlloc [SHELL32.196]
464 * NOTES
465 * exported by ordinal
467 LPVOID WINAPI SHAlloc(DWORD len)
469 IMalloc * ppv;
470 LPBYTE ret;
472 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
474 ret = (LPVOID) IMalloc_Alloc(ShellTaskAllocator, len);
475 TRACE("%lu bytes at %p\n",len, ret);
476 return (LPVOID)ret;
479 /*************************************************************************
480 * SHFree [SHELL32.195]
482 * NOTES
483 * exported by ordinal
485 void WINAPI SHFree(LPVOID pv)
487 IMalloc * ppv;
489 TRACE("%p\n",pv);
490 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
491 IMalloc_Free(ShellTaskAllocator, pv);
494 /*************************************************************************
495 * SHGetDesktopFolder [SHELL32.@]
497 DWORD WINAPI SHGetDesktopFolder(IShellFolder **psf)
499 HRESULT hres = S_OK;
500 TRACE("\n");
502 if(!psf) return E_INVALIDARG;
503 *psf = NULL;
504 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
506 TRACE("-- %p->(%p)\n",psf, *psf);
507 return hres;
509 /**************************************************************************
510 * Default ClassFactory Implementation
512 * SHCreateDefClassObject
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
520 typedef struct
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;
530 static ICOM_VTABLE(IClassFactory) dclfvt;
532 /**************************************************************************
533 * IDefClF_fnConstructor
536 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
538 IDefClFImpl* lpclf;
540 lpclf = (IDefClFImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
541 lpclf->ref = 1;
542 lpclf->lpVtbl = &dclfvt;
543 lpclf->lpfnCI = lpfnCI;
544 lpclf->pcRefDll = pcRefDll;
546 if (pcRefDll) InterlockedIncrement(pcRefDll);
547 lpclf->riidInst = riidInst;
549 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
550 return (LPCLASSFACTORY)lpclf;
552 /**************************************************************************
553 * IDefClF_fnQueryInterface
555 static HRESULT WINAPI IDefClF_fnQueryInterface(
556 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
558 ICOM_THIS(IDefClFImpl,iface);
560 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
562 *ppvObj = NULL;
564 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
565 *ppvObj = This;
566 InterlockedIncrement(&This->ref);
567 return S_OK;
570 TRACE("-- E_NOINTERFACE\n");
571 return E_NOINTERFACE;
573 /******************************************************************************
574 * IDefClF_fnAddRef
576 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
578 ICOM_THIS(IDefClFImpl,iface);
579 TRACE("(%p)->(count=%lu)\n",This,This->ref);
581 return InterlockedIncrement(&This->ref);
583 /******************************************************************************
584 * IDefClF_fnRelease
586 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
588 ICOM_THIS(IDefClFImpl,iface);
589 TRACE("(%p)->(count=%lu)\n",This,This->ref);
591 if (!InterlockedDecrement(&This->ref))
593 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
595 TRACE("-- destroying IClassFactory(%p)\n",This);
596 HeapFree(GetProcessHeap(),0,This);
597 return 0;
599 return This->ref;
601 /******************************************************************************
602 * IDefClF_fnCreateInstance
604 static HRESULT WINAPI IDefClF_fnCreateInstance(
605 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
607 ICOM_THIS(IDefClFImpl,iface);
609 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
611 *ppvObject = NULL;
613 if ( This->riidInst==NULL ||
614 IsEqualCLSID(riid, This->riidInst) ||
615 IsEqualCLSID(riid, &IID_IUnknown) )
617 return This->lpfnCI(pUnkOuter, riid, ppvObject);
620 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
621 return E_NOINTERFACE;
623 /******************************************************************************
624 * IDefClF_fnLockServer
626 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
628 ICOM_THIS(IDefClFImpl,iface);
629 TRACE("%p->(0x%x), not implemented\n",This, fLock);
630 return E_NOTIMPL;
633 static ICOM_VTABLE(IClassFactory) dclfvt =
635 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
636 IDefClF_fnQueryInterface,
637 IDefClF_fnAddRef,
638 IDefClF_fnRelease,
639 IDefClF_fnCreateInstance,
640 IDefClF_fnLockServer
643 /******************************************************************************
644 * SHCreateDefClassObject [SHELL32.70]
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 */
653 IClassFactory * pcf;
655 TRACE("%s %p %p %p %s\n",
656 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
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;
664 /*************************************************************************
665 * DragAcceptFiles [SHELL32.54]
667 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
669 LONG exstyle;
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);
680 /*************************************************************************
681 * DragFinish [SHELL32.80]
683 void WINAPI DragFinish(HDROP h)
685 TRACE("\n");
686 GlobalFree((HGLOBAL)h);
689 /*************************************************************************
690 * DragQueryPoint [SHELL32.135]
692 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
694 DROPFILES *lpDropFileStruct;
695 BOOL bRet;
697 TRACE("\n");
699 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
701 *p = lpDropFileStruct->pt;
702 bRet = lpDropFileStruct->fNC;
704 GlobalUnlock(hDrop);
705 return bRet;
708 /*************************************************************************
709 * DragQueryFile [SHELL32.81]
710 * DragQueryFileA [SHELL32.82]
712 UINT WINAPI DragQueryFileA(
713 HDROP hDrop,
714 UINT lFile,
715 LPSTR lpszFile,
716 UINT lLength)
718 LPSTR lpDrop;
719 UINT i = 0;
720 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
722 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
724 if(!lpDropFileStruct) goto end;
726 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
728 if(lpDropFileStruct->fWide == TRUE) {
729 LPWSTR lpszFileW = NULL;
731 if(lpszFile) {
732 lpszFileW = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
733 if(lpszFileW == NULL) {
734 goto end;
737 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
739 if(lpszFileW) {
740 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
741 HeapFree(GetProcessHeap(), 0, lpszFileW);
743 goto end;
746 while (i++ < lFile)
748 while (*lpDrop++); /* skip filename */
749 if (!*lpDrop)
751 i = (lFile == 0xFFFFFFFF) ? i : 0;
752 goto end;
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;
766 /*************************************************************************
767 * DragQueryFileW [SHELL32.133]
769 UINT WINAPI DragQueryFileW(
770 HDROP hDrop,
771 UINT lFile,
772 LPWSTR lpszwFile,
773 UINT lLength)
775 LPWSTR lpwDrop;
776 UINT i = 0;
777 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
779 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
781 if(!lpDropFileStruct) goto end;
783 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
785 if(lpDropFileStruct->fWide == FALSE) {
786 LPSTR lpszFileA = NULL;
788 if(lpszwFile) {
789 lpszFileA = (LPSTR) HeapAlloc(GetProcessHeap(), 0, lLength);
790 if(lpszFileA == NULL) {
791 goto end;
794 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
796 if(lpszFileA) {
797 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
798 HeapFree(GetProcessHeap(), 0, lpszFileA);
800 goto end;
803 i = 0;
804 while (i++ < lFile)
806 while (*lpwDrop++); /* skip filename */
807 if (!*lpwDrop)
809 i = (lFile == 0xFFFFFFFF) ? i : 0;
810 goto end;
814 i = strlenW(lpwDrop);
815 i++;
816 if ( !lpszwFile) goto end; /* needed buffer size */
818 i = (lLength > i) ? i : lLength;
819 lstrcpynW (lpszwFile, lpwDrop, i);
820 end:
821 GlobalUnlock(hDrop);
822 return i;