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
31 #include "wine/debug.h"
40 #include "shell32_main.h"
41 #include "undocshell.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(shell);
47 WINE_DECLARE_DEBUG_CHANNEL(pidl);
49 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
50 /* !!! it is in both here and comctl32undoc.c !!! */
51 typedef struct tagCREATEMRULIST
53 DWORD cbSize; /* size of struct */
54 DWORD nMaxItems; /* max no. of items in list */
55 DWORD dwFlags; /* see below */
56 HKEY hKey; /* root reg. key under which list is saved */
57 LPCSTR lpszSubKey; /* reg. subkey */
58 PROC lpfnCompare; /* item compare proc */
59 } CREATEMRULISTA, *LPCREATEMRULISTA;
62 #define MRUF_STRING_LIST 0 /* list will contain strings */
63 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
64 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
66 extern HANDLE WINAPI CreateMRUListA(LPCREATEMRULISTA lpcml);
67 extern DWORD WINAPI FreeMRUList(HANDLE hMRUList);
68 extern INT WINAPI AddMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData);
69 extern INT WINAPI FindMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
70 extern INT WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
72 /*************************************************************************
73 * ParseFieldA [internal]
75 * copies a field from a ',' delimited string
77 * first field is nField = 1
79 DWORD WINAPI ParseFieldA(
85 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src),nField,dst,len);
87 if (!src || !src[0] || !dst || !len)
90 /* skip n fields delimited by ',' */
93 if (*src=='\0') return FALSE;
94 if (*(src++)==',') nField--;
97 /* copy part till the next ',' to dst */
98 while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
100 /* finalize the string */
106 /*************************************************************************
107 * ParseFieldW [internal]
109 * copies a field from a ',' delimited string
111 * first field is nField = 1
113 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
115 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n", debugstr_w(src), nField, dst, len);
117 if (!src || !src[0] || !dst || !len)
120 /* skip n fields delimited by ',' */
123 if (*src == 0x0) return FALSE;
124 if (*src++ == ',') nField--;
127 /* copy part till the next ',' to dst */
128 while ( *src != 0x0 && *src != ',' && (len--)>0 ) *(dst++) = *(src++);
130 /* finalize the string */
136 /*************************************************************************
137 * ParseField [SHELL32.58]
139 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
141 if (SHELL_OsIsUnicode())
142 return ParseFieldW(src, nField, dst, len);
143 return ParseFieldA(src, nField, dst, len);
146 /*************************************************************************
147 * GetFileNameFromBrowse [SHELL32.63]
150 BOOL WINAPI GetFileNameFromBrowse(
154 LPCSTR lpstrInitialDir,
160 FARPROC pGetOpenFileNameA;
164 TRACE("%p, %s, %ld, %s, %s, %s, %s)\n",
165 hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
166 lpstrFilter, lpstrTitle);
168 hmodule = LoadLibraryA("comdlg32.dll");
169 if(!hmodule) return FALSE;
170 pGetOpenFileNameA = GetProcAddress(hmodule, "GetOpenFileNameA");
171 if(!pGetOpenFileNameA)
173 FreeLibrary(hmodule);
177 memset(&ofn, 0, sizeof(ofn));
179 ofn.lStructSize = sizeof(ofn);
180 ofn.hwndOwner = hwndOwner;
181 ofn.lpstrFilter = lpstrFilter;
182 ofn.lpstrFile = lpstrFile;
183 ofn.nMaxFile = nMaxFile;
184 ofn.lpstrInitialDir = lpstrInitialDir;
185 ofn.lpstrTitle = lpstrTitle;
186 ofn.lpstrDefExt = lpstrDefExt;
187 ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
188 ret = pGetOpenFileNameA(&ofn);
190 FreeLibrary(hmodule);
194 /*************************************************************************
195 * SHGetSetSettings [SHELL32.68]
197 VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
201 FIXME("%p 0x%08lx TRUE\n", lpss, dwMask);
205 SHGetSettings((LPSHELLFLAGSTATE)lpss,dwMask);
209 /*************************************************************************
210 * SHGetSettings [SHELL32.@]
213 * the registry path are for win98 (tested)
214 * and possibly are the same in nt40
217 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
221 DWORD dwDataSize = sizeof (DWORD);
223 TRACE("(%p 0x%08lx)\n",lpsfs,dwMask);
225 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
226 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
229 if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
230 lpsfs->fShowExtensions = ((dwData == 0) ? 0 : 1);
232 if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
233 lpsfs->fShowInfoTip = ((dwData == 0) ? 0 : 1);
235 if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
236 lpsfs->fDontPrettyPath = ((dwData == 0) ? 0 : 1);
238 if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
239 lpsfs->fHideIcons = ((dwData == 0) ? 0 : 1);
241 if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
242 lpsfs->fMapNetDrvBtn = ((dwData == 0) ? 0 : 1);
244 if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
245 lpsfs->fShowAttribCol = ((dwData == 0) ? 0 : 1);
247 if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
249 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
250 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
252 else if (dwData == 1)
253 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 1;
254 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
256 else if (dwData == 2)
257 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
258 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 1;
263 TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
266 /*************************************************************************
267 * SHShellFolderView_Message [SHELL32.73]
269 * Send a message to an explorer cabinet window.
272 * hwndCabinet [I] The window containing the shellview to communicate with
273 * dwMessage [I] The SFVM message to send
274 * dwParam [I] Message parameter
280 * Message SFVM_REARRANGE = 1
282 * This message gets sent when a column gets clicked to instruct the
283 * shell view to re-sort the item list. dwParam identifies the column
286 int WINAPI SHShellFolderView_Message(
291 FIXME("%p %08lx %08lx stub\n",hwndCabinet, dwMessage, dwParam);
295 /*************************************************************************
296 * RegisterShellHook [SHELL32.181]
298 * Register a shell hook.
301 * hwnd [I] Window handle
302 * dwType [I] Type of hook.
305 * Exported by ordinal
307 BOOL WINAPI RegisterShellHook(
311 FIXME("(%p,0x%08lx):stub.\n",hWnd, dwType);
315 /*************************************************************************
316 * ShellMessageBoxW [SHELL32.182]
318 * See ShellMessageBoxA.
320 int WINAPIV ShellMessageBoxW(
328 WCHAR szText[100],szTitle[100];
329 LPCWSTR pszText = szText, pszTitle = szTitle, pszTemp;
333 va_start(args, uType);
334 /* wvsprintfA(buf,fmt, args); */
336 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
337 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
339 if (!HIWORD(lpCaption))
340 LoadStringW(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
342 pszTitle = lpCaption;
345 LoadStringW(hInstance, (DWORD)lpText, szText, sizeof(szText)/sizeof(szText[0]));
349 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
350 pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
354 ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
355 LocalFree((HLOCAL)pszTemp);
359 /*************************************************************************
360 * ShellMessageBoxA [SHELL32.183]
362 * Format and output an error message.
365 * hInstance [I] Instance handle of message creator
366 * hWnd [I] Window handle of message creator
367 * lpText [I] Resource Id of title or LPSTR
368 * lpCaption [I] Resource Id of title or LPSTR
369 * uType [I] Type of error message
372 * A return value from MessageBoxA().
375 * Exported by ordinal
377 int WINAPIV ShellMessageBoxA(
385 char szText[100],szTitle[100];
386 LPCSTR pszText = szText, pszTitle = szTitle, pszTemp;
390 va_start(args, uType);
391 /* wvsprintfA(buf,fmt, args); */
393 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
394 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
396 if (!HIWORD(lpCaption))
397 LoadStringA(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle));
399 pszTitle = lpCaption;
402 LoadStringA(hInstance, (DWORD)lpText, szText, sizeof(szText));
406 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
407 pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
411 ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
412 LocalFree((HLOCAL)pszTemp);
416 /*************************************************************************
417 * SHRegisterDragDrop [SHELL32.86]
420 * exported by ordinal
422 HRESULT WINAPI SHRegisterDragDrop(
424 LPDROPTARGET pDropTarget)
426 FIXME("(%p,%p):stub.\n", hWnd, pDropTarget);
427 return RegisterDragDrop(hWnd, pDropTarget);
430 /*************************************************************************
431 * SHRevokeDragDrop [SHELL32.87]
434 * exported by ordinal
436 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
438 FIXME("(%p):stub.\n",hWnd);
439 return RevokeDragDrop(hWnd);
442 /*************************************************************************
443 * SHDoDragDrop [SHELL32.88]
446 * exported by ordinal
448 HRESULT WINAPI SHDoDragDrop(
450 LPDATAOBJECT lpDataObject,
451 LPDROPSOURCE lpDropSource,
455 FIXME("(%p %p %p 0x%08lx %p):stub.\n",
456 hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
457 return DoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
460 /*************************************************************************
461 * ArrangeWindows [SHELL32.184]
464 WORD WINAPI ArrangeWindows(
471 FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
472 hwndParent, dwReserved, lpRect, cKids, lpKids);
476 /*************************************************************************
477 * SignalFileOpen [SHELL32.103]
480 * exported by ordinal
483 SignalFileOpen (DWORD dwParam1)
485 FIXME("(0x%08lx):stub.\n", dwParam1);
490 /*************************************************************************
491 * SHADD_get_policy - helper function for SHAddToRecentDocs
494 * policy [IN] policy name (null termed string) to find
495 * type [OUT] ptr to DWORD to receive type
496 * buffer [OUT] ptr to area to hold data retrieved
497 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
501 * result of the SHQueryValueEx call
503 static INT SHADD_get_policy(LPSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
508 /* Get the key for the policies location in the registry
510 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
511 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
512 0, KEY_READ, &Policy_basekey)) {
514 if (RegOpenKeyExA(HKEY_CURRENT_USER,
515 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
516 0, KEY_READ, &Policy_basekey)) {
517 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
520 return ERROR_FILE_NOT_FOUND;
524 /* Retrieve the data if it exists
526 ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
527 RegCloseKey(Policy_basekey);
532 /*************************************************************************
533 * SHADD_compare_mru - helper function for SHAddToRecentDocs
536 * data1 [IN] data being looked for
537 * data2 [IN] data in MRU
538 * cbdata [IN] length from FindMRUData call (not used)
541 * position within MRU list that data was added.
543 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
545 return lstrcmpiA(data1, data2);
548 /*************************************************************************
549 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
552 * mruhandle [IN] handle for created MRU list
553 * doc_name [IN] null termed pure doc name
554 * new_lnk_name [IN] null termed path and file name for .lnk file
555 * buffer [IN/OUT] 2048 byte area to consturct MRU data
556 * len [OUT] ptr to int to receive space used in buffer
559 * position within MRU list that data was added.
561 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
562 LPSTR buffer, INT *len)
568 * RecentDocs MRU data structure seems to be:
569 * +0h document file name w/ terminating 0h
570 * +nh short int w/ size of remaining
571 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
572 * +n+4h 10 bytes zeros - unknown
573 * +n+eh shortcut file name w/ terminating 0h
574 * +n+e+nh 3 zero bytes - unknown
577 /* Create the MRU data structure for "RecentDocs"
580 lstrcpyA(ptr, doc_name);
581 ptr += (lstrlenA(buffer) + 1);
582 wlen= lstrlenA(new_lnk_name) + 1 + 12;
583 *((short int*)ptr) = wlen;
584 ptr += 2; /* step past the length */
585 *(ptr++) = 0x30; /* unknown reason */
586 *(ptr++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
589 lstrcpyA(ptr, new_lnk_name);
590 ptr += (lstrlenA(new_lnk_name) + 1);
595 /* Add the new entry into the MRU list
597 return AddMRUData(mruhandle, (LPCVOID)buffer, *len);
600 /*************************************************************************
601 * SHAddToRecentDocs [SHELL32.@]
604 * uFlags [IN] SHARD_PATH or SHARD_PIDL
605 * pv [IN] string or pidl, NULL clears the list
610 void WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
612 /* If list is a string list lpfnCompare has the following prototype
613 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
614 * for binary lists the prototype is
615 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
616 * where cbData is the no. of bytes to compare.
617 * Need to check what return value means identical - 0?
623 CHAR doc_name[MAX_PATH];
624 CHAR link_dir[MAX_PATH];
625 CHAR new_lnk_filepath[MAX_PATH];
626 CHAR new_lnk_name[MAX_PATH];
629 HWND hwnd = 0; /* FIXME: get real window handle */
631 DWORD data[64], datalen, type;
634 * RecentDocs MRU data structure seems to be:
635 * +0h document file name w/ terminating 0h
636 * +nh short int w/ size of remaining
637 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
638 * +n+4h 10 bytes zeros - unknown
639 * +n+eh shortcut file name w/ terminating 0h
640 * +n+e+nh 3 zero bytes - unknown
643 /* See if we need to do anything.
646 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
647 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
648 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
651 if (ret == ERROR_SUCCESS) {
652 if (!( (type == REG_DWORD) ||
653 ((type == REG_BINARY) && (datalen == 4)) )) {
654 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
659 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
660 /* now test the actual policy value */
665 /* Open key to where the necessary info is
667 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
668 * and the close should be done during the _DETACH. The resulting
669 * key is stored in the DLL global data.
671 if (RegCreateKeyExA(HKEY_CURRENT_USER,
672 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
673 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
674 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
678 /* Get path to user's "Recent" directory
680 if(SUCCEEDED(SHGetMalloc(&ppM))) {
681 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
683 SHGetPathFromIDListA(pidl, link_dir);
684 IMalloc_Free(ppM, pidl);
689 ERR("serious issues 1\n");
691 IMalloc_Release(ppM);
696 ERR("serious issues 2\n");
698 TRACE("Users Recent dir %s\n", link_dir);
700 /* If no input, then go clear the lists */
702 /* clear user's Recent dir
705 /* FIXME: delete all files in "link_dir"
707 * while( more files ) {
708 * lstrcpyA(old_lnk_name, link_dir);
709 * PathAppendA(old_lnk_name, filenam);
710 * DeleteFileA(old_lnk_name);
713 FIXME("should delete all files in %s\\ \n", link_dir);
717 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
718 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
719 * and naturally it fails w/ rc=2. It should do it against
720 * HKEY_CURRENT_USER which is where it is stored, and where
721 * the MRU routines expect it!!!!
723 RegDeleteKeyA(HCUbasekey, "RecentDocs");
724 RegCloseKey(HCUbasekey);
728 /* Have data to add, the jobs to be done:
729 * 1. Add document to MRU list in registry "HKCU\Software\
730 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
731 * 2. Add shortcut to document in the user's Recent directory
733 * 3. Add shortcut to Start menu's Documents submenu.
736 /* Get the pure document name from the input
738 if (uFlags & SHARD_PIDL) {
739 SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
742 lstrcpyA(doc_name, (LPSTR) pv);
744 TRACE("full document name %s\n", doc_name);
745 PathStripPathA(doc_name);
746 TRACE("stripped document name %s\n", doc_name);
749 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
752 * doc_name - pure file-spec, no path
753 * link_dir - path to the user's Recent directory
754 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
756 * new_lnk_name- pure file-spec, no path for new .lnk file
758 * - path and file name of new .lnk file
760 CREATEMRULISTA mymru;
762 INT len, pos, bufused, err;
767 CHAR old_lnk_name[MAX_PATH];
770 mymru.cbSize = sizeof(CREATEMRULISTA);
771 mymru.nMaxItems = 15;
772 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
773 mymru.hKey = HCUbasekey;
774 mymru.lpszSubKey = "RecentDocs";
775 mymru.lpfnCompare = &SHADD_compare_mru;
776 mruhandle = CreateMRUListA(&mymru);
779 ERR("MRU processing failed, handle zero\n");
780 RegCloseKey(HCUbasekey);
783 len = lstrlenA(doc_name);
784 pos = FindMRUData(mruhandle, doc_name, len, 0);
786 /* Now get the MRU entry that will be replaced
787 * and delete the .lnk file for it
789 if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
790 buffer, 2048)) != -1) {
792 ptr += (lstrlenA(buffer) + 1);
793 slen = *((short int*)ptr);
794 ptr += 2; /* skip the length area */
795 if (bufused >= slen + (ptr-buffer)) {
796 /* buffer size looks good */
797 ptr += 12; /* get to string */
798 len = bufused - (ptr-buffer); /* get length of buf remaining */
799 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
800 /* appears to be good string */
801 lstrcpyA(old_lnk_name, link_dir);
802 PathAppendA(old_lnk_name, ptr);
803 if (!DeleteFileA(old_lnk_name)) {
804 if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) {
805 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
806 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
807 old_lnk_name, err, attr);
810 TRACE("old .lnk file %s did not exist\n",
815 ERR("Delete for %s failed, attr=%08lx\n",
820 TRACE("deleted old .lnk file %s\n", old_lnk_name);
826 /* Create usable .lnk file name for the "Recent" directory
828 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
829 lstrcpyA(new_lnk_filepath, link_dir);
830 PathAppendA(new_lnk_filepath, new_lnk_name);
832 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
833 while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
835 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
836 lstrcpyA(new_lnk_filepath, link_dir);
837 PathAppendA(new_lnk_filepath, new_lnk_name);
839 SetErrorMode(olderrormode);
840 TRACE("new shortcut will be %s\n", new_lnk_filepath);
842 /* Now add the new MRU entry and data
844 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
846 FreeMRUList(mruhandle);
847 TRACE("Updated MRU list, new doc is position %d\n", pos);
850 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
853 * doc_name - pure file-spec, no path
855 * - path and file name of new .lnk file
856 * uFlags[in] - flags on call to SHAddToRecentDocs
857 * pv[in] - document path/pidl on call to SHAddToRecentDocs
859 IShellLinkA *psl = NULL;
860 IPersistFile *pPf = NULL;
863 WCHAR widelink[MAX_PATH];
867 hres = CoCreateInstance( &CLSID_ShellLink,
869 CLSCTX_INPROC_SERVER,
872 if(SUCCEEDED(hres)) {
874 hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
878 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
882 /* Set the document path or pidl */
883 if (uFlags & SHARD_PIDL) {
884 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
886 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
890 ERR("failed Set{IDList|Path} %08lx\n", hres);
894 lstrcpyA(desc, "Shortcut to ");
895 lstrcatA(desc, doc_name);
896 hres = IShellLinkA_SetDescription(psl, desc);
899 ERR("failed SetDescription %08lx\n", hres);
903 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
905 /* create the short cut */
906 hres = IPersistFile_Save(pPf, widelink, TRUE);
909 ERR("failed IPersistFile::Save %08lx\n", hres);
910 IPersistFile_Release(pPf);
911 IShellLinkA_Release(psl);
914 hres = IPersistFile_SaveCompleted(pPf, widelink);
915 IPersistFile_Release(pPf);
916 IShellLinkA_Release(psl);
917 TRACE("shortcut %s has been created, result=%08lx\n",
918 new_lnk_filepath, hres);
921 ERR("CoCreateInstance failed, hres=%08lx\n", hres);
929 RegCloseKey(HCUbasekey);
933 /*************************************************************************
934 * SHCreateShellFolderViewEx [SHELL32.174]
937 * see IShellFolder::CreateViewObject
939 HRESULT WINAPI SHCreateShellFolderViewEx(
940 LPCSHELLFOLDERVIEWINFO psvcbi, /* [in] shelltemplate struct */
941 LPSHELLVIEW* ppv) /* [out] IShellView pointer */
946 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
947 psvcbi->pshf, psvcbi->pidlFolder, psvcbi->lpfnCallback,
948 psvcbi->uViewMode, psvcbi->dwUser);
950 psf = IShellView_Constructor(psvcbi->pshf);
953 return E_OUTOFMEMORY;
955 IShellView_AddRef(psf);
956 hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
957 IShellView_Release(psf);
961 /*************************************************************************
962 * SHWinHelp [SHELL32.127]
965 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
966 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
969 /*************************************************************************
970 * SHRunControlPanel [SHELL32.161]
973 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
974 { FIXME("0x%08lx 0x%08lx stub\n",x,z);
978 static LPUNKNOWN SHELL32_IExplorerInterface=0;
979 /*************************************************************************
980 * SHSetInstanceExplorer [SHELL32.176]
985 HRESULT WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
986 { TRACE("%p\n", lpUnknown);
987 SHELL32_IExplorerInterface = lpUnknown;
988 return (HRESULT) lpUnknown;
990 /*************************************************************************
991 * SHGetInstanceExplorer [SHELL32.@]
994 * gets the interface pointer of the explorer and a reference
996 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
997 { TRACE("%p\n", lpUnknown);
999 *lpUnknown = SHELL32_IExplorerInterface;
1001 if (!SHELL32_IExplorerInterface)
1004 IUnknown_AddRef(SHELL32_IExplorerInterface);
1007 /*************************************************************************
1008 * SHFreeUnusedLibraries [SHELL32.123]
1013 void WINAPI SHFreeUnusedLibraries (void)
1017 /*************************************************************************
1018 * DAD_AutoScroll [SHELL32.129]
1021 BOOL WINAPI DAD_AutoScroll(HWND hwnd, AUTO_SCROLL_DATA *samples, LPPOINT pt)
1023 FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1026 /*************************************************************************
1027 * DAD_DragEnter [SHELL32.130]
1030 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1032 FIXME("hwnd = %p\n",hwnd);
1035 /*************************************************************************
1036 * DAD_DragEnterEx [SHELL32.131]
1039 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1041 FIXME("hwnd = %p (%ld,%ld)\n",hwnd,p.x,p.y);
1044 /*************************************************************************
1045 * DAD_DragMove [SHELL32.134]
1048 BOOL WINAPI DAD_DragMove(POINT p)
1050 FIXME("(%ld,%ld)\n",p.x,p.y);
1053 /*************************************************************************
1054 * DAD_DragLeave [SHELL32.132]
1057 BOOL WINAPI DAD_DragLeave(VOID)
1062 /*************************************************************************
1063 * DAD_SetDragImage [SHELL32.136]
1068 BOOL WINAPI DAD_SetDragImage(
1069 HIMAGELIST himlTrack,
1072 FIXME("%p %p stub\n",himlTrack, lppt);
1075 /*************************************************************************
1076 * DAD_ShowDragImage [SHELL32.137]
1081 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1083 FIXME("0x%08x stub\n",bShow);
1087 static const WCHAR szwCabLocation[] = {
1088 'S','o','f','t','w','a','r','e','\\',
1089 'M','i','c','r','o','s','o','f','t','\\',
1090 'W','i','n','d','o','w','s','\\',
1091 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1092 'E','x','p','l','o','r','e','r','\\',
1093 'C','a','b','i','n','e','t','S','t','a','t','e',0
1096 static const WCHAR szwSettings[] = { 'S','e','t','t','i','n','g','s',0 };
1098 /*************************************************************************
1099 * ReadCabinetState [SHELL32.651] NT 4.0
1102 BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
1107 TRACE("%p %d \n",cs,length);
1109 if( (cs == NULL) || (length < (int)sizeof(*cs)) )
1112 r = RegOpenKeyW( HKEY_CURRENT_USER, szwCabLocation, &hkey );
1113 if( r == ERROR_SUCCESS )
1116 r = RegQueryValueExW( hkey, szwSettings,
1117 NULL, &type, (LPBYTE)cs, (LPDWORD)&length );
1118 RegCloseKey( hkey );
1122 /* if we can't read from the registry, create default values */
1123 if ( (r != ERROR_SUCCESS) || (cs->cLength < sizeof(*cs)) ||
1124 (cs->cLength != length) )
1126 ERR("Initializing shell cabinet settings\n");
1127 memset(cs, 0, sizeof(*cs));
1128 cs->cLength = sizeof(*cs);
1130 cs->fFullPathTitle = FALSE;
1131 cs->fSaveLocalView = TRUE;
1132 cs->fNotShell = FALSE;
1133 cs->fSimpleDefault = TRUE;
1134 cs->fDontShowDescBar = FALSE;
1135 cs->fNewWindowMode = FALSE;
1136 cs->fShowCompColor = FALSE;
1137 cs->fDontPrettyNames = FALSE;
1138 cs->fAdminsCreateCommonGroups = TRUE;
1139 cs->fMenuEnumFilter = 96;
1145 /*************************************************************************
1146 * WriteCabinetState [SHELL32.652] NT 4.0
1149 BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
1159 r = RegCreateKeyExW( HKEY_CURRENT_USER, szwCabLocation, 0,
1160 NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
1161 if( r == ERROR_SUCCESS )
1163 r = RegSetValueExW( hkey, szwSettings, 0,
1164 REG_BINARY, (LPBYTE) cs, cs->cLength);
1166 RegCloseKey( hkey );
1169 return (r==ERROR_SUCCESS);
1172 /*************************************************************************
1173 * FileIconInit [SHELL32.660]
1176 BOOL WINAPI FileIconInit(BOOL bFullInit)
1177 { FIXME("(%s)\n", bFullInit ? "true" : "false");
1180 /*************************************************************************
1181 * IsUserAdmin [SHELL32.680] NT 4.0
1184 HRESULT WINAPI IsUserAdmin(void)
1189 /*************************************************************************
1190 * SHAllocShared [SHELL32.520]
1193 * parameter1 is return value from HeapAlloc
1194 * parameter2 is equal to the size allocated with HeapAlloc
1195 * parameter3 is return value from GetCurrentProcessId
1197 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1198 * WM_USER+2 could be the undocumented CWM_SETPATH
1199 * the allocated memory contains a pidl
1201 HGLOBAL WINAPI SHAllocShared(LPVOID psrc, DWORD size, DWORD procID)
1205 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc,size,procID);
1206 hmem = GlobalAlloc(GMEM_FIXED, size);
1210 pmem = GlobalLock (hmem);
1215 memcpy (pmem, psrc, size);
1219 /*************************************************************************
1220 * SHLockShared [SHELL32.521]
1223 * parameter1 is return value from SHAllocShared
1224 * parameter2 is return value from GetCurrentProcessId
1225 * the receiver of (WM_USER+2) tries to lock the HANDLE (?)
1226 * the return value seems to be a memory address
1228 LPVOID WINAPI SHLockShared(HANDLE hmem, DWORD procID)
1229 { TRACE("handle=%p procID=0x%04lx\n",hmem,procID);
1230 return GlobalLock(hmem);
1232 /*************************************************************************
1233 * SHUnlockShared [SHELL32.522]
1236 * parameter1 is return value from SHLockShared
1238 BOOL WINAPI SHUnlockShared(LPVOID pv)
1241 return GlobalUnlock((HANDLE)pv);
1243 /*************************************************************************
1244 * SHFreeShared [SHELL32.523]
1247 * parameter1 is return value from SHAllocShared
1248 * parameter2 is return value from GetCurrentProcessId
1250 BOOL WINAPI SHFreeShared(
1254 TRACE("handle=%p 0x%04lx\n",hMem,pid);
1255 return (BOOL)GlobalFree(hMem);
1258 /*************************************************************************
1259 * SetAppStartingCursor [SHELL32.99]
1261 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1262 { FIXME("hwnd=%p 0x%04lx stub\n",u,v );
1265 /*************************************************************************
1266 * SHLoadOLE [SHELL32.151]
1269 HRESULT WINAPI SHLoadOLE(DWORD u)
1270 { FIXME("0x%04lx stub\n",u);
1273 /*************************************************************************
1274 * DriveType [SHELL32.64]
1277 HRESULT WINAPI DriveType(DWORD u)
1278 { FIXME("0x%04lx stub\n",u);
1281 /*************************************************************************
1282 * SHAbortInvokeCommand [SHELL32.198]
1285 HRESULT WINAPI SHAbortInvokeCommand(void)
1289 /*************************************************************************
1290 * SHOutOfMemoryMessageBox [SHELL32.126]
1293 int WINAPI SHOutOfMemoryMessageBox(
1298 FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1301 /*************************************************************************
1302 * SHFlushClipboard [SHELL32.121]
1305 HRESULT WINAPI SHFlushClipboard(void)
1310 /*************************************************************************
1311 * SHWaitForFileToOpen [SHELL32.97]
1314 BOOL WINAPI SHWaitForFileToOpen(
1319 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1323 /************************************************************************
1326 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1327 * second one could be a size (0x0c). The size is the same as the structure saved to
1328 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1329 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1331 HRESULT WINAPI shell32_654 (CABINETSTATE *cs, int length)
1333 TRACE("%p %d\n",cs,length);
1334 return ReadCabinetState(cs,length);
1337 /************************************************************************
1338 * RLBuildListOfPaths [SHELL32.146]
1343 DWORD WINAPI RLBuildListOfPaths (void)
1347 /************************************************************************
1348 * SHValidateUNC [SHELL32.173]
1351 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1353 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1357 /************************************************************************
1358 * DoEnvironmentSubstA [SHELL32.@]
1361 HRESULT WINAPI DoEnvironmentSubstA(LPSTR x, LPSTR y)
1363 FIXME("(%s, %s) stub\n", debugstr_a(x), debugstr_a(y));
1367 /************************************************************************
1368 * DoEnvironmentSubstW [SHELL32.@]
1371 HRESULT WINAPI DoEnvironmentSubstW(LPWSTR x, LPWSTR y)
1373 FIXME("(%s, %s): stub\n", debugstr_w(x), debugstr_w(y));
1377 /************************************************************************
1378 * DoEnvironmentSubst [SHELL32.53]
1381 HRESULT WINAPI DoEnvironmentSubstAW(LPVOID x, LPVOID y)
1383 if (SHELL_OsIsUnicode())
1384 return DoEnvironmentSubstW(x, y);
1385 return DoEnvironmentSubstA(x, y);
1388 /*************************************************************************
1391 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1392 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1396 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1401 /*************************************************************************
1404 DWORD WINAPI SHELL32_714(LPVOID x)
1406 FIXME("(%s)stub\n", debugstr_w(x));
1410 /*************************************************************************
1411 * SHAddFromPropSheetExtArray [SHELL32.167]
1413 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1415 FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1419 /*************************************************************************
1420 * SHCreatePropSheetExtArray [SHELL32.168]
1422 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1424 FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1428 /*************************************************************************
1429 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1431 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1433 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1437 /*************************************************************************
1438 * SHDestroyPropSheetExtArray [SHELL32.169]
1440 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1442 FIXME("(%08lx)stub\n", a);
1446 /*************************************************************************
1447 * CIDLData_CreateFromIDArray [SHELL32.83]
1449 * Create IDataObject from PIDLs??
1451 HRESULT WINAPI CIDLData_CreateFromIDArray(
1452 LPCITEMIDLIST pidlFolder,
1454 LPCITEMIDLIST *lppidlFiles,
1455 LPDATAOBJECT *ppdataObject)
1458 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1460 TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1464 for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1466 *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1467 lppidlFiles, cpidlFiles);
1468 if (*ppdataObject) return S_OK;
1469 return E_OUTOFMEMORY;
1472 /*************************************************************************
1473 * SHCreateStdEnumFmtEtc [SHELL32.74]
1478 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1480 const FORMATETC *lpFormats,
1481 LPENUMFORMATETC *ppenumFormatetc)
1483 IEnumFORMATETC *pef;
1485 TRACE("cf=%ld fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1487 pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1489 return E_OUTOFMEMORY;
1491 IEnumFORMATETC_AddRef(pef);
1492 hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1493 IEnumFORMATETC_Release(pef);
1499 /*************************************************************************
1500 * SHELL32_256 (SHELL32.256)
1502 HRESULT WINAPI SHELL32_256(LPDWORD lpdw0, LPDWORD lpdw1)
1506 FIXME("stub %p 0x%08lx %p\n", lpdw0, lpdw0 ? *lpdw0 : 0, lpdw1);
1508 if (!lpdw0 || *lpdw0 != 0x10)
1512 LPVOID lpdata = 0;/*LocalAlloc(GMEM_ZEROINIT, 0x4E4);*/
1515 ret = E_OUTOFMEMORY;
1518 /* Initialize and return unknown lpdata structure */
1525 /*************************************************************************
1526 * SHFindFiles (SHELL32.90)
1528 BOOL WINAPI SHFindFiles( LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlSaveFile )
1530 FIXME("%p %p\n", pidlFolder, pidlSaveFile );