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