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
);
73 /* Get a function pointer from a DLL handle */
74 #define GET_FUNC(func, module, name, fail) \
77 if (!SHELL32_h##module && !(SHELL32_h##module = LoadLibraryA(#module ".dll"))) return fail; \
78 func = (void*)GetProcAddress(SHELL32_h##module, name); \
79 if (!func) return fail; \
83 /* Function pointers for GET_FUNC macro */
84 static HMODULE SHELL32_hshlwapi
=NULL
;
85 static HANDLE (WINAPI
*pSHAllocShared
)(LPCVOID
,DWORD
,DWORD
);
86 static LPVOID (WINAPI
*pSHLockShared
)(HANDLE
,DWORD
);
87 static BOOL (WINAPI
*pSHUnlockShared
)(LPVOID
);
88 static BOOL (WINAPI
*pSHFreeShared
)(HANDLE
,DWORD
);
91 /*************************************************************************
92 * ParseFieldA [internal]
94 * copies a field from a ',' delimited string
96 * first field is nField = 1
98 DWORD WINAPI
ParseFieldA(
104 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src
),nField
,dst
,len
);
106 if (!src
|| !src
[0] || !dst
|| !len
)
109 /* skip n fields delimited by ',' */
112 if (*src
=='\0') return FALSE
;
113 if (*(src
++)==',') nField
--;
116 /* copy part till the next ',' to dst */
117 while ( *src
!='\0' && *src
!=',' && (len
--)>0 ) *(dst
++)=*(src
++);
119 /* finalize the string */
125 /*************************************************************************
126 * ParseFieldW [internal]
128 * copies a field from a ',' delimited string
130 * first field is nField = 1
132 DWORD WINAPI
ParseFieldW(LPCWSTR src
, DWORD nField
, LPWSTR dst
, DWORD len
)
134 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n", debugstr_w(src
), nField
, dst
, len
);
136 if (!src
|| !src
[0] || !dst
|| !len
)
139 /* skip n fields delimited by ',' */
142 if (*src
== 0x0) return FALSE
;
143 if (*src
++ == ',') nField
--;
146 /* copy part till the next ',' to dst */
147 while ( *src
!= 0x0 && *src
!= ',' && (len
--)>0 ) *(dst
++) = *(src
++);
149 /* finalize the string */
155 /*************************************************************************
156 * ParseField [SHELL32.58]
158 DWORD WINAPI
ParseFieldAW(LPCVOID src
, DWORD nField
, LPVOID dst
, DWORD len
)
160 if (SHELL_OsIsUnicode())
161 return ParseFieldW(src
, nField
, dst
, len
);
162 return ParseFieldA(src
, nField
, dst
, len
);
165 /*************************************************************************
166 * GetFileNameFromBrowse [SHELL32.63]
169 BOOL WINAPI
GetFileNameFromBrowse(
173 LPCSTR lpstrInitialDir
,
179 FARPROC pGetOpenFileNameA
;
183 TRACE("%p, %s, %ld, %s, %s, %s, %s)\n",
184 hwndOwner
, lpstrFile
, nMaxFile
, lpstrInitialDir
, lpstrDefExt
,
185 lpstrFilter
, lpstrTitle
);
187 hmodule
= LoadLibraryA("comdlg32.dll");
188 if(!hmodule
) return FALSE
;
189 pGetOpenFileNameA
= GetProcAddress(hmodule
, "GetOpenFileNameA");
190 if(!pGetOpenFileNameA
)
192 FreeLibrary(hmodule
);
196 memset(&ofn
, 0, sizeof(ofn
));
198 ofn
.lStructSize
= sizeof(ofn
);
199 ofn
.hwndOwner
= hwndOwner
;
200 ofn
.lpstrFilter
= lpstrFilter
;
201 ofn
.lpstrFile
= lpstrFile
;
202 ofn
.nMaxFile
= nMaxFile
;
203 ofn
.lpstrInitialDir
= lpstrInitialDir
;
204 ofn
.lpstrTitle
= lpstrTitle
;
205 ofn
.lpstrDefExt
= lpstrDefExt
;
206 ofn
.Flags
= OFN_EXPLORER
| OFN_HIDEREADONLY
| OFN_FILEMUSTEXIST
;
207 ret
= pGetOpenFileNameA(&ofn
);
209 FreeLibrary(hmodule
);
213 /*************************************************************************
214 * SHGetSetSettings [SHELL32.68]
216 VOID WINAPI
SHGetSetSettings(LPSHELLSTATE lpss
, DWORD dwMask
, BOOL bSet
)
220 FIXME("%p 0x%08lx TRUE\n", lpss
, dwMask
);
224 SHGetSettings((LPSHELLFLAGSTATE
)lpss
,dwMask
);
228 /*************************************************************************
229 * SHGetSettings [SHELL32.@]
232 * the registry path are for win98 (tested)
233 * and possibly are the same in nt40
236 VOID WINAPI
SHGetSettings(LPSHELLFLAGSTATE lpsfs
, DWORD dwMask
)
240 DWORD dwDataSize
= sizeof (DWORD
);
242 TRACE("(%p 0x%08lx)\n",lpsfs
,dwMask
);
244 if (RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
245 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0))
248 if ( (SSF_SHOWEXTENSIONS
& dwMask
) && !RegQueryValueExA(hKey
, "HideFileExt", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
249 lpsfs
->fShowExtensions
= ((dwData
== 0) ? 0 : 1);
251 if ( (SSF_SHOWINFOTIP
& dwMask
) && !RegQueryValueExA(hKey
, "ShowInfoTip", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
252 lpsfs
->fShowInfoTip
= ((dwData
== 0) ? 0 : 1);
254 if ( (SSF_DONTPRETTYPATH
& dwMask
) && !RegQueryValueExA(hKey
, "DontPrettyPath", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
255 lpsfs
->fDontPrettyPath
= ((dwData
== 0) ? 0 : 1);
257 if ( (SSF_HIDEICONS
& dwMask
) && !RegQueryValueExA(hKey
, "HideIcons", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
258 lpsfs
->fHideIcons
= ((dwData
== 0) ? 0 : 1);
260 if ( (SSF_MAPNETDRVBUTTON
& dwMask
) && !RegQueryValueExA(hKey
, "MapNetDrvBtn", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
261 lpsfs
->fMapNetDrvBtn
= ((dwData
== 0) ? 0 : 1);
263 if ( (SSF_SHOWATTRIBCOL
& dwMask
) && !RegQueryValueExA(hKey
, "ShowAttribCol", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
264 lpsfs
->fShowAttribCol
= ((dwData
== 0) ? 0 : 1);
266 if (((SSF_SHOWALLOBJECTS
| SSF_SHOWSYSFILES
) & dwMask
) && !RegQueryValueExA(hKey
, "Hidden", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
268 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 0;
269 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 0;
271 else if (dwData
== 1)
272 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 1;
273 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 0;
275 else if (dwData
== 2)
276 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 0;
277 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 1;
282 TRACE("-- 0x%04x\n", *(WORD
*)lpsfs
);
285 /*************************************************************************
286 * SHShellFolderView_Message [SHELL32.73]
288 * Send a message to an explorer cabinet window.
291 * hwndCabinet [I] The window containing the shellview to communicate with
292 * dwMessage [I] The SFVM message to send
293 * dwParam [I] Message parameter
299 * Message SFVM_REARRANGE = 1
301 * This message gets sent when a column gets clicked to instruct the
302 * shell view to re-sort the item list. dwParam identifies the column
305 LRESULT WINAPI
SHShellFolderView_Message(
310 FIXME("%p %08x %08lx stub\n",hwndCabinet
, uMessage
, lParam
);
314 /*************************************************************************
315 * RegisterShellHook [SHELL32.181]
317 * Register a shell hook.
320 * hwnd [I] Window handle
321 * dwType [I] Type of hook.
324 * Exported by ordinal
326 BOOL WINAPI
RegisterShellHook(
330 FIXME("(%p,0x%08lx):stub.\n",hWnd
, dwType
);
334 /*************************************************************************
335 * ShellMessageBoxW [SHELL32.182]
337 * See ShellMessageBoxA.
339 int WINAPIV
ShellMessageBoxW(
347 WCHAR szText
[100],szTitle
[100];
348 LPCWSTR pszText
= szText
, pszTitle
= szTitle
, pszTemp
;
352 va_start(args
, uType
);
353 /* wvsprintfA(buf,fmt, args); */
355 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
356 (DWORD
)hInstance
,(DWORD
)hWnd
,lpText
,lpCaption
,uType
);
358 if (!HIWORD(lpCaption
))
359 LoadStringW(hInstance
, (DWORD
)lpCaption
, szTitle
, sizeof(szTitle
)/sizeof(szTitle
[0]));
361 pszTitle
= lpCaption
;
364 LoadStringW(hInstance
, (DWORD
)lpText
, szText
, sizeof(szText
)/sizeof(szText
[0]));
368 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
369 pszText
, 0, 0, (LPWSTR
)&pszTemp
, 0, &args
);
373 ret
= MessageBoxW(hWnd
,pszTemp
,pszTitle
,uType
);
374 LocalFree((HLOCAL
)pszTemp
);
378 /*************************************************************************
379 * ShellMessageBoxA [SHELL32.183]
381 * Format and output an error message.
384 * hInstance [I] Instance handle of message creator
385 * hWnd [I] Window handle of message creator
386 * lpText [I] Resource Id of title or LPSTR
387 * lpCaption [I] Resource Id of title or LPSTR
388 * uType [I] Type of error message
391 * A return value from MessageBoxA().
394 * Exported by ordinal
396 int WINAPIV
ShellMessageBoxA(
404 char szText
[100],szTitle
[100];
405 LPCSTR pszText
= szText
, pszTitle
= szTitle
, pszTemp
;
409 va_start(args
, uType
);
410 /* wvsprintfA(buf,fmt, args); */
412 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
413 (DWORD
)hInstance
,(DWORD
)hWnd
,lpText
,lpCaption
,uType
);
415 if (!HIWORD(lpCaption
))
416 LoadStringA(hInstance
, (DWORD
)lpCaption
, szTitle
, sizeof(szTitle
));
418 pszTitle
= lpCaption
;
421 LoadStringA(hInstance
, (DWORD
)lpText
, szText
, sizeof(szText
));
425 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
426 pszText
, 0, 0, (LPSTR
)&pszTemp
, 0, &args
);
430 ret
= MessageBoxA(hWnd
,pszTemp
,pszTitle
,uType
);
431 LocalFree((HLOCAL
)pszTemp
);
435 /*************************************************************************
436 * SHRegisterDragDrop [SHELL32.86]
439 * exported by ordinal
441 HRESULT WINAPI
SHRegisterDragDrop(
443 LPDROPTARGET pDropTarget
)
445 FIXME("(%p,%p):stub.\n", hWnd
, pDropTarget
);
446 return RegisterDragDrop(hWnd
, pDropTarget
);
449 /*************************************************************************
450 * SHRevokeDragDrop [SHELL32.87]
453 * exported by ordinal
455 HRESULT WINAPI
SHRevokeDragDrop(HWND hWnd
)
457 FIXME("(%p):stub.\n",hWnd
);
458 return RevokeDragDrop(hWnd
);
461 /*************************************************************************
462 * SHDoDragDrop [SHELL32.88]
465 * exported by ordinal
467 HRESULT WINAPI
SHDoDragDrop(
469 LPDATAOBJECT lpDataObject
,
470 LPDROPSOURCE lpDropSource
,
474 FIXME("(%p %p %p 0x%08lx %p):stub.\n",
475 hWnd
, lpDataObject
, lpDropSource
, dwOKEffect
, pdwEffect
);
476 return DoDragDrop(lpDataObject
, lpDropSource
, dwOKEffect
, pdwEffect
);
479 /*************************************************************************
480 * ArrangeWindows [SHELL32.184]
483 WORD WINAPI
ArrangeWindows(
490 FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
491 hwndParent
, dwReserved
, lpRect
, cKids
, lpKids
);
495 /*************************************************************************
496 * SignalFileOpen [SHELL32.103]
499 * exported by ordinal
502 SignalFileOpen (DWORD dwParam1
)
504 FIXME("(0x%08lx):stub.\n", dwParam1
);
509 /*************************************************************************
510 * SHADD_get_policy - helper function for SHAddToRecentDocs
513 * policy [IN] policy name (null termed string) to find
514 * type [OUT] ptr to DWORD to receive type
515 * buffer [OUT] ptr to area to hold data retrieved
516 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
520 * result of the SHQueryValueEx call
522 static INT
SHADD_get_policy(LPSTR policy
, LPDWORD type
, LPVOID buffer
, LPDWORD len
)
527 /* Get the key for the policies location in the registry
529 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
530 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
531 0, KEY_READ
, &Policy_basekey
)) {
533 if (RegOpenKeyExA(HKEY_CURRENT_USER
,
534 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
535 0, KEY_READ
, &Policy_basekey
)) {
536 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
539 return ERROR_FILE_NOT_FOUND
;
543 /* Retrieve the data if it exists
545 ret
= SHQueryValueExA(Policy_basekey
, policy
, 0, type
, buffer
, len
);
546 RegCloseKey(Policy_basekey
);
551 /*************************************************************************
552 * SHADD_compare_mru - helper function for SHAddToRecentDocs
555 * data1 [IN] data being looked for
556 * data2 [IN] data in MRU
557 * cbdata [IN] length from FindMRUData call (not used)
560 * position within MRU list that data was added.
562 static INT CALLBACK
SHADD_compare_mru(LPCVOID data1
, LPCVOID data2
, DWORD cbData
)
564 return lstrcmpiA(data1
, data2
);
567 /*************************************************************************
568 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
571 * mruhandle [IN] handle for created MRU list
572 * doc_name [IN] null termed pure doc name
573 * new_lnk_name [IN] null termed path and file name for .lnk file
574 * buffer [IN/OUT] 2048 byte area to consturct MRU data
575 * len [OUT] ptr to int to receive space used in buffer
578 * position within MRU list that data was added.
580 static INT
SHADD_create_add_mru_data(HANDLE mruhandle
, LPSTR doc_name
, LPSTR new_lnk_name
,
581 LPSTR buffer
, INT
*len
)
587 * RecentDocs MRU data structure seems to be:
588 * +0h document file name w/ terminating 0h
589 * +nh short int w/ size of remaining
590 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
591 * +n+4h 10 bytes zeros - unknown
592 * +n+eh shortcut file name w/ terminating 0h
593 * +n+e+nh 3 zero bytes - unknown
596 /* Create the MRU data structure for "RecentDocs"
599 lstrcpyA(ptr
, doc_name
);
600 ptr
+= (lstrlenA(buffer
) + 1);
601 wlen
= lstrlenA(new_lnk_name
) + 1 + 12;
602 *((short int*)ptr
) = wlen
;
603 ptr
+= 2; /* step past the length */
604 *(ptr
++) = 0x30; /* unknown reason */
605 *(ptr
++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
608 lstrcpyA(ptr
, new_lnk_name
);
609 ptr
+= (lstrlenA(new_lnk_name
) + 1);
614 /* Add the new entry into the MRU list
616 return AddMRUData(mruhandle
, (LPCVOID
)buffer
, *len
);
619 /*************************************************************************
620 * SHAddToRecentDocs [SHELL32.@]
623 * uFlags [IN] SHARD_PATH or SHARD_PIDL
624 * pv [IN] string or pidl, NULL clears the list
629 void WINAPI
SHAddToRecentDocs (UINT uFlags
,LPCVOID pv
)
631 /* If list is a string list lpfnCompare has the following prototype
632 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
633 * for binary lists the prototype is
634 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
635 * where cbData is the no. of bytes to compare.
636 * Need to check what return value means identical - 0?
642 CHAR doc_name
[MAX_PATH
];
643 CHAR link_dir
[MAX_PATH
];
644 CHAR new_lnk_filepath
[MAX_PATH
];
645 CHAR new_lnk_name
[MAX_PATH
];
648 HWND hwnd
= 0; /* FIXME: get real window handle */
650 DWORD data
[64], datalen
, type
;
653 * RecentDocs MRU data structure seems to be:
654 * +0h document file name w/ terminating 0h
655 * +nh short int w/ size of remaining
656 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
657 * +n+4h 10 bytes zeros - unknown
658 * +n+eh shortcut file name w/ terminating 0h
659 * +n+e+nh 3 zero bytes - unknown
662 /* See if we need to do anything.
665 ret
=SHADD_get_policy( "NoRecentDocsHistory", &type
, &data
, &datalen
);
666 if ((ret
> 0) && (ret
!= ERROR_FILE_NOT_FOUND
)) {
667 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret
);
670 if (ret
== ERROR_SUCCESS
) {
671 if (!( (type
== REG_DWORD
) ||
672 ((type
== REG_BINARY
) && (datalen
== 4)) )) {
673 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
678 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data
[0]);
679 /* now test the actual policy value */
684 /* Open key to where the necessary info is
686 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
687 * and the close should be done during the _DETACH. The resulting
688 * key is stored in the DLL global data.
690 if (RegCreateKeyExA(HKEY_CURRENT_USER
,
691 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
692 0, 0, 0, KEY_READ
, 0, &HCUbasekey
, 0)) {
693 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
697 /* Get path to user's "Recent" directory
699 if(SUCCEEDED(SHGetMalloc(&ppM
))) {
700 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd
, CSIDL_RECENT
,
702 SHGetPathFromIDListA(pidl
, link_dir
);
703 IMalloc_Free(ppM
, pidl
);
708 ERR("serious issues 1\n");
710 IMalloc_Release(ppM
);
715 ERR("serious issues 2\n");
717 TRACE("Users Recent dir %s\n", link_dir
);
719 /* If no input, then go clear the lists */
721 /* clear user's Recent dir
724 /* FIXME: delete all files in "link_dir"
726 * while( more files ) {
727 * lstrcpyA(old_lnk_name, link_dir);
728 * PathAppendA(old_lnk_name, filenam);
729 * DeleteFileA(old_lnk_name);
732 FIXME("should delete all files in %s\\ \n", link_dir
);
736 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
737 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
738 * and naturally it fails w/ rc=2. It should do it against
739 * HKEY_CURRENT_USER which is where it is stored, and where
740 * the MRU routines expect it!!!!
742 RegDeleteKeyA(HCUbasekey
, "RecentDocs");
743 RegCloseKey(HCUbasekey
);
747 /* Have data to add, the jobs to be done:
748 * 1. Add document to MRU list in registry "HKCU\Software\
749 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
750 * 2. Add shortcut to document in the user's Recent directory
752 * 3. Add shortcut to Start menu's Documents submenu.
755 /* Get the pure document name from the input
757 if (uFlags
& SHARD_PIDL
) {
758 SHGetPathFromIDListA((LPCITEMIDLIST
) pv
, doc_name
);
761 lstrcpyA(doc_name
, (LPSTR
) pv
);
763 TRACE("full document name %s\n", doc_name
);
764 PathStripPathA(doc_name
);
765 TRACE("stripped document name %s\n", doc_name
);
768 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
771 * doc_name - pure file-spec, no path
772 * link_dir - path to the user's Recent directory
773 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
775 * new_lnk_name- pure file-spec, no path for new .lnk file
777 * - path and file name of new .lnk file
779 CREATEMRULISTA mymru
;
781 INT len
, pos
, bufused
, err
;
786 CHAR old_lnk_name
[MAX_PATH
];
789 mymru
.cbSize
= sizeof(CREATEMRULISTA
);
790 mymru
.nMaxItems
= 15;
791 mymru
.dwFlags
= MRUF_BINARY_LIST
| MRUF_DELAYED_SAVE
;
792 mymru
.hKey
= HCUbasekey
;
793 mymru
.lpszSubKey
= "RecentDocs";
794 mymru
.lpfnCompare
= &SHADD_compare_mru
;
795 mruhandle
= CreateMRUListA(&mymru
);
798 ERR("MRU processing failed, handle zero\n");
799 RegCloseKey(HCUbasekey
);
802 len
= lstrlenA(doc_name
);
803 pos
= FindMRUData(mruhandle
, doc_name
, len
, 0);
805 /* Now get the MRU entry that will be replaced
806 * and delete the .lnk file for it
808 if ((bufused
= EnumMRUListA(mruhandle
, (pos
== -1) ? 14 : pos
,
809 buffer
, 2048)) != -1) {
811 ptr
+= (lstrlenA(buffer
) + 1);
812 slen
= *((short int*)ptr
);
813 ptr
+= 2; /* skip the length area */
814 if (bufused
>= slen
+ (ptr
-buffer
)) {
815 /* buffer size looks good */
816 ptr
+= 12; /* get to string */
817 len
= bufused
- (ptr
-buffer
); /* get length of buf remaining */
818 if ((lstrlenA(ptr
) > 0) && (lstrlenA(ptr
) <= len
-1)) {
819 /* appears to be good string */
820 lstrcpyA(old_lnk_name
, link_dir
);
821 PathAppendA(old_lnk_name
, ptr
);
822 if (!DeleteFileA(old_lnk_name
)) {
823 if ((attr
= GetFileAttributesA(old_lnk_name
)) == INVALID_FILE_ATTRIBUTES
) {
824 if ((err
= GetLastError()) != ERROR_FILE_NOT_FOUND
) {
825 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
826 old_lnk_name
, err
, attr
);
829 TRACE("old .lnk file %s did not exist\n",
834 ERR("Delete for %s failed, attr=%08lx\n",
839 TRACE("deleted old .lnk file %s\n", old_lnk_name
);
845 /* Create usable .lnk file name for the "Recent" directory
847 wsprintfA(new_lnk_name
, "%s.lnk", doc_name
);
848 lstrcpyA(new_lnk_filepath
, link_dir
);
849 PathAppendA(new_lnk_filepath
, new_lnk_name
);
851 olderrormode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
852 while (GetFileAttributesA(new_lnk_filepath
) != INVALID_FILE_ATTRIBUTES
) {
854 wsprintfA(new_lnk_name
, "%s (%u).lnk", doc_name
, i
);
855 lstrcpyA(new_lnk_filepath
, link_dir
);
856 PathAppendA(new_lnk_filepath
, new_lnk_name
);
858 SetErrorMode(olderrormode
);
859 TRACE("new shortcut will be %s\n", new_lnk_filepath
);
861 /* Now add the new MRU entry and data
863 pos
= SHADD_create_add_mru_data(mruhandle
, doc_name
, new_lnk_name
,
865 FreeMRUList(mruhandle
);
866 TRACE("Updated MRU list, new doc is position %d\n", pos
);
869 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
872 * doc_name - pure file-spec, no path
874 * - path and file name of new .lnk file
875 * uFlags[in] - flags on call to SHAddToRecentDocs
876 * pv[in] - document path/pidl on call to SHAddToRecentDocs
878 IShellLinkA
*psl
= NULL
;
879 IPersistFile
*pPf
= NULL
;
882 WCHAR widelink
[MAX_PATH
];
886 hres
= CoCreateInstance( &CLSID_ShellLink
,
888 CLSCTX_INPROC_SERVER
,
891 if(SUCCEEDED(hres
)) {
893 hres
= IShellLinkA_QueryInterface(psl
, &IID_IPersistFile
,
897 ERR("failed QueryInterface for IPersistFile %08lx\n", hres
);
901 /* Set the document path or pidl */
902 if (uFlags
& SHARD_PIDL
) {
903 hres
= IShellLinkA_SetIDList(psl
, (LPCITEMIDLIST
) pv
);
905 hres
= IShellLinkA_SetPath(psl
, (LPCSTR
) pv
);
909 ERR("failed Set{IDList|Path} %08lx\n", hres
);
913 lstrcpyA(desc
, "Shortcut to ");
914 lstrcatA(desc
, doc_name
);
915 hres
= IShellLinkA_SetDescription(psl
, desc
);
918 ERR("failed SetDescription %08lx\n", hres
);
922 MultiByteToWideChar(CP_ACP
, 0, new_lnk_filepath
, -1,
924 /* create the short cut */
925 hres
= IPersistFile_Save(pPf
, widelink
, TRUE
);
928 ERR("failed IPersistFile::Save %08lx\n", hres
);
929 IPersistFile_Release(pPf
);
930 IShellLinkA_Release(psl
);
933 hres
= IPersistFile_SaveCompleted(pPf
, widelink
);
934 IPersistFile_Release(pPf
);
935 IShellLinkA_Release(psl
);
936 TRACE("shortcut %s has been created, result=%08lx\n",
937 new_lnk_filepath
, hres
);
940 ERR("CoCreateInstance failed, hres=%08lx\n", hres
);
948 RegCloseKey(HCUbasekey
);
952 /*************************************************************************
953 * SHCreateShellFolderViewEx [SHELL32.174]
956 * see IShellFolder::CreateViewObject
958 HRESULT WINAPI
SHCreateShellFolderViewEx(
959 LPCSFV psvcbi
, /* [in] shelltemplate struct */
960 IShellView
**ppv
) /* [out] IShellView pointer */
965 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=%p\n",
966 psvcbi
->pshf
, psvcbi
->pidlFolder
, psvcbi
->pfnCallback
,
967 psvcbi
->fvm
, psvcbi
->psvOuter
);
969 psf
= IShellView_Constructor(psvcbi
->pshf
);
972 return E_OUTOFMEMORY
;
974 IShellView_AddRef(psf
);
975 hRes
= IShellView_QueryInterface(psf
, &IID_IShellView
, (LPVOID
*)ppv
);
976 IShellView_Release(psf
);
980 /*************************************************************************
981 * SHWinHelp [SHELL32.127]
984 HRESULT WINAPI
SHWinHelp (DWORD v
, DWORD w
, DWORD x
, DWORD z
)
985 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v
,w
,x
,z
);
988 /*************************************************************************
989 * SHRunControlPanel [SHELL32.161]
992 HRESULT WINAPI
SHRunControlPanel (DWORD x
, DWORD z
)
993 { FIXME("0x%08lx 0x%08lx stub\n",x
,z
);
997 static LPUNKNOWN SHELL32_IExplorerInterface
=0;
998 /*************************************************************************
999 * SHSetInstanceExplorer [SHELL32.176]
1002 * Sets the interface
1004 HRESULT WINAPI
SHSetInstanceExplorer (LPUNKNOWN lpUnknown
)
1005 { TRACE("%p\n", lpUnknown
);
1006 SHELL32_IExplorerInterface
= lpUnknown
;
1007 return (HRESULT
) lpUnknown
;
1009 /*************************************************************************
1010 * SHGetInstanceExplorer [SHELL32.@]
1013 * gets the interface pointer of the explorer and a reference
1015 HRESULT WINAPI
SHGetInstanceExplorer (LPUNKNOWN
* lpUnknown
)
1016 { TRACE("%p\n", lpUnknown
);
1018 *lpUnknown
= SHELL32_IExplorerInterface
;
1020 if (!SHELL32_IExplorerInterface
)
1023 IUnknown_AddRef(SHELL32_IExplorerInterface
);
1026 /*************************************************************************
1027 * SHFreeUnusedLibraries [SHELL32.123]
1032 void WINAPI
SHFreeUnusedLibraries (void)
1036 /*************************************************************************
1037 * DAD_AutoScroll [SHELL32.129]
1040 BOOL WINAPI
DAD_AutoScroll(HWND hwnd
, AUTO_SCROLL_DATA
*samples
, LPPOINT pt
)
1042 FIXME("hwnd = %p %p %p\n",hwnd
,samples
,pt
);
1045 /*************************************************************************
1046 * DAD_DragEnter [SHELL32.130]
1049 BOOL WINAPI
DAD_DragEnter(HWND hwnd
)
1051 FIXME("hwnd = %p\n",hwnd
);
1054 /*************************************************************************
1055 * DAD_DragEnterEx [SHELL32.131]
1058 BOOL WINAPI
DAD_DragEnterEx(HWND hwnd
, POINT p
)
1060 FIXME("hwnd = %p (%ld,%ld)\n",hwnd
,p
.x
,p
.y
);
1063 /*************************************************************************
1064 * DAD_DragMove [SHELL32.134]
1067 BOOL WINAPI
DAD_DragMove(POINT p
)
1069 FIXME("(%ld,%ld)\n",p
.x
,p
.y
);
1072 /*************************************************************************
1073 * DAD_DragLeave [SHELL32.132]
1076 BOOL WINAPI
DAD_DragLeave(VOID
)
1081 /*************************************************************************
1082 * DAD_SetDragImage [SHELL32.136]
1087 BOOL WINAPI
DAD_SetDragImage(
1088 HIMAGELIST himlTrack
,
1091 FIXME("%p %p stub\n",himlTrack
, lppt
);
1094 /*************************************************************************
1095 * DAD_ShowDragImage [SHELL32.137]
1100 BOOL WINAPI
DAD_ShowDragImage(BOOL bShow
)
1102 FIXME("0x%08x stub\n",bShow
);
1106 static const WCHAR szwCabLocation
[] = {
1107 'S','o','f','t','w','a','r','e','\\',
1108 'M','i','c','r','o','s','o','f','t','\\',
1109 'W','i','n','d','o','w','s','\\',
1110 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1111 'E','x','p','l','o','r','e','r','\\',
1112 'C','a','b','i','n','e','t','S','t','a','t','e',0
1115 static const WCHAR szwSettings
[] = { 'S','e','t','t','i','n','g','s',0 };
1117 /*************************************************************************
1118 * ReadCabinetState [SHELL32.651] NT 4.0
1121 BOOL WINAPI
ReadCabinetState(CABINETSTATE
*cs
, int length
)
1126 TRACE("%p %d \n",cs
,length
);
1128 if( (cs
== NULL
) || (length
< (int)sizeof(*cs
)) )
1131 r
= RegOpenKeyW( HKEY_CURRENT_USER
, szwCabLocation
, &hkey
);
1132 if( r
== ERROR_SUCCESS
)
1135 r
= RegQueryValueExW( hkey
, szwSettings
,
1136 NULL
, &type
, (LPBYTE
)cs
, (LPDWORD
)&length
);
1137 RegCloseKey( hkey
);
1141 /* if we can't read from the registry, create default values */
1142 if ( (r
!= ERROR_SUCCESS
) || (cs
->cLength
< sizeof(*cs
)) ||
1143 (cs
->cLength
!= length
) )
1145 ERR("Initializing shell cabinet settings\n");
1146 memset(cs
, 0, sizeof(*cs
));
1147 cs
->cLength
= sizeof(*cs
);
1149 cs
->fFullPathTitle
= FALSE
;
1150 cs
->fSaveLocalView
= TRUE
;
1151 cs
->fNotShell
= FALSE
;
1152 cs
->fSimpleDefault
= TRUE
;
1153 cs
->fDontShowDescBar
= FALSE
;
1154 cs
->fNewWindowMode
= FALSE
;
1155 cs
->fShowCompColor
= FALSE
;
1156 cs
->fDontPrettyNames
= FALSE
;
1157 cs
->fAdminsCreateCommonGroups
= TRUE
;
1158 cs
->fMenuEnumFilter
= 96;
1164 /*************************************************************************
1165 * WriteCabinetState [SHELL32.652] NT 4.0
1168 BOOL WINAPI
WriteCabinetState(CABINETSTATE
*cs
)
1178 r
= RegCreateKeyExW( HKEY_CURRENT_USER
, szwCabLocation
, 0,
1179 NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
);
1180 if( r
== ERROR_SUCCESS
)
1182 r
= RegSetValueExW( hkey
, szwSettings
, 0,
1183 REG_BINARY
, (LPBYTE
) cs
, cs
->cLength
);
1185 RegCloseKey( hkey
);
1188 return (r
==ERROR_SUCCESS
);
1191 /*************************************************************************
1192 * FileIconInit [SHELL32.660]
1195 BOOL WINAPI
FileIconInit(BOOL bFullInit
)
1196 { FIXME("(%s)\n", bFullInit
? "true" : "false");
1199 /*************************************************************************
1200 * IsUserAdmin [SHELL32.680] NT 4.0
1203 HRESULT WINAPI
IsUserAdmin(void)
1208 /*************************************************************************
1209 * SHAllocShared [SHELL32.520]
1211 * See shlwapi.SHAllocShared
1213 HANDLE WINAPI
SHAllocShared(LPVOID lpvData
, DWORD dwSize
, DWORD dwProcId
)
1215 GET_FUNC(pSHAllocShared
, shlwapi
, (char*)7, NULL
);
1216 return pSHAllocShared(lpvData
, dwSize
, dwProcId
);
1219 /*************************************************************************
1220 * SHLockShared [SHELL32.521]
1222 * See shlwapi.SHLockShared
1224 LPVOID WINAPI
SHLockShared(HANDLE hShared
, DWORD dwProcId
)
1226 GET_FUNC(pSHLockShared
, shlwapi
, (char*)8, NULL
);
1227 return pSHLockShared(hShared
, dwProcId
);
1230 /*************************************************************************
1231 * SHUnlockShared [SHELL32.522]
1233 * See shlwapi.SHUnlockShared
1235 BOOL WINAPI
SHUnlockShared(LPVOID lpView
)
1237 GET_FUNC(pSHUnlockShared
, shlwapi
, (char*)9, FALSE
);
1238 return pSHUnlockShared(lpView
);
1241 /*************************************************************************
1242 * SHFreeShared [SHELL32.523]
1244 * See shlwapi.SHFreeShared
1246 BOOL WINAPI
SHFreeShared(HANDLE hShared
, DWORD dwProcId
)
1248 GET_FUNC(pSHFreeShared
, shlwapi
, (char*)10, FALSE
);
1249 return pSHFreeShared(hShared
, dwProcId
);
1252 /*************************************************************************
1253 * SetAppStartingCursor [SHELL32.99]
1255 HRESULT WINAPI
SetAppStartingCursor(HWND u
, DWORD v
)
1256 { FIXME("hwnd=%p 0x%04lx stub\n",u
,v
);
1259 /*************************************************************************
1260 * SHLoadOLE [SHELL32.151]
1263 HRESULT WINAPI
SHLoadOLE(LPARAM lParam
)
1264 { FIXME("0x%04lx stub\n",lParam
);
1267 /*************************************************************************
1268 * DriveType [SHELL32.64]
1271 HRESULT WINAPI
DriveType(DWORD u
)
1272 { FIXME("0x%04lx stub\n",u
);
1275 /*************************************************************************
1276 * SHAbortInvokeCommand [SHELL32.198]
1279 HRESULT WINAPI
SHAbortInvokeCommand(void)
1283 /*************************************************************************
1284 * SHOutOfMemoryMessageBox [SHELL32.126]
1287 int WINAPI
SHOutOfMemoryMessageBox(
1292 FIXME("%p %s 0x%08x stub\n",hwndOwner
, lpCaption
, uType
);
1295 /*************************************************************************
1296 * SHFlushClipboard [SHELL32.121]
1299 HRESULT WINAPI
SHFlushClipboard(void)
1304 /*************************************************************************
1305 * SHWaitForFileToOpen [SHELL32.97]
1308 BOOL WINAPI
SHWaitForFileToOpen(
1313 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl
, dwFlags
, dwTimeout
);
1317 /************************************************************************
1320 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1321 * second one could be a size (0x0c). The size is the same as the structure saved to
1322 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1323 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1325 HRESULT WINAPI
shell32_654 (CABINETSTATE
*cs
, int length
)
1327 TRACE("%p %d\n",cs
,length
);
1328 return ReadCabinetState(cs
,length
);
1331 /************************************************************************
1332 * RLBuildListOfPaths [SHELL32.146]
1337 DWORD WINAPI
RLBuildListOfPaths (void)
1341 /************************************************************************
1342 * SHValidateUNC [SHELL32.173]
1345 HRESULT WINAPI
SHValidateUNC (DWORD x
, DWORD y
, DWORD z
)
1347 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x
,y
,z
);
1351 /************************************************************************
1352 * DoEnvironmentSubstA [SHELL32.@]
1355 HRESULT WINAPI
DoEnvironmentSubstA(LPSTR x
, LPSTR y
)
1357 FIXME("(%s, %s) stub\n", debugstr_a(x
), debugstr_a(y
));
1361 /************************************************************************
1362 * DoEnvironmentSubstW [SHELL32.@]
1365 HRESULT WINAPI
DoEnvironmentSubstW(LPWSTR x
, LPWSTR y
)
1367 FIXME("(%s, %s): stub\n", debugstr_w(x
), debugstr_w(y
));
1371 /************************************************************************
1372 * DoEnvironmentSubst [SHELL32.53]
1375 HRESULT WINAPI
DoEnvironmentSubstAW(LPVOID x
, LPVOID y
)
1377 if (SHELL_OsIsUnicode())
1378 return DoEnvironmentSubstW(x
, y
);
1379 return DoEnvironmentSubstA(x
, y
);
1382 /*************************************************************************
1385 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1386 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1390 BOOL WINAPI
shell32_243(DWORD a
, DWORD b
)
1395 /*************************************************************************
1398 DWORD WINAPI
SHELL32_714(LPVOID x
)
1400 FIXME("(%s)stub\n", debugstr_w(x
));
1404 /*************************************************************************
1405 * SHAddFromPropSheetExtArray [SHELL32.167]
1407 DWORD WINAPI
SHAddFromPropSheetExtArray(DWORD a
, DWORD b
, DWORD c
)
1409 FIXME("(%08lx,%08lx,%08lx)stub\n", a
, b
, c
);
1413 /*************************************************************************
1414 * SHCreatePropSheetExtArray [SHELL32.168]
1416 DWORD WINAPI
SHCreatePropSheetExtArray(DWORD a
, LPCSTR b
, DWORD c
)
1418 FIXME("(%08lx,%s,%08lx)stub\n", a
, debugstr_a(b
), c
);
1422 /*************************************************************************
1423 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1425 DWORD WINAPI
SHReplaceFromPropSheetExtArray(DWORD a
, DWORD b
, DWORD c
, DWORD d
)
1427 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a
, b
, c
, d
);
1431 /*************************************************************************
1432 * SHDestroyPropSheetExtArray [SHELL32.169]
1434 DWORD WINAPI
SHDestroyPropSheetExtArray(DWORD a
)
1436 FIXME("(%08lx)stub\n", a
);
1440 /*************************************************************************
1441 * CIDLData_CreateFromIDArray [SHELL32.83]
1443 * Create IDataObject from PIDLs??
1445 HRESULT WINAPI
CIDLData_CreateFromIDArray(
1446 LPCITEMIDLIST pidlFolder
,
1448 LPCITEMIDLIST
*lppidlFiles
,
1449 LPDATAOBJECT
*ppdataObject
)
1452 HWND hwnd
= 0; /*FIXME: who should be hwnd of owner? set to desktop */
1454 TRACE("(%p, %ld, %p, %p)\n", pidlFolder
, cpidlFiles
, lppidlFiles
, ppdataObject
);
1458 for (i
=0; i
<cpidlFiles
; i
++) pdump (lppidlFiles
[i
]);
1460 *ppdataObject
= IDataObject_Constructor( hwnd
, pidlFolder
,
1461 lppidlFiles
, cpidlFiles
);
1462 if (*ppdataObject
) return S_OK
;
1463 return E_OUTOFMEMORY
;
1466 /*************************************************************************
1467 * SHCreateStdEnumFmtEtc [SHELL32.74]
1472 HRESULT WINAPI
SHCreateStdEnumFmtEtc(
1474 const FORMATETC
*lpFormats
,
1475 LPENUMFORMATETC
*ppenumFormatetc
)
1477 IEnumFORMATETC
*pef
;
1479 TRACE("cf=%ld fe=%p pef=%p\n", cFormats
, lpFormats
, ppenumFormatetc
);
1481 pef
= IEnumFORMATETC_Constructor(cFormats
, lpFormats
);
1483 return E_OUTOFMEMORY
;
1485 IEnumFORMATETC_AddRef(pef
);
1486 hRes
= IEnumFORMATETC_QueryInterface(pef
, &IID_IEnumFORMATETC
, (LPVOID
*)ppenumFormatetc
);
1487 IEnumFORMATETC_Release(pef
);
1493 /*************************************************************************
1494 * SHELL32_256 (SHELL32.256)
1496 HRESULT WINAPI
SHELL32_256(LPDWORD lpdw0
, LPDWORD lpdw1
)
1500 FIXME("stub %p 0x%08lx %p\n", lpdw0
, lpdw0
? *lpdw0
: 0, lpdw1
);
1502 if (!lpdw0
|| *lpdw0
!= 0x10)
1506 LPVOID lpdata
= 0;/*LocalAlloc(GMEM_ZEROINIT, 0x4E4);*/
1509 ret
= E_OUTOFMEMORY
;
1512 /* Initialize and return unknown lpdata structure */
1519 /*************************************************************************
1520 * SHFindFiles (SHELL32.90)
1522 BOOL WINAPI
SHFindFiles( LPCITEMIDLIST pidlFolder
, LPCITEMIDLIST pidlSaveFile
)
1524 FIXME("%p %p\n", pidlFolder
, pidlSaveFile
);