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"
34 #include "shell32_main.h"
35 #include "undocshell.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 WINE_DECLARE_DEBUG_CHANNEL(pidl);
43 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
44 /* !!! it is in both here and comctl32undoc.c !!! */
45 typedef struct tagCREATEMRULIST
47 DWORD cbSize; /* size of struct */
48 DWORD nMaxItems; /* max no. of items in list */
49 DWORD dwFlags; /* see below */
50 HKEY hKey; /* root reg. key under which list is saved */
51 LPCSTR lpszSubKey; /* reg. subkey */
52 PROC lpfnCompare; /* item compare proc */
53 } CREATEMRULISTA, *LPCREATEMRULISTA;
56 #define MRUF_STRING_LIST 0 /* list will contain strings */
57 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
58 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
60 extern HANDLE WINAPI CreateMRUListA(LPCREATEMRULISTA lpcml);
61 extern DWORD WINAPI FreeMRUList(HANDLE hMRUList);
62 extern INT WINAPI AddMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData);
63 extern INT WINAPI FindMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
64 extern INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
66 /*************************************************************************
67 * ParseFieldA [internal]
69 * copies a field from a ',' delimited string
71 * first field is nField = 1
73 DWORD WINAPI ParseFieldA(
79 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src),nField,dst,len);
81 if (!src || !src[0] || !dst || !len)
84 /* skip n fields delimited by ',' */
87 if (*src=='\0') return FALSE;
88 if (*(src++)==',') nField--;
91 /* copy part till the next ',' to dst */
92 while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
94 /* finalize the string */
100 /*************************************************************************
101 * ParseFieldW [internal]
103 * copies a field from a ',' delimited string
105 * first field is nField = 1
107 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
109 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n", debugstr_w(src), nField, dst, len);
111 if (!src || !src[0] || !dst || !len)
114 /* skip n fields delimited by ',' */
117 if (*src == 0x0) return FALSE;
118 if (*src++ == ',') nField--;
121 /* copy part till the next ',' to dst */
122 while ( *src != 0x0 && *src != ',' && (len--)>0 ) *(dst++) = *(src++);
124 /* finalize the string */
130 /*************************************************************************
131 * ParseField [SHELL32.58]
133 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
135 if (SHELL_OsIsUnicode())
136 return ParseFieldW(src, nField, dst, len);
137 return ParseFieldA(src, nField, dst, len);
140 /*************************************************************************
141 * GetFileNameFromBrowse [SHELL32.63]
144 BOOL WINAPI GetFileNameFromBrowse(
148 LPCSTR lpstrInitialDir,
154 FARPROC pGetOpenFileNameA;
158 TRACE("%p, %s, %ld, %s, %s, %s, %s)\n",
159 hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
160 lpstrFilter, lpstrTitle);
162 hmodule = LoadLibraryA("comdlg32.dll");
163 if(!hmodule) return FALSE;
164 pGetOpenFileNameA = GetProcAddress(hmodule, "GetOpenFileNameA");
165 if(!pGetOpenFileNameA)
167 FreeLibrary(hmodule);
171 memset(&ofn, 0, sizeof(ofn));
173 ofn.lStructSize = sizeof(ofn);
174 ofn.hwndOwner = hwndOwner;
175 ofn.lpstrFilter = lpstrFilter;
176 ofn.lpstrFile = lpstrFile;
177 ofn.nMaxFile = nMaxFile;
178 ofn.lpstrInitialDir = lpstrInitialDir;
179 ofn.lpstrTitle = lpstrTitle;
180 ofn.lpstrDefExt = lpstrDefExt;
181 ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
182 ret = pGetOpenFileNameA(&ofn);
184 FreeLibrary(hmodule);
188 /*************************************************************************
189 * SHGetSetSettings [SHELL32.68]
191 VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
195 FIXME("%p 0x%08lx TRUE\n", lpss, dwMask);
199 SHGetSettings((LPSHELLFLAGSTATE)lpss,dwMask);
203 /*************************************************************************
204 * SHGetSettings [SHELL32.@]
207 * the registry path are for win98 (tested)
208 * and possibly are the same in nt40
211 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
215 DWORD dwDataSize = sizeof (DWORD);
217 TRACE("(%p 0x%08lx)\n",lpsfs,dwMask);
219 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
220 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
223 if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
224 lpsfs->fShowExtensions = ((dwData == 0) ? 0 : 1);
226 if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
227 lpsfs->fShowInfoTip = ((dwData == 0) ? 0 : 1);
229 if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
230 lpsfs->fDontPrettyPath = ((dwData == 0) ? 0 : 1);
232 if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
233 lpsfs->fHideIcons = ((dwData == 0) ? 0 : 1);
235 if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
236 lpsfs->fMapNetDrvBtn = ((dwData == 0) ? 0 : 1);
238 if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
239 lpsfs->fShowAttribCol = ((dwData == 0) ? 0 : 1);
241 if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
243 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
244 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
246 else if (dwData == 1)
247 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 1;
248 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
250 else if (dwData == 2)
251 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
252 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 1;
257 TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
260 /*************************************************************************
261 * SHShellFolderView_Message [SHELL32.73]
263 * Send a message to an explorer cabinet window.
266 * hwndCabinet [I] The window containing the shellview to communicate with
267 * dwMessage [I] The SFVM message to send
268 * dwParam [I] Message parameter
274 * Message SFVM_REARRANGE = 1
276 * This message gets sent when a column gets clicked to instruct the
277 * shell view to re-sort the item list. dwParam identifies the column
280 int WINAPI SHShellFolderView_Message(
285 FIXME("%p %08lx %08lx stub\n",hwndCabinet, dwMessage, dwParam);
289 /*************************************************************************
290 * RegisterShellHook [SHELL32.181]
292 * Register a shell hook.
295 * hwnd [I] Window handle
296 * dwType [I] Type of hook.
299 * Exported by ordinal
301 BOOL WINAPI RegisterShellHook(
305 FIXME("(%p,0x%08lx):stub.\n",hWnd, dwType);
309 /*************************************************************************
310 * ShellMessageBoxW [SHELL32.182]
312 * See ShellMessageBoxA.
314 int WINAPIV ShellMessageBoxW(
322 WCHAR szText[100],szTitle[100];
323 LPCWSTR pszText = szText, pszTitle = szTitle, pszTemp;
327 va_start(args, uType);
328 /* wvsprintfA(buf,fmt, args); */
330 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
331 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
333 if (!HIWORD(lpCaption))
334 LoadStringW(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
336 pszTitle = lpCaption;
339 LoadStringW(hInstance, (DWORD)lpText, szText, sizeof(szText)/sizeof(szText[0]));
343 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
344 pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
348 ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
349 LocalFree((HLOCAL)pszTemp);
353 /*************************************************************************
354 * ShellMessageBoxA [SHELL32.183]
356 * Format and output an error message.
359 * hInstance [I] Instance handle of message creator
360 * hWnd [I] Window handle of message creator
361 * lpText [I] Resource Id of title or LPSTR
362 * lpCaption [I] Resource Id of title or LPSTR
363 * uType [I] Type of error message
366 * A return value from MessageBoxA().
369 * Exported by ordinal
371 int WINAPIV ShellMessageBoxA(
379 char szText[100],szTitle[100];
380 LPCSTR pszText = szText, pszTitle = szTitle, pszTemp;
384 va_start(args, uType);
385 /* wvsprintfA(buf,fmt, args); */
387 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
388 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
390 if (!HIWORD(lpCaption))
391 LoadStringA(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle));
393 pszTitle = lpCaption;
396 LoadStringA(hInstance, (DWORD)lpText, szText, sizeof(szText));
400 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
401 pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
405 ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
406 LocalFree((HLOCAL)pszTemp);
410 /*************************************************************************
411 * SHRegisterDragDrop [SHELL32.86]
414 * exported by ordinal
416 HRESULT WINAPI SHRegisterDragDrop(
418 LPDROPTARGET pDropTarget)
420 FIXME("(%p,%p):stub.\n", hWnd, pDropTarget);
421 if (GetShellOle()) return pRegisterDragDrop(hWnd, pDropTarget);
425 /*************************************************************************
426 * SHRevokeDragDrop [SHELL32.87]
429 * exported by ordinal
431 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
433 FIXME("(%p):stub.\n",hWnd);
434 if (GetShellOle()) return pRevokeDragDrop(hWnd);
438 /*************************************************************************
439 * SHDoDragDrop [SHELL32.88]
442 * exported by ordinal
444 HRESULT WINAPI SHDoDragDrop(
446 LPDATAOBJECT lpDataObject,
447 LPDROPSOURCE lpDropSource,
451 FIXME("(%p %p %p 0x%08lx %p):stub.\n",
452 hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
453 if (GetShellOle()) return pDoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
457 /*************************************************************************
458 * ArrangeWindows [SHELL32.184]
461 WORD WINAPI ArrangeWindows(
468 FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
469 hwndParent, dwReserved, lpRect, cKids, lpKids);
473 /*************************************************************************
474 * SignalFileOpen [SHELL32.103]
477 * exported by ordinal
480 SignalFileOpen (DWORD dwParam1)
482 FIXME("(0x%08lx):stub.\n", dwParam1);
487 /*************************************************************************
488 * SHADD_get_policy - helper function for SHAddToRecentDocs
491 * policy [IN] policy name (null termed string) to find
492 * type [OUT] ptr to DWORD to receive type
493 * buffer [OUT] ptr to area to hold data retrieved
494 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
498 * result of the SHQueryValueEx call
500 static INT SHADD_get_policy(LPSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
505 /* Get the key for the policies location in the registry
507 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
508 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
509 0, KEY_READ, &Policy_basekey)) {
511 if (RegOpenKeyExA(HKEY_CURRENT_USER,
512 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
513 0, KEY_READ, &Policy_basekey)) {
514 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
517 return ERROR_FILE_NOT_FOUND;
521 /* Retrieve the data if it exists
523 ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
524 RegCloseKey(Policy_basekey);
529 /*************************************************************************
530 * SHADD_compare_mru - helper function for SHAddToRecentDocs
533 * data1 [IN] data being looked for
534 * data2 [IN] data in MRU
535 * cbdata [IN] length from FindMRUData call (not used)
538 * position within MRU list that data was added.
540 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
542 return lstrcmpiA(data1, data2);
545 /*************************************************************************
546 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
549 * mruhandle [IN] handle for created MRU list
550 * doc_name [IN] null termed pure doc name
551 * new_lnk_name [IN] null termed path and file name for .lnk file
552 * buffer [IN/OUT] 2048 byte area to consturct MRU data
553 * len [OUT] ptr to int to receive space used in buffer
556 * position within MRU list that data was added.
558 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
559 LPSTR buffer, INT *len)
565 * RecentDocs MRU data structure seems to be:
566 * +0h document file name w/ terminating 0h
567 * +nh short int w/ size of remaining
568 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
569 * +n+4h 10 bytes zeros - unknown
570 * +n+eh shortcut file name w/ terminating 0h
571 * +n+e+nh 3 zero bytes - unknown
574 /* Create the MRU data structure for "RecentDocs"
577 lstrcpyA(ptr, doc_name);
578 ptr += (lstrlenA(buffer) + 1);
579 wlen= lstrlenA(new_lnk_name) + 1 + 12;
580 *((short int*)ptr) = wlen;
581 ptr += 2; /* step past the length */
582 *(ptr++) = 0x30; /* unknown reason */
583 *(ptr++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
586 lstrcpyA(ptr, new_lnk_name);
587 ptr += (lstrlenA(new_lnk_name) + 1);
592 /* Add the new entry into the MRU list
594 return AddMRUData(mruhandle, (LPCVOID)buffer, *len);
597 /*************************************************************************
598 * SHAddToRecentDocs [SHELL32.@]
601 * uFlags [IN] SHARD_PATH or SHARD_PIDL
602 * pv [IN] string or pidl, NULL clears the list
607 * FIXME: ?? MSDN shows this as a VOID
609 DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
611 /* If list is a string list lpfnCompare has the following prototype
612 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
613 * for binary lists the prototype is
614 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
615 * where cbData is the no. of bytes to compare.
616 * Need to check what return value means identical - 0?
622 CHAR doc_name[MAX_PATH];
623 CHAR link_dir[MAX_PATH];
624 CHAR new_lnk_filepath[MAX_PATH];
625 CHAR new_lnk_name[MAX_PATH];
628 HWND hwnd = 0; /* FIXME: get real window handle */
630 DWORD data[64], datalen, type;
633 * RecentDocs MRU data structure seems to be:
634 * +0h document file name w/ terminating 0h
635 * +nh short int w/ size of remaining
636 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
637 * +n+4h 10 bytes zeros - unknown
638 * +n+eh shortcut file name w/ terminating 0h
639 * +n+e+nh 3 zero bytes - unknown
642 /* See if we need to do anything.
645 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
646 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
647 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
650 if (ret == ERROR_SUCCESS) {
651 if (!( (type == REG_DWORD) ||
652 ((type == REG_BINARY) && (datalen == 4)) )) {
653 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
658 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
659 /* now test the actual policy value */
664 /* Open key to where the necessary info is
666 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
667 * and the close should be done during the _DETACH. The resulting
668 * key is stored in the DLL global data.
670 if (RegCreateKeyExA(HKEY_CURRENT_USER,
671 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
672 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
673 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
677 /* Get path to user's "Recent" directory
679 if(SUCCEEDED(SHGetMalloc(&ppM))) {
680 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
682 SHGetPathFromIDListA(pidl, link_dir);
683 IMalloc_Free(ppM, pidl);
688 ERR("serious issues 1\n");
690 IMalloc_Release(ppM);
695 ERR("serious issues 2\n");
697 TRACE("Users Recent dir %s\n", link_dir);
699 /* If no input, then go clear the lists */
701 /* clear user's Recent dir
704 /* FIXME: delete all files in "link_dir"
706 * while( more files ) {
707 * lstrcpyA(old_lnk_name, link_dir);
708 * PathAppendA(old_lnk_name, filenam);
709 * DeleteFileA(old_lnk_name);
712 FIXME("should delete all files in %s\\ \n", link_dir);
716 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
717 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
718 * and naturally it fails w/ rc=2. It should do it against
719 * HKEY_CURRENT_USER which is where it is stored, and where
720 * the MRU routines expect it!!!!
722 RegDeleteKeyA(HCUbasekey, "RecentDocs");
723 RegCloseKey(HCUbasekey);
727 /* Have data to add, the jobs to be done:
728 * 1. Add document to MRU list in registry "HKCU\Software\
729 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
730 * 2. Add shortcut to document in the user's Recent directory
732 * 3. Add shortcut to Start menu's Documents submenu.
735 /* Get the pure document name from the input
737 if (uFlags & SHARD_PIDL) {
738 SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
741 lstrcpyA(doc_name, (LPSTR) pv);
743 TRACE("full document name %s\n", doc_name);
744 PathStripPathA(doc_name);
745 TRACE("stripped document name %s\n", doc_name);
748 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
751 * doc_name - pure file-spec, no path
752 * link_dir - path to the user's Recent directory
753 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
755 * new_lnk_name- pure file-spec, no path for new .lnk file
757 * - path and file name of new .lnk file
759 CREATEMRULISTA mymru;
761 INT len, pos, bufused, err;
766 CHAR old_lnk_name[MAX_PATH];
769 mymru.cbSize = sizeof(CREATEMRULISTA);
770 mymru.nMaxItems = 15;
771 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
772 mymru.hKey = HCUbasekey;
773 mymru.lpszSubKey = "RecentDocs";
774 mymru.lpfnCompare = &SHADD_compare_mru;
775 mruhandle = CreateMRUListA(&mymru);
778 ERR("MRU processing failed, handle zero\n");
779 RegCloseKey(HCUbasekey);
782 len = lstrlenA(doc_name);
783 pos = FindMRUData(mruhandle, doc_name, len, 0);
785 /* Now get the MRU entry that will be replaced
786 * and delete the .lnk file for it
788 if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
789 buffer, 2048)) != -1) {
791 ptr += (lstrlenA(buffer) + 1);
792 slen = *((short int*)ptr);
793 ptr += 2; /* skip the length area */
794 if (bufused >= slen + (ptr-buffer)) {
795 /* buffer size looks good */
796 ptr += 12; /* get to string */
797 len = bufused - (ptr-buffer); /* get length of buf remaining */
798 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
799 /* appears to be good string */
800 lstrcpyA(old_lnk_name, link_dir);
801 PathAppendA(old_lnk_name, ptr);
802 if (!DeleteFileA(old_lnk_name)) {
803 if ((attr = GetFileAttributesA(old_lnk_name)) == -1) {
804 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
805 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
806 old_lnk_name, err, attr);
809 TRACE("old .lnk file %s did not exist\n",
814 ERR("Delete for %s failed, attr=%08lx\n",
819 TRACE("deleted old .lnk file %s\n", old_lnk_name);
825 /* Create usable .lnk file name for the "Recent" directory
827 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
828 lstrcpyA(new_lnk_filepath, link_dir);
829 PathAppendA(new_lnk_filepath, new_lnk_name);
831 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
832 while (GetFileAttributesA(new_lnk_filepath) != -1) {
834 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
835 lstrcpyA(new_lnk_filepath, link_dir);
836 PathAppendA(new_lnk_filepath, new_lnk_name);
838 SetErrorMode(olderrormode);
839 TRACE("new shortcut will be %s\n", new_lnk_filepath);
841 /* Now add the new MRU entry and data
843 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
845 FreeMRUList(mruhandle);
846 TRACE("Updated MRU list, new doc is position %d\n", pos);
849 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
852 * doc_name - pure file-spec, no path
854 * - path and file name of new .lnk file
855 * uFlags[in] - flags on call to SHAddToRecentDocs
856 * pv[in] - document path/pidl on call to SHAddToRecentDocs
858 IShellLinkA *psl = NULL;
859 IPersistFile *pPf = NULL;
862 WCHAR widelink[MAX_PATH];
866 hres = CoCreateInstance( &CLSID_ShellLink,
868 CLSCTX_INPROC_SERVER,
871 if(SUCCEEDED(hres)) {
873 hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
877 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
881 /* Set the document path or pidl */
882 if (uFlags & SHARD_PIDL) {
883 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
885 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
889 ERR("failed Set{IDList|Path} %08lx\n", hres);
893 lstrcpyA(desc, "Shortcut to ");
894 lstrcatA(desc, doc_name);
895 hres = IShellLinkA_SetDescription(psl, desc);
898 ERR("failed SetDescription %08lx\n", hres);
902 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
904 /* create the short cut */
905 hres = IPersistFile_Save(pPf, widelink, TRUE);
908 ERR("failed IPersistFile::Save %08lx\n", hres);
909 IPersistFile_Release(pPf);
910 IShellLinkA_Release(psl);
913 hres = IPersistFile_SaveCompleted(pPf, widelink);
914 IPersistFile_Release(pPf);
915 IShellLinkA_Release(psl);
916 TRACE("shortcut %s has been created, result=%08lx\n",
917 new_lnk_filepath, hres);
920 ERR("CoCreateInstance failed, hres=%08lx\n", hres);
928 RegCloseKey(HCUbasekey);
932 /*************************************************************************
933 * SHCreateShellFolderViewEx [SHELL32.174]
936 * see IShellFolder::CreateViewObject
938 HRESULT WINAPI SHCreateShellFolderViewEx(
939 LPCSHELLFOLDERVIEWINFO psvcbi, /* [in] shelltemplate struct */
940 LPSHELLVIEW* ppv) /* [out] IShellView pointer */
945 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
946 psvcbi->pshf, psvcbi->pidlFolder, psvcbi->lpfnCallback,
947 psvcbi->uViewMode, psvcbi->dwUser);
949 psf = IShellView_Constructor(psvcbi->pshf);
952 return E_OUTOFMEMORY;
954 IShellView_AddRef(psf);
955 hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
956 IShellView_Release(psf);
960 /*************************************************************************
961 * SHWinHelp [SHELL32.127]
964 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
965 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
968 /*************************************************************************
969 * SHRunControlPanel [SHELL32.161]
972 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
973 { FIXME("0x%08lx 0x%08lx stub\n",x,z);
977 static LPUNKNOWN SHELL32_IExplorerInterface=0;
978 /*************************************************************************
979 * SHSetInstanceExplorer [SHELL32.176]
984 HRESULT WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
985 { TRACE("%p\n", lpUnknown);
986 SHELL32_IExplorerInterface = lpUnknown;
987 return (HRESULT) lpUnknown;
989 /*************************************************************************
990 * SHGetInstanceExplorer [SHELL32.@]
993 * gets the interface pointer of the explorer and a reference
995 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
996 { TRACE("%p\n", lpUnknown);
998 *lpUnknown = SHELL32_IExplorerInterface;
1000 if (!SHELL32_IExplorerInterface)
1003 IUnknown_AddRef(SHELL32_IExplorerInterface);
1006 /*************************************************************************
1007 * SHFreeUnusedLibraries [SHELL32.123]
1012 void WINAPI SHFreeUnusedLibraries (void)
1016 /*************************************************************************
1017 * DAD_AutoScroll [SHELL32.129]
1020 DWORD WINAPI DAD_AutoScroll(HWND hwnd, LPSCROLLSAMPLES samples, LPPOINT pt)
1022 FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1025 /*************************************************************************
1026 * DAD_DragEnter [SHELL32.130]
1029 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1031 FIXME("hwnd = %p\n",hwnd);
1034 /*************************************************************************
1035 * DAD_DragEnterEx [SHELL32.131]
1038 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1040 FIXME("hwnd = %p (%ld,%ld)\n",hwnd,p.x,p.y);
1043 /*************************************************************************
1044 * DAD_DragMove [SHELL32.134]
1047 BOOL WINAPI DAD_DragMove(POINT p)
1049 FIXME("(%ld,%ld)\n",p.x,p.y);
1052 /*************************************************************************
1053 * DAD_DragLeave [SHELL32.132]
1056 BOOL WINAPI DAD_DragLeave(VOID)
1061 /*************************************************************************
1062 * DAD_SetDragImage [SHELL32.136]
1067 BOOL WINAPI DAD_SetDragImage(
1068 HIMAGELIST himlTrack,
1071 FIXME("%p %p stub\n",himlTrack, lppt);
1074 /*************************************************************************
1075 * DAD_ShowDragImage [SHELL32.137]
1080 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1082 FIXME("0x%08x stub\n",bShow);
1085 /*************************************************************************
1086 * ReadCabinetState [SHELL32.651] NT 4.0
1089 HRESULT WINAPI ReadCabinetState(DWORD u, DWORD v)
1090 { FIXME("0x%04lx 0x%04lx stub\n",u,v);
1093 /*************************************************************************
1094 * WriteCabinetState [SHELL32.652] NT 4.0
1097 HRESULT WINAPI WriteCabinetState(DWORD u)
1098 { FIXME("0x%04lx stub\n",u);
1101 /*************************************************************************
1102 * FileIconInit [SHELL32.660]
1105 BOOL WINAPI FileIconInit(BOOL bFullInit)
1106 { FIXME("(%s)\n", bFullInit ? "true" : "false");
1109 /*************************************************************************
1110 * IsUserAdmin [SHELL32.680] NT 4.0
1113 HRESULT WINAPI IsUserAdmin(void)
1118 /*************************************************************************
1119 * SHAllocShared [SHELL32.520]
1122 * parameter1 is return value from HeapAlloc
1123 * parameter2 is equal to the size allocated with HeapAlloc
1124 * parameter3 is return value from GetCurrentProcessId
1126 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1127 * WM_USER+2 could be the undocumented CWM_SETPATH
1128 * the allocated memory contains a pidl
1130 HGLOBAL WINAPI SHAllocShared(LPVOID psrc, DWORD size, DWORD procID)
1134 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc,size,procID);
1135 hmem = GlobalAlloc(GMEM_FIXED, size);
1139 pmem = GlobalLock (hmem);
1144 memcpy (pmem, psrc, size);
1148 /*************************************************************************
1149 * SHLockShared [SHELL32.521]
1152 * parameter1 is return value from SHAllocShared
1153 * parameter2 is return value from GetCurrentProcessId
1154 * the receiver of (WM_USER+2) tries to lock the HANDLE (?)
1155 * the return value seems to be a memory address
1157 LPVOID WINAPI SHLockShared(HANDLE hmem, DWORD procID)
1158 { TRACE("handle=%p procID=0x%04lx\n",hmem,procID);
1159 return GlobalLock(hmem);
1161 /*************************************************************************
1162 * SHUnlockShared [SHELL32.522]
1165 * parameter1 is return value from SHLockShared
1167 BOOL WINAPI SHUnlockShared(LPVOID pv)
1170 return GlobalUnlock((HANDLE)pv);
1172 /*************************************************************************
1173 * SHFreeShared [SHELL32.523]
1176 * parameter1 is return value from SHAllocShared
1177 * parameter2 is return value from GetCurrentProcessId
1179 BOOL WINAPI SHFreeShared(
1183 TRACE("handle=%p 0x%04lx\n",hMem,pid);
1184 return (BOOL)GlobalFree(hMem);
1187 /*************************************************************************
1188 * SetAppStartingCursor [SHELL32.99]
1190 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1191 { FIXME("hwnd=%p 0x%04lx stub\n",u,v );
1194 /*************************************************************************
1195 * SHLoadOLE [SHELL32.151]
1198 HRESULT WINAPI SHLoadOLE(DWORD u)
1199 { FIXME("0x%04lx stub\n",u);
1202 /*************************************************************************
1203 * DriveType [SHELL32.64]
1206 HRESULT WINAPI DriveType(DWORD u)
1207 { FIXME("0x%04lx stub\n",u);
1210 /*************************************************************************
1211 * SHAbortInvokeCommand [SHELL32.198]
1214 HRESULT WINAPI SHAbortInvokeCommand(void)
1218 /*************************************************************************
1219 * SHOutOfMemoryMessageBox [SHELL32.126]
1222 int WINAPI SHOutOfMemoryMessageBox(
1227 FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1230 /*************************************************************************
1231 * SHFlushClipboard [SHELL32.121]
1234 HRESULT WINAPI SHFlushClipboard(void)
1239 /*************************************************************************
1240 * SHWaitForFileToOpen [SHELL32.97]
1243 BOOL WINAPI SHWaitForFileToOpen(
1248 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1252 /************************************************************************
1255 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1256 * second one could be a size (0x0c). The size is the same as the structure saved to
1257 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1258 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1260 HRESULT WINAPI shell32_654 (DWORD x, DWORD y)
1261 { FIXME("0x%08lx 0x%08lx stub\n",x,y);
1265 /************************************************************************
1266 * RLBuildListOfPaths [SHELL32.146]
1271 DWORD WINAPI RLBuildListOfPaths (void)
1275 /************************************************************************
1276 * SHValidateUNC [SHELL32.173]
1279 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1281 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1285 /************************************************************************
1286 * DoEnvironmentSubstA [SHELL32.@]
1289 HRESULT WINAPI DoEnvironmentSubstA(LPSTR x, LPSTR y)
1291 FIXME("(%s, %s) stub\n", debugstr_a(x), debugstr_a(y));
1295 /************************************************************************
1296 * DoEnvironmentSubstW [SHELL32.@]
1299 HRESULT WINAPI DoEnvironmentSubstW(LPWSTR x, LPWSTR y)
1301 FIXME("(%s, %s): stub\n", debugstr_w(x), debugstr_w(y));
1305 /************************************************************************
1306 * DoEnvironmentSubst [SHELL32.53]
1309 HRESULT WINAPI DoEnvironmentSubstAW(LPVOID x, LPVOID y)
1311 if (SHELL_OsIsUnicode())
1312 return DoEnvironmentSubstW(x, y);
1313 return DoEnvironmentSubstA(x, y);
1316 /*************************************************************************
1319 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1320 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1324 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1329 /*************************************************************************
1332 DWORD WINAPI SHELL32_714(LPVOID x)
1334 FIXME("(%s)stub\n", debugstr_w(x));
1338 /*************************************************************************
1339 * SHAddFromPropSheetExtArray [SHELL32.167]
1341 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1343 FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1347 /*************************************************************************
1348 * SHCreatePropSheetExtArray [SHELL32.168]
1350 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1352 FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1356 /*************************************************************************
1357 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1359 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1361 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1365 /*************************************************************************
1366 * SHDestroyPropSheetExtArray [SHELL32.169]
1368 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1370 FIXME("(%08lx)stub\n", a);
1374 /*************************************************************************
1375 * CIDLData_CreateFromIDArray [SHELL32.83]
1377 * Create IDataObject from PIDLs??
1379 HRESULT WINAPI CIDLData_CreateFromIDArray(
1380 LPCITEMIDLIST pidlFolder,
1382 LPCITEMIDLIST *lppidlFiles,
1383 LPDATAOBJECT *ppdataObject)
1386 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1388 TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1392 for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1394 *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1395 lppidlFiles, cpidlFiles);
1396 if (*ppdataObject) return S_OK;
1397 return E_OUTOFMEMORY;
1400 /*************************************************************************
1401 * SHCreateStdEnumFmtEtc [SHELL32.74]
1406 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1408 const FORMATETC *lpFormats,
1409 LPENUMFORMATETC *ppenumFormatetc)
1411 IEnumFORMATETC *pef;
1413 TRACE("cf=%ld fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1415 pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1417 return E_OUTOFMEMORY;
1419 IEnumFORMATETC_AddRef(pef);
1420 hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1421 IEnumFORMATETC_Release(pef);