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