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