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