[SHELL32]
[reactos.git] / dll / win32 / shell32 / shellord.cpp
1 /*
2 * The parameters of many functions changes between different OS versions
3 * (NT uses Unicode strings, 95 uses ASCII strings)
4 *
5 * Copyright 1997 Marcus Meissner
6 * 1998 J├╝rgen Schmied
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23 #include "precomp.h"
24
25 #include <mmsystem.h>
26 #include <commoncontrols.h>
27
28 WINE_DEFAULT_DEBUG_CHANNEL(shell);
29 WINE_DECLARE_DEBUG_CHANNEL(pidl);
30
31 /* FIXME: !!! move flags to header file !!! */
32 /* dwFlags */
33 #define MRUF_STRING_LIST 0 /* list will contain strings */
34 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
35 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
36
37 EXTERN_C HANDLE WINAPI CreateMRUListA(LPCREATEMRULISTA lpcml);
38 EXTERN_C INT WINAPI AddMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData);
39 EXTERN_C INT WINAPI FindMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
40 EXTERN_C INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
41
42
43 /* Get a function pointer from a DLL handle */
44 #define GET_FUNC(func, funcType, module, name, fail) \
45 do { \
46 if (!func) { \
47 if (!SHELL32_h##module && !(SHELL32_h##module = LoadLibraryA(#module ".dll"))) return fail; \
48 func = (funcType)GetProcAddress(SHELL32_h##module, name); \
49 if (!func) return fail; \
50 } \
51 } while (0)
52
53 /* Function pointers for GET_FUNC macro */
54 static HMODULE SHELL32_hshlwapi=NULL;
55
56
57 /*************************************************************************
58 * ParseFieldA [internal]
59 *
60 * copies a field from a ',' delimited string
61 *
62 * first field is nField = 1
63 */
64 DWORD WINAPI ParseFieldA(
65 LPCSTR src,
66 DWORD nField,
67 LPSTR dst,
68 DWORD len)
69 {
70 WARN("(%s,0x%08x,%p,%d) semi-stub.\n",debugstr_a(src),nField,dst,len);
71
72 if (!src || !src[0] || !dst || !len)
73 return 0;
74
75 /* skip n fields delimited by ',' */
76 while (nField > 1)
77 {
78 if (*src=='\0') return FALSE;
79 if (*(src++)==',') nField--;
80 }
81
82 /* copy part till the next ',' to dst */
83 while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
84
85 /* finalize the string */
86 *dst=0x0;
87
88 return TRUE;
89 }
90
91 /*************************************************************************
92 * ParseFieldW [internal]
93 *
94 * copies a field from a ',' delimited string
95 *
96 * first field is nField = 1
97 */
98 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
99 {
100 WARN("(%s,0x%08x,%p,%d) semi-stub.\n", debugstr_w(src), nField, dst, len);
101
102 if (!src || !src[0] || !dst || !len)
103 return 0;
104
105 /* skip n fields delimited by ',' */
106 while (nField > 1)
107 {
108 if (*src == 0x0) return FALSE;
109 if (*src++ == ',') nField--;
110 }
111
112 /* copy part till the next ',' to dst */
113 while ( *src != 0x0 && *src != ',' && (len--)>0 ) *(dst++) = *(src++);
114
115 /* finalize the string */
116 *dst = 0x0;
117
118 return TRUE;
119 }
120
121 /*************************************************************************
122 * ParseField [SHELL32.58]
123 */
124 EXTERN_C DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
125 {
126 if (SHELL_OsIsUnicode())
127 return ParseFieldW((LPCWSTR)src, nField, (LPWSTR)dst, len);
128 return ParseFieldA((LPCSTR)src, nField, (LPSTR)dst, len);
129 }
130
131 /*************************************************************************
132 * GetFileNameFromBrowse [SHELL32.63]
133 *
134 */
135 BOOL WINAPI GetFileNameFromBrowse(
136 HWND hwndOwner,
137 LPWSTR lpstrFile,
138 UINT nMaxFile,
139 LPCWSTR lpstrInitialDir,
140 LPCWSTR lpstrDefExt,
141 LPCWSTR lpstrFilter,
142 LPCWSTR lpstrTitle)
143 {
144 typedef BOOL (WINAPI *GetOpenFileNameProc)(OPENFILENAMEW *ofn);
145 HMODULE hmodule;
146 GetOpenFileNameProc pGetOpenFileNameW;
147 OPENFILENAMEW ofn;
148 BOOL ret;
149
150 TRACE("%p, %s, %d, %s, %s, %s, %s)\n",
151 hwndOwner, debugstr_w(lpstrFile), nMaxFile, lpstrInitialDir, lpstrDefExt,
152 lpstrFilter, lpstrTitle);
153
154 hmodule = LoadLibraryW(L"comdlg32.dll");
155 if(!hmodule) return FALSE;
156 pGetOpenFileNameW = (GetOpenFileNameProc)GetProcAddress(hmodule, "GetOpenFileNameW");
157 if(!pGetOpenFileNameW)
158 {
159 FreeLibrary(hmodule);
160 return FALSE;
161 }
162
163 memset(&ofn, 0, sizeof(ofn));
164
165 ofn.lStructSize = sizeof(ofn);
166 ofn.hwndOwner = hwndOwner;
167 ofn.lpstrFilter = lpstrFilter;
168 ofn.lpstrFile = lpstrFile;
169 ofn.nMaxFile = nMaxFile;
170 ofn.lpstrInitialDir = lpstrInitialDir;
171 ofn.lpstrTitle = lpstrTitle;
172 ofn.lpstrDefExt = lpstrDefExt;
173 ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
174 ret = pGetOpenFileNameW(&ofn);
175
176 FreeLibrary(hmodule);
177 return ret;
178 }
179
180 /*************************************************************************
181 * SHGetSetSettings [SHELL32.68]
182 */
183 EXTERN_C VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
184 {
185 if(bSet)
186 {
187 FIXME("%p 0x%08x TRUE\n", lpss, dwMask);
188 }
189 else
190 {
191 SHGetSettings((LPSHELLFLAGSTATE)lpss,dwMask);
192 }
193 }
194
195 /*************************************************************************
196 * SHGetSettings [SHELL32.@]
197 *
198 * NOTES
199 * the registry path are for win98 (tested)
200 * and possibly are the same in nt40
201 *
202 */
203 EXTERN_C VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
204 {
205 HKEY hKey;
206 DWORD dwData;
207 DWORD dwDataSize = sizeof (DWORD);
208
209 TRACE("(%p 0x%08x)\n",lpsfs,dwMask);
210
211 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
212 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
213 return;
214
215 if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
216 lpsfs->fShowExtensions = ((dwData == 0) ? 0 : 1);
217
218 if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
219 lpsfs->fShowInfoTip = ((dwData == 0) ? 0 : 1);
220
221 if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
222 lpsfs->fDontPrettyPath = ((dwData == 0) ? 0 : 1);
223
224 if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
225 lpsfs->fHideIcons = ((dwData == 0) ? 0 : 1);
226
227 if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
228 lpsfs->fMapNetDrvBtn = ((dwData == 0) ? 0 : 1);
229
230 if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
231 lpsfs->fShowAttribCol = ((dwData == 0) ? 0 : 1);
232
233 if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
234 { if (dwData == 0)
235 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
236 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
237 }
238 else if (dwData == 1)
239 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 1;
240 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
241 }
242 else if (dwData == 2)
243 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
244 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 1;
245 }
246 }
247 RegCloseKey (hKey);
248
249 TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
250 }
251
252 /*************************************************************************
253 * SHShellFolderView_Message [SHELL32.73]
254 *
255 * Send a message to an explorer cabinet window.
256 *
257 * PARAMS
258 * hwndCabinet [I] The window containing the shellview to communicate with
259 * dwMessage [I] The SFVM message to send
260 * dwParam [I] Message parameter
261 *
262 * RETURNS
263 * fixme.
264 *
265 * NOTES
266 * Message SFVM_REARRANGE = 1
267 *
268 * This message gets sent when a column gets clicked to instruct the
269 * shell view to re-sort the item list. dwParam identifies the column
270 * that was clicked.
271 */
272 LRESULT WINAPI SHShellFolderView_Message(
273 HWND hwndCabinet,
274 UINT uMessage,
275 LPARAM lParam)
276 {
277 FIXME("%p %08x %08lx stub\n",hwndCabinet, uMessage, lParam);
278 return 0;
279 }
280
281 /*************************************************************************
282 * RegisterShellHook [SHELL32.181]
283 *
284 * Register a shell hook.
285 *
286 * PARAMS
287 * hwnd [I] Window handle
288 * dwType [I] Type of hook.
289 *
290 * NOTES
291 * Exported by ordinal
292 */
293 BOOL WINAPI RegisterShellHook(
294 HWND hWnd,
295 DWORD dwType)
296 {
297 if (dwType == 3)
298 return RegisterShellHookWindow(hWnd);
299 else if (dwType == 0)
300 return DeregisterShellHookWindow(hWnd);
301
302 ERR("Unsupported argument");
303 return FALSE;
304 }
305
306 /*************************************************************************
307 * ShellMessageBoxW [SHELL32.182]
308 *
309 * See ShellMessageBoxA.
310 *
311 * NOTE:
312 * shlwapi.ShellMessageBoxWrapW is a duplicate of shell32.ShellMessageBoxW
313 * because we can't forward to it in the .spec file since it's exported by
314 * ordinal. If you change the implementation here please update the code in
315 * shlwapi as well.
316 */
317 EXTERN_C int ShellMessageBoxW(
318 HINSTANCE hInstance,
319 HWND hWnd,
320 LPCWSTR lpText,
321 LPCWSTR lpCaption,
322 UINT uType,
323 ...)
324 {
325 WCHAR szText[100],szTitle[100];
326 LPCWSTR pszText = szText, pszTitle = szTitle;
327 LPWSTR pszTemp;
328 va_list args;
329 int ret;
330
331 va_start(args, uType);
332 /* wvsprintfA(buf,fmt, args); */
333
334 TRACE("(%p,%p,%p,%p,%08x)\n",
335 hInstance,hWnd,lpText,lpCaption,uType);
336
337 if (IS_INTRESOURCE(lpCaption))
338 LoadStringW(hInstance, LOWORD(lpCaption), szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
339 else
340 pszTitle = lpCaption;
341
342 if (IS_INTRESOURCE(lpText))
343 LoadStringW(hInstance, LOWORD(lpText), szText, sizeof(szText)/sizeof(szText[0]));
344 else
345 pszText = lpText;
346
347 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
348 pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
349
350 va_end(args);
351
352 ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
353 LocalFree(pszTemp);
354 return ret;
355 }
356
357 /*************************************************************************
358 * ShellMessageBoxA [SHELL32.183]
359 *
360 * Format and output an error message.
361 *
362 * PARAMS
363 * hInstance [I] Instance handle of message creator
364 * hWnd [I] Window handle of message creator
365 * lpText [I] Resource Id of title or LPSTR
366 * lpCaption [I] Resource Id of title or LPSTR
367 * uType [I] Type of error message
368 *
369 * RETURNS
370 * A return value from MessageBoxA().
371 *
372 * NOTES
373 * Exported by ordinal
374 */
375 EXTERN_C int ShellMessageBoxA(
376 HINSTANCE hInstance,
377 HWND hWnd,
378 LPCSTR lpText,
379 LPCSTR lpCaption,
380 UINT uType,
381 ...)
382 {
383 char szText[100],szTitle[100];
384 LPCSTR pszText = szText, pszTitle = szTitle;
385 LPSTR pszTemp;
386 va_list args;
387 int ret;
388
389 va_start(args, uType);
390 /* wvsprintfA(buf,fmt, args); */
391
392 TRACE("(%p,%p,%p,%p,%08x)\n",
393 hInstance,hWnd,lpText,lpCaption,uType);
394
395 if (IS_INTRESOURCE(lpCaption))
396 LoadStringA(hInstance, LOWORD(lpCaption), szTitle, sizeof(szTitle));
397 else
398 pszTitle = lpCaption;
399
400 if (IS_INTRESOURCE(lpText))
401 LoadStringA(hInstance, LOWORD(lpText), szText, sizeof(szText));
402 else
403 pszText = lpText;
404
405 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
406 pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
407
408 va_end(args);
409
410 ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
411 LocalFree(pszTemp);
412 return ret;
413 }
414
415 /*************************************************************************
416 * SHRegisterDragDrop [SHELL32.86]
417 *
418 * Probably equivalent to RegisterDragDrop but under Windows 95 it could use the
419 * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
420 * for details. Under Windows 98 this function initializes the true OLE when called
421 * the first time, on XP always returns E_OUTOFMEMORY and it got removed from Vista.
422 *
423 * We follow Windows 98 behaviour.
424 *
425 * NOTES
426 * exported by ordinal
427 *
428 * SEE ALSO
429 * RegisterDragDrop, SHLoadOLE
430 */
431 HRESULT WINAPI SHRegisterDragDrop(
432 HWND hWnd,
433 LPDROPTARGET pDropTarget)
434 {
435 static BOOL ole_initialized = FALSE;
436 HRESULT hr;
437
438 TRACE("(%p,%p)\n", hWnd, pDropTarget);
439
440 if (!ole_initialized)
441 {
442 hr = OleInitialize(NULL);
443 if (FAILED(hr))
444 return hr;
445 ole_initialized = TRUE;
446 }
447 return RegisterDragDrop(hWnd, pDropTarget);
448 }
449
450 /*************************************************************************
451 * SHRevokeDragDrop [SHELL32.87]
452 *
453 * Probably equivalent to RevokeDragDrop but under Windows 95 it could use the
454 * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
455 * for details. Function removed from Windows Vista.
456 *
457 * We call ole32 RevokeDragDrop which seems to work even if OleInitialize was
458 * not called.
459 *
460 * NOTES
461 * exported by ordinal
462 *
463 * SEE ALSO
464 * RevokeDragDrop, SHLoadOLE
465 */
466 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
467 {
468 TRACE("(%p)\n", hWnd);
469 return RevokeDragDrop(hWnd);
470 }
471
472 /*************************************************************************
473 * SHDoDragDrop [SHELL32.88]
474 *
475 * Probably equivalent to DoDragDrop but under Windows 9x it could use the
476 * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
477 * for details
478 *
479 * NOTES
480 * exported by ordinal
481 *
482 * SEE ALSO
483 * DoDragDrop, SHLoadOLE
484 */
485 HRESULT WINAPI SHDoDragDrop(
486 HWND hWnd,
487 IDataObject * lpDataObject,
488 LPDROPSOURCE lpDropSource,
489 DWORD dwOKEffect,
490 LPDWORD pdwEffect)
491 {
492 FIXME("(%p %p %p 0x%08x %p):stub.\n",
493 hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
494 return DoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
495 }
496
497 /*************************************************************************
498 * ArrangeWindows [SHELL32.184]
499 *
500 */
501 WORD WINAPI ArrangeWindows(
502 HWND hwndParent,
503 DWORD dwReserved,
504 LPCRECT lpRect,
505 WORD cKids,
506 CONST HWND * lpKids)
507 {
508 /* Unimplemented in WinXP SP3 */
509 TRACE("(%p 0x%08x %p 0x%04x %p):stub.\n",
510 hwndParent, dwReserved, lpRect, cKids, lpKids);
511 return 0;
512 }
513
514 /*************************************************************************
515 * SignalFileOpen [SHELL32.103]
516 *
517 * NOTES
518 * exported by ordinal
519 */
520 EXTERN_C BOOL WINAPI
521 SignalFileOpen (LPCITEMIDLIST pidl)
522 {
523 FIXME("(0x%08x):stub.\n", pidl);
524
525 return 0;
526 }
527
528 /*************************************************************************
529 * SHADD_get_policy - helper function for SHAddToRecentDocs
530 *
531 * PARAMETERS
532 * policy [IN] policy name (null termed string) to find
533 * type [OUT] ptr to DWORD to receive type
534 * buffer [OUT] ptr to area to hold data retrieved
535 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
536 * length filled
537 *
538 * RETURNS
539 * result of the SHQueryValueEx call
540 */
541 static INT SHADD_get_policy(LPCSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
542 {
543 HKEY Policy_basekey;
544 INT ret;
545
546 /* Get the key for the policies location in the registry
547 */
548 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
549 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
550 0, KEY_READ, &Policy_basekey)) {
551
552 if (RegOpenKeyExA(HKEY_CURRENT_USER,
553 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
554 0, KEY_READ, &Policy_basekey)) {
555 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
556 policy);
557 *len = 0;
558 return ERROR_FILE_NOT_FOUND;
559 }
560 }
561
562 /* Retrieve the data if it exists
563 */
564 ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
565 RegCloseKey(Policy_basekey);
566 return ret;
567 }
568
569
570 /*************************************************************************
571 * SHADD_compare_mru - helper function for SHAddToRecentDocs
572 *
573 * PARAMETERS
574 * data1 [IN] data being looked for
575 * data2 [IN] data in MRU
576 * cbdata [IN] length from FindMRUData call (not used)
577 *
578 * RETURNS
579 * position within MRU list that data was added.
580 */
581 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
582 {
583 return lstrcmpiA((LPCSTR)data1, (LPCSTR)data2);
584 }
585
586 /*************************************************************************
587 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
588 *
589 * PARAMETERS
590 * mruhandle [IN] handle for created MRU list
591 * doc_name [IN] null termed pure doc name
592 * new_lnk_name [IN] null termed path and file name for .lnk file
593 * buffer [IN/OUT] 2048 byte area to construct MRU data
594 * len [OUT] ptr to int to receive space used in buffer
595 *
596 * RETURNS
597 * position within MRU list that data was added.
598 */
599 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPCSTR doc_name, LPCSTR new_lnk_name,
600 LPSTR buffer, INT *len)
601 {
602 LPSTR ptr;
603 INT wlen;
604
605 /*FIXME: Document:
606 * RecentDocs MRU data structure seems to be:
607 * +0h document file name w/ terminating 0h
608 * +nh short int w/ size of remaining
609 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
610 * +n+4h 10 bytes zeros - unknown
611 * +n+eh shortcut file name w/ terminating 0h
612 * +n+e+nh 3 zero bytes - unknown
613 */
614
615 /* Create the MRU data structure for "RecentDocs"
616 */
617 ptr = buffer;
618 lstrcpyA(ptr, doc_name);
619 ptr += (lstrlenA(buffer) + 1);
620 wlen= lstrlenA(new_lnk_name) + 1 + 12;
621 *((short int*)ptr) = wlen;
622 ptr += 2; /* step past the length */
623 *(ptr++) = 0x30; /* unknown reason */
624 *(ptr++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
625 memset(ptr, 0, 10);
626 ptr += 10;
627 lstrcpyA(ptr, new_lnk_name);
628 ptr += (lstrlenA(new_lnk_name) + 1);
629 memset(ptr, 0, 3);
630 ptr += 3;
631 *len = ptr - buffer;
632
633 /* Add the new entry into the MRU list
634 */
635 return AddMRUData(mruhandle, buffer, *len);
636 }
637
638 /*************************************************************************
639 * SHAddToRecentDocs [SHELL32.@]
640 *
641 * Modify (add/clear) Shell's list of recently used documents.
642 *
643 * PARAMETERS
644 * uFlags [IN] SHARD_PATHA, SHARD_PATHW or SHARD_PIDL
645 * pv [IN] string or pidl, NULL clears the list
646 *
647 * NOTES
648 * exported by name
649 *
650 * FIXME
651 * convert to unicode
652 */
653 void WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
654 {
655 /* If list is a string list lpfnCompare has the following prototype
656 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
657 * for binary lists the prototype is
658 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
659 * where cbData is the no. of bytes to compare.
660 * Need to check what return value means identical - 0?
661 */
662
663
664 UINT olderrormode;
665 HKEY HCUbasekey;
666 CHAR doc_name[MAX_PATH];
667 CHAR link_dir[MAX_PATH];
668 CHAR new_lnk_filepath[MAX_PATH];
669 CHAR new_lnk_name[MAX_PATH];
670 CHAR * ext;
671 CComPtr<IMalloc> ppM;
672 LPITEMIDLIST pidl;
673 HWND hwnd = 0; /* FIXME: get real window handle */
674 INT ret;
675 DWORD data[64], datalen, type;
676
677 TRACE("%04x %p\n", uFlags, pv);
678
679 /*FIXME: Document:
680 * RecentDocs MRU data structure seems to be:
681 * +0h document file name w/ terminating 0h
682 * +nh short int w/ size of remaining
683 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
684 * +n+4h 10 bytes zeros - unknown
685 * +n+eh shortcut file name w/ terminating 0h
686 * +n+e+nh 3 zero bytes - unknown
687 */
688
689 /* See if we need to do anything.
690 */
691 datalen = 64;
692 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, data, &datalen);
693 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
694 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
695 return;
696 }
697 if (ret == ERROR_SUCCESS) {
698 if (!( (type == REG_DWORD) ||
699 ((type == REG_BINARY) && (datalen == 4)) )) {
700 ERR("Error policy data for \"NoRecentDocsHistory\" not formatted correctly, type=%d, len=%d\n",
701 type, datalen);
702 return;
703 }
704
705 TRACE("policy value for NoRecentDocsHistory = %08x\n", data[0]);
706 /* now test the actual policy value */
707 if ( data[0] != 0)
708 return;
709 }
710
711 /* Open key to where the necessary info is
712 */
713 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
714 * and the close should be done during the _DETACH. The resulting
715 * key is stored in the DLL global data.
716 */
717 if (RegCreateKeyExA(HKEY_CURRENT_USER,
718 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
719 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
720 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
721 return;
722 }
723
724 /* Get path to user's "Recent" directory
725 */
726 if(SUCCEEDED(SHGetMalloc(&ppM))) {
727 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
728 &pidl))) {
729 SHGetPathFromIDListA(pidl, link_dir);
730 ppM->Free(pidl);
731 }
732 else {
733 /* serious issues */
734 link_dir[0] = 0;
735 ERR("serious issues 1\n");
736 }
737 }
738 else {
739 /* serious issues */
740 link_dir[0] = 0;
741 ERR("serious issues 2\n");
742 }
743 TRACE("Users Recent dir %s\n", link_dir);
744
745 /* If no input, then go clear the lists */
746 if (!pv) {
747 /* clear user's Recent dir
748 */
749
750 /* FIXME: delete all files in "link_dir"
751 *
752 * while( more files ) {
753 * lstrcpyA(old_lnk_name, link_dir);
754 * PathAppendA(old_lnk_name, filenam);
755 * DeleteFileA(old_lnk_name);
756 * }
757 */
758 FIXME("should delete all files in %s\\\n", link_dir);
759
760 /* clear MRU list
761 */
762 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
763 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
764 * and naturally it fails w/ rc=2. It should do it against
765 * HKEY_CURRENT_USER which is where it is stored, and where
766 * the MRU routines expect it!!!!
767 */
768 RegDeleteKeyA(HCUbasekey, "RecentDocs");
769 RegCloseKey(HCUbasekey);
770 return;
771 }
772
773 /* Have data to add, the jobs to be done:
774 * 1. Add document to MRU list in registry "HKCU\Software\
775 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
776 * 2. Add shortcut to document in the user's Recent directory
777 * (CSIDL_RECENT).
778 * 3. Add shortcut to Start menu's Documents submenu.
779 */
780
781 /* Get the pure document name from the input
782 */
783 switch (uFlags)
784 {
785 case SHARD_PIDL:
786 SHGetPathFromIDListA((LPCITEMIDLIST)pv, doc_name);
787 break;
788
789 case SHARD_PATHA:
790 lstrcpynA(doc_name, (LPCSTR)pv, MAX_PATH);
791 break;
792
793 case SHARD_PATHW:
794 WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pv, -1, doc_name, MAX_PATH, NULL, NULL);
795 break;
796
797 default:
798 FIXME("Unsupported flags: %u\n", uFlags);
799 return;
800 }
801
802 TRACE("full document name %s\n", debugstr_a(doc_name));
803
804 /* check if file is a shortcut */
805 ext = strrchr(doc_name, '.');
806 if (!lstrcmpiA(ext, ".lnk"))
807 {
808 CComPtr<IShellLinkA> ShellLink;
809 IShellLink_ConstructFromFile(NULL, IID_IShellLinkA, (LPCITEMIDLIST)SHSimpleIDListFromPathA(doc_name), (LPVOID*)&ShellLink);
810 ShellLink->GetPath(doc_name, MAX_PATH, NULL, 0);
811 }
812
813 ext = strrchr(doc_name, '.');
814 if (!lstrcmpiA(ext, ".exe"))
815 {
816 /* executables are not added */
817 return;
818 }
819
820 PathStripPathA(doc_name);
821 TRACE("stripped document name %s\n", debugstr_a(doc_name));
822
823
824 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
825
826 { /* on input needs:
827 * doc_name - pure file-spec, no path
828 * link_dir - path to the user's Recent directory
829 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
830 * creates:
831 * new_lnk_name- pure file-spec, no path for new .lnk file
832 * new_lnk_filepath
833 * - path and file name of new .lnk file
834 */
835 CREATEMRULISTA mymru;
836 HANDLE mruhandle;
837 INT len, pos, bufused, err;
838 INT i;
839 DWORD attr;
840 CHAR buffer[2048];
841 CHAR *ptr;
842 CHAR old_lnk_name[MAX_PATH];
843 short int slen;
844
845 mymru.cbSize = sizeof(CREATEMRULISTA);
846 mymru.nMaxItems = 15;
847 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
848 mymru.hKey = HCUbasekey;
849 mymru.lpszSubKey = "RecentDocs";
850 mymru.lpfnCompare = (PROC)SHADD_compare_mru;
851 mruhandle = CreateMRUListA(&mymru);
852 if (!mruhandle) {
853 /* MRU failed */
854 ERR("MRU processing failed, handle zero\n");
855 RegCloseKey(HCUbasekey);
856 return;
857 }
858 len = lstrlenA(doc_name);
859 pos = FindMRUData(mruhandle, doc_name, len, 0);
860
861 /* Now get the MRU entry that will be replaced
862 * and delete the .lnk file for it
863 */
864 if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
865 buffer, 2048)) != -1) {
866 ptr = buffer;
867 ptr += (lstrlenA(buffer) + 1);
868 slen = *((short int*)ptr);
869 ptr += 2; /* skip the length area */
870 if (bufused >= slen + (ptr-buffer)) {
871 /* buffer size looks good */
872 ptr += 12; /* get to string */
873 len = bufused - (ptr-buffer); /* get length of buf remaining */
874 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
875 /* appears to be good string */
876 lstrcpyA(old_lnk_name, link_dir);
877 PathAppendA(old_lnk_name, ptr);
878 if (!DeleteFileA(old_lnk_name)) {
879 if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) {
880 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
881 ERR("Delete for %s failed, err=%d, attr=%08x\n",
882 old_lnk_name, err, attr);
883 }
884 else {
885 TRACE("old .lnk file %s did not exist\n",
886 old_lnk_name);
887 }
888 }
889 else {
890 ERR("Delete for %s failed, attr=%08x\n",
891 old_lnk_name, attr);
892 }
893 }
894 else {
895 TRACE("deleted old .lnk file %s\n", old_lnk_name);
896 }
897 }
898 }
899 }
900
901 /* Create usable .lnk file name for the "Recent" directory
902 */
903 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
904 lstrcpyA(new_lnk_filepath, link_dir);
905 PathAppendA(new_lnk_filepath, new_lnk_name);
906 i = 1;
907 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
908 while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
909 i++;
910 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
911 lstrcpyA(new_lnk_filepath, link_dir);
912 PathAppendA(new_lnk_filepath, new_lnk_name);
913 }
914 SetErrorMode(olderrormode);
915 TRACE("new shortcut will be %s\n", new_lnk_filepath);
916
917 /* Now add the new MRU entry and data
918 */
919 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
920 buffer, &len);
921 FreeMRUList(mruhandle);
922 TRACE("Updated MRU list, new doc is position %d\n", pos);
923 }
924
925 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
926
927 { /* on input needs:
928 * doc_name - pure file-spec, no path
929 * new_lnk_filepath
930 * - path and file name of new .lnk file
931 * uFlags[in] - flags on call to SHAddToRecentDocs
932 * pv[in] - document path/pidl on call to SHAddToRecentDocs
933 */
934 CComPtr<IShellLinkA> psl;
935 CComPtr<IPersistFile> pPf;
936 HRESULT hres;
937 CHAR desc[MAX_PATH];
938 WCHAR widelink[MAX_PATH];
939
940 CoInitialize(0);
941
942 hres = CoCreateInstance(CLSID_ShellLink,
943 NULL,
944 CLSCTX_INPROC_SERVER,
945 IID_PPV_ARG(IShellLinkA,&psl));
946 if(SUCCEEDED(hres)) {
947
948 hres = psl->QueryInterface(IID_PPV_ARG(IPersistFile,&pPf));
949 if(FAILED(hres)) {
950 /* bombed */
951 ERR("failed QueryInterface for IPersistFile %08x\n", hres);
952 goto fail;
953 }
954
955 /* Set the document path or pidl */
956 if (uFlags == SHARD_PIDL) {
957 hres = psl->SetIDList((LPCITEMIDLIST) pv);
958 } else {
959 hres = psl->SetPath((LPCSTR) pv);
960 }
961 if(FAILED(hres)) {
962 /* bombed */
963 ERR("failed Set{IDList|Path} %08x\n", hres);
964 goto fail;
965 }
966
967 lstrcpyA(desc, "Shortcut to ");
968 lstrcatA(desc, doc_name);
969 hres = psl->SetDescription(desc);
970 if(FAILED(hres)) {
971 /* bombed */
972 ERR("failed SetDescription %08x\n", hres);
973 goto fail;
974 }
975
976 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
977 widelink, MAX_PATH);
978 /* create the short cut */
979 hres = pPf->Save(widelink, TRUE);
980 if(FAILED(hres)) {
981 /* bombed */
982 ERR("failed IPersistFile::Save %08x\n", hres);
983 goto fail;
984 }
985 hres = pPf->SaveCompleted(widelink);
986 TRACE("shortcut %s has been created, result=%08x\n",
987 new_lnk_filepath, hres);
988 }
989 else {
990 ERR("CoCreateInstance failed, hres=%08x\n", hres);
991 }
992 }
993
994 fail:
995 CoUninitialize();
996
997 /* all done */
998 RegCloseKey(HCUbasekey);
999 return;
1000 }
1001
1002 /*************************************************************************
1003 * SHCreateShellFolderViewEx [SHELL32.174]
1004 *
1005 * Create a new instance of the default Shell folder view object.
1006 *
1007 * RETURNS
1008 * Success: S_OK
1009 * Failure: error value
1010 *
1011 * NOTES
1012 * see IShellFolder::CreateViewObject
1013 */
1014 HRESULT WINAPI SHCreateShellFolderViewEx(
1015 LPCSFV psvcbi, /* [in] shelltemplate struct */
1016 IShellView **ppv) /* [out] IShellView pointer */
1017 {
1018 CComPtr<IShellView> psf;
1019 HRESULT hRes;
1020
1021 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=%p\n",
1022 psvcbi->pshf, psvcbi->pidl, psvcbi->pfnCallback,
1023 psvcbi->fvm, psvcbi->psvOuter);
1024
1025 *ppv = NULL;
1026 hRes = IShellView_Constructor(psvcbi->pshf, &psf);
1027 if (FAILED(hRes))
1028 return hRes;
1029
1030 hRes = psf->QueryInterface(IID_PPV_ARG(IShellView, ppv));
1031
1032 return hRes;
1033 }
1034 /*************************************************************************
1035 * SHWinHelp [SHELL32.127]
1036 *
1037 */
1038 EXTERN_C HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
1039 { FIXME("0x%08x 0x%08x 0x%08x 0x%08x stub\n",v,w,x,z);
1040 return 0;
1041 }
1042 /*************************************************************************
1043 * SHRunControlPanel [SHELL32.161]
1044 *
1045 */
1046 EXTERN_C BOOL WINAPI SHRunControlPanel (LPCWSTR lpcszCmdLine, HWND hwndMsgParent)
1047 {
1048 FIXME("0x%08x 0x%08x stub\n",lpcszCmdLine,hwndMsgParent);
1049 return 0;
1050 }
1051
1052 static IUnknown * SHELL32_IExplorerInterface=0;
1053 /*************************************************************************
1054 * SHSetInstanceExplorer [SHELL32.176]
1055 *
1056 * NOTES
1057 * Sets the interface
1058 */
1059 VOID WINAPI SHSetInstanceExplorer (IUnknown * lpUnknown)
1060 { TRACE("%p\n", lpUnknown);
1061 SHELL32_IExplorerInterface = lpUnknown;
1062 }
1063 /*************************************************************************
1064 * SHGetInstanceExplorer [SHELL32.@]
1065 *
1066 * NOTES
1067 * gets the interface pointer of the explorer and a reference
1068 */
1069 HRESULT WINAPI SHGetInstanceExplorer (IUnknown **lpUnknown)
1070 { TRACE("%p\n", lpUnknown);
1071
1072 *lpUnknown = SHELL32_IExplorerInterface;
1073
1074 if (!SHELL32_IExplorerInterface)
1075 return E_FAIL;
1076
1077 SHELL32_IExplorerInterface->AddRef();
1078 return S_OK;
1079 }
1080 /*************************************************************************
1081 * SHFreeUnusedLibraries [SHELL32.123]
1082 *
1083 * Probably equivalent to CoFreeUnusedLibraries but under Windows 9x it could use
1084 * the shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
1085 * for details
1086 *
1087 * NOTES
1088 * exported by ordinal
1089 *
1090 * SEE ALSO
1091 * CoFreeUnusedLibraries, SHLoadOLE
1092 */
1093 void WINAPI SHFreeUnusedLibraries (void)
1094 {
1095 FIXME("stub\n");
1096 CoFreeUnusedLibraries();
1097 }
1098 /*************************************************************************
1099 * DAD_AutoScroll [SHELL32.129]
1100 *
1101 */
1102 BOOL WINAPI DAD_AutoScroll(HWND hwnd, AUTO_SCROLL_DATA *samples, const POINT * pt)
1103 {
1104 FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1105 return FALSE;
1106 }
1107 /*************************************************************************
1108 * DAD_DragEnter [SHELL32.130]
1109 *
1110 */
1111 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1112 {
1113 FIXME("hwnd = %p\n",hwnd);
1114 return FALSE;
1115 }
1116 /*************************************************************************
1117 * DAD_DragEnterEx [SHELL32.131]
1118 *
1119 */
1120 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1121 {
1122 FIXME("hwnd = %p (%d,%d)\n",hwnd,p.x,p.y);
1123 return FALSE;
1124 }
1125 /*************************************************************************
1126 * DAD_DragMove [SHELL32.134]
1127 *
1128 */
1129 BOOL WINAPI DAD_DragMove(POINT p)
1130 {
1131 FIXME("(%d,%d)\n",p.x,p.y);
1132 return FALSE;
1133 }
1134 /*************************************************************************
1135 * DAD_DragLeave [SHELL32.132]
1136 *
1137 */
1138 BOOL WINAPI DAD_DragLeave(VOID)
1139 {
1140 FIXME("\n");
1141 return FALSE;
1142 }
1143 /*************************************************************************
1144 * DAD_SetDragImage [SHELL32.136]
1145 *
1146 * NOTES
1147 * exported by name
1148 */
1149 BOOL WINAPI DAD_SetDragImage(
1150 HIMAGELIST himlTrack,
1151 LPPOINT lppt)
1152 {
1153 FIXME("%p %p stub\n",himlTrack, lppt);
1154 return FALSE;
1155 }
1156 /*************************************************************************
1157 * DAD_ShowDragImage [SHELL32.137]
1158 *
1159 * NOTES
1160 * exported by name
1161 */
1162 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1163 {
1164 FIXME("0x%08x stub\n",bShow);
1165 return FALSE;
1166 }
1167
1168 static const WCHAR szwCabLocation[] = {
1169 'S','o','f','t','w','a','r','e','\\',
1170 'M','i','c','r','o','s','o','f','t','\\',
1171 'W','i','n','d','o','w','s','\\',
1172 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1173 'E','x','p','l','o','r','e','r','\\',
1174 'C','a','b','i','n','e','t','S','t','a','t','e',0
1175 };
1176
1177 static const WCHAR szwSettings[] = { 'S','e','t','t','i','n','g','s',0 };
1178
1179 /*************************************************************************
1180 * ReadCabinetState [SHELL32.651] NT 4.0
1181 *
1182 */
1183 BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
1184 {
1185 HKEY hkey = 0;
1186 DWORD type, r;
1187
1188 TRACE("%p %d\n", cs, length);
1189
1190 if( (cs == NULL) || (length < (int)sizeof(*cs)) )
1191 return FALSE;
1192
1193 r = RegOpenKeyW( HKEY_CURRENT_USER, szwCabLocation, &hkey );
1194 if( r == ERROR_SUCCESS )
1195 {
1196 type = REG_BINARY;
1197 r = RegQueryValueExW( hkey, szwSettings,
1198 NULL, &type, (LPBYTE)cs, (LPDWORD)&length );
1199 RegCloseKey( hkey );
1200
1201 }
1202
1203 /* if we can't read from the registry, create default values */
1204 if ( (r != ERROR_SUCCESS) || (cs->cLength < sizeof(*cs)) ||
1205 (cs->cLength != length) )
1206 {
1207 ERR("Initializing shell cabinet settings\n");
1208 memset(cs, 0, sizeof(*cs));
1209 cs->cLength = sizeof(*cs);
1210 cs->nVersion = 2;
1211 cs->fFullPathTitle = FALSE;
1212 cs->fSaveLocalView = TRUE;
1213 cs->fNotShell = FALSE;
1214 cs->fSimpleDefault = TRUE;
1215 cs->fDontShowDescBar = FALSE;
1216 cs->fNewWindowMode = FALSE;
1217 cs->fShowCompColor = FALSE;
1218 cs->fDontPrettyNames = FALSE;
1219 cs->fAdminsCreateCommonGroups = TRUE;
1220 cs->fMenuEnumFilter = 96;
1221 }
1222
1223 return TRUE;
1224 }
1225
1226 /*************************************************************************
1227 * WriteCabinetState [SHELL32.652] NT 4.0
1228 *
1229 */
1230 BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
1231 {
1232 DWORD r;
1233 HKEY hkey = 0;
1234
1235 TRACE("%p\n",cs);
1236
1237 if( cs == NULL )
1238 return FALSE;
1239
1240 r = RegCreateKeyExW( HKEY_CURRENT_USER, szwCabLocation, 0,
1241 NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
1242 if( r == ERROR_SUCCESS )
1243 {
1244 r = RegSetValueExW( hkey, szwSettings, 0,
1245 REG_BINARY, (LPBYTE) cs, cs->cLength);
1246
1247 RegCloseKey( hkey );
1248 }
1249
1250 return (r==ERROR_SUCCESS);
1251 }
1252
1253 /*************************************************************************
1254 * FileIconInit [SHELL32.660]
1255 *
1256 */
1257 BOOL WINAPI FileIconInit(BOOL bFullInit)
1258 {
1259 FIXME("(%s)\n", bFullInit ? "true" : "false");
1260 return FALSE;
1261 }
1262
1263 /*************************************************************************
1264 * IsUserAnAdmin [SHELL32.680] NT 4.0
1265 *
1266 * Checks whether the current user is a member of the Administrators group.
1267 *
1268 * PARAMS
1269 * None
1270 *
1271 * RETURNS
1272 * Success: TRUE
1273 * Failure: FALSE
1274 */
1275 BOOL WINAPI IsUserAnAdmin(VOID)
1276 {
1277 SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
1278 HANDLE hToken;
1279 DWORD dwSize;
1280 PTOKEN_GROUPS lpGroups;
1281 PSID lpSid;
1282 DWORD i;
1283 BOOL bResult = FALSE;
1284
1285 TRACE("\n");
1286
1287 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
1288 {
1289 return FALSE;
1290 }
1291
1292 if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
1293 {
1294 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1295 {
1296 CloseHandle(hToken);
1297 return FALSE;
1298 }
1299 }
1300
1301 lpGroups = (PTOKEN_GROUPS)HeapAlloc(GetProcessHeap(), 0, dwSize);
1302 if (lpGroups == NULL)
1303 {
1304 CloseHandle(hToken);
1305 return FALSE;
1306 }
1307
1308 if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize))
1309 {
1310 HeapFree(GetProcessHeap(), 0, lpGroups);
1311 CloseHandle(hToken);
1312 return FALSE;
1313 }
1314
1315 CloseHandle(hToken);
1316
1317 if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
1318 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
1319 &lpSid))
1320 {
1321 HeapFree(GetProcessHeap(), 0, lpGroups);
1322 return FALSE;
1323 }
1324
1325 for (i = 0; i < lpGroups->GroupCount; i++)
1326 {
1327 if (EqualSid(lpSid, lpGroups->Groups[i].Sid))
1328 {
1329 bResult = TRUE;
1330 break;
1331 }
1332 }
1333
1334 FreeSid(lpSid);
1335 HeapFree(GetProcessHeap(), 0, lpGroups);
1336 return bResult;
1337 }
1338
1339 /*************************************************************************
1340 * SHAllocShared [SHELL32.520]
1341 *
1342 * See shlwapi.SHAllocShared
1343 */
1344 HANDLE WINAPI SHAllocShared(LPVOID lpvData, DWORD dwSize, DWORD dwProcId)
1345 {
1346 typedef HANDLE (WINAPI *SHAllocSharedProc)(LPCVOID, DWORD, DWORD);
1347 static SHAllocSharedProc pSHAllocShared;
1348
1349 GET_FUNC(pSHAllocShared, SHAllocSharedProc, shlwapi, (char*)7, NULL);
1350 return pSHAllocShared(lpvData, dwSize, dwProcId);
1351 }
1352
1353 /*************************************************************************
1354 * SHLockShared [SHELL32.521]
1355 *
1356 * See shlwapi.SHLockShared
1357 */
1358 LPVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
1359 {
1360 typedef HANDLE (WINAPI *SHLockSharedProc)(HANDLE, DWORD);
1361 static SHLockSharedProc pSHLockShared;
1362
1363 GET_FUNC(pSHLockShared, SHLockSharedProc, shlwapi, (char*)8, NULL);
1364 return pSHLockShared(hShared, dwProcId);
1365 }
1366
1367 /*************************************************************************
1368 * SHUnlockShared [SHELL32.522]
1369 *
1370 * See shlwapi.SHUnlockShared
1371 */
1372 BOOL WINAPI SHUnlockShared(LPVOID lpView)
1373 {
1374 typedef HANDLE (WINAPI *SHUnlockSharedProc)(LPCVOID);
1375 static SHUnlockSharedProc pSHUnlockShared;
1376
1377 GET_FUNC(pSHUnlockShared, SHUnlockSharedProc, shlwapi, (char*)9, FALSE);
1378 return pSHUnlockShared(lpView) != NULL;
1379 }
1380
1381 /*************************************************************************
1382 * SHFreeShared [SHELL32.523]
1383 *
1384 * See shlwapi.SHFreeShared
1385 */
1386 BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
1387 {
1388 typedef HANDLE (WINAPI *SHFreeSharedProc)(HANDLE, DWORD);
1389 static SHFreeSharedProc pSHFreeShared;
1390
1391 GET_FUNC(pSHFreeShared, SHFreeSharedProc, shlwapi, (char*)10, FALSE);
1392 return pSHFreeShared(hShared, dwProcId) != NULL;
1393 }
1394
1395 /*************************************************************************
1396 * SetAppStartingCursor [SHELL32.99]
1397 */
1398 EXTERN_C HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1399 { FIXME("hwnd=%p 0x%04x stub\n",u,v );
1400 return 0;
1401 }
1402
1403 /*************************************************************************
1404 * SHLoadOLE [SHELL32.151]
1405 *
1406 * To reduce the memory usage of Windows 95, its shell32 contained an
1407 * internal implementation of a part of COM (see e.g. SHGetMalloc, SHCoCreateInstance,
1408 * SHRegisterDragDrop etc.) that allowed to use in-process STA objects without
1409 * the need to load OLE32.DLL. If OLE32.DLL was already loaded, the SH* function
1410 * would just call the Co* functions.
1411 *
1412 * The SHLoadOLE was called when OLE32.DLL was being loaded to transfer all the
1413 * information from the shell32 "mini-COM" to ole32.dll.
1414 *
1415 * See http://blogs.msdn.com/oldnewthing/archive/2004/07/05/173226.aspx for a
1416 * detailed description.
1417 *
1418 * Under wine ole32.dll is always loaded as it is imported by shlwapi.dll which is
1419 * imported by shell32 and no "mini-COM" is used (except for the "LoadWithoutCOM"
1420 * hack in SHCoCreateInstance)
1421 */
1422 HRESULT WINAPI SHLoadOLE(LPARAM lParam)
1423 { FIXME("0x%08lx stub\n",lParam);
1424 return S_OK;
1425 }
1426 /*************************************************************************
1427 * DriveType [SHELL32.64]
1428 *
1429 */
1430 EXTERN_C int WINAPI DriveType(int DriveType)
1431 {
1432 WCHAR root[] = L"A:\\";
1433 root[0] = L'A' + DriveType;
1434 return GetDriveTypeW(root);
1435 }
1436
1437 /*************************************************************************
1438 * InvalidateDriveType [SHELL32.65]
1439 * Unimplemented in XP SP3
1440 */
1441 EXTERN_C int WINAPI InvalidateDriveType(int u)
1442 {
1443 TRACE("0x%08x stub\n",u);
1444 return 0;
1445 }
1446
1447 /*************************************************************************
1448 * SHAbortInvokeCommand [SHELL32.198]
1449 *
1450 */
1451 EXTERN_C HRESULT WINAPI SHAbortInvokeCommand(void)
1452 { FIXME("stub\n");
1453 return 1;
1454 }
1455
1456 /*************************************************************************
1457 * SHOutOfMemoryMessageBox [SHELL32.126]
1458 *
1459 */
1460 int WINAPI SHOutOfMemoryMessageBox(
1461 HWND hwndOwner,
1462 LPCSTR lpCaption,
1463 UINT uType)
1464 {
1465 FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1466 return 0;
1467 }
1468
1469 /*************************************************************************
1470 * SHFlushClipboard [SHELL32.121]
1471 *
1472 */
1473 EXTERN_C HRESULT WINAPI SHFlushClipboard(void)
1474 {
1475 return OleFlushClipboard();
1476 }
1477
1478 /*************************************************************************
1479 * SHWaitForFileToOpen [SHELL32.97]
1480 *
1481 */
1482 BOOL WINAPI SHWaitForFileToOpen(
1483 LPCITEMIDLIST pidl,
1484 DWORD dwFlags,
1485 DWORD dwTimeout)
1486 {
1487 FIXME("%p 0x%08x 0x%08x stub\n", pidl, dwFlags, dwTimeout);
1488 return 0;
1489 }
1490
1491 /************************************************************************
1492 * RLBuildListOfPaths [SHELL32.146]
1493 *
1494 * NOTES
1495 * builds a DPA
1496 */
1497 EXTERN_C DWORD WINAPI RLBuildListOfPaths (void)
1498 { FIXME("stub\n");
1499 return 0;
1500 }
1501
1502 /************************************************************************
1503 * SHValidateUNC [SHELL32.173]
1504 *
1505 */
1506 EXTERN_C BOOL WINAPI SHValidateUNC (HWND hwndOwner, LPWSTR pszFile, UINT fConnect)
1507 {
1508 FIXME("0x%08x 0x%08x 0x%08x stub\n",hwndOwner,pszFile,fConnect);
1509 return 0;
1510 }
1511
1512 /************************************************************************
1513 * DoEnvironmentSubstA [SHELL32.@]
1514 *
1515 * See DoEnvironmentSubstW.
1516 */
1517 EXTERN_C DWORD WINAPI DoEnvironmentSubstA(LPSTR pszString, UINT cchString)
1518 {
1519 LPSTR dst;
1520 BOOL res = FALSE;
1521 DWORD len = cchString;
1522
1523 TRACE("(%s, %d)\n", debugstr_a(pszString), cchString);
1524 if (pszString == NULL) /* Really return 0? */
1525 return 0;
1526 if ((dst = (LPSTR)HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(CHAR))))
1527 {
1528 len = ExpandEnvironmentStringsA(pszString, dst, cchString);
1529 /* len includes the terminating 0 */
1530 if (len && len < cchString)
1531 {
1532 res = TRUE;
1533 memcpy(pszString, dst, len);
1534 }
1535 else
1536 len = cchString;
1537
1538 HeapFree(GetProcessHeap(), 0, dst);
1539 }
1540 return MAKELONG(len, res);
1541 }
1542
1543 /************************************************************************
1544 * DoEnvironmentSubstW [SHELL32.@]
1545 *
1546 * Replace all %KEYWORD% in the string with the value of the named
1547 * environment variable. If the buffer is too small, the string is not modified.
1548 *
1549 * PARAMS
1550 * pszString [I] '\0' terminated string with %keyword%.
1551 * [O] '\0' terminated string with %keyword% substituted.
1552 * cchString [I] size of str.
1553 *
1554 * RETURNS
1555 * Success: The string in the buffer is updated
1556 * HIWORD: TRUE
1557 * LOWORD: characters used in the buffer, including space for the terminating 0
1558 * Failure: buffer too small. The string is not modified.
1559 * HIWORD: FALSE
1560 * LOWORD: provided size of the buffer in characters
1561 */
1562 EXTERN_C DWORD WINAPI DoEnvironmentSubstW(LPWSTR pszString, UINT cchString)
1563 {
1564 LPWSTR dst;
1565 BOOL res = FALSE;
1566 DWORD len = cchString;
1567
1568 TRACE("(%s, %d)\n", debugstr_w(pszString), cchString);
1569
1570 if ((cchString < MAXLONG) && (dst = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(WCHAR))))
1571 {
1572 len = ExpandEnvironmentStringsW(pszString, dst, cchString);
1573 /* len includes the terminating 0 */
1574 if (len && len <= cchString)
1575 {
1576 res = TRUE;
1577 memcpy(pszString, dst, len * sizeof(WCHAR));
1578 }
1579 else
1580 len = cchString;
1581
1582 HeapFree(GetProcessHeap(), 0, dst);
1583 }
1584 return MAKELONG(len, res);
1585 }
1586
1587 /************************************************************************
1588 * DoEnvironmentSubst [SHELL32.53]
1589 *
1590 * See DoEnvironmentSubstA.
1591 */
1592 DWORD WINAPI DoEnvironmentSubstAW(LPVOID x, UINT y)
1593 {
1594 if (SHELL_OsIsUnicode())
1595 return DoEnvironmentSubstW((LPWSTR)x, y);
1596 return DoEnvironmentSubstA((LPSTR)x, y);
1597 }
1598
1599 /*************************************************************************
1600 * GUIDFromStringA [SHELL32.703]
1601 */
1602 BOOL WINAPI GUIDFromStringA(LPCSTR str, LPGUID guid)
1603 {
1604 TRACE("GUIDFromStringA() stub\n");
1605 return FALSE;
1606 }
1607
1608 /*************************************************************************
1609 * GUIDFromStringW [SHELL32.704]
1610 */
1611 BOOL WINAPI GUIDFromStringW(LPCWSTR str, LPGUID guid)
1612 {
1613 UNICODE_STRING guid_str;
1614
1615 RtlInitUnicodeString(&guid_str, str);
1616 return !RtlGUIDFromString(&guid_str, guid);
1617 }
1618
1619 /*************************************************************************
1620 * PathIsTemporaryW [SHELL32.714]
1621 */
1622 EXTERN_C BOOL WINAPI PathIsTemporaryW(LPWSTR Str)
1623 {
1624 FIXME("(%s)stub\n", debugstr_w(Str));
1625 return FALSE;
1626 }
1627
1628 /*************************************************************************
1629 * PathIsTemporaryA [SHELL32.713]
1630 */
1631 EXTERN_C BOOL WINAPI PathIsTemporaryA(LPSTR Str)
1632 {
1633 FIXME("(%s)stub\n", debugstr_a(Str));
1634 return FALSE;
1635 }
1636
1637 typedef struct _PSXA
1638 {
1639 UINT uiCount;
1640 UINT uiAllocated;
1641 IShellPropSheetExt *pspsx[0];
1642 } PSXA, *PPSXA;
1643
1644 typedef struct _PSXA_CALL
1645 {
1646 LPFNADDPROPSHEETPAGE lpfnAddReplaceWith;
1647 LPARAM lParam;
1648 BOOL bCalled;
1649 BOOL bMultiple;
1650 UINT uiCount;
1651 } PSXA_CALL, *PPSXA_CALL;
1652
1653 static BOOL CALLBACK PsxaCall(HPROPSHEETPAGE hpage, LPARAM lParam)
1654 {
1655 PPSXA_CALL Call = (PPSXA_CALL)lParam;
1656
1657 if (Call != NULL)
1658 {
1659 if ((Call->bMultiple || !Call->bCalled) &&
1660 Call->lpfnAddReplaceWith(hpage, Call->lParam))
1661 {
1662 Call->bCalled = TRUE;
1663 Call->uiCount++;
1664 return TRUE;
1665 }
1666 }
1667
1668 return FALSE;
1669 }
1670
1671 /*************************************************************************
1672 * SHAddFromPropSheetExtArray [SHELL32.167]
1673 */
1674 UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
1675 {
1676 PSXA_CALL Call;
1677 UINT i;
1678 PPSXA psxa = (PPSXA)hpsxa;
1679
1680 TRACE("(%p,%p,%08lx)\n", hpsxa, lpfnAddPage, lParam);
1681
1682 if (psxa)
1683 {
1684 ZeroMemory(&Call, sizeof(Call));
1685 Call.lpfnAddReplaceWith = lpfnAddPage;
1686 Call.lParam = lParam;
1687 Call.bMultiple = TRUE;
1688
1689 /* Call the AddPage method of all registered IShellPropSheetExt interfaces */
1690 for (i = 0; i != psxa->uiCount; i++)
1691 {
1692 psxa->pspsx[i]->AddPages(PsxaCall, (LPARAM)&Call);
1693 }
1694
1695 return Call.uiCount;
1696 }
1697
1698 return 0;
1699 }
1700
1701 /*************************************************************************
1702 * SHCreatePropSheetExtArray [SHELL32.168]
1703 */
1704 HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
1705 {
1706 return SHCreatePropSheetExtArrayEx(hKey, pszSubKey, max_iface, NULL);
1707 }
1708
1709
1710 /*************************************************************************
1711 * SHCreatePropSheetExtArrayEx [SHELL32.194]
1712 */
1713 EXTERN_C HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj)
1714 {
1715 static const WCHAR szPropSheetSubKey[] = {'s','h','e','l','l','e','x','\\','P','r','o','p','e','r','t','y','S','h','e','e','t','H','a','n','d','l','e','r','s',0};
1716 WCHAR szHandler[64];
1717 DWORD dwHandlerLen;
1718 WCHAR szClsidHandler[39];
1719 DWORD dwClsidSize;
1720 CLSID clsid;
1721 LONG lRet;
1722 DWORD dwIndex;
1723 HKEY hkBase, hkPropSheetHandlers;
1724 PPSXA psxa = NULL;
1725 HRESULT hr;
1726
1727 TRACE("(%p,%s,%u)\n", hKey, debugstr_w(pszSubKey), max_iface);
1728
1729 if (max_iface == 0)
1730 return NULL;
1731
1732 /* Open the registry key */
1733 lRet = RegOpenKeyW(hKey, pszSubKey, &hkBase);
1734 if (lRet != ERROR_SUCCESS)
1735 return NULL;
1736
1737 lRet = RegOpenKeyExW(hkBase, szPropSheetSubKey, 0, KEY_ENUMERATE_SUB_KEYS, &hkPropSheetHandlers);
1738 RegCloseKey(hkBase);
1739 if (lRet == ERROR_SUCCESS)
1740 {
1741 /* Create and initialize the Property Sheet Extensions Array */
1742 psxa = (PPSXA)LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, sizeof(PSXA) + max_iface * sizeof(IShellPropSheetExt *));
1743 if (psxa)
1744 {
1745 psxa->uiAllocated = max_iface;
1746
1747 /* Enumerate all subkeys and attempt to load the shell extensions */
1748 dwIndex = 0;
1749 do
1750 {
1751 dwHandlerLen = sizeof(szHandler) / sizeof(szHandler[0]);
1752 lRet = RegEnumKeyExW(hkPropSheetHandlers, dwIndex++, szHandler, &dwHandlerLen, NULL, NULL, NULL, NULL);
1753 if (lRet != ERROR_SUCCESS)
1754 {
1755 if (lRet == ERROR_MORE_DATA)
1756 continue;
1757
1758 if (lRet == ERROR_NO_MORE_ITEMS)
1759 lRet = ERROR_SUCCESS;
1760 break;
1761 }
1762 szHandler[(sizeof(szHandler) / sizeof(szHandler[0])) - 1] = 0;
1763 hr = CLSIDFromString(szHandler, &clsid);
1764 if (FAILED(hr))
1765 {
1766 dwClsidSize = sizeof(szClsidHandler);
1767 if (SHGetValueW(hkPropSheetHandlers, szHandler, NULL, NULL, szClsidHandler, &dwClsidSize) == ERROR_SUCCESS)
1768 {
1769 szClsidHandler[(sizeof(szClsidHandler) / sizeof(szClsidHandler[0])) - 1] = 0;
1770 hr = CLSIDFromString(szClsidHandler, &clsid);
1771 }
1772 }
1773 if (SUCCEEDED(hr))
1774 {
1775 CComPtr<IShellExtInit> psxi;
1776 CComPtr<IShellPropSheetExt> pspsx;
1777
1778 /* Attempt to get an IShellPropSheetExt and an IShellExtInit instance.
1779 Only if both interfaces are supported it's a real shell extension.
1780 Then call IShellExtInit's Initialize method. */
1781 if (SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER/* | CLSCTX_NO_CODE_DOWNLOAD */, IID_PPV_ARG(IShellPropSheetExt, &pspsx))))
1782 {
1783 if (SUCCEEDED(pspsx->QueryInterface(IID_PPV_ARG(IShellExtInit, &psxi))))
1784 {
1785 if (SUCCEEDED(psxi->Initialize(NULL, pDataObj, hKey)))
1786 {
1787 /* Add the IShellPropSheetExt instance to the array */
1788 psxa->pspsx[psxa->uiCount++] = pspsx.Detach();
1789 }
1790 }
1791 }
1792 }
1793 } while (psxa->uiCount != psxa->uiAllocated);
1794 }
1795 else
1796 lRet = ERROR_NOT_ENOUGH_MEMORY;
1797
1798 RegCloseKey(hkPropSheetHandlers);
1799 }
1800
1801 if (lRet != ERROR_SUCCESS && psxa)
1802 {
1803 SHDestroyPropSheetExtArray((HPSXA)psxa);
1804 psxa = NULL;
1805 }
1806
1807 return (HPSXA)psxa;
1808 }
1809
1810 /*************************************************************************
1811 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1812 */
1813 UINT WINAPI SHReplaceFromPropSheetExtArray(HPSXA hpsxa, UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
1814 {
1815 PSXA_CALL Call;
1816 UINT i;
1817 PPSXA psxa = (PPSXA)hpsxa;
1818
1819 TRACE("(%p,%u,%p,%08lx)\n", hpsxa, uPageID, lpfnReplaceWith, lParam);
1820
1821 if (psxa)
1822 {
1823 ZeroMemory(&Call, sizeof(Call));
1824 Call.lpfnAddReplaceWith = lpfnReplaceWith;
1825 Call.lParam = lParam;
1826
1827 /* Call the ReplacePage method of all registered IShellPropSheetExt interfaces.
1828 Each shell extension is only allowed to call the callback once during the callback. */
1829 for (i = 0; i != psxa->uiCount; i++)
1830 {
1831 Call.bCalled = FALSE;
1832 psxa->pspsx[i]->ReplacePage(uPageID, PsxaCall, (LPARAM)&Call);
1833 }
1834
1835 return Call.uiCount;
1836 }
1837
1838 return 0;
1839 }
1840
1841 /*************************************************************************
1842 * SHDestroyPropSheetExtArray [SHELL32.169]
1843 */
1844 void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
1845 {
1846 UINT i;
1847 PPSXA psxa = (PPSXA)hpsxa;
1848
1849 TRACE("(%p)\n", hpsxa);
1850
1851 if (psxa)
1852 {
1853 for (i = 0; i != psxa->uiCount; i++)
1854 {
1855 psxa->pspsx[i]->Release();
1856 }
1857
1858 LocalFree((HLOCAL)psxa);
1859 }
1860 }
1861
1862 /*************************************************************************
1863 * CIDLData_CreateFromIDArray [SHELL32.83]
1864 *
1865 * Create IDataObject from PIDLs??
1866 */
1867 HRESULT WINAPI CIDLData_CreateFromIDArray(
1868 LPCITEMIDLIST pidlFolder,
1869 UINT cpidlFiles,
1870 LPCITEMIDLIST *lppidlFiles,
1871 IDataObject **ppdataObject)
1872 {
1873 UINT i;
1874 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1875 HRESULT hResult;
1876
1877 TRACE("(%p, %d, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1878 if (TRACE_ON(pidl))
1879 {
1880 pdump (pidlFolder);
1881 for (i = 0; i < cpidlFiles; i++)
1882 pdump(lppidlFiles[i]);
1883 }
1884 hResult = IDataObject_Constructor(hwnd, pidlFolder, lppidlFiles, cpidlFiles, ppdataObject);
1885 return hResult;
1886 }
1887
1888 /*************************************************************************
1889 * SHCreateStdEnumFmtEtc [SHELL32.74]
1890 *
1891 * NOTES
1892 *
1893 */
1894 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1895 UINT cFormats,
1896 const FORMATETC *lpFormats,
1897 LPENUMFORMATETC *ppenumFormatetc)
1898 {
1899 CComPtr<IEnumFORMATETC> pef;
1900 HRESULT hRes;
1901 TRACE("cf=%d fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1902
1903 hRes = IEnumFORMATETC_Constructor(cFormats, lpFormats, &pef);
1904 if (FAILED(hRes))
1905 return hRes;
1906
1907 pef->AddRef();
1908 hRes = pef->QueryInterface(IID_PPV_ARG(IEnumFORMATETC, ppenumFormatetc));
1909
1910 return hRes;
1911 }
1912
1913
1914 /*************************************************************************
1915 * SHCreateShellFolderView (SHELL32.256)
1916 */
1917 HRESULT WINAPI SHCreateShellFolderView(const SFV_CREATE *pcsfv, IShellView **ppsv)
1918 {
1919 CComPtr<IShellView> psf;
1920 HRESULT hRes;
1921
1922 *ppsv = NULL;
1923 if (!pcsfv || pcsfv->cbSize != sizeof(*pcsfv))
1924 return E_INVALIDARG;
1925
1926 TRACE("sf=%p outer=%p callback=%p\n",
1927 pcsfv->pshf, pcsfv->psvOuter, pcsfv->psfvcb);
1928
1929 hRes = IShellView_Constructor(pcsfv->pshf, &psf);
1930 if (FAILED(hRes))
1931 return hRes;
1932
1933 hRes = psf->QueryInterface(IID_PPV_ARG(IShellView, ppsv));
1934
1935 return hRes;
1936 }
1937
1938 /*************************************************************************
1939 * SHFindFiles (SHELL32.90)
1940 */
1941 BOOL WINAPI SHFindFiles( LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlSaveFile )
1942 {
1943 FIXME("%p %p\n", pidlFolder, pidlSaveFile );
1944 return FALSE;
1945 }
1946
1947 /*************************************************************************
1948 * SHUpdateImageW (SHELL32.192)
1949 *
1950 * Notifies the shell that an icon in the system image list has been changed.
1951 *
1952 * PARAMS
1953 * pszHashItem [I] Path to file that contains the icon.
1954 * iIndex [I] Zero-based index of the icon in the file.
1955 * uFlags [I] Flags determining the icon attributes. See notes.
1956 * iImageIndex [I] Index of the icon in the system image list.
1957 *
1958 * RETURNS
1959 * Nothing
1960 *
1961 * NOTES
1962 * uFlags can be one or more of the following flags:
1963 * GIL_NOTFILENAME - pszHashItem is not a file name.
1964 * GIL_SIMULATEDOC - Create a document icon using the specified icon.
1965 */
1966 void WINAPI SHUpdateImageW(LPCWSTR pszHashItem, int iIndex, UINT uFlags, int iImageIndex)
1967 {
1968 FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_w(pszHashItem), iIndex, uFlags, iImageIndex);
1969 }
1970
1971 /*************************************************************************
1972 * SHUpdateImageA (SHELL32.191)
1973 *
1974 * See SHUpdateImageW.
1975 */
1976 VOID WINAPI SHUpdateImageA(LPCSTR pszHashItem, INT iIndex, UINT uFlags, INT iImageIndex)
1977 {
1978 FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_a(pszHashItem), iIndex, uFlags, iImageIndex);
1979 }
1980
1981 INT WINAPI SHHandleUpdateImage(LPCITEMIDLIST pidlExtra)
1982 {
1983 FIXME("%p - stub\n", pidlExtra);
1984
1985 return -1;
1986 }
1987
1988 BOOL WINAPI SHObjectProperties(HWND hwnd, DWORD dwType, LPCWSTR szObject, LPCWSTR szPage)
1989 {
1990 FIXME("%p, 0x%08x, %s, %s - stub\n", hwnd, dwType, debugstr_w(szObject), debugstr_w(szPage));
1991
1992 return TRUE;
1993 }
1994
1995 BOOL WINAPI SHGetNewLinkInfoA(LPCSTR pszLinkTo, LPCSTR pszDir, LPSTR pszName, BOOL *pfMustCopy,
1996 UINT uFlags)
1997 {
1998 WCHAR wszLinkTo[MAX_PATH];
1999 WCHAR wszDir[MAX_PATH];
2000 WCHAR wszName[MAX_PATH];
2001 BOOL res;
2002
2003 MultiByteToWideChar(CP_ACP, 0, pszLinkTo, -1, wszLinkTo, MAX_PATH);
2004 MultiByteToWideChar(CP_ACP, 0, pszDir, -1, wszDir, MAX_PATH);
2005
2006 res = SHGetNewLinkInfoW(wszLinkTo, wszDir, wszName, pfMustCopy, uFlags);
2007
2008 if (res)
2009 WideCharToMultiByte(CP_ACP, 0, wszName, -1, pszName, MAX_PATH, NULL, NULL);
2010
2011 return res;
2012 }
2013
2014 BOOL WINAPI SHGetNewLinkInfoW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName, BOOL *pfMustCopy,
2015 UINT uFlags)
2016 {
2017 const WCHAR *basename;
2018 WCHAR *dst_basename;
2019 int i=2;
2020 static const WCHAR lnkformat[] = {'%','s','.','l','n','k',0};
2021 static const WCHAR lnkformatnum[] = {'%','s',' ','(','%','d',')','.','l','n','k',0};
2022
2023 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(pszLinkTo), debugstr_w(pszDir),
2024 pszName, pfMustCopy, uFlags);
2025
2026 *pfMustCopy = FALSE;
2027
2028 if (uFlags & SHGNLI_PIDL)
2029 {
2030 FIXME("SHGNLI_PIDL flag unsupported\n");
2031 return FALSE;
2032 }
2033
2034 if (uFlags)
2035 FIXME("ignoring flags: 0x%08x\n", uFlags);
2036
2037 /* FIXME: should test if the file is a shortcut or DOS program */
2038 if (GetFileAttributesW(pszLinkTo) == INVALID_FILE_ATTRIBUTES)
2039 return FALSE;
2040
2041 basename = strrchrW(pszLinkTo, '\\');
2042 if (basename)
2043 basename = basename+1;
2044 else
2045 basename = pszLinkTo;
2046
2047 lstrcpynW(pszName, pszDir, MAX_PATH);
2048 if (!PathAddBackslashW(pszName))
2049 return FALSE;
2050
2051 dst_basename = pszName + strlenW(pszName);
2052
2053 snprintfW(dst_basename, pszName + MAX_PATH - dst_basename, lnkformat, basename);
2054
2055 while (GetFileAttributesW(pszName) != INVALID_FILE_ATTRIBUTES)
2056 {
2057 snprintfW(dst_basename, pszName + MAX_PATH - dst_basename, lnkformatnum, basename, i);
2058 i++;
2059 }
2060
2061 return TRUE;
2062 }
2063
2064 /*************************************************************************
2065 * SHStartNetConnectionDialog (SHELL32.@)
2066 */
2067 HRESULT WINAPI SHStartNetConnectionDialog(HWND hwnd, LPCSTR pszRemoteName, DWORD dwType)
2068 {
2069 FIXME("%p, %s, 0x%08x - stub\n", hwnd, debugstr_a(pszRemoteName), dwType);
2070
2071 return S_OK;
2072 }
2073 /*************************************************************************
2074 * SHEmptyRecycleBinA (SHELL32.@)
2075 */
2076 HRESULT WINAPI SHEmptyRecycleBinA(HWND hwnd, LPCSTR pszRootPath, DWORD dwFlags)
2077 {
2078 LPWSTR szRootPathW = NULL;
2079 int len;
2080 HRESULT hr;
2081
2082 TRACE("%p, %s, 0x%08x\n", hwnd, debugstr_a(pszRootPath), dwFlags);
2083
2084 if (pszRootPath)
2085 {
2086 len = MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, NULL, 0);
2087 if (len == 0)
2088 return HRESULT_FROM_WIN32(GetLastError());
2089 szRootPathW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2090 if (!szRootPathW)
2091 return E_OUTOFMEMORY;
2092 if (MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, szRootPathW, len) == 0)
2093 {
2094 HeapFree(GetProcessHeap(), 0, szRootPathW);
2095 return HRESULT_FROM_WIN32(GetLastError());
2096 }
2097 }
2098
2099 hr = SHEmptyRecycleBinW(hwnd, szRootPathW, dwFlags);
2100 HeapFree(GetProcessHeap(), 0, szRootPathW);
2101
2102 return hr;
2103 }
2104
2105 HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags)
2106 {
2107 WCHAR szPath[MAX_PATH] = {0};
2108 DWORD dwSize, dwType;
2109 LONG ret;
2110
2111 TRACE("%p, %s, 0x%08x\n", hwnd, debugstr_w(pszRootPath), dwFlags);
2112
2113 if (!(dwFlags & SHERB_NOCONFIRMATION))
2114 {
2115 /* FIXME
2116 * enumerate available files
2117 * show confirmation dialog
2118 */
2119 FIXME("show confirmation dialog\n");
2120 }
2121
2122 if (dwFlags & SHERB_NOPROGRESSUI)
2123 {
2124 ret = EmptyRecycleBinW(pszRootPath);
2125 }
2126 else
2127 {
2128 /* FIXME
2129 * show a progress dialog
2130 */
2131 ret = EmptyRecycleBinW(pszRootPath);
2132 }
2133
2134 if (!ret)
2135 return HRESULT_FROM_WIN32(GetLastError());
2136
2137 if (!(dwFlags & SHERB_NOSOUND))
2138 {
2139 dwSize = sizeof(szPath);
2140 ret = RegGetValueW(HKEY_CURRENT_USER,
2141 L"AppEvents\\Schemes\\Apps\\Explorer\\EmptyRecycleBin\\.Current",
2142 NULL,
2143 RRF_RT_REG_EXPAND_SZ,
2144 &dwType,
2145 (PVOID)szPath,
2146 &dwSize);
2147 if (ret != ERROR_SUCCESS)
2148 return S_OK;
2149
2150 if (dwType != REG_EXPAND_SZ) /* type dismatch */
2151 return S_OK;
2152
2153 szPath[(sizeof(szPath)/sizeof(WCHAR))-1] = L'\0';
2154 PlaySoundW(szPath, NULL, SND_FILENAME);
2155 }
2156 return S_OK;
2157 }
2158
2159 HRESULT WINAPI SHQueryRecycleBinA(LPCSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
2160 {
2161 LPWSTR szRootPathW = NULL;
2162 int len;
2163 HRESULT hr;
2164
2165 TRACE("%s, %p\n", debugstr_a(pszRootPath), pSHQueryRBInfo);
2166
2167 if (pszRootPath)
2168 {
2169 len = MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, NULL, 0);
2170 if (len == 0)
2171 return HRESULT_FROM_WIN32(GetLastError());
2172 szRootPathW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2173 if (!szRootPathW)
2174 return E_OUTOFMEMORY;
2175 if (MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, szRootPathW, len) == 0)
2176 {
2177 HeapFree(GetProcessHeap(), 0, szRootPathW);
2178 return HRESULT_FROM_WIN32(GetLastError());
2179 }
2180 }
2181
2182 hr = SHQueryRecycleBinW(szRootPathW, pSHQueryRBInfo);
2183 HeapFree(GetProcessHeap(), 0, szRootPathW);
2184
2185 return hr;
2186 }
2187
2188 HRESULT WINAPI SHQueryRecycleBinW(LPCWSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
2189 {
2190 FIXME("%s, %p - stub\n", debugstr_w(pszRootPath), pSHQueryRBInfo);
2191
2192 if (!(pszRootPath) || (pszRootPath[0] == 0) ||
2193 !(pSHQueryRBInfo) || (pSHQueryRBInfo->cbSize < sizeof(SHQUERYRBINFO)))
2194 {
2195 return E_INVALIDARG;
2196 }
2197
2198 pSHQueryRBInfo->i64Size = 0;
2199 pSHQueryRBInfo->i64NumItems = 0;
2200
2201 return S_OK;
2202 }
2203
2204 /*************************************************************************
2205 * SHSetLocalizedName (SHELL32.@)
2206 */
2207 EXTERN_C HRESULT WINAPI SHSetLocalizedName(LPCWSTR pszPath, LPCWSTR pszResModule, int idsRes)
2208 {
2209 FIXME("%p, %s, %d - stub\n", pszPath, debugstr_w(pszResModule), idsRes);
2210
2211 return S_OK;
2212 }
2213
2214 /*************************************************************************
2215 * LinkWindow_RegisterClass (SHELL32.258)
2216 */
2217 EXTERN_C BOOL WINAPI LinkWindow_RegisterClass(void)
2218 {
2219 FIXME("()\n");
2220 return TRUE;
2221 }
2222
2223 /*************************************************************************
2224 * LinkWindow_UnregisterClass (SHELL32.259)
2225 */
2226 EXTERN_C BOOL WINAPI LinkWindow_UnregisterClass(void)
2227 {
2228 FIXME("()\n");
2229 return TRUE;
2230
2231 }
2232
2233 /*************************************************************************
2234 * SHFlushSFCache (SHELL32.526)
2235 *
2236 * Notifies the shell that a user-specified special folder location has changed.
2237 *
2238 * NOTES
2239 * In Wine, the shell folder registry values are not cached, so this function
2240 * has no effect.
2241 */
2242 EXTERN_C void WINAPI SHFlushSFCache(void)
2243 {
2244 }
2245
2246 /*************************************************************************
2247 * SHGetImageList (SHELL32.727)
2248 *
2249 * Returns a copy of a shell image list.
2250 *
2251 * NOTES
2252 * Windows XP features 4 sizes of image list, and Vista 5. Wine currently
2253 * only supports the traditional small and large image lists, so requests
2254 * for the others will currently fail.
2255 */
2256 EXTERN_C HRESULT WINAPI SHGetImageList(int iImageList, REFIID riid, void **ppv)
2257 {
2258 HIMAGELIST hLarge, hSmall;
2259 HIMAGELIST hNew;
2260 HRESULT ret = E_FAIL;
2261
2262 /* Wine currently only maintains large and small image lists */
2263 if ((iImageList != SHIL_LARGE) && (iImageList != SHIL_SMALL) && (iImageList != SHIL_SYSSMALL))
2264 {
2265 FIXME("Unsupported image list %i requested\n", iImageList);
2266 return E_FAIL;
2267 }
2268
2269 Shell_GetImageLists(&hLarge, &hSmall);
2270
2271 // Duplicating the imagelist causes the start menu items not to draw on the first show.
2272 // Was the Duplicate necessary for some reason? I believe Windows returns the raw pointer here.
2273 hNew = /*ImageList_Duplicate*/(iImageList == SHIL_LARGE ? hLarge : hSmall);
2274
2275 /* Get the interface for the new image list */
2276 if (hNew)
2277 {
2278 IImageList *imageList = reinterpret_cast<IImageList*>(hNew);
2279 ret = imageList->QueryInterface(riid, ppv);
2280
2281 // Since we are not duplicating, destroying makes no sense.
2282 /* ImageList_Destroy(hNew); */
2283 }
2284
2285 return ret;
2286 }
2287
2288 /*************************************************************************
2289 * SHParseDisplayName [shell version 6.0]
2290 */
2291 EXTERN_C HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc,
2292 LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
2293 {
2294 CComPtr<IShellFolder> psfDesktop;
2295 HRESULT hr=E_FAIL;
2296 ULONG dwAttr=sfgaoIn;
2297
2298 if(!ppidl)
2299 return E_INVALIDARG;
2300
2301 if (!pszName || !psfgaoOut)
2302 {
2303 *ppidl = NULL;
2304 return E_INVALIDARG;
2305 }
2306
2307 hr = SHGetDesktopFolder(&psfDesktop);
2308 if (FAILED(hr))
2309 {
2310 *ppidl = NULL;
2311 return hr;
2312 }
2313
2314 hr = psfDesktop->ParseDisplayName((HWND)NULL, pbc, (LPOLESTR)pszName, (ULONG *)NULL, ppidl, &dwAttr);
2315
2316 psfDesktop->Release();
2317
2318 if (SUCCEEDED(hr))
2319 *psfgaoOut = dwAttr;
2320 else
2321 *ppidl = NULL;
2322
2323 return hr;
2324 }