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