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
12 #include "debugtools.h"
16 #include "wine/obj_base.h"
20 #include "shell32_main.h"
21 #include "undocshell.h"
25 DEFAULT_DEBUG_CHANNEL(shell
);
26 DECLARE_DEBUG_CHANNEL(pidl
);
28 /*************************************************************************
29 * ParseFieldA [internal]
31 * copies a field from a ',' delimited string
33 * first field is nField = 1
35 DWORD WINAPI
ParseFieldA(
41 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src
),nField
,dst
,len
);
43 if (!src
|| !src
[0] || !dst
|| !len
)
46 /* skip n fields delimited by ',' */
49 if (*src
=='\0') return FALSE
;
50 if (*(src
++)==',') nField
--;
53 /* copy part till the next ',' to dst */
54 while ( *src
!='\0' && *src
!=',' && (len
--)>0 ) *(dst
++)=*(src
++);
56 /* finalize the string */
62 /*************************************************************************
63 * ParseFieldW [internal]
65 * copies a field from a ',' delimited string
67 * first field is nField = 1
69 DWORD WINAPI
ParseFieldW(LPCWSTR src
, DWORD nField
, LPWSTR dst
, DWORD len
)
71 FIXME("(%s,0x%08lx,%p,%ld) stub\n",
72 debugstr_w(src
), nField
, dst
, len
);
76 /*************************************************************************
77 * ParseField [SHELL32.58]
79 DWORD WINAPI
ParseFieldAW(LPCVOID src
, DWORD nField
, LPVOID dst
, DWORD len
)
81 if (SHELL_OsIsUnicode())
82 return ParseFieldW(src
, nField
, dst
, len
);
83 return ParseFieldA(src
, nField
, dst
, len
);
86 /*************************************************************************
87 * GetFileNameFromBrowse [SHELL32.63]
90 BOOL WINAPI
GetFileNameFromBrowse(
94 LPCSTR lpstrInitialDir
,
99 FIXME("(%04x,%s,%ld,%s,%s,%s,%s):stub.\n",
100 hwndOwner
, lpstrFile
, nMaxFile
, lpstrInitialDir
, lpstrDefExt
,
101 lpstrFilter
, lpstrTitle
);
103 /* puts up a Open Dialog and requests input into targetbuf */
104 /* OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_FILEMUSTEXIST|OFN_unknown */
105 strcpy(lpstrFile
,"x:\\dummy.exe");
109 /*************************************************************************
110 * SHGetSetSettings [SHELL32.68]
112 VOID WINAPI
SHGetSetSettings(DWORD x
, DWORD y
, DWORD z
)
114 FIXME("0x%08lx 0x%08lx 0x%08lx\n", x
, y
, z
);
117 /*************************************************************************
118 * SHGetSettings [SHELL32.@]
121 * the registry path are for win98 (tested)
122 * and possibly are the same in nt40
125 VOID WINAPI
SHGetSettings(LPSHELLFLAGSTATE lpsfs
, DWORD dwMask
)
129 DWORD dwDataSize
= sizeof (DWORD
);
131 TRACE("(%p 0x%08lx)\n",lpsfs
,dwMask
);
133 if (RegCreateKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
134 0, 0, 0, KEY_ALL_ACCESS
, 0, &hKey
, 0))
137 if ( (SSF_SHOWEXTENSIONS
& dwMask
) && !RegQueryValueExA(hKey
, "HideFileExt", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
138 lpsfs
->fShowExtensions
= ((dwData
== 0) ? 0 : 1);
140 if ( (SSF_SHOWINFOTIP
& dwMask
) && !RegQueryValueExA(hKey
, "ShowInfoTip", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
141 lpsfs
->fShowInfoTip
= ((dwData
== 0) ? 0 : 1);
143 if ( (SSF_DONTPRETTYPATH
& dwMask
) && !RegQueryValueExA(hKey
, "DontPrettyPath", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
144 lpsfs
->fDontPrettyPath
= ((dwData
== 0) ? 0 : 1);
146 if ( (SSF_HIDEICONS
& dwMask
) && !RegQueryValueExA(hKey
, "HideIcons", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
147 lpsfs
->fHideIcons
= ((dwData
== 0) ? 0 : 1);
149 if ( (SSF_MAPNETDRVBUTTON
& dwMask
) && !RegQueryValueExA(hKey
, "MapNetDrvBtn", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
150 lpsfs
->fMapNetDrvBtn
= ((dwData
== 0) ? 0 : 1);
152 if ( (SSF_SHOWATTRIBCOL
& dwMask
) && !RegQueryValueExA(hKey
, "ShowAttribCol", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
153 lpsfs
->fShowAttribCol
= ((dwData
== 0) ? 0 : 1);
155 if (((SSF_SHOWALLOBJECTS
| SSF_SHOWSYSFILES
) & dwMask
) && !RegQueryValueExA(hKey
, "Hidden", 0, 0, (LPBYTE
)&dwData
, &dwDataSize
))
157 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 0;
158 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 0;
160 else if (dwData
== 1)
161 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 1;
162 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 0;
164 else if (dwData
== 2)
165 { if (SSF_SHOWALLOBJECTS
& dwMask
) lpsfs
->fShowAllObjects
= 0;
166 if (SSF_SHOWSYSFILES
& dwMask
) lpsfs
->fShowSysFiles
= 1;
171 TRACE("-- 0x%04x\n", *(WORD
*)lpsfs
);
174 /*************************************************************************
175 * SHShellFolderView_Message [SHELL32.73]
178 * hwndCabinet defines the explorer cabinet window that contains the
179 * shellview you need to communicate with
180 * uMsg identifying the SFVM enum to perform
184 * Message SFVM_REARRANGE = 1
185 * This message gets sent when a column gets clicked to instruct the
186 * shell view to re-sort the item list. lParam identifies the column
189 int WINAPI
SHShellFolderView_Message(
194 FIXME("%04x %08lx %08lx stub\n",hwndCabinet
, dwMessage
, dwParam
);
198 /*************************************************************************
199 * RegisterShellHook [SHELL32.181]
202 * hwnd [I] window handle
206 * exported by ordinal
208 BOOL WINAPI
RegisterShellHook(
212 FIXME("(0x%08x,0x%08lx):stub.\n",hWnd
, dwType
);
215 /*************************************************************************
216 * ShellMessageBoxW [SHELL32.182]
218 * Format and output errormessage.
220 * idText resource ID of title or LPSTR
221 * idTitle resource ID of title or LPSTR
224 * exported by ordinal
226 int WINAPIV
ShellMessageBoxW(
234 WCHAR szText
[100],szTitle
[100];
235 LPCWSTR pszText
= szText
, pszTitle
= szTitle
, pszTemp
;
239 va_start(args
, uType
);
240 /* wvsprintfA(buf,fmt, args); */
242 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
243 (DWORD
)hInstance
,(DWORD
)hWnd
,lpText
,lpCaption
,uType
);
245 if (!HIWORD(lpCaption
))
246 LoadStringW(hInstance
, (DWORD
)lpCaption
, szTitle
, sizeof(szTitle
)/sizeof(szTitle
[0]));
248 pszTitle
= lpCaption
;
251 LoadStringW(hInstance
, (DWORD
)lpText
, szText
, sizeof(szText
)/sizeof(szText
[0]));
255 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
256 pszText
, 0, 0, (LPWSTR
)&pszTemp
, 0, &args
);
260 ret
= MessageBoxW(hWnd
,pszTemp
,pszTitle
,uType
);
261 LocalFree((HLOCAL
)pszTemp
);
265 /*************************************************************************
266 * ShellMessageBoxA [SHELL32.183]
268 int WINAPIV
ShellMessageBoxA(
276 char szText
[100],szTitle
[100];
277 LPCSTR pszText
= szText
, pszTitle
= szTitle
, pszTemp
;
281 va_start(args
, uType
);
282 /* wvsprintfA(buf,fmt, args); */
284 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
285 (DWORD
)hInstance
,(DWORD
)hWnd
,lpText
,lpCaption
,uType
);
287 if (!HIWORD(lpCaption
))
288 LoadStringA(hInstance
, (DWORD
)lpCaption
, szTitle
, sizeof(szTitle
));
290 pszTitle
= lpCaption
;
293 LoadStringA(hInstance
, (DWORD
)lpText
, szText
, sizeof(szText
));
297 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_STRING
,
298 pszText
, 0, 0, (LPSTR
)&pszTemp
, 0, &args
);
302 ret
= MessageBoxA(hWnd
,pszTemp
,pszTitle
,uType
);
303 LocalFree((HLOCAL
)pszTemp
);
307 /*************************************************************************
308 * SHFree [SHELL32.195]
311 * free_ptr() - frees memory using IMalloc
312 * exported by ordinal
315 void WINAPI
SHFree(LPVOID x
)
318 WORD len
= *(LPWORD
)((LPBYTE
)x
-2);
320 if ( *(LPWORD
)((LPBYTE
)x
+len
) != 0x7384)
323 if ( (*(LPWORD
)((LPBYTE
)x
-4)) != 0x8271)
326 memset((LPBYTE
)x
-4, 0xde, len
+6);
328 TRACE("%p len=%u\n",x
, len
);
334 HeapFree(GetProcessHeap(), 0, x
);
337 /*************************************************************************
338 * SHAlloc [SHELL32.196]
341 * void *task_alloc(DWORD len), uses SHMalloc allocator
342 * exported by ordinal
344 LPVOID WINAPI
SHAlloc(DWORD len
)
349 ret
= (LPVOID
) HeapAlloc(GetProcessHeap(),0,len
+6);
351 ret
= (LPVOID
) HeapAlloc(GetProcessHeap(),0,len
);
355 *(LPWORD
)(ret
) = 0x8271;
356 *(LPWORD
)(ret
+2) = (WORD
)len
;
357 *(LPWORD
)(ret
+4+len
) = 0x7384;
359 memset(ret
, 0xdf, len
);
361 TRACE("%lu bytes at %p\n",len
, ret
);
365 /*************************************************************************
366 * SHRegisterDragDrop [SHELL32.86]
369 * exported by ordinal
371 HRESULT WINAPI
SHRegisterDragDrop(
373 LPDROPTARGET pDropTarget
)
375 FIXME("(0x%08x,%p):stub.\n", hWnd
, pDropTarget
);
376 if (GetShellOle()) return pRegisterDragDrop(hWnd
, pDropTarget
);
380 /*************************************************************************
381 * SHRevokeDragDrop [SHELL32.87]
384 * exported by ordinal
386 HRESULT WINAPI
SHRevokeDragDrop(HWND hWnd
)
388 FIXME("(0x%08x):stub.\n",hWnd
);
392 /*************************************************************************
393 * SHDoDragDrop [SHELL32.88]
396 * exported by ordinal
398 HRESULT WINAPI
SHDoDragDrop(
400 LPDATAOBJECT lpDataObject
,
401 LPDROPSOURCE lpDropSource
,
405 FIXME("(0x%04x %p %p 0x%08lx %p):stub.\n",
406 hWnd
, lpDataObject
, lpDropSource
, dwOKEffect
, pdwEffect
);
410 /*************************************************************************
411 * ArrangeWindows [SHELL32.184]
414 WORD WINAPI
ArrangeWindows(
421 FIXME("(0x%08x 0x%08lx %p 0x%04x %p):stub.\n",
422 hwndParent
, dwReserved
, lpRect
, cKids
, lpKids
);
426 /*************************************************************************
427 * SignalFileOpen [SHELL32.103]
430 * exported by ordinal
433 SignalFileOpen (DWORD dwParam1
)
435 FIXME("(0x%08lx):stub.\n", dwParam1
);
440 /*************************************************************************
441 * SHADD_get_policy - helper function for SHAddToRecentDocs
444 * policy [IN] policy name (null termed string) to find
445 * type [OUT] ptr to DWORD to receive type
446 * buffer [OUT] ptr to area to hold data retrieved
447 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
451 * result of the SHQueryValueEx call
453 static INT
SHADD_get_policy(LPSTR policy
, LPDWORD type
, LPVOID buffer
, LPDWORD len
)
458 /* Get the key for the policies location in the registry
460 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE
,
461 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
462 0, KEY_READ
, &Policy_basekey
)) {
464 if (RegOpenKeyExA(HKEY_CURRENT_USER
,
465 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
466 0, KEY_READ
, &Policy_basekey
)) {
467 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
470 return ERROR_FILE_NOT_FOUND
;
474 /* Retrieve the data if it exists
476 ret
= SHQueryValueExA(Policy_basekey
, policy
, 0, type
, buffer
, len
);
477 RegCloseKey(Policy_basekey
);
482 /*************************************************************************
483 * SHADD_compare_mru - helper function for SHAddToRecentDocs
486 * data1 [IN] data being looked for
487 * data2 [IN] data in MRU
488 * cbdata [IN] length from FindMRUData call (not used)
491 * position within MRU list that data was added.
493 static INT CALLBACK
SHADD_compare_mru(LPCVOID data1
, LPCVOID data2
, DWORD cbData
)
495 return lstrcmpiA(data1
, data2
);
498 /*************************************************************************
499 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
502 * mruhandle [IN] handle for created MRU list
503 * doc_name [IN] null termed pure doc name
504 * new_lnk_name [IN] null termed path and file name for .lnk file
505 * buffer [IN/OUT] 2048 byte area to consturct MRU data
506 * len [OUT] ptr to int to receive space used in buffer
509 * position within MRU list that data was added.
511 static INT
SHADD_create_add_mru_data(HANDLE mruhandle
, LPSTR doc_name
, LPSTR new_lnk_name
,
512 LPSTR buffer
, INT
*len
)
518 * RecentDocs MRU data structure seems to be:
519 * +0h document file name w/ terminating 0h
520 * +nh short int w/ size of remaining
521 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
522 * +n+4h 10 bytes zeros - unknown
523 * +n+eh shortcut file name w/ terminating 0h
524 * +n+e+nh 3 zero bytes - unknown
527 /* Create the MRU data structure for "RecentDocs"
530 lstrcpyA(ptr
, doc_name
);
531 ptr
+= (lstrlenA(buffer
) + 1);
532 wlen
= lstrlenA(new_lnk_name
) + 1 + 12;
533 *((short int*)ptr
) = wlen
;
534 ptr
+= 2; /* step past the length */
535 *(ptr
++) = 0x30; /* unknown reason */
536 *(ptr
++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
539 lstrcpyA(ptr
, new_lnk_name
);
540 ptr
+= (lstrlenA(new_lnk_name
) + 1);
545 /* Add the new entry into the MRU list
547 return pAddMRUData(mruhandle
, (LPCVOID
)buffer
, *len
);
550 /*************************************************************************
551 * SHAddToRecentDocs [SHELL32.@]
554 * uFlags [IN] SHARD_PATH or SHARD_PIDL
555 * pv [IN] string or pidl, NULL clears the list
560 * FIXME: ?? MSDN shows this as a VOID
562 DWORD WINAPI
SHAddToRecentDocs (UINT uFlags
,LPCVOID pv
)
565 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
566 /* !!! it is in both here and comctl32undoc.c !!! */
567 typedef struct tagCREATEMRULIST
569 DWORD cbSize
; /* size of struct */
570 DWORD nMaxItems
; /* max no. of items in list */
571 DWORD dwFlags
; /* see below */
572 HKEY hKey
; /* root reg. key under which list is saved */
573 LPCSTR lpszSubKey
; /* reg. subkey */
574 PROC lpfnCompare
; /* item compare proc */
575 } CREATEMRULIST
, *LPCREATEMRULIST
;
578 #define MRUF_STRING_LIST 0 /* list will contain strings */
579 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
580 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
582 /* If list is a string list lpfnCompare has the following prototype
583 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
584 * for binary lists the prototype is
585 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
586 * where cbData is the no. of bytes to compare.
587 * Need to check what return value means identical - 0?
593 CHAR doc_name
[MAX_PATH
];
594 CHAR link_dir
[MAX_PATH
];
595 CHAR new_lnk_filepath
[MAX_PATH
];
596 CHAR new_lnk_name
[MAX_PATH
];
599 HWND hwnd
= 0; /* FIXME: get real window handle */
601 DWORD data
[64], datalen
, type
;
604 * RecentDocs MRU data structure seems to be:
605 * +0h document file name w/ terminating 0h
606 * +nh short int w/ size of remaining
607 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
608 * +n+4h 10 bytes zeros - unknown
609 * +n+eh shortcut file name w/ terminating 0h
610 * +n+e+nh 3 zero bytes - unknown
613 /* See if we need to do anything.
616 ret
=SHADD_get_policy( "NoRecentDocsHistory", &type
, &data
, &datalen
);
617 if ((ret
> 0) && (ret
!= ERROR_FILE_NOT_FOUND
)) {
618 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret
);
621 if (ret
== ERROR_SUCCESS
) {
622 if (!( (type
== REG_DWORD
) ||
623 ((type
== REG_BINARY
) && (datalen
== 4)) )) {
624 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
629 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data
[0]);
630 /* now test the actual policy value */
635 /* Open key to where the necessary info is
637 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
638 * and the close should be done during the _DETACH. The resulting
639 * key is stored in the DLL global data.
641 if (RegCreateKeyExA(HKEY_CURRENT_USER
,
642 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
643 0, 0, 0, KEY_READ
, 0, &HCUbasekey
, 0)) {
644 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
648 /* Get path to user's "Recent" directory
650 if(SUCCEEDED(SHGetMalloc(&ppM
))) {
651 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd
, CSIDL_RECENT
,
653 SHGetPathFromIDListA(pidl
, link_dir
);
654 IMalloc_Free(ppM
, pidl
);
659 ERR("serious issues 1\n");
661 IMalloc_Release(ppM
);
666 ERR("serious issues 2\n");
668 TRACE("Users Recent dir %s\n", link_dir
);
670 /* If no input, then go clear the lists */
672 /* clear user's Recent dir
675 /* FIXME: delete all files in "link_dir"
677 * while( more files ) {
678 * lstrcpyA(old_lnk_name, link_dir);
679 * PathAppendA(old_lnk_name, filenam);
680 * DeleteFileA(old_lnk_name);
683 FIXME("should delete all files in %s\\ \n", link_dir
);
687 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
688 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
689 * and naturally it fails w/ rc=2. It should do it against
690 * HKEY_CURRENT_USER which is where it is stored, and where
691 * the MRU routines expect it!!!!
693 RegDeleteKeyA(HCUbasekey
, "RecentDocs");
694 RegCloseKey(HCUbasekey
);
698 /* Have data to add, the jobs to be done:
699 * 1. Add document to MRU list in registry "HKCU\Software\
700 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
701 * 2. Add shortcut to document in the user's Recent directory
703 * 3. Add shortcut to Start menu's Documents submenu.
706 /* Get the pure document name from the input
708 if (uFlags
& SHARD_PIDL
) {
709 SHGetPathFromIDListA((LPCITEMIDLIST
) pv
, doc_name
);
712 lstrcpyA(doc_name
, (LPSTR
) pv
);
714 TRACE("full document name %s\n", doc_name
);
715 PathStripPathA(doc_name
);;
716 TRACE("stripped document name %s\n", doc_name
);
719 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
722 * doc_name - pure file-spec, no path
723 * link_dir - path to the user's Recent directory
724 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
726 * new_lnk_name- pure file-spec, no path for new .lnk file
728 * - path and file name of new .lnk file
732 INT len
, pos
, bufused
, err
;
737 CHAR old_lnk_name
[MAX_PATH
];
740 mymru
.cbSize
= sizeof(CREATEMRULIST
);
741 mymru
.nMaxItems
= 15;
742 mymru
.dwFlags
= MRUF_BINARY_LIST
| MRUF_DELAYED_SAVE
;
743 mymru
.hKey
= HCUbasekey
;
744 mymru
.lpszSubKey
= "RecentDocs";
745 mymru
.lpfnCompare
= &SHADD_compare_mru
;
746 mruhandle
= pCreateMRUListA(&mymru
);
749 ERR("MRU processing failed, handle zero\n");
750 RegCloseKey(HCUbasekey
);
753 len
= lstrlenA(doc_name
);
754 pos
= pFindMRUData(mruhandle
, doc_name
, len
, 0);
756 /* Now get the MRU entry that will be replaced
757 * and delete the .lnk file for it
759 if ((bufused
= pEnumMRUListA(mruhandle
, (pos
== -1) ? 14 : pos
,
760 buffer
, 2048)) != -1) {
762 ptr
+= (lstrlenA(buffer
) + 1);
763 slen
= *((short int*)ptr
);
764 ptr
+= 2; /* skip the length area */
765 if (bufused
>= slen
+ (ptr
-buffer
)) {
766 /* buffer size looks good */
767 ptr
+= 12; /* get to string */
768 len
= bufused
- (ptr
-buffer
); /* get length of buf remaining */
769 if ((lstrlenA(ptr
) > 0) && (lstrlenA(ptr
) <= len
-1)) {
770 /* appears to be good string */
771 lstrcpyA(old_lnk_name
, link_dir
);
772 PathAppendA(old_lnk_name
, ptr
);
773 if (!DeleteFileA(old_lnk_name
)) {
774 if ((attr
= GetFileAttributesA(old_lnk_name
)) == -1) {
775 if ((err
= GetLastError()) != ERROR_FILE_NOT_FOUND
) {
776 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
777 old_lnk_name
, err
, attr
);
780 TRACE("old .lnk file %s did not exist\n",
785 ERR("Delete for %s failed, attr=%08lx\n",
790 TRACE("deleted old .lnk file %s\n", old_lnk_name
);
796 /* Create usable .lnk file name for the "Recent" directory
798 wsprintfA(new_lnk_name
, "%s.lnk", doc_name
);
799 lstrcpyA(new_lnk_filepath
, link_dir
);
800 PathAppendA(new_lnk_filepath
, new_lnk_name
);
802 olderrormode
= SetErrorMode(SEM_FAILCRITICALERRORS
);
803 while (GetFileAttributesA(new_lnk_filepath
) != -1) {
805 wsprintfA(new_lnk_name
, "%s (%u).lnk", doc_name
, i
);
806 lstrcpyA(new_lnk_filepath
, link_dir
);
807 PathAppendA(new_lnk_filepath
, new_lnk_name
);
809 SetErrorMode(olderrormode
);
810 TRACE("new shortcut will be %s\n", new_lnk_filepath
);
812 /* Now add the new MRU entry and data
814 pos
= SHADD_create_add_mru_data(mruhandle
, doc_name
, new_lnk_name
,
816 pFreeMRUListA(mruhandle
);
817 TRACE("Updated MRU list, new doc is position %d\n", pos
);
820 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
823 * doc_name - pure file-spec, no path
825 * - path and file name of new .lnk file
826 * uFlags[in] - flags on call to SHAddToRecentDocs
827 * pv[in] - document path/pidl on call to SHAddToRecentDocs
829 IShellLinkA
*psl
= NULL
;
830 IPersistFile
*pPf
= NULL
;
833 WCHAR widelink
[MAX_PATH
];
837 hres
= CoCreateInstance( &CLSID_ShellLink
,
839 CLSCTX_INPROC_SERVER
,
842 if(SUCCEEDED(hres
)) {
844 hres
= IShellLinkA_QueryInterface(psl
, &IID_IPersistFile
,
848 ERR("failed QueryInterface for IPersistFile %08lx\n", hres
);
852 /* Set the document path or pidl */
853 if (uFlags
& SHARD_PIDL
) {
854 hres
= IShellLinkA_SetIDList(psl
, (LPCITEMIDLIST
) pv
);
856 hres
= IShellLinkA_SetPath(psl
, (LPCSTR
) pv
);
860 ERR("failed Set{IDList|Path} %08lx\n", hres
);
864 lstrcpyA(desc
, "Shortcut to ");
865 lstrcatA(desc
, doc_name
);
866 hres
= IShellLinkA_SetDescription(psl
, desc
);
869 ERR("failed SetDescription %08lx\n", hres
);
873 MultiByteToWideChar(CP_ACP
, 0, new_lnk_filepath
, -1,
875 /* create the short cut */
876 hres
= IPersistFile_Save(pPf
, widelink
, TRUE
);
879 ERR("failed IPersistFile::Save %08lx\n", hres
);
880 IPersistFile_Release(pPf
);
881 IShellLinkA_Release(psl
);
884 hres
= IPersistFile_SaveCompleted(pPf
, widelink
);
885 IPersistFile_Release(pPf
);
886 IShellLinkA_Release(psl
);
887 TRACE("shortcut %s has been created, result=%08lx\n",
888 new_lnk_filepath
, hres
);
891 ERR("CoCreateInstance failed, hres=%08lx\n", hres
);
899 RegCloseKey(HCUbasekey
);
903 /*************************************************************************
904 * SHCreateShellFolderViewEx [SHELL32.174]
907 * see IShellFolder::CreateViewObject
909 HRESULT WINAPI
SHCreateShellFolderViewEx(
910 LPCSHELLFOLDERVIEWINFO psvcbi
, /* [in] shelltemplate struct */
911 LPSHELLVIEW
* ppv
) /* [out] IShellView pointer */
916 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
917 psvcbi
->pshf
, psvcbi
->pidlFolder
, psvcbi
->lpfnCallback
,
918 psvcbi
->uViewMode
, psvcbi
->dwUser
);
920 psf
= IShellView_Constructor(psvcbi
->pshf
);
923 return E_OUTOFMEMORY
;
925 IShellView_AddRef(psf
);
926 hRes
= IShellView_QueryInterface(psf
, &IID_IShellView
, (LPVOID
*)ppv
);
927 IShellView_Release(psf
);
931 /*************************************************************************
932 * SHWinHelp [SHELL32.127]
935 HRESULT WINAPI
SHWinHelp (DWORD v
, DWORD w
, DWORD x
, DWORD z
)
936 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v
,w
,x
,z
);
939 /*************************************************************************
940 * SHRunControlPanel [SHELL32.161]
943 HRESULT WINAPI
SHRunControlPanel (DWORD x
, DWORD z
)
944 { FIXME("0x%08lx 0x%08lx stub\n",x
,z
);
947 /*************************************************************************
948 * ShellExecuteEx [SHELL32.291]
951 BOOL WINAPI
ShellExecuteExAW (LPVOID sei
)
952 { if (SHELL_OsIsUnicode())
953 return ShellExecuteExW (sei
);
954 return ShellExecuteExA (sei
);
956 /*************************************************************************
957 * ShellExecuteExA [SHELL32.292]
959 * placeholder in the commandline:
964 * %I adress of a global item ID (explorer switch /idlist)
965 * %L ??? path/url/current file ???
967 * %* all following parameters (see batfile)
969 BOOL WINAPI
ShellExecuteExA (LPSHELLEXECUTEINFOA sei
)
970 { CHAR szApplicationName
[MAX_PATH
],szCommandline
[MAX_PATH
],szPidl
[20];
973 STARTUPINFOA startup
;
974 PROCESS_INFORMATION info
;
976 WARN("mask=0x%08lx hwnd=0x%04x verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s incomplete\n",
977 sei
->fMask
, sei
->hwnd
, debugstr_a(sei
->lpVerb
),
978 debugstr_a(sei
->lpFile
), debugstr_a(sei
->lpParameters
),
979 debugstr_a(sei
->lpDirectory
), sei
->nShow
,
980 (sei
->fMask
& SEE_MASK_CLASSNAME
) ? debugstr_a(sei
->lpClass
) : "not used");
982 ZeroMemory(szApplicationName
,MAX_PATH
);
984 strcpy(szApplicationName
, sei
->lpFile
);
986 ZeroMemory(szCommandline
,MAX_PATH
);
987 if (sei
->lpParameters
)
988 strcpy(szCommandline
, sei
->lpParameters
);
990 if (sei
->fMask
& (SEE_MASK_CLASSKEY
| SEE_MASK_INVOKEIDLIST
| SEE_MASK_ICON
| SEE_MASK_HOTKEY
|
991 SEE_MASK_CONNECTNETDRV
| SEE_MASK_FLAG_DDEWAIT
|
992 SEE_MASK_DOENVSUBST
| SEE_MASK_FLAG_NO_UI
| SEE_MASK_UNICODE
|
993 SEE_MASK_NO_CONSOLE
| SEE_MASK_ASYNCOK
| SEE_MASK_HMONITOR
))
995 FIXME("flags ignored: 0x%08lx\n", sei
->fMask
);
998 /* launch a document by fileclass like 'Wordpad.Document.1' */
999 if (sei
->fMask
& SEE_MASK_CLASSNAME
)
1001 /* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
1002 /* the commandline contains 'c:\Path\wordpad.exe "%1"' */
1003 HCR_GetExecuteCommand(sei
->lpClass
, (sei
->lpVerb
) ? sei
->lpVerb
: "open", szCommandline
, sizeof(szCommandline
));
1004 /* fixme: get the extension of lpFile, check if it fits to the lpClass */
1005 TRACE("SEE_MASK_CLASSNAME->'%s'\n", szCommandline
);
1008 /* process the IDList */
1009 if ( (sei
->fMask
& SEE_MASK_INVOKEIDLIST
) == SEE_MASK_INVOKEIDLIST
) /*0x0c*/
1011 SHGetPathFromIDListA (sei
->lpIDList
,szApplicationName
);
1012 TRACE("-- idlist=%p (%s)\n", sei
->lpIDList
, szApplicationName
);
1016 if (sei
->fMask
& SEE_MASK_IDLIST
)
1018 pos
= strstr(szCommandline
, "%I");
1022 HGLOBAL hmem
= SHAllocShared ( sei
->lpIDList
, ILGetSize(sei
->lpIDList
), 0);
1023 pv
= SHLockShared(hmem
,0);
1024 sprintf(szPidl
,":%p",pv
);
1027 gap
= strlen(szPidl
);
1028 len
= strlen(pos
)-2;
1029 memmove(pos
+gap
,pos
+2,len
);
1030 memcpy(pos
,szPidl
,gap
);
1036 TRACE("execute:'%s','%s'\n",szApplicationName
, szCommandline
);
1038 if (szCommandline
[0]) {
1039 strcat(szApplicationName
, " ");
1040 strcat(szApplicationName
, szCommandline
);
1043 ZeroMemory(&startup
,sizeof(STARTUPINFOA
));
1044 startup
.cb
= sizeof(STARTUPINFOA
);
1046 if (! CreateProcessA(NULL
, szApplicationName
,
1047 NULL
, NULL
, FALSE
, 0,
1048 NULL
, sei
->lpDirectory
,
1051 sei
->hInstApp
= GetLastError();
1057 /* Give 30 seconds to the app to come up */
1058 if ( WaitForInputIdle ( info
.hProcess
, 30000 ) == 0xFFFFFFFF )
1059 ERR("WaitForInputIdle failed: Error %ld\n", GetLastError() );
1061 if(sei
->fMask
& SEE_MASK_NOCLOSEPROCESS
)
1062 sei
->hProcess
= info
.hProcess
;
1064 CloseHandle( info
.hProcess
);
1065 CloseHandle( info
.hThread
);
1068 /*************************************************************************
1069 * ShellExecuteExW [SHELL32.293]
1072 BOOL WINAPI
ShellExecuteExW (LPSHELLEXECUTEINFOW sei
)
1073 { SHELLEXECUTEINFOA seiA
;
1078 memcpy(&seiA
, sei
, sizeof(SHELLEXECUTEINFOA
));
1081 seiA
.lpVerb
= HEAP_strdupWtoA( GetProcessHeap(), 0, sei
->lpVerb
);
1084 seiA
.lpFile
= HEAP_strdupWtoA( GetProcessHeap(), 0, sei
->lpFile
);
1086 if (sei
->lpParameters
)
1087 seiA
.lpParameters
= HEAP_strdupWtoA( GetProcessHeap(), 0, sei
->lpParameters
);
1089 if (sei
->lpDirectory
)
1090 seiA
.lpDirectory
= HEAP_strdupWtoA( GetProcessHeap(), 0, sei
->lpDirectory
);
1092 if ((sei
->fMask
& SEE_MASK_CLASSNAME
) && sei
->lpClass
)
1093 seiA
.lpClass
= HEAP_strdupWtoA( GetProcessHeap(), 0, sei
->lpClass
);
1095 seiA
.lpClass
= NULL
;
1097 ret
= ShellExecuteExA(&seiA
);
1099 if (seiA
.lpVerb
) HeapFree( GetProcessHeap(), 0, (LPSTR
) seiA
.lpVerb
);
1100 if (seiA
.lpFile
) HeapFree( GetProcessHeap(), 0, (LPSTR
) seiA
.lpFile
);
1101 if (seiA
.lpParameters
) HeapFree( GetProcessHeap(), 0, (LPSTR
) seiA
.lpParameters
);
1102 if (seiA
.lpDirectory
) HeapFree( GetProcessHeap(), 0, (LPSTR
) seiA
.lpDirectory
);
1103 if (seiA
.lpClass
) HeapFree( GetProcessHeap(), 0, (LPSTR
) seiA
.lpClass
);
1108 static LPUNKNOWN SHELL32_IExplorerInterface
=0;
1109 /*************************************************************************
1110 * SHSetInstanceExplorer [SHELL32.176]
1113 * Sets the interface
1115 HRESULT WINAPI
SHSetInstanceExplorer (LPUNKNOWN lpUnknown
)
1116 { TRACE("%p\n", lpUnknown
);
1117 SHELL32_IExplorerInterface
= lpUnknown
;
1118 return (HRESULT
) lpUnknown
;
1120 /*************************************************************************
1121 * SHGetInstanceExplorer [SHELL32.@]
1124 * gets the interface pointer of the explorer and a reference
1126 HRESULT WINAPI
SHGetInstanceExplorer (LPUNKNOWN
* lpUnknown
)
1127 { TRACE("%p\n", lpUnknown
);
1129 *lpUnknown
= SHELL32_IExplorerInterface
;
1131 if (!SHELL32_IExplorerInterface
)
1134 IUnknown_AddRef(SHELL32_IExplorerInterface
);
1137 /*************************************************************************
1138 * SHFreeUnusedLibraries [SHELL32.123]
1143 void WINAPI
SHFreeUnusedLibraries (void)
1147 /*************************************************************************
1148 * DAD_SetDragImage [SHELL32.136]
1153 BOOL WINAPI
DAD_SetDragImage(
1154 HIMAGELIST himlTrack
,
1157 FIXME("%p %p stub\n",himlTrack
, lppt
);
1160 /*************************************************************************
1161 * DAD_ShowDragImage [SHELL32.137]
1166 BOOL WINAPI
DAD_ShowDragImage(BOOL bShow
)
1168 FIXME("0x%08x stub\n",bShow
);
1171 /*************************************************************************
1172 * ReadCabinetState [SHELL32.651] NT 4.0
1175 HRESULT WINAPI
ReadCabinetState(DWORD u
, DWORD v
)
1176 { FIXME("0x%04lx 0x%04lx stub\n",u
,v
);
1179 /*************************************************************************
1180 * WriteCabinetState [SHELL32.652] NT 4.0
1183 HRESULT WINAPI
WriteCabinetState(DWORD u
)
1184 { FIXME("0x%04lx stub\n",u
);
1187 /*************************************************************************
1188 * FileIconInit [SHELL32.660]
1191 BOOL WINAPI
FileIconInit(BOOL bFullInit
)
1192 { FIXME("(%s)\n", bFullInit
? "true" : "false");
1195 /*************************************************************************
1196 * IsUserAdmin [SHELL32.680] NT 4.0
1199 HRESULT WINAPI
IsUserAdmin(void)
1204 /*************************************************************************
1205 * SHAllocShared [SHELL32.520]
1208 * parameter1 is return value from HeapAlloc
1209 * parameter2 is equal to the size allocated with HeapAlloc
1210 * parameter3 is return value from GetCurrentProcessId
1212 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1213 * WM_USER+2 could be the undocumented CWM_SETPATH
1214 * the allocated memory contains a pidl
1216 HGLOBAL WINAPI
SHAllocShared(LPVOID psrc
, DWORD size
, DWORD procID
)
1220 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc
,size
,procID
);
1221 hmem
= GlobalAlloc(GMEM_FIXED
, size
);
1225 pmem
= GlobalLock (hmem
);
1230 memcpy (pmem
, psrc
, size
);
1234 /*************************************************************************
1235 * SHLockShared [SHELL32.521]
1238 * parameter1 is return value from SHAllocShared
1239 * parameter2 is return value from GetCurrentProcessId
1240 * the receiver of (WM_USER+2) tries to lock the HANDLE (?)
1241 * the return value seems to be a memory address
1243 LPVOID WINAPI
SHLockShared(HANDLE hmem
, DWORD procID
)
1244 { TRACE("handle=0x%04x procID=0x%04lx\n",hmem
,procID
);
1245 return GlobalLock(hmem
);
1247 /*************************************************************************
1248 * SHUnlockShared [SHELL32.522]
1251 * parameter1 is return value from SHLockShared
1253 BOOL WINAPI
SHUnlockShared(LPVOID pv
)
1256 return GlobalUnlock((HANDLE
)pv
);
1258 /*************************************************************************
1259 * SHFreeShared [SHELL32.523]
1262 * parameter1 is return value from SHAllocShared
1263 * parameter2 is return value from GetCurrentProcessId
1265 BOOL WINAPI
SHFreeShared(
1269 TRACE("handle=0x%04x 0x%04lx\n",hMem
,pid
);
1270 return GlobalFree(hMem
);
1273 /*************************************************************************
1274 * SetAppStartingCursor [SHELL32.99]
1276 HRESULT WINAPI
SetAppStartingCursor(HWND u
, DWORD v
)
1277 { FIXME("hwnd=0x%04x 0x%04lx stub\n",u
,v
);
1280 /*************************************************************************
1281 * SHLoadOLE [SHELL32.151]
1284 HRESULT WINAPI
SHLoadOLE(DWORD u
)
1285 { FIXME("0x%04lx stub\n",u
);
1288 /*************************************************************************
1289 * DriveType [SHELL32.64]
1292 HRESULT WINAPI
DriveType(DWORD u
)
1293 { FIXME("0x%04lx stub\n",u
);
1296 /*************************************************************************
1297 * SHAbortInvokeCommand [SHELL32.198]
1300 HRESULT WINAPI
SHAbortInvokeCommand(void)
1304 /*************************************************************************
1305 * SHOutOfMemoryMessageBox [SHELL32.126]
1308 int WINAPI
SHOutOfMemoryMessageBox(
1313 FIXME("0x%04x %s 0x%08x stub\n",hwndOwner
, lpCaption
, uType
);
1316 /*************************************************************************
1317 * SHFlushClipboard [SHELL32.121]
1320 HRESULT WINAPI
SHFlushClipboard(void)
1325 /*************************************************************************
1326 * SHWaitForFileToOpen [SHELL32.97]
1329 BOOL WINAPI
SHWaitForFileToOpen(
1334 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl
, dwFlags
, dwTimeout
);
1338 /************************************************************************
1341 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1342 * second one could be a size (0x0c). The size is the same as the structure saved to
1343 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1344 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1346 HRESULT WINAPI
shell32_654 (DWORD x
, DWORD y
)
1347 { FIXME("0x%08lx 0x%08lx stub\n",x
,y
);
1351 /************************************************************************
1352 * RLBuildListOfPaths [SHELL32.146]
1357 DWORD WINAPI
RLBuildListOfPaths (void)
1361 /************************************************************************
1362 * SHValidateUNC [SHELL32.173]
1365 HRESULT WINAPI
SHValidateUNC (DWORD x
, DWORD y
, DWORD z
)
1367 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x
,y
,z
);
1371 /************************************************************************
1372 * DoEnvironmentSubstA [SHELL32.@]
1375 HRESULT WINAPI
DoEnvironmentSubstA(LPSTR x
, LPSTR y
)
1377 FIXME("(%s, %s) stub\n", debugstr_a(x
), debugstr_a(y
));
1381 /************************************************************************
1382 * DoEnvironmentSubstW [SHELL32.@]
1385 HRESULT WINAPI
DoEnvironmentSubstW(LPWSTR x
, LPWSTR y
)
1387 FIXME("(%s, %s): stub\n", debugstr_w(x
), debugstr_w(y
));
1391 /************************************************************************
1392 * DoEnvironmentSubst [SHELL32.53]
1395 HRESULT WINAPI
DoEnvironmentSubstAW(LPVOID x
, LPVOID y
)
1397 if (SHELL_OsIsUnicode())
1398 return DoEnvironmentSubstW(x
, y
);
1399 return DoEnvironmentSubstA(x
, y
);
1402 /*************************************************************************
1405 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1406 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1410 BOOL WINAPI
shell32_243(DWORD a
, DWORD b
)
1415 /*************************************************************************
1418 DWORD WINAPI
SHELL32_714(LPVOID x
)
1420 FIXME("(%s)stub\n", debugstr_w(x
));
1424 /*************************************************************************
1425 * SHAddFromPropSheetExtArray [SHELL32.167]
1427 DWORD WINAPI
SHAddFromPropSheetExtArray(DWORD a
, DWORD b
, DWORD c
)
1429 FIXME("(%08lx,%08lx,%08lx)stub\n", a
, b
, c
);
1433 /*************************************************************************
1434 * SHCreatePropSheetExtArray [SHELL32.168]
1436 DWORD WINAPI
SHCreatePropSheetExtArray(DWORD a
, LPCSTR b
, DWORD c
)
1438 FIXME("(%08lx,%s,%08lx)stub\n", a
, debugstr_a(b
), c
);
1442 /*************************************************************************
1443 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1445 DWORD WINAPI
SHReplaceFromPropSheetExtArray(DWORD a
, DWORD b
, DWORD c
, DWORD d
)
1447 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a
, b
, c
, d
);
1451 /*************************************************************************
1452 * SHDestroyPropSheetExtArray [SHELL32.169]
1454 DWORD WINAPI
SHDestroyPropSheetExtArray(DWORD a
)
1456 FIXME("(%08lx)stub\n", a
);
1460 /*************************************************************************
1461 * CIDLData_CreateFromIDArray [SHELL32.83]
1463 * Create IDataObject from PIDLs??
1465 HRESULT WINAPI
CIDLData_CreateFromIDArray(
1466 LPCITEMIDLIST pidlFolder
,
1468 LPCITEMIDLIST
*lppidlFiles
,
1469 LPDATAOBJECT
*ppdataObject
)
1472 HWND hwnd
= 0; /*FIXME: who should be hwnd of owner? set to desktop */
1475 if (TRACE_ON(shell
)) {
1476 TRACE("(%p, %ld, %p, %p)\n", pidlFolder
, cpidlFiles
,
1477 lppidlFiles
, ppdataObject
);
1478 boldpidl
= TRACE_ON(pidl
);
1479 __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE
, __wine_dbch_shell
, FALSE
);
1480 __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE
, __wine_dbch_pidl
, TRUE
);
1482 for (i
=0; i
<cpidlFiles
; i
++){
1483 pdump (lppidlFiles
[i
]);
1485 __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE
, __wine_dbch_shell
, TRUE
);
1486 __WINE_SET_DEBUGGING(__WINE_DBCL_TRACE
, __wine_dbch_pidl
, boldpidl
);
1488 *ppdataObject
= IDataObject_Constructor( hwnd
, pidlFolder
,
1489 lppidlFiles
, cpidlFiles
);
1490 if (*ppdataObject
) return S_OK
;
1491 return E_OUTOFMEMORY
;