[CMAKE]
[reactos.git] / 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 WINAPI 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 WINAPI 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 CHAR * ext;
689 IMalloc *ppM;
690 LPITEMIDLIST pidl;
691 HWND hwnd = 0; /* FIXME: get real window handle */
692 INT ret;
693 DWORD data[64], datalen, type;
694
695 TRACE("%04x %p\n", uFlags, pv);
696
697 /*FIXME: Document:
698 * RecentDocs MRU data structure seems to be:
699 * +0h document file name w/ terminating 0h
700 * +nh short int w/ size of remaining
701 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
702 * +n+4h 10 bytes zeros - unknown
703 * +n+eh shortcut file name w/ terminating 0h
704 * +n+e+nh 3 zero bytes - unknown
705 */
706
707 /* See if we need to do anything.
708 */
709 datalen = 64;
710 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, data, &datalen);
711 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
712 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
713 return;
714 }
715 if (ret == ERROR_SUCCESS) {
716 if (!( (type == REG_DWORD) ||
717 ((type == REG_BINARY) && (datalen == 4)) )) {
718 ERR("Error policy data for \"NoRecentDocsHistory\" not formatted correctly, type=%d, len=%d\n",
719 type, datalen);
720 return;
721 }
722
723 TRACE("policy value for NoRecentDocsHistory = %08x\n", data[0]);
724 /* now test the actual policy value */
725 if ( data[0] != 0)
726 return;
727 }
728
729 /* Open key to where the necessary info is
730 */
731 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
732 * and the close should be done during the _DETACH. The resulting
733 * key is stored in the DLL global data.
734 */
735 if (RegCreateKeyExA(HKEY_CURRENT_USER,
736 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
737 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
738 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
739 return;
740 }
741
742 /* Get path to user's "Recent" directory
743 */
744 if(SUCCEEDED(SHGetMalloc(&ppM))) {
745 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
746 &pidl))) {
747 SHGetPathFromIDListA(pidl, link_dir);
748 IMalloc_Free(ppM, pidl);
749 }
750 else {
751 /* serious issues */
752 link_dir[0] = 0;
753 ERR("serious issues 1\n");
754 }
755 IMalloc_Release(ppM);
756 }
757 else {
758 /* serious issues */
759 link_dir[0] = 0;
760 ERR("serious issues 2\n");
761 }
762 TRACE("Users Recent dir %s\n", link_dir);
763
764 /* If no input, then go clear the lists */
765 if (!pv) {
766 /* clear user's Recent dir
767 */
768
769 /* FIXME: delete all files in "link_dir"
770 *
771 * while( more files ) {
772 * lstrcpyA(old_lnk_name, link_dir);
773 * PathAppendA(old_lnk_name, filenam);
774 * DeleteFileA(old_lnk_name);
775 * }
776 */
777 FIXME("should delete all files in %s\\\n", link_dir);
778
779 /* clear MRU list
780 */
781 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
782 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
783 * and naturally it fails w/ rc=2. It should do it against
784 * HKEY_CURRENT_USER which is where it is stored, and where
785 * the MRU routines expect it!!!!
786 */
787 RegDeleteKeyA(HCUbasekey, "RecentDocs");
788 RegCloseKey(HCUbasekey);
789 return;
790 }
791
792 /* Have data to add, the jobs to be done:
793 * 1. Add document to MRU list in registry "HKCU\Software\
794 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
795 * 2. Add shortcut to document in the user's Recent directory
796 * (CSIDL_RECENT).
797 * 3. Add shortcut to Start menu's Documents submenu.
798 */
799
800 /* Get the pure document name from the input
801 */
802 switch (uFlags)
803 {
804 case SHARD_PIDL:
805 SHGetPathFromIDListA(pv, doc_name);
806 break;
807
808 case SHARD_PATHA:
809 lstrcpynA(doc_name, pv, MAX_PATH);
810 break;
811
812 case SHARD_PATHW:
813 WideCharToMultiByte(CP_ACP, 0, pv, -1, doc_name, MAX_PATH, NULL, NULL);
814 break;
815
816 default:
817 FIXME("Unsupported flags: %u\n", uFlags);
818 return;
819 }
820
821 TRACE("full document name %s\n", debugstr_a(doc_name));
822
823 /* check if file is a shortcut */
824 ext = strrchr(doc_name, '.');
825 if (!lstrcmpiA(ext, ".lnk"))
826 {
827 IShellLinkA * ShellLink;
828
829 IShellLink_ConstructFromFile(NULL, &IID_IShellLinkA, (LPCITEMIDLIST)SHSimpleIDListFromPathA(doc_name), (LPVOID*)&ShellLink);
830 IShellLinkA_GetPath(ShellLink, doc_name, MAX_PATH, NULL, 0);
831
832 IShellLinkA_Release(ShellLink);
833 }
834
835 ext = strrchr(doc_name, '.');
836 if (!lstrcmpiA(ext, ".exe"))
837 {
838 /* executables are not added */
839 return;
840 }
841
842 PathStripPathA(doc_name);
843 TRACE("stripped document name %s\n", debugstr_a(doc_name));
844
845 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
846
847 { /* on input needs:
848 * doc_name - pure file-spec, no path
849 * link_dir - path to the user's Recent directory
850 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
851 * creates:
852 * new_lnk_name- pure file-spec, no path for new .lnk file
853 * new_lnk_filepath
854 * - path and file name of new .lnk file
855 */
856 CREATEMRULISTA mymru;
857 HANDLE mruhandle;
858 INT len, pos, bufused, err;
859 INT i;
860 DWORD attr;
861 CHAR buffer[2048];
862 CHAR *ptr;
863 CHAR old_lnk_name[MAX_PATH];
864 short int slen;
865
866 mymru.cbSize = sizeof(CREATEMRULISTA);
867 mymru.nMaxItems = 15;
868 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
869 mymru.hKey = HCUbasekey;
870 mymru.lpszSubKey = "RecentDocs";
871 mymru.lpfnCompare = (PROC)SHADD_compare_mru;
872 mruhandle = CreateMRUListA(&mymru);
873 if (!mruhandle) {
874 /* MRU failed */
875 ERR("MRU processing failed, handle zero\n");
876 RegCloseKey(HCUbasekey);
877 return;
878 }
879 len = lstrlenA(doc_name);
880 pos = FindMRUData(mruhandle, doc_name, len, 0);
881
882 /* Now get the MRU entry that will be replaced
883 * and delete the .lnk file for it
884 */
885 if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
886 buffer, 2048)) != -1) {
887 ptr = buffer;
888 ptr += (lstrlenA(buffer) + 1);
889 slen = *((short int*)ptr);
890 ptr += 2; /* skip the length area */
891 if (bufused >= slen + (ptr-buffer)) {
892 /* buffer size looks good */
893 ptr += 12; /* get to string */
894 len = bufused - (ptr-buffer); /* get length of buf remaining */
895 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
896 /* appears to be good string */
897 lstrcpyA(old_lnk_name, link_dir);
898 PathAppendA(old_lnk_name, ptr);
899 if (!DeleteFileA(old_lnk_name)) {
900 if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) {
901 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
902 ERR("Delete for %s failed, err=%d, attr=%08x\n",
903 old_lnk_name, err, attr);
904 }
905 else {
906 TRACE("old .lnk file %s did not exist\n",
907 old_lnk_name);
908 }
909 }
910 else {
911 ERR("Delete for %s failed, attr=%08x\n",
912 old_lnk_name, attr);
913 }
914 }
915 else {
916 TRACE("deleted old .lnk file %s\n", old_lnk_name);
917 }
918 }
919 }
920 }
921
922 /* Create usable .lnk file name for the "Recent" directory
923 */
924 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
925 lstrcpyA(new_lnk_filepath, link_dir);
926 PathAppendA(new_lnk_filepath, new_lnk_name);
927 i = 1;
928 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
929 while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
930 i++;
931 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
932 lstrcpyA(new_lnk_filepath, link_dir);
933 PathAppendA(new_lnk_filepath, new_lnk_name);
934 }
935 SetErrorMode(olderrormode);
936 TRACE("new shortcut will be %s\n", new_lnk_filepath);
937
938 /* Now add the new MRU entry and data
939 */
940 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
941 buffer, &len);
942 FreeMRUList(mruhandle);
943 TRACE("Updated MRU list, new doc is position %d\n", pos);
944 }
945
946 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
947
948 { /* on input needs:
949 * doc_name - pure file-spec, no path
950 * new_lnk_filepath
951 * - path and file name of new .lnk file
952 * uFlags[in] - flags on call to SHAddToRecentDocs
953 * pv[in] - document path/pidl on call to SHAddToRecentDocs
954 */
955 IShellLinkA *psl = NULL;
956 IPersistFile *pPf = NULL;
957 HRESULT hres;
958 CHAR desc[MAX_PATH];
959 WCHAR widelink[MAX_PATH];
960
961 CoInitialize(0);
962
963 hres = CoCreateInstance( &CLSID_ShellLink,
964 NULL,
965 CLSCTX_INPROC_SERVER,
966 &IID_IShellLinkA,
967 (LPVOID )&psl);
968 if(SUCCEEDED(hres)) {
969
970 hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
971 (LPVOID *)&pPf);
972 if(FAILED(hres)) {
973 /* bombed */
974 ERR("failed QueryInterface for IPersistFile %08x\n", hres);
975 goto fail;
976 }
977
978 /* Set the document path or pidl */
979 if (uFlags == SHARD_PIDL) {
980 hres = IShellLinkA_SetIDList(psl, pv);
981 } else {
982 hres = IShellLinkA_SetPath(psl, pv);
983 }
984 if(FAILED(hres)) {
985 /* bombed */
986 ERR("failed Set{IDList|Path} %08x\n", hres);
987 goto fail;
988 }
989
990 lstrcpyA(desc, "Shortcut to ");
991 lstrcatA(desc, doc_name);
992 hres = IShellLinkA_SetDescription(psl, desc);
993 if(FAILED(hres)) {
994 /* bombed */
995 ERR("failed SetDescription %08x\n", hres);
996 goto fail;
997 }
998
999 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
1000 widelink, MAX_PATH);
1001 /* create the short cut */
1002 hres = IPersistFile_Save(pPf, widelink, TRUE);
1003 if(FAILED(hres)) {
1004 /* bombed */
1005 ERR("failed IPersistFile::Save %08x\n", hres);
1006 IPersistFile_Release(pPf);
1007 IShellLinkA_Release(psl);
1008 goto fail;
1009 }
1010 hres = IPersistFile_SaveCompleted(pPf, widelink);
1011 IPersistFile_Release(pPf);
1012 IShellLinkA_Release(psl);
1013 TRACE("shortcut %s has been created, result=%08x\n",
1014 new_lnk_filepath, hres);
1015 }
1016 else {
1017 ERR("CoCreateInstance failed, hres=%08x\n", hres);
1018 }
1019 }
1020
1021 fail:
1022 CoUninitialize();
1023
1024 /* all done */
1025 RegCloseKey(HCUbasekey);
1026 return;
1027 }
1028
1029 /*************************************************************************
1030 * SHCreateShellFolderViewEx [SHELL32.174]
1031 *
1032 * Create a new instance of the default Shell folder view object.
1033 *
1034 * RETURNS
1035 * Success: S_OK
1036 * Failure: error value
1037 *
1038 * NOTES
1039 * see IShellFolder::CreateViewObject
1040 */
1041 HRESULT WINAPI SHCreateShellFolderViewEx(
1042 LPCSFV psvcbi, /* [in] shelltemplate struct */
1043 IShellView **ppv) /* [out] IShellView pointer */
1044 {
1045 IShellView * psf;
1046 HRESULT hRes;
1047
1048 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=%p\n",
1049 psvcbi->pshf, psvcbi->pidl, psvcbi->pfnCallback,
1050 psvcbi->fvm, psvcbi->psvOuter);
1051
1052 psf = IShellView_Constructor(psvcbi->pshf);
1053
1054 if (!psf)
1055 return E_OUTOFMEMORY;
1056
1057 IShellView_AddRef(psf);
1058 hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
1059 IShellView_Release(psf);
1060
1061 return hRes;
1062 }
1063 /*************************************************************************
1064 * SHWinHelp [SHELL32.127]
1065 *
1066 */
1067 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
1068 { FIXME("0x%08x 0x%08x 0x%08x 0x%08x stub\n",v,w,x,z);
1069 return 0;
1070 }
1071 /*************************************************************************
1072 * SHRunControlPanel [SHELL32.161]
1073 *
1074 */
1075 HRESULT WINAPI SHRunControlPanel (LPCWSTR lpcszCmdLine, HWND hwndMsgParent)
1076 {
1077 FIXME("0x%08x 0x%08x stub\n",lpcszCmdLine,hwndMsgParent);
1078 return 0;
1079 }
1080
1081 static LPUNKNOWN SHELL32_IExplorerInterface=0;
1082 /*************************************************************************
1083 * SHSetInstanceExplorer [SHELL32.176]
1084 *
1085 * NOTES
1086 * Sets the interface
1087 */
1088 VOID WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
1089 { TRACE("%p\n", lpUnknown);
1090 SHELL32_IExplorerInterface = lpUnknown;
1091 }
1092 /*************************************************************************
1093 * SHGetInstanceExplorer [SHELL32.@]
1094 *
1095 * NOTES
1096 * gets the interface pointer of the explorer and a reference
1097 */
1098 HRESULT WINAPI SHGetInstanceExplorer (IUnknown **lpUnknown)
1099 { TRACE("%p\n", lpUnknown);
1100
1101 *lpUnknown = SHELL32_IExplorerInterface;
1102
1103 if (!SHELL32_IExplorerInterface)
1104 return E_FAIL;
1105
1106 IUnknown_AddRef(SHELL32_IExplorerInterface);
1107 return NOERROR;
1108 }
1109 /*************************************************************************
1110 * SHFreeUnusedLibraries [SHELL32.123]
1111 *
1112 * Probably equivalent to CoFreeUnusedLibraries but under Windows 9x it could use
1113 * the shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
1114 * for details
1115 *
1116 * NOTES
1117 * exported by ordinal
1118 *
1119 * SEE ALSO
1120 * CoFreeUnusedLibraries, SHLoadOLE
1121 */
1122 void WINAPI SHFreeUnusedLibraries (void)
1123 {
1124 FIXME("stub\n");
1125 CoFreeUnusedLibraries();
1126 }
1127 /*************************************************************************
1128 * DAD_AutoScroll [SHELL32.129]
1129 *
1130 */
1131 BOOL WINAPI DAD_AutoScroll(HWND hwnd, AUTO_SCROLL_DATA *samples, const POINT * pt)
1132 {
1133 FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1134 return 0;
1135 }
1136 /*************************************************************************
1137 * DAD_DragEnter [SHELL32.130]
1138 *
1139 */
1140 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1141 {
1142 FIXME("hwnd = %p\n",hwnd);
1143 return FALSE;
1144 }
1145 /*************************************************************************
1146 * DAD_DragEnterEx [SHELL32.131]
1147 *
1148 */
1149 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1150 {
1151 FIXME("hwnd = %p (%d,%d)\n",hwnd,p.x,p.y);
1152 return FALSE;
1153 }
1154 /*************************************************************************
1155 * DAD_DragMove [SHELL32.134]
1156 *
1157 */
1158 BOOL WINAPI DAD_DragMove(POINT p)
1159 {
1160 FIXME("(%d,%d)\n",p.x,p.y);
1161 return FALSE;
1162 }
1163 /*************************************************************************
1164 * DAD_DragLeave [SHELL32.132]
1165 *
1166 */
1167 BOOL WINAPI DAD_DragLeave(VOID)
1168 {
1169 FIXME("\n");
1170 return FALSE;
1171 }
1172 /*************************************************************************
1173 * DAD_SetDragImage [SHELL32.136]
1174 *
1175 * NOTES
1176 * exported by name
1177 */
1178 BOOL WINAPI DAD_SetDragImage(
1179 HIMAGELIST himlTrack,
1180 LPPOINT lppt)
1181 {
1182 FIXME("%p %p stub\n",himlTrack, lppt);
1183 return 0;
1184 }
1185 /*************************************************************************
1186 * DAD_ShowDragImage [SHELL32.137]
1187 *
1188 * NOTES
1189 * exported by name
1190 */
1191 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1192 {
1193 FIXME("0x%08x stub\n",bShow);
1194 return 0;
1195 }
1196
1197 static const WCHAR szwCabLocation[] = {
1198 'S','o','f','t','w','a','r','e','\\',
1199 'M','i','c','r','o','s','o','f','t','\\',
1200 'W','i','n','d','o','w','s','\\',
1201 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1202 'E','x','p','l','o','r','e','r','\\',
1203 'C','a','b','i','n','e','t','S','t','a','t','e',0
1204 };
1205
1206 static const WCHAR szwSettings[] = { 'S','e','t','t','i','n','g','s',0 };
1207
1208 /*************************************************************************
1209 * ReadCabinetState [SHELL32.651] NT 4.0
1210 *
1211 */
1212 BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
1213 {
1214 HKEY hkey = 0;
1215 DWORD type, r;
1216
1217 TRACE("%p %d\n", cs, length);
1218
1219 if( (cs == NULL) || (length < (int)sizeof(*cs)) )
1220 return FALSE;
1221
1222 r = RegOpenKeyW( HKEY_CURRENT_USER, szwCabLocation, &hkey );
1223 if( r == ERROR_SUCCESS )
1224 {
1225 type = REG_BINARY;
1226 r = RegQueryValueExW( hkey, szwSettings,
1227 NULL, &type, (LPBYTE)cs, (LPDWORD)&length );
1228 RegCloseKey( hkey );
1229
1230 }
1231
1232 /* if we can't read from the registry, create default values */
1233 if ( (r != ERROR_SUCCESS) || (cs->cLength < sizeof(*cs)) ||
1234 (cs->cLength != length) )
1235 {
1236 ERR("Initializing shell cabinet settings\n");
1237 memset(cs, 0, sizeof(*cs));
1238 cs->cLength = sizeof(*cs);
1239 cs->nVersion = 2;
1240 cs->fFullPathTitle = FALSE;
1241 cs->fSaveLocalView = TRUE;
1242 cs->fNotShell = FALSE;
1243 cs->fSimpleDefault = TRUE;
1244 cs->fDontShowDescBar = FALSE;
1245 cs->fNewWindowMode = FALSE;
1246 cs->fShowCompColor = FALSE;
1247 cs->fDontPrettyNames = FALSE;
1248 cs->fAdminsCreateCommonGroups = TRUE;
1249 cs->fMenuEnumFilter = 96;
1250 }
1251
1252 return TRUE;
1253 }
1254
1255 /*************************************************************************
1256 * WriteCabinetState [SHELL32.652] NT 4.0
1257 *
1258 */
1259 BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
1260 {
1261 DWORD r;
1262 HKEY hkey = 0;
1263
1264 TRACE("%p\n",cs);
1265
1266 if( cs == NULL )
1267 return FALSE;
1268
1269 r = RegCreateKeyExW( HKEY_CURRENT_USER, szwCabLocation, 0,
1270 NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
1271 if( r == ERROR_SUCCESS )
1272 {
1273 r = RegSetValueExW( hkey, szwSettings, 0,
1274 REG_BINARY, (LPBYTE) cs, cs->cLength);
1275
1276 RegCloseKey( hkey );
1277 }
1278
1279 return (r==ERROR_SUCCESS);
1280 }
1281
1282 /*************************************************************************
1283 * FileIconInit [SHELL32.660]
1284 *
1285 */
1286 BOOL WINAPI FileIconInit(BOOL bFullInit)
1287 { FIXME("(%s)\n", bFullInit ? "true" : "false");
1288 return 0;
1289 }
1290
1291 /*************************************************************************
1292 * IsUserAnAdmin [SHELL32.680] NT 4.0
1293 *
1294 * Checks whether the current user is a member of the Administrators group.
1295 *
1296 * PARAMS
1297 * None
1298 *
1299 * RETURNS
1300 * Success: TRUE
1301 * Failure: FALSE
1302 */
1303 BOOL WINAPI IsUserAnAdmin(VOID)
1304 {
1305 SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
1306 HANDLE hToken;
1307 DWORD dwSize;
1308 PTOKEN_GROUPS lpGroups;
1309 PSID lpSid;
1310 DWORD i;
1311 BOOL bResult = FALSE;
1312
1313 TRACE("\n");
1314 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
1315 {
1316 return FALSE;
1317 }
1318
1319 if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
1320 {
1321 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1322 {
1323 CloseHandle(hToken);
1324 return FALSE;
1325 }
1326 }
1327
1328 lpGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
1329 if (lpGroups == NULL)
1330 {
1331 CloseHandle(hToken);
1332 return FALSE;
1333 }
1334
1335 if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize))
1336 {
1337 HeapFree(GetProcessHeap(), 0, lpGroups);
1338 CloseHandle(hToken);
1339 return FALSE;
1340 }
1341
1342 CloseHandle(hToken);
1343
1344 if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
1345 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
1346 &lpSid))
1347 {
1348 HeapFree(GetProcessHeap(), 0, lpGroups);
1349 return FALSE;
1350 }
1351
1352 for (i = 0; i < lpGroups->GroupCount; i++)
1353 {
1354 if (EqualSid(lpSid, lpGroups->Groups[i].Sid))
1355 {
1356 bResult = TRUE;
1357 break;
1358 }
1359 }
1360
1361 FreeSid(lpSid);
1362 HeapFree(GetProcessHeap(), 0, lpGroups);
1363 return bResult;
1364 }
1365
1366 /*************************************************************************
1367 * SHAllocShared [SHELL32.520]
1368 *
1369 * See shlwapi.SHAllocShared
1370 */
1371 HANDLE WINAPI SHAllocShared(LPVOID lpvData, DWORD dwSize, DWORD dwProcId)
1372 {
1373 GET_FUNC(pSHAllocShared, shlwapi, (char*)7, NULL);
1374 return pSHAllocShared(lpvData, dwSize, dwProcId);
1375 }
1376
1377 /*************************************************************************
1378 * SHLockShared [SHELL32.521]
1379 *
1380 * See shlwapi.SHLockShared
1381 */
1382 LPVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
1383 {
1384 GET_FUNC(pSHLockShared, shlwapi, (char*)8, NULL);
1385 return pSHLockShared(hShared, dwProcId);
1386 }
1387
1388 /*************************************************************************
1389 * SHUnlockShared [SHELL32.522]
1390 *
1391 * See shlwapi.SHUnlockShared
1392 */
1393 BOOL WINAPI SHUnlockShared(LPVOID lpView)
1394 {
1395 GET_FUNC(pSHUnlockShared, shlwapi, (char*)9, FALSE);
1396 return pSHUnlockShared(lpView);
1397 }
1398
1399 /*************************************************************************
1400 * SHFreeShared [SHELL32.523]
1401 *
1402 * See shlwapi.SHFreeShared
1403 */
1404 BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
1405 {
1406 GET_FUNC(pSHFreeShared, shlwapi, (char*)10, FALSE);
1407 return pSHFreeShared(hShared, dwProcId);
1408 }
1409
1410 /*************************************************************************
1411 * SetAppStartingCursor [SHELL32.99]
1412 */
1413 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1414 { FIXME("hwnd=%p 0x%04x stub\n",u,v );
1415 return 0;
1416 }
1417
1418 /*************************************************************************
1419 * SHLoadOLE [SHELL32.151]
1420 *
1421 * To reduce the memory usage of Windows 95, its shell32 contained an
1422 * internal implementation of a part of COM (see e.g. SHGetMalloc, SHCoCreateInstance,
1423 * SHRegisterDragDrop etc.) that allowed to use in-process STA objects without
1424 * the need to load OLE32.DLL. If OLE32.DLL was already loaded, the SH* function
1425 * would just call the Co* functions.
1426 *
1427 * The SHLoadOLE was called when OLE32.DLL was being loaded to transfer all the
1428 * information from the shell32 "mini-COM" to ole32.dll.
1429 *
1430 * See http://blogs.msdn.com/oldnewthing/archive/2004/07/05/173226.aspx for a
1431 * detailed description.
1432 *
1433 * Under wine ole32.dll is always loaded as it is imported by shlwapi.dll which is
1434 * imported by shell32 and no "mini-COM" is used (except for the "LoadWithoutCOM"
1435 * hack in SHCoCreateInstance)
1436 */
1437 HRESULT WINAPI SHLoadOLE(LPARAM lParam)
1438 { FIXME("0x%08lx stub\n",lParam);
1439 return S_OK;
1440 }
1441 /*************************************************************************
1442 * DriveType [SHELL32.64]
1443 *
1444 */
1445 HRESULT WINAPI DriveType(int DriveType)
1446 {
1447 WCHAR root[] = L"A:\\";
1448 root[0] = L'A' + DriveType;
1449 return GetDriveTypeW(root);
1450 }
1451 /*************************************************************************
1452 * InvalidateDriveType [SHELL32.65]
1453 * Unimplemented in XP SP3
1454 */
1455 int WINAPI InvalidateDriveType(int u)
1456 {
1457 TRACE("0x%08x stub\n",u);
1458 return 0;
1459 }
1460 /*************************************************************************
1461 * SHAbortInvokeCommand [SHELL32.198]
1462 *
1463 */
1464 HRESULT WINAPI SHAbortInvokeCommand(void)
1465 { FIXME("stub\n");
1466 return 1;
1467 }
1468 /*************************************************************************
1469 * SHOutOfMemoryMessageBox [SHELL32.126]
1470 *
1471 */
1472 int WINAPI SHOutOfMemoryMessageBox(
1473 HWND hwndOwner,
1474 LPCSTR lpCaption,
1475 UINT uType)
1476 {
1477 FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1478 return 0;
1479 }
1480 /*************************************************************************
1481 * SHFlushClipboard [SHELL32.121]
1482 *
1483 */
1484 HRESULT WINAPI SHFlushClipboard(void)
1485 {
1486 return OleFlushClipboard();
1487 }
1488
1489 /*************************************************************************
1490 * SHWaitForFileToOpen [SHELL32.97]
1491 *
1492 */
1493 BOOL WINAPI SHWaitForFileToOpen(
1494 LPCITEMIDLIST pidl,
1495 DWORD dwFlags,
1496 DWORD dwTimeout)
1497 {
1498 FIXME("%p 0x%08x 0x%08x stub\n", pidl, dwFlags, dwTimeout);
1499 return 0;
1500 }
1501
1502 /************************************************************************
1503 * RLBuildListOfPaths [SHELL32.146]
1504 *
1505 * NOTES
1506 * builds a DPA
1507 */
1508 DWORD WINAPI RLBuildListOfPaths (void)
1509 { FIXME("stub\n");
1510 return 0;
1511 }
1512 /************************************************************************
1513 * SHValidateUNC [SHELL32.173]
1514 *
1515 */
1516 HRESULT WINAPI SHValidateUNC (HWND hwndOwner, LPWSTR pszFile, UINT fConnect)
1517 {
1518 FIXME("0x%08x 0x%08x 0x%08x stub\n",hwndOwner,pszFile,fConnect);
1519 return 0;
1520 }
1521
1522 /************************************************************************
1523 * DoEnvironmentSubstA [SHELL32.@]
1524 *
1525 * Replace %KEYWORD% in the str with the value of variable KEYWORD
1526 * from environment. If it is not found the %KEYWORD% is left
1527 * intact. If the buffer is too small, str is not modified.
1528 *
1529 * PARAMS
1530 * pszString [I] '\0' terminated string with %keyword%.
1531 * [O] '\0' terminated string with %keyword% substituted.
1532 * cchString [I] size of str.
1533 *
1534 * RETURNS
1535 * cchString length in the HIWORD;
1536 * TRUE in LOWORD if subst was successful and FALSE in other case
1537 */
1538 DWORD WINAPI DoEnvironmentSubstA(LPSTR pszString, UINT cchString)
1539 {
1540 LPSTR dst;
1541 BOOL res = FALSE;
1542 FIXME("(%s, %d) stub\n", debugstr_a(pszString), cchString);
1543 if (pszString == NULL) /* Really return 0? */
1544 return 0;
1545 if ((dst = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(CHAR))))
1546 {
1547 DWORD num = ExpandEnvironmentStringsA(pszString, dst, cchString);
1548 if (num && num < cchString) /* dest buffer is too small */
1549 {
1550 res = TRUE;
1551 memcpy(pszString, dst, num);
1552 }
1553 HeapFree(GetProcessHeap(), 0, dst);
1554 }
1555 return MAKELONG(res,cchString); /* Always cchString? */
1556 }
1557
1558 /************************************************************************
1559 * DoEnvironmentSubstW [SHELL32.@]
1560 *
1561 * See DoEnvironmentSubstA.
1562 */
1563 DWORD WINAPI DoEnvironmentSubstW(LPWSTR pszString, UINT cchString)
1564 {
1565 LPWSTR dst;
1566 BOOL res = FALSE;
1567 FIXME("(%s, %d): stub\n", debugstr_w(pszString), cchString);
1568 if ((dst = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(WCHAR))))
1569 {
1570 DWORD num = ExpandEnvironmentStringsW(pszString, dst, cchString);
1571 if (num)
1572 {
1573 res = TRUE;
1574 wcscpy(pszString, dst);
1575 }
1576 HeapFree(GetProcessHeap(), 0, dst);
1577 }
1578
1579 return MAKELONG(res,cchString);
1580 }
1581
1582 /************************************************************************
1583 * DoEnvironmentSubst [SHELL32.53]
1584 *
1585 * See DoEnvironmentSubstA.
1586 */
1587 DWORD WINAPI DoEnvironmentSubstAW(LPVOID x, UINT y)
1588 {
1589 if (SHELL_OsIsUnicode())
1590 return DoEnvironmentSubstW(x, y);
1591 return DoEnvironmentSubstA(x, y);
1592 }
1593
1594 /*************************************************************************
1595 * GUIDFromStringA [SHELL32.703]
1596 */
1597 BOOL WINAPI GUIDFromStringA(LPCSTR str, LPGUID guid)
1598 {
1599 TRACE("GUIDFromStringA() stub\n");
1600 return FALSE;
1601 }
1602
1603 /*************************************************************************
1604 * GUIDFromStringW [SHELL32.704]
1605 */
1606 BOOL WINAPI GUIDFromStringW(LPCWSTR str, LPGUID guid)
1607 {
1608 UNICODE_STRING guid_str;
1609
1610 RtlInitUnicodeString(&guid_str, str);
1611 return !RtlGUIDFromString(&guid_str, guid);
1612 }
1613
1614 /*************************************************************************
1615 * PathIsTemporaryW [SHELL32.714]
1616 */
1617 BOOL WINAPI PathIsTemporaryW(LPWSTR Str)
1618 {
1619 FIXME("(%s)stub\n", debugstr_w(Str));
1620 return FALSE;
1621 }
1622
1623 /*************************************************************************
1624 * PathIsTemporaryA [SHELL32.713]
1625 */
1626 BOOL WINAPI PathIsTemporaryA(LPSTR Str)
1627 {
1628 FIXME("(%s)stub\n", debugstr_a(Str));
1629 return FALSE;
1630 }
1631
1632 typedef struct _PSXA
1633 {
1634 UINT uiCount;
1635 UINT uiAllocated;
1636 IShellPropSheetExt *pspsx[1];
1637 } PSXA, *PPSXA;
1638
1639 typedef struct _PSXA_CALL
1640 {
1641 LPFNADDPROPSHEETPAGE lpfnAddReplaceWith;
1642 LPARAM lParam;
1643 BOOL bCalled;
1644 BOOL bMultiple;
1645 UINT uiCount;
1646 } PSXA_CALL, *PPSXA_CALL;
1647
1648 static BOOL CALLBACK PsxaCall(HPROPSHEETPAGE hpage, LPARAM lParam)
1649 {
1650 PPSXA_CALL Call = (PPSXA_CALL)lParam;
1651
1652 if (Call != NULL)
1653 {
1654 if ((Call->bMultiple || !Call->bCalled) &&
1655 Call->lpfnAddReplaceWith(hpage, Call->lParam))
1656 {
1657 Call->bCalled = TRUE;
1658 Call->uiCount++;
1659 return TRUE;
1660 }
1661 }
1662
1663 return FALSE;
1664 }
1665
1666 /*************************************************************************
1667 * SHAddFromPropSheetExtArray [SHELL32.167]
1668 */
1669 UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
1670 {
1671 PSXA_CALL Call;
1672 UINT i;
1673 PPSXA psxa = (PPSXA)hpsxa;
1674
1675 TRACE("(%p,%p,%08lx)\n", hpsxa, lpfnAddPage, lParam);
1676
1677 if (psxa)
1678 {
1679 ZeroMemory(&Call, sizeof(Call));
1680 Call.lpfnAddReplaceWith = lpfnAddPage;
1681 Call.lParam = lParam;
1682 Call.bMultiple = TRUE;
1683
1684 /* Call the AddPage method of all registered IShellPropSheetExt interfaces */
1685 for (i = 0; i != psxa->uiCount; i++)
1686 {
1687 psxa->pspsx[i]->lpVtbl->AddPages(psxa->pspsx[i], PsxaCall, (LPARAM)&Call);
1688 }
1689
1690 return Call.uiCount;
1691 }
1692
1693 return 0;
1694 }
1695
1696 /*************************************************************************
1697 * SHCreatePropSheetExtArray [SHELL32.168]
1698 */
1699 HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
1700 {
1701 return SHCreatePropSheetExtArrayEx(hKey, pszSubKey, max_iface, NULL);
1702 }
1703
1704 /*************************************************************************
1705 * SHCreatePropSheetExtArrayEx [SHELL32.194]
1706 */
1707 HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, IDataObject *pDataObj)
1708 {
1709 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};
1710 WCHAR szHandler[64];
1711 DWORD dwHandlerLen;
1712 WCHAR szClsidHandler[39];
1713 DWORD dwClsidSize;
1714 CLSID clsid;
1715 LONG lRet;
1716 DWORD dwIndex;
1717 IShellExtInit *psxi;
1718 IShellPropSheetExt *pspsx;
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 = LocalAlloc(LMEM_FIXED, FIELD_OFFSET(PSXA, pspsx[max_iface]));
1739 if (psxa)
1740 {
1741 ZeroMemory(psxa, FIELD_OFFSET(PSXA, pspsx[max_iface]));
1742 psxa->uiAllocated = max_iface;
1743
1744 /* Enumerate all subkeys and attempt to load the shell extensions */
1745 dwIndex = 0;
1746 do
1747 {
1748 dwHandlerLen = sizeof(szHandler) / sizeof(szHandler[0]);
1749 lRet = RegEnumKeyExW(hkPropSheetHandlers, dwIndex++, szHandler, &dwHandlerLen, NULL, NULL, NULL, NULL);
1750 if (lRet != ERROR_SUCCESS)
1751 {
1752 if (lRet == ERROR_MORE_DATA)
1753 continue;
1754
1755 if (lRet == ERROR_NO_MORE_ITEMS)
1756 lRet = ERROR_SUCCESS;
1757 break;
1758 }
1759 szHandler[(sizeof(szHandler) / sizeof(szHandler[0])) - 1] = 0;
1760 hr = CLSIDFromString(szHandler, &clsid);
1761 if (FAILED(hr))
1762 {
1763 dwClsidSize = sizeof(szClsidHandler);
1764 if (SHGetValueW(hkPropSheetHandlers, szHandler, NULL, NULL, szClsidHandler, &dwClsidSize) == ERROR_SUCCESS)
1765 {
1766 szClsidHandler[(sizeof(szClsidHandler) / sizeof(szClsidHandler[0])) - 1] = 0;
1767 hr = CLSIDFromString(szClsidHandler, &clsid);
1768 }
1769 }
1770 if (SUCCEEDED(hr))
1771 {
1772 /* Attempt to get an IShellPropSheetExt and an IShellExtInit instance.
1773 Only if both interfaces are supported it's a real shell extension.
1774 Then call IShellExtInit's Initialize method. */
1775 if (SUCCEEDED(CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER/* | CLSCTX_NO_CODE_DOWNLOAD */, &IID_IShellPropSheetExt, (LPVOID *)&pspsx)))
1776 {
1777 if (SUCCEEDED(pspsx->lpVtbl->QueryInterface(pspsx, &IID_IShellExtInit, (PVOID *)&psxi)))
1778 {
1779 if (SUCCEEDED(psxi->lpVtbl->Initialize(psxi, NULL, pDataObj, hKey)))
1780 {
1781 /* Add the IShellPropSheetExt instance to the array */
1782 psxa->pspsx[psxa->uiCount++] = pspsx;
1783 }
1784 else
1785 {
1786 psxi->lpVtbl->Release(psxi);
1787 pspsx->lpVtbl->Release(pspsx);
1788 }
1789 }
1790 else
1791 pspsx->lpVtbl->Release(pspsx);
1792 }
1793 }
1794 } while (psxa->uiCount != psxa->uiAllocated);
1795 }
1796 else
1797 lRet = ERROR_NOT_ENOUGH_MEMORY;
1798
1799 RegCloseKey(hkPropSheetHandlers);
1800 }
1801
1802 if (lRet != ERROR_SUCCESS && psxa)
1803 {
1804 SHDestroyPropSheetExtArray((HPSXA)psxa);
1805 psxa = NULL;
1806 }
1807
1808 return (HPSXA)psxa;
1809 }
1810
1811 /*************************************************************************
1812 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1813 */
1814 UINT WINAPI SHReplaceFromPropSheetExtArray(HPSXA hpsxa, UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
1815 {
1816 PSXA_CALL Call;
1817 UINT i;
1818 PPSXA psxa = (PPSXA)hpsxa;
1819
1820 TRACE("(%p,%u,%p,%08lx)\n", hpsxa, uPageID, lpfnReplaceWith, lParam);
1821
1822 if (psxa)
1823 {
1824 ZeroMemory(&Call, sizeof(Call));
1825 Call.lpfnAddReplaceWith = lpfnReplaceWith;
1826 Call.lParam = lParam;
1827
1828 /* Call the ReplacePage method of all registered IShellPropSheetExt interfaces.
1829 Each shell extension is only allowed to call the callback once during the callback. */
1830 for (i = 0; i != psxa->uiCount; i++)
1831 {
1832 Call.bCalled = FALSE;
1833 psxa->pspsx[i]->lpVtbl->ReplacePage(psxa->pspsx[i], uPageID, PsxaCall, (LPARAM)&Call);
1834 }
1835
1836 return Call.uiCount;
1837 }
1838
1839 return 0;
1840 }
1841
1842 /*************************************************************************
1843 * SHDestroyPropSheetExtArray [SHELL32.169]
1844 */
1845 void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
1846 {
1847 UINT i;
1848 PPSXA psxa = (PPSXA)hpsxa;
1849
1850 TRACE("(%p)\n", hpsxa);
1851
1852 if (psxa)
1853 {
1854 for (i = 0; i != psxa->uiCount; i++)
1855 {
1856 psxa->pspsx[i]->lpVtbl->Release(psxa->pspsx[i]);
1857 }
1858
1859 LocalFree(psxa);
1860 }
1861 }
1862
1863 /*************************************************************************
1864 * CIDLData_CreateFromIDArray [SHELL32.83]
1865 *
1866 * Create IDataObject from PIDLs??
1867 */
1868 HRESULT WINAPI CIDLData_CreateFromIDArray(
1869 LPCITEMIDLIST pidlFolder,
1870 UINT cpidlFiles,
1871 LPCITEMIDLIST *lppidlFiles,
1872 IDataObject **ppdataObject)
1873 {
1874 UINT i;
1875 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1876
1877 TRACE("(%p, %d, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1878 if (TRACE_ON(pidl))
1879 {
1880 pdump (pidlFolder);
1881 for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1882 }
1883 *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1884 lppidlFiles, cpidlFiles);
1885 if (*ppdataObject) return S_OK;
1886 return E_OUTOFMEMORY;
1887 }
1888
1889 /*************************************************************************
1890 * SHCreateStdEnumFmtEtc [SHELL32.74]
1891 *
1892 * NOTES
1893 *
1894 */
1895 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1896 UINT cFormats,
1897 const FORMATETC *lpFormats,
1898 LPENUMFORMATETC *ppenumFormatetc)
1899 {
1900 IEnumFORMATETC *pef;
1901 HRESULT hRes;
1902 TRACE("cf=%d fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1903
1904 pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1905 if (!pef)
1906 return E_OUTOFMEMORY;
1907
1908 IEnumFORMATETC_AddRef(pef);
1909 hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1910 IEnumFORMATETC_Release(pef);
1911
1912 return hRes;
1913 }
1914
1915
1916 /*************************************************************************
1917 * SHCreateShellFolderView (SHELL32.256)
1918 */
1919 HRESULT WINAPI SHCreateShellFolderView(const SFV_CREATE *pcsfv, IShellView **ppsv)
1920 {
1921 HRESULT ret = S_OK;
1922
1923 FIXME("SHCreateShellFolderView() stub\n");
1924
1925 if (!pcsfv || sizeof(*pcsfv) != pcsfv->cbSize)
1926 ret = E_INVALIDARG;
1927 else
1928 {
1929 LPVOID lpdata = 0;/*LocalAlloc(LMEM_ZEROINIT, 0x4E4);*/
1930
1931 if (!lpdata)
1932 ret = E_OUTOFMEMORY;
1933 else
1934 {
1935 /* Initialize and return unknown lpdata structure */
1936 }
1937 }
1938
1939 return ret;
1940 }
1941
1942 /*************************************************************************
1943 * SHFindFiles (SHELL32.90)
1944 */
1945 BOOL WINAPI SHFindFiles( LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlSaveFile )
1946 {
1947 FIXME("%p %p\n", pidlFolder, pidlSaveFile );
1948 return FALSE;
1949 }
1950
1951 /*************************************************************************
1952 * SHUpdateImageW (SHELL32.192)
1953 *
1954 * Notifies the shell that an icon in the system image list has been changed.
1955 *
1956 * PARAMS
1957 * pszHashItem [I] Path to file that contains the icon.
1958 * iIndex [I] Zero-based index of the icon in the file.
1959 * uFlags [I] Flags determining the icon attributes. See notes.
1960 * iImageIndex [I] Index of the icon in the system image list.
1961 *
1962 * RETURNS
1963 * Nothing
1964 *
1965 * NOTES
1966 * uFlags can be one or more of the following flags:
1967 * GIL_NOTFILENAME - pszHashItem is not a file name.
1968 * GIL_SIMULATEDOC - Create a document icon using the specified icon.
1969 */
1970 void WINAPI SHUpdateImageW(LPCWSTR pszHashItem, int iIndex, UINT uFlags, int iImageIndex)
1971 {
1972 FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_w(pszHashItem), iIndex, uFlags, iImageIndex);
1973 }
1974
1975 /*************************************************************************
1976 * SHUpdateImageA (SHELL32.191)
1977 *
1978 * See SHUpdateImageW.
1979 */
1980 VOID WINAPI SHUpdateImageA(LPCSTR pszHashItem, INT iIndex, UINT uFlags, INT iImageIndex)
1981 {
1982 FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_a(pszHashItem), iIndex, uFlags, iImageIndex);
1983 }
1984
1985 INT WINAPI SHHandleUpdateImage(LPCITEMIDLIST pidlExtra)
1986 {
1987 FIXME("%p - stub\n", pidlExtra);
1988
1989 return -1;
1990 }
1991
1992 BOOL WINAPI SHObjectProperties(HWND hwnd, DWORD dwType, LPCWSTR szObject, LPCWSTR szPage)
1993 {
1994 FIXME("%p, 0x%08x, %s, %s - stub\n", hwnd, dwType, debugstr_w(szObject), debugstr_w(szPage));
1995
1996 return TRUE;
1997 }
1998
1999 BOOL WINAPI SHGetNewLinkInfoA(LPCSTR pszLinkTo, LPCSTR pszDir, LPSTR pszName, BOOL *pfMustCopy,
2000 UINT uFlags)
2001 {
2002 WCHAR wszLinkTo[MAX_PATH];
2003 WCHAR wszDir[MAX_PATH];
2004 WCHAR wszName[MAX_PATH];
2005 BOOL res;
2006
2007 MultiByteToWideChar(CP_ACP, 0, pszLinkTo, -1, wszLinkTo, MAX_PATH);
2008 MultiByteToWideChar(CP_ACP, 0, pszDir, -1, wszDir, MAX_PATH);
2009
2010 res = SHGetNewLinkInfoW(wszLinkTo, wszDir, wszName, pfMustCopy, uFlags);
2011
2012 if (res)
2013 WideCharToMultiByte(CP_ACP, 0, wszName, -1, pszName, MAX_PATH, NULL, NULL);
2014
2015 return res;
2016 }
2017
2018 BOOL WINAPI SHGetNewLinkInfoW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName, BOOL *pfMustCopy,
2019 UINT uFlags)
2020 {
2021 const WCHAR *basename;
2022 WCHAR *dst_basename;
2023 int i=2;
2024 static const WCHAR lnkformat[] = {'%','s','.','l','n','k',0};
2025 static const WCHAR lnkformatnum[] = {'%','s',' ','(','%','d',')','.','l','n','k',0};
2026
2027 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(pszLinkTo), debugstr_w(pszDir),
2028 pszName, pfMustCopy, uFlags);
2029
2030 *pfMustCopy = FALSE;
2031
2032 if (uFlags & SHGNLI_PIDL)
2033 {
2034 FIXME("SHGNLI_PIDL flag unsupported\n");
2035 return FALSE;
2036 }
2037
2038 if (uFlags)
2039 FIXME("ignoring flags: 0x%08x\n", uFlags);
2040
2041 /* FIXME: should test if the file is a shortcut or DOS program */
2042 if (GetFileAttributesW(pszLinkTo) == INVALID_FILE_ATTRIBUTES)
2043 return FALSE;
2044
2045 basename = strrchrW(pszLinkTo, '\\');
2046 if (basename)
2047 basename = basename+1;
2048 else
2049 basename = pszLinkTo;
2050
2051 lstrcpynW(pszName, pszDir, MAX_PATH);
2052 if (!PathAddBackslashW(pszName))
2053 return FALSE;
2054
2055 dst_basename = pszName + strlenW(pszName);
2056
2057 snprintfW(dst_basename, pszName + MAX_PATH - dst_basename, lnkformat, basename);
2058
2059 while (GetFileAttributesW(pszName) != INVALID_FILE_ATTRIBUTES)
2060 {
2061 snprintfW(dst_basename, pszName + MAX_PATH - dst_basename, lnkformatnum, basename, i);
2062 i++;
2063 }
2064
2065 return TRUE;
2066 }
2067
2068 /*************************************************************************
2069 * SHStartNetConnectionDialog (SHELL32.@)
2070 */
2071 HRESULT WINAPI SHStartNetConnectionDialog(HWND hwnd, LPCSTR pszRemoteName, DWORD dwType)
2072 {
2073 FIXME("%p, %s, 0x%08x - stub\n", hwnd, debugstr_a(pszRemoteName), dwType);
2074
2075 return S_OK;
2076 }
2077 /*************************************************************************
2078 * SHEmptyRecycleBinA (SHELL32.@)
2079 */
2080 HRESULT WINAPI SHEmptyRecycleBinA(HWND hwnd, LPCSTR pszRootPath, DWORD dwFlags)
2081 {
2082 LPWSTR szRootPathW = NULL;
2083 int len;
2084 HRESULT hr;
2085
2086 TRACE("%p, %s, 0x%08x\n", hwnd, debugstr_a(pszRootPath), dwFlags);
2087
2088 if (pszRootPath)
2089 {
2090 len = MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, NULL, 0);
2091 if (len == 0)
2092 return HRESULT_FROM_WIN32(GetLastError());
2093 szRootPathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2094 if (!szRootPathW)
2095 return E_OUTOFMEMORY;
2096 if (MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, szRootPathW, len) == 0)
2097 {
2098 HeapFree(GetProcessHeap(), 0, szRootPathW);
2099 return HRESULT_FROM_WIN32(GetLastError());
2100 }
2101 }
2102
2103 hr = SHEmptyRecycleBinW(hwnd, szRootPathW, dwFlags);
2104 HeapFree(GetProcessHeap(), 0, szRootPathW);
2105
2106 return hr;
2107 }
2108
2109 HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags)
2110 {
2111 WCHAR szPath[MAX_PATH] = {0};
2112 DWORD dwSize, dwType;
2113 LONG ret;
2114
2115 TRACE("%p, %s, 0x%08x\n", hwnd, debugstr_w(pszRootPath), dwFlags);
2116
2117 if (!(dwFlags & SHERB_NOCONFIRMATION))
2118 {
2119 /* FIXME
2120 * enumerate available files
2121 * show confirmation dialog
2122 */
2123 FIXME("show confirmation dialog\n");
2124 }
2125
2126 if (dwFlags & SHERB_NOPROGRESSUI)
2127 {
2128 ret = EmptyRecycleBinW(pszRootPath);
2129 }
2130 else
2131 {
2132 /* FIXME
2133 * show a progress dialog
2134 */
2135 ret = EmptyRecycleBinW(pszRootPath);
2136 }
2137
2138 if (!ret)
2139 return HRESULT_FROM_WIN32(GetLastError());
2140
2141 if (!(dwFlags & SHERB_NOSOUND))
2142 {
2143 dwSize = sizeof(szPath);
2144 ret = RegGetValueW(HKEY_CURRENT_USER,
2145 L"AppEvents\\Schemes\\Apps\\Explorer\\EmptyRecycleBin\\.Current",
2146 NULL,
2147 RRF_RT_REG_EXPAND_SZ,
2148 &dwType,
2149 (PVOID)szPath,
2150 &dwSize);
2151 if (ret != ERROR_SUCCESS)
2152 return S_OK;
2153
2154 if (dwType != REG_EXPAND_SZ) /* type dismatch */
2155 return S_OK;
2156
2157 szPath[(sizeof(szPath)/sizeof(WCHAR))-1] = L'\0';
2158 PlaySoundW(szPath, NULL, SND_FILENAME);
2159 }
2160 return S_OK;
2161 }
2162
2163 HRESULT WINAPI SHQueryRecycleBinA(LPCSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
2164 {
2165 LPWSTR szRootPathW = NULL;
2166 int len;
2167 HRESULT hr;
2168
2169 TRACE("%s, %p\n", debugstr_a(pszRootPath), pSHQueryRBInfo);
2170
2171 if (pszRootPath)
2172 {
2173 len = MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, NULL, 0);
2174 if (len == 0)
2175 return HRESULT_FROM_WIN32(GetLastError());
2176 szRootPathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
2177 if (!szRootPathW)
2178 return E_OUTOFMEMORY;
2179 if (MultiByteToWideChar(CP_ACP, 0, pszRootPath, -1, szRootPathW, len) == 0)
2180 {
2181 HeapFree(GetProcessHeap(), 0, szRootPathW);
2182 return HRESULT_FROM_WIN32(GetLastError());
2183 }
2184 }
2185
2186 hr = SHQueryRecycleBinW(szRootPathW, pSHQueryRBInfo);
2187 HeapFree(GetProcessHeap(), 0, szRootPathW);
2188
2189 return hr;
2190 }
2191
2192 HRESULT WINAPI SHQueryRecycleBinW(LPCWSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
2193 {
2194 FIXME("%s, %p - stub\n", debugstr_w(pszRootPath), pSHQueryRBInfo);
2195
2196 if (!(pszRootPath) || (pszRootPath[0] == 0) ||
2197 !(pSHQueryRBInfo) || (pSHQueryRBInfo->cbSize < sizeof(SHQUERYRBINFO)))
2198 {
2199 return E_INVALIDARG;
2200 }
2201
2202 pSHQueryRBInfo->i64Size = 0;
2203 pSHQueryRBInfo->i64NumItems = 0;
2204
2205 return S_OK;
2206 }
2207
2208 /*************************************************************************
2209 * SHSetLocalizedName (SHELL32.@)
2210 */
2211 HRESULT WINAPI SHSetLocalizedName(LPCWSTR pszPath, LPCWSTR pszResModule, int idsRes)
2212 {
2213 FIXME("%p, %s, %d - stub\n", pszPath, debugstr_w(pszResModule), idsRes);
2214
2215 return S_OK;
2216 }
2217
2218 /*************************************************************************
2219 * LinkWindow_RegisterClass (SHELL32.258)
2220 */
2221 BOOL WINAPI LinkWindow_RegisterClass(void)
2222 {
2223 FIXME("()\n");
2224 return TRUE;
2225 }
2226
2227 /*************************************************************************
2228 * LinkWindow_UnregisterClass (SHELL32.259)
2229 */
2230 BOOL WINAPI LinkWindow_UnregisterClass(void)
2231 {
2232 FIXME("()\n");
2233 return TRUE;
2234
2235 }
2236
2237 /*************************************************************************
2238 * SHFlushSFCache (SHELL32.526)
2239 *
2240 * Notifies the shell that a user-specified special folder location has changed.
2241 *
2242 * NOTES
2243 * In Wine, the shell folder registry values are not cached, so this function
2244 * has no effect.
2245 */
2246 void WINAPI SHFlushSFCache(void)
2247 {
2248 }
2249
2250 HRESULT WINAPI SHGetImageList(int iImageList, REFIID riid, void **ppv)
2251 {
2252 FIXME("STUB: %i %s\n",iImageList,debugstr_guid(riid));
2253 return E_NOINTERFACE;
2254 }
2255
2256 /*************************************************************************
2257 * SHParseDisplayName [shell version 6.0]
2258 */
2259 HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc,
2260 LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
2261 {
2262 IShellFolder * psfDesktop;
2263 HRESULT hr=E_FAIL;
2264 ULONG dwAttr=sfgaoIn;
2265
2266 if(!ppidl)
2267 return E_INVALIDARG;
2268
2269 if (!pszName || !psfgaoOut)
2270 {
2271 *ppidl = NULL;
2272 return E_INVALIDARG;
2273 }
2274
2275 hr = SHGetDesktopFolder(&psfDesktop);
2276 if (FAILED(hr))
2277 {
2278 *ppidl = NULL;
2279 return hr;
2280 }
2281
2282 hr = IShellFolder_ParseDisplayName(psfDesktop, (HWND)NULL, pbc, (LPOLESTR)pszName, (ULONG *)NULL, ppidl, &dwAttr);
2283
2284 IShellFolder_Release(psfDesktop);
2285
2286 if (SUCCEEDED(hr))
2287 *psfgaoOut = dwAttr;
2288 else
2289 *ppidl = NULL;
2290
2291 return hr;
2292 }