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 if (GetShellOle()) return pRegisterDragDrop(hWnd, pDropTarget);
431 /*************************************************************************
432 * SHRevokeDragDrop [SHELL32.87]
435 * exported by ordinal
437 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
439 FIXME("(%p):stub.\n",hWnd);
440 if (GetShellOle()) return pRevokeDragDrop(hWnd);
444 /*************************************************************************
445 * SHDoDragDrop [SHELL32.88]
448 * exported by ordinal
450 HRESULT WINAPI SHDoDragDrop(
452 LPDATAOBJECT lpDataObject,
453 LPDROPSOURCE lpDropSource,
457 FIXME("(%p %p %p 0x%08lx %p):stub.\n",
458 hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
459 if (GetShellOle()) return pDoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
463 /*************************************************************************
464 * ArrangeWindows [SHELL32.184]
467 WORD WINAPI ArrangeWindows(
474 FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
475 hwndParent, dwReserved, lpRect, cKids, lpKids);
479 /*************************************************************************
480 * SignalFileOpen [SHELL32.103]
483 * exported by ordinal
486 SignalFileOpen (DWORD dwParam1)
488 FIXME("(0x%08lx):stub.\n", dwParam1);
493 /*************************************************************************
494 * SHADD_get_policy - helper function for SHAddToRecentDocs
497 * policy [IN] policy name (null termed string) to find
498 * type [OUT] ptr to DWORD to receive type
499 * buffer [OUT] ptr to area to hold data retrieved
500 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
504 * result of the SHQueryValueEx call
506 static INT SHADD_get_policy(LPSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
511 /* Get the key for the policies location in the registry
513 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
514 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
515 0, KEY_READ, &Policy_basekey)) {
517 if (RegOpenKeyExA(HKEY_CURRENT_USER,
518 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
519 0, KEY_READ, &Policy_basekey)) {
520 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
523 return ERROR_FILE_NOT_FOUND;
527 /* Retrieve the data if it exists
529 ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
530 RegCloseKey(Policy_basekey);
535 /*************************************************************************
536 * SHADD_compare_mru - helper function for SHAddToRecentDocs
539 * data1 [IN] data being looked for
540 * data2 [IN] data in MRU
541 * cbdata [IN] length from FindMRUData call (not used)
544 * position within MRU list that data was added.
546 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
548 return lstrcmpiA(data1, data2);
551 /*************************************************************************
552 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
555 * mruhandle [IN] handle for created MRU list
556 * doc_name [IN] null termed pure doc name
557 * new_lnk_name [IN] null termed path and file name for .lnk file
558 * buffer [IN/OUT] 2048 byte area to consturct MRU data
559 * len [OUT] ptr to int to receive space used in buffer
562 * position within MRU list that data was added.
564 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
565 LPSTR buffer, INT *len)
571 * RecentDocs MRU data structure seems to be:
572 * +0h document file name w/ terminating 0h
573 * +nh short int w/ size of remaining
574 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
575 * +n+4h 10 bytes zeros - unknown
576 * +n+eh shortcut file name w/ terminating 0h
577 * +n+e+nh 3 zero bytes - unknown
580 /* Create the MRU data structure for "RecentDocs"
583 lstrcpyA(ptr, doc_name);
584 ptr += (lstrlenA(buffer) + 1);
585 wlen= lstrlenA(new_lnk_name) + 1 + 12;
586 *((short int*)ptr) = wlen;
587 ptr += 2; /* step past the length */
588 *(ptr++) = 0x30; /* unknown reason */
589 *(ptr++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
592 lstrcpyA(ptr, new_lnk_name);
593 ptr += (lstrlenA(new_lnk_name) + 1);
598 /* Add the new entry into the MRU list
600 return AddMRUData(mruhandle, (LPCVOID)buffer, *len);
603 /*************************************************************************
604 * SHAddToRecentDocs [SHELL32.@]
607 * uFlags [IN] SHARD_PATH or SHARD_PIDL
608 * pv [IN] string or pidl, NULL clears the list
613 * FIXME: ?? MSDN shows this as a VOID
615 DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
617 /* If list is a string list lpfnCompare has the following prototype
618 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
619 * for binary lists the prototype is
620 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
621 * where cbData is the no. of bytes to compare.
622 * Need to check what return value means identical - 0?
628 CHAR doc_name[MAX_PATH];
629 CHAR link_dir[MAX_PATH];
630 CHAR new_lnk_filepath[MAX_PATH];
631 CHAR new_lnk_name[MAX_PATH];
634 HWND hwnd = 0; /* FIXME: get real window handle */
636 DWORD data[64], datalen, type;
639 * RecentDocs MRU data structure seems to be:
640 * +0h document file name w/ terminating 0h
641 * +nh short int w/ size of remaining
642 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
643 * +n+4h 10 bytes zeros - unknown
644 * +n+eh shortcut file name w/ terminating 0h
645 * +n+e+nh 3 zero bytes - unknown
648 /* See if we need to do anything.
651 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
652 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
653 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
656 if (ret == ERROR_SUCCESS) {
657 if (!( (type == REG_DWORD) ||
658 ((type == REG_BINARY) && (datalen == 4)) )) {
659 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
664 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
665 /* now test the actual policy value */
670 /* Open key to where the necessary info is
672 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
673 * and the close should be done during the _DETACH. The resulting
674 * key is stored in the DLL global data.
676 if (RegCreateKeyExA(HKEY_CURRENT_USER,
677 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
678 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
679 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
683 /* Get path to user's "Recent" directory
685 if(SUCCEEDED(SHGetMalloc(&ppM))) {
686 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
688 SHGetPathFromIDListA(pidl, link_dir);
689 IMalloc_Free(ppM, pidl);
694 ERR("serious issues 1\n");
696 IMalloc_Release(ppM);
701 ERR("serious issues 2\n");
703 TRACE("Users Recent dir %s\n", link_dir);
705 /* If no input, then go clear the lists */
707 /* clear user's Recent dir
710 /* FIXME: delete all files in "link_dir"
712 * while( more files ) {
713 * lstrcpyA(old_lnk_name, link_dir);
714 * PathAppendA(old_lnk_name, filenam);
715 * DeleteFileA(old_lnk_name);
718 FIXME("should delete all files in %s\\ \n", link_dir);
722 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
723 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
724 * and naturally it fails w/ rc=2. It should do it against
725 * HKEY_CURRENT_USER which is where it is stored, and where
726 * the MRU routines expect it!!!!
728 RegDeleteKeyA(HCUbasekey, "RecentDocs");
729 RegCloseKey(HCUbasekey);
733 /* Have data to add, the jobs to be done:
734 * 1. Add document to MRU list in registry "HKCU\Software\
735 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
736 * 2. Add shortcut to document in the user's Recent directory
738 * 3. Add shortcut to Start menu's Documents submenu.
741 /* Get the pure document name from the input
743 if (uFlags & SHARD_PIDL) {
744 SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
747 lstrcpyA(doc_name, (LPSTR) pv);
749 TRACE("full document name %s\n", doc_name);
750 PathStripPathA(doc_name);
751 TRACE("stripped document name %s\n", doc_name);
754 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
757 * doc_name - pure file-spec, no path
758 * link_dir - path to the user's Recent directory
759 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
761 * new_lnk_name- pure file-spec, no path for new .lnk file
763 * - path and file name of new .lnk file
765 CREATEMRULISTA mymru;
767 INT len, pos, bufused, err;
772 CHAR old_lnk_name[MAX_PATH];
775 mymru.cbSize = sizeof(CREATEMRULISTA);
776 mymru.nMaxItems = 15;
777 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
778 mymru.hKey = HCUbasekey;
779 mymru.lpszSubKey = "RecentDocs";
780 mymru.lpfnCompare = &SHADD_compare_mru;
781 mruhandle = CreateMRUListA(&mymru);
784 ERR("MRU processing failed, handle zero\n");
785 RegCloseKey(HCUbasekey);
788 len = lstrlenA(doc_name);
789 pos = FindMRUData(mruhandle, doc_name, len, 0);
791 /* Now get the MRU entry that will be replaced
792 * and delete the .lnk file for it
794 if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
795 buffer, 2048)) != -1) {
797 ptr += (lstrlenA(buffer) + 1);
798 slen = *((short int*)ptr);
799 ptr += 2; /* skip the length area */
800 if (bufused >= slen + (ptr-buffer)) {
801 /* buffer size looks good */
802 ptr += 12; /* get to string */
803 len = bufused - (ptr-buffer); /* get length of buf remaining */
804 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
805 /* appears to be good string */
806 lstrcpyA(old_lnk_name, link_dir);
807 PathAppendA(old_lnk_name, ptr);
808 if (!DeleteFileA(old_lnk_name)) {
809 if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) {
810 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
811 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
812 old_lnk_name, err, attr);
815 TRACE("old .lnk file %s did not exist\n",
820 ERR("Delete for %s failed, attr=%08lx\n",
825 TRACE("deleted old .lnk file %s\n", old_lnk_name);
831 /* Create usable .lnk file name for the "Recent" directory
833 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
834 lstrcpyA(new_lnk_filepath, link_dir);
835 PathAppendA(new_lnk_filepath, new_lnk_name);
837 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
838 while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
840 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
841 lstrcpyA(new_lnk_filepath, link_dir);
842 PathAppendA(new_lnk_filepath, new_lnk_name);
844 SetErrorMode(olderrormode);
845 TRACE("new shortcut will be %s\n", new_lnk_filepath);
847 /* Now add the new MRU entry and data
849 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
851 FreeMRUList(mruhandle);
852 TRACE("Updated MRU list, new doc is position %d\n", pos);
855 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
858 * doc_name - pure file-spec, no path
860 * - path and file name of new .lnk file
861 * uFlags[in] - flags on call to SHAddToRecentDocs
862 * pv[in] - document path/pidl on call to SHAddToRecentDocs
864 IShellLinkA *psl = NULL;
865 IPersistFile *pPf = NULL;
868 WCHAR widelink[MAX_PATH];
872 hres = CoCreateInstance( &CLSID_ShellLink,
874 CLSCTX_INPROC_SERVER,
877 if(SUCCEEDED(hres)) {
879 hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
883 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
887 /* Set the document path or pidl */
888 if (uFlags & SHARD_PIDL) {
889 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
891 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
895 ERR("failed Set{IDList|Path} %08lx\n", hres);
899 lstrcpyA(desc, "Shortcut to ");
900 lstrcatA(desc, doc_name);
901 hres = IShellLinkA_SetDescription(psl, desc);
904 ERR("failed SetDescription %08lx\n", hres);
908 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
910 /* create the short cut */
911 hres = IPersistFile_Save(pPf, widelink, TRUE);
914 ERR("failed IPersistFile::Save %08lx\n", hres);
915 IPersistFile_Release(pPf);
916 IShellLinkA_Release(psl);
919 hres = IPersistFile_SaveCompleted(pPf, widelink);
920 IPersistFile_Release(pPf);
921 IShellLinkA_Release(psl);
922 TRACE("shortcut %s has been created, result=%08lx\n",
923 new_lnk_filepath, hres);
926 ERR("CoCreateInstance failed, hres=%08lx\n", hres);
934 RegCloseKey(HCUbasekey);
938 /*************************************************************************
939 * SHCreateShellFolderViewEx [SHELL32.174]
942 * see IShellFolder::CreateViewObject
944 HRESULT WINAPI SHCreateShellFolderViewEx(
945 LPCSHELLFOLDERVIEWINFO psvcbi, /* [in] shelltemplate struct */
946 LPSHELLVIEW* ppv) /* [out] IShellView pointer */
951 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
952 psvcbi->pshf, psvcbi->pidlFolder, psvcbi->lpfnCallback,
953 psvcbi->uViewMode, psvcbi->dwUser);
955 psf = IShellView_Constructor(psvcbi->pshf);
958 return E_OUTOFMEMORY;
960 IShellView_AddRef(psf);
961 hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
962 IShellView_Release(psf);
966 /*************************************************************************
967 * SHWinHelp [SHELL32.127]
970 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
971 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
974 /*************************************************************************
975 * SHRunControlPanel [SHELL32.161]
978 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
979 { FIXME("0x%08lx 0x%08lx stub\n",x,z);
983 static LPUNKNOWN SHELL32_IExplorerInterface=0;
984 /*************************************************************************
985 * SHSetInstanceExplorer [SHELL32.176]
990 HRESULT WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
991 { TRACE("%p\n", lpUnknown);
992 SHELL32_IExplorerInterface = lpUnknown;
993 return (HRESULT) lpUnknown;
995 /*************************************************************************
996 * SHGetInstanceExplorer [SHELL32.@]
999 * gets the interface pointer of the explorer and a reference
1001 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
1002 { TRACE("%p\n", lpUnknown);
1004 *lpUnknown = SHELL32_IExplorerInterface;
1006 if (!SHELL32_IExplorerInterface)
1009 IUnknown_AddRef(SHELL32_IExplorerInterface);
1012 /*************************************************************************
1013 * SHFreeUnusedLibraries [SHELL32.123]
1018 void WINAPI SHFreeUnusedLibraries (void)
1022 /*************************************************************************
1023 * DAD_AutoScroll [SHELL32.129]
1026 BOOL WINAPI DAD_AutoScroll(HWND hwnd, AUTO_SCROLL_DATA *samples, LPPOINT pt)
1028 FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1031 /*************************************************************************
1032 * DAD_DragEnter [SHELL32.130]
1035 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1037 FIXME("hwnd = %p\n",hwnd);
1040 /*************************************************************************
1041 * DAD_DragEnterEx [SHELL32.131]
1044 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1046 FIXME("hwnd = %p (%ld,%ld)\n",hwnd,p.x,p.y);
1049 /*************************************************************************
1050 * DAD_DragMove [SHELL32.134]
1053 BOOL WINAPI DAD_DragMove(POINT p)
1055 FIXME("(%ld,%ld)\n",p.x,p.y);
1058 /*************************************************************************
1059 * DAD_DragLeave [SHELL32.132]
1062 BOOL WINAPI DAD_DragLeave(VOID)
1067 /*************************************************************************
1068 * DAD_SetDragImage [SHELL32.136]
1073 BOOL WINAPI DAD_SetDragImage(
1074 HIMAGELIST himlTrack,
1077 FIXME("%p %p stub\n",himlTrack, lppt);
1080 /*************************************************************************
1081 * DAD_ShowDragImage [SHELL32.137]
1086 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1088 FIXME("0x%08x stub\n",bShow);
1092 static const WCHAR szwCabLocation[] = {
1093 'S','o','f','t','w','a','r','e','\\',
1094 'M','i','c','r','o','s','o','f','t','\\',
1095 'W','i','n','d','o','w','s','\\',
1096 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1097 'E','x','p','l','o','r','e','r','\\',
1098 'C','a','b','i','n','e','t','S','t','a','t','e',0
1101 static const WCHAR szwSettings[] = { 'S','e','t','t','i','n','g','s',0 };
1103 /*************************************************************************
1104 * ReadCabinetState [SHELL32.651] NT 4.0
1107 BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
1112 TRACE("%p %d \n",cs,length);
1114 if( (cs == NULL) || (length < (int)sizeof(*cs)) )
1117 r = RegOpenKeyW( HKEY_CURRENT_USER, szwCabLocation, &hkey );
1118 if( r == ERROR_SUCCESS )
1121 r = RegQueryValueExW( hkey, szwSettings,
1122 NULL, &type, (LPBYTE)cs, (LPDWORD)&length );
1123 RegCloseKey( hkey );
1127 /* if we can't read from the registry, create default values */
1128 if ( (r != ERROR_SUCCESS) || (cs->cLength < sizeof(*cs)) ||
1129 (cs->cLength != length) )
1131 ERR("Initializing shell cabinet settings\n");
1132 memset(cs, 0, sizeof(*cs));
1133 cs->cLength = sizeof(*cs);
1135 cs->fFullPathTitle = FALSE;
1136 cs->fSaveLocalView = TRUE;
1137 cs->fNotShell = FALSE;
1138 cs->fSimpleDefault = TRUE;
1139 cs->fDontShowDescBar = FALSE;
1140 cs->fNewWindowMode = FALSE;
1141 cs->fShowCompColor = FALSE;
1142 cs->fDontPrettyNames = FALSE;
1143 cs->fAdminsCreateCommonGroups = TRUE;
1144 cs->fMenuEnumFilter = 96;
1150 /*************************************************************************
1151 * WriteCabinetState [SHELL32.652] NT 4.0
1154 BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
1164 r = RegCreateKeyExW( HKEY_CURRENT_USER, szwCabLocation, 0,
1165 NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
1166 if( r == ERROR_SUCCESS )
1168 r = RegSetValueExW( hkey, szwSettings, 0,
1169 REG_BINARY, (LPBYTE) cs, cs->cLength);
1171 RegCloseKey( hkey );
1174 return (r==ERROR_SUCCESS);
1177 /*************************************************************************
1178 * FileIconInit [SHELL32.660]
1181 BOOL WINAPI FileIconInit(BOOL bFullInit)
1182 { FIXME("(%s)\n", bFullInit ? "true" : "false");
1185 /*************************************************************************
1186 * IsUserAdmin [SHELL32.680] NT 4.0
1189 HRESULT WINAPI IsUserAdmin(void)
1194 /*************************************************************************
1195 * SHAllocShared [SHELL32.520]
1198 * parameter1 is return value from HeapAlloc
1199 * parameter2 is equal to the size allocated with HeapAlloc
1200 * parameter3 is return value from GetCurrentProcessId
1202 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1203 * WM_USER+2 could be the undocumented CWM_SETPATH
1204 * the allocated memory contains a pidl
1206 HGLOBAL WINAPI SHAllocShared(LPVOID psrc, DWORD size, DWORD procID)
1210 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc,size,procID);
1211 hmem = GlobalAlloc(GMEM_FIXED, size);
1215 pmem = GlobalLock (hmem);
1220 memcpy (pmem, psrc, size);
1224 /*************************************************************************
1225 * SHLockShared [SHELL32.521]
1228 * parameter1 is return value from SHAllocShared
1229 * parameter2 is return value from GetCurrentProcessId
1230 * the receiver of (WM_USER+2) tries to lock the HANDLE (?)
1231 * the return value seems to be a memory address
1233 LPVOID WINAPI SHLockShared(HANDLE hmem, DWORD procID)
1234 { TRACE("handle=%p procID=0x%04lx\n",hmem,procID);
1235 return GlobalLock(hmem);
1237 /*************************************************************************
1238 * SHUnlockShared [SHELL32.522]
1241 * parameter1 is return value from SHLockShared
1243 BOOL WINAPI SHUnlockShared(LPVOID pv)
1246 return GlobalUnlock((HANDLE)pv);
1248 /*************************************************************************
1249 * SHFreeShared [SHELL32.523]
1252 * parameter1 is return value from SHAllocShared
1253 * parameter2 is return value from GetCurrentProcessId
1255 BOOL WINAPI SHFreeShared(
1259 TRACE("handle=%p 0x%04lx\n",hMem,pid);
1260 return (BOOL)GlobalFree(hMem);
1263 /*************************************************************************
1264 * SetAppStartingCursor [SHELL32.99]
1266 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1267 { FIXME("hwnd=%p 0x%04lx stub\n",u,v );
1270 /*************************************************************************
1271 * SHLoadOLE [SHELL32.151]
1274 HRESULT WINAPI SHLoadOLE(DWORD u)
1275 { FIXME("0x%04lx stub\n",u);
1278 /*************************************************************************
1279 * DriveType [SHELL32.64]
1282 HRESULT WINAPI DriveType(DWORD u)
1283 { FIXME("0x%04lx stub\n",u);
1286 /*************************************************************************
1287 * SHAbortInvokeCommand [SHELL32.198]
1290 HRESULT WINAPI SHAbortInvokeCommand(void)
1294 /*************************************************************************
1295 * SHOutOfMemoryMessageBox [SHELL32.126]
1298 int WINAPI SHOutOfMemoryMessageBox(
1303 FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1306 /*************************************************************************
1307 * SHFlushClipboard [SHELL32.121]
1310 HRESULT WINAPI SHFlushClipboard(void)
1315 /*************************************************************************
1316 * SHWaitForFileToOpen [SHELL32.97]
1319 BOOL WINAPI SHWaitForFileToOpen(
1324 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1328 /************************************************************************
1331 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1332 * second one could be a size (0x0c). The size is the same as the structure saved to
1333 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1334 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1336 HRESULT WINAPI shell32_654 (CABINETSTATE *cs, int length)
1338 TRACE("%p %d\n",cs,length);
1339 return ReadCabinetState(cs,length);
1342 /************************************************************************
1343 * RLBuildListOfPaths [SHELL32.146]
1348 DWORD WINAPI RLBuildListOfPaths (void)
1352 /************************************************************************
1353 * SHValidateUNC [SHELL32.173]
1356 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1358 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1362 /************************************************************************
1363 * DoEnvironmentSubstA [SHELL32.@]
1366 HRESULT WINAPI DoEnvironmentSubstA(LPSTR x, LPSTR y)
1368 FIXME("(%s, %s) stub\n", debugstr_a(x), debugstr_a(y));
1372 /************************************************************************
1373 * DoEnvironmentSubstW [SHELL32.@]
1376 HRESULT WINAPI DoEnvironmentSubstW(LPWSTR x, LPWSTR y)
1378 FIXME("(%s, %s): stub\n", debugstr_w(x), debugstr_w(y));
1382 /************************************************************************
1383 * DoEnvironmentSubst [SHELL32.53]
1386 HRESULT WINAPI DoEnvironmentSubstAW(LPVOID x, LPVOID y)
1388 if (SHELL_OsIsUnicode())
1389 return DoEnvironmentSubstW(x, y);
1390 return DoEnvironmentSubstA(x, y);
1393 /*************************************************************************
1396 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1397 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1401 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1406 /*************************************************************************
1409 DWORD WINAPI SHELL32_714(LPVOID x)
1411 FIXME("(%s)stub\n", debugstr_w(x));
1415 /*************************************************************************
1416 * SHAddFromPropSheetExtArray [SHELL32.167]
1418 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1420 FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1424 /*************************************************************************
1425 * SHCreatePropSheetExtArray [SHELL32.168]
1427 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1429 FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1433 /*************************************************************************
1434 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1436 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1438 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1442 /*************************************************************************
1443 * SHDestroyPropSheetExtArray [SHELL32.169]
1445 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1447 FIXME("(%08lx)stub\n", a);
1451 /*************************************************************************
1452 * CIDLData_CreateFromIDArray [SHELL32.83]
1454 * Create IDataObject from PIDLs??
1456 HRESULT WINAPI CIDLData_CreateFromIDArray(
1457 LPCITEMIDLIST pidlFolder,
1459 LPCITEMIDLIST *lppidlFiles,
1460 LPDATAOBJECT *ppdataObject)
1463 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1465 TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1469 for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1471 *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1472 lppidlFiles, cpidlFiles);
1473 if (*ppdataObject) return S_OK;
1474 return E_OUTOFMEMORY;
1477 /*************************************************************************
1478 * SHCreateStdEnumFmtEtc [SHELL32.74]
1483 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1485 const FORMATETC *lpFormats,
1486 LPENUMFORMATETC *ppenumFormatetc)
1488 IEnumFORMATETC *pef;
1490 TRACE("cf=%ld fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1492 pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1494 return E_OUTOFMEMORY;
1496 IEnumFORMATETC_AddRef(pef);
1497 hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1498 IEnumFORMATETC_Release(pef);
1504 /*************************************************************************
1507 HRESULT WINAPI SHELL32_256(LPDWORD lpdw0, LPDWORD lpdw1)
1511 FIXME("stub %p 0x%08lx %p\n", lpdw0, lpdw0 ? *lpdw0 : 0, lpdw1);
1513 if (!lpdw0 || *lpdw0 != 0x10)
1517 LPVOID lpdata = 0;/*LocalAlloc(GMEM_ZEROINIT, 0x4E4);*/
1520 ret = E_OUTOFMEMORY;
1523 /* Initialize and return unknown lpdata structure */