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
216 * FIXME: implement new flags such as SSF_WIN95CLASSIC and SSF_STARTPANELON
219 VOID WINAPI
SHGetSettings(LPSHELLFLAGSTATE lpsfs
, DWORD dwMask
)
223 DWORD dwDataSize
= sizeof (DWORD
);
225 TRACE("(%p 0x%08lx)\n",lpsfs
,dwMask
);
227 if (RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
228 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0))
231 if ( (SSF_SHOWEXTENSIONS
& dwMask
) && !RegQueryValueExA(hKey
, "HideFileExt", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
232 lpsfs
->fShowExtensions
= ((dwData
== 0) ? 0 : 1);
234 if ( (SSF_SHOWINFOTIP
& dwMask
) && !RegQueryValueExA(hKey
, "ShowInfoTip", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
235 lpsfs
->fShowInfoTip
= ((dwData
== 0) ? 0 : 1);
237 if ( (SSF_DONTPRETTYPATH
& dwMask
) && !RegQueryValueExA(hKey
, "DontPrettyPath", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
238 lpsfs
->fDontPrettyPath
= ((dwData
== 0) ? 0 : 1);
240 if ( (SSF_HIDEICONS
& dwMask
) && !RegQueryValueExA(hKey
, "HideIcons", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
241 lpsfs
->fHideIcons
= ((dwData
== 0) ? 0 : 1);
243 if ( (SSF_MAPNETDRVBUTTON
& dwMask
) && !RegQueryValueExA(hKey
, "MapNetDrvBtn", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
244 lpsfs
->fMapNetDrvBtn
= ((dwData
== 0) ? 0 : 1);
246 if ( (SSF_SHOWATTRIBCOL
& dwMask
) && !RegQueryValueExA(hKey
, "ShowAttribCol", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
247 lpsfs
->fShowAttribCol
= ((dwData
== 0) ? 0 : 1);
249 if (((SSF_SHOWALLOBJECTS
| SSF_SHOWSYSFILES
) & dwMask
) && !RegQueryValueExA(hKey
, "Hidden", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
251 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 0;
252 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 0;
254 else if (dwData
== 1)
255 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 1;
256 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 0;
258 else if (dwData
== 2)
259 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 0;
260 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 1;
265 TRACE("-- 0x%04x\n", *(WORD
*)lpsfs
);
268 /*************************************************************************
269 * SHShellFolderView_Message [SHELL32.73]
271 * Send a message to an explorer cabinet window.
274 * hwndCabinet [I] The window containing the shellview to communicate with
275 * dwMessage [I] The SFVM message to send
276 * dwParam [I] Message parameter
282 * Message SFVM_REARRANGE = 1
284 * This message gets sent when a column gets clicked to instruct the
285 * shell view to re-sort the item list. dwParam identifies the column
288 int WINAPI
SHShellFolderView_Message(
293 FIXME("%p %08lx %08lx stub\n",hwndCabinet
, dwMessage
, dwParam
);
297 /*************************************************************************
298 * RegisterShellHook [SHELL32.181]
300 * Register a shell hook.
303 * hwnd [I] Window handle
304 * dwType [I] Type of hook.
307 * Exported by ordinal
309 BOOL WINAPI
RegisterShellHook(
313 FIXME("(%p,0x%08lx):stub.\n",hWnd
, dwType
);
317 /*************************************************************************
318 * ShellMessageBoxW [SHELL32.182]
320 * See ShellMessageBoxA.
322 int WINAPIV
ShellMessageBoxW(
330 WCHAR szText
[100],szTitle
[100];
331 LPCWSTR pszText
= szText
, pszTitle
= szTitle
, pszTemp
;
335 va_start(args
, uType
);
336 /* wvsprintfA(buf,fmt, args); */
338 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
339 (DWORD
)hInstance
,(DWORD
)hWnd
,lpText
,lpCaption
,uType
);
341 if (!HIWORD(lpCaption
))
342 LoadStringW(hInstance
, (DWORD
)lpCaption
, szTitle
, sizeof(szTitle
)/sizeof(szTitle
[0]));
344 pszTitle
= lpCaption
;
347 LoadStringW(hInstance
, (DWORD
)lpText
, szText
, sizeof(szText
)/sizeof(szText
[0]));
351 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
352 pszText
, 0, 0, (LPWSTR
)&pszTemp
, 0, &args
);
356 ret
= MessageBoxW(hWnd
,pszTemp
,pszTitle
,uType
);
357 LocalFree((HLOCAL
)pszTemp
);
361 /*************************************************************************
362 * ShellMessageBoxA [SHELL32.183]
364 * Format and output an error message.
367 * hInstance [I] Instance handle of message creator
368 * hWnd [I] Window handle of message creator
369 * lpText [I] Resource Id of title or LPSTR
370 * lpCaption [I] Resource Id of title or LPSTR
371 * uType [I] Type of error message
374 * A return value from MessageBoxA().
377 * Exported by ordinal
379 int WINAPIV
ShellMessageBoxA(
387 char szText
[100],szTitle
[100];
388 LPCSTR pszText
= szText
, pszTitle
= szTitle
, pszTemp
;
392 va_start(args
, uType
);
393 /* wvsprintfA(buf,fmt, args); */
395 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
396 (DWORD
)hInstance
,(DWORD
)hWnd
,lpText
,lpCaption
,uType
);
398 if (!HIWORD(lpCaption
))
399 LoadStringA(hInstance
, (DWORD
)lpCaption
, szTitle
, sizeof(szTitle
));
401 pszTitle
= lpCaption
;
404 LoadStringA(hInstance
, (DWORD
)lpText
, szText
, sizeof(szText
));
408 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
409 pszText
, 0, 0, (LPSTR
)&pszTemp
, 0, &args
);
413 ret
= MessageBoxA(hWnd
,pszTemp
,pszTitle
,uType
);
414 LocalFree((HLOCAL
)pszTemp
);
418 /*************************************************************************
419 * SHRegisterDragDrop [SHELL32.86]
422 * exported by ordinal
424 HRESULT WINAPI
SHRegisterDragDrop(
426 LPDROPTARGET pDropTarget
)
428 FIXME("(%p,%p):stub.\n", hWnd
, pDropTarget
);
429 if (GetShellOle()) return pRegisterDragDrop(hWnd
, pDropTarget
);
433 /*************************************************************************
434 * SHRevokeDragDrop [SHELL32.87]
437 * exported by ordinal
439 HRESULT WINAPI
SHRevokeDragDrop(HWND hWnd
)
441 FIXME("(%p):stub.\n",hWnd
);
442 if (GetShellOle()) return pRevokeDragDrop(hWnd
);
446 /*************************************************************************
447 * SHDoDragDrop [SHELL32.88]
450 * exported by ordinal
452 HRESULT WINAPI
SHDoDragDrop(
454 LPDATAOBJECT lpDataObject
,
455 LPDROPSOURCE lpDropSource
,
459 FIXME("(%p %p %p 0x%08lx %p):stub.\n",
460 hWnd
, lpDataObject
, lpDropSource
, dwOKEffect
, pdwEffect
);
461 if (GetShellOle()) return pDoDragDrop(lpDataObject
, lpDropSource
, dwOKEffect
, pdwEffect
);
465 /*************************************************************************
466 * ArrangeWindows [SHELL32.184]
469 WORD WINAPI
ArrangeWindows(
476 FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
477 hwndParent
, dwReserved
, lpRect
, cKids
, lpKids
);
481 /*************************************************************************
482 * SignalFileOpen [SHELL32.103]
485 * exported by ordinal
488 SignalFileOpen (DWORD dwParam1
)
490 FIXME("(0x%08lx):stub.\n", dwParam1
);
495 /*************************************************************************
496 * SHADD_get_policy - helper function for SHAddToRecentDocs
499 * policy [IN] policy name (null termed string) to find
500 * type [OUT] ptr to DWORD to receive type
501 * buffer [OUT] ptr to area to hold data retrieved
502 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
506 * result of the SHQueryValueEx call
508 static INT
SHADD_get_policy(LPSTR policy
, LPDWORD type
, LPVOID buffer
, LPDWORD len
)
513 /* Get the key for the policies location in the registry
515 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
516 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
517 0, KEY_READ
, &Policy_basekey
)) {
519 if (RegOpenKeyExA(HKEY_CURRENT_USER
,
520 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
521 0, KEY_READ
, &Policy_basekey
)) {
522 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
525 return ERROR_FILE_NOT_FOUND
;
529 /* Retrieve the data if it exists
531 ret
= SHQueryValueExA(Policy_basekey
, policy
, 0, type
, buffer
, len
);
532 RegCloseKey(Policy_basekey
);
537 /*************************************************************************
538 * SHADD_compare_mru - helper function for SHAddToRecentDocs
541 * data1 [IN] data being looked for
542 * data2 [IN] data in MRU
543 * cbdata [IN] length from FindMRUData call (not used)
546 * position within MRU list that data was added.
548 static INT CALLBACK
SHADD_compare_mru(LPCVOID data1
, LPCVOID data2
, DWORD cbData
)
550 return lstrcmpiA(data1
, data2
);
553 /*************************************************************************
554 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
557 * mruhandle [IN] handle for created MRU list
558 * doc_name [IN] null termed pure doc name
559 * new_lnk_name [IN] null termed path and file name for .lnk file
560 * buffer [IN/OUT] 2048 byte area to consturct MRU data
561 * len [OUT] ptr to int to receive space used in buffer
564 * position within MRU list that data was added.
566 static INT
SHADD_create_add_mru_data(HANDLE mruhandle
, LPSTR doc_name
, LPSTR new_lnk_name
,
567 LPSTR buffer
, INT
*len
)
573 * RecentDocs MRU data structure seems to be:
574 * +0h document file name w/ terminating 0h
575 * +nh short int w/ size of remaining
576 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
577 * +n+4h 10 bytes zeros - unknown
578 * +n+eh shortcut file name w/ terminating 0h
579 * +n+e+nh 3 zero bytes - unknown
582 /* Create the MRU data structure for "RecentDocs"
585 lstrcpyA(ptr
, doc_name
);
586 ptr
+= (lstrlenA(buffer
) + 1);
587 wlen
= lstrlenA(new_lnk_name
) + 1 + 12;
588 *((short int*)ptr
) = wlen
;
589 ptr
+= 2; /* step past the length */
590 *(ptr
++) = 0x30; /* unknown reason */
591 *(ptr
++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
594 lstrcpyA(ptr
, new_lnk_name
);
595 ptr
+= (lstrlenA(new_lnk_name
) + 1);
600 /* Add the new entry into the MRU list
602 return AddMRUData(mruhandle
, (LPCVOID
)buffer
, *len
);
605 /*************************************************************************
606 * SHAddToRecentDocs [SHELL32.@]
609 * uFlags [IN] SHARD_PATH or SHARD_PIDL
610 * pv [IN] string or pidl, NULL clears the list
616 void WINAPI
SHAddToRecentDocs (UINT uFlags
,LPCVOID pv
)
618 /* If list is a string list lpfnCompare has the following prototype
619 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
620 * for binary lists the prototype is
621 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
622 * where cbData is the no. of bytes to compare.
623 * Need to check what return value means identical - 0?
629 CHAR doc_name
[MAX_PATH
];
630 CHAR link_dir
[MAX_PATH
];
631 CHAR new_lnk_filepath
[MAX_PATH
];
632 CHAR new_lnk_name
[MAX_PATH
];
635 HWND hwnd
= 0; /* FIXME: get real window handle */
637 DWORD data
[64], datalen
, type
;
640 * RecentDocs MRU data structure seems to be:
641 * +0h document file name w/ terminating 0h
642 * +nh short int w/ size of remaining
643 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
644 * +n+4h 10 bytes zeros - unknown
645 * +n+eh shortcut file name w/ terminating 0h
646 * +n+e+nh 3 zero bytes - unknown
649 /* See if we need to do anything.
652 ret
=SHADD_get_policy( "NoRecentDocsHistory", &type
, &data
, &datalen
);
653 if ((ret
> 0) && (ret
!= ERROR_FILE_NOT_FOUND
)) {
654 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret
);
657 if (ret
== ERROR_SUCCESS
) {
658 if (!( (type
== REG_DWORD
) ||
659 ((type
== REG_BINARY
) && (datalen
== 4)) )) {
660 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
665 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data
[0]);
666 /* now test the actual policy value */
671 /* Open key to where the necessary info is
673 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
674 * and the close should be done during the _DETACH. The resulting
675 * key is stored in the DLL global data.
677 if (RegCreateKeyExA(HKEY_CURRENT_USER
,
678 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
679 0, 0, 0, KEY_READ
, 0, &HCUbasekey
, 0)) {
680 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
684 /* Get path to user's "Recent" directory
686 if(SUCCEEDED(SHGetMalloc(&ppM
))) {
687 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd
, CSIDL_RECENT
,
689 SHGetPathFromIDListA(pidl
, link_dir
);
690 IMalloc_Free(ppM
, pidl
);
695 ERR("serious issues 1\n");
697 IMalloc_Release(ppM
);
702 ERR("serious issues 2\n");
704 TRACE("Users Recent dir %s\n", link_dir
);
706 /* If no input, then go clear the lists */
708 /* clear user's Recent dir
711 /* FIXME: delete all files in "link_dir"
713 * while( more files ) {
714 * lstrcpyA(old_lnk_name, link_dir);
715 * PathAppendA(old_lnk_name, filenam);
716 * DeleteFileA(old_lnk_name);
719 FIXME("should delete all files in %s\\ \n", link_dir
);
723 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
724 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
725 * and naturally it fails w/ rc=2. It should do it against
726 * HKEY_CURRENT_USER which is where it is stored, and where
727 * the MRU routines expect it!!!!
729 RegDeleteKeyA(HCUbasekey
, "RecentDocs");
730 RegCloseKey(HCUbasekey
);
734 /* Have data to add, the jobs to be done:
735 * 1. Add document to MRU list in registry "HKCU\Software\
736 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
737 * 2. Add shortcut to document in the user's Recent directory
739 * 3. Add shortcut to Start menu's Documents submenu.
742 /* Get the pure document name from the input
744 if (uFlags
& SHARD_PIDL
) {
745 SHGetPathFromIDListA((LPCITEMIDLIST
) pv
, doc_name
);
748 lstrcpyA(doc_name
, (LPSTR
) pv
);
750 TRACE("full document name %s\n", doc_name
);
751 PathStripPathA(doc_name
);
752 TRACE("stripped document name %s\n", doc_name
);
755 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
758 * doc_name - pure file-spec, no path
759 * link_dir - path to the user's Recent directory
760 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
762 * new_lnk_name- pure file-spec, no path for new .lnk file
764 * - path and file name of new .lnk file
766 CREATEMRULISTA mymru
;
768 INT len
, pos
, bufused
, err
;
773 CHAR old_lnk_name
[MAX_PATH
];
776 mymru
.cbSize
= sizeof(CREATEMRULISTA
);
777 mymru
.nMaxItems
= 15;
778 mymru
.dwFlags
= MRUF_BINARY_LIST
| MRUF_DELAYED_SAVE
;
779 mymru
.hKey
= HCUbasekey
;
780 mymru
.lpszSubKey
= "RecentDocs";
781 mymru
.lpfnCompare
= &SHADD_compare_mru
;
782 mruhandle
= CreateMRUListA(&mymru
);
785 ERR("MRU processing failed, handle zero\n");
786 RegCloseKey(HCUbasekey
);
789 len
= lstrlenA(doc_name
);
790 pos
= FindMRUData(mruhandle
, doc_name
, len
, 0);
792 /* Now get the MRU entry that will be replaced
793 * and delete the .lnk file for it
795 if ((bufused
= EnumMRUListA(mruhandle
, (pos
== -1) ? 14 : pos
,
796 buffer
, 2048)) != -1) {
798 ptr
+= (lstrlenA(buffer
) + 1);
799 slen
= *((short int*)ptr
);
800 ptr
+= 2; /* skip the length area */
801 if (bufused
>= slen
+ (ptr
-buffer
)) {
802 /* buffer size looks good */
803 ptr
+= 12; /* get to string */
804 len
= bufused
- (ptr
-buffer
); /* get length of buf remaining */
805 if ((lstrlenA(ptr
) > 0) && (lstrlenA(ptr
) <= len
-1)) {
806 /* appears to be good string */
807 lstrcpyA(old_lnk_name
, link_dir
);
808 PathAppendA(old_lnk_name
, ptr
);
809 if (!DeleteFileA(old_lnk_name
)) {
810 if ((attr
= GetFileAttributesA(old_lnk_name
)) == INVALID_FILE_ATTRIBUTES
) {
811 if ((err
= GetLastError()) != ERROR_FILE_NOT_FOUND
) {
812 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
813 old_lnk_name
, err
, attr
);
816 TRACE("old .lnk file %s did not exist\n",
821 ERR("Delete for %s failed, attr=%08lx\n",
826 TRACE("deleted old .lnk file %s\n", old_lnk_name
);
832 /* Create usable .lnk file name for the "Recent" directory
834 wsprintfA(new_lnk_name
, "%s.lnk", doc_name
);
835 lstrcpyA(new_lnk_filepath
, link_dir
);
836 PathAppendA(new_lnk_filepath
, new_lnk_name
);
838 olderrormode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
839 while (GetFileAttributesA(new_lnk_filepath
) != INVALID_FILE_ATTRIBUTES
) {
841 wsprintfA(new_lnk_name
, "%s (%u).lnk", doc_name
, i
);
842 lstrcpyA(new_lnk_filepath
, link_dir
);
843 PathAppendA(new_lnk_filepath
, new_lnk_name
);
845 SetErrorMode(olderrormode
);
846 TRACE("new shortcut will be %s\n", new_lnk_filepath
);
848 /* Now add the new MRU entry and data
850 pos
= SHADD_create_add_mru_data(mruhandle
, doc_name
, new_lnk_name
,
852 FreeMRUList(mruhandle
);
853 TRACE("Updated MRU list, new doc is position %d\n", pos
);
856 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
859 * doc_name - pure file-spec, no path
861 * - path and file name of new .lnk file
862 * uFlags[in] - flags on call to SHAddToRecentDocs
863 * pv[in] - document path/pidl on call to SHAddToRecentDocs
865 IShellLinkA
*psl
= NULL
;
866 IPersistFile
*pPf
= NULL
;
869 WCHAR widelink
[MAX_PATH
];
873 hres
= CoCreateInstance( &CLSID_ShellLink
,
875 CLSCTX_INPROC_SERVER
,
878 if(SUCCEEDED(hres
)) {
880 hres
= IShellLinkA_QueryInterface(psl
, &IID_IPersistFile
,
884 ERR("failed QueryInterface for IPersistFile %08lx\n", hres
);
888 /* Set the document path or pidl */
889 if (uFlags
& SHARD_PIDL
) {
890 hres
= IShellLinkA_SetIDList(psl
, (LPCITEMIDLIST
) pv
);
892 hres
= IShellLinkA_SetPath(psl
, (LPCSTR
) pv
);
896 ERR("failed Set{IDList|Path} %08lx\n", hres
);
900 lstrcpyA(desc
, "Shortcut to ");
901 lstrcatA(desc
, doc_name
);
902 hres
= IShellLinkA_SetDescription(psl
, desc
);
905 ERR("failed SetDescription %08lx\n", hres
);
909 MultiByteToWideChar(CP_ACP
, 0, new_lnk_filepath
, -1,
911 /* create the short cut */
912 hres
= IPersistFile_Save(pPf
, widelink
, TRUE
);
915 ERR("failed IPersistFile::Save %08lx\n", hres
);
916 IPersistFile_Release(pPf
);
917 IShellLinkA_Release(psl
);
920 hres
= IPersistFile_SaveCompleted(pPf
, widelink
);
921 IPersistFile_Release(pPf
);
922 IShellLinkA_Release(psl
);
923 TRACE("shortcut %s has been created, result=%08lx\n",
924 new_lnk_filepath
, hres
);
927 ERR("CoCreateInstance failed, hres=%08lx\n", hres
);
935 RegCloseKey(HCUbasekey
);
939 /*************************************************************************
940 * SHCreateShellFolderViewEx [SHELL32.174]
943 * see IShellFolder::CreateViewObject
945 HRESULT WINAPI
SHCreateShellFolderViewEx(
946 LPCSHELLFOLDERVIEWINFO psvcbi
, /* [in] shelltemplate struct */
947 LPSHELLVIEW
* ppv
) /* [out] IShellView pointer */
952 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
953 psvcbi
->pshf
, psvcbi
->pidlFolder
, psvcbi
->lpfnCallback
,
954 psvcbi
->uViewMode
, psvcbi
->dwUser
);
956 psf
= IShellView_Constructor(psvcbi
->pshf
);
959 return E_OUTOFMEMORY
;
961 IShellView_AddRef(psf
);
962 hRes
= IShellView_QueryInterface(psf
, &IID_IShellView
, (LPVOID
*)ppv
);
963 IShellView_Release(psf
);
967 /*************************************************************************
968 * SHWinHelp [SHELL32.127]
971 HRESULT WINAPI
SHWinHelp (DWORD v
, DWORD w
, DWORD x
, DWORD z
)
972 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v
,w
,x
,z
);
975 /*************************************************************************
976 * SHRunControlPanel [SHELL32.161]
979 HRESULT WINAPI
SHRunControlPanel (DWORD x
, DWORD z
)
980 { FIXME("0x%08lx 0x%08lx stub\n",x
,z
);
984 static LPUNKNOWN SHELL32_IExplorerInterface
=0;
985 /*************************************************************************
986 * SHSetInstanceExplorer [SHELL32.176]
991 HRESULT WINAPI
SHSetInstanceExplorer (LPUNKNOWN lpUnknown
)
992 { TRACE("%p\n", lpUnknown
);
993 SHELL32_IExplorerInterface
= lpUnknown
;
994 return (HRESULT
) lpUnknown
;
996 /*************************************************************************
997 * SHGetInstanceExplorer [SHELL32.@]
1000 * gets the interface pointer of the explorer and a reference
1002 HRESULT WINAPI
SHGetInstanceExplorer (LPUNKNOWN
* lpUnknown
)
1003 { TRACE("%p\n", lpUnknown
);
1005 *lpUnknown
= SHELL32_IExplorerInterface
;
1007 if (!SHELL32_IExplorerInterface
)
1010 IUnknown_AddRef(SHELL32_IExplorerInterface
);
1013 /*************************************************************************
1014 * SHFreeUnusedLibraries [SHELL32.123]
1019 void WINAPI
SHFreeUnusedLibraries (void)
1023 /*************************************************************************
1024 * DAD_AutoScroll [SHELL32.129]
1027 BOOL WINAPI
DAD_AutoScroll(HWND hwnd
, AUTO_SCROLL_DATA
*samples
, LPPOINT pt
)
1029 FIXME("hwnd = %p %p %p\n",hwnd
,samples
,pt
);
1032 /*************************************************************************
1033 * DAD_DragEnter [SHELL32.130]
1036 BOOL WINAPI
DAD_DragEnter(HWND hwnd
)
1038 FIXME("hwnd = %p\n",hwnd
);
1041 /*************************************************************************
1042 * DAD_DragEnterEx [SHELL32.131]
1045 BOOL WINAPI
DAD_DragEnterEx(HWND hwnd
, POINT p
)
1047 FIXME("hwnd = %p (%ld,%ld)\n",hwnd
,p
.x
,p
.y
);
1050 /*************************************************************************
1051 * DAD_DragMove [SHELL32.134]
1054 BOOL WINAPI
DAD_DragMove(POINT p
)
1056 FIXME("(%ld,%ld)\n",p
.x
,p
.y
);
1059 /*************************************************************************
1060 * DAD_DragLeave [SHELL32.132]
1063 BOOL WINAPI
DAD_DragLeave(VOID
)
1068 /*************************************************************************
1069 * DAD_SetDragImage [SHELL32.136]
1074 BOOL WINAPI
DAD_SetDragImage(
1075 HIMAGELIST himlTrack
,
1078 FIXME("%p %p stub\n",himlTrack
, lppt
);
1081 /*************************************************************************
1082 * DAD_ShowDragImage [SHELL32.137]
1087 BOOL WINAPI
DAD_ShowDragImage(BOOL bShow
)
1089 FIXME("0x%08x stub\n",bShow
);
1093 static const WCHAR szwCabLocation
[] = {
1094 'S','o','f','t','w','a','r','e','\\',
1095 'M','i','c','r','o','s','o','f','t','\\',
1096 'W','i','n','d','o','w','s','\\',
1097 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1098 'E','x','p','l','o','r','e','r','\\',
1099 'C','a','b','i','n','e','t','S','t','a','t','e',0
1102 static const WCHAR szwSettings
[] = { 'S','e','t','t','i','n','g','s',0 };
1104 /*************************************************************************
1105 * ReadCabinetState [SHELL32.651] NT 4.0
1108 BOOL WINAPI
ReadCabinetState(CABINETSTATE
*cs
, int length
)
1113 TRACE("%p %d \n",cs
,length
);
1115 if( (cs
== NULL
) || (length
< (int)sizeof(*cs
)) )
1118 r
= RegOpenKeyW( HKEY_CURRENT_USER
, szwCabLocation
, &hkey
);
1119 if( r
== ERROR_SUCCESS
)
1122 r
= RegQueryValueExW( hkey
, szwSettings
,
1123 NULL
, &type
, (LPBYTE
)cs
, (LPDWORD
)&length
);
1124 RegCloseKey( hkey
);
1128 /* if we can't read from the registry, create default values */
1129 if ( (r
!= ERROR_SUCCESS
) || (cs
->cLength
< sizeof(*cs
)) ||
1130 (cs
->cLength
!= length
) )
1132 ERR("Initializing shell cabinet settings\n");
1133 memset(cs
, 0, sizeof(*cs
));
1134 cs
->cLength
= sizeof(*cs
);
1136 cs
->fFullPathTitle
= FALSE
;
1137 cs
->fSaveLocalView
= TRUE
;
1138 cs
->fNotShell
= FALSE
;
1139 cs
->fSimpleDefault
= TRUE
;
1140 cs
->fDontShowDescBar
= FALSE
;
1141 cs
->fNewWindowMode
= FALSE
;
1142 cs
->fShowCompColor
= FALSE
;
1143 cs
->fDontPrettyNames
= FALSE
;
1144 cs
->fAdminsCreateCommonGroups
= TRUE
;
1145 cs
->fMenuEnumFilter
= 96;
1151 /*************************************************************************
1152 * WriteCabinetState [SHELL32.652] NT 4.0
1155 BOOL WINAPI
WriteCabinetState(CABINETSTATE
*cs
)
1165 r
= RegCreateKeyExW( HKEY_CURRENT_USER
, szwCabLocation
, 0,
1166 NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
1167 if( r
== ERROR_SUCCESS
)
1169 r
= RegSetValueExW( hkey
, szwSettings
, 0,
1170 REG_BINARY
, (LPBYTE
) cs
, cs
->cLength
);
1172 RegCloseKey( hkey
);
1175 return (r
==ERROR_SUCCESS
);
1178 /*************************************************************************
1179 * FileIconInit [SHELL32.660]
1182 BOOL WINAPI
FileIconInit(BOOL bFullInit
)
1183 { FIXME("(%s)\n", bFullInit
? "true" : "false");
1186 /*************************************************************************
1187 * IsUserAdmin [SHELL32.680] NT 4.0
1190 HRESULT WINAPI
IsUserAdmin(void)
1195 /*************************************************************************
1196 * SHAllocShared [SHELL32.520]
1199 * parameter1 is return value from HeapAlloc
1200 * parameter2 is equal to the size allocated with HeapAlloc
1201 * parameter3 is return value from GetCurrentProcessId
1203 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1204 * WM_USER+2 could be the undocumented CWM_SETPATH
1205 * the allocated memory contains a pidl
1207 HGLOBAL WINAPI
SHAllocShared(LPVOID psrc
, DWORD size
, DWORD procID
)
1211 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc
,size
,procID
);
1212 hmem
= GlobalAlloc(GMEM_FIXED
, size
);
1216 pmem
= GlobalLock (hmem
);
1221 memcpy (pmem
, psrc
, size
);
1225 /*************************************************************************
1226 * SHLockShared [SHELL32.521]
1229 * parameter1 is return value from SHAllocShared
1230 * parameter2 is return value from GetCurrentProcessId
1231 * the receiver of (WM_USER+2) tries to lock the HANDLE (?)
1232 * the return value seems to be a memory address
1234 LPVOID WINAPI
SHLockShared(HANDLE hmem
, DWORD procID
)
1235 { TRACE("handle=%p procID=0x%04lx\n",hmem
,procID
);
1236 return GlobalLock(hmem
);
1238 /*************************************************************************
1239 * SHUnlockShared [SHELL32.522]
1242 * parameter1 is return value from SHLockShared
1244 BOOL WINAPI
SHUnlockShared(LPVOID pv
)
1247 return GlobalUnlock((HANDLE
)pv
);
1249 /*************************************************************************
1250 * SHFreeShared [SHELL32.523]
1253 * parameter1 is return value from SHAllocShared
1254 * parameter2 is return value from GetCurrentProcessId
1256 BOOL WINAPI
SHFreeShared(
1260 TRACE("handle=%p 0x%04lx\n",hMem
,pid
);
1261 return (BOOL
)GlobalFree(hMem
);
1264 /*************************************************************************
1265 * SetAppStartingCursor [SHELL32.99]
1267 HRESULT WINAPI
SetAppStartingCursor(HWND u
, DWORD v
)
1268 { FIXME("hwnd=%p 0x%04lx stub\n",u
,v
);
1271 /*************************************************************************
1272 * SHLoadOLE [SHELL32.151]
1275 HRESULT WINAPI
SHLoadOLE(DWORD u
)
1276 { FIXME("0x%04lx stub\n",u
);
1279 /*************************************************************************
1280 * DriveType [SHELL32.64]
1283 HRESULT WINAPI
DriveType(DWORD u
)
1284 { FIXME("0x%04lx stub\n",u
);
1287 /*************************************************************************
1288 * SHAbortInvokeCommand [SHELL32.198]
1291 HRESULT WINAPI
SHAbortInvokeCommand(void)
1295 /*************************************************************************
1296 * SHOutOfMemoryMessageBox [SHELL32.126]
1299 int WINAPI
SHOutOfMemoryMessageBox(
1304 FIXME("%p %s 0x%08x stub\n",hwndOwner
, lpCaption
, uType
);
1307 /*************************************************************************
1308 * SHFlushClipboard [SHELL32.121]
1311 HRESULT WINAPI
SHFlushClipboard(void)
1316 /*************************************************************************
1317 * SHWaitForFileToOpen [SHELL32.97]
1320 BOOL WINAPI
SHWaitForFileToOpen(
1325 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl
, dwFlags
, dwTimeout
);
1329 /************************************************************************
1332 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1333 * second one could be a size (0x0c). The size is the same as the structure saved to
1334 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1335 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1337 HRESULT WINAPI
shell32_654 (CABINETSTATE
*cs
, int length
)
1339 TRACE("%p %d\n",cs
,length
);
1340 return ReadCabinetState(cs
,length
);
1343 /************************************************************************
1344 * RLBuildListOfPaths [SHELL32.146]
1349 DWORD WINAPI
RLBuildListOfPaths (void)
1353 /************************************************************************
1354 * SHValidateUNC [SHELL32.173]
1357 HRESULT WINAPI
SHValidateUNC (DWORD x
, DWORD y
, DWORD z
)
1359 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x
,y
,z
);
1363 /************************************************************************
1364 * DoEnvironmentSubstA [SHELL32.@]
1367 HRESULT WINAPI
DoEnvironmentSubstA(LPSTR x
, LPSTR y
)
1369 FIXME("(%s, %s) stub\n", debugstr_a(x
), debugstr_a(y
));
1373 /************************************************************************
1374 * DoEnvironmentSubstW [SHELL32.@]
1377 HRESULT WINAPI
DoEnvironmentSubstW(LPWSTR x
, LPWSTR y
)
1379 FIXME("(%s, %s): stub\n", debugstr_w(x
), debugstr_w(y
));
1383 /************************************************************************
1384 * DoEnvironmentSubst [SHELL32.53]
1387 HRESULT WINAPI
DoEnvironmentSubstAW(LPVOID x
, LPVOID y
)
1389 if (SHELL_OsIsUnicode())
1390 return DoEnvironmentSubstW(x
, y
);
1391 return DoEnvironmentSubstA(x
, y
);
1394 /*************************************************************************
1397 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1398 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1402 BOOL WINAPI
shell32_243(DWORD a
, DWORD b
)
1407 /*************************************************************************
1410 DWORD WINAPI
SHELL32_714(LPVOID x
)
1412 FIXME("(%s)stub\n", debugstr_w(x
));
1416 /*************************************************************************
1417 * SHAddFromPropSheetExtArray [SHELL32.167]
1419 DWORD WINAPI
SHAddFromPropSheetExtArray(DWORD a
, DWORD b
, DWORD c
)
1421 FIXME("(%08lx,%08lx,%08lx)stub\n", a
, b
, c
);
1425 /*************************************************************************
1426 * SHCreatePropSheetExtArray [SHELL32.168]
1428 DWORD WINAPI
SHCreatePropSheetExtArray(DWORD a
, LPCSTR b
, DWORD c
)
1430 FIXME("(%08lx,%s,%08lx)stub\n", a
, debugstr_a(b
), c
);
1434 /*************************************************************************
1435 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1437 DWORD WINAPI
SHReplaceFromPropSheetExtArray(DWORD a
, DWORD b
, DWORD c
, DWORD d
)
1439 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a
, b
, c
, d
);
1443 /*************************************************************************
1444 * SHDestroyPropSheetExtArray [SHELL32.169]
1446 DWORD WINAPI
SHDestroyPropSheetExtArray(DWORD a
)
1448 FIXME("(%08lx)stub\n", a
);
1452 /*************************************************************************
1453 * CIDLData_CreateFromIDArray [SHELL32.83]
1455 * Create IDataObject from PIDLs??
1457 HRESULT WINAPI
CIDLData_CreateFromIDArray(
1458 LPCITEMIDLIST pidlFolder
,
1460 LPCITEMIDLIST
*lppidlFiles
,
1461 LPDATAOBJECT
*ppdataObject
)
1464 HWND hwnd
= 0; /*FIXME: who should be hwnd of owner? set to desktop */
1466 TRACE("(%p, %ld, %p, %p)\n", pidlFolder
, cpidlFiles
, lppidlFiles
, ppdataObject
);
1470 for (i
=0; i
<cpidlFiles
; i
++) pdump (lppidlFiles
[i
]);
1472 *ppdataObject
= IDataObject_Constructor( hwnd
, pidlFolder
,
1473 lppidlFiles
, cpidlFiles
);
1474 if (*ppdataObject
) return S_OK
;
1475 return E_OUTOFMEMORY
;
1478 /*************************************************************************
1479 * SHCreateStdEnumFmtEtc [SHELL32.74]
1484 HRESULT WINAPI
SHCreateStdEnumFmtEtc(
1486 const FORMATETC
*lpFormats
,
1487 LPENUMFORMATETC
*ppenumFormatetc
)
1489 IEnumFORMATETC
*pef
;
1491 TRACE("cf=%ld fe=%p pef=%p\n", cFormats
, lpFormats
, ppenumFormatetc
);
1493 pef
= IEnumFORMATETC_Constructor(cFormats
, lpFormats
);
1495 return E_OUTOFMEMORY
;
1497 IEnumFORMATETC_AddRef(pef
);
1498 hRes
= IEnumFORMATETC_QueryInterface(pef
, &IID_IEnumFORMATETC
, (LPVOID
*)ppenumFormatetc
);
1499 IEnumFORMATETC_Release(pef
);
1505 /*************************************************************************
1508 HRESULT WINAPI
SHELL32_256(LPDWORD lpdw0
, LPDWORD lpdw1
)
1512 FIXME("stub %p 0x%08lx %p\n", lpdw0
, lpdw0
? *lpdw0
: 0, lpdw1
);
1514 if (!lpdw0
|| *lpdw0
!= 0x10)
1518 LPVOID lpdata
= 0;/*LocalAlloc(GMEM_ZEROINIT, 0x4E4);*/
1521 ret
= E_OUTOFMEMORY
;
1524 /* Initialize and return unknown lpdata structure */