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