2 * The parameters of many functions changes between different OS versions
3 * (NT uses Unicode strings, 95 uses ASCII strings)
5 * Copyright 1997 Marcus Meissner
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "wine/debug.h"
35 #include "shell32_main.h"
36 #include "undocshell.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(shell);
42 WINE_DECLARE_DEBUG_CHANNEL(pidl);
44 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
45 /* !!! it is in both here and comctl32undoc.c !!! */
46 typedef struct tagCREATEMRULIST
48 DWORD cbSize; /* size of struct */
49 DWORD nMaxItems; /* max no. of items in list */
50 DWORD dwFlags; /* see below */
51 HKEY hKey; /* root reg. key under which list is saved */
52 LPCSTR lpszSubKey; /* reg. subkey */
53 PROC lpfnCompare; /* item compare proc */
54 } CREATEMRULISTA, *LPCREATEMRULISTA;
57 #define MRUF_STRING_LIST 0 /* list will contain strings */
58 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
59 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
61 extern HANDLE WINAPI CreateMRUListA(LPCREATEMRULISTA lpcml);
62 extern DWORD WINAPI FreeMRUList(HANDLE hMRUList);
63 extern INT WINAPI AddMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData);
64 extern INT WINAPI FindMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
65 extern INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
67 /*************************************************************************
68 * ParseFieldA [internal]
70 * copies a field from a ',' delimited string
72 * first field is nField = 1
74 DWORD WINAPI ParseFieldA(
80 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src),nField,dst,len);
82 if (!src || !src[0] || !dst || !len)
85 /* skip n fields delimited by ',' */
88 if (*src=='\0') return FALSE;
89 if (*(src++)==',') nField--;
92 /* copy part till the next ',' to dst */
93 while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
95 /* finalize the string */
101 /*************************************************************************
102 * ParseFieldW [internal]
104 * copies a field from a ',' delimited string
106 * first field is nField = 1
108 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
110 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n", debugstr_w(src), nField, dst, len);
112 if (!src || !src[0] || !dst || !len)
115 /* skip n fields delimited by ',' */
118 if (*src == 0x0) return FALSE;
119 if (*src++ == ',') nField--;
122 /* copy part till the next ',' to dst */
123 while ( *src != 0x0 && *src != ',' && (len--)>0 ) *(dst++) = *(src++);
125 /* finalize the string */
131 /*************************************************************************
132 * ParseField [SHELL32.58]
134 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
136 if (SHELL_OsIsUnicode())
137 return ParseFieldW(src, nField, dst, len);
138 return ParseFieldA(src, nField, dst, len);
141 /*************************************************************************
142 * GetFileNameFromBrowse [SHELL32.63]
145 BOOL WINAPI GetFileNameFromBrowse(
149 LPCSTR lpstrInitialDir,
155 FARPROC pGetOpenFileNameA;
159 TRACE("%p, %s, %ld, %s, %s, %s, %s)\n",
160 hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
161 lpstrFilter, lpstrTitle);
163 hmodule = LoadLibraryA("comdlg32.dll");
164 if(!hmodule) return FALSE;
165 pGetOpenFileNameA = GetProcAddress(hmodule, "GetOpenFileNameA");
166 if(!pGetOpenFileNameA)
168 FreeLibrary(hmodule);
172 memset(&ofn, 0, sizeof(ofn));
174 ofn.lStructSize = sizeof(ofn);
175 ofn.hwndOwner = hwndOwner;
176 ofn.lpstrFilter = lpstrFilter;
177 ofn.lpstrFile = lpstrFile;
178 ofn.nMaxFile = nMaxFile;
179 ofn.lpstrInitialDir = lpstrInitialDir;
180 ofn.lpstrTitle = lpstrTitle;
181 ofn.lpstrDefExt = lpstrDefExt;
182 ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
183 ret = pGetOpenFileNameA(&ofn);
185 FreeLibrary(hmodule);
189 /*************************************************************************
190 * SHGetSetSettings [SHELL32.68]
192 VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
196 FIXME("%p 0x%08lx TRUE\n", lpss, dwMask);
200 SHGetSettings((LPSHELLFLAGSTATE)lpss,dwMask);
204 /*************************************************************************
205 * SHGetSettings [SHELL32.@]
208 * the registry path are for win98 (tested)
209 * and possibly are the same in nt40
212 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
216 DWORD dwDataSize = sizeof (DWORD);
218 TRACE("(%p 0x%08lx)\n",lpsfs,dwMask);
220 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
221 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
224 if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
225 lpsfs->fShowExtensions = ((dwData == 0) ? 0 : 1);
227 if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
228 lpsfs->fShowInfoTip = ((dwData == 0) ? 0 : 1);
230 if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
231 lpsfs->fDontPrettyPath = ((dwData == 0) ? 0 : 1);
233 if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
234 lpsfs->fHideIcons = ((dwData == 0) ? 0 : 1);
236 if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
237 lpsfs->fMapNetDrvBtn = ((dwData == 0) ? 0 : 1);
239 if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
240 lpsfs->fShowAttribCol = ((dwData == 0) ? 0 : 1);
242 if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
244 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
245 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
247 else if (dwData == 1)
248 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 1;
249 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
251 else if (dwData == 2)
252 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
253 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 1;
258 TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
261 /*************************************************************************
262 * SHShellFolderView_Message [SHELL32.73]
265 * hwndCabinet defines the explorer cabinet window that contains the
266 * shellview you need to communicate with
267 * uMsg identifying the SFVM enum to perform
271 * Message SFVM_REARRANGE = 1
272 * This message gets sent when a column gets clicked to instruct the
273 * shell view to re-sort the item list. lParam identifies the column
276 int WINAPI SHShellFolderView_Message(
281 FIXME("%p %08lx %08lx stub\n",hwndCabinet, dwMessage, dwParam);
285 /*************************************************************************
286 * RegisterShellHook [SHELL32.181]
289 * hwnd [I] window handle
293 * exported by ordinal
295 BOOL WINAPI RegisterShellHook(
299 FIXME("(%p,0x%08lx):stub.\n",hWnd, dwType);
302 /*************************************************************************
303 * ShellMessageBoxW [SHELL32.182]
305 * Format and output errormessage.
307 * idText resource ID of title or LPSTR
308 * idTitle resource ID of title or LPSTR
311 * exported by ordinal
313 int WINAPIV ShellMessageBoxW(
321 WCHAR szText[100],szTitle[100];
322 LPCWSTR pszText = szText, pszTitle = szTitle, pszTemp;
326 va_start(args, uType);
327 /* wvsprintfA(buf,fmt, args); */
329 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
330 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
332 if (!HIWORD(lpCaption))
333 LoadStringW(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
335 pszTitle = lpCaption;
338 LoadStringW(hInstance, (DWORD)lpText, szText, sizeof(szText)/sizeof(szText[0]));
342 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
343 pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
347 ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
348 LocalFree((HLOCAL)pszTemp);
352 /*************************************************************************
353 * ShellMessageBoxA [SHELL32.183]
355 int WINAPIV ShellMessageBoxA(
363 char szText[100],szTitle[100];
364 LPCSTR pszText = szText, pszTitle = szTitle, pszTemp;
368 va_start(args, uType);
369 /* wvsprintfA(buf,fmt, args); */
371 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
372 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
374 if (!HIWORD(lpCaption))
375 LoadStringA(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle));
377 pszTitle = lpCaption;
380 LoadStringA(hInstance, (DWORD)lpText, szText, sizeof(szText));
384 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
385 pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
389 ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
390 LocalFree((HLOCAL)pszTemp);
394 /*************************************************************************
395 * SHRegisterDragDrop [SHELL32.86]
398 * exported by ordinal
400 HRESULT WINAPI SHRegisterDragDrop(
402 LPDROPTARGET pDropTarget)
404 FIXME("(%p,%p):stub.\n", hWnd, pDropTarget);
405 if (GetShellOle()) return pRegisterDragDrop(hWnd, pDropTarget);
409 /*************************************************************************
410 * SHRevokeDragDrop [SHELL32.87]
413 * exported by ordinal
415 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
417 FIXME("(%p):stub.\n",hWnd);
418 if (GetShellOle()) return pRevokeDragDrop(hWnd);
422 /*************************************************************************
423 * SHDoDragDrop [SHELL32.88]
426 * exported by ordinal
428 HRESULT WINAPI SHDoDragDrop(
430 LPDATAOBJECT lpDataObject,
431 LPDROPSOURCE lpDropSource,
435 FIXME("(%p %p %p 0x%08lx %p):stub.\n",
436 hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
437 if (GetShellOle()) return pDoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
441 /*************************************************************************
442 * ArrangeWindows [SHELL32.184]
445 WORD WINAPI ArrangeWindows(
452 FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
453 hwndParent, dwReserved, lpRect, cKids, lpKids);
457 /*************************************************************************
458 * SignalFileOpen [SHELL32.103]
461 * exported by ordinal
464 SignalFileOpen (DWORD dwParam1)
466 FIXME("(0x%08lx):stub.\n", dwParam1);
471 /*************************************************************************
472 * SHADD_get_policy - helper function for SHAddToRecentDocs
475 * policy [IN] policy name (null termed string) to find
476 * type [OUT] ptr to DWORD to receive type
477 * buffer [OUT] ptr to area to hold data retrieved
478 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
482 * result of the SHQueryValueEx call
484 static INT SHADD_get_policy(LPSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
489 /* Get the key for the policies location in the registry
491 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
492 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
493 0, KEY_READ, &Policy_basekey)) {
495 if (RegOpenKeyExA(HKEY_CURRENT_USER,
496 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
497 0, KEY_READ, &Policy_basekey)) {
498 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
501 return ERROR_FILE_NOT_FOUND;
505 /* Retrieve the data if it exists
507 ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
508 RegCloseKey(Policy_basekey);
513 /*************************************************************************
514 * SHADD_compare_mru - helper function for SHAddToRecentDocs
517 * data1 [IN] data being looked for
518 * data2 [IN] data in MRU
519 * cbdata [IN] length from FindMRUData call (not used)
522 * position within MRU list that data was added.
524 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
526 return lstrcmpiA(data1, data2);
529 /*************************************************************************
530 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
533 * mruhandle [IN] handle for created MRU list
534 * doc_name [IN] null termed pure doc name
535 * new_lnk_name [IN] null termed path and file name for .lnk file
536 * buffer [IN/OUT] 2048 byte area to consturct MRU data
537 * len [OUT] ptr to int to receive space used in buffer
540 * position within MRU list that data was added.
542 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
543 LPSTR buffer, INT *len)
549 * RecentDocs MRU data structure seems to be:
550 * +0h document file name w/ terminating 0h
551 * +nh short int w/ size of remaining
552 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
553 * +n+4h 10 bytes zeros - unknown
554 * +n+eh shortcut file name w/ terminating 0h
555 * +n+e+nh 3 zero bytes - unknown
558 /* Create the MRU data structure for "RecentDocs"
561 lstrcpyA(ptr, doc_name);
562 ptr += (lstrlenA(buffer) + 1);
563 wlen= lstrlenA(new_lnk_name) + 1 + 12;
564 *((short int*)ptr) = wlen;
565 ptr += 2; /* step past the length */
566 *(ptr++) = 0x30; /* unknown reason */
567 *(ptr++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
570 lstrcpyA(ptr, new_lnk_name);
571 ptr += (lstrlenA(new_lnk_name) + 1);
576 /* Add the new entry into the MRU list
578 return AddMRUData(mruhandle, (LPCVOID)buffer, *len);
581 /*************************************************************************
582 * SHAddToRecentDocs [SHELL32.@]
585 * uFlags [IN] SHARD_PATH or SHARD_PIDL
586 * pv [IN] string or pidl, NULL clears the list
591 * FIXME: ?? MSDN shows this as a VOID
593 DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
595 /* If list is a string list lpfnCompare has the following prototype
596 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
597 * for binary lists the prototype is
598 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
599 * where cbData is the no. of bytes to compare.
600 * Need to check what return value means identical - 0?
606 CHAR doc_name[MAX_PATH];
607 CHAR link_dir[MAX_PATH];
608 CHAR new_lnk_filepath[MAX_PATH];
609 CHAR new_lnk_name[MAX_PATH];
612 HWND hwnd = 0; /* FIXME: get real window handle */
614 DWORD data[64], datalen, type;
617 * RecentDocs MRU data structure seems to be:
618 * +0h document file name w/ terminating 0h
619 * +nh short int w/ size of remaining
620 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
621 * +n+4h 10 bytes zeros - unknown
622 * +n+eh shortcut file name w/ terminating 0h
623 * +n+e+nh 3 zero bytes - unknown
626 /* See if we need to do anything.
629 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
630 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
631 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
634 if (ret == ERROR_SUCCESS) {
635 if (!( (type == REG_DWORD) ||
636 ((type == REG_BINARY) && (datalen == 4)) )) {
637 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
642 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
643 /* now test the actual policy value */
648 /* Open key to where the necessary info is
650 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
651 * and the close should be done during the _DETACH. The resulting
652 * key is stored in the DLL global data.
654 if (RegCreateKeyExA(HKEY_CURRENT_USER,
655 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
656 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
657 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
661 /* Get path to user's "Recent" directory
663 if(SUCCEEDED(SHGetMalloc(&ppM))) {
664 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
666 SHGetPathFromIDListA(pidl, link_dir);
667 IMalloc_Free(ppM, pidl);
672 ERR("serious issues 1\n");
674 IMalloc_Release(ppM);
679 ERR("serious issues 2\n");
681 TRACE("Users Recent dir %s\n", link_dir);
683 /* If no input, then go clear the lists */
685 /* clear user's Recent dir
688 /* FIXME: delete all files in "link_dir"
690 * while( more files ) {
691 * lstrcpyA(old_lnk_name, link_dir);
692 * PathAppendA(old_lnk_name, filenam);
693 * DeleteFileA(old_lnk_name);
696 FIXME("should delete all files in %s\\ \n", link_dir);
700 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
701 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
702 * and naturally it fails w/ rc=2. It should do it against
703 * HKEY_CURRENT_USER which is where it is stored, and where
704 * the MRU routines expect it!!!!
706 RegDeleteKeyA(HCUbasekey, "RecentDocs");
707 RegCloseKey(HCUbasekey);
711 /* Have data to add, the jobs to be done:
712 * 1. Add document to MRU list in registry "HKCU\Software\
713 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
714 * 2. Add shortcut to document in the user's Recent directory
716 * 3. Add shortcut to Start menu's Documents submenu.
719 /* Get the pure document name from the input
721 if (uFlags & SHARD_PIDL) {
722 SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
725 lstrcpyA(doc_name, (LPSTR) pv);
727 TRACE("full document name %s\n", doc_name);
728 PathStripPathA(doc_name);
729 TRACE("stripped document name %s\n", doc_name);
732 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
735 * doc_name - pure file-spec, no path
736 * link_dir - path to the user's Recent directory
737 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
739 * new_lnk_name- pure file-spec, no path for new .lnk file
741 * - path and file name of new .lnk file
743 CREATEMRULISTA mymru;
745 INT len, pos, bufused, err;
750 CHAR old_lnk_name[MAX_PATH];
753 mymru.cbSize = sizeof(CREATEMRULISTA);
754 mymru.nMaxItems = 15;
755 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
756 mymru.hKey = HCUbasekey;
757 mymru.lpszSubKey = "RecentDocs";
758 mymru.lpfnCompare = &SHADD_compare_mru;
759 mruhandle = CreateMRUListA(&mymru);
762 ERR("MRU processing failed, handle zero\n");
763 RegCloseKey(HCUbasekey);
766 len = lstrlenA(doc_name);
767 pos = FindMRUData(mruhandle, doc_name, len, 0);
769 /* Now get the MRU entry that will be replaced
770 * and delete the .lnk file for it
772 if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
773 buffer, 2048)) != -1) {
775 ptr += (lstrlenA(buffer) + 1);
776 slen = *((short int*)ptr);
777 ptr += 2; /* skip the length area */
778 if (bufused >= slen + (ptr-buffer)) {
779 /* buffer size looks good */
780 ptr += 12; /* get to string */
781 len = bufused - (ptr-buffer); /* get length of buf remaining */
782 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
783 /* appears to be good string */
784 lstrcpyA(old_lnk_name, link_dir);
785 PathAppendA(old_lnk_name, ptr);
786 if (!DeleteFileA(old_lnk_name)) {
787 if ((attr = GetFileAttributesA(old_lnk_name)) == -1) {
788 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
789 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
790 old_lnk_name, err, attr);
793 TRACE("old .lnk file %s did not exist\n",
798 ERR("Delete for %s failed, attr=%08lx\n",
803 TRACE("deleted old .lnk file %s\n", old_lnk_name);
809 /* Create usable .lnk file name for the "Recent" directory
811 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
812 lstrcpyA(new_lnk_filepath, link_dir);
813 PathAppendA(new_lnk_filepath, new_lnk_name);
815 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
816 while (GetFileAttributesA(new_lnk_filepath) != -1) {
818 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
819 lstrcpyA(new_lnk_filepath, link_dir);
820 PathAppendA(new_lnk_filepath, new_lnk_name);
822 SetErrorMode(olderrormode);
823 TRACE("new shortcut will be %s\n", new_lnk_filepath);
825 /* Now add the new MRU entry and data
827 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
829 FreeMRUList(mruhandle);
830 TRACE("Updated MRU list, new doc is position %d\n", pos);
833 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
836 * doc_name - pure file-spec, no path
838 * - path and file name of new .lnk file
839 * uFlags[in] - flags on call to SHAddToRecentDocs
840 * pv[in] - document path/pidl on call to SHAddToRecentDocs
842 IShellLinkA *psl = NULL;
843 IPersistFile *pPf = NULL;
846 WCHAR widelink[MAX_PATH];
850 hres = CoCreateInstance( &CLSID_ShellLink,
852 CLSCTX_INPROC_SERVER,
855 if(SUCCEEDED(hres)) {
857 hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
861 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
865 /* Set the document path or pidl */
866 if (uFlags & SHARD_PIDL) {
867 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
869 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
873 ERR("failed Set{IDList|Path} %08lx\n", hres);
877 lstrcpyA(desc, "Shortcut to ");
878 lstrcatA(desc, doc_name);
879 hres = IShellLinkA_SetDescription(psl, desc);
882 ERR("failed SetDescription %08lx\n", hres);
886 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
888 /* create the short cut */
889 hres = IPersistFile_Save(pPf, widelink, TRUE);
892 ERR("failed IPersistFile::Save %08lx\n", hres);
893 IPersistFile_Release(pPf);
894 IShellLinkA_Release(psl);
897 hres = IPersistFile_SaveCompleted(pPf, widelink);
898 IPersistFile_Release(pPf);
899 IShellLinkA_Release(psl);
900 TRACE("shortcut %s has been created, result=%08lx\n",
901 new_lnk_filepath, hres);
904 ERR("CoCreateInstance failed, hres=%08lx\n", hres);
912 RegCloseKey(HCUbasekey);
916 /*************************************************************************
917 * SHCreateShellFolderViewEx [SHELL32.174]
920 * see IShellFolder::CreateViewObject
922 HRESULT WINAPI SHCreateShellFolderViewEx(
923 LPCSHELLFOLDERVIEWINFO psvcbi, /* [in] shelltemplate struct */
924 LPSHELLVIEW* ppv) /* [out] IShellView pointer */
929 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
930 psvcbi->pshf, psvcbi->pidlFolder, psvcbi->lpfnCallback,
931 psvcbi->uViewMode, psvcbi->dwUser);
933 psf = IShellView_Constructor(psvcbi->pshf);
936 return E_OUTOFMEMORY;
938 IShellView_AddRef(psf);
939 hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
940 IShellView_Release(psf);
944 /*************************************************************************
945 * SHWinHelp [SHELL32.127]
948 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
949 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
952 /*************************************************************************
953 * SHRunControlPanel [SHELL32.161]
956 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
957 { FIXME("0x%08lx 0x%08lx stub\n",x,z);
961 static LPUNKNOWN SHELL32_IExplorerInterface=0;
962 /*************************************************************************
963 * SHSetInstanceExplorer [SHELL32.176]
968 HRESULT WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
969 { TRACE("%p\n", lpUnknown);
970 SHELL32_IExplorerInterface = lpUnknown;
971 return (HRESULT) lpUnknown;
973 /*************************************************************************
974 * SHGetInstanceExplorer [SHELL32.@]
977 * gets the interface pointer of the explorer and a reference
979 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
980 { TRACE("%p\n", lpUnknown);
982 *lpUnknown = SHELL32_IExplorerInterface;
984 if (!SHELL32_IExplorerInterface)
987 IUnknown_AddRef(SHELL32_IExplorerInterface);
990 /*************************************************************************
991 * SHFreeUnusedLibraries [SHELL32.123]
996 void WINAPI SHFreeUnusedLibraries (void)
1000 /*************************************************************************
1001 * DAD_AutoScroll [SHELL32.129]
1004 DWORD WINAPI DAD_AutoScroll(HWND hwnd, LPSCROLLSAMPLES samples, LPPOINT pt)
1006 FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1009 /*************************************************************************
1010 * DAD_DragEnter [SHELL32.130]
1013 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1015 FIXME("hwnd = %p\n",hwnd);
1018 /*************************************************************************
1019 * DAD_DragEnterEx [SHELL32.131]
1022 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1024 FIXME("hwnd = %p (%ld,%ld)\n",hwnd,p.x,p.y);
1027 /*************************************************************************
1028 * DAD_DragMove [SHELL32.134]
1031 BOOL WINAPI DAD_DragMove(POINT p)
1033 FIXME("(%ld,%ld)\n",p.x,p.y);
1036 /*************************************************************************
1037 * DAD_DragLeave [SHELL32.132]
1040 BOOL WINAPI DAD_DragLeave(VOID)
1045 /*************************************************************************
1046 * DAD_SetDragImage [SHELL32.136]
1051 BOOL WINAPI DAD_SetDragImage(
1052 HIMAGELIST himlTrack,
1055 FIXME("%p %p stub\n",himlTrack, lppt);
1058 /*************************************************************************
1059 * DAD_ShowDragImage [SHELL32.137]
1064 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1066 FIXME("0x%08x stub\n",bShow);
1069 /*************************************************************************
1070 * ReadCabinetState [SHELL32.651] NT 4.0
1073 HRESULT WINAPI ReadCabinetState(DWORD u, DWORD v)
1074 { FIXME("0x%04lx 0x%04lx stub\n",u,v);
1077 /*************************************************************************
1078 * WriteCabinetState [SHELL32.652] NT 4.0
1081 HRESULT WINAPI WriteCabinetState(DWORD u)
1082 { FIXME("0x%04lx stub\n",u);
1085 /*************************************************************************
1086 * FileIconInit [SHELL32.660]
1089 BOOL WINAPI FileIconInit(BOOL bFullInit)
1090 { FIXME("(%s)\n", bFullInit ? "true" : "false");
1093 /*************************************************************************
1094 * IsUserAdmin [SHELL32.680] NT 4.0
1097 HRESULT WINAPI IsUserAdmin(void)
1102 /*************************************************************************
1103 * SHAllocShared [SHELL32.520]
1106 * parameter1 is return value from HeapAlloc
1107 * parameter2 is equal to the size allocated with HeapAlloc
1108 * parameter3 is return value from GetCurrentProcessId
1110 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1111 * WM_USER+2 could be the undocumented CWM_SETPATH
1112 * the allocated memory contains a pidl
1114 HGLOBAL WINAPI SHAllocShared(LPVOID psrc, DWORD size, DWORD procID)
1118 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc,size,procID);
1119 hmem = GlobalAlloc(GMEM_FIXED, size);
1123 pmem = GlobalLock (hmem);
1128 memcpy (pmem, psrc, size);
1132 /*************************************************************************
1133 * SHLockShared [SHELL32.521]
1136 * parameter1 is return value from SHAllocShared
1137 * parameter2 is return value from GetCurrentProcessId
1138 * the receiver of (WM_USER+2) tries to lock the HANDLE (?)
1139 * the return value seems to be a memory address
1141 LPVOID WINAPI SHLockShared(HANDLE hmem, DWORD procID)
1142 { TRACE("handle=%p procID=0x%04lx\n",hmem,procID);
1143 return GlobalLock(hmem);
1145 /*************************************************************************
1146 * SHUnlockShared [SHELL32.522]
1149 * parameter1 is return value from SHLockShared
1151 BOOL WINAPI SHUnlockShared(LPVOID pv)
1154 return GlobalUnlock((HANDLE)pv);
1156 /*************************************************************************
1157 * SHFreeShared [SHELL32.523]
1160 * parameter1 is return value from SHAllocShared
1161 * parameter2 is return value from GetCurrentProcessId
1163 BOOL WINAPI SHFreeShared(
1167 TRACE("handle=%p 0x%04lx\n",hMem,pid);
1168 return (BOOL)GlobalFree(hMem);
1171 /*************************************************************************
1172 * SetAppStartingCursor [SHELL32.99]
1174 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1175 { FIXME("hwnd=%p 0x%04lx stub\n",u,v );
1178 /*************************************************************************
1179 * SHLoadOLE [SHELL32.151]
1182 HRESULT WINAPI SHLoadOLE(DWORD u)
1183 { FIXME("0x%04lx stub\n",u);
1186 /*************************************************************************
1187 * DriveType [SHELL32.64]
1190 HRESULT WINAPI DriveType(DWORD u)
1191 { FIXME("0x%04lx stub\n",u);
1194 /*************************************************************************
1195 * SHAbortInvokeCommand [SHELL32.198]
1198 HRESULT WINAPI SHAbortInvokeCommand(void)
1202 /*************************************************************************
1203 * SHOutOfMemoryMessageBox [SHELL32.126]
1206 int WINAPI SHOutOfMemoryMessageBox(
1211 FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1214 /*************************************************************************
1215 * SHFlushClipboard [SHELL32.121]
1218 HRESULT WINAPI SHFlushClipboard(void)
1223 /*************************************************************************
1224 * SHWaitForFileToOpen [SHELL32.97]
1227 BOOL WINAPI SHWaitForFileToOpen(
1232 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1236 /************************************************************************
1239 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1240 * second one could be a size (0x0c). The size is the same as the structure saved to
1241 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1242 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1244 HRESULT WINAPI shell32_654 (DWORD x, DWORD y)
1245 { FIXME("0x%08lx 0x%08lx stub\n",x,y);
1249 /************************************************************************
1250 * RLBuildListOfPaths [SHELL32.146]
1255 DWORD WINAPI RLBuildListOfPaths (void)
1259 /************************************************************************
1260 * SHValidateUNC [SHELL32.173]
1263 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1265 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1269 /************************************************************************
1270 * DoEnvironmentSubstA [SHELL32.@]
1273 HRESULT WINAPI DoEnvironmentSubstA(LPSTR x, LPSTR y)
1275 FIXME("(%s, %s) stub\n", debugstr_a(x), debugstr_a(y));
1279 /************************************************************************
1280 * DoEnvironmentSubstW [SHELL32.@]
1283 HRESULT WINAPI DoEnvironmentSubstW(LPWSTR x, LPWSTR y)
1285 FIXME("(%s, %s): stub\n", debugstr_w(x), debugstr_w(y));
1289 /************************************************************************
1290 * DoEnvironmentSubst [SHELL32.53]
1293 HRESULT WINAPI DoEnvironmentSubstAW(LPVOID x, LPVOID y)
1295 if (SHELL_OsIsUnicode())
1296 return DoEnvironmentSubstW(x, y);
1297 return DoEnvironmentSubstA(x, y);
1300 /*************************************************************************
1303 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1304 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1308 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1313 /*************************************************************************
1316 DWORD WINAPI SHELL32_714(LPVOID x)
1318 FIXME("(%s)stub\n", debugstr_w(x));
1322 /*************************************************************************
1323 * SHAddFromPropSheetExtArray [SHELL32.167]
1325 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1327 FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1331 /*************************************************************************
1332 * SHCreatePropSheetExtArray [SHELL32.168]
1334 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1336 FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1340 /*************************************************************************
1341 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1343 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1345 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1349 /*************************************************************************
1350 * SHDestroyPropSheetExtArray [SHELL32.169]
1352 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1354 FIXME("(%08lx)stub\n", a);
1358 /*************************************************************************
1359 * CIDLData_CreateFromIDArray [SHELL32.83]
1361 * Create IDataObject from PIDLs??
1363 HRESULT WINAPI CIDLData_CreateFromIDArray(
1364 LPCITEMIDLIST pidlFolder,
1366 LPCITEMIDLIST *lppidlFiles,
1367 LPDATAOBJECT *ppdataObject)
1370 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1372 TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1376 for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1378 *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1379 lppidlFiles, cpidlFiles);
1380 if (*ppdataObject) return S_OK;
1381 return E_OUTOFMEMORY;
1384 /*************************************************************************
1385 * SHCreateStdEnumFmtEtc [SHELL32.74]
1390 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1392 const FORMATETC *lpFormats,
1393 LPENUMFORMATETC *ppenumFormatetc)
1395 IEnumFORMATETC *pef;
1397 TRACE("cf=%ld fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1399 pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1401 return E_OUTOFMEMORY;
1403 IEnumFORMATETC_AddRef(pef);
1404 hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1405 IEnumFORMATETC_Release(pef);