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