inetcpl: German translation for the content property sheet.
[wine.git] / dlls / shell32 / shellole.c
blob6d284b52cf0481409ad04d6a31d3e39208e38ce7
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "shellapi.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "shlobj.h"
36 #include "shlguid.h"
37 #include "winreg.h"
38 #include "winerror.h"
40 #include "undocshell.h"
41 #include "wine/unicode.h"
42 #include "shell32_main.h"
44 #include "wine/debug.h"
45 #include "shlwapi.h"
46 #include "debughlp.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 extern INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax); /* shlwapi.24 */
52 /**************************************************************************
53 * Default ClassFactory types
55 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
56 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
58 /* this table contains all CLSID's of shell32 objects */
59 static const struct {
60 REFIID riid;
61 LPFNCREATEINSTANCE lpfnCI;
62 } InterfaceTable[] = {
64 {&CLSID_AutoComplete, IAutoComplete_Constructor},
65 {&CLSID_ControlPanel, IControlPanel_Constructor},
66 {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
67 {&CLSID_FolderShortcut, FolderShortcut_Constructor},
68 {&CLSID_MyComputer, ISF_MyComputer_Constructor},
69 {&CLSID_MyDocuments, MyDocuments_Constructor},
70 {&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
71 {&CLSID_Printers, Printers_Constructor},
72 {&CLSID_QueryAssociations, QueryAssociations_Constructor},
73 {&CLSID_RecycleBin, RecycleBin_Constructor},
74 {&CLSID_ShellDesktop, ISF_Desktop_Constructor},
75 {&CLSID_ShellFSFolder, IFSFolder_Constructor},
76 {&CLSID_ShellItem, IShellItem_Constructor},
77 {&CLSID_ShellLink, IShellLink_Constructor},
78 {&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
79 {&CLSID_UnixFolder, UnixFolder_Constructor},
80 {&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
81 {&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
82 {NULL, NULL}
85 /*************************************************************************
86 * SHCoCreateInstance [SHELL32.102]
88 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
89 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
90 * SHLoadOLE for details.
92 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
93 * shell32.dll the function will load the object manually without the help of ole32
95 * NOTES
96 * exported by ordinal
98 * SEE ALSO
99 * CoCreateInstace, SHLoadOLE
101 HRESULT WINAPI SHCoCreateInstance(
102 LPCWSTR aclsid,
103 const CLSID *clsid,
104 LPUNKNOWN pUnkOuter,
105 REFIID refiid,
106 LPVOID *ppv)
108 DWORD hres;
109 IID iid;
110 const CLSID * myclsid = clsid;
111 WCHAR sKeyName[MAX_PATH];
112 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
113 WCHAR sClassID[60];
114 const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
115 const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
116 WCHAR sDllPath[MAX_PATH];
117 HKEY hKey = 0;
118 DWORD dwSize;
119 IClassFactory * pcf = NULL;
121 if(!ppv) return E_POINTER;
122 *ppv=NULL;
124 /* if the clsid is a string, convert it */
125 if (!clsid)
127 if (!aclsid) return REGDB_E_CLASSNOTREG;
128 SHCLSIDFromStringW(aclsid, &iid);
129 myclsid = &iid;
132 TRACE("(%p,%s,unk:%p,%s,%p)\n",
133 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
135 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
137 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
138 IClassFactory_Release(pcf);
139 goto end;
142 /* we look up the dll path in the registry */
143 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
144 lstrcpyW(sKeyName, sCLSID);
145 lstrcatW(sKeyName, sClassID);
146 lstrcatW(sKeyName, sInProcServer32);
148 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
149 return E_ACCESSDENIED;
151 /* if a special registry key is set, we load a shell extension without help of OLE32 */
152 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
154 /* load an external dll without ole32 */
155 HANDLE hLibrary;
156 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
157 DllGetClassObjectFunc DllGetClassObject;
159 dwSize = sizeof(sDllPath);
160 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
162 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
163 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
164 hres = E_ACCESSDENIED;
165 goto end;
166 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
167 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
168 FreeLibrary( hLibrary );
169 hres = E_ACCESSDENIED;
170 goto end;
171 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
172 TRACE("GetClassObject failed 0x%08x\n", hres);
173 goto end;
176 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
177 IClassFactory_Release(pcf);
178 } else {
180 /* load an external dll in the usual way */
181 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
184 end:
185 if (hKey) RegCloseKey(hKey);
186 if(hres!=S_OK)
188 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
189 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
190 ERR("class not found in registry\n");
193 TRACE("-- instance: %p\n",*ppv);
194 return hres;
197 /*************************************************************************
198 * DllGetClassObject [SHELL32.@]
199 * SHDllGetClassObject [SHELL32.128]
201 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
203 HRESULT hres = E_OUTOFMEMORY;
204 IClassFactory * pcf = NULL;
205 int i;
207 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
209 if (!ppv) return E_INVALIDARG;
210 *ppv = NULL;
212 /* search our internal interface table */
213 for(i=0;InterfaceTable[i].riid;i++) {
214 if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
215 TRACE("index[%u]\n", i);
216 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
220 if (!pcf) {
221 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
222 return CLASS_E_CLASSNOTAVAILABLE;
225 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
226 IClassFactory_Release(pcf);
228 TRACE("-- pointer to class factory: %p\n",*ppv);
229 return hres;
232 /*************************************************************************
233 * SHCLSIDFromString [SHELL32.147]
235 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
236 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
238 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
240 * NOTES
241 * exported by ordinal
243 * SEE ALSO
244 * CLSIDFromString, SHLoadOLE
246 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
248 WCHAR buffer[40];
249 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
250 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
251 return CO_E_CLASSSTRING;
252 return CLSIDFromString( buffer, id );
254 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
256 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
257 return CLSIDFromString(clsid, id);
259 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
261 if (SHELL_OsIsUnicode())
262 return SHCLSIDFromStringW (clsid, id);
263 return SHCLSIDFromStringA (clsid, id);
266 /*************************************************************************
267 * SHGetMalloc [SHELL32.@]
269 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
270 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
271 * see SHLoadOLE for details.
273 * PARAMS
274 * lpmal [O] Destination for IMalloc interface.
276 * RETURNS
277 * Success: S_OK. lpmal contains the shells IMalloc interface.
278 * Failure. An HRESULT error code.
280 * SEE ALSO
281 * CoGetMalloc, SHLoadOLE
283 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
285 TRACE("(%p)\n", lpmal);
286 return CoGetMalloc(MEMCTX_TASK, lpmal);
289 /*************************************************************************
290 * SHAlloc [SHELL32.196]
292 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
293 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
294 * see SHLoadOLE for details.
296 * NOTES
297 * exported by ordinal
299 * SEE ALSO
300 * CoTaskMemAlloc, SHLoadOLE
302 LPVOID WINAPI SHAlloc(DWORD len)
304 LPVOID ret;
306 ret = CoTaskMemAlloc(len);
307 TRACE("%u bytes at %p\n",len, ret);
308 return ret;
311 /*************************************************************************
312 * SHFree [SHELL32.195]
314 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
315 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
316 * see SHLoadOLE for details.
318 * NOTES
319 * exported by ordinal
321 * SEE ALSO
322 * CoTaskMemFree, SHLoadOLE
324 void WINAPI SHFree(LPVOID pv)
326 TRACE("%p\n",pv);
327 CoTaskMemFree(pv);
330 /*************************************************************************
331 * SHGetDesktopFolder [SHELL32.@]
333 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
335 HRESULT hres;
337 TRACE("(%p)\n", psf);
339 if(!psf) return E_INVALIDARG;
341 *psf = NULL;
342 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
344 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
345 return hres;
347 /**************************************************************************
348 * Default ClassFactory Implementation
350 * SHCreateDefClassObject
352 * NOTES
353 * Helper function for dlls without their own classfactory.
354 * A generic classfactory is returned.
355 * When the CreateInstance of the cf is called the callback is executed.
358 typedef struct
360 const IClassFactoryVtbl *lpVtbl;
361 LONG ref;
362 CLSID *rclsid;
363 LPFNCREATEINSTANCE lpfnCI;
364 const IID * riidInst;
365 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
366 } IDefClFImpl;
368 static const IClassFactoryVtbl dclfvt;
370 /**************************************************************************
371 * IDefClF_fnConstructor
374 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
376 IDefClFImpl* lpclf;
378 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
379 lpclf->ref = 1;
380 lpclf->lpVtbl = &dclfvt;
381 lpclf->lpfnCI = lpfnCI;
382 lpclf->pcRefDll = pcRefDll;
384 if (pcRefDll) InterlockedIncrement(pcRefDll);
385 lpclf->riidInst = riidInst;
387 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
388 return (LPCLASSFACTORY)lpclf;
390 /**************************************************************************
391 * IDefClF_fnQueryInterface
393 static HRESULT WINAPI IDefClF_fnQueryInterface(
394 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
396 IDefClFImpl *This = (IDefClFImpl *)iface;
398 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
400 *ppvObj = NULL;
402 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
403 *ppvObj = This;
404 InterlockedIncrement(&This->ref);
405 return S_OK;
408 TRACE("-- E_NOINTERFACE\n");
409 return E_NOINTERFACE;
411 /******************************************************************************
412 * IDefClF_fnAddRef
414 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
416 IDefClFImpl *This = (IDefClFImpl *)iface;
417 ULONG refCount = InterlockedIncrement(&This->ref);
419 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
421 return refCount;
423 /******************************************************************************
424 * IDefClF_fnRelease
426 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
428 IDefClFImpl *This = (IDefClFImpl *)iface;
429 ULONG refCount = InterlockedDecrement(&This->ref);
431 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
433 if (!refCount)
435 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
437 TRACE("-- destroying IClassFactory(%p)\n",This);
438 HeapFree(GetProcessHeap(),0,This);
439 return 0;
441 return refCount;
443 /******************************************************************************
444 * IDefClF_fnCreateInstance
446 static HRESULT WINAPI IDefClF_fnCreateInstance(
447 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
449 IDefClFImpl *This = (IDefClFImpl *)iface;
451 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
453 *ppvObject = NULL;
455 if ( This->riidInst==NULL ||
456 IsEqualCLSID(riid, This->riidInst) ||
457 IsEqualCLSID(riid, &IID_IUnknown) )
459 return This->lpfnCI(pUnkOuter, riid, ppvObject);
462 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
463 return E_NOINTERFACE;
465 /******************************************************************************
466 * IDefClF_fnLockServer
468 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
470 IDefClFImpl *This = (IDefClFImpl *)iface;
471 TRACE("%p->(0x%x), not implemented\n",This, fLock);
472 return E_NOTIMPL;
475 static const IClassFactoryVtbl dclfvt =
477 IDefClF_fnQueryInterface,
478 IDefClF_fnAddRef,
479 IDefClF_fnRelease,
480 IDefClF_fnCreateInstance,
481 IDefClF_fnLockServer
484 /******************************************************************************
485 * SHCreateDefClassObject [SHELL32.70]
487 HRESULT WINAPI SHCreateDefClassObject(
488 REFIID riid,
489 LPVOID* ppv,
490 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
491 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
492 REFIID riidInst) /* [in] optional interface to the instance */
494 IClassFactory * pcf;
496 TRACE("%s %p %p %p %s\n",
497 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
499 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
500 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
501 *ppv = pcf;
502 return NOERROR;
505 /*************************************************************************
506 * DragAcceptFiles [SHELL32.@]
508 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
510 LONG exstyle;
512 if( !IsWindow(hWnd) ) return;
513 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
514 if (b)
515 exstyle |= WS_EX_ACCEPTFILES;
516 else
517 exstyle &= ~WS_EX_ACCEPTFILES;
518 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
521 /*************************************************************************
522 * DragFinish [SHELL32.@]
524 void WINAPI DragFinish(HDROP h)
526 TRACE("\n");
527 GlobalFree(h);
530 /*************************************************************************
531 * DragQueryPoint [SHELL32.@]
533 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
535 DROPFILES *lpDropFileStruct;
536 BOOL bRet;
538 TRACE("\n");
540 lpDropFileStruct = GlobalLock(hDrop);
542 *p = lpDropFileStruct->pt;
543 bRet = lpDropFileStruct->fNC;
545 GlobalUnlock(hDrop);
546 return bRet;
549 /*************************************************************************
550 * DragQueryFileA [SHELL32.@]
551 * DragQueryFile [SHELL32.@]
553 UINT WINAPI DragQueryFileA(
554 HDROP hDrop,
555 UINT lFile,
556 LPSTR lpszFile,
557 UINT lLength)
559 LPSTR lpDrop;
560 UINT i = 0;
561 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
563 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
565 if(!lpDropFileStruct) goto end;
567 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
569 if(lpDropFileStruct->fWide) {
570 LPWSTR lpszFileW = NULL;
572 if(lpszFile) {
573 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
574 if(lpszFileW == NULL) {
575 goto end;
578 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
580 if(lpszFileW) {
581 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
582 HeapFree(GetProcessHeap(), 0, lpszFileW);
584 goto end;
587 while (i++ < lFile)
589 while (*lpDrop++); /* skip filename */
590 if (!*lpDrop)
592 i = (lFile == 0xFFFFFFFF) ? i : 0;
593 goto end;
597 i = strlen(lpDrop);
598 if (!lpszFile ) goto end; /* needed buffer size */
599 lstrcpynA (lpszFile, lpDrop, lLength);
600 end:
601 GlobalUnlock(hDrop);
602 return i;
605 /*************************************************************************
606 * DragQueryFileW [SHELL32.@]
608 UINT WINAPI DragQueryFileW(
609 HDROP hDrop,
610 UINT lFile,
611 LPWSTR lpszwFile,
612 UINT lLength)
614 LPWSTR lpwDrop;
615 UINT i = 0;
616 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
618 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
620 if(!lpDropFileStruct) goto end;
622 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
624 if(lpDropFileStruct->fWide == FALSE) {
625 LPSTR lpszFileA = NULL;
627 if(lpszwFile) {
628 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
629 if(lpszFileA == NULL) {
630 goto end;
633 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
635 if(lpszFileA) {
636 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
637 HeapFree(GetProcessHeap(), 0, lpszFileA);
639 goto end;
642 i = 0;
643 while (i++ < lFile)
645 while (*lpwDrop++); /* skip filename */
646 if (!*lpwDrop)
648 i = (lFile == 0xFFFFFFFF) ? i : 0;
649 goto end;
653 i = strlenW(lpwDrop);
654 if ( !lpszwFile) goto end; /* needed buffer size */
655 lstrcpynW (lpszwFile, lpwDrop, lLength);
656 end:
657 GlobalUnlock(hDrop);
658 return i;