win32u: Move desktop resize on WM_DISPLAYCHANGE out of the drivers.
[wine.git] / dlls / shell32 / shellord.c
bloba007c0e5c603c31660518d4d212897c8c7e1b022
1 /*
2 * The parameters of many functions changes between different OS versions
3 * (NT uses Unicode strings, 95 uses ANSI strings)
5 * Copyright 1997 Marcus Meissner
6 * 1998 Jürgen Schmied
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.
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.
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
23 #include <string.h>
24 #include <stdarg.h>
25 #include <stdio.h>
27 #define COBJMACROS
29 #include "winerror.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "wine/debug.h"
34 #include "winnls.h"
35 #include "winternl.h"
37 #include "shellapi.h"
38 #include "objbase.h"
39 #include "shlguid.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "shlobj.h"
43 #include "shell32_main.h"
44 #include "pidl.h"
45 #include "shlwapi.h"
46 #include "commdlg.h"
47 #include "commoncontrols.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 WINE_DECLARE_DEBUG_CHANNEL(pidl);
52 /* SHWaitForFileToOpen flags */
53 #define SHWFF_ADD 0x01
54 #define SHWFF_REMOVE 0x02
55 #define SHWFF_WAIT 0x04
57 /* RegisterShellHook types */
58 #define RSH_DEREGISTER 0
59 #define RSH_REGISTER 1
60 #define RSH_REGISTER_PROGMAN 2
61 #define RSH_REGISTER_TASKMAN 3
63 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
64 /* !!! it is in both here and comctl32undoc.c !!! */
65 typedef struct tagCREATEMRULIST
67 DWORD cbSize; /* size of struct */
68 DWORD nMaxItems; /* max no. of items in list */
69 DWORD dwFlags; /* see below */
70 HKEY hKey; /* root reg. key under which list is saved */
71 LPCSTR lpszSubKey; /* reg. subkey */
72 int (CALLBACK *lpfnCompare)(LPCVOID, LPCVOID, DWORD); /* item compare proc */
73 } CREATEMRULISTA, *LPCREATEMRULISTA;
75 /* dwFlags */
76 #define MRUF_STRING_LIST 0 /* list will contain strings */
77 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
78 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
80 extern HANDLE WINAPI CreateMRUListA(LPCREATEMRULISTA lpcml);
81 extern DWORD WINAPI FreeMRUList(HANDLE hMRUList);
82 extern INT WINAPI AddMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData);
83 extern INT WINAPI FindMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
84 extern INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
87 /*************************************************************************
88 * ParseFieldA [internal]
90 * copies a field from a ',' delimited string
92 * first field is nField = 1
94 DWORD WINAPI ParseFieldA(
95 LPCSTR src,
96 DWORD nField,
97 LPSTR dst,
98 DWORD len)
100 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src),nField,dst,len);
102 if (!src || !src[0] || !dst || !len)
103 return 0;
105 /* skip n fields delimited by ',' */
106 while (nField > 1)
108 if (*src=='\0') return FALSE;
109 if (*(src++)==',') nField--;
112 /* copy part till the next ',' to dst */
113 while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
115 /* finalize the string */
116 *dst=0x0;
118 return TRUE;
121 /*************************************************************************
122 * ParseFieldW [internal]
124 * copies a field from a ',' delimited string
126 * first field is nField = 1
128 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
130 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n", debugstr_w(src), nField, dst, len);
132 if (!src || !src[0] || !dst || !len)
133 return 0;
135 /* skip n fields delimited by ',' */
136 while (nField > 1)
138 if (*src == 0x0) return FALSE;
139 if (*src++ == ',') nField--;
142 /* copy part till the next ',' to dst */
143 while ( *src != 0x0 && *src != ',' && (len--)>0 ) *(dst++) = *(src++);
145 /* finalize the string */
146 *dst = 0x0;
148 return TRUE;
151 /*************************************************************************
152 * ParseField [SHELL32.58]
154 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
156 if (SHELL_OsIsUnicode())
157 return ParseFieldW(src, nField, dst, len);
158 return ParseFieldA(src, nField, dst, len);
161 /*************************************************************************
162 * GetFileNameFromBrowseA [internal]
164 static BOOL GetFileNameFromBrowseA(
165 HWND hwndOwner,
166 LPSTR lpstrFile,
167 DWORD nMaxFile,
168 LPCSTR lpstrInitialDir,
169 LPCSTR lpstrDefExt,
170 LPCSTR lpstrFilter,
171 LPCSTR lpstrTitle)
173 OPENFILENAMEA ofn;
174 BOOL ret;
176 TRACE("%p, %s, %ld, %s, %s, %s, %s)\n",
177 hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
178 lpstrFilter, lpstrTitle);
180 memset(&ofn, 0, sizeof(ofn));
182 ofn.lStructSize = sizeof(ofn);
183 ofn.hwndOwner = hwndOwner;
184 ofn.lpstrFilter = lpstrFilter;
185 ofn.lpstrFile = lpstrFile;
186 ofn.nMaxFile = nMaxFile;
187 ofn.lpstrInitialDir = lpstrInitialDir;
188 ofn.lpstrTitle = lpstrTitle;
189 ofn.lpstrDefExt = lpstrDefExt;
190 ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
191 ret = GetOpenFileNameA(&ofn);
193 return ret;
196 /*************************************************************************
197 * GetFileNameFromBrowseW [internal]
199 static BOOL GetFileNameFromBrowseW(
200 HWND hwndOwner,
201 LPWSTR lpstrFile,
202 DWORD nMaxFile,
203 LPCWSTR lpstrInitialDir,
204 LPCWSTR lpstrDefExt,
205 LPCWSTR lpstrFilter,
206 LPCWSTR lpstrTitle)
208 OPENFILENAMEW ofn;
209 BOOL ret;
211 TRACE("%p, %s, %ld, %s, %s, %s, %s)\n",
212 hwndOwner, debugstr_w(lpstrFile), nMaxFile, debugstr_w(lpstrInitialDir), debugstr_w(lpstrDefExt),
213 debugstr_w(lpstrFilter), debugstr_w(lpstrTitle));
215 memset(&ofn, 0, sizeof(ofn));
217 ofn.lStructSize = sizeof(ofn);
218 ofn.hwndOwner = hwndOwner;
219 ofn.lpstrFilter = lpstrFilter;
220 ofn.lpstrFile = lpstrFile;
221 ofn.nMaxFile = nMaxFile;
222 ofn.lpstrInitialDir = lpstrInitialDir;
223 ofn.lpstrTitle = lpstrTitle;
224 ofn.lpstrDefExt = lpstrDefExt;
225 ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
226 ret = GetOpenFileNameW(&ofn);
228 return ret;
231 /*************************************************************************
232 * GetFileNameFromBrowse [SHELL32.63]
235 BOOL WINAPI GetFileNameFromBrowseAW(
236 HWND hwndOwner,
237 LPVOID lpstrFile,
238 DWORD nMaxFile,
239 LPCVOID lpstrInitialDir,
240 LPCVOID lpstrDefExt,
241 LPCVOID lpstrFilter,
242 LPCVOID lpstrTitle)
244 if (SHELL_OsIsUnicode())
245 return GetFileNameFromBrowseW(hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt, lpstrFilter, lpstrTitle);
247 return GetFileNameFromBrowseA(hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt, lpstrFilter, lpstrTitle);
250 /*************************************************************************
251 * SHGetSetSettings [SHELL32.68]
253 VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
255 if(bSet)
257 FIXME("%p 0x%08lx TRUE\n", lpss, dwMask);
259 else
261 SHGetSettings((LPSHELLFLAGSTATE)lpss,dwMask);
265 /*************************************************************************
266 * SHGetSettings [SHELL32.@]
268 * NOTES
269 * the registry path are for win98 (tested)
270 * and possibly are the same in nt40
273 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
275 HKEY hKey;
276 DWORD dwData;
277 DWORD dwDataSize = sizeof (DWORD);
279 TRACE("(%p 0x%08lx)\n",lpsfs,dwMask);
281 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
282 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
283 return;
285 if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
286 lpsfs->fShowExtensions = ((dwData == 0) ? 0 : 1);
288 if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
289 lpsfs->fShowInfoTip = ((dwData == 0) ? 0 : 1);
291 if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
292 lpsfs->fDontPrettyPath = ((dwData == 0) ? 0 : 1);
294 if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
295 lpsfs->fHideIcons = ((dwData == 0) ? 0 : 1);
297 if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
298 lpsfs->fMapNetDrvBtn = ((dwData == 0) ? 0 : 1);
300 if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
301 lpsfs->fShowAttribCol = ((dwData == 0) ? 0 : 1);
303 if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
304 { if (dwData == 0)
305 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
306 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
308 else if (dwData == 1)
309 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = -1;
310 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
312 else if (dwData == 2)
313 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
314 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = -1;
317 RegCloseKey (hKey);
319 TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
322 /*************************************************************************
323 * SHShellFolderView_Message [SHELL32.73]
325 * Send a message to an explorer cabinet window.
327 * PARAMS
328 * hwndCabinet [I] The window containing the shellview to communicate with
329 * dwMessage [I] The SFVM message to send
330 * dwParam [I] Message parameter
332 * RETURNS
333 * fixme.
335 * NOTES
336 * Message SFVM_REARRANGE = 1
338 * This message gets sent when a column gets clicked to instruct the
339 * shell view to re-sort the item list. dwParam identifies the column
340 * that was clicked.
342 LRESULT WINAPI SHShellFolderView_Message(
343 HWND hwndCabinet,
344 UINT uMessage,
345 LPARAM lParam)
347 FIXME("%p %08x %08Ix stub\n",hwndCabinet, uMessage, lParam);
348 return 0;
351 /*************************************************************************
352 * RegisterShellHook [SHELL32.181]
354 * Register a shell hook.
356 * PARAMS
357 * hwnd [I] Window handle
358 * dwType [I] Type of hook.
360 * NOTES
361 * Exported by ordinal
363 BOOL WINAPI RegisterShellHook(
364 HWND hWnd,
365 DWORD dwType)
367 FIXME("(%p,0x%08lx):stub.\n",hWnd, dwType);
368 return TRUE;
371 /*************************************************************************
372 * ShellMessageBoxW [SHELL32.182]
374 * See ShellMessageBoxA.
376 * NOTE:
377 * shlwapi.ShellMessageBoxWrapW is a duplicate of shell32.ShellMessageBoxW
378 * because we can't forward to it in the .spec file since it's exported by
379 * ordinal. If you change the implementation here please update the code in
380 * shlwapi as well.
382 int WINAPIV ShellMessageBoxW(
383 HINSTANCE hInstance,
384 HWND hWnd,
385 LPCWSTR lpText,
386 LPCWSTR lpCaption,
387 UINT uType,
388 ...)
390 WCHAR szText[100],szTitle[100];
391 LPCWSTR pszText = szText, pszTitle = szTitle;
392 LPWSTR pszTemp;
393 va_list args;
394 int ret;
396 va_start(args, uType);
397 /* wvsprintfA(buf,fmt, args); */
399 TRACE("(%p,%p,%p,%p,%08x)\n",
400 hInstance,hWnd,lpText,lpCaption,uType);
402 if (IS_INTRESOURCE(lpCaption))
403 LoadStringW(hInstance, LOWORD(lpCaption), szTitle, ARRAY_SIZE(szTitle));
404 else
405 pszTitle = lpCaption;
407 if (IS_INTRESOURCE(lpText))
408 LoadStringW(hInstance, LOWORD(lpText), szText, ARRAY_SIZE(szText));
409 else
410 pszText = lpText;
412 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
413 pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
415 va_end(args);
417 ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
418 LocalFree(pszTemp);
419 return ret;
422 /*************************************************************************
423 * ShellMessageBoxA [SHELL32.183]
425 * Format and output an error message.
427 * PARAMS
428 * hInstance [I] Instance handle of message creator
429 * hWnd [I] Window handle of message creator
430 * lpText [I] Resource Id of title or LPSTR
431 * lpCaption [I] Resource Id of title or LPSTR
432 * uType [I] Type of error message
434 * RETURNS
435 * A return value from MessageBoxA().
437 * NOTES
438 * Exported by ordinal
440 int WINAPIV ShellMessageBoxA(
441 HINSTANCE hInstance,
442 HWND hWnd,
443 LPCSTR lpText,
444 LPCSTR lpCaption,
445 UINT uType,
446 ...)
448 char szText[100],szTitle[100];
449 LPCSTR pszText = szText, pszTitle = szTitle;
450 LPSTR pszTemp;
451 va_list args;
452 int ret;
454 va_start(args, uType);
455 /* wvsprintfA(buf,fmt, args); */
457 TRACE("(%p,%p,%p,%p,%08x)\n",
458 hInstance,hWnd,lpText,lpCaption,uType);
460 if (IS_INTRESOURCE(lpCaption))
461 LoadStringA(hInstance, LOWORD(lpCaption), szTitle, sizeof(szTitle));
462 else
463 pszTitle = lpCaption;
465 if (IS_INTRESOURCE(lpText))
466 LoadStringA(hInstance, LOWORD(lpText), szText, sizeof(szText));
467 else
468 pszText = lpText;
470 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
471 pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
473 va_end(args);
475 ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
476 LocalFree(pszTemp);
477 return ret;
480 /*************************************************************************
481 * SHRegisterDragDrop [SHELL32.86]
483 * Probably equivalent to RegisterDragDrop but under Windows 95 it could use the
484 * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
485 * for details. Under Windows 98 this function initializes the true OLE when called
486 * the first time, on XP always returns E_OUTOFMEMORY and it got removed from Vista.
488 * We follow Windows 98 behaviour.
490 * NOTES
491 * exported by ordinal
493 * SEE ALSO
494 * RegisterDragDrop, SHLoadOLE
496 HRESULT WINAPI SHRegisterDragDrop(
497 HWND hWnd,
498 LPDROPTARGET pDropTarget)
500 static BOOL ole_initialized = FALSE;
501 HRESULT hr;
503 TRACE("(%p,%p)\n", hWnd, pDropTarget);
505 if (!ole_initialized)
507 hr = OleInitialize(NULL);
508 if (FAILED(hr))
509 return hr;
510 ole_initialized = TRUE;
512 return RegisterDragDrop(hWnd, pDropTarget);
515 /*************************************************************************
516 * SHRevokeDragDrop [SHELL32.87]
518 * Probably equivalent to RevokeDragDrop but under Windows 95 it could use the
519 * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
520 * for details. Function removed from Windows Vista.
522 * We call ole32 RevokeDragDrop which seems to work even if OleInitialize was
523 * not called.
525 * NOTES
526 * exported by ordinal
528 * SEE ALSO
529 * RevokeDragDrop, SHLoadOLE
531 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
533 TRACE("(%p)\n", hWnd);
534 return RevokeDragDrop(hWnd);
537 /*************************************************************************
538 * SHDoDragDrop [SHELL32.88]
540 * Probably equivalent to DoDragDrop but under Windows 9x it could use the
541 * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
542 * for details
544 * NOTES
545 * exported by ordinal
547 * SEE ALSO
548 * DoDragDrop, SHLoadOLE
550 HRESULT WINAPI SHDoDragDrop(
551 HWND hWnd,
552 LPDATAOBJECT lpDataObject,
553 LPDROPSOURCE lpDropSource,
554 DWORD dwOKEffect,
555 LPDWORD pdwEffect)
557 FIXME("(%p %p %p 0x%08lx %p):stub.\n",
558 hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
559 return DoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
562 /*************************************************************************
563 * ArrangeWindows [SHELL32.184]
566 WORD WINAPI ArrangeWindows(HWND hwndParent, DWORD dwReserved, const RECT *lpRect,
567 WORD cKids, const HWND *lpKids)
569 FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
570 hwndParent, dwReserved, lpRect, cKids, lpKids);
571 return 0;
574 /*************************************************************************
575 * SignalFileOpen [SHELL32.103]
577 * NOTES
578 * exported by ordinal
580 BOOL WINAPI
581 SignalFileOpen (PCIDLIST_ABSOLUTE pidl)
583 FIXME("(%p):stub.\n", pidl);
585 return FALSE;
588 /*************************************************************************
589 * SHADD_get_policy - helper function for SHAddToRecentDocs
591 * PARAMETERS
592 * policy [IN] policy name (null termed string) to find
593 * type [OUT] ptr to DWORD to receive type
594 * buffer [OUT] ptr to area to hold data retrieved
595 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
596 * length filled
598 * RETURNS
599 * result of the SHQueryValueEx call
601 static INT SHADD_get_policy(LPCSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
603 HKEY Policy_basekey;
604 INT ret;
606 /* Get the key for the policies location in the registry
608 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
609 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
610 0, KEY_READ, &Policy_basekey)) {
612 if (RegOpenKeyExA(HKEY_CURRENT_USER,
613 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
614 0, KEY_READ, &Policy_basekey)) {
615 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
616 policy);
617 *len = 0;
618 return ERROR_FILE_NOT_FOUND;
622 /* Retrieve the data if it exists
624 ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
625 RegCloseKey(Policy_basekey);
626 return ret;
630 /*************************************************************************
631 * SHADD_compare_mru - helper function for SHAddToRecentDocs
633 * PARAMETERS
634 * data1 [IN] data being looked for
635 * data2 [IN] data in MRU
636 * cbdata [IN] length from FindMRUData call (not used)
638 * RETURNS
639 * position within MRU list that data was added.
641 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
643 return lstrcmpiA(data1, data2);
646 /*************************************************************************
647 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
649 * PARAMETERS
650 * mruhandle [IN] handle for created MRU list
651 * doc_name [IN] null termed pure doc name
652 * new_lnk_name [IN] null termed path and file name for .lnk file
653 * buffer [IN/OUT] 2048 byte area to construct MRU data
654 * len [OUT] ptr to int to receive space used in buffer
656 * RETURNS
657 * position within MRU list that data was added.
659 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPCSTR doc_name, LPCSTR new_lnk_name,
660 LPSTR buffer, INT *len)
662 LPSTR ptr;
663 INT wlen;
665 /*FIXME: Document:
666 * RecentDocs MRU data structure seems to be:
667 * +0h document file name w/ terminating 0h
668 * +nh short int w/ size of remaining
669 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
670 * +n+4h 10 bytes zeros - unknown
671 * +n+eh shortcut file name w/ terminating 0h
672 * +n+e+nh 3 zero bytes - unknown
675 /* Create the MRU data structure for "RecentDocs"
677 ptr = buffer;
678 lstrcpyA(ptr, doc_name);
679 ptr += (lstrlenA(buffer) + 1);
680 wlen= lstrlenA(new_lnk_name) + 1 + 12;
681 *((short int*)ptr) = wlen;
682 ptr += 2; /* step past the length */
683 *(ptr++) = 0x30; /* unknown reason */
684 *(ptr++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
685 memset(ptr, 0, 10);
686 ptr += 10;
687 lstrcpyA(ptr, new_lnk_name);
688 ptr += (lstrlenA(new_lnk_name) + 1);
689 memset(ptr, 0, 3);
690 ptr += 3;
691 *len = ptr - buffer;
693 /* Add the new entry into the MRU list
695 return AddMRUData(mruhandle, buffer, *len);
698 /*************************************************************************
699 * SHAddToRecentDocs [SHELL32.@]
701 * Modify (add/clear) Shell's list of recently used documents.
703 * PARAMETERS
704 * uFlags [IN] SHARD_PATHA, SHARD_PATHW or SHARD_PIDL
705 * pv [IN] string or pidl, NULL clears the list
707 * NOTES
708 * exported by name
710 * FIXME
711 * convert to unicode
713 void WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
715 /* If list is a string list lpfnCompare has the following prototype
716 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
717 * for binary lists the prototype is
718 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
719 * where cbData is the no. of bytes to compare.
720 * Need to check what return value means identical - 0?
724 UINT olderrormode;
725 HKEY HCUbasekey;
726 CHAR doc_name[MAX_PATH];
727 CHAR link_dir[MAX_PATH];
728 CHAR new_lnk_filepath[MAX_PATH];
729 CHAR new_lnk_name[MAX_PATH];
730 LPITEMIDLIST pidl;
731 HWND hwnd = 0; /* FIXME: get real window handle */
732 INT ret;
733 DWORD data[64], datalen, type;
735 TRACE("%04x %p\n", uFlags, pv);
737 /*FIXME: Document:
738 * RecentDocs MRU data structure seems to be:
739 * +0h document file name w/ terminating 0h
740 * +nh short int w/ size of remaining
741 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
742 * +n+4h 10 bytes zeros - unknown
743 * +n+eh shortcut file name w/ terminating 0h
744 * +n+e+nh 3 zero bytes - unknown
747 /* See if we need to do anything.
749 datalen = 64;
750 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, data, &datalen);
751 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
752 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
753 return;
755 if (ret == ERROR_SUCCESS) {
756 if (!( (type == REG_DWORD) ||
757 ((type == REG_BINARY) && (datalen == 4)) )) {
758 ERR("Error policy data for \"NoRecentDocsHistory\" not formatted correctly, type=%ld, len=%ld\n",
759 type, datalen);
760 return;
763 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
764 /* now test the actual policy value */
765 if ( data[0] != 0)
766 return;
769 /* Open key to where the necessary info is
771 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
772 * and the close should be done during the _DETACH. The resulting
773 * key is stored in the DLL global data.
775 if (RegCreateKeyExA(HKEY_CURRENT_USER,
776 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
777 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
778 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
779 return;
782 /* Get path to user's "Recent" directory
784 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT, &pidl)))
786 SHGetPathFromIDListA(pidl, link_dir);
787 ILFree(pidl);
789 else
791 /* serious issues */
792 link_dir[0] = 0;
793 ERR("serious issues 1\n");
796 TRACE("Users Recent dir %s\n", link_dir);
798 /* If no input, then go clear the lists */
799 if (!pv) {
800 /* clear user's Recent dir
803 /* FIXME: delete all files in "link_dir"
805 * while( more files ) {
806 * lstrcpyA(old_lnk_name, link_dir);
807 * PathAppendA(old_lnk_name, filenam);
808 * DeleteFileA(old_lnk_name);
811 FIXME("should delete all files in %s\\\n", link_dir);
813 /* clear MRU list
815 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
816 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
817 * and naturally it fails w/ rc=2. It should do it against
818 * HKEY_CURRENT_USER which is where it is stored, and where
819 * the MRU routines expect it!!!!
821 RegDeleteKeyA(HCUbasekey, "RecentDocs");
822 RegCloseKey(HCUbasekey);
823 return;
826 /* Have data to add, the jobs to be done:
827 * 1. Add document to MRU list in registry "HKCU\Software\
828 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
829 * 2. Add shortcut to document in the user's Recent directory
830 * (CSIDL_RECENT).
831 * 3. Add shortcut to Start menu's Documents submenu.
834 /* Get the pure document name from the input
836 switch (uFlags)
838 case SHARD_PIDL:
839 if (!SHGetPathFromIDListA(pv, doc_name))
841 WARN("can't get path from PIDL\n");
842 return;
844 break;
846 case SHARD_PATHA:
847 lstrcpynA(doc_name, pv, MAX_PATH);
848 break;
850 case SHARD_PATHW:
851 WideCharToMultiByte(CP_ACP, 0, pv, -1, doc_name, MAX_PATH, NULL, NULL);
852 break;
854 default:
855 FIXME("Unsupported flags: %u\n", uFlags);
856 return;
859 TRACE("full document name %s\n", debugstr_a(doc_name));
860 PathStripPathA(doc_name);
861 TRACE("stripped document name %s\n", debugstr_a(doc_name));
864 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
866 { /* on input needs:
867 * doc_name - pure file-spec, no path
868 * link_dir - path to the user's Recent directory
869 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
870 * creates:
871 * new_lnk_name- pure file-spec, no path for new .lnk file
872 * new_lnk_filepath
873 * - path and file name of new .lnk file
875 CREATEMRULISTA mymru;
876 HANDLE mruhandle;
877 INT len, pos, bufused, err;
878 INT i;
879 DWORD attr;
880 CHAR buffer[2048];
881 CHAR *ptr;
882 CHAR old_lnk_name[MAX_PATH];
883 short int slen;
885 mymru.cbSize = sizeof(CREATEMRULISTA);
886 mymru.nMaxItems = 15;
887 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
888 mymru.hKey = HCUbasekey;
889 mymru.lpszSubKey = "RecentDocs";
890 mymru.lpfnCompare = SHADD_compare_mru;
891 mruhandle = CreateMRUListA(&mymru);
892 if (!mruhandle) {
893 /* MRU failed */
894 ERR("MRU processing failed, handle zero\n");
895 RegCloseKey(HCUbasekey);
896 return;
898 len = lstrlenA(doc_name);
899 pos = FindMRUData(mruhandle, doc_name, len, 0);
901 /* Now get the MRU entry that will be replaced
902 * and delete the .lnk file for it
904 if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
905 buffer, 2048)) != -1) {
906 ptr = buffer;
907 ptr += (lstrlenA(buffer) + 1);
908 slen = *((short int*)ptr);
909 ptr += 2; /* skip the length area */
910 if (bufused >= slen + (ptr-buffer)) {
911 /* buffer size looks good */
912 ptr += 12; /* get to string */
913 len = bufused - (ptr-buffer); /* get length of buf remaining */
914 if (ptr[0] && (lstrlenA(ptr) <= len-1)) {
915 /* appears to be good string */
916 lstrcpyA(old_lnk_name, link_dir);
917 PathAppendA(old_lnk_name, ptr);
918 if (!DeleteFileA(old_lnk_name)) {
919 if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) {
920 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
921 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
922 old_lnk_name, err, attr);
924 else {
925 TRACE("old .lnk file %s did not exist\n",
926 old_lnk_name);
929 else {
930 ERR("Delete for %s failed, attr=%08lx\n",
931 old_lnk_name, attr);
934 else {
935 TRACE("deleted old .lnk file %s\n", old_lnk_name);
941 /* Create usable .lnk file name for the "Recent" directory
943 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
944 lstrcpyA(new_lnk_filepath, link_dir);
945 PathAppendA(new_lnk_filepath, new_lnk_name);
946 i = 1;
947 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
948 while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
949 i++;
950 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
951 lstrcpyA(new_lnk_filepath, link_dir);
952 PathAppendA(new_lnk_filepath, new_lnk_name);
954 SetErrorMode(olderrormode);
955 TRACE("new shortcut will be %s\n", new_lnk_filepath);
957 /* Now add the new MRU entry and data
959 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
960 buffer, &len);
961 FreeMRUList(mruhandle);
962 TRACE("Updated MRU list, new doc is position %d\n", pos);
965 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
967 { /* on input needs:
968 * doc_name - pure file-spec, no path
969 * new_lnk_filepath
970 * - path and file name of new .lnk file
971 * uFlags[in] - flags on call to SHAddToRecentDocs
972 * pv[in] - document path/pidl on call to SHAddToRecentDocs
974 IShellLinkA *psl = NULL;
975 IPersistFile *pPf = NULL;
976 HRESULT hres;
977 CHAR desc[MAX_PATH];
978 WCHAR widelink[MAX_PATH];
980 CoInitialize(0);
982 hres = CoCreateInstance( &CLSID_ShellLink,
983 NULL,
984 CLSCTX_INPROC_SERVER,
985 &IID_IShellLinkA,
986 (LPVOID )&psl);
987 if(SUCCEEDED(hres)) {
989 hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
990 (LPVOID *)&pPf);
991 if(FAILED(hres)) {
992 /* bombed */
993 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
994 goto fail;
997 /* Set the document path or pidl */
998 if (uFlags == SHARD_PIDL) {
999 hres = IShellLinkA_SetIDList(psl, pv);
1000 } else {
1001 hres = IShellLinkA_SetPath(psl, pv);
1003 if(FAILED(hres)) {
1004 /* bombed */
1005 ERR("failed Set{IDList|Path} %08lx\n", hres);
1006 goto fail;
1009 lstrcpyA(desc, "Shortcut to ");
1010 lstrcatA(desc, doc_name);
1011 hres = IShellLinkA_SetDescription(psl, desc);
1012 if(FAILED(hres)) {
1013 /* bombed */
1014 ERR("failed SetDescription %08lx\n", hres);
1015 goto fail;
1018 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
1019 widelink, MAX_PATH);
1020 /* create the short cut */
1021 hres = IPersistFile_Save(pPf, widelink, TRUE);
1022 if(FAILED(hres)) {
1023 /* bombed */
1024 ERR("failed IPersistFile::Save %08lx\n", hres);
1025 IPersistFile_Release(pPf);
1026 IShellLinkA_Release(psl);
1027 goto fail;
1029 hres = IPersistFile_SaveCompleted(pPf, widelink);
1030 IPersistFile_Release(pPf);
1031 IShellLinkA_Release(psl);
1032 TRACE("shortcut %s has been created, result=%08lx\n",
1033 new_lnk_filepath, hres);
1035 else {
1036 ERR("CoCreateInstance failed, hres=%08lx\n", hres);
1040 fail:
1041 CoUninitialize();
1043 /* all done */
1044 RegCloseKey(HCUbasekey);
1045 return;
1048 /*************************************************************************
1049 * SHWinHelp [SHELL32.127]
1052 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
1053 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
1054 return 0;
1056 /*************************************************************************
1057 * SHRunControlPanel [SHELL32.161]
1060 BOOL WINAPI SHRunControlPanel (LPCWSTR commandLine, HWND parent)
1062 FIXME("(%s, %p): stub\n", debugstr_w(commandLine), parent);
1063 return FALSE;
1066 /*************************************************************************
1067 * SHFreeUnusedLibraries [SHELL32.123]
1069 * Probably equivalent to CoFreeUnusedLibraries but under Windows 9x it could use
1070 * the shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
1071 * for details
1073 * NOTES
1074 * exported by ordinal
1076 * SEE ALSO
1077 * CoFreeUnusedLibraries, SHLoadOLE
1079 void WINAPI SHFreeUnusedLibraries (void)
1081 FIXME("stub\n");
1082 CoFreeUnusedLibraries();
1084 /*************************************************************************
1085 * DAD_AutoScroll [SHELL32.129]
1088 BOOL WINAPI DAD_AutoScroll(HWND hwnd, AUTO_SCROLL_DATA *samples, LPPOINT pt)
1090 FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1091 return FALSE;
1093 /*************************************************************************
1094 * DAD_DragEnter [SHELL32.130]
1097 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1099 FIXME("hwnd = %p\n",hwnd);
1100 return FALSE;
1102 /*************************************************************************
1103 * DAD_DragEnterEx [SHELL32.131]
1106 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1108 FIXME("hwnd = %p (%ld,%ld)\n",hwnd,p.x,p.y);
1109 return FALSE;
1111 /*************************************************************************
1112 * DAD_DragMove [SHELL32.134]
1115 BOOL WINAPI DAD_DragMove(POINT p)
1117 FIXME("(%ld,%ld)\n",p.x,p.y);
1118 return FALSE;
1120 /*************************************************************************
1121 * DAD_DragLeave [SHELL32.132]
1124 BOOL WINAPI DAD_DragLeave(VOID)
1126 FIXME("\n");
1127 return FALSE;
1129 /*************************************************************************
1130 * DAD_SetDragImage [SHELL32.136]
1132 * NOTES
1133 * exported by name
1135 BOOL WINAPI DAD_SetDragImage(
1136 HIMAGELIST himlTrack,
1137 LPPOINT lppt)
1139 FIXME("%p %p stub\n",himlTrack, lppt);
1140 return FALSE;
1142 /*************************************************************************
1143 * DAD_ShowDragImage [SHELL32.137]
1145 * NOTES
1146 * exported by name
1148 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1150 FIXME("0x%08x stub\n",bShow);
1151 return FALSE;
1154 /*************************************************************************
1155 * ReadCabinetState [SHELL32.651] NT 4.0
1158 BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
1160 HKEY hkey = 0;
1161 DWORD type, r;
1163 TRACE("%p %d\n", cs, length);
1165 if( (cs == NULL) || (length < (int)sizeof(*cs)) )
1166 return FALSE;
1168 r = RegOpenKeyW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CabinetState", &hkey );
1169 if( r == ERROR_SUCCESS )
1171 type = REG_BINARY;
1172 r = RegQueryValueExW( hkey, L"Settings", NULL, &type, (LPBYTE)cs, (LPDWORD)&length );
1173 RegCloseKey( hkey );
1177 /* if we can't read from the registry, create default values */
1178 if ( (r != ERROR_SUCCESS) || (cs->cLength < sizeof(*cs)) ||
1179 (cs->cLength != length) )
1181 ERR("Initializing shell cabinet settings\n");
1182 memset(cs, 0, sizeof(*cs));
1183 cs->cLength = sizeof(*cs);
1184 cs->nVersion = 2;
1185 cs->fFullPathTitle = 0;
1186 cs->fSaveLocalView = -1;
1187 cs->fNotShell = 0;
1188 cs->fSimpleDefault = -1;
1189 cs->fDontShowDescBar = 0;
1190 cs->fNewWindowMode = 0;
1191 cs->fShowCompColor = 0;
1192 cs->fDontPrettyNames = 0;
1193 cs->fAdminsCreateCommonGroups = -1;
1194 cs->fMenuEnumFilter = 96;
1197 return TRUE;
1200 /*************************************************************************
1201 * WriteCabinetState [SHELL32.652] NT 4.0
1204 BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
1206 DWORD r;
1207 HKEY hkey = 0;
1209 TRACE("%p\n",cs);
1211 if( cs == NULL )
1212 return FALSE;
1214 r = RegCreateKeyExW( HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\CabinetState", 0,
1215 NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
1216 if( r == ERROR_SUCCESS )
1218 r = RegSetValueExW( hkey, L"Settings", 0, REG_BINARY, (LPBYTE) cs, cs->cLength);
1219 RegCloseKey( hkey );
1222 return (r==ERROR_SUCCESS);
1225 /*************************************************************************
1226 * FileIconInit [SHELL32.660]
1229 BOOL WINAPI FileIconInit(BOOL bFullInit)
1230 { FIXME("(%s)\n", bFullInit ? "true" : "false");
1231 return FALSE;
1234 /*************************************************************************
1235 * IsUserAnAdmin [SHELL32.680] NT 4.0
1237 * Checks whether the current user is a member of the Administrators group.
1239 * PARAMS
1240 * None
1242 * RETURNS
1243 * Success: TRUE
1244 * Failure: FALSE
1246 BOOL WINAPI IsUserAnAdmin(VOID)
1248 SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
1249 HANDLE hToken;
1250 DWORD dwSize;
1251 PTOKEN_GROUPS lpGroups;
1252 PSID lpSid;
1253 DWORD i;
1254 BOOL bResult = FALSE;
1256 TRACE("\n");
1257 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
1259 return FALSE;
1262 if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
1264 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1266 CloseHandle(hToken);
1267 return FALSE;
1271 lpGroups = malloc(dwSize);
1272 if (lpGroups == NULL)
1274 CloseHandle(hToken);
1275 return FALSE;
1278 if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize))
1280 free(lpGroups);
1281 CloseHandle(hToken);
1282 return FALSE;
1285 CloseHandle(hToken);
1286 if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
1287 DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
1288 &lpSid))
1290 free(lpGroups);
1291 return FALSE;
1294 for (i = 0; i < lpGroups->GroupCount; i++)
1296 if (EqualSid(lpSid, lpGroups->Groups[i].Sid))
1298 bResult = TRUE;
1299 break;
1303 FreeSid(lpSid);
1304 free(lpGroups);
1305 return bResult;
1308 /*************************************************************************
1309 * SetAppStartingCursor [SHELL32.99]
1311 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1312 { FIXME("hwnd=%p 0x%04lx stub\n",u,v );
1313 return 0;
1316 /*************************************************************************
1317 * SHLoadOLE [SHELL32.151]
1319 * To reduce the memory usage of Windows 95, its shell32 contained an
1320 * internal implementation of a part of COM (see e.g. SHGetMalloc, SHCoCreateInstance,
1321 * SHRegisterDragDrop etc.) that allowed to use in-process STA objects without
1322 * the need to load OLE32.DLL. If OLE32.DLL was already loaded, the SH* function
1323 * would just call the Co* functions.
1325 * The SHLoadOLE was called when OLE32.DLL was being loaded to transfer all the
1326 * information from the shell32 "mini-COM" to ole32.dll.
1328 * See http://blogs.msdn.com/oldnewthing/archive/2004/07/05/173226.aspx for a
1329 * detailed description.
1331 * Under wine ole32.dll is always loaded as it is imported by shlwapi.dll which is
1332 * imported by shell32 and no "mini-COM" is used (except for the "LoadWithoutCOM"
1333 * hack in SHCoCreateInstance)
1335 HRESULT WINAPI SHLoadOLE(LPARAM lParam)
1336 { FIXME("0x%08Ix stub\n",lParam);
1337 return S_OK;
1339 /*************************************************************************
1340 * DriveType [SHELL32.64]
1343 int WINAPI DriveType(int u)
1344 { FIXME("0x%04x stub\n",u);
1345 return 0;
1347 /*************************************************************************
1348 * InvalidateDriveType [SHELL32.65]
1351 int WINAPI InvalidateDriveType(int u)
1352 { FIXME("0x%08x stub\n",u);
1353 return 0;
1355 /*************************************************************************
1356 * SHAbortInvokeCommand [SHELL32.198]
1359 HRESULT WINAPI SHAbortInvokeCommand(void)
1360 { FIXME("stub\n");
1361 return 1;
1363 /*************************************************************************
1364 * SHOutOfMemoryMessageBox [SHELL32.126]
1367 int WINAPI SHOutOfMemoryMessageBox(
1368 HWND hwndOwner,
1369 LPCSTR lpCaption,
1370 UINT uType)
1372 FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1373 return 0;
1375 /*************************************************************************
1376 * SHFlushClipboard [SHELL32.121]
1379 HRESULT WINAPI SHFlushClipboard(void)
1380 { FIXME("stub\n");
1381 return 1;
1384 /*************************************************************************
1385 * SHWaitForFileToOpen [SHELL32.97]
1388 BOOL WINAPI SHWaitForFileToOpen(
1389 LPCITEMIDLIST pidl,
1390 DWORD dwFlags,
1391 DWORD dwTimeout)
1393 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1394 return FALSE;
1397 /************************************************************************
1398 * RLBuildListOfPaths [SHELL32.146]
1400 * NOTES
1401 * builds a DPA
1403 DWORD WINAPI RLBuildListOfPaths (void)
1404 { FIXME("stub\n");
1405 return 0;
1407 /************************************************************************
1408 * SHValidateUNC [SHELL32.173]
1411 BOOL WINAPI SHValidateUNC (HWND hwndOwner, PWSTR pszFile, UINT fConnect)
1413 FIXME("(%p, %s, 0x%08x): stub\n", hwndOwner, debugstr_w(pszFile), fConnect);
1414 return FALSE;
1417 /************************************************************************
1418 * DoEnvironmentSubstA [SHELL32.@]
1420 * See DoEnvironmentSubstW.
1422 DWORD WINAPI DoEnvironmentSubstA(LPSTR pszString, UINT cchString)
1424 LPSTR dst;
1425 BOOL res = FALSE;
1426 DWORD len = cchString;
1428 TRACE("(%s, %d)\n", debugstr_a(pszString), cchString);
1430 if ((dst = malloc(cchString * sizeof(CHAR))))
1432 len = ExpandEnvironmentStringsA(pszString, dst, cchString);
1433 /* len includes the terminating 0 */
1434 if (len && len < cchString)
1436 res = TRUE;
1437 memcpy(pszString, dst, len);
1439 else
1440 len = cchString;
1442 free(dst);
1444 return MAKELONG(len, res);
1447 /************************************************************************
1448 * DoEnvironmentSubstW [SHELL32.@]
1450 * Replace all %KEYWORD% in the string with the value of the named
1451 * environment variable. If the buffer is too small, the string is not modified.
1453 * PARAMS
1454 * pszString [I] '\0' terminated string with %keyword%.
1455 * [O] '\0' terminated string with %keyword% substituted.
1456 * cchString [I] size of str.
1458 * RETURNS
1459 * Success: The string in the buffer is updated
1460 * HIWORD: TRUE
1461 * LOWORD: characters used in the buffer, including space for the terminating 0
1462 * Failure: buffer too small. The string is not modified.
1463 * HIWORD: FALSE
1464 * LOWORD: provided size of the buffer in characters
1466 DWORD WINAPI DoEnvironmentSubstW(LPWSTR pszString, UINT cchString)
1468 LPWSTR dst;
1469 BOOL res = FALSE;
1470 DWORD len = cchString;
1472 TRACE("(%s, %d)\n", debugstr_w(pszString), cchString);
1474 if ((cchString < MAXLONG) && (dst = malloc(cchString * sizeof(WCHAR))))
1476 len = ExpandEnvironmentStringsW(pszString, dst, cchString);
1477 /* len includes the terminating 0 */
1478 if (len && len <= cchString)
1480 res = TRUE;
1481 memcpy(pszString, dst, len * sizeof(WCHAR));
1483 else
1484 len = cchString;
1486 free(dst);
1488 return MAKELONG(len, res);
1491 /************************************************************************
1492 * DoEnvironmentSubst [SHELL32.53]
1494 * See DoEnvironmentSubstA.
1496 DWORD WINAPI DoEnvironmentSubstAW(LPVOID x, UINT y)
1498 if (SHELL_OsIsUnicode())
1499 return DoEnvironmentSubstW(x, y);
1500 return DoEnvironmentSubstA(x, y);
1503 /*************************************************************************
1504 * @ [SHELL32.243]
1506 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1507 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1511 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1513 return FALSE;
1516 /*************************************************************************
1517 * GUIDFromStringW [SHELL32.704]
1519 BOOL WINAPI GUIDFromStringW(LPCWSTR str, LPGUID guid)
1521 UNICODE_STRING guid_str;
1523 RtlInitUnicodeString(&guid_str, str);
1524 return !RtlGUIDFromString(&guid_str, guid);
1527 /*************************************************************************
1528 * PathIsTemporaryW [SHELL32.714]
1530 BOOL WINAPI PathIsTemporaryW(const WCHAR *path)
1532 FIXME("(%s) stub\n", debugstr_w(path));
1533 return FALSE;
1536 typedef struct _PSXA
1538 UINT uiCount;
1539 UINT uiAllocated;
1540 IShellPropSheetExt *pspsx[1];
1541 } PSXA, *PPSXA;
1543 typedef struct _PSXA_CALL
1545 LPFNADDPROPSHEETPAGE lpfnAddReplaceWith;
1546 LPARAM lParam;
1547 BOOL bCalled;
1548 BOOL bMultiple;
1549 UINT uiCount;
1550 } PSXA_CALL, *PPSXA_CALL;
1552 static BOOL CALLBACK PsxaCall(HPROPSHEETPAGE hpage, LPARAM lParam)
1554 PPSXA_CALL Call = (PPSXA_CALL)lParam;
1556 if (Call != NULL)
1558 if ((Call->bMultiple || !Call->bCalled) &&
1559 Call->lpfnAddReplaceWith(hpage, Call->lParam))
1561 Call->bCalled = TRUE;
1562 Call->uiCount++;
1563 return TRUE;
1567 return FALSE;
1570 /*************************************************************************
1571 * SHAddFromPropSheetExtArray [SHELL32.167]
1573 UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
1575 PSXA_CALL Call;
1576 UINT i;
1577 PPSXA psxa = (PPSXA)hpsxa;
1579 TRACE("(%p,%p,%08Ix)\n", hpsxa, lpfnAddPage, lParam);
1581 if (psxa)
1583 ZeroMemory(&Call, sizeof(Call));
1584 Call.lpfnAddReplaceWith = lpfnAddPage;
1585 Call.lParam = lParam;
1586 Call.bMultiple = TRUE;
1588 /* Call the AddPage method of all registered IShellPropSheetExt interfaces */
1589 for (i = 0; i != psxa->uiCount; i++)
1591 IShellPropSheetExt_AddPages(psxa->pspsx[i], PsxaCall, (LPARAM)&Call);
1594 return Call.uiCount;
1597 return 0;
1600 /*************************************************************************
1601 * SHCreatePropSheetExtArray [SHELL32.168]
1603 HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
1605 return SHCreatePropSheetExtArrayEx(hKey, pszSubKey, max_iface, NULL);
1608 /*************************************************************************
1609 * SHCreatePropSheetExtArrayEx [SHELL32.194]
1611 HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, LPDATAOBJECT pDataObj)
1613 WCHAR szHandler[64];
1614 DWORD dwHandlerLen;
1615 WCHAR szClsidHandler[39];
1616 DWORD dwClsidSize;
1617 CLSID clsid;
1618 LONG lRet;
1619 DWORD dwIndex;
1620 IShellExtInit *psxi;
1621 IShellPropSheetExt *pspsx;
1622 HKEY hkBase, hkPropSheetHandlers;
1623 PPSXA psxa = NULL;
1625 TRACE("(%p,%s,%u)\n", hKey, debugstr_w(pszSubKey), max_iface);
1627 if (max_iface == 0)
1628 return NULL;
1630 /* Open the registry key */
1631 lRet = RegOpenKeyW(hKey, pszSubKey, &hkBase);
1632 if (lRet != ERROR_SUCCESS)
1633 return NULL;
1635 lRet = RegOpenKeyExW(hkBase, L"shellex\\PropertySheetHandlers", 0, KEY_ENUMERATE_SUB_KEYS, &hkPropSheetHandlers);
1636 RegCloseKey(hkBase);
1637 if (lRet == ERROR_SUCCESS)
1639 /* Create and initialize the Property Sheet Extensions Array */
1640 psxa = LocalAlloc(LMEM_FIXED, FIELD_OFFSET(PSXA, pspsx[max_iface]));
1641 if (psxa)
1643 ZeroMemory(psxa, FIELD_OFFSET(PSXA, pspsx[max_iface]));
1644 psxa->uiAllocated = max_iface;
1646 /* Enumerate all subkeys and attempt to load the shell extensions */
1647 dwIndex = 0;
1650 dwHandlerLen = ARRAY_SIZE(szHandler);
1651 lRet = RegEnumKeyExW(hkPropSheetHandlers, dwIndex++, szHandler, &dwHandlerLen, NULL, NULL, NULL, NULL);
1652 if (lRet != ERROR_SUCCESS)
1654 if (lRet == ERROR_MORE_DATA)
1655 continue;
1657 if (lRet == ERROR_NO_MORE_ITEMS)
1658 lRet = ERROR_SUCCESS;
1659 break;
1662 /* The CLSID is stored either in the key itself or in its default value. */
1663 if (FAILED(lRet = SHCLSIDFromStringW(szHandler, &clsid)))
1665 dwClsidSize = sizeof(szClsidHandler);
1666 if (SHGetValueW(hkPropSheetHandlers, szHandler, NULL, NULL, szClsidHandler, &dwClsidSize) == ERROR_SUCCESS)
1668 /* Force a NULL-termination and convert the string */
1669 szClsidHandler[ARRAY_SIZE(szClsidHandler) - 1] = 0;
1670 lRet = SHCLSIDFromStringW(szClsidHandler, &clsid);
1674 if (SUCCEEDED(lRet))
1676 /* Attempt to get an IShellPropSheetExt and an IShellExtInit instance.
1677 Only if both interfaces are supported it's a real shell extension.
1678 Then call IShellExtInit's Initialize method. */
1679 if (SUCCEEDED(CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER/* | CLSCTX_NO_CODE_DOWNLOAD */, &IID_IShellPropSheetExt, (LPVOID *)&pspsx)))
1681 if (SUCCEEDED(IShellPropSheetExt_QueryInterface(pspsx, &IID_IShellExtInit, (PVOID *)&psxi)))
1683 if (SUCCEEDED(IShellExtInit_Initialize(psxi, NULL, pDataObj, hKey)))
1685 /* Add the IShellPropSheetExt instance to the array */
1686 psxa->pspsx[psxa->uiCount++] = pspsx;
1688 else
1690 IShellExtInit_Release(psxi);
1691 IShellPropSheetExt_Release(pspsx);
1694 else
1695 IShellPropSheetExt_Release(pspsx);
1699 } while (psxa->uiCount != psxa->uiAllocated);
1701 else
1702 lRet = ERROR_NOT_ENOUGH_MEMORY;
1704 RegCloseKey(hkPropSheetHandlers);
1707 if (lRet != ERROR_SUCCESS && psxa)
1709 SHDestroyPropSheetExtArray((HPSXA)psxa);
1710 psxa = NULL;
1713 return (HPSXA)psxa;
1716 /*************************************************************************
1717 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1719 UINT WINAPI SHReplaceFromPropSheetExtArray(HPSXA hpsxa, UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
1721 PSXA_CALL Call;
1722 UINT i;
1723 PPSXA psxa = (PPSXA)hpsxa;
1725 TRACE("(%p,%u,%p,%08Ix)\n", hpsxa, uPageID, lpfnReplaceWith, lParam);
1727 if (psxa)
1729 ZeroMemory(&Call, sizeof(Call));
1730 Call.lpfnAddReplaceWith = lpfnReplaceWith;
1731 Call.lParam = lParam;
1733 /* Call the ReplacePage method of all registered IShellPropSheetExt interfaces.
1734 Each shell extension is only allowed to call the callback once during the callback. */
1735 for (i = 0; i != psxa->uiCount; i++)
1737 Call.bCalled = FALSE;
1738 IShellPropSheetExt_ReplacePage(psxa->pspsx[i], uPageID, PsxaCall, (LPARAM)&Call);
1741 return Call.uiCount;
1744 return 0;
1747 /*************************************************************************
1748 * SHDestroyPropSheetExtArray [SHELL32.169]
1750 void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
1752 UINT i;
1753 PPSXA psxa = (PPSXA)hpsxa;
1755 TRACE("(%p)\n", hpsxa);
1757 if (psxa)
1759 for (i = 0; i != psxa->uiCount; i++)
1761 IShellPropSheetExt_Release(psxa->pspsx[i]);
1764 LocalFree(psxa);
1768 /*************************************************************************
1769 * CIDLData_CreateFromIDArray [SHELL32.83]
1771 * Create IDataObject from PIDLs??
1773 HRESULT WINAPI CIDLData_CreateFromIDArray(
1774 LPCITEMIDLIST pidlFolder,
1775 DWORD cpidlFiles,
1776 LPCITEMIDLIST *lppidlFiles,
1777 LPDATAOBJECT *ppdataObject)
1779 UINT i;
1780 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1782 TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1783 if (TRACE_ON(pidl))
1785 pdump (pidlFolder);
1786 for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1788 *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1789 lppidlFiles, cpidlFiles);
1790 if (*ppdataObject) return S_OK;
1791 return E_OUTOFMEMORY;
1794 /*************************************************************************
1795 * SHCreateStdEnumFmtEtc [SHELL32.74]
1797 * NOTES
1800 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1801 DWORD cFormats,
1802 const FORMATETC *lpFormats,
1803 LPENUMFORMATETC *ppenumFormatetc)
1805 IEnumFORMATETC *pef;
1806 HRESULT hRes;
1807 TRACE("cf=%ld fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1809 pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1810 if (!pef)
1811 return E_OUTOFMEMORY;
1813 IEnumFORMATETC_AddRef(pef);
1814 hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1815 IEnumFORMATETC_Release(pef);
1817 return hRes;
1820 /*************************************************************************
1821 * SHFindFiles (SHELL32.90)
1823 BOOL WINAPI SHFindFiles( LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlSaveFile )
1825 FIXME("%p %p\n", pidlFolder, pidlSaveFile );
1826 return FALSE;
1829 /*************************************************************************
1830 * SHUpdateImageW (SHELL32.192)
1832 * Notifies the shell that an icon in the system image list has been changed.
1834 * PARAMS
1835 * pszHashItem [I] Path to file that contains the icon.
1836 * iIndex [I] Zero-based index of the icon in the file.
1837 * uFlags [I] Flags determining the icon attributes. See notes.
1838 * iImageIndex [I] Index of the icon in the system image list.
1840 * RETURNS
1841 * Nothing
1843 * NOTES
1844 * uFlags can be one or more of the following flags:
1845 * GIL_NOTFILENAME - pszHashItem is not a file name.
1846 * GIL_SIMULATEDOC - Create a document icon using the specified icon.
1848 void WINAPI SHUpdateImageW(LPCWSTR pszHashItem, int iIndex, UINT uFlags, int iImageIndex)
1850 FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_w(pszHashItem), iIndex, uFlags, iImageIndex);
1853 /*************************************************************************
1854 * SHUpdateImageA (SHELL32.191)
1856 * See SHUpdateImageW.
1858 VOID WINAPI SHUpdateImageA(LPCSTR pszHashItem, INT iIndex, UINT uFlags, INT iImageIndex)
1860 FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_a(pszHashItem), iIndex, uFlags, iImageIndex);
1863 INT WINAPI SHHandleUpdateImage(LPCITEMIDLIST pidlExtra)
1865 FIXME("%p - stub\n", pidlExtra);
1867 return -1;
1870 BOOL WINAPI SHObjectProperties(HWND hwnd, DWORD dwType, LPCWSTR szObject, LPCWSTR szPage)
1872 FIXME("%p, 0x%08lx, %s, %s - stub\n", hwnd, dwType, debugstr_w(szObject), debugstr_w(szPage));
1874 return TRUE;
1877 BOOL WINAPI SHGetNewLinkInfoA(LPCSTR pszLinkTo, LPCSTR pszDir, LPSTR pszName, BOOL *pfMustCopy,
1878 UINT uFlags)
1880 WCHAR wszLinkTo[MAX_PATH];
1881 WCHAR wszDir[MAX_PATH];
1882 WCHAR wszName[MAX_PATH];
1883 BOOL res;
1885 MultiByteToWideChar(CP_ACP, 0, pszLinkTo, -1, wszLinkTo, MAX_PATH);
1886 MultiByteToWideChar(CP_ACP, 0, pszDir, -1, wszDir, MAX_PATH);
1888 res = SHGetNewLinkInfoW(wszLinkTo, wszDir, wszName, pfMustCopy, uFlags);
1890 if (res)
1891 WideCharToMultiByte(CP_ACP, 0, wszName, -1, pszName, MAX_PATH, NULL, NULL);
1893 return res;
1896 BOOL WINAPI SHGetNewLinkInfoW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName, BOOL *pfMustCopy,
1897 UINT uFlags)
1899 const WCHAR *basename;
1900 WCHAR *dst_basename;
1901 int i=2;
1903 TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(pszLinkTo), debugstr_w(pszDir),
1904 pszName, pfMustCopy, uFlags);
1906 *pfMustCopy = FALSE;
1908 if (uFlags & SHGNLI_PIDL)
1910 FIXME("SHGNLI_PIDL flag unsupported\n");
1911 return FALSE;
1914 if (uFlags)
1915 FIXME("ignoring flags: 0x%08x\n", uFlags);
1917 /* FIXME: should test if the file is a shortcut or DOS program */
1918 if (GetFileAttributesW(pszLinkTo) == INVALID_FILE_ATTRIBUTES)
1919 return FALSE;
1921 basename = wcsrchr(pszLinkTo, '\\');
1922 if (basename)
1923 basename = basename+1;
1924 else
1925 basename = pszLinkTo;
1927 lstrcpynW(pszName, pszDir, MAX_PATH);
1928 if (!PathAddBackslashW(pszName))
1929 return FALSE;
1931 dst_basename = pszName + lstrlenW(pszName);
1933 swprintf(dst_basename, pszName + MAX_PATH - dst_basename, L"%s.lnk", basename);
1935 while (GetFileAttributesW(pszName) != INVALID_FILE_ATTRIBUTES)
1937 swprintf(dst_basename, pszName + MAX_PATH - dst_basename, L"%s (%d).lnk", basename, i);
1938 i++;
1941 return TRUE;
1944 HRESULT WINAPI SHStartNetConnectionDialog(HWND hwnd, LPCSTR pszRemoteName, DWORD dwType)
1946 FIXME("%p, %s, 0x%08lx - stub\n", hwnd, debugstr_a(pszRemoteName), dwType);
1948 return S_OK;
1951 DWORD WINAPI SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options)
1953 FIXME("%p, 0x%08x, 0x%08x, 0x%08x - stub\n", hwnd, drive, fmtID, options);
1955 return SHFMT_NOFORMAT;
1958 /*************************************************************************
1959 * SHRemoveLocalizedName (SHELL32.@)
1961 HRESULT WINAPI SHRemoveLocalizedName(const WCHAR *path)
1963 FIXME("%s stub\n", debugstr_w(path));
1964 return S_OK;
1967 /*************************************************************************
1968 * SHSetLocalizedName (SHELL32.@)
1970 HRESULT WINAPI SHSetLocalizedName(LPWSTR pszPath, LPCWSTR pszResModule, int idsRes)
1972 FIXME("%p, %s, %d - stub\n", pszPath, debugstr_w(pszResModule), idsRes);
1974 return S_OK;
1977 /*************************************************************************
1978 * LinkWindow_RegisterClass (SHELL32.258)
1980 BOOL WINAPI LinkWindow_RegisterClass(void)
1982 FIXME("()\n");
1983 return TRUE;
1986 /*************************************************************************
1987 * LinkWindow_UnregisterClass (SHELL32.259)
1989 BOOL WINAPI LinkWindow_UnregisterClass(void)
1991 FIXME("()\n");
1992 return TRUE;
1995 /*************************************************************************
1996 * SHFlushSFCache (SHELL32.526)
1998 * Notifies the shell that a user-specified special folder location has changed.
2000 * NOTES
2001 * In Wine, the shell folder registry values are not cached, so this function
2002 * has no effect.
2004 void WINAPI SHFlushSFCache(void)