Change calls to CLSIDFromString to SHCLSIDFromStringW except in
[wine/wine-kai.git] / dlls / shell32 / shellole.c
blob1253c4459dd3db66b63dcb88670ee8c7ddee20b7
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 <stdlib.h>
25 #include <string.h>
27 #include "shellapi.h"
28 #include "shlobj.h"
29 #include "shlguid.h"
30 #include "winreg.h"
31 #include "winerror.h"
33 #include "undocshell.h"
34 #include "wine/unicode.h"
35 #include "shell32_main.h"
37 #include "wine/debug.h"
38 #include "shlwapi.h"
39 #include "winuser.h"
40 #include "debughlp.h"
41 #include "wine/obj_dragdrophelper.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(shell);
45 extern HRESULT WINAPI IFSFolder_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
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'};
50 HINSTANCE hShellOle32 = 0;
51 /**************************************************************************
52 * Default ClassFactory types
54 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
55 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
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}
70 /*************************************************************************
71 * __CoCreateInstance [internal]
73 * NOTES
74 * wraper for late bound call to OLE32.DLL
77 HRESULT (WINAPI *pCoCreateInstance)(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv) = NULL;
79 void * __GetExternalFunc(HMODULE * phModule, LPCWSTR szModuleName, LPCSTR szProcName)
81 if (!*phModule) *phModule = GetModuleHandleW(szModuleName);
82 if (!*phModule) *phModule = LoadLibraryW(szModuleName);
83 if (*phModule) return GetProcAddress(*phModule, szProcName);
84 return NULL;
87 HRESULT __CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
89 if(!pCoCreateInstance) pCoCreateInstance = __GetExternalFunc(&hShellOle32, sOLE32, "CoCreateInstance");
90 if(!pCoCreateInstance) return E_FAIL;
91 return pCoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, ppv);
94 /*************************************************************************
95 * SHCoCreateInstance [SHELL32.102]
97 * NOTES
98 * exported by ordinal
101 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
103 DWORD WINAPI __SHGUIDToStringW (REFGUID guid, LPWSTR str)
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'};
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] );
119 /************************************************************************/
121 LRESULT WINAPI SHCoCreateInstance(
122 LPCSTR aclsid,
123 REFCLSID clsid,
124 LPUNKNOWN pUnkOuter,
125 REFIID refiid,
126 LPVOID *ppv)
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;
143 if(!ppv) return E_POINTER;
144 *ppv=NULL;
146 /* if the clsid is a string, convert it */
147 if (!clsid)
149 if (!aclsid) return REGDB_E_CLASSNOTREG;
150 SHCLSIDFromStringA(aclsid, &iid);
151 myclsid = &iid;
154 TRACE("(%p,%s,unk:%p,%s,%p)\n",
155 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
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);
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 );
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));
170 /* if the com object is inside shell32, omit use of ole32 */
171 bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));
173 RegCloseKey (hKey);
174 } else {
175 /* since we can't find it in the registry we try internally */
176 bLoadFromShell32 = TRUE;
179 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);
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));
186 } else if (bLoadWithoutCOM) {
188 /* load a external dll without ole32 */
189 HANDLE hLibrary;
190 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
191 DllGetClassObjectFunc DllGetClassObject;
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;
207 } else {
209 /* load a external dll in the usual way */
210 hres = __CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
211 goto end;
214 /* here we should have a ClassFactory */
215 if (!pcf) return E_ACCESSDENIED;
217 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
218 IClassFactory_Release(pcf);
219 end:
220 if(hres!=S_OK)
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");
227 TRACE("-- instance: %p\n",*ppv);
228 return hres;
231 /*************************************************************************
232 * DllGetClassObject [SHELL32.128]
234 HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
236 HRESULT hres = E_OUTOFMEMORY;
237 IClassFactory * pcf = NULL;
238 int i;
240 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
242 if (!ppv) return E_INVALIDARG;
243 *ppv = NULL;
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);
253 if (!pcf) {
254 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
255 return CLASS_E_CLASSNOTAVAILABLE;
258 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
259 IClassFactory_Release(pcf);
261 TRACE("-- pointer to class factory: %p\n",*ppv);
262 return hres;
265 /*************************************************************************
266 * SHCLSIDFromString [SHELL32.147]
268 * NOTES
269 * exported by ordinal
271 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
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 );
279 DWORD WINAPI SHCLSIDFromStringW (LPWSTR clsid, CLSID *id)
281 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
282 return CLSIDFromString(clsid, id);
284 DWORD WINAPI SHCLSIDFromStringAW (LPVOID clsid, CLSID *id)
286 if (SHELL_OsIsUnicode())
287 return SHCLSIDFromStringW (clsid, id);
288 return SHCLSIDFromStringA (clsid, id);
291 /*************************************************************************
292 * Shell Memory Allocator
295 /* set the vtable later */
296 extern ICOM_VTABLE(IMalloc) VT_Shell_IMalloc32;
298 /* this is the static object instance */
299 typedef struct {
300 ICOM_VFIELD(IMalloc);
301 DWORD dummy;
302 } _ShellMalloc;
304 _ShellMalloc Shell_Malloc = { &VT_Shell_IMalloc32,1};
306 /* this is the global allocator of shell32 */
307 IMalloc * ShellTaskAllocator = NULL;
309 /******************************************************************************
310 * IShellMalloc_QueryInterface [VTABLE]
312 static HRESULT WINAPI IShellMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid, LPVOID *obj)
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;
319 return E_NOINTERFACE;
322 /******************************************************************************
323 * IShellMalloc_AddRefRelease [VTABLE]
325 static ULONG WINAPI IShellMalloc_fnAddRefRelease(LPMALLOC iface)
327 return 1;
330 /******************************************************************************
331 * IShellMalloc_Alloc [VTABLE]
333 static LPVOID WINAPI IShellMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
335 LPVOID addr;
337 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
338 TRACE("(%p,%ld);\n",addr,cb);
339 return addr;
342 /******************************************************************************
343 * IShellMalloc_Realloc [VTABLE]
345 static LPVOID WINAPI IShellMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
347 LPVOID addr;
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;
356 } else {
357 if (cb) {
358 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
359 } else {
360 addr = NULL;
364 TRACE("(%p->%p,%ld)\n",pv,addr,cb);
365 return addr;
368 /******************************************************************************
369 * IShellMalloc_Free [VTABLE]
371 static VOID WINAPI IShellMalloc_fnFree(LPMALLOC iface, LPVOID pv)
373 TRACE("(%p)\n",pv);
374 LocalFree((HANDLE) pv);
377 /******************************************************************************
378 * IShellMalloc_GetSize [VTABLE]
380 static DWORD WINAPI IShellMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
382 DWORD cb = (DWORD) LocalSize((HANDLE)pv);
383 TRACE("(%p,%ld)\n", pv, cb);
384 return cb;
387 /******************************************************************************
388 * IShellMalloc_DidAlloc [VTABLE]
390 static INT WINAPI IShellMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
392 TRACE("(%p)\n",pv);
393 return -1;
396 /******************************************************************************
397 * IShellMalloc_HeapMinimize [VTABLE]
399 static VOID WINAPI IShellMalloc_fnHeapMinimize(LPMALLOC iface)
401 TRACE("()\n");
404 static ICOM_VTABLE(IMalloc) VT_Shell_IMalloc32 =
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
418 /*************************************************************************
419 * SHGetMalloc [SHELL32.@]
420 * returns the interface to shell malloc.
422 * NOTES
423 * uses OLE32.CoGetMalloc if OLE32.DLL is already loaded.
424 * if not it uses a internal implementations as fallback.
426 DWORD WINAPI SHGetMalloc(LPMALLOC *lpmal)
428 HRESULT (WINAPI *pCoGetMalloc)(DWORD,LPMALLOC *);
429 HMODULE hOle32;
431 TRACE("(%p)\n", lpmal);
433 if (!ShellTaskAllocator)
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");
441 if(!ShellTaskAllocator) {
442 ShellTaskAllocator = (IMalloc* ) &Shell_Malloc;
443 TRACE("use fallback allocator\n");
446 *lpmal = ShellTaskAllocator;
447 return S_OK;
450 /*************************************************************************
451 * SHAlloc [SHELL32.196]
453 * NOTES
454 * exported by ordinal
456 LPVOID WINAPI SHAlloc(DWORD len)
458 IMalloc * ppv;
459 LPBYTE ret;
461 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
463 ret = (LPVOID) IMalloc_Alloc(ShellTaskAllocator, len);
464 TRACE("%lu bytes at %p\n",len, ret);
465 return (LPVOID)ret;
468 /*************************************************************************
469 * SHFree [SHELL32.195]
471 * NOTES
472 * exported by ordinal
474 void WINAPI SHFree(LPVOID pv)
476 IMalloc * ppv;
478 TRACE("%p\n",pv);
479 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
480 IMalloc_Free(ShellTaskAllocator, pv);
483 /*************************************************************************
484 * SHGetDesktopFolder [SHELL32.@]
486 DWORD WINAPI SHGetDesktopFolder(IShellFolder **psf)
488 HRESULT hres = S_OK;
489 TRACE("\n");
491 if(!psf) return E_INVALIDARG;
492 *psf = NULL;
493 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
495 TRACE("-- %p->(%p)\n",psf, *psf);
496 return hres;
498 /**************************************************************************
499 * Default ClassFactory Implementation
501 * SHCreateDefClassObject
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
509 typedef struct
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;
519 static ICOM_VTABLE(IClassFactory) dclfvt;
521 /**************************************************************************
522 * IDefClF_fnConstructor
525 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
527 IDefClFImpl* lpclf;
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;
535 if (pcRefDll) InterlockedIncrement(pcRefDll);
536 lpclf->riidInst = riidInst;
538 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
539 return (LPCLASSFACTORY)lpclf;
541 /**************************************************************************
542 * IDefClF_fnQueryInterface
544 static HRESULT WINAPI IDefClF_fnQueryInterface(
545 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
547 ICOM_THIS(IDefClFImpl,iface);
549 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
551 *ppvObj = NULL;
553 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
554 *ppvObj = This;
555 InterlockedIncrement(&This->ref);
556 return S_OK;
559 TRACE("-- E_NOINTERFACE\n");
560 return E_NOINTERFACE;
562 /******************************************************************************
563 * IDefClF_fnAddRef
565 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
567 ICOM_THIS(IDefClFImpl,iface);
568 TRACE("(%p)->(count=%lu)\n",This,This->ref);
570 return InterlockedIncrement(&This->ref);
572 /******************************************************************************
573 * IDefClF_fnRelease
575 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
577 ICOM_THIS(IDefClFImpl,iface);
578 TRACE("(%p)->(count=%lu)\n",This,This->ref);
580 if (!InterlockedDecrement(&This->ref))
582 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
584 TRACE("-- destroying IClassFactory(%p)\n",This);
585 HeapFree(GetProcessHeap(),0,This);
586 return 0;
588 return This->ref;
590 /******************************************************************************
591 * IDefClF_fnCreateInstance
593 static HRESULT WINAPI IDefClF_fnCreateInstance(
594 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
596 ICOM_THIS(IDefClFImpl,iface);
598 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
600 *ppvObject = NULL;
602 if ( This->riidInst==NULL ||
603 IsEqualCLSID(riid, This->riidInst) ||
604 IsEqualCLSID(riid, &IID_IUnknown) )
606 return This->lpfnCI(pUnkOuter, riid, ppvObject);
609 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
610 return E_NOINTERFACE;
612 /******************************************************************************
613 * IDefClF_fnLockServer
615 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
617 ICOM_THIS(IDefClFImpl,iface);
618 TRACE("%p->(0x%x), not implemented\n",This, fLock);
619 return E_NOTIMPL;
622 static ICOM_VTABLE(IClassFactory) dclfvt =
624 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
625 IDefClF_fnQueryInterface,
626 IDefClF_fnAddRef,
627 IDefClF_fnRelease,
628 IDefClF_fnCreateInstance,
629 IDefClF_fnLockServer
632 /******************************************************************************
633 * SHCreateDefClassObject [SHELL32.70]
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 */
642 IClassFactory * pcf;
644 TRACE("%s %p %p %p %s\n",
645 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
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;
653 /*************************************************************************
654 * DragAcceptFiles [SHELL32.54]
656 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
658 LONG exstyle;
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);
669 /*************************************************************************
670 * DragFinish [SHELL32.80]
672 void WINAPI DragFinish(HDROP h)
674 TRACE("\n");
675 GlobalFree((HGLOBAL)h);
678 /*************************************************************************
679 * DragQueryPoint [SHELL32.135]
681 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
683 DROPFILES *lpDropFileStruct;
684 BOOL bRet;
686 TRACE("\n");
688 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
690 *p = lpDropFileStruct->pt;
691 bRet = lpDropFileStruct->fNC;
693 GlobalUnlock(hDrop);
694 return bRet;
697 /*************************************************************************
698 * DragQueryFile [SHELL32.81]
699 * DragQueryFileA [SHELL32.82]
701 UINT WINAPI DragQueryFileA(
702 HDROP hDrop,
703 UINT lFile,
704 LPSTR lpszFile,
705 UINT lLength)
707 LPSTR lpDrop;
708 UINT i = 0;
709 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
711 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
713 if(!lpDropFileStruct) goto end;
715 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
717 if(lpDropFileStruct->fWide == TRUE) {
718 LPWSTR lpszFileW = NULL;
720 if(lpszFile) {
721 lpszFileW = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
722 if(lpszFileW == NULL) {
723 goto end;
726 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
728 if(lpszFileW) {
729 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
730 HeapFree(GetProcessHeap(), 0, lpszFileW);
732 goto end;
735 while (i++ < lFile)
737 while (*lpDrop++); /* skip filename */
738 if (!*lpDrop)
740 i = (lFile == 0xFFFFFFFF) ? i : 0;
741 goto end;
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;
755 /*************************************************************************
756 * DragQueryFileW [SHELL32.133]
758 UINT WINAPI DragQueryFileW(
759 HDROP hDrop,
760 UINT lFile,
761 LPWSTR lpszwFile,
762 UINT lLength)
764 LPWSTR lpwDrop;
765 UINT i = 0;
766 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
768 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
770 if(!lpDropFileStruct) goto end;
772 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
774 if(lpDropFileStruct->fWide == FALSE) {
775 LPSTR lpszFileA = NULL;
777 if(lpszwFile) {
778 lpszFileA = (LPSTR) HeapAlloc(GetProcessHeap(), 0, lLength);
779 if(lpszFileA == NULL) {
780 goto end;
783 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
785 if(lpszFileA) {
786 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
787 HeapFree(GetProcessHeap(), 0, lpszFileA);
789 goto end;
792 i = 0;
793 while (i++ < lFile)
795 while (*lpwDrop++); /* skip filename */
796 if (!*lpwDrop)
798 i = (lFile == 0xFFFFFFFF) ? i : 0;
799 goto end;
803 i = strlenW(lpwDrop);
804 i++;
805 if ( !lpszwFile) goto end; /* needed buffer size */
807 i = (lLength > i) ? i : lLength;
808 lstrcpynW (lpszwFile, lpwDrop, i);
809 end:
810 GlobalUnlock(hDrop);
811 return i;