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"
20 #include "shell32_main.h"
21 #include "undocshell.h"
24 DEFAULT_DEBUG_CHANNEL(shell);
25 DECLARE_DEBUG_CHANNEL(pidl);
27 /*************************************************************************
28 * ParseFieldA [internal]
30 * copys a field from a ',' delimited string
32 * first field is nField = 1
34 DWORD WINAPI ParseFieldA(
40 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src),nField,dst,len);
42 if (!src || !src[0] || !dst || !len)
45 /* skip n fields delimited by ',' */
48 if (*src=='\0') return FALSE;
49 if (*(src++)==',') nField--;
52 /* copy part till the next ',' to dst */
53 while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
55 /* finalize the string */
61 /*************************************************************************
62 * ParseFieldW [internal]
64 * copys a field from a ',' delimited string
66 * first field is nField = 1
68 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
70 FIXME("(%s,0x%08lx,%p,%ld) stub\n",
71 debugstr_w(src), nField, dst, len);
75 /*************************************************************************
76 * ParseField [SHELL32.58]
78 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
80 if (SHELL_OsIsUnicode())
81 return ParseFieldW(src, nField, dst, len);
82 return ParseFieldA(src, nField, dst, len);
85 /*************************************************************************
86 * GetFileNameFromBrowse [SHELL32.63]
89 BOOL WINAPI GetFileNameFromBrowse(
93 LPCSTR lpstrInitialDir,
98 FIXME("(%04x,%s,%ld,%s,%s,%s,%s):stub.\n",
99 hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
100 lpstrFilter, lpstrTitle);
102 /* puts up a Open Dialog and requests input into targetbuf */
103 /* OFN_HIDEREADONLY|OFN_NOCHANGEDIR|OFN_FILEMUSTEXIST|OFN_unknown */
104 strcpy(lpstrFile,"x:\\dummy.exe");
108 /*************************************************************************
109 * SHGetSetSettings [SHELL32.68]
111 VOID WINAPI SHGetSetSettings(DWORD x, DWORD y, DWORD z)
113 FIXME("0x%08lx 0x%08lx 0x%08lx\n", x, y, z);
116 /*************************************************************************
117 * SHGetSettings [SHELL32.@]
120 * the registry path are for win98 (tested)
121 * and possibly are the same in nt40
124 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
128 DWORD dwDataSize = sizeof (DWORD);
130 TRACE("(%p 0x%08lx)\n",lpsfs,dwMask);
132 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
133 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
136 if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
137 lpsfs->fShowExtensions = ((dwData == 0) ? 0 : 1);
139 if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
140 lpsfs->fShowInfoTip = ((dwData == 0) ? 0 : 1);
142 if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
143 lpsfs->fDontPrettyPath = ((dwData == 0) ? 0 : 1);
145 if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
146 lpsfs->fHideIcons = ((dwData == 0) ? 0 : 1);
148 if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
149 lpsfs->fMapNetDrvBtn = ((dwData == 0) ? 0 : 1);
151 if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
152 lpsfs->fShowAttribCol = ((dwData == 0) ? 0 : 1);
154 if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
156 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
157 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
159 else if (dwData == 1)
160 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 1;
161 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
163 else if (dwData == 2)
164 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
165 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 1;
170 TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
173 /*************************************************************************
174 * SHShellFolderView_Message [SHELL32.73]
177 * hwndCabinet defines the explorer cabinet window that contains the
178 * shellview you need to communicate with
179 * uMsg identifying the SFVM enum to perform
183 * Message SFVM_REARRANGE = 1
184 * This message gets sent when a column gets clicked to instruct the
185 * shell view to re-sort the item list. lParam identifies the column
188 int WINAPI SHShellFolderView_Message(
193 FIXME("%04x %08lx %08lx stub\n",hwndCabinet, dwMessage, dwParam);
197 /*************************************************************************
198 * RegisterShellHook [SHELL32.181]
201 * hwnd [I] window handle
205 * exported by ordinal
207 BOOL WINAPI RegisterShellHook(
211 FIXME("(0x%08x,0x%08lx):stub.\n",hWnd, dwType);
214 /*************************************************************************
215 * ShellMessageBoxW [SHELL32.182]
217 * Format and output errormessage.
219 * idText resource ID of title or LPSTR
220 * idTitle resource ID of title or LPSTR
223 * exported by ordinal
225 int WINAPIV ShellMessageBoxW(
233 WCHAR szText[100],szTitle[100];
234 LPCWSTR pszText = szText, pszTitle = szTitle, pszTemp;
238 va_start(args, uType);
239 /* wvsprintfA(buf,fmt, args); */
241 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
242 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
244 if (!HIWORD(lpCaption))
245 LoadStringW(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
247 pszTitle = lpCaption;
250 LoadStringW(hInstance, (DWORD)lpText, szText, sizeof(szText)/sizeof(szText[0]));
254 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
255 pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
259 ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
260 LocalFree((HLOCAL)pszTemp);
264 /*************************************************************************
265 * ShellMessageBoxA [SHELL32.183]
267 int WINAPIV ShellMessageBoxA(
275 char szText[100],szTitle[100];
276 LPCSTR pszText = szText, pszTitle = szTitle, pszTemp;
280 va_start(args, uType);
281 /* wvsprintfA(buf,fmt, args); */
283 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
284 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
286 if (!HIWORD(lpCaption))
287 LoadStringA(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle));
289 pszTitle = lpCaption;
292 LoadStringA(hInstance, (DWORD)lpText, szText, sizeof(szText));
296 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
297 pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
301 ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
302 LocalFree((HLOCAL)pszTemp);
306 /*************************************************************************
307 * SHFree [SHELL32.195]
310 * free_ptr() - frees memory using IMalloc
311 * exported by ordinal
314 void WINAPI SHFree(LPVOID x)
317 WORD len = *(LPWORD)((LPBYTE)x-2);
319 if ( *(LPWORD)((LPBYTE)x+len) != 0x7384)
322 if ( (*(LPWORD)((LPBYTE)x-4)) != 0x8271)
325 memset((LPBYTE)x-4, 0xde, len+6);
327 TRACE("%p len=%u\n",x, len);
333 HeapFree(GetProcessHeap(), 0, x);
336 /*************************************************************************
337 * SHAlloc [SHELL32.196]
340 * void *task_alloc(DWORD len), uses SHMalloc allocator
341 * exported by ordinal
343 LPVOID WINAPI SHAlloc(DWORD len)
348 ret = (LPVOID) HeapAlloc(GetProcessHeap(),0,len+6);
350 ret = (LPVOID) HeapAlloc(GetProcessHeap(),0,len);
354 *(LPWORD)(ret) = 0x8271;
355 *(LPWORD)(ret+2) = (WORD)len;
356 *(LPWORD)(ret+4+len) = 0x7384;
358 memset(ret, 0xdf, len);
360 TRACE("%lu bytes at %p\n",len, ret);
364 /*************************************************************************
365 * SHRegisterDragDrop [SHELL32.86]
368 * exported by ordinal
370 HRESULT WINAPI SHRegisterDragDrop(
372 LPDROPTARGET pDropTarget)
374 FIXME("(0x%08x,%p):stub.\n", hWnd, pDropTarget);
375 if (GetShellOle()) return pRegisterDragDrop(hWnd, pDropTarget);
379 /*************************************************************************
380 * SHRevokeDragDrop [SHELL32.87]
383 * exported by ordinal
385 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
387 FIXME("(0x%08x):stub.\n",hWnd);
391 /*************************************************************************
392 * SHDoDragDrop [SHELL32.88]
395 * exported by ordinal
397 HRESULT WINAPI SHDoDragDrop(
399 LPDATAOBJECT lpDataObject,
400 LPDROPSOURCE lpDropSource,
404 FIXME("(0x%04x %p %p 0x%08lx %p):stub.\n",
405 hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
409 /*************************************************************************
410 * ArrangeWindows [SHELL32.184]
413 WORD WINAPI ArrangeWindows(
420 FIXME("(0x%08x 0x%08lx %p 0x%04x %p):stub.\n",
421 hwndParent, dwReserved, lpRect, cKids, lpKids);
425 /*************************************************************************
426 * SignalFileOpen [SHELL32.103]
429 * exported by ordinal
432 SignalFileOpen (DWORD dwParam1)
434 FIXME("(0x%08lx):stub.\n", dwParam1);
439 /*************************************************************************
440 * SHADD_get_policy - helper function for SHAddToRecentDocs
443 * policy [IN] policy name (null termed string) to find
444 * type [OUT] ptr to DWORD to receive type
445 * buffer [OUT] ptr to area to hold data retrieved
446 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
450 * result of the SHQueryValueEx call
452 static INT SHADD_get_policy(LPSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
457 /* Get the key for the policies location in the registry
459 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
460 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
461 0, KEY_READ, &Policy_basekey)) {
463 if (RegOpenKeyExA(HKEY_CURRENT_USER,
464 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
465 0, KEY_READ, &Policy_basekey)) {
466 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
469 return ERROR_FILE_NOT_FOUND;
473 /* Retrieve the data if it exists
475 ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
476 RegCloseKey(Policy_basekey);
481 /*************************************************************************
482 * SHADD_compare_mru - helper function for SHAddToRecentDocs
485 * data1 [IN] data being looked for
486 * data2 [IN] data in MRU
487 * cbdata [IN] length from FindMRUData call (not used)
490 * position within MRU list that data was added.
492 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
494 return lstrcmpiA(data1, data2);
497 /*************************************************************************
498 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
501 * mruhandle [IN] handle for created MRU list
502 * doc_name [IN] null termed pure doc name
503 * new_lnk_name [IN] null termed path and file name for .lnk file
504 * buffer [IN/OUT] 2048 byte area to consturct MRU data
505 * len [OUT] ptr to int to receive space used in buffer
508 * position within MRU list that data was added.
510 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
511 LPSTR buffer, INT *len)
517 * RecentDocs MRU data structure seems to be:
518 * +0h document file name w/ terminating 0h
519 * +nh short int w/ size of remaining
520 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
521 * +n+4h 10 bytes zeros - unknown
522 * +n+eh shortcut file name w/ terminating 0h
523 * +n+e+nh 3 zero bytes - unknown
526 /* Create the MRU data structure for "RecentDocs"
529 lstrcpyA(ptr, doc_name);
530 ptr += (lstrlenA(buffer) + 1);
531 wlen= lstrlenA(new_lnk_name) + 1 + 12;
532 *((short int*)ptr) = wlen;
533 ptr += 2; /* step past the length */
534 *(ptr++) = 0x30; /* unknown reason */
535 *(ptr++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
538 lstrcpyA(ptr, new_lnk_name);
539 ptr += (lstrlenA(new_lnk_name) + 1);
544 /* Add the new entry into the MRU list
546 return pAddMRUData(mruhandle, (LPCVOID)buffer, *len);
549 /*************************************************************************
550 * SHAddToRecentDocs [SHELL32.@]
553 * uFlags [IN] SHARD_PATH or SHARD_PIDL
554 * pv [IN] string or pidl, NULL clears the list
559 * FIXME: ?? MSDN shows this as a VOID
561 DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
564 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
565 /* !!! it is in both here and comctl32undoc.c !!! */
566 typedef struct tagCREATEMRULIST
568 DWORD cbSize; /* size of struct */
569 DWORD nMaxItems; /* max no. of items in list */
570 DWORD dwFlags; /* see below */
571 HKEY hKey; /* root reg. key under which list is saved */
572 LPCSTR lpszSubKey; /* reg. subkey */
573 PROC lpfnCompare; /* item compare proc */
574 } CREATEMRULIST, *LPCREATEMRULIST;
577 #define MRUF_STRING_LIST 0 /* list will contain strings */
578 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
579 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
581 /* If list is a string list lpfnCompare has the following prototype
582 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
583 * for binary lists the prototype is
584 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
585 * where cbData is the no. of bytes to compare.
586 * Need to check what return value means identical - 0?
592 CHAR doc_name[MAX_PATH];
593 CHAR link_dir[MAX_PATH];
594 CHAR new_lnk_filepath[MAX_PATH];
595 CHAR new_lnk_name[MAX_PATH];
598 HWND hwnd = 0; /* FIXME: get real window handle */
600 DWORD data[64], datalen, type;
603 * RecentDocs MRU data structure seems to be:
604 * +0h document file name w/ terminating 0h
605 * +nh short int w/ size of remaining
606 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
607 * +n+4h 10 bytes zeros - unknown
608 * +n+eh shortcut file name w/ terminating 0h
609 * +n+e+nh 3 zero bytes - unknown
612 /* See if we need to do anything.
615 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
616 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
617 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
620 if (ret == ERROR_SUCCESS) {
621 if (!( (type == REG_DWORD) ||
622 ((type == REG_BINARY) && (datalen == 4)) )) {
623 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
628 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
629 /* now test the actual policy value */
634 /* Open key to where the necessary info is
636 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
637 * and the close should be done during the _DETACH. The resulting
638 * key is stored in the DLL global data.
640 if (RegCreateKeyExA(HKEY_CURRENT_USER,
641 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
642 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
643 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
647 /* Get path to user's "Recent" directory
649 if(SUCCEEDED(SHGetMalloc(&ppM))) {
650 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
652 SHGetPathFromIDListA(pidl, link_dir);
653 IMalloc_Free(ppM, pidl);
658 ERR("serious issues 1\n");
660 IMalloc_Release(ppM);
665 ERR("serious issues 2\n");
667 TRACE("Users Recent dir %s\n", link_dir);
669 /* If no input, then go clear the lists */
671 /* clear user's Recent dir
674 /* FIXME: delete all files in "link_dir"
676 * while( more files ) {
677 * lstrcpyA(old_lnk_name, link_dir);
678 * PathAppendA(old_lnk_name, filenam);
679 * DeleteFileA(old_lnk_name);
682 FIXME("should delete all files in %s\\ \n", link_dir);
686 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
687 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
688 * and naturally it fails w/ rc=2. It should do it against
689 * HKEY_CURRENT_USER which is where it is stored, and where
690 * the MRU routines expect it!!!!
692 RegDeleteKeyA(HCUbasekey, "RecentDocs");
693 RegCloseKey(HCUbasekey);
697 /* Have data to add, the jobs to be done:
698 * 1. Add document to MRU list in registry "HKCU\Software\
699 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
700 * 2. Add shortcut to document in the user's Recent directory
702 * 3. Add shortcut to Start menu's Documents submenu.
705 /* Get the pure document name from the input
707 if (uFlags & SHARD_PIDL) {
708 SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
711 lstrcpyA(doc_name, (LPSTR) pv);
713 TRACE("full document name %s\n", doc_name);
714 PathStripPathA(doc_name);;
715 TRACE("stripped document name %s\n", doc_name);
718 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
721 * doc_name - pure file-spec, no path
722 * link_dir - path to the user's Recent directory
723 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
725 * new_lnk_name- pure file-spec, no path for new .lnk file
727 * - path and file name of new .lnk file
731 INT len, pos, bufused, err;
736 CHAR old_lnk_name[MAX_PATH];
739 mymru.cbSize = sizeof(CREATEMRULIST);
740 mymru.nMaxItems = 15;
741 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
742 mymru.hKey = HCUbasekey;
743 mymru.lpszSubKey = "RecentDocs";
744 mymru.lpfnCompare = &SHADD_compare_mru;
745 mruhandle = pCreateMRUListA(&mymru);
748 ERR("MRU processing failed, handle zero\n");
749 RegCloseKey(HCUbasekey);
752 len = lstrlenA(doc_name);
753 pos = pFindMRUData(mruhandle, doc_name, len, 0);
755 /* Now get the MRU entry that will be replaced
756 * and delete the .lnk file for it
758 if ((bufused = pEnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
759 buffer, 2048)) != -1) {
761 ptr += (lstrlenA(buffer) + 1);
762 slen = *((short int*)ptr);
763 ptr += 2; /* skip the length area */
764 if (bufused >= slen + (ptr-buffer)) {
765 /* buffer size looks good */
766 ptr += 12; /* get to string */
767 len = bufused - (ptr-buffer); /* get length of buf remaining */
768 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
769 /* appears to be good string */
770 lstrcpyA(old_lnk_name, link_dir);
771 PathAppendA(old_lnk_name, ptr);
772 if (!DeleteFileA(old_lnk_name)) {
773 if ((attr = GetFileAttributesA(old_lnk_name)) == -1) {
774 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
775 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
776 old_lnk_name, err, attr);
779 TRACE("old .lnk file %s did not exist\n",
784 ERR("Delete for %s failed, attr=%08lx\n",
789 TRACE("deleted old .lnk file %s\n", old_lnk_name);
795 /* Create usable .lnk file name for the "Recent" directory
797 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
798 lstrcpyA(new_lnk_filepath, link_dir);
799 PathAppendA(new_lnk_filepath, new_lnk_name);
801 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
802 while (GetFileAttributesA(new_lnk_filepath) != -1) {
804 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
805 lstrcpyA(new_lnk_filepath, link_dir);
806 PathAppendA(new_lnk_filepath, new_lnk_name);
808 SetErrorMode(olderrormode);
809 TRACE("new shortcut will be %s\n", new_lnk_filepath);
811 /* Now add the new MRU entry and data
813 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
815 pFreeMRUListA(mruhandle);
816 TRACE("Updated MRU list, new doc is position %d\n", pos);
819 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
822 * doc_name - pure file-spec, no path
824 * - path and file name of new .lnk file
825 * uFlags[in] - flags on call to SHAddToRecentDocs
826 * pv[in] - document path/pidl on call to SHAddToRecentDocs
828 IShellLinkA *psl = NULL;
829 IPersistFile *pPf = NULL;
832 WCHAR widelink[MAX_PATH];
836 hres = CoCreateInstance( &CLSID_ShellLink,
838 CLSCTX_INPROC_SERVER,
841 if(SUCCEEDED(hres)) {
843 hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
847 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
851 /* Set the document path or pidl */
852 if (uFlags & SHARD_PIDL) {
853 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
855 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
859 ERR("failed Set{IDList|Path} %08lx\n", hres);
863 lstrcpyA(desc, "Shortcut to ");
864 lstrcatA(desc, doc_name);
865 hres = IShellLinkA_SetDescription(psl, desc);
868 ERR("failed SetDescription %08lx\n", hres);
872 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
874 /* create the short cut */
875 hres = IPersistFile_Save(pPf, widelink, TRUE);
878 ERR("failed IPersistFile::Save %08lx\n", hres);
879 IPersistFile_Release(pPf);
880 IShellLinkA_Release(psl);
883 hres = IPersistFile_SaveCompleted(pPf, widelink);
884 IPersistFile_Release(pPf);
885 IShellLinkA_Release(psl);
886 TRACE("shortcut %s has been created, result=%08lx\n",
887 new_lnk_filepath, hres);
890 ERR("CoCreateInstance failed, hres=%08lx\n", hres);
898 RegCloseKey(HCUbasekey);
902 /*************************************************************************
903 * SHCreateShellFolderViewEx [SHELL32.174]
906 * see IShellFolder::CreateViewObject
908 HRESULT WINAPI SHCreateShellFolderViewEx(
909 LPCSHELLFOLDERVIEWINFO psvcbi, /* [in] shelltemplate struct */
910 LPSHELLVIEW* ppv) /* [out] IShellView pointer */
915 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
916 psvcbi->pshf, psvcbi->pidlFolder, psvcbi->lpfnCallback,
917 psvcbi->uViewMode, psvcbi->dwUser);
919 psf = IShellView_Constructor(psvcbi->pshf);
922 return E_OUTOFMEMORY;
924 IShellView_AddRef(psf);
925 hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
926 IShellView_Release(psf);
930 /*************************************************************************
931 * SHWinHelp [SHELL32.127]
934 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
935 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
938 /*************************************************************************
939 * SHRunControlPanel [SHELL32.161]
942 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
943 { FIXME("0x%08lx 0x%08lx stub\n",x,z);
946 /*************************************************************************
947 * ShellExecuteEx [SHELL32.291]
950 BOOL WINAPI ShellExecuteExAW (LPVOID sei)
951 { if (SHELL_OsIsUnicode())
952 return ShellExecuteExW (sei);
953 return ShellExecuteExA (sei);
955 /*************************************************************************
956 * ShellExecuteExA [SHELL32.292]
958 * placeholder in the commandline:
963 * %I adress of a global item ID (explorer switch /idlist)
964 * %L ??? path/url/current file ???
966 * %* all following parameters (see batfile)
968 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
969 { CHAR szApplicationName[MAX_PATH],szCommandline[MAX_PATH],szPidl[20];
972 STARTUPINFOA startup;
973 PROCESS_INFORMATION info;
975 WARN("mask=0x%08lx hwnd=0x%04x verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s incomplete\n",
976 sei->fMask, sei->hwnd, debugstr_a(sei->lpVerb),
977 debugstr_a(sei->lpFile), debugstr_a(sei->lpParameters),
978 debugstr_a(sei->lpDirectory), sei->nShow,
979 (sei->fMask & SEE_MASK_CLASSNAME) ? debugstr_a(sei->lpClass) : "not used");
981 ZeroMemory(szApplicationName,MAX_PATH);
983 strcpy(szApplicationName, sei->lpFile);
985 ZeroMemory(szCommandline,MAX_PATH);
986 if (sei->lpParameters)
987 strcpy(szCommandline, sei->lpParameters);
989 if (sei->fMask & (SEE_MASK_CLASSKEY | SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
990 SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
991 SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
992 SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
994 FIXME("flags ignored: 0x%08lx\n", sei->fMask);
997 /* launch a document by fileclass like 'Wordpad.Document.1' */
998 if (sei->fMask & SEE_MASK_CLASSNAME)
1000 /* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
1001 /* the commandline contains 'c:\Path\wordpad.exe "%1"' */
1002 HCR_GetExecuteCommand(sei->lpClass, (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
1003 /* fixme: get the extension of lpFile, check if it fits to the lpClass */
1004 TRACE("SEE_MASK_CLASSNAME->'%s'\n", szCommandline);
1007 /* process the IDList */
1008 if ( (sei->fMask & SEE_MASK_INVOKEIDLIST) == SEE_MASK_INVOKEIDLIST) /*0x0c*/
1010 SHGetPathFromIDListA (sei->lpIDList,szApplicationName);
1011 TRACE("-- idlist=%p (%s)\n", sei->lpIDList, szApplicationName);
1015 if (sei->fMask & SEE_MASK_IDLIST )
1017 pos = strstr(szCommandline, "%I");
1021 HGLOBAL hmem = SHAllocShared ( sei->lpIDList, ILGetSize(sei->lpIDList), 0);
1022 pv = SHLockShared(hmem,0);
1023 sprintf(szPidl,":%p",pv );
1026 gap = strlen(szPidl);
1027 len = strlen(pos)-2;
1028 memmove(pos+gap,pos+2,len);
1029 memcpy(pos,szPidl,gap);
1035 TRACE("execute:'%s','%s'\n",szApplicationName, szCommandline);
1037 strcat(szApplicationName, " ");
1038 strcat(szApplicationName, szCommandline);
1040 ZeroMemory(&startup,sizeof(STARTUPINFOA));
1041 startup.cb = sizeof(STARTUPINFOA);
1043 if (! CreateProcessA(NULL, szApplicationName,
1044 NULL, NULL, FALSE, 0,
1045 NULL, NULL, &startup, &info))
1047 sei->hInstApp = GetLastError();
1053 /* Give 30 seconds to the app to come up */
1054 if ( WaitForInputIdle ( info.hProcess, 30000 ) == 0xFFFFFFFF )
1055 ERR("WaitForInputIdle failed: Error %ld\n", GetLastError() );
1057 if(sei->fMask & SEE_MASK_NOCLOSEPROCESS)
1058 sei->hProcess = info.hProcess;
1060 CloseHandle( info.hProcess );
1061 CloseHandle( info.hThread );
1064 /*************************************************************************
1065 * ShellExecuteExW [SHELL32.293]
1068 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
1069 { SHELLEXECUTEINFOA seiA;
1074 memcpy(&seiA, sei, sizeof(SHELLEXECUTEINFOA));
1077 seiA.lpVerb = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpVerb);
1080 seiA.lpFile = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpFile);
1082 if (sei->lpParameters)
1083 seiA.lpParameters = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpParameters);
1085 if (sei->lpDirectory)
1086 seiA.lpDirectory = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpDirectory);
1088 if ((sei->fMask & SEE_MASK_CLASSNAME) && sei->lpClass)
1089 seiA.lpClass = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpClass);
1091 seiA.lpClass = NULL;
1093 ret = ShellExecuteExA(&seiA);
1095 if (seiA.lpVerb) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpVerb );
1096 if (seiA.lpFile) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpFile );
1097 if (seiA.lpParameters) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpParameters );
1098 if (seiA.lpDirectory) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpDirectory );
1099 if (seiA.lpClass) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpClass );
1104 static LPUNKNOWN SHELL32_IExplorerInterface=0;
1105 /*************************************************************************
1106 * SHSetInstanceExplorer [SHELL32.176]
1109 * Sets the interface
1111 HRESULT WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
1112 { TRACE("%p\n", lpUnknown);
1113 SHELL32_IExplorerInterface = lpUnknown;
1114 return (HRESULT) lpUnknown;
1116 /*************************************************************************
1117 * SHGetInstanceExplorer [SHELL32.@]
1120 * gets the interface pointer of the explorer and a reference
1122 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
1123 { TRACE("%p\n", lpUnknown);
1125 *lpUnknown = SHELL32_IExplorerInterface;
1127 if (!SHELL32_IExplorerInterface)
1130 IUnknown_AddRef(SHELL32_IExplorerInterface);
1133 /*************************************************************************
1134 * SHFreeUnusedLibraries [SHELL32.123]
1139 void WINAPI SHFreeUnusedLibraries (void)
1143 /*************************************************************************
1144 * DAD_SetDragImage [SHELL32.136]
1149 BOOL WINAPI DAD_SetDragImage(
1150 HIMAGELIST himlTrack,
1153 FIXME("%p %p stub\n",himlTrack, lppt);
1156 /*************************************************************************
1157 * DAD_ShowDragImage [SHELL32.137]
1162 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1164 FIXME("0x%08x stub\n",bShow);
1167 /*************************************************************************
1168 * ReadCabinetState [SHELL32.651] NT 4.0
1171 HRESULT WINAPI ReadCabinetState(DWORD u, DWORD v)
1172 { FIXME("0x%04lx 0x%04lx stub\n",u,v);
1175 /*************************************************************************
1176 * WriteCabinetState [SHELL32.652] NT 4.0
1179 HRESULT WINAPI WriteCabinetState(DWORD u)
1180 { FIXME("0x%04lx stub\n",u);
1183 /*************************************************************************
1184 * FileIconInit [SHELL32.660]
1187 BOOL WINAPI FileIconInit(BOOL bFullInit)
1188 { FIXME("(%s)\n", bFullInit ? "true" : "false");
1191 /*************************************************************************
1192 * IsUserAdmin [SHELL32.680] NT 4.0
1195 HRESULT WINAPI IsUserAdmin(void)
1200 /*************************************************************************
1201 * SHAllocShared [SHELL32.520]
1204 * parameter1 is return value from HeapAlloc
1205 * parameter2 is equal to the size allocated with HeapAlloc
1206 * parameter3 is return value from GetCurrentProcessId
1208 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1209 * WM_USER+2 could be the undocumented CWM_SETPATH
1210 * the allocated memory contains a pidl
1212 HGLOBAL WINAPI SHAllocShared(LPVOID psrc, DWORD size, DWORD procID)
1216 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc,size,procID);
1217 hmem = GlobalAlloc(GMEM_FIXED, size);
1221 pmem = GlobalLock (hmem);
1226 memcpy (pmem, psrc, size);
1230 /*************************************************************************
1231 * SHLockShared [SHELL32.521]
1234 * parameter1 is return value from SHAllocShared
1235 * parameter2 is return value from GetCurrentProcessId
1236 * the receiver of (WM_USER+2) trys to lock the HANDLE (?)
1237 * the returnvalue seems to be a memoryadress
1239 LPVOID WINAPI SHLockShared(HANDLE hmem, DWORD procID)
1240 { TRACE("handle=0x%04x procID=0x%04lx\n",hmem,procID);
1241 return GlobalLock(hmem);
1243 /*************************************************************************
1244 * SHUnlockShared [SHELL32.522]
1247 * parameter1 is return value from SHLockShared
1249 BOOL WINAPI SHUnlockShared(LPVOID pv)
1252 return GlobalUnlock((HANDLE)pv);
1254 /*************************************************************************
1255 * SHFreeShared [SHELL32.523]
1258 * parameter1 is return value from SHAllocShared
1259 * parameter2 is return value from GetCurrentProcessId
1261 BOOL WINAPI SHFreeShared(
1265 TRACE("handle=0x%04x 0x%04lx\n",hMem,pid);
1266 return GlobalFree(hMem);
1269 /*************************************************************************
1270 * SetAppStartingCursor [SHELL32.99]
1272 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1273 { FIXME("hwnd=0x%04x 0x%04lx stub\n",u,v );
1276 /*************************************************************************
1277 * SHLoadOLE [SHELL32.151]
1280 HRESULT WINAPI SHLoadOLE(DWORD u)
1281 { FIXME("0x%04lx stub\n",u);
1284 /*************************************************************************
1285 * DriveType [SHELL32.64]
1288 HRESULT WINAPI DriveType(DWORD u)
1289 { FIXME("0x%04lx stub\n",u);
1292 /*************************************************************************
1293 * SHAbortInvokeCommand [SHELL32.198]
1296 HRESULT WINAPI SHAbortInvokeCommand(void)
1300 /*************************************************************************
1301 * SHOutOfMemoryMessageBox [SHELL32.126]
1304 int WINAPI SHOutOfMemoryMessageBox(
1309 FIXME("0x%04x %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1312 /*************************************************************************
1313 * SHFlushClipboard [SHELL32.121]
1316 HRESULT WINAPI SHFlushClipboard(void)
1321 /*************************************************************************
1322 * SHWaitForFileToOpen [SHELL32.97]
1325 BOOL WINAPI SHWaitForFileToOpen(
1330 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1334 /************************************************************************
1337 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1338 * second one could be a size (0x0c). The size is the same as the structure saved to
1339 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1340 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1342 HRESULT WINAPI shell32_654 (DWORD x, DWORD y)
1343 { FIXME("0x%08lx 0x%08lx stub\n",x,y);
1347 /************************************************************************
1348 * RLBuildListOfPaths [SHELL32.146]
1353 DWORD WINAPI RLBuildListOfPaths (void)
1357 /************************************************************************
1358 * SHValidateUNC [SHELL32.173]
1361 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1363 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1367 /************************************************************************
1368 * DoEnvironmentSubstA [SHELL32.@]
1371 HRESULT WINAPI DoEnvironmentSubstA(LPSTR x, LPSTR y)
1373 FIXME("(%s, %s) stub\n", debugstr_a(x), debugstr_a(y));
1377 /************************************************************************
1378 * DoEnvironmentSubstW [SHELL32.@]
1381 HRESULT WINAPI DoEnvironmentSubstW(LPWSTR x, LPWSTR y)
1383 FIXME("(%s, %s): stub\n", debugstr_w(x), debugstr_w(y));
1387 /************************************************************************
1388 * DoEnvironmentSubst [SHELL32.53]
1391 HRESULT WINAPI DoEnvironmentSubstAW(LPVOID x, LPVOID y)
1393 if (SHELL_OsIsUnicode())
1394 return DoEnvironmentSubstW(x, y);
1395 return DoEnvironmentSubstA(x, y);
1398 /*************************************************************************
1401 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1402 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1406 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1411 /*************************************************************************
1414 DWORD WINAPI SHELL32_714(LPVOID x)
1416 FIXME("(%s)stub\n", debugstr_w(x));
1420 /*************************************************************************
1421 * SHAddFromPropSheetExtArray [SHELL32.167]
1423 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1425 FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1429 /*************************************************************************
1430 * SHCreatePropSheetExtArray [SHELL32.168]
1432 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1434 FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1438 /*************************************************************************
1439 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1441 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1443 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1447 /*************************************************************************
1448 * SHDestroyPropSheetExtArray [SHELL32.169]
1450 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1452 FIXME("(%08lx)stub\n", a);
1456 /*************************************************************************
1457 * CIDLData_CreateFromIDArray [SHELL32.83]
1459 * Create IDataObject from PIDLs??
1461 HRESULT WINAPI CIDLData_CreateFromIDArray(
1462 LPCITEMIDLIST pidlFolder,
1464 LPCITEMIDLIST *lppidlFiles,
1465 LPDATAOBJECT *ppdataObject)
1468 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1471 if (TRACE_ON(shell)) {
1472 TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles,
1473 lppidlFiles, ppdataObject);
1474 boldpidl = TRACE_ON(pidl);
1475 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_shell, FALSE);
1476 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, TRUE);
1478 for (i=0; i<cpidlFiles; i++){
1479 pdump (lppidlFiles[i]);
1481 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_shell, TRUE);
1482 __SET_DEBUGGING(__DBCL_TRACE, __wine_dbch_pidl, boldpidl);
1484 *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1485 lppidlFiles, cpidlFiles);
1486 if (*ppdataObject) return S_OK;
1487 return E_OUTOFMEMORY;