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"
26 DEFAULT_DEBUG_CHANNEL(shell);
27 DECLARE_DEBUG_CHANNEL(pidl);
29 /*************************************************************************
30 * ParseFieldA [internal]
32 * copies a field from a ',' delimited string
34 * first field is nField = 1
36 DWORD WINAPI ParseFieldA(
42 WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src),nField,dst,len);
44 if (!src || !src[0] || !dst || !len)
47 /* skip n fields delimited by ',' */
50 if (*src=='\0') return FALSE;
51 if (*(src++)==',') nField--;
54 /* copy part till the next ',' to dst */
55 while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
57 /* finalize the string */
63 /*************************************************************************
64 * ParseFieldW [internal]
66 * copies a field from a ',' delimited string
68 * first field is nField = 1
70 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
72 FIXME("(%s,0x%08lx,%p,%ld) stub\n",
73 debugstr_w(src), nField, dst, len);
77 /*************************************************************************
78 * ParseField [SHELL32.58]
80 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
82 if (SHELL_OsIsUnicode())
83 return ParseFieldW(src, nField, dst, len);
84 return ParseFieldA(src, nField, dst, len);
87 /*************************************************************************
88 * GetFileNameFromBrowse [SHELL32.63]
91 BOOL WINAPI GetFileNameFromBrowse(
95 LPCSTR lpstrInitialDir,
101 FARPROC pGetOpenFileNameA;
105 TRACE("%04x, %s, %ld, %s, %s, %s, %s)\n",
106 hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
107 lpstrFilter, lpstrTitle);
109 hmodule = LoadLibraryA("comdlg32.dll");
110 if(!hmodule) return FALSE;
111 pGetOpenFileNameA = GetProcAddress(hmodule, "GetOpenFileNameA");
112 if(!pGetOpenFileNameA)
114 FreeLibrary(hmodule);
118 memset(&ofn, 0, sizeof(ofn));
120 ofn.lStructSize = sizeof(ofn);
121 ofn.hwndOwner = hwndOwner;
122 ofn.lpstrFilter = lpstrFilter;
123 ofn.lpstrFile = lpstrFile;
124 ofn.nMaxFile = nMaxFile;
125 ofn.lpstrInitialDir = lpstrInitialDir;
126 ofn.lpstrTitle = lpstrTitle;
127 ofn.lpstrDefExt = lpstrDefExt;
128 ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
129 ret = pGetOpenFileNameA(&ofn);
131 FreeLibrary(hmodule);
135 /*************************************************************************
136 * SHGetSetSettings [SHELL32.68]
138 VOID WINAPI SHGetSetSettings(DWORD x, DWORD y, DWORD z)
140 FIXME("0x%08lx 0x%08lx 0x%08lx\n", x, y, z);
143 /*************************************************************************
144 * SHGetSettings [SHELL32.@]
147 * the registry path are for win98 (tested)
148 * and possibly are the same in nt40
151 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
155 DWORD dwDataSize = sizeof (DWORD);
157 TRACE("(%p 0x%08lx)\n",lpsfs,dwMask);
159 if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
160 0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
163 if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
164 lpsfs->fShowExtensions = ((dwData == 0) ? 0 : 1);
166 if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
167 lpsfs->fShowInfoTip = ((dwData == 0) ? 0 : 1);
169 if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
170 lpsfs->fDontPrettyPath = ((dwData == 0) ? 0 : 1);
172 if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
173 lpsfs->fHideIcons = ((dwData == 0) ? 0 : 1);
175 if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
176 lpsfs->fMapNetDrvBtn = ((dwData == 0) ? 0 : 1);
178 if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
179 lpsfs->fShowAttribCol = ((dwData == 0) ? 0 : 1);
181 if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
183 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
184 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
186 else if (dwData == 1)
187 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 1;
188 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 0;
190 else if (dwData == 2)
191 { if (SSF_SHOWALLOBJECTS & dwMask) lpsfs->fShowAllObjects = 0;
192 if (SSF_SHOWSYSFILES & dwMask) lpsfs->fShowSysFiles = 1;
197 TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
200 /*************************************************************************
201 * SHShellFolderView_Message [SHELL32.73]
204 * hwndCabinet defines the explorer cabinet window that contains the
205 * shellview you need to communicate with
206 * uMsg identifying the SFVM enum to perform
210 * Message SFVM_REARRANGE = 1
211 * This message gets sent when a column gets clicked to instruct the
212 * shell view to re-sort the item list. lParam identifies the column
215 int WINAPI SHShellFolderView_Message(
220 FIXME("%04x %08lx %08lx stub\n",hwndCabinet, dwMessage, dwParam);
224 /*************************************************************************
225 * RegisterShellHook [SHELL32.181]
228 * hwnd [I] window handle
232 * exported by ordinal
234 BOOL WINAPI RegisterShellHook(
238 FIXME("(0x%08x,0x%08lx):stub.\n",hWnd, dwType);
241 /*************************************************************************
242 * ShellMessageBoxW [SHELL32.182]
244 * Format and output errormessage.
246 * idText resource ID of title or LPSTR
247 * idTitle resource ID of title or LPSTR
250 * exported by ordinal
252 int WINAPIV ShellMessageBoxW(
260 WCHAR szText[100],szTitle[100];
261 LPCWSTR pszText = szText, pszTitle = szTitle, pszTemp;
265 va_start(args, uType);
266 /* wvsprintfA(buf,fmt, args); */
268 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
269 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
271 if (!HIWORD(lpCaption))
272 LoadStringW(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
274 pszTitle = lpCaption;
277 LoadStringW(hInstance, (DWORD)lpText, szText, sizeof(szText)/sizeof(szText[0]));
281 FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
282 pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
286 ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
287 LocalFree((HLOCAL)pszTemp);
291 /*************************************************************************
292 * ShellMessageBoxA [SHELL32.183]
294 int WINAPIV ShellMessageBoxA(
302 char szText[100],szTitle[100];
303 LPCSTR pszText = szText, pszTitle = szTitle, pszTemp;
307 va_start(args, uType);
308 /* wvsprintfA(buf,fmt, args); */
310 TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
311 (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
313 if (!HIWORD(lpCaption))
314 LoadStringA(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle));
316 pszTitle = lpCaption;
319 LoadStringA(hInstance, (DWORD)lpText, szText, sizeof(szText));
323 FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
324 pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
328 ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
329 LocalFree((HLOCAL)pszTemp);
333 /*************************************************************************
334 * SHFree [SHELL32.195]
337 * free_ptr() - frees memory using IMalloc
338 * exported by ordinal
341 void WINAPI SHFree(LPVOID x)
344 WORD len = *(LPWORD)((LPBYTE)x-2);
346 if ( *(LPWORD)((LPBYTE)x+len) != 0x7384)
349 if ( (*(LPWORD)((LPBYTE)x-4)) != 0x8271)
352 memset((LPBYTE)x-4, 0xde, len+6);
354 TRACE("%p len=%u\n",x, len);
360 HeapFree(GetProcessHeap(), 0, x);
363 /*************************************************************************
364 * SHAlloc [SHELL32.196]
367 * void *task_alloc(DWORD len), uses SHMalloc allocator
368 * exported by ordinal
370 LPVOID WINAPI SHAlloc(DWORD len)
375 ret = (LPVOID) HeapAlloc(GetProcessHeap(),0,len+6);
377 ret = (LPVOID) HeapAlloc(GetProcessHeap(),0,len);
381 *(LPWORD)(ret) = 0x8271;
382 *(LPWORD)(ret+2) = (WORD)len;
383 *(LPWORD)(ret+4+len) = 0x7384;
385 memset(ret, 0xdf, len);
387 TRACE("%lu bytes at %p\n",len, ret);
391 /*************************************************************************
392 * SHRegisterDragDrop [SHELL32.86]
395 * exported by ordinal
397 HRESULT WINAPI SHRegisterDragDrop(
399 LPDROPTARGET pDropTarget)
401 FIXME("(0x%08x,%p):stub.\n", hWnd, pDropTarget);
402 if (GetShellOle()) return pRegisterDragDrop(hWnd, pDropTarget);
406 /*************************************************************************
407 * SHRevokeDragDrop [SHELL32.87]
410 * exported by ordinal
412 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
414 FIXME("(0x%08x):stub.\n",hWnd);
418 /*************************************************************************
419 * SHDoDragDrop [SHELL32.88]
422 * exported by ordinal
424 HRESULT WINAPI SHDoDragDrop(
426 LPDATAOBJECT lpDataObject,
427 LPDROPSOURCE lpDropSource,
431 FIXME("(0x%04x %p %p 0x%08lx %p):stub.\n",
432 hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
436 /*************************************************************************
437 * ArrangeWindows [SHELL32.184]
440 WORD WINAPI ArrangeWindows(
447 FIXME("(0x%08x 0x%08lx %p 0x%04x %p):stub.\n",
448 hwndParent, dwReserved, lpRect, cKids, lpKids);
452 /*************************************************************************
453 * SignalFileOpen [SHELL32.103]
456 * exported by ordinal
459 SignalFileOpen (DWORD dwParam1)
461 FIXME("(0x%08lx):stub.\n", dwParam1);
466 /*************************************************************************
467 * SHADD_get_policy - helper function for SHAddToRecentDocs
470 * policy [IN] policy name (null termed string) to find
471 * type [OUT] ptr to DWORD to receive type
472 * buffer [OUT] ptr to area to hold data retrieved
473 * len [IN/OUT] ptr to DWORD holding size of buffer and getting
477 * result of the SHQueryValueEx call
479 static INT SHADD_get_policy(LPSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
484 /* Get the key for the policies location in the registry
486 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
487 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
488 0, KEY_READ, &Policy_basekey)) {
490 if (RegOpenKeyExA(HKEY_CURRENT_USER,
491 "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
492 0, KEY_READ, &Policy_basekey)) {
493 TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
496 return ERROR_FILE_NOT_FOUND;
500 /* Retrieve the data if it exists
502 ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
503 RegCloseKey(Policy_basekey);
508 /*************************************************************************
509 * SHADD_compare_mru - helper function for SHAddToRecentDocs
512 * data1 [IN] data being looked for
513 * data2 [IN] data in MRU
514 * cbdata [IN] length from FindMRUData call (not used)
517 * position within MRU list that data was added.
519 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
521 return lstrcmpiA(data1, data2);
524 /*************************************************************************
525 * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
528 * mruhandle [IN] handle for created MRU list
529 * doc_name [IN] null termed pure doc name
530 * new_lnk_name [IN] null termed path and file name for .lnk file
531 * buffer [IN/OUT] 2048 byte area to consturct MRU data
532 * len [OUT] ptr to int to receive space used in buffer
535 * position within MRU list that data was added.
537 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
538 LPSTR buffer, INT *len)
544 * RecentDocs MRU data structure seems to be:
545 * +0h document file name w/ terminating 0h
546 * +nh short int w/ size of remaining
547 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
548 * +n+4h 10 bytes zeros - unknown
549 * +n+eh shortcut file name w/ terminating 0h
550 * +n+e+nh 3 zero bytes - unknown
553 /* Create the MRU data structure for "RecentDocs"
556 lstrcpyA(ptr, doc_name);
557 ptr += (lstrlenA(buffer) + 1);
558 wlen= lstrlenA(new_lnk_name) + 1 + 12;
559 *((short int*)ptr) = wlen;
560 ptr += 2; /* step past the length */
561 *(ptr++) = 0x30; /* unknown reason */
562 *(ptr++) = 0; /* unknown, but can be 0x00, 0x01, 0x02 */
565 lstrcpyA(ptr, new_lnk_name);
566 ptr += (lstrlenA(new_lnk_name) + 1);
571 /* Add the new entry into the MRU list
573 return pAddMRUData(mruhandle, (LPCVOID)buffer, *len);
576 /*************************************************************************
577 * SHAddToRecentDocs [SHELL32.@]
580 * uFlags [IN] SHARD_PATH or SHARD_PIDL
581 * pv [IN] string or pidl, NULL clears the list
586 * FIXME: ?? MSDN shows this as a VOID
588 DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
591 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
592 /* !!! it is in both here and comctl32undoc.c !!! */
593 typedef struct tagCREATEMRULIST
595 DWORD cbSize; /* size of struct */
596 DWORD nMaxItems; /* max no. of items in list */
597 DWORD dwFlags; /* see below */
598 HKEY hKey; /* root reg. key under which list is saved */
599 LPCSTR lpszSubKey; /* reg. subkey */
600 PROC lpfnCompare; /* item compare proc */
601 } CREATEMRULIST, *LPCREATEMRULIST;
604 #define MRUF_STRING_LIST 0 /* list will contain strings */
605 #define MRUF_BINARY_LIST 1 /* list will contain binary data */
606 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
608 /* If list is a string list lpfnCompare has the following prototype
609 * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
610 * for binary lists the prototype is
611 * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
612 * where cbData is the no. of bytes to compare.
613 * Need to check what return value means identical - 0?
619 CHAR doc_name[MAX_PATH];
620 CHAR link_dir[MAX_PATH];
621 CHAR new_lnk_filepath[MAX_PATH];
622 CHAR new_lnk_name[MAX_PATH];
625 HWND hwnd = 0; /* FIXME: get real window handle */
627 DWORD data[64], datalen, type;
630 * RecentDocs MRU data structure seems to be:
631 * +0h document file name w/ terminating 0h
632 * +nh short int w/ size of remaining
633 * +n+2h 02h 30h, or 01h 30h, or 00h 30h - unknown
634 * +n+4h 10 bytes zeros - unknown
635 * +n+eh shortcut file name w/ terminating 0h
636 * +n+e+nh 3 zero bytes - unknown
639 /* See if we need to do anything.
642 ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
643 if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
644 ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
647 if (ret == ERROR_SUCCESS) {
648 if (!( (type == REG_DWORD) ||
649 ((type == REG_BINARY) && (datalen == 4)) )) {
650 ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
655 TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
656 /* now test the actual policy value */
661 /* Open key to where the necessary info is
663 /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
664 * and the close should be done during the _DETACH. The resulting
665 * key is stored in the DLL global data.
667 if (RegCreateKeyExA(HKEY_CURRENT_USER,
668 "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
669 0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
670 ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
674 /* Get path to user's "Recent" directory
676 if(SUCCEEDED(SHGetMalloc(&ppM))) {
677 if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
679 SHGetPathFromIDListA(pidl, link_dir);
680 IMalloc_Free(ppM, pidl);
685 ERR("serious issues 1\n");
687 IMalloc_Release(ppM);
692 ERR("serious issues 2\n");
694 TRACE("Users Recent dir %s\n", link_dir);
696 /* If no input, then go clear the lists */
698 /* clear user's Recent dir
701 /* FIXME: delete all files in "link_dir"
703 * while( more files ) {
704 * lstrcpyA(old_lnk_name, link_dir);
705 * PathAppendA(old_lnk_name, filenam);
706 * DeleteFileA(old_lnk_name);
709 FIXME("should delete all files in %s\\ \n", link_dir);
713 /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
714 * HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
715 * and naturally it fails w/ rc=2. It should do it against
716 * HKEY_CURRENT_USER which is where it is stored, and where
717 * the MRU routines expect it!!!!
719 RegDeleteKeyA(HCUbasekey, "RecentDocs");
720 RegCloseKey(HCUbasekey);
724 /* Have data to add, the jobs to be done:
725 * 1. Add document to MRU list in registry "HKCU\Software\
726 * Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
727 * 2. Add shortcut to document in the user's Recent directory
729 * 3. Add shortcut to Start menu's Documents submenu.
732 /* Get the pure document name from the input
734 if (uFlags & SHARD_PIDL) {
735 SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
738 lstrcpyA(doc_name, (LPSTR) pv);
740 TRACE("full document name %s\n", doc_name);
741 PathStripPathA(doc_name);;
742 TRACE("stripped document name %s\n", doc_name);
745 /* *** JOB 1: Update registry for ...\Explorer\RecentDocs list *** */
748 * doc_name - pure file-spec, no path
749 * link_dir - path to the user's Recent directory
750 * HCUbasekey - key of ...Windows\CurrentVersion\Explorer" node
752 * new_lnk_name- pure file-spec, no path for new .lnk file
754 * - path and file name of new .lnk file
758 INT len, pos, bufused, err;
763 CHAR old_lnk_name[MAX_PATH];
766 mymru.cbSize = sizeof(CREATEMRULIST);
767 mymru.nMaxItems = 15;
768 mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
769 mymru.hKey = HCUbasekey;
770 mymru.lpszSubKey = "RecentDocs";
771 mymru.lpfnCompare = &SHADD_compare_mru;
772 mruhandle = pCreateMRUListA(&mymru);
775 ERR("MRU processing failed, handle zero\n");
776 RegCloseKey(HCUbasekey);
779 len = lstrlenA(doc_name);
780 pos = pFindMRUData(mruhandle, doc_name, len, 0);
782 /* Now get the MRU entry that will be replaced
783 * and delete the .lnk file for it
785 if ((bufused = pEnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
786 buffer, 2048)) != -1) {
788 ptr += (lstrlenA(buffer) + 1);
789 slen = *((short int*)ptr);
790 ptr += 2; /* skip the length area */
791 if (bufused >= slen + (ptr-buffer)) {
792 /* buffer size looks good */
793 ptr += 12; /* get to string */
794 len = bufused - (ptr-buffer); /* get length of buf remaining */
795 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
796 /* appears to be good string */
797 lstrcpyA(old_lnk_name, link_dir);
798 PathAppendA(old_lnk_name, ptr);
799 if (!DeleteFileA(old_lnk_name)) {
800 if ((attr = GetFileAttributesA(old_lnk_name)) == -1) {
801 if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
802 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
803 old_lnk_name, err, attr);
806 TRACE("old .lnk file %s did not exist\n",
811 ERR("Delete for %s failed, attr=%08lx\n",
816 TRACE("deleted old .lnk file %s\n", old_lnk_name);
822 /* Create usable .lnk file name for the "Recent" directory
824 wsprintfA(new_lnk_name, "%s.lnk", doc_name);
825 lstrcpyA(new_lnk_filepath, link_dir);
826 PathAppendA(new_lnk_filepath, new_lnk_name);
828 olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
829 while (GetFileAttributesA(new_lnk_filepath) != -1) {
831 wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
832 lstrcpyA(new_lnk_filepath, link_dir);
833 PathAppendA(new_lnk_filepath, new_lnk_name);
835 SetErrorMode(olderrormode);
836 TRACE("new shortcut will be %s\n", new_lnk_filepath);
838 /* Now add the new MRU entry and data
840 pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
842 pFreeMRUListA(mruhandle);
843 TRACE("Updated MRU list, new doc is position %d\n", pos);
846 /* *** JOB 2: Create shortcut in user's "Recent" directory *** */
849 * doc_name - pure file-spec, no path
851 * - path and file name of new .lnk file
852 * uFlags[in] - flags on call to SHAddToRecentDocs
853 * pv[in] - document path/pidl on call to SHAddToRecentDocs
855 IShellLinkA *psl = NULL;
856 IPersistFile *pPf = NULL;
859 WCHAR widelink[MAX_PATH];
863 hres = CoCreateInstance( &CLSID_ShellLink,
865 CLSCTX_INPROC_SERVER,
868 if(SUCCEEDED(hres)) {
870 hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
874 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
878 /* Set the document path or pidl */
879 if (uFlags & SHARD_PIDL) {
880 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
882 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
886 ERR("failed Set{IDList|Path} %08lx\n", hres);
890 lstrcpyA(desc, "Shortcut to ");
891 lstrcatA(desc, doc_name);
892 hres = IShellLinkA_SetDescription(psl, desc);
895 ERR("failed SetDescription %08lx\n", hres);
899 MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
901 /* create the short cut */
902 hres = IPersistFile_Save(pPf, widelink, TRUE);
905 ERR("failed IPersistFile::Save %08lx\n", hres);
906 IPersistFile_Release(pPf);
907 IShellLinkA_Release(psl);
910 hres = IPersistFile_SaveCompleted(pPf, widelink);
911 IPersistFile_Release(pPf);
912 IShellLinkA_Release(psl);
913 TRACE("shortcut %s has been created, result=%08lx\n",
914 new_lnk_filepath, hres);
917 ERR("CoCreateInstance failed, hres=%08lx\n", hres);
925 RegCloseKey(HCUbasekey);
929 /*************************************************************************
930 * SHCreateShellFolderViewEx [SHELL32.174]
933 * see IShellFolder::CreateViewObject
935 HRESULT WINAPI SHCreateShellFolderViewEx(
936 LPCSHELLFOLDERVIEWINFO psvcbi, /* [in] shelltemplate struct */
937 LPSHELLVIEW* ppv) /* [out] IShellView pointer */
942 TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
943 psvcbi->pshf, psvcbi->pidlFolder, psvcbi->lpfnCallback,
944 psvcbi->uViewMode, psvcbi->dwUser);
946 psf = IShellView_Constructor(psvcbi->pshf);
949 return E_OUTOFMEMORY;
951 IShellView_AddRef(psf);
952 hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
953 IShellView_Release(psf);
957 /*************************************************************************
958 * SHWinHelp [SHELL32.127]
961 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
962 { FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
965 /*************************************************************************
966 * SHRunControlPanel [SHELL32.161]
969 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
970 { FIXME("0x%08lx 0x%08lx stub\n",x,z);
973 /*************************************************************************
974 * ShellExecuteEx [SHELL32.291]
977 BOOL WINAPI ShellExecuteExAW (LPVOID sei)
978 { if (SHELL_OsIsUnicode())
979 return ShellExecuteExW (sei);
980 return ShellExecuteExA (sei);
982 /*************************************************************************
983 * ShellExecuteExA [SHELL32.292]
985 * placeholder in the commandline:
990 * %I adress of a global item ID (explorer switch /idlist)
991 * %L ??? path/url/current file ???
993 * %* all following parameters (see batfile)
995 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
996 { CHAR szApplicationName[MAX_PATH],szCommandline[MAX_PATH],szPidl[20];
999 STARTUPINFOA startup;
1000 PROCESS_INFORMATION info;
1002 WARN("mask=0x%08lx hwnd=0x%04x verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s incomplete\n",
1003 sei->fMask, sei->hwnd, debugstr_a(sei->lpVerb),
1004 debugstr_a(sei->lpFile), debugstr_a(sei->lpParameters),
1005 debugstr_a(sei->lpDirectory), sei->nShow,
1006 (sei->fMask & SEE_MASK_CLASSNAME) ? debugstr_a(sei->lpClass) : "not used");
1008 ZeroMemory(szApplicationName,MAX_PATH);
1010 strcpy(szApplicationName, sei->lpFile);
1012 ZeroMemory(szCommandline,MAX_PATH);
1013 if (sei->lpParameters)
1014 strcpy(szCommandline, sei->lpParameters);
1016 if (sei->fMask & (SEE_MASK_CLASSKEY | SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
1017 SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
1018 SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
1019 SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
1021 FIXME("flags ignored: 0x%08lx\n", sei->fMask);
1024 /* launch a document by fileclass like 'Wordpad.Document.1' */
1025 if (sei->fMask & SEE_MASK_CLASSNAME)
1027 /* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
1028 /* the commandline contains 'c:\Path\wordpad.exe "%1"' */
1029 HCR_GetExecuteCommand(sei->lpClass, (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
1030 /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
1031 TRACE("SEE_MASK_CLASSNAME->'%s'\n", szCommandline);
1034 /* process the IDList */
1035 if ( (sei->fMask & SEE_MASK_INVOKEIDLIST) == SEE_MASK_INVOKEIDLIST) /*0x0c*/
1037 SHGetPathFromIDListA (sei->lpIDList,szApplicationName);
1038 TRACE("-- idlist=%p (%s)\n", sei->lpIDList, szApplicationName);
1042 if (sei->fMask & SEE_MASK_IDLIST )
1044 pos = strstr(szCommandline, "%I");
1048 HGLOBAL hmem = SHAllocShared ( sei->lpIDList, ILGetSize(sei->lpIDList), 0);
1049 pv = SHLockShared(hmem,0);
1050 sprintf(szPidl,":%p",pv );
1053 gap = strlen(szPidl);
1054 len = strlen(pos)-2;
1055 memmove(pos+gap,pos+2,len);
1056 memcpy(pos,szPidl,gap);
1062 TRACE("execute:'%s','%s'\n",szApplicationName, szCommandline);
1064 if (szCommandline[0]) {
1065 strcat(szApplicationName, " ");
1066 strcat(szApplicationName, szCommandline);
1069 ZeroMemory(&startup,sizeof(STARTUPINFOA));
1070 startup.cb = sizeof(STARTUPINFOA);
1072 if (! CreateProcessA(NULL, szApplicationName,
1073 NULL, NULL, FALSE, 0,
1074 NULL, sei->lpDirectory,
1077 sei->hInstApp = GetLastError();
1083 /* Give 30 seconds to the app to come up */
1084 if ( WaitForInputIdle ( info.hProcess, 30000 ) == 0xFFFFFFFF )
1085 ERR("WaitForInputIdle failed: Error %ld\n", GetLastError() );
1087 if(sei->fMask & SEE_MASK_NOCLOSEPROCESS)
1088 sei->hProcess = info.hProcess;
1090 CloseHandle( info.hProcess );
1091 CloseHandle( info.hThread );
1094 /*************************************************************************
1095 * ShellExecuteExW [SHELL32.293]
1098 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
1099 { SHELLEXECUTEINFOA seiA;
1104 memcpy(&seiA, sei, sizeof(SHELLEXECUTEINFOA));
1107 seiA.lpVerb = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpVerb);
1110 seiA.lpFile = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpFile);
1112 if (sei->lpParameters)
1113 seiA.lpParameters = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpParameters);
1115 if (sei->lpDirectory)
1116 seiA.lpDirectory = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpDirectory);
1118 if ((sei->fMask & SEE_MASK_CLASSNAME) && sei->lpClass)
1119 seiA.lpClass = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpClass);
1121 seiA.lpClass = NULL;
1123 ret = ShellExecuteExA(&seiA);
1125 if (seiA.lpVerb) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpVerb );
1126 if (seiA.lpFile) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpFile );
1127 if (seiA.lpParameters) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpParameters );
1128 if (seiA.lpDirectory) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpDirectory );
1129 if (seiA.lpClass) HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpClass );
1134 static LPUNKNOWN SHELL32_IExplorerInterface=0;
1135 /*************************************************************************
1136 * SHSetInstanceExplorer [SHELL32.176]
1139 * Sets the interface
1141 HRESULT WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
1142 { TRACE("%p\n", lpUnknown);
1143 SHELL32_IExplorerInterface = lpUnknown;
1144 return (HRESULT) lpUnknown;
1146 /*************************************************************************
1147 * SHGetInstanceExplorer [SHELL32.@]
1150 * gets the interface pointer of the explorer and a reference
1152 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
1153 { TRACE("%p\n", lpUnknown);
1155 *lpUnknown = SHELL32_IExplorerInterface;
1157 if (!SHELL32_IExplorerInterface)
1160 IUnknown_AddRef(SHELL32_IExplorerInterface);
1163 /*************************************************************************
1164 * SHFreeUnusedLibraries [SHELL32.123]
1169 void WINAPI SHFreeUnusedLibraries (void)
1173 /*************************************************************************
1174 * DAD_SetDragImage [SHELL32.136]
1179 BOOL WINAPI DAD_SetDragImage(
1180 HIMAGELIST himlTrack,
1183 FIXME("%p %p stub\n",himlTrack, lppt);
1186 /*************************************************************************
1187 * DAD_ShowDragImage [SHELL32.137]
1192 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1194 FIXME("0x%08x stub\n",bShow);
1197 /*************************************************************************
1198 * ReadCabinetState [SHELL32.651] NT 4.0
1201 HRESULT WINAPI ReadCabinetState(DWORD u, DWORD v)
1202 { FIXME("0x%04lx 0x%04lx stub\n",u,v);
1205 /*************************************************************************
1206 * WriteCabinetState [SHELL32.652] NT 4.0
1209 HRESULT WINAPI WriteCabinetState(DWORD u)
1210 { FIXME("0x%04lx stub\n",u);
1213 /*************************************************************************
1214 * FileIconInit [SHELL32.660]
1217 BOOL WINAPI FileIconInit(BOOL bFullInit)
1218 { FIXME("(%s)\n", bFullInit ? "true" : "false");
1221 /*************************************************************************
1222 * IsUserAdmin [SHELL32.680] NT 4.0
1225 HRESULT WINAPI IsUserAdmin(void)
1230 /*************************************************************************
1231 * SHAllocShared [SHELL32.520]
1234 * parameter1 is return value from HeapAlloc
1235 * parameter2 is equal to the size allocated with HeapAlloc
1236 * parameter3 is return value from GetCurrentProcessId
1238 * the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1239 * WM_USER+2 could be the undocumented CWM_SETPATH
1240 * the allocated memory contains a pidl
1242 HGLOBAL WINAPI SHAllocShared(LPVOID psrc, DWORD size, DWORD procID)
1246 TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc,size,procID);
1247 hmem = GlobalAlloc(GMEM_FIXED, size);
1251 pmem = GlobalLock (hmem);
1256 memcpy (pmem, psrc, size);
1260 /*************************************************************************
1261 * SHLockShared [SHELL32.521]
1264 * parameter1 is return value from SHAllocShared
1265 * parameter2 is return value from GetCurrentProcessId
1266 * the receiver of (WM_USER+2) tries to lock the HANDLE (?)
1267 * the return value seems to be a memory address
1269 LPVOID WINAPI SHLockShared(HANDLE hmem, DWORD procID)
1270 { TRACE("handle=0x%04x procID=0x%04lx\n",hmem,procID);
1271 return GlobalLock(hmem);
1273 /*************************************************************************
1274 * SHUnlockShared [SHELL32.522]
1277 * parameter1 is return value from SHLockShared
1279 BOOL WINAPI SHUnlockShared(LPVOID pv)
1282 return GlobalUnlock((HANDLE)pv);
1284 /*************************************************************************
1285 * SHFreeShared [SHELL32.523]
1288 * parameter1 is return value from SHAllocShared
1289 * parameter2 is return value from GetCurrentProcessId
1291 BOOL WINAPI SHFreeShared(
1295 TRACE("handle=0x%04x 0x%04lx\n",hMem,pid);
1296 return GlobalFree(hMem);
1299 /*************************************************************************
1300 * SetAppStartingCursor [SHELL32.99]
1302 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1303 { FIXME("hwnd=0x%04x 0x%04lx stub\n",u,v );
1306 /*************************************************************************
1307 * SHLoadOLE [SHELL32.151]
1310 HRESULT WINAPI SHLoadOLE(DWORD u)
1311 { FIXME("0x%04lx stub\n",u);
1314 /*************************************************************************
1315 * DriveType [SHELL32.64]
1318 HRESULT WINAPI DriveType(DWORD u)
1319 { FIXME("0x%04lx stub\n",u);
1322 /*************************************************************************
1323 * SHAbortInvokeCommand [SHELL32.198]
1326 HRESULT WINAPI SHAbortInvokeCommand(void)
1330 /*************************************************************************
1331 * SHOutOfMemoryMessageBox [SHELL32.126]
1334 int WINAPI SHOutOfMemoryMessageBox(
1339 FIXME("0x%04x %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1342 /*************************************************************************
1343 * SHFlushClipboard [SHELL32.121]
1346 HRESULT WINAPI SHFlushClipboard(void)
1351 /*************************************************************************
1352 * SHWaitForFileToOpen [SHELL32.97]
1355 BOOL WINAPI SHWaitForFileToOpen(
1360 FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1364 /************************************************************************
1367 * NOTES: first parameter seems to be a pointer (same as passed to WriteCabinetState)
1368 * second one could be a size (0x0c). The size is the same as the structure saved to
1369 * HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1370 * I'm (js) guessing: this one is just ReadCabinetState ;-)
1372 HRESULT WINAPI shell32_654 (DWORD x, DWORD y)
1373 { FIXME("0x%08lx 0x%08lx stub\n",x,y);
1377 /************************************************************************
1378 * RLBuildListOfPaths [SHELL32.146]
1383 DWORD WINAPI RLBuildListOfPaths (void)
1387 /************************************************************************
1388 * SHValidateUNC [SHELL32.173]
1391 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1393 FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1397 /************************************************************************
1398 * DoEnvironmentSubstA [SHELL32.@]
1401 HRESULT WINAPI DoEnvironmentSubstA(LPSTR x, LPSTR y)
1403 FIXME("(%s, %s) stub\n", debugstr_a(x), debugstr_a(y));
1407 /************************************************************************
1408 * DoEnvironmentSubstW [SHELL32.@]
1411 HRESULT WINAPI DoEnvironmentSubstW(LPWSTR x, LPWSTR y)
1413 FIXME("(%s, %s): stub\n", debugstr_w(x), debugstr_w(y));
1417 /************************************************************************
1418 * DoEnvironmentSubst [SHELL32.53]
1421 HRESULT WINAPI DoEnvironmentSubstAW(LPVOID x, LPVOID y)
1423 if (SHELL_OsIsUnicode())
1424 return DoEnvironmentSubstW(x, y);
1425 return DoEnvironmentSubstA(x, y);
1428 /*************************************************************************
1431 * Win98+ by-ordinal routine. In Win98 this routine returns zero and
1432 * does nothing else. Possibly this does something in NT or SHELL32 5.0?
1436 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1441 /*************************************************************************
1444 DWORD WINAPI SHELL32_714(LPVOID x)
1446 FIXME("(%s)stub\n", debugstr_w(x));
1450 /*************************************************************************
1451 * SHAddFromPropSheetExtArray [SHELL32.167]
1453 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1455 FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1459 /*************************************************************************
1460 * SHCreatePropSheetExtArray [SHELL32.168]
1462 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1464 FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1468 /*************************************************************************
1469 * SHReplaceFromPropSheetExtArray [SHELL32.170]
1471 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1473 FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1477 /*************************************************************************
1478 * SHDestroyPropSheetExtArray [SHELL32.169]
1480 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1482 FIXME("(%08lx)stub\n", a);
1486 /*************************************************************************
1487 * CIDLData_CreateFromIDArray [SHELL32.83]
1489 * Create IDataObject from PIDLs??
1491 HRESULT WINAPI CIDLData_CreateFromIDArray(
1492 LPCITEMIDLIST pidlFolder,
1494 LPCITEMIDLIST *lppidlFiles,
1495 LPDATAOBJECT *ppdataObject)
1498 HWND hwnd = 0; /*FIXME: who should be hwnd of owner? set to desktop */
1500 TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1504 for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1506 *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1507 lppidlFiles, cpidlFiles);
1508 if (*ppdataObject) return S_OK;
1509 return E_OUTOFMEMORY;