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
24 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
26 static const WCHAR sShell32
[12] = {'S','H','E','L','L','3','2','.','D','L','L','\0'};
28 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
30 DWORD WINAPI
__SHGUIDToStringW (REFGUID guid
, LPWSTR str
)
32 WCHAR sFormat
[52] = {'{','%','0','8','l','x','-','%','0','4',
33 'x','-','%','0','4','x','-','%','0','2',
34 'x','%','0','2','x','-','%','0','2','x',
35 '%','0','2','x','%','0','2','x','%','0',
36 '2','x','%','0','2','x','%','0','2','x',
39 return swprintf ( str
, sFormat
,
40 guid
.Data1
, guid
.Data2
, guid
.Data3
,
41 guid
.Data4
[0], guid
.Data4
[1], guid
.Data4
[2], guid
.Data4
[3],
42 guid
.Data4
[4], guid
.Data4
[5], guid
.Data4
[6], guid
.Data4
[7] );
46 /*************************************************************************
47 * SHCoCreateInstance [SHELL32.102]
49 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
50 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
51 * SHLoadOLE for details.
53 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
54 * shell32.dll the function will load the object manually without the help of ole32
60 * CoCreateInstace, SHLoadOLE
62 HRESULT WINAPI
SHCoCreateInstance(
71 const CLSID
* myclsid
= clsid
;
72 WCHAR sKeyName
[MAX_PATH
];
73 const WCHAR sCLSID
[7] = {'C','L','S','I','D','\\','\0'};
75 const WCHAR sInProcServer32
[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
76 const WCHAR sLoadWithoutCOM
[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
77 WCHAR sDllPath
[MAX_PATH
];
80 BOOLEAN bLoadFromShell32
= FALSE
;
81 BOOLEAN bLoadWithoutCOM
= FALSE
;
82 CComPtr
<IClassFactory
> pcf
;
84 if(!ppv
) return E_POINTER
;
87 /* if the clsid is a string, convert it */
90 if (!aclsid
) return REGDB_E_CLASSNOTREG
;
91 CLSIDFromString((LPOLESTR
)aclsid
, &iid
);
95 TRACE("(%p,%s,unk:%p,%s,%p)\n",
96 aclsid
, shdebugstr_guid(myclsid
), pUnkOuter
, shdebugstr_guid(&refiid
), ppv
);
98 /* we look up the dll path in the registry */
99 __SHGUIDToStringW(*myclsid
, sClassID
);
100 wcscpy(sKeyName
, sCLSID
);
101 wcscat(sKeyName
, sClassID
);
102 wcscat(sKeyName
, sInProcServer32
);
104 if (ERROR_SUCCESS
== RegOpenKeyExW(HKEY_CLASSES_ROOT
, sKeyName
, 0, KEY_READ
, &hKey
)) {
105 dwSize
= sizeof(sDllPath
);
106 SHQueryValueExW(hKey
, NULL
, 0,0, sDllPath
, &dwSize
);
108 /* if a special registry key is set, we load a shell extension without help of OLE32 */
109 bLoadWithoutCOM
= (ERROR_SUCCESS
== SHQueryValueExW(hKey
, sLoadWithoutCOM
, 0, 0, 0, 0));
111 /* if the com object is inside shell32, omit use of ole32 */
112 bLoadFromShell32
= (0==lstrcmpiW( PathFindFileNameW(sDllPath
), sShell32
));
116 /* since we can't find it in the registry we try internally */
117 bLoadFromShell32
= TRUE
;
120 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM
, bLoadFromShell32
);
122 /* now we create an instance */
123 if (bLoadFromShell32
) {
124 if (! SUCCEEDED(DllGetClassObject(*myclsid
, IID_PPV_ARG(IClassFactory
, &pcf
)))) {
125 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid
));
127 } else if (bLoadWithoutCOM
) {
129 /* load an external dll without ole32 */
131 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
, REFIID iid
, LPVOID
*ppv
);
132 DllGetClassObjectFunc DllGetClassObject
;
134 if ((hLibrary
= LoadLibraryExW(sDllPath
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
)) == 0) {
135 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath
));
136 hres
= E_ACCESSDENIED
;
138 } else if (!(DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress(hLibrary
, "DllGetClassObject"))) {
139 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath
));
140 FreeLibrary( hLibrary
);
141 hres
= E_ACCESSDENIED
;
143 } else if (! SUCCEEDED(hres
= DllGetClassObject(*myclsid
, IID_PPV_ARG(IClassFactory
, &pcf
)))) {
144 TRACE("GetClassObject failed 0x%08x\n", hres
);
150 /* load an external dll in the usual way */
151 hres
= CoCreateInstance(*myclsid
, pUnkOuter
, CLSCTX_INPROC_SERVER
, refiid
, ppv
);
155 /* here we should have a ClassFactory */
156 if (!pcf
) return E_ACCESSDENIED
;
158 hres
= pcf
->CreateInstance(pUnkOuter
, refiid
, ppv
);
162 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
163 hres
, shdebugstr_guid(myclsid
), shdebugstr_guid(&refiid
));
164 ERR("class not found in registry\n");
167 TRACE("-- instance: %p\n",*ppv
);
171 /*************************************************************************
172 * SHCLSIDFromString [SHELL32.147]
174 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
175 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
177 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
180 * exported by ordinal
183 * CLSIDFromString, SHLoadOLE
185 DWORD WINAPI
SHCLSIDFromStringA (LPCSTR clsid
, CLSID
*id
)
188 TRACE("(%p(%s) %p)\n", clsid
, clsid
, id
);
189 if (!MultiByteToWideChar( CP_ACP
, 0, clsid
, -1, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
190 return CO_E_CLASSSTRING
;
191 return CLSIDFromString( buffer
, id
);
194 DWORD WINAPI
SHCLSIDFromStringW (LPCWSTR clsid
, CLSID
*id
)
196 TRACE("(%p(%s) %p)\n", clsid
, debugstr_w(clsid
), id
);
197 return CLSIDFromString((LPWSTR
)clsid
, id
);
200 EXTERN_C DWORD WINAPI
SHCLSIDFromStringAW (LPCVOID clsid
, CLSID
*id
)
202 if (SHELL_OsIsUnicode())
203 return SHCLSIDFromStringW ((LPCWSTR
)clsid
, id
);
204 return SHCLSIDFromStringA ((LPCSTR
)clsid
, id
);
207 /*************************************************************************
208 * SHGetMalloc [SHELL32.@]
210 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
211 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
212 * see SHLoadOLE for details.
215 * lpmal [O] Destination for IMalloc interface.
218 * Success: S_OK. lpmal contains the shells IMalloc interface.
219 * Failure. An HRESULT error code.
222 * CoGetMalloc, SHLoadOLE
224 HRESULT WINAPI
SHGetMalloc(LPMALLOC
*lpmal
)
226 TRACE("(%p)\n", lpmal
);
227 return CoGetMalloc(MEMCTX_TASK
, lpmal
);
230 /*************************************************************************
231 * SHAlloc [SHELL32.196]
233 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
234 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
235 * see SHLoadOLE for details.
238 * exported by ordinal
241 * CoTaskMemAlloc, SHLoadOLE
243 LPVOID WINAPI
SHAlloc(SIZE_T len
)
247 ret
= CoTaskMemAlloc(len
);
248 TRACE("%u bytes at %p\n",len
, ret
);
252 /*************************************************************************
253 * SHFree [SHELL32.195]
255 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
256 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
257 * see SHLoadOLE for details.
260 * exported by ordinal
263 * CoTaskMemFree, SHLoadOLE
265 void WINAPI
SHFree(LPVOID pv
)
271 /*************************************************************************
272 * DragAcceptFiles [SHELL32.@]
274 void WINAPI
DragAcceptFiles(HWND hWnd
, BOOL b
)
278 if( !IsWindow(hWnd
) ) return;
279 exstyle
= GetWindowLongPtrA(hWnd
,GWL_EXSTYLE
);
281 exstyle
|= WS_EX_ACCEPTFILES
;
283 exstyle
&= ~WS_EX_ACCEPTFILES
;
284 SetWindowLongPtrA(hWnd
,GWL_EXSTYLE
,exstyle
);
287 /*************************************************************************
288 * DragFinish [SHELL32.@]
290 void WINAPI
DragFinish(HDROP h
)
293 GlobalFree((HGLOBAL
)h
);
296 /*************************************************************************
297 * DragQueryPoint [SHELL32.@]
299 BOOL WINAPI
DragQueryPoint(HDROP hDrop
, POINT
*p
)
301 DROPFILES
*lpDropFileStruct
;
306 lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
308 *p
= lpDropFileStruct
->pt
;
309 bRet
= lpDropFileStruct
->fNC
;
315 /*************************************************************************
316 * DragQueryFileA [SHELL32.@]
317 * DragQueryFile [SHELL32.@]
319 UINT WINAPI
DragQueryFileA(
327 DROPFILES
*lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
329 TRACE("(%p, %x, %p, %u)\n", hDrop
,lFile
,lpszFile
,lLength
);
331 if(!lpDropFileStruct
) goto end
;
333 lpDrop
= (LPSTR
) lpDropFileStruct
+ lpDropFileStruct
->pFiles
;
335 if(lpDropFileStruct
->fWide
) {
336 LPWSTR lpszFileW
= NULL
;
339 lpszFileW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, lLength
*sizeof(WCHAR
));
340 if(lpszFileW
== NULL
) {
344 i
= DragQueryFileW(hDrop
, lFile
, lpszFileW
, lLength
);
347 WideCharToMultiByte(CP_ACP
, 0, lpszFileW
, -1, lpszFile
, lLength
, 0, NULL
);
348 HeapFree(GetProcessHeap(), 0, lpszFileW
);
355 while (*lpDrop
++); /* skip filename */
358 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
364 if (!lpszFile
) goto end
; /* needed buffer size */
365 lstrcpynA (lpszFile
, lpDrop
, lLength
);
371 /*************************************************************************
372 * DragQueryFileW [SHELL32.@]
374 UINT WINAPI
DragQueryFileW(
382 DROPFILES
*lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
384 TRACE("(%p, %x, %p, %u)\n", hDrop
,lFile
,lpszwFile
,lLength
);
386 if(!lpDropFileStruct
) goto end
;
388 lpwDrop
= (LPWSTR
) ((LPSTR
)lpDropFileStruct
+ lpDropFileStruct
->pFiles
);
390 if(lpDropFileStruct
->fWide
== FALSE
) {
391 LPSTR lpszFileA
= NULL
;
394 lpszFileA
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, lLength
);
395 if(lpszFileA
== NULL
) {
399 i
= DragQueryFileA(hDrop
, lFile
, lpszFileA
, lLength
);
402 MultiByteToWideChar(CP_ACP
, 0, lpszFileA
, -1, lpszwFile
, lLength
);
403 HeapFree(GetProcessHeap(), 0, lpszFileA
);
411 while (*lpwDrop
++); /* skip filename */
414 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
420 if ( !lpszwFile
) goto end
; /* needed buffer size */
421 lstrcpynW (lpszwFile
, lpwDrop
, lLength
);
427 /*************************************************************************
428 * SHPropStgCreate [SHELL32.685]
430 EXTERN_C HRESULT WINAPI
SHPropStgCreate(IPropertySetStorage
*psstg
, REFFMTID fmtid
,
431 const CLSID
*pclsid
, DWORD grfFlags
, DWORD grfMode
,
432 DWORD dwDisposition
, IPropertyStorage
**ppstg
, UINT
*puCodePage
)
438 TRACE("%p %s %s %x %x %x %p %p\n", psstg
, debugstr_guid(&fmtid
), debugstr_guid(pclsid
),
439 grfFlags
, grfMode
, dwDisposition
, ppstg
, puCodePage
);
441 hres
= psstg
->Open(fmtid
, grfMode
, ppstg
);
443 switch (dwDisposition
)
449 hres
= psstg
->Delete(fmtid
);
458 hres
= psstg
->Create(fmtid
, pclsid
, grfFlags
, grfMode
, ppstg
);
466 prop
.ulKind
= PRSPEC_PROPID
;
467 prop
.propid
= PID_CODEPAGE
;
468 hres
= (*ppstg
)->ReadMultiple(1, &prop
, &ret
);
469 if (FAILED(hres
) || ret
.vt
!=VT_I2
)
472 *puCodePage
= ret
.iVal
;
479 /*************************************************************************
480 * SHPropStgReadMultiple [SHELL32.688]
482 EXTERN_C HRESULT WINAPI
SHPropStgReadMultiple(IPropertyStorage
*pps
, UINT uCodePage
,
483 ULONG cpspec
, const PROPSPEC
*rgpspec
, PROPVARIANT
*rgvar
)
488 FIXME("%p %u %u %p %p\n", pps
, uCodePage
, cpspec
, rgpspec
, rgvar
);
490 memset(rgvar
, 0, cpspec
*sizeof(PROPVARIANT
));
491 hres
= pps
->ReadMultiple(cpspec
, rgpspec
, rgvar
);
500 prop
.ulKind
= PRSPEC_PROPID
;
501 prop
.propid
= PID_CODEPAGE
;
502 hres
= pps
->ReadMultiple(1, &prop
, &ret
);
503 if(FAILED(hres
) || ret
.vt
!=VT_I2
)
506 uCodePage
= ret
.iVal
;
509 hres
= pps
->Stat(&stat
);
513 /* TODO: do something with codepage and stat */
517 /*************************************************************************
518 * SHPropStgWriteMultiple [SHELL32.689]
520 EXTERN_C HRESULT WINAPI
SHPropStgWriteMultiple(IPropertyStorage
*pps
, UINT
*uCodePage
,
521 ULONG cpspec
, const PROPSPEC
*rgpspec
, PROPVARIANT
*rgvar
, PROPID propidNameFirst
)
527 FIXME("%p %p %u %p %p %d\n", pps
, uCodePage
, cpspec
, rgpspec
, rgvar
, propidNameFirst
);
529 hres
= pps
->Stat(&stat
);
533 if (uCodePage
&& *uCodePage
)
534 codepage
= *uCodePage
;
540 prop
.ulKind
= PRSPEC_PROPID
;
541 prop
.propid
= PID_CODEPAGE
;
542 hres
= pps
->ReadMultiple(1, &prop
, &ret
);
545 if (ret
.vt
!=VT_I2
|| !ret
.iVal
)
550 *uCodePage
= codepage
;
553 /* TODO: do something with codepage and stat */
555 hres
= pps
->WriteMultiple(cpspec
, rgpspec
, rgvar
, propidNameFirst
);
559 /*************************************************************************
560 * SHCreateQueryCancelAutoPlayMoniker [SHELL32.@]
562 HRESULT WINAPI
SHCreateQueryCancelAutoPlayMoniker(IMoniker
**moniker
)
564 TRACE("%p\n", moniker
);
566 if (!moniker
) return E_INVALIDARG
;
567 return CreateClassMoniker(CLSID_QueryCancelAutoPlay
, moniker
);