ReactOS 0.4.16-dev-1007-g2e85425
CShellLink.cpp
Go to the documentation of this file.
1/*
2 *
3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2005 Mike McCormack
6 * Copyright 2009 Andrew Hill
7 * Copyright 2013 Dominik Hornung
8 * Copyright 2017 Hermes Belusca-Maito
9 * Copyright 2018-2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 *
25 * NOTES
26 * Nearly complete information about the binary formats
27 * of .lnk files available at http://www.wotsit.org
28 *
29 * You can use winedump to examine the contents of a link file:
30 * winedump lnk sc.lnk
31 *
32 * MSI advertised shortcuts are totally undocumented. They provide an
33 * icon for a program that is not yet installed, and invoke MSI to
34 * install the program when the shortcut is clicked on. They are
35 * created by passing a special string to SetPath, and the information
36 * in that string is parsed an stored.
37 */
38/*
39 * In the following is listed more documentation about the Shell Link file format,
40 * as well as its interface.
41 *
42 * General introduction about "Shell Links" (MSDN):
43 * https://learn.microsoft.com/en-us/windows/win32/shell/links
44 *
45 *
46 * Details of the file format:
47 *
48 * - Official MSDN documentation "[MS-SHLLINK]: Shell Link (.LNK) Binary File Format":
49 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-shllink/16cb4ca1-9339-4d0c-a68d-bf1d6cc0f943
50 *
51 * - Forensics:
52 * http://forensicswiki.org/wiki/LNK
53 * http://computerforensics.parsonage.co.uk/downloads/TheMeaningofLIFE.pdf
54 * https://ithreats.files.wordpress.com/2009/05/lnk_the_windows_shortcut_file_format.pdf
55 * https://github.com/libyal/liblnk/blob/master/documentation/Windows%20Shortcut%20File%20(LNK)%20format.asciidoc
56 *
57 * - List of possible shell link header flags (SHELL_LINK_DATA_FLAGS enumeration):
58 * https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/ne-shlobj_core-shell_link_data_flags
59 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-shllink/ae350202-3ba9-4790-9e9e-98935f4ee5af
60 *
61 *
62 * In addition to storing its target by using a PIDL, a shell link file also
63 * stores metadata to make the shell able to track the link target, in situations
64 * where the link target is moved amongst local or network directories, or moved
65 * to different volumes. For this, two structures are used:
66 *
67 * - The first and oldest one (from NewShell/WinNT4) is the "LinkInfo" structure,
68 * stored in a serialized manner at the beginning of the shell link file:
69 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-shllink/6813269d-0cc8-4be2-933f-e96e8e3412dc
70 * The official API for manipulating this is located in LINKINFO.DLL .
71 *
72 * - The second, more recent one, is an extra binary block appended to the
73 * extra-data list of the shell link file: this is the "TrackerDataBlock":
74 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-shllink/df8e3748-fba5-4524-968a-f72be06d71fc
75 * Its purpose is for link tracking, and works in coordination with the
76 * "Distributed Link Tracking" service ('TrkWks' client, 'TrkSvr' server).
77 * See a detailed explanation at:
78 * http://www.serverwatch.com/tutorials/article.php/1476701/Searching-for-the-Missing-Link-Distributed-Link-Tracking.htm
79 *
80 *
81 * MSI installations most of the time create so-called "advertised shortcuts".
82 * They provide an icon for a program that may not be installed yet, and invoke
83 * MSI to install the program when the shortcut is opened (resolved).
84 * The philosophy of this approach is explained in detail inside the MSDN article
85 * "Application Resiliency: Unlock the Hidden Features of Windows Installer"
86 * (by Michael Sanford), here:
87 * https://learn.microsoft.com/en-us/previous-versions/dotnet/articles/aa302344(v=msdn.10)
88 *
89 * This functionality is implemented by adding a binary "Darwin" data block
90 * of type "EXP_DARWIN_LINK", signature EXP_DARWIN_ID_SIG == 0xA0000006,
91 * to the shell link file:
92 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-shllink/48f8a4c4-99fe-4787-a39f-b1367103eba8
93 * or, this could be done more simply by specifying a special link target path
94 * with the IShellLink::SetPath() function. Defining the following GUID:
95 * SHELL32_AdvtShortcutComponent = "::{9db1186e-40df-11d1-aa8c-00c04fb67863}:"
96 * setting a target of the form:
97 * "::{SHELL32_AdvtShortcutComponent}:<MSI_App_ID>"
98 * would automatically create the necessary binary block.
99 *
100 * With that, the target of the shortcut now becomes the MSI data. The latter
101 * is parsed from MSI and retrieved by the shell that then can run the program.
102 *
103 * This MSI functionality, dubbed "link blessing", actually originates from an
104 * older technology introduced in Internet Explorer 3 (and now obsolete since
105 * Internet Explorer 7), called "MS Internet Component Download (MSICD)", see
106 * this MSDN introductory article:
107 * https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa741198(v=vs.85)
108 * and leveraged in Internet Explorer 4 with "Software Update Channels", see:
109 * https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa740931(v=vs.85)
110 * Applications supporting this technology could present shell links having
111 * a special target, see subsection "Modifying the Shortcut" in the article:
112 * https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa741201(v=vs.85)#pub_shor
113 *
114 * Similarly as for the MSI shortcuts, these MSICD shortcuts are created by
115 * specifying a special link target path with the IShellLink::SetPath() function,
116 * defining the following GUID:
117 * SHELL32_AdvtShortcutProduct = "::{9db1186f-40df-11d1-aa8c-00c04fb67863}:"
118 * and setting a target of the form:
119 * "::{SHELL32_AdvtShortcutProduct}:<AppName>::<Path>" .
120 * A tool, called "blesslnk.exe", was also provided for automatizing the process;
121 * its ReadMe can be found in the (now outdated) MS "Internet Client SDK" (INetSDK,
122 * for MS Windows 95 and NT), whose contents can be read at:
123 * http://www.msfn.org/board/topic/145352-new-windows-lnk-vulnerability/?page=4#comment-944223
124 * The MS INetSDK can be found at:
125 * https://web.archive.org/web/20100924000013/http://support.microsoft.com/kb/177877
126 *
127 * Internally the shell link target of these MSICD shortcuts is converted into
128 * a binary data block of a type similar to Darwin / "EXP_DARWIN_LINK", but with
129 * a different signature EXP_LOGO3_ID_SIG == 0xA0000007 . Such shell links are
130 * called "Logo3" shortcuts. They were evoked in this user comment in "The Old
131 * New Thing" blog:
132 * https://web.archive.org/web/20190110073640/https://blogs.msdn.microsoft.com/oldnewthing/20121210-00/?p=5883#comment-1025083
133 *
134 * The shell exports the API 'SoftwareUpdateMessageBox' (in shdocvw.dll) that
135 * displays a message when an update for an application supporting this
136 * technology is available.
137 *
138 */
139
140#include "precomp.h"
141
142#include <appmgmt.h>
143
145
146/*
147 * Allows to define whether or not Windows-compatible behaviour
148 * should be adopted when setting and retrieving icon location paths.
149 * See CShellLink::SetIconLocation(LPCWSTR pszIconPath, INT iIcon)
150 * for more details.
151 */
152#define ICON_LINK_WINDOWS_COMPAT
153
154#define SHLINK_LOCAL 0
155#define SHLINK_REMOTE 1
156
157/* link file formats */
158
159#include "pshpack1.h"
160
162{
170};
171
173{
178};
179
181{
184 WCHAR label[12]; /* assume 8.3 */
185};
186
187#include "poppack.h"
188
189/* IShellLink Implementation */
190
191static HRESULT ShellLink_UpdatePath(LPCWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath);
192
193/* strdup on the process heap */
195{
196 INT len;
197 LPWSTR p;
198
199 assert(str);
200
201 len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
202 p = (LPWSTR)HeapAlloc(heap, flags, len * sizeof(WCHAR));
203 if (!p)
204 return p;
206 return p;
207}
208
210{
211 LPWSTR dest;
212 if (!src) return NULL;
213 dest = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wcslen(src) + 1) * sizeof(WCHAR));
214 if (dest)
215 wcscpy(dest, src);
216 return dest;
217}
218
220{
221 // Note: Don't call SHExpandEnvironmentStringsW here, we need the required length
222 WCHAR szStack[MAX_PATH];
223 DWORD cch = ExpandEnvironmentStringsW(pszPath, szStack, _countof(szStack));
224 if (cch <= _countof(szStack))
225 return cch && PathIsDirectory(szStack);
226
227 PWSTR szHeap = (PWSTR)SHAlloc(cch);
228 if (!szHeap)
229 return FALSE;
230 BOOL bResult = ExpandEnvironmentStringsW(pszPath, szHeap, cch) && PathIsDirectory(szHeap);
231 SHFree(szHeap);
232 return bResult;
233}
234
235// TODO: Use it for constructor & destructor too
237{
239 m_pPidl = NULL;
240
242 m_sPath = NULL;
243 ZeroMemory(&volume, sizeof(volume));
244
252 m_sArgs = NULL;
255
256 m_bRunAs = FALSE;
257 m_bDirty = FALSE;
258
259 if (m_pDBList)
261 m_pDBList = NULL;
262
264}
265
267{
268 m_Header.dwSize = sizeof(m_Header);
269 m_Header.clsid = CLSID_ShellLink;
270 m_Header.dwFlags = 0;
271
277
280 m_Header.wHotKey = 0;
281
282 m_pPidl = NULL;
283
284 m_sPath = NULL;
285 ZeroMemory(&volume, sizeof(volume));
286
290 m_sArgs = NULL;
292 m_bRunAs = FALSE;
293 m_bDirty = FALSE;
294 m_pDBList = NULL;
296 m_hIcon = NULL;
297 m_idCmdFirst = 0;
298
300
302}
303
305{
306 TRACE("-- destroying IShellLink(%p)\n", this);
307
309
311
319}
320
322{
323 TRACE("%p %p\n", this, pclsid);
324
325 if (pclsid == NULL)
326 return E_POINTER;
327 *pclsid = CLSID_ShellLink;
328 return S_OK;
329}
330
331/************************************************************************
332 * IPersistStream_IsDirty (IPersistStream)
333 */
335{
336 TRACE("(%p)\n", this);
337 return (m_bDirty ? S_OK : S_FALSE);
338}
339
341{
342 TRACE("(%p, %s, %x)\n", this, debugstr_w(pszFileName), dwMode);
343
344 if (dwMode == 0)
346
349 if (SUCCEEDED(hr))
350 {
353 hr = Load(stm);
355 m_bDirty = FALSE;
356 }
357 TRACE("-- returning hr %08x\n", hr);
358 return hr;
359}
360
362{
363 BOOL bAlreadyExists;
364 WCHAR szFullPath[MAX_PATH];
365
366 TRACE("(%p)->(%s)\n", this, debugstr_w(pszFileName));
367
368 if (!pszFileName)
369 return E_FAIL;
370
371 bAlreadyExists = PathFileExistsW(pszFileName);
372
375 if (SUCCEEDED(hr))
376 {
377 hr = Save(stm, FALSE);
378
379 if (SUCCEEDED(hr))
380 {
381 GetFullPathNameW(pszFileName, _countof(szFullPath), szFullPath, NULL);
382 if (bAlreadyExists)
384 else
386
387 if (m_sLinkPath)
389
391 m_bDirty = FALSE;
392 }
393 else
394 {
396 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName));
397 }
398 }
399
400 return hr;
401}
402
404{
405 FIXME("(%p)->(%s)\n", this, debugstr_w(pszFileName));
406 return S_OK;
407}
408
410{
411 *ppszFileName = NULL;
412
413 if (!m_sLinkPath)
414 {
415 /* IPersistFile::GetCurFile called before IPersistFile::Save */
416 return S_FALSE;
417 }
418
419 *ppszFileName = (LPOLESTR)CoTaskMemAlloc((wcslen(m_sLinkPath) + 1) * sizeof(WCHAR));
420 if (!*ppszFileName)
421 {
422 /* out of memory */
423 return E_OUTOFMEMORY;
424 }
425
426 /* copy last saved filename */
427 wcscpy(*ppszFileName, m_sLinkPath);
428
429 return S_OK;
430}
431
432static HRESULT Stream_LoadString(IStream* stm, BOOL unicode, LPWSTR *pstr)
433{
434 TRACE("%p\n", stm);
435
436 USHORT len;
437 DWORD count = 0;
438 HRESULT hr = stm->Read(&len, sizeof(len), &count);
439 if (FAILED(hr) || count != sizeof(len))
440 return E_FAIL;
441
442 if (unicode)
443 len *= sizeof(WCHAR);
444
445 TRACE("reading %d\n", len);
446 LPSTR temp = (LPSTR)HeapAlloc(GetProcessHeap(), 0, len + sizeof(WCHAR));
447 if (!temp)
448 return E_OUTOFMEMORY;
449 count = 0;
450 hr = stm->Read(temp, len, &count);
451 if (FAILED(hr) || count != len)
452 {
454 return E_FAIL;
455 }
456
457 TRACE("read %s\n", debugstr_an(temp, len));
458
459 /* convert to unicode if necessary */
460 LPWSTR str;
461 if (!unicode)
462 {
464 str = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (count + 1) * sizeof(WCHAR));
465 if (!str)
466 {
468 return E_OUTOFMEMORY;
469 }
472 }
473 else
474 {
475 count /= sizeof(WCHAR);
476 str = (LPWSTR)temp;
477 }
478 str[count] = 0;
479
480 *pstr = str;
481
482 return S_OK;
483}
484
485
486/*
487 * NOTE: The following 5 functions are part of LINKINFO.DLL
488 */
490{
491 WCHAR drive[4] = { path[0], ':', '\\', 0 };
492
493 volume->type = GetDriveTypeW(drive);
494 BOOL bRet = GetVolumeInformationW(drive, volume->label, _countof(volume->label), &volume->serial, NULL, NULL, NULL, 0);
495 TRACE("ret = %d type %d serial %08x name %s\n", bRet,
496 volume->type, volume->serial, debugstr_w(volume->label));
497 return bRet;
498}
499
501{
502 struct sized_chunk
503 {
504 DWORD size;
505 unsigned char data[1];
506 } *chunk;
507
508 TRACE("%p\n", stm);
509
510 DWORD size;
511 ULONG count;
512 HRESULT hr = stm->Read(&size, sizeof(size), &count);
513 if (FAILED(hr) || count != sizeof(size))
514 return E_FAIL;
515
516 chunk = static_cast<sized_chunk *>(HeapAlloc(GetProcessHeap(), 0, size));
517 if (!chunk)
518 return E_OUTOFMEMORY;
519
520 chunk->size = size;
521 hr = stm->Read(chunk->data, size - sizeof(size), &count);
522 if (FAILED(hr) || count != (size - sizeof(size)))
523 {
525 return E_FAIL;
526 }
527
528 TRACE("Read %d bytes\n", chunk->size);
529
530 *data = chunk;
531
532 return S_OK;
533}
534
536{
537 volume->serial = vol->dwVolSerial;
538 volume->type = vol->dwType;
539
540 if (!vol->dwVolLabelOfs)
541 return FALSE;
542 if (vol->dwSize <= vol->dwVolLabelOfs)
543 return FALSE;
544 INT len = vol->dwSize - vol->dwVolLabelOfs;
545
546 LPSTR label = (LPSTR)vol;
547 label += vol->dwVolLabelOfs; // FIXME: 0x14 Unicode
549
550 return TRUE;
551}
552
554{
555 UINT len = 0;
556
557 while (len < maxlen && p[len])
558 len++;
559
560 UINT wlen = MultiByteToWideChar(CP_ACP, 0, p, len, NULL, 0);
561 LPWSTR path = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, (wlen + 1) * sizeof(WCHAR));
562 if (!path)
563 return NULL;
564 MultiByteToWideChar(CP_ACP, 0, p, len, path, wlen);
565 path[wlen] = 0;
566
567 return path;
568}
569
572{
573 char *p = NULL;
574 HRESULT hr = Stream_ReadChunk(stm, (LPVOID*) &p);
575 if (FAILED(hr))
576 return hr;
577
578 LOCATION_INFO *loc = reinterpret_cast<LOCATION_INFO *>(p);
579 if (loc->dwTotalSize < sizeof(LOCATION_INFO))
580 {
582 return E_FAIL;
583 }
584
585 /* if there's valid local volume information, load it */
586 if (loc->dwVolTableOfs &&
587 ((loc->dwVolTableOfs + sizeof(LOCAL_VOLUME_INFO)) <= loc->dwTotalSize))
588 {
590
593 }
594
595 /* if there's a local path, load it */
596 DWORD n = loc->dwLocalPathOfs;
597 if (n && n < loc->dwTotalSize)
598 *path = Stream_LoadPath(&p[n], loc->dwTotalSize - n); // FIXME: Unicode offset (if present)
599
600 TRACE("type %d serial %08x name %s path %s\n", volume->type,
601 volume->serial, debugstr_w(volume->label), debugstr_w(*path));
602
604 return S_OK;
605}
606
607
608/*
609 * The format of the advertised shortcut info is:
610 *
611 * Offset Description
612 * ------ -----------
613 * 0 Length of the block (4 bytes, usually 0x314)
614 * 4 tag (dword)
615 * 8 string data in ASCII
616 * 8+0x104 string data in UNICODE
617 *
618 * In the original Win32 implementation the buffers are not initialized
619 * to zero, so data trailing the string is random garbage.
620 */
622{
623 LPEXP_DARWIN_LINK pInfo;
624
625 *str = NULL;
626
628 if (!pInfo)
629 return E_FAIL;
630
631 /* Make sure that the size of the structure is valid */
632 if (pInfo->dbh.cbSize != sizeof(*pInfo))
633 {
634 ERR("Ooops. This structure is not as expected...\n");
635 return E_FAIL;
636 }
637
638 TRACE("dwSig %08x string = '%s'\n", pInfo->dbh.dwSignature, debugstr_w(pInfo->szwDarwinID));
639
640 *str = pInfo->szwDarwinID;
641 return S_OK;
642}
643
644/************************************************************************
645 * IPersistStream_Load (IPersistStream)
646 */
648{
649 TRACE("%p %p\n", this, stm);
650
651 if (!stm)
653
654 /* Free all the old stuff */
655 Reset();
656
657 ULONG dwBytesRead = 0;
658 HRESULT hr = stm->Read(&m_Header, sizeof(m_Header), &dwBytesRead);
659 if (FAILED(hr))
660 return hr;
661
662 if (dwBytesRead != sizeof(m_Header))
663 return E_FAIL;
664 if (m_Header.dwSize != sizeof(m_Header))
665 return E_FAIL;
666 if (!IsEqualIID(m_Header.clsid, CLSID_ShellLink))
667 return E_FAIL;
668
669 /* Load the new data in order */
670
671 if (TRACE_ON(shell))
672 {
673 SYSTEMTIME stCreationTime;
674 SYSTEMTIME stLastAccessTime;
675 SYSTEMTIME stLastWriteTime;
676 WCHAR sTemp[MAX_PATH];
677
681
683 NULL, sTemp, _countof(sTemp));
684 TRACE("-- stCreationTime: %s\n", debugstr_w(sTemp));
686 NULL, sTemp, _countof(sTemp));
687 TRACE("-- stLastAccessTime: %s\n", debugstr_w(sTemp));
689 NULL, sTemp, _countof(sTemp));
690 TRACE("-- stLastWriteTime: %s\n", debugstr_w(sTemp));
691 }
692
693 /* load all the new stuff */
695 {
696 hr = ILLoadFromStream(stm, &m_pPidl);
697 if (FAILED(hr))
698 return hr;
699 }
700 pdump(m_pPidl);
701
702 /* Load the location information... */
704 {
706 if (FAILED(hr))
707 return hr;
708 }
709 /* ... but if it is required not to use it, clear it */
711 {
713 m_sPath = NULL;
714 ZeroMemory(&volume, sizeof(volume));
715 }
716
717 BOOL unicode = !!(m_Header.dwFlags & SLDF_UNICODE);
718
720 {
721 hr = Stream_LoadString(stm, unicode, &m_sDescription);
722 if (FAILED(hr))
723 return hr;
724 TRACE("Description -> %s\n", debugstr_w(m_sDescription));
725 }
726
728 {
729 hr = Stream_LoadString(stm, unicode, &m_sPathRel);
730 if (FAILED(hr))
731 return hr;
732 TRACE("Relative Path-> %s\n", debugstr_w(m_sPathRel));
733 }
734
736 {
737 hr = Stream_LoadString(stm, unicode, &m_sWorkDir);
738 if (FAILED(hr))
739 return hr;
741 TRACE("Working Dir -> %s\n", debugstr_w(m_sWorkDir));
742 }
743
745 {
746 hr = Stream_LoadString(stm, unicode, &m_sArgs);
747 if (FAILED(hr))
748 return hr;
749 TRACE("Arguments -> %s\n", debugstr_w(m_sArgs));
750 }
751
753 {
754 hr = Stream_LoadString(stm, unicode, &m_sIcoPath);
755 if (FAILED(hr))
756 return hr;
757 TRACE("Icon file -> %s\n", debugstr_w(m_sIcoPath));
758 }
759
760 /* Now load the optional data block list */
762 if (FAILED(hr)) // FIXME: Should we fail?
763 return hr;
764
766 if (pSpecial && pSpecial->cbSize == sizeof(*pSpecial) && ILGetSize(m_pPidl) > pSpecial->cbOffset)
767 {
769 {
770 LPITEMIDLIST pidl = ILCombine(folder, (LPITEMIDLIST)((char*)m_pPidl + pSpecial->cbOffset));
771 if (pidl)
772 {
774 m_pPidl = pidl;
775 TRACE("Replaced pidl base with CSIDL %u up to %ub.\n", pSpecial->idSpecialFolder, pSpecial->cbOffset);
776 }
777 ILFree(folder);
778 }
779 }
780
781 if (TRACE_ON(shell))
782 {
783#if (NTDDI_VERSION < NTDDI_LONGHORN)
785 {
786 hr = GetAdvertiseInfo(&sProduct, EXP_LOGO3_ID_SIG);
787 if (SUCCEEDED(hr))
788 TRACE("Product -> %s\n", debugstr_w(sProduct));
789 }
790#endif
792 {
794 if (SUCCEEDED(hr))
795 TRACE("Component -> %s\n", debugstr_w(sComponent));
796 }
797 }
798
800 m_bRunAs = TRUE;
801 else
802 m_bRunAs = FALSE;
803
804 TRACE("OK\n");
805
806 pdump(m_pPidl);
807
808 return S_OK;
809}
810
811/************************************************************************
812 * Stream_WriteString
813 *
814 * Helper function for IPersistStream_Save. Writes a unicode string
815 * with terminating nul byte to a stream, preceded by the its length.
816 */
818{
820 USHORT len;
821 DWORD count;
822
823 length = wcslen(str) + 1;
824 if (length > MAXUSHORT)
825 {
826 return E_INVALIDARG;
827 }
828
829 len = (USHORT)length;
830 HRESULT hr = stm->Write(&len, sizeof(len), &count);
831 if (FAILED(hr))
832 return hr;
833
834 length *= sizeof(WCHAR);
835
836 hr = stm->Write(str, (ULONG)length, &count);
837 if (FAILED(hr))
838 return hr;
839
840 return S_OK;
841}
842
843/************************************************************************
844 * Stream_WriteLocationInfo
845 *
846 * Writes the location info to a stream
847 *
848 * FIXME: One day we might want to write the network volume information
849 * and the final path.
850 * Figure out how Windows deals with unicode paths here.
851 */
853 CShellLink::volume_info *volume) // FIXME: Write Unicode strings
854{
856 LOCATION_INFO *loc;
857
858 TRACE("%p %s %p\n", stm, debugstr_w(path), volume);
859
860 /* figure out the size of everything */
861 DWORD label_size = WideCharToMultiByte(CP_ACP, 0, volume->label, -1,
862 NULL, 0, NULL, NULL);
863 DWORD path_size = WideCharToMultiByte(CP_ACP, 0, path, -1,
864 NULL, 0, NULL, NULL);
865 DWORD volume_info_size = sizeof(*vol) + label_size;
866 DWORD final_path_size = 1;
867 DWORD total_size = sizeof(*loc) + volume_info_size + path_size + final_path_size;
868
869 /* create pointers to everything */
870 loc = static_cast<LOCATION_INFO *>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, total_size));
871 vol = (LOCAL_VOLUME_INFO*) &loc[1];
872 LPSTR szLabel = (LPSTR) &vol[1];
873 LPSTR szPath = &szLabel[label_size];
874 LPSTR szFinalPath = &szPath[path_size];
875
876 /* fill in the location information header */
877 loc->dwTotalSize = total_size;
878 loc->dwHeaderSize = sizeof(*loc);
879 loc->dwFlags = 1;
880 loc->dwVolTableOfs = sizeof(*loc);
881 loc->dwLocalPathOfs = sizeof(*loc) + volume_info_size;
882 loc->dwNetworkVolTableOfs = 0;
883 loc->dwFinalPathOfs = sizeof(*loc) + volume_info_size + path_size;
884
885 /* fill in the volume information */
886 vol->dwSize = volume_info_size;
887 vol->dwType = volume->type;
888 vol->dwVolSerial = volume->serial;
889 vol->dwVolLabelOfs = sizeof(*vol);
890
891 /* copy in the strings */
892 WideCharToMultiByte(CP_ACP, 0, volume->label, -1,
893 szLabel, label_size, NULL, NULL);
895 szPath, path_size, NULL, NULL);
896 *szFinalPath = 0;
897
898 ULONG count = 0;
899 HRESULT hr = stm->Write(loc, total_size, &count);
900 HeapFree(GetProcessHeap(), 0, loc);
901
902 return hr;
903}
904
905/************************************************************************
906 * IPersistStream_Save (IPersistStream)
907 *
908 * FIXME: makes assumptions about byte order
909 */
911{
912 TRACE("%p %p %x\n", this, stm, fClearDirty);
913
914 m_Header.dwSize = sizeof(m_Header);
915 m_Header.clsid = CLSID_ShellLink;
917
918 /* Store target attributes */
919 WIN32_FIND_DATAW wfd = {};
920 WCHAR FsTarget[MAX_PATH];
921 if (GetPath(FsTarget, _countof(FsTarget), NULL, 0) == S_OK && PathFileExistsW(FsTarget))
922 {
923 HANDLE hFind = FindFirstFileW(FsTarget, &wfd);
924 if (hFind != INVALID_HANDLE_VALUE)
925 FindClose(hFind);
926 }
927 m_Header.dwFileAttributes = wfd.dwFileAttributes;
928 m_Header.ftCreationTime = wfd.ftCreationTime;
929 m_Header.ftLastAccessTime = wfd.ftLastAccessTime;
930 m_Header.ftLastWriteTime = wfd.ftLastWriteTime;
931 m_Header.nFileSizeLow = wfd.nFileSizeLow;
932
933 /*
934 * Reset the flags: keep only the flags related to data blocks as they were
935 * already set in accordance by the different mutator member functions.
936 * The other flags will be determined now by the presence or absence of data.
937 */
938 UINT NT6SimpleFlags = LOBYTE(GetVersion()) > 6 ? (0x00040000 | 0x00400000 | 0x00800000 | 0x02000000) : 0;
940 SLDF_HAS_DARWINID | SLDF_FORCE_NO_LINKINFO | NT6SimpleFlags |
941#if (NTDDI_VERSION < NTDDI_LONGHORN)
943#endif
945 // TODO: When we will support Vista+ functionality, add other flags to this list.
946
947 /* The stored strings are in UNICODE */
949
950 if (m_pPidl)
956 if (m_sPathRel && *m_sPathRel)
958 if (m_sWorkDir && *m_sWorkDir)
960 if (m_sArgs && *m_sArgs)
962 if (m_sIcoPath && *m_sIcoPath)
964 if (m_bRunAs)
966
967 /* Write the shortcut header */
968 ULONG count;
969 HRESULT hr = stm->Write(&m_Header, sizeof(m_Header), &count);
970 if (FAILED(hr))
971 {
972 ERR("Write failed\n");
973 return hr;
974 }
975
976 /* Save the data in order */
977
978 if (m_pPidl)
979 {
980 hr = ILSaveToStream(stm, m_pPidl);
981 if (FAILED(hr))
982 {
983 ERR("Failed to write PIDL\n");
984 return hr;
985 }
986 }
987
989 {
991 if (FAILED(hr))
992 return hr;
993 }
994
996 {
998 if (FAILED(hr))
999 return hr;
1000 }
1001
1003 {
1005 if (FAILED(hr))
1006 return hr;
1007 }
1008
1010 {
1012 if (FAILED(hr))
1013 return hr;
1014 }
1015
1017 {
1019 if (FAILED(hr))
1020 return hr;
1021 }
1022
1024 {
1026 if (FAILED(hr))
1027 return hr;
1028 }
1029
1030 /*
1031 * Now save the data block list.
1032 *
1033 * NOTE that both advertised Product and Component are already saved
1034 * inside Logo3 and Darwin data blocks in the m_pDBList list, and the
1035 * m_Header.dwFlags is suitably initialized.
1036 */
1038 if (FAILED(hr))
1039 return hr;
1040
1041 /* Clear the dirty bit if requested */
1042 if (fClearDirty)
1043 m_bDirty = FALSE;
1044
1045 return hr;
1046}
1047
1048/************************************************************************
1049 * IPersistStream_GetSizeMax (IPersistStream)
1050 */
1052{
1053 TRACE("(%p)\n", this);
1054 return E_NOTIMPL;
1055}
1056
1058{
1060 return FALSE;
1061
1062 return TRUE;
1063}
1064
1065/**************************************************************************
1066 * ShellLink_UpdatePath
1067 * update absolute path in sPath using relative path in sPathRel
1068 */
1069static HRESULT ShellLink_UpdatePath(LPCWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath)
1070{
1071 if (!path || !psPath)
1072 return E_INVALIDARG;
1073
1074 if (!*psPath && sPathRel)
1075 {
1076 WCHAR buffer[2*MAX_PATH], abs_path[2*MAX_PATH];
1077 LPWSTR final = NULL;
1078
1079 /* first try if [directory of link file] + [relative path] finds an existing file */
1080
1081 GetFullPathNameW(path, MAX_PATH * 2, buffer, &final);
1082 if (!final)
1083 final = buffer;
1084 wcscpy(final, sPathRel);
1085
1086 *abs_path = '\0';
1087
1089 {
1090 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1091 wcscpy(abs_path, buffer);
1092 }
1093 else
1094 {
1095 /* try if [working directory] + [relative path] finds an existing file */
1096 if (sWorkDir)
1097 {
1098 wcscpy(buffer, sWorkDir);
1099 wcscpy(PathAddBackslashW(buffer), sPathRel);
1100
1102 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1103 wcscpy(abs_path, buffer);
1104 }
1105 }
1106
1107 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1108 if (!*abs_path)
1109 wcscpy(abs_path, sPathRel);
1110
1111 *psPath = strdupW(abs_path);
1112 if (!*psPath)
1113 return E_OUTOFMEMORY;
1114 }
1115
1116 return S_OK;
1117}
1118
1120{
1121 HRESULT hr;
1122 LPWSTR pszFileW;
1123 WIN32_FIND_DATAW wfd;
1124
1125 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1126 this, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(m_sPath));
1127
1128 /* Allocate a temporary UNICODE buffer */
1129 pszFileW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, max(cchMaxPath, MAX_PATH) * sizeof(WCHAR));
1130 if (!pszFileW)
1131 return E_OUTOFMEMORY;
1132
1133 /* Call the UNICODE function */
1134 hr = GetPath(pszFileW, cchMaxPath, &wfd, fFlags);
1135
1136 /* Convert the file path back to ANSI */
1137 WideCharToMultiByte(CP_ACP, 0, pszFileW, -1,
1138 pszFile, cchMaxPath, NULL, NULL);
1139
1140 /* Free the temporary buffer */
1141 HeapFree(GetProcessHeap(), 0, pszFileW);
1142
1143 if (pfd)
1144 {
1145 ZeroMemory(pfd, sizeof(*pfd));
1146
1147 /* Copy the file data if a file path was returned */
1148 if (*pszFile)
1149 {
1150 DWORD len;
1151
1152 /* Copy the fixed part */
1153 CopyMemory(pfd, &wfd, FIELD_OFFSET(WIN32_FIND_DATAA, cFileName));
1154
1155 /* Convert the file names to ANSI */
1156 len = lstrlenW(wfd.cFileName);
1157 WideCharToMultiByte(CP_ACP, 0, wfd.cFileName, len + 1,
1158 pfd->cFileName, sizeof(pfd->cFileName), NULL, NULL);
1159 len = lstrlenW(wfd.cAlternateFileName);
1160 WideCharToMultiByte(CP_ACP, 0, wfd.cAlternateFileName, len + 1,
1161 pfd->cAlternateFileName, sizeof(pfd->cAlternateFileName), NULL, NULL);
1162 }
1163 }
1164
1165 return hr;
1166}
1167
1169{
1170 TRACE("(%p)->(ppidl=%p)\n", this, ppidl);
1171
1172 if (!m_pPidl)
1173 {
1174 *ppidl = NULL;
1175 return S_FALSE;
1176 }
1177
1178 *ppidl = ILClone(m_pPidl);
1179 return S_OK;
1180}
1181
1183{
1184 TRACE("(%p)->(pidl=%p)\n", this, pidl);
1185 return SetTargetFromPIDLOrPath(pidl, NULL);
1186}
1187
1189{
1190 TRACE("(%p)->(%p len=%u)\n", this, pszName, cchMaxName);
1191
1192 if (cchMaxName)
1193 *pszName = 0;
1194
1195 if (m_sDescription)
1197 pszName, cchMaxName, NULL, NULL);
1198
1199 return S_OK;
1200}
1201
1203{
1204 TRACE("(%p)->(pName=%s)\n", this, pszName);
1205
1208
1209 if (pszName)
1210 {
1212 if (!m_sDescription)
1213 return E_OUTOFMEMORY;
1214 }
1215 m_bDirty = TRUE;
1216
1217 return S_OK;
1218}
1219
1221{
1222 TRACE("(%p)->(%p len=%u)\n", this, pszDir, cchMaxPath);
1223
1224 if (cchMaxPath)
1225 *pszDir = 0;
1226
1227 if (m_sWorkDir)
1229 pszDir, cchMaxPath, NULL, NULL);
1230
1231 return S_OK;
1232}
1233
1235{
1236 TRACE("(%p)->(dir=%s)\n", this, pszDir);
1237
1239 m_sWorkDir = NULL;
1240
1241 if (pszDir)
1242 {
1244 if (!m_sWorkDir)
1245 return E_OUTOFMEMORY;
1246 }
1247 m_bDirty = TRUE;
1248
1249 return S_OK;
1250}
1251
1253{
1254 TRACE("(%p)->(%p len=%u)\n", this, pszArgs, cchMaxPath);
1255
1256 if (cchMaxPath)
1257 *pszArgs = 0;
1258
1259 if (m_sArgs)
1261 pszArgs, cchMaxPath, NULL, NULL);
1262
1263 return S_OK;
1264}
1265
1267{
1268 TRACE("(%p)->(args=%s)\n", this, pszArgs);
1269
1271 m_sArgs = NULL;
1272
1273 if (pszArgs)
1274 {
1275 m_sArgs = HEAP_strdupAtoW(GetProcessHeap(), 0, pszArgs);
1276 if (!m_sArgs)
1277 return E_OUTOFMEMORY;
1278 }
1279 m_bDirty = TRUE;
1280
1281 return S_OK;
1282}
1283
1285{
1286 TRACE("(%p)->(%p)(0x%08x)\n", this, pwHotkey, m_Header.wHotKey);
1287 *pwHotkey = m_Header.wHotKey;
1288 return S_OK;
1289}
1290
1292{
1293 TRACE("(%p)->(hotkey=%x)\n", this, wHotkey);
1294
1295 m_Header.wHotKey = wHotkey;
1296 m_bDirty = TRUE;
1297
1298 return S_OK;
1299}
1300
1302{
1303 TRACE("(%p)->(%p) %d\n", this, piShowCmd, m_Header.nShowCommand);
1304 *piShowCmd = m_Header.nShowCommand;
1305 return S_OK;
1306}
1307
1309{
1310 TRACE("(%p) %d\n", this, iShowCmd);
1311
1312 m_Header.nShowCommand = iShowCmd;
1313 m_bDirty = TRUE;
1314
1315 return S_OK;
1316}
1317
1319{
1320 HRESULT hr;
1321 LPWSTR pszIconPathW;
1322
1323 TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath, cchIconPath, piIcon);
1324
1325 /* Allocate a temporary UNICODE buffer */
1326 pszIconPathW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, cchIconPath * sizeof(WCHAR));
1327 if (!pszIconPathW)
1328 return E_OUTOFMEMORY;
1329
1330 /* Call the UNICODE function */
1331 hr = GetIconLocation(pszIconPathW, cchIconPath, piIcon);
1332
1333 /* Convert the file path back to ANSI */
1334 WideCharToMultiByte(CP_ACP, 0, pszIconPathW, -1,
1335 pszIconPath, cchIconPath, NULL, NULL);
1336
1337 /* Free the temporary buffer */
1338 HeapFree(GetProcessHeap(), 0, pszIconPathW);
1339
1340 return hr;
1341}
1342
1344{
1345 HRESULT hr;
1346 LPWSTR pszIconFileW;
1347
1348 TRACE("(%p)->(%u %p len=%u piIndex=%p pwFlags=%p)\n", this, uFlags, pszIconFile, cchMax, piIndex, pwFlags);
1349
1350 /* Allocate a temporary UNICODE buffer */
1351 pszIconFileW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, cchMax * sizeof(WCHAR));
1352 if (!pszIconFileW)
1353 return E_OUTOFMEMORY;
1354
1355 /* Call the UNICODE function */
1356 hr = GetIconLocation(uFlags, pszIconFileW, cchMax, piIndex, pwFlags);
1357
1358 /* Convert the file path back to ANSI */
1359 WideCharToMultiByte(CP_ACP, 0, pszIconFileW, -1,
1360 pszIconFile, cchMax, NULL, NULL);
1361
1362 /* Free the temporary buffer */
1363 HeapFree(GetProcessHeap(), 0, pszIconFileW);
1364
1365 return hr;
1366}
1367
1368HRESULT STDMETHODCALLTYPE CShellLink::Extract(PCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
1369{
1370 TRACE("(%p)->(path=%s iicon=%u)\n", this, pszFile, nIconIndex);
1371
1372 LPWSTR str = NULL;
1373 if (pszFile)
1374 {
1375 str = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1376 if (!str)
1377 return E_OUTOFMEMORY;
1378 }
1379
1380 HRESULT hr = Extract(str, nIconIndex, phiconLarge, phiconSmall, nIconSize);
1381
1382 if (str)
1384
1385 return hr;
1386}
1387
1389{
1390 TRACE("(%p)->(path=%s iicon=%u)\n", this, pszIconPath, iIcon);
1391
1392 LPWSTR str = NULL;
1393 if (pszIconPath)
1394 {
1395 str = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1396 if (!str)
1397 return E_OUTOFMEMORY;
1398 }
1399
1400 HRESULT hr = SetIconLocation(str, iIcon);
1401
1402 if (str)
1404
1405 return hr;
1406}
1407
1409{
1410 TRACE("(%p)->(path=%s %x)\n", this, pszPathRel, dwReserved);
1411
1413 m_sPathRel = NULL;
1414
1415 if (pszPathRel)
1416 {
1417 m_sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1418 m_bDirty = TRUE;
1419 }
1420
1422}
1423
1424static LPWSTR
1426{
1427 DWORD Result, sz = 0;
1428
1429 Result = CommandLineFromMsiDescriptor(component, NULL, &sz);
1430 if (Result != ERROR_SUCCESS)
1431 return NULL;
1432
1433 sz++;
1434 LPWSTR path = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sz * sizeof(WCHAR));
1435 Result = CommandLineFromMsiDescriptor(component, path, &sz);
1436 if (Result != ERROR_SUCCESS)
1437 {
1439 path = NULL;
1440 }
1441
1442 TRACE("returning %s\n", debugstr_w(path));
1443
1444 return path;
1445}
1446
1448{
1449 HRESULT hr = S_OK;
1450 BOOL bSuccess;
1451
1452 TRACE("(%p)->(hwnd=%p flags=%x)\n", this, hwnd, fFlags);
1453
1454 /* FIXME: use IResolveShellLink interface? */
1455
1456 // FIXME: See InvokeCommand().
1457
1458#if (NTDDI_VERSION < NTDDI_LONGHORN)
1459 // NOTE: For Logo3 (EXP_LOGO3_ID_SIG), check also for SHRestricted(REST_NOLOGO3CHANNELNOTIFY)
1461 {
1462 FIXME("Logo3 links are not supported yet!\n");
1463 return E_FAIL;
1464 }
1465#endif
1466
1467 /* Resolve Darwin (MSI) target */
1469 {
1470 LPWSTR component = NULL;
1471 hr = GetAdvertiseInfo(&component, EXP_DARWIN_ID_SIG);
1472 if (FAILED(hr))
1473 return E_FAIL;
1474
1475 /* Clear the cached path */
1478 if (!m_sPath)
1479 return E_FAIL;
1480 }
1481
1482 if (!m_sPath && m_pPidl)
1483 {
1485
1486 bSuccess = SHGetPathFromIDListW(m_pPidl, buffer);
1487 if (bSuccess && *buffer)
1488 {
1490 if (!m_sPath)
1491 return E_OUTOFMEMORY;
1492
1493 m_bDirty = TRUE;
1494 }
1495 else
1496 {
1497 hr = S_OK; /* don't report an error occurred while just caching information */
1498 }
1499 }
1500
1501 // FIXME: Strange to do that here...
1502 if (!m_sIcoPath && m_sPath)
1503 {
1505 if (!m_sIcoPath)
1506 return E_OUTOFMEMORY;
1507
1508 m_Header.nIconIndex = 0;
1509
1510 m_bDirty = TRUE;
1511 }
1512
1513 return hr;
1514}
1515
1517{
1518 TRACE("(%p)->(path=%s)\n", this, pszFile);
1519
1520 if (!pszFile)
1521 return E_INVALIDARG;
1522
1523 LPWSTR str = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1524 if (!str)
1525 return E_OUTOFMEMORY;
1526
1527 HRESULT hr = SetPath(str);
1529
1530 return hr;
1531}
1532
1534{
1536
1537 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1538 this, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(m_sPath));
1539
1540 if (cchMaxPath)
1541 *pszFile = 0;
1542 // FIXME: What if cchMaxPath == 0 , or pszFile == NULL ??
1543
1544 // FIXME: What about Darwin??
1545
1546 /*
1547 * Retrieve the path to the target from the PIDL (if we have one).
1548 * NOTE: Do NOT use the cached path (m_sPath from link info).
1549 */
1551 {
1552 if (fFlags & SLGP_SHORTPATH)
1554 // FIXME: Add support for SLGP_UNCPRIORITY
1555 }
1556 else
1557 {
1558 *buffer = 0;
1559 }
1560
1561 /* If we have a FindData structure, initialize it */
1562 if (pfd)
1563 {
1564 ZeroMemory(pfd, sizeof(*pfd));
1565
1566 /* Copy the file data if the target is a file path */
1567 if (*buffer)
1568 {
1569 pfd->dwFileAttributes = m_Header.dwFileAttributes;
1570 pfd->ftCreationTime = m_Header.ftCreationTime;
1571 pfd->ftLastAccessTime = m_Header.ftLastAccessTime;
1572 pfd->ftLastWriteTime = m_Header.ftLastWriteTime;
1573 pfd->nFileSizeHigh = 0;
1574 pfd->nFileSizeLow = m_Header.nFileSizeLow;
1575
1576 /*
1577 * Build temporarily a short path in pfd->cFileName (of size MAX_PATH),
1578 * then extract and store the short file name in pfd->cAlternateFileName.
1579 */
1580 GetShortPathNameW(buffer, pfd->cFileName, _countof(pfd->cFileName));
1581 lstrcpynW(pfd->cAlternateFileName,
1582 PathFindFileNameW(pfd->cFileName),
1583 _countof(pfd->cAlternateFileName));
1584
1585 /* Now extract and store the long file name in pfd->cFileName */
1586 lstrcpynW(pfd->cFileName,
1588 _countof(pfd->cFileName));
1589 }
1590 }
1591
1592 /* Finally check if we have a raw path the user actually wants to retrieve */
1593 if ((fFlags & SLGP_RAWPATH) && (m_Header.dwFlags & SLDF_HAS_EXP_SZ))
1594 {
1595 /* Search for a target environment block */
1596 LPEXP_SZ_LINK pInfo;
1598 if (pInfo && (pInfo->cbSize == sizeof(*pInfo)))
1599 lstrcpynW(buffer, pInfo->szwTarget, cchMaxPath);
1600 }
1601
1602 /* For diagnostics purposes only... */
1603 // NOTE: SLGP_UNCPRIORITY is unsupported
1604 fFlags &= ~(SLGP_RAWPATH | SLGP_SHORTPATH);
1605 if (fFlags) FIXME("(%p): Unsupported flags %lu\n", this, fFlags);
1606
1607 /* Copy the data back to the user */
1608 if (*buffer)
1609 lstrcpynW(pszFile, buffer, cchMaxPath);
1610
1611 return (*buffer ? S_OK : S_FALSE);
1612}
1613
1615{
1616 TRACE("(%p)->(%p len=%u)\n", this, pszName, cchMaxName);
1617
1618 *pszName = 0;
1619 if (m_sDescription)
1620 lstrcpynW(pszName, m_sDescription, cchMaxName);
1621
1622 return S_OK;
1623}
1624
1626{
1627 TRACE("(%p)->(desc=%s)\n", this, debugstr_w(pszName));
1628
1631
1632 if (pszName)
1633 {
1634 m_sDescription = strdupW(pszName);
1635 if (!m_sDescription)
1636 return E_OUTOFMEMORY;
1637 }
1638 m_bDirty = TRUE;
1639
1640 return S_OK;
1641}
1642
1644{
1645 TRACE("(%p)->(%p len %u)\n", this, pszDir, cchMaxPath);
1646
1647 if (cchMaxPath)
1648 *pszDir = 0;
1649
1650 if (m_sWorkDir)
1651 lstrcpynW(pszDir, m_sWorkDir, cchMaxPath);
1652
1653 return S_OK;
1654}
1655
1657{
1658 TRACE("(%p)->(dir=%s)\n", this, debugstr_w(pszDir));
1659
1661 m_sWorkDir = NULL;
1662
1663 if (pszDir)
1664 {
1666 if (!m_sWorkDir)
1667 return E_OUTOFMEMORY;
1668 }
1669 m_bDirty = TRUE;
1670
1671 return S_OK;
1672}
1673
1675{
1676 TRACE("(%p)->(%p len=%u)\n", this, pszArgs, cchMaxPath);
1677
1678 if (cchMaxPath)
1679 *pszArgs = 0;
1680
1681 if (m_sArgs)
1682 lstrcpynW(pszArgs, m_sArgs, cchMaxPath);
1683
1684 return S_OK;
1685}
1686
1688{
1689 TRACE("(%p)->(args=%s)\n", this, debugstr_w(pszArgs));
1690
1692 m_sArgs = NULL;
1693
1694 if (pszArgs)
1695 {
1696 m_sArgs = strdupW(pszArgs);
1697 if (!m_sArgs)
1698 return E_OUTOFMEMORY;
1699 }
1700 m_bDirty = TRUE;
1701
1702 return S_OK;
1703}
1704
1706{
1707 TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath, cchIconPath, piIcon);
1708
1709 if (cchIconPath)
1710 *pszIconPath = 0;
1711
1712 *piIcon = 0;
1713
1714 /* Update the original icon path location */
1716 {
1718
1719 /* Search for an icon environment block */
1720 LPEXP_SZ_LINK pInfo;
1722 if (pInfo && (pInfo->cbSize == sizeof(*pInfo)))
1723 {
1725
1726 m_Header.dwFlags &= ~SLDF_HAS_ICONLOCATION;
1728
1730 if (!m_sIcoPath)
1731 return E_OUTOFMEMORY;
1732
1734
1735 m_bDirty = TRUE;
1736 }
1737 }
1738
1739 *piIcon = m_Header.nIconIndex;
1740
1741 if (m_sIcoPath)
1742 lstrcpynW(pszIconPath, m_sIcoPath, cchIconPath);
1743
1744 return S_OK;
1745}
1746
1748 UINT uFlags, PWSTR pszIconFile, UINT cchMax, int *piIndex, UINT *pwFlags)
1749{
1753 return hr;
1754 hr = pei->GetIconLocation(uFlags, pszIconFile, cchMax, piIndex, pwFlags);
1756 return hr;
1757
1758 return S_OK;
1759}
1760
1762{
1763 HRESULT hr;
1764
1765 pszIconFile[0] = UNICODE_NULL;
1766
1767 /*
1768 * It is possible for a shell link to point to another shell link,
1769 * and in particular there is the possibility to point to itself.
1770 * Now, suppose we ask such a link to retrieve its associated icon.
1771 * This function would be called, and due to COM would be called again
1772 * recursively. To solve this issue, we forbid calling GetIconLocation()
1773 * with GIL_FORSHORTCUT set in uFlags, as done by Windows (shown by tests).
1774 */
1775 if (uFlags & GIL_FORSHORTCUT)
1776 return E_INVALIDARG;
1777
1778 /*
1779 * Now, we set GIL_FORSHORTCUT so that: i) we allow the icon extractor
1780 * of the target to give us a suited icon, and ii) we protect ourselves
1781 * against recursive call.
1782 */
1783 uFlags |= GIL_FORSHORTCUT;
1784
1785 if (uFlags & GIL_DEFAULTICON)
1786 return S_FALSE;
1787
1788 hr = GetIconLocation(pszIconFile, cchMax, piIndex);
1789 if (FAILED(hr) || pszIconFile[0] == UNICODE_NULL)
1790 {
1791 hr = SHELL_PidlGetIconLocationW(m_pPidl, uFlags, pszIconFile, cchMax, piIndex, pwFlags);
1792 }
1793 else
1794 {
1795 // TODO: If GetIconLocation succeeded, why are we setting GIL_NOTFILENAME? And are we not PERINSTANCE?
1796 *pwFlags = GIL_NOTFILENAME | GIL_PERCLASS;
1797 }
1798
1799 return hr;
1800}
1801
1803CShellLink::Extract(PCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize)
1804{
1805 HRESULT hr = NOERROR;
1806 UINT cxyLarge = LOWORD(nIconSize), cxySmall = HIWORD(nIconSize);
1807
1808 if (phiconLarge)
1809 {
1810 *phiconLarge = NULL;
1811 PrivateExtractIconsW(pszFile, nIconIndex, cxyLarge, cxyLarge, phiconLarge, NULL, 1, 0);
1812
1813 if (*phiconLarge == NULL)
1814 hr = S_FALSE;
1815 }
1816
1817 if (phiconSmall)
1818 {
1819 *phiconSmall = NULL;
1820 PrivateExtractIconsW(pszFile, nIconIndex, cxySmall, cxySmall, phiconSmall, NULL, 1, 0);
1821
1822 if (*phiconSmall == NULL)
1823 hr = S_FALSE;
1824 }
1825
1826 if (hr == S_FALSE)
1827 {
1828 if (phiconLarge && *phiconLarge)
1829 {
1830 DestroyIcon(*phiconLarge);
1831 *phiconLarge = NULL;
1832 }
1833 if (phiconSmall && *phiconSmall)
1834 {
1835 DestroyIcon(*phiconSmall);
1836 *phiconSmall = NULL;
1837 }
1838 }
1839
1840 return hr;
1841}
1842
1843#if 0
1844/* Extends the functionality of PathUnExpandEnvStringsW */
1845BOOL PathFullyUnExpandEnvStringsW(
1846 _In_ LPCWSTR pszPath,
1847 _Out_ LPWSTR pszBuf,
1848 _In_ UINT cchBuf)
1849{
1850 BOOL Ret = FALSE; // Set to TRUE as soon as PathUnExpandEnvStrings starts unexpanding.
1851 BOOL res;
1852 LPCWSTR p;
1853
1854 // *pszBuf = L'\0';
1855 while (*pszPath && cchBuf > 0)
1856 {
1857 /* Attempt unexpanding the path */
1858 res = PathUnExpandEnvStringsW(pszPath, pszBuf, cchBuf);
1859 if (!res)
1860 {
1861 /* The unexpansion failed. Try to find a path delimiter. */
1862 p = wcspbrk(pszPath, L" /\\:*?\"<>|%");
1863 if (!p) /* None found, we will copy the remaining path */
1864 p = pszPath + wcslen(pszPath);
1865 else /* Found one, we will copy the delimiter and skip it */
1866 ++p;
1867 /* If we overflow, we cannot unexpand more, so return FALSE */
1868 if (p - pszPath >= cchBuf)
1869 return FALSE; // *pszBuf = L'\0';
1870
1871 /* Copy the untouched portion of path up to the delimiter, included */
1872 wcsncpy(pszBuf, pszPath, p - pszPath);
1873 pszBuf[p - pszPath] = L'\0'; // NULL-terminate
1874
1875 /* Advance the pointers and decrease the remaining buffer size */
1876 cchBuf -= (p - pszPath);
1877 pszBuf += (p - pszPath);
1878 pszPath += (p - pszPath);
1879 }
1880 else
1881 {
1882 /*
1883 * The unexpansion succeeded. Skip the unexpanded part by trying
1884 * to find where the original path and the unexpanded string
1885 * become different.
1886 * NOTE: An alternative(?) would be to stop also at the last
1887 * path delimiter encountered in the loop (i.e. would be the
1888 * first path delimiter in the strings).
1889 */
1890 LPWSTR q;
1891
1892 /*
1893 * The algorithm starts at the end of the strings and loops back
1894 * while the characters are equal, until it finds a discrepancy.
1895 */
1896 p = pszPath + wcslen(pszPath);
1897 q = pszBuf + wcslen(pszBuf); // This wcslen should be < cchBuf
1898 while ((*p == *q) && (p > pszPath) && (q > pszBuf))
1899 {
1900 --p; --q;
1901 }
1902 /* Skip discrepancy */
1903 ++p; ++q;
1904
1905 /* Advance the pointers and decrease the remaining buffer size */
1906 cchBuf -= (q - pszBuf);
1907 pszBuf = q;
1908 pszPath = p;
1909
1910 Ret = TRUE;
1911 }
1912 }
1913
1914 return Ret;
1915}
1916#endif
1917
1919{
1920 HRESULT hr = E_FAIL;
1921 WCHAR szIconPath[MAX_PATH];
1922
1923 TRACE("(%p)->(path=%s iicon=%u)\n", this, debugstr_w(pszIconPath), iIcon);
1924
1925 if (pszIconPath)
1926 {
1927 /*
1928 * Check whether the user-given file path contains unexpanded
1929 * environment variables. If so, create a target environment block.
1930 * Note that in this block we will store the user-given path.
1931 * It will contain the unexpanded environment variables, but
1932 * it can also contain already expanded path that the user does
1933 * not want to see them unexpanded (e.g. so that they always
1934 * refer to the same place even if the would-be corresponding
1935 * environment variable could change).
1936 */
1937#ifdef ICON_LINK_WINDOWS_COMPAT
1938 /* Try to fully unexpand the icon path */
1939 // if (PathFullyUnExpandEnvStringsW(pszIconPath, szIconPath, _countof(szIconPath)))
1940 BOOL bSuccess = PathUnExpandEnvStringsW(pszIconPath, szIconPath, _countof(szIconPath));
1941 if (bSuccess && wcscmp(pszIconPath, szIconPath) != 0)
1942#else
1943 /*
1944 * In some situations, described in http://stackoverflow.com/questions/2976489/ishelllinkseticonlocation-translates-my-icon-path-into-program-files-which-i
1945 * the result of PathUnExpandEnvStringsW() could be wrong, and instead
1946 * one would have to store the actual provided icon location path, while
1947 * creating an icon environment block ONLY if that path already contains
1948 * environment variables. This is what the present case is trying to implement.
1949 */
1950 SHExpandEnvironmentStringsW(pszIconPath, szIconPath, _countof(szIconPath));
1951 if (wcscmp(pszIconPath, szIconPath) != 0)
1952#endif
1953 {
1954 /*
1955 * The user-given file path contains unexpanded environment
1956 * variables, so we need an icon environment block.
1957 */
1959 LPEXP_SZ_LINK pInfo;
1960
1961#ifdef ICON_LINK_WINDOWS_COMPAT
1962 /* Make pszIconPath point to the unexpanded path */
1963 LPCWSTR pszOrgIconPath = pszIconPath;
1964 pszIconPath = szIconPath;
1965#endif
1967 if (pInfo)
1968 {
1969 /* Make sure that the size of the structure is valid */
1970 if (pInfo->cbSize != sizeof(*pInfo))
1971 {
1972 ERR("Ooops. This structure is not as expected...\n");
1973
1974 /* Invalid structure, remove it altogether */
1975 m_Header.dwFlags &= ~SLDF_HAS_EXP_ICON_SZ;
1977
1978 /* Reset the pointer and go use the static buffer */
1979 pInfo = NULL;
1980 }
1981 }
1982 if (!pInfo)
1983 {
1984 /* Use the static buffer */
1985 pInfo = &buffer;
1986 buffer.cbSize = sizeof(buffer);
1987 buffer.dwSignature = EXP_SZ_ICON_SIG;
1988 }
1989
1990 lstrcpynW(pInfo->szwTarget, pszIconPath, _countof(pInfo->szwTarget));
1991 WideCharToMultiByte(CP_ACP, 0, pszIconPath, -1,
1992 pInfo->szTarget, _countof(pInfo->szTarget), NULL, NULL);
1993
1994 hr = S_OK;
1995 if (pInfo == &buffer)
1996 hr = AddDataBlock(pInfo);
1997 if (hr == S_OK)
1999
2000#ifdef ICON_LINK_WINDOWS_COMPAT
2001 /* Set pszIconPath back to the original one */
2002 pszIconPath = pszOrgIconPath;
2003#else
2004 /* Now, make pszIconPath point to the expanded path */
2005 pszIconPath = szIconPath;
2006#endif
2007 }
2008 else
2009 {
2010 /*
2011 * The user-given file path does not contain unexpanded environment
2012 * variables, so we need to remove any icon environment block.
2013 */
2014 m_Header.dwFlags &= ~SLDF_HAS_EXP_ICON_SZ;
2016
2017 /* pszIconPath points to the user path */
2018 }
2019 }
2020
2021#ifdef ICON_LINK_WINDOWS_COMPAT
2022 /* Store the original icon path location (may contain unexpanded environment strings) */
2023#endif
2024 if (pszIconPath)
2025 {
2026 m_Header.dwFlags &= ~SLDF_HAS_ICONLOCATION;
2028
2029 m_sIcoPath = strdupW(pszIconPath);
2030 if (!m_sIcoPath)
2031 return E_OUTOFMEMORY;
2032
2034 }
2035
2036 hr = S_OK;
2037
2038 m_Header.nIconIndex = iIcon;
2039 m_bDirty = TRUE;
2040
2041 return hr;
2042}
2043
2045{
2046 TRACE("(%p)->(path=%s %x)\n", this, debugstr_w(pszPathRel), dwReserved);
2047
2049 m_sPathRel = NULL;
2050
2051 if (pszPathRel)
2052 {
2053 m_sPathRel = strdupW(pszPathRel);
2054 if (!m_sPathRel)
2055 return E_OUTOFMEMORY;
2056 }
2057 m_bDirty = TRUE;
2058
2060}
2061
2063{
2064 if (!str)
2065 return NULL;
2066
2067 LPCWSTR p = wcschr(str, L':');
2068 if (!p)
2069 return NULL;
2070
2071 DWORD len = p - str;
2072 LPWSTR ret = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (len + 1));
2073 if (!ret)
2074 return ret;
2075
2076 memcpy(ret, str, sizeof(WCHAR)*len);
2077 ret[len] = 0;
2078 return ret;
2079}
2080
2082{
2084 LPEXP_DARWIN_LINK pInfo;
2085
2086 if ( (dwSig != EXP_DARWIN_ID_SIG)
2088 && (dwSig != EXP_LOGO3_ID_SIG)
2089#endif
2090 )
2091 {
2092 return E_INVALIDARG;
2093 }
2094
2095 if (!string)
2096 return S_FALSE;
2097
2099 if (pInfo)
2100 {
2101 /* Make sure that the size of the structure is valid */
2102 if (pInfo->dbh.cbSize != sizeof(*pInfo))
2103 {
2104 ERR("Ooops. This structure is not as expected...\n");
2105
2106 /* Invalid structure, remove it altogether */
2107 if (dwSig == EXP_DARWIN_ID_SIG)
2108 m_Header.dwFlags &= ~SLDF_HAS_DARWINID;
2109#if (NTDDI_VERSION < NTDDI_LONGHORN)
2110 else if (dwSig == EXP_LOGO3_ID_SIG)
2111 m_Header.dwFlags &= ~SLDF_HAS_LOGO3ID;
2112#endif
2113 RemoveDataBlock(dwSig);
2114
2115 /* Reset the pointer and go use the static buffer */
2116 pInfo = NULL;
2117 }
2118 }
2119 if (!pInfo)
2120 {
2121 /* Use the static buffer */
2122 pInfo = &buffer;
2123 buffer.dbh.cbSize = sizeof(buffer);
2124 buffer.dbh.dwSignature = dwSig;
2125 }
2126
2127 lstrcpynW(pInfo->szwDarwinID, string, _countof(pInfo->szwDarwinID));
2128 WideCharToMultiByte(CP_ACP, 0, string, -1,
2129 pInfo->szDarwinID, _countof(pInfo->szDarwinID), NULL, NULL);
2130
2131 HRESULT hr = S_OK;
2132 if (pInfo == &buffer)
2133 hr = AddDataBlock(pInfo);
2134 if (hr == S_OK)
2135 {
2136 if (dwSig == EXP_DARWIN_ID_SIG)
2138#if (NTDDI_VERSION < NTDDI_LONGHORN)
2139 else if (dwSig == EXP_LOGO3_ID_SIG)
2141#endif
2142 }
2143
2144 return hr;
2145}
2146
2148{
2149 HRESULT hr;
2150 LPCWSTR szComponent = NULL, szProduct = NULL, p;
2151 INT len;
2152 GUID guid;
2153 WCHAR szGuid[38+1];
2154
2156
2157 while (str[0])
2158 {
2159 /* each segment must start with two colons */
2160 if (str[0] != ':' || str[1] != ':')
2161 return E_FAIL;
2162
2163 /* the last segment is just two colons */
2164 if (!str[2])
2165 break;
2166 str += 2;
2167
2168 /* there must be a colon straight after a guid */
2169 p = wcschr(str, L':');
2170 if (!p)
2171 return E_FAIL;
2172 len = p - str;
2173 if (len != 38)
2174 return E_FAIL;
2175
2176 /* get the guid, and check if it's validly formatted */
2177 memcpy(szGuid, str, sizeof(WCHAR)*len);
2178 szGuid[len] = 0;
2179
2181 if (hr != S_OK)
2182 return hr;
2183 str = p + 1;
2184
2185 /* match it up to a guid that we care about */
2186 if (IsEqualGUID(guid, SHELL32_AdvtShortcutComponent) && !szComponent)
2187 szComponent = str; /* Darwin */
2188 else if (IsEqualGUID(guid, SHELL32_AdvtShortcutProduct) && !szProduct)
2189 szProduct = str; /* Logo3 */
2190 else
2191 return E_FAIL;
2192
2193 /* skip to the next field */
2194 str = wcschr(str, L':');
2195 if (!str)
2196 return E_FAIL;
2197 }
2198
2199 /* we have to have a component for an advertised shortcut */
2200 if (!szComponent)
2201 return E_FAIL;
2202
2203 szComponent = GetAdvertisedArg(szComponent);
2204 szProduct = GetAdvertisedArg(szProduct);
2205
2206 hr = WriteAdvertiseInfo(szComponent, EXP_DARWIN_ID_SIG);
2207 // if (FAILED(hr))
2208 // return hr;
2209#if (NTDDI_VERSION < NTDDI_LONGHORN)
2210 hr = WriteAdvertiseInfo(szProduct, EXP_LOGO3_ID_SIG);
2211 // if (FAILED(hr))
2212 // return hr;
2213#endif
2214
2215 HeapFree(GetProcessHeap(), 0, (PVOID)szComponent);
2216 HeapFree(GetProcessHeap(), 0, (PVOID)szProduct);
2217
2218 if (TRACE_ON(shell))
2219 {
2221 TRACE("Component = %s\n", debugstr_w(sComponent));
2222#if (NTDDI_VERSION < NTDDI_LONGHORN)
2223 GetAdvertiseInfo(&sProduct, EXP_LOGO3_ID_SIG);
2224 TRACE("Product = %s\n", debugstr_w(sProduct));
2225#endif
2226 }
2227
2228 return S_OK;
2229}
2230
2232{
2233 HRESULT hr = S_OK;
2234 LPITEMIDLIST pidlNew = NULL;
2236
2237 /*
2238 * Not both 'pidl' and 'pszFile' should be set.
2239 * But either one or both can be NULL.
2240 */
2241 if (pidl && pszFile)
2242 return E_FAIL;
2243
2244 if (pidl)
2245 {
2246 /* Clone the PIDL */
2247 pidlNew = ILClone(pidl);
2248 if (!pidlNew)
2249 return E_FAIL;
2250 }
2251 else if (pszFile)
2252 {
2253 /* Build a PIDL for this path target */
2254 hr = SHILCreateFromPathW(pszFile, &pidlNew, NULL);
2255 if (FAILED(hr))
2256 {
2257 /* This failed, try to resolve the path, then create a simple PIDL */
2258
2261
2263 {
2264 hr = E_INVALIDARG;
2265 szPath[0] = 0;
2266 }
2267 else
2268 {
2269 hr = S_OK;
2271 // NOTE: Don't make it failed here even if pidlNew was NULL.
2272 // We don't fail on purpose even if SHSimpleIDListFromPathW returns NULL.
2273 // This behaviour has been verified with tests.
2274 }
2275 }
2276 }
2277 // else if (!pidl && !pszFile) { pidlNew = NULL; hr = S_OK; }
2278
2279 ILFree(m_pPidl);
2280 m_pPidl = pidlNew;
2281
2282 if (!pszFile)
2283 {
2284 if (SHGetPathFromIDListW(pidlNew, szPath))
2285 pszFile = szPath;
2286 }
2287
2288 // TODO: Fully update link info, tracker, file attribs...
2289
2290 // if (pszFile)
2291 if (!pszFile)
2292 {
2293 *szPath = L'\0';
2294 pszFile = szPath;
2295 }
2296
2297 /* Update the cached path (for link info) */
2299
2300 if (m_sPath)
2302
2303 m_sPath = strdupW(pszFile);
2304 if (!m_sPath)
2305 return E_OUTOFMEMORY;
2306
2307 m_bDirty = TRUE;
2308 return hr;
2309}
2310
2312{
2313 LPWSTR unquoted = NULL;
2314 HRESULT hr = S_OK;
2315
2316 TRACE("(%p)->(path=%s)\n", this, debugstr_w(pszFile));
2317
2318 if (!pszFile)
2319 return E_INVALIDARG;
2320
2321 /*
2322 * Allow upgrading Logo3 shortcuts (m_Header.dwFlags & SLDF_HAS_LOGO3ID),
2323 * but forbid upgrading Darwin ones.
2324 */
2326 return S_FALSE;
2327
2328 /* quotes at the ends of the string are stripped */
2329 SIZE_T len = wcslen(pszFile);
2330 if (pszFile[0] == L'"' && pszFile[len-1] == L'"')
2331 {
2332 unquoted = strdupW(pszFile);
2333 PathUnquoteSpacesW(unquoted);
2334 pszFile = unquoted;
2335 }
2336
2337 /* any other quote marks are invalid */
2338 if (wcschr(pszFile, L'"'))
2339 {
2340 hr = S_FALSE;
2341 goto end;
2342 }
2343
2344 /* Clear the cached path */
2346 m_sPath = NULL;
2347
2348 /* Check for an advertised target (Logo3 or Darwin) */
2349 if (SetAdvertiseInfo(pszFile) != S_OK)
2350 {
2351 /* This is not an advertised target, but a regular path */
2353
2354 /*
2355 * Check whether the user-given file path contains unexpanded
2356 * environment variables. If so, create a target environment block.
2357 * Note that in this block we will store the user-given path.
2358 * It will contain the unexpanded environment variables, but
2359 * it can also contain already expanded path that the user does
2360 * not want to see them unexpanded (e.g. so that they always
2361 * refer to the same place even if the would-be corresponding
2362 * environment variable could change).
2363 */
2364 if (*pszFile)
2366 else
2367 *szPath = L'\0';
2368
2369 if (*pszFile && (wcscmp(pszFile, szPath) != 0))
2370 {
2371 /*
2372 * The user-given file path contains unexpanded environment
2373 * variables, so we need a target environment block.
2374 */
2376 LPEXP_SZ_LINK pInfo;
2377
2379 if (pInfo)
2380 {
2381 /* Make sure that the size of the structure is valid */
2382 if (pInfo->cbSize != sizeof(*pInfo))
2383 {
2384 ERR("Ooops. This structure is not as expected...\n");
2385
2386 /* Invalid structure, remove it altogether */
2387 m_Header.dwFlags &= ~SLDF_HAS_EXP_SZ;
2389
2390 /* Reset the pointer and go use the static buffer */
2391 pInfo = NULL;
2392 }
2393 }
2394 if (!pInfo)
2395 {
2396 /* Use the static buffer */
2397 pInfo = &buffer;
2398 buffer.cbSize = sizeof(buffer);
2399 buffer.dwSignature = EXP_SZ_LINK_SIG;
2400 }
2401
2402 lstrcpynW(pInfo->szwTarget, pszFile, _countof(pInfo->szwTarget));
2403 WideCharToMultiByte(CP_ACP, 0, pszFile, -1,
2404 pInfo->szTarget, _countof(pInfo->szTarget), NULL, NULL);
2405
2406 hr = S_OK;
2407 if (pInfo == &buffer)
2408 hr = AddDataBlock(pInfo);
2409 if (hr == S_OK)
2411
2412 /* Now, make pszFile point to the expanded path */
2413 pszFile = szPath;
2414 }
2415 else
2416 {
2417 /*
2418 * The user-given file path does not contain unexpanded environment
2419 * variables, so we need to remove any target environment block.
2420 */
2421 m_Header.dwFlags &= ~SLDF_HAS_EXP_SZ;
2423
2424 /* pszFile points to the user path */
2425 }
2426
2427 /* Set the target */
2428 hr = SetTargetFromPIDLOrPath(NULL, pszFile);
2429 }
2430
2431 m_bDirty = TRUE;
2432
2433end:
2434 HeapFree(GetProcessHeap(), 0, unquoted);
2435 return hr;
2436}
2437
2439{
2440 if (SHAddDataBlock(&m_pDBList, (DATABLOCK_HEADER*)pDataBlock))
2441 {
2442 m_bDirty = TRUE;
2443 return S_OK;
2444 }
2445 return S_FALSE;
2446}
2447
2449{
2450 DATABLOCK_HEADER* pBlock;
2451 PVOID pDataBlock;
2452
2453 TRACE("%p %08x %p\n", this, dwSig, ppDataBlock);
2454
2455 *ppDataBlock = NULL;
2456
2457 pBlock = SHFindDataBlock(m_pDBList, dwSig);
2458 if (!pBlock)
2459 {
2460 ERR("unknown datablock %08x (not found)\n", dwSig);
2461 return E_FAIL;
2462 }
2463
2464 pDataBlock = LocalAlloc(LMEM_ZEROINIT, pBlock->cbSize);
2465 if (!pDataBlock)
2466 return E_OUTOFMEMORY;
2467
2468 CopyMemory(pDataBlock, pBlock, pBlock->cbSize);
2469
2470 *ppDataBlock = pDataBlock;
2471 return S_OK;
2472}
2473
2475{
2476 if (SHRemoveDataBlock(&m_pDBList, dwSig))
2477 {
2478 m_bDirty = TRUE;
2479 return S_OK;
2480 }
2481 return S_FALSE;
2482}
2483
2485{
2486 TRACE("%p %p\n", this, pdwFlags);
2487 *pdwFlags = m_Header.dwFlags;
2488 return S_OK;
2489}
2490
2492{
2493 if (m_Header.dwFlags == dwFlags)
2494 return S_FALSE;
2496 m_bDirty = TRUE;
2497 return S_OK;
2498}
2499
2500/**************************************************************************
2501 * CShellLink implementation of IShellExtInit::Initialize()
2502 *
2503 * Loads the shelllink from the dataobject the shell is pointing to.
2504 */
2506{
2507 TRACE("%p %p %p %p\n", this, pidlFolder, pdtobj, hkeyProgID);
2508
2509 if (!pdtobj)
2510 return E_FAIL;
2511
2512 FORMATETC format;
2513 format.cfFormat = CF_HDROP;
2514 format.ptd = NULL;
2515 format.dwAspect = DVASPECT_CONTENT;
2516 format.lindex = -1;
2517 format.tymed = TYMED_HGLOBAL;
2518
2519 STGMEDIUM stgm;
2520 HRESULT hr = pdtobj->GetData(&format, &stgm);
2521 if (FAILED(hr))
2522 return hr;
2523
2524 UINT count = DragQueryFileW((HDROP)stgm.hGlobal, -1, NULL, 0);
2525 if (count == 1)
2526 {
2527 count = DragQueryFileW((HDROP)stgm.hGlobal, 0, NULL, 0);
2528 count++;
2529 LPWSTR path = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
2530 if (path)
2531 {
2532 count = DragQueryFileW((HDROP)stgm.hGlobal, 0, path, count);
2533 hr = Load(path, 0);
2535 }
2536 }
2537 ReleaseStgMedium(&stgm);
2538
2539 return S_OK;
2540}
2541
2543{
2544 INT id = 0;
2545
2546 m_idCmdFirst = idCmdFirst;
2547
2548 TRACE("%p %p %u %u %u %u\n", this,
2549 hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
2550
2551 if (!hMenu)
2552 return E_INVALIDARG;
2553
2556
2557 MENUITEMINFOW mii;
2558 ZeroMemory(&mii, sizeof(mii));
2559 mii.cbSize = sizeof(mii);
2561 mii.dwTypeData = strOpen.GetBuffer();
2562 mii.cch = wcslen(mii.dwTypeData);
2563 mii.wID = idCmdFirst + id++;
2565 mii.fType = MFT_STRING;
2566 if (!InsertMenuItemW(hMenu, indexMenu++, TRUE, &mii))
2567 return E_FAIL;
2568
2570 mii.dwTypeData = strOpenFileLoc.GetBuffer();
2571 mii.cch = wcslen(mii.dwTypeData);
2572 mii.wID = idCmdFirst + id++;
2573 mii.fState = MFS_ENABLED;
2574 mii.fType = MFT_STRING;
2575 if (!InsertMenuItemW(hMenu, indexMenu++, TRUE, &mii))
2576 return E_FAIL;
2577
2578 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, id);
2579}
2580
2582{
2583 // TODO: SHOpenFolderAndSelectItems
2584 WCHAR szParams[MAX_PATH + 64];
2585 StringCbPrintfW(szParams, sizeof(szParams), L"/select,%s", m_sPath);
2586
2587 INT_PTR ret;
2588 ret = reinterpret_cast<INT_PTR>(ShellExecuteW(NULL, NULL, L"explorer.exe", szParams,
2590 if (ret <= 32)
2591 {
2592 ERR("ret: %08lX\n", ret);
2593 return E_FAIL;
2594 }
2595
2596 return S_OK;
2597}
2598
2600{
2601 TRACE("%p %p\n", this, lpici);
2602
2603 if (lpici->cbSize < sizeof(CMINVOKECOMMANDINFO))
2604 return E_INVALIDARG;
2605
2606 // NOTE: We could use lpici->hwnd (certainly in case lpici->fMask doesn't contain CMIC_MASK_FLAG_NO_UI)
2607 // as the parent window handle... ?
2608 /* FIXME: get using interface set from IObjectWithSite?? */
2609 // NOTE: We might need an extended version of Resolve that provides us with paths...
2610 HRESULT hr = Resolve(lpici->hwnd, (lpici->fMask & CMIC_MASK_FLAG_NO_UI) ? SLR_NO_UI : 0);
2611 if (FAILED(hr))
2612 {
2613 TRACE("failed to resolve component error 0x%08x\n", hr);
2614 return hr;
2615 }
2616
2617 UINT idCmd = LOWORD(lpici->lpVerb);
2618 TRACE("idCmd: %d\n", idCmd);
2619
2620 switch (idCmd)
2621 {
2622 case IDCMD_OPEN:
2623 return DoOpen(lpici);
2625 return DoOpenFileLocation();
2626 default:
2627 return E_NOTIMPL;
2628 }
2629}
2630
2632{
2634 const BOOL unicode = IsUnicode(*lpici);
2635
2636 CStringW args;
2637 if (m_sArgs)
2638 args = m_sArgs;
2639
2640 if (unicode)
2641 {
2642 if (!StrIsNullOrEmpty(iciex->lpParametersW))
2643 {
2644 args += L' ';
2645 args += iciex->lpParametersW;
2646 }
2647 }
2648 else
2649 {
2650 CComHeapPtr<WCHAR> pszParams;
2651 if (!StrIsNullOrEmpty(lpici->lpParameters) && __SHCloneStrAtoW(&pszParams, lpici->lpParameters))
2652 {
2653 args += L' ';
2654 args += pszParams;
2655 }
2656 }
2657
2659 SHELLEXECUTEINFOW sei = { sizeof(sei) };
2662 sei.lpDirectory = m_sWorkDir;
2663 if (m_pPidl)
2664 {
2665 sei.lpIDList = m_pPidl;
2667 }
2668 else
2669 {
2670 sei.lpFile = m_sPath;
2672 {
2673 sei.fMask &= ~SEE_MASK_DOENVSUBST; // The link does not want to expand lpFile
2675 sei.lpDirectory = dir;
2676 }
2677 }
2678 sei.lpParameters = args;
2679 sei.lpClass = m_sLinkPath;
2681 if (lpici->nShow != SW_SHOWNORMAL && lpici->nShow != SW_SHOW)
2682 sei.nShow = lpici->nShow; // Allow invoker to override .lnk show mode
2683
2684 // Use the invoker specified working directory if the link did not specify one
2685 if (StrIsNullOrEmpty(sei.lpDirectory) || !PathEnvSubstIsDirectory(sei.lpDirectory))
2686 {
2687 LPCSTR pszDirA = lpici->lpDirectory;
2688 if (unicode && !StrIsNullOrEmpty(iciex->lpDirectoryW))
2689 sei.lpDirectory = iciex->lpDirectoryW;
2690 else if (pszDirA && SHAnsiToUnicode(pszDirA, dir, _countof(dir)))
2691 sei.lpDirectory = dir;
2692 }
2693 return (ShellExecuteExW(&sei) ? S_OK : E_FAIL);
2694}
2695
2697{
2698 FIXME("%p %lu %u %p %p %u\n", this, idCmd, uType, pwReserved, pszName, cchMax);
2699 return E_NOTIMPL;
2700}
2701
2704{
2705 switch(uMsg)
2706 {
2707 case WM_INITDIALOG:
2708 if (lParam)
2709 {
2710 HWND hDlgCtrl = GetDlgItem(hwndDlg, IDC_SHORTEX_RUN_DIFFERENT);
2711 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0);
2712 }
2713 return TRUE;
2714 case WM_COMMAND:
2715 {
2716 HWND hDlgCtrl = GetDlgItem(hwndDlg, IDC_SHORTEX_RUN_DIFFERENT);
2717 if (LOWORD(wParam) == IDOK)
2718 {
2719 if (SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
2720 EndDialog(hwndDlg, 1);
2721 else
2722 EndDialog(hwndDlg, 0);
2723 }
2724 else if (LOWORD(wParam) == IDCANCEL)
2725 {
2726 EndDialog(hwndDlg, -1);
2727 }
2729 {
2730 if (SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED)
2731 SendMessage(hDlgCtrl, BM_SETCHECK, BST_UNCHECKED, 0);
2732 else
2733 SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0);
2734 }
2735 }
2736 }
2737 return FALSE;
2738}
2739
2740static void GetTypeDescriptionByPath(PCWSTR pszFullPath, DWORD fAttributes, PWSTR szBuf, UINT cchBuf)
2741{
2742 if (fAttributes == INVALID_FILE_ATTRIBUTES && !PathFileExistsAndAttributesW(pszFullPath, &fAttributes))
2743 fAttributes = 0;
2744
2745 SHFILEINFOW fi;
2746 if (!SHGetFileInfoW(pszFullPath, fAttributes, &fi, sizeof(fi), SHGFI_TYPENAME | SHGFI_USEFILEATTRIBUTES))
2747 {
2748 ERR("SHGetFileInfoW failed for %ls (%lu)\n", pszFullPath, GetLastError());
2749 fi.szTypeName[0] = UNICODE_NULL;
2750 }
2751
2752 BOOL fFolder = (fAttributes & FILE_ATTRIBUTE_DIRECTORY);
2753 LPCWSTR pwszExt = fFolder ? L"" : PathFindExtensionW(pszFullPath);
2754 if (pwszExt[0])
2755 {
2756 if (!fi.szTypeName[0])
2757 StringCchPrintfW(szBuf, cchBuf, L"%s", pwszExt + 1);
2758 else
2759 StringCchPrintfW(szBuf, cchBuf, L"%s (%s)", fi.szTypeName, pwszExt);
2760 }
2761 else
2762 {
2763 StringCchPrintfW(szBuf, cchBuf, L"%s", fi.szTypeName);
2764 }
2765}
2766
2768{
2769 TRACE("CShellLink::OnInitDialog(hwnd %p hwndFocus %p lParam %p)\n", hwndDlg, hwndFocus, lParam);
2770
2772
2773 TRACE("m_sArgs: %S sComponent: %S m_sDescription: %S m_sIcoPath: %S m_sPath: %S m_sPathRel: %S sProduct: %S m_sWorkDir: %S\n", m_sArgs, sComponent, m_sDescription,
2775
2776 m_bInInit = TRUE;
2778
2779 /* Get file information */
2780 // FIXME! FIXME! Shouldn't we use m_sIcoPath, m_Header.nIconIndex instead???
2781 SHFILEINFOW fi;
2782 if (!SHGetFileInfoW(m_sLinkPath, 0, &fi, sizeof(fi), SHGFI_TYPENAME | SHGFI_ICON))
2783 {
2784 ERR("SHGetFileInfoW failed for %ls (%lu)\n", m_sLinkPath, GetLastError());
2785 fi.szTypeName[0] = L'\0';
2786 fi.hIcon = NULL;
2787 }
2788
2789 if (fi.hIcon)
2790 {
2791 if (m_hIcon)
2793 m_hIcon = fi.hIcon;
2795 }
2796 else
2797 ERR("ExtractIconW failed %ls %u\n", m_sIcoPath, m_Header.nIconIndex);
2798
2799 if (!SHGetFileInfoW(m_sLinkPath, 0, &fi, sizeof(fi), SHGFI_DISPLAYNAME))
2802
2803 /* Target type */
2804 if (m_sPath)
2805 {
2809 }
2810
2811 /* Target location */
2812 if (m_sPath)
2813 {
2818 }
2819
2820 /* Target path */
2821 if (m_sPath)
2822 {
2823 WCHAR newpath[MAX_PATH * 2];
2824 newpath[0] = UNICODE_NULL;
2825 if (wcschr(m_sPath, ' '))
2826 StringCchPrintfExW(newpath, _countof(newpath), NULL, NULL, 0, L"\"%ls\"", m_sPath);
2827 else
2828 StringCchCopyExW(newpath, _countof(newpath), m_sPath, NULL, NULL, 0);
2829
2830 if (m_sArgs && m_sArgs[0])
2831 {
2832 StringCchCatW(newpath, _countof(newpath), L" ");
2833 StringCchCatW(newpath, _countof(newpath), m_sArgs);
2834 }
2835 SetDlgItemTextW(hwndDlg, IDC_SHORTCUT_TARGET_TEXT, newpath);
2836 }
2837
2838 /* Working dir */
2839 if (m_sWorkDir)
2841
2842 /* Description */
2843 if (m_sDescription)
2845
2846 /* Hot key */
2848
2849 /* Run */
2851 const DWORD runshowcmd[] = { SW_SHOWNORMAL, SW_SHOWMINNOACTIVE, SW_SHOWMAXIMIZED };
2852 HWND hRunCombo = GetDlgItem(hwndDlg, IDC_SHORTCUT_RUN_COMBO);
2853 for (UINT i = 0; i < _countof(runstrings); ++i)
2854 {
2856 if (!LoadStringW(shell32_hInstance, runstrings[i], buf, _countof(buf)))
2857 break;
2858
2859 int index = SendMessageW(hRunCombo, CB_ADDSTRING, 0, (LPARAM)buf);
2860 if (index < 0)
2861 continue;
2862 SendMessageW(hRunCombo, CB_SETITEMDATA, index, runshowcmd[i]);
2863 if (!i || m_Header.nShowCommand == runshowcmd[i])
2864 SendMessageW(hRunCombo, CB_SETCURSEL, index, 0);
2865 }
2866
2867 BOOL disablecontrols = FALSE;
2868 if (darwin)
2869 {
2870 disablecontrols = TRUE;
2873 }
2874 else
2875 {
2876 WCHAR path[MAX_PATH * 2];
2877 path[0] = UNICODE_NULL;
2879 if (FAILED(hr))
2880 hr = GetPath(path, _countof(path), NULL, 0);
2881#if DBG
2882 if (GetKeyState(VK_CONTROL) < 0) // Allow inspection of PIDL parsing path
2883 {
2884 hr = S_OK;
2885 path[0] = UNICODE_NULL;
2886 }
2887#endif
2888 if (hr != S_OK)
2889 {
2890 disablecontrols = TRUE;
2891 LPITEMIDLIST pidl;
2892 if (GetIDList(&pidl) == S_OK)
2893 {
2894 path[0] = UNICODE_NULL;
2895 SHGetNameAndFlagsW(pidl, SHGDN_FORADDRESSBAR | SHGDN_FORPARSING, path, _countof(path), NULL);
2898 ILRemoveLastID(pidl);
2899 path[0] = UNICODE_NULL;
2901 SHGetNameAndFlagsW(pidl, SHGDN_NORMAL, path, _countof(path), NULL);
2903 ILFree(pidl);
2904 }
2907 }
2908 else
2909 {
2910 ASSERT(FAILED(hr) || !(path[0] == ':' && path[1] == ':' && path[2] == '{'));
2911 }
2912 }
2913
2914 HWND hWndTarget = GetDlgItem(hwndDlg, IDC_SHORTCUT_TARGET_TEXT);
2915 EnableWindow(hWndTarget, !disablecontrols);
2916 PostMessage(hWndTarget, EM_SETSEL, 0, -1); // Fix caret bug when first opening the tab [CORE-20016]
2917
2918 /* auto-completion */
2919 SHAutoComplete(hWndTarget, SHACF_DEFAULT);
2921
2922 m_bInInit = FALSE;
2923
2924 return TRUE;
2925}
2926
2927void CShellLink::OnCommand(HWND hwndDlg, int id, HWND hwndCtl, UINT codeNotify)
2928{
2929 switch (id)
2930 {
2931 case IDC_SHORTCUT_FIND:
2933 return;
2934
2936 {
2937 WCHAR wszPath[MAX_PATH] = L"";
2938
2939 if (m_sIcoPath)
2940 wcscpy(wszPath, m_sIcoPath);
2941 else
2942 FindExecutableW(m_sPath, NULL, wszPath);
2943
2945 if (PickIconDlg(hwndDlg, wszPath, _countof(wszPath), &IconIndex))
2946 {
2947 SetIconLocation(wszPath, IconIndex);
2948 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2949
2950 HICON hIconLarge = CreateShortcutIcon(wszPath, IconIndex);
2951 if (hIconLarge)
2952 {
2953 if (m_hIcon)
2955 m_hIcon = hIconLarge;
2957 }
2958 }
2959 return;
2960 }
2961
2963 {
2965 if (result == 1 || result == 0)
2966 {
2967 if (m_bRunAs != result)
2968 {
2969 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2970 }
2971
2972 m_bRunAs = result;
2973 }
2974 return;
2975 }
2976 }
2977 if (codeNotify == EN_CHANGE || codeNotify == CBN_SELCHANGE)
2978 {
2979 if (!m_bInInit)
2980 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
2981 }
2982}
2983
2984LRESULT CShellLink::OnNotify(HWND hwndDlg, int idFrom, LPNMHDR pnmhdr)
2985{
2986 WCHAR wszBuf[MAX_PATH];
2987 LPPSHNOTIFY lppsn = (LPPSHNOTIFY)pnmhdr;
2988
2989 if (lppsn->hdr.code == PSN_APPLY)
2990 {
2991 /* set working directory */
2992 GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_START_IN_EDIT, wszBuf, _countof(wszBuf));
2993 SetWorkingDirectory(wszBuf);
2994
2995 /* set link destination */
2996 GetDlgItemTextW(hwndDlg, IDC_SHORTCUT_TARGET_TEXT, wszBuf, _countof(wszBuf));
2997 LPWSTR lpszArgs = NULL;
2998 LPWSTR unquoted = strdupW(wszBuf);
2999 StrTrimW(unquoted, L" ");
3000
3001 if (!PathFileExistsW(unquoted))
3002 {
3003 lpszArgs = PathGetArgsW(unquoted);
3004 PathRemoveArgsW(unquoted);
3005 StrTrimW(lpszArgs, L" ");
3006 }
3007 if (unquoted[0] == '"' && unquoted[wcslen(unquoted) - 1] == '"')
3008 PathUnquoteSpacesW(unquoted);
3009
3010 WCHAR *pwszExt = PathFindExtensionW(unquoted);
3011 if (!_wcsicmp(pwszExt, L".lnk"))
3012 {
3013 // FIXME load localized error msg
3014 MessageBoxW(hwndDlg, L"You cannot create a link to a shortcut", L"Error", MB_ICONERROR);
3016 return TRUE;
3017 }
3018
3019 if (!PathFileExistsW(unquoted))
3020 {
3021 // FIXME load localized error msg
3022 MessageBoxW(hwndDlg, L"The specified file name in the target box is invalid", L"Error", MB_ICONERROR);
3024 return TRUE;
3025 }
3026
3027 SetPath(unquoted);
3028 if (lpszArgs)
3029 SetArguments(lpszArgs);
3030 else
3031 SetArguments(L"\0");
3032
3033 HeapFree(GetProcessHeap(), 0, unquoted);
3034
3036
3038 if (index != CB_ERR)
3039 {
3041 }
3042
3043 TRACE("This %p m_sLinkPath %S\n", this, m_sLinkPath);
3047 return TRUE;
3048 }
3049 return FALSE;
3050}
3051
3053{
3054 if (m_hIcon)
3055 {
3057 m_hIcon = NULL;
3058 }
3059}
3060
3061/**************************************************************************
3062 * SH_ShellLinkDlgProc
3063 *
3064 * dialog proc of the shortcut property dialog
3065 */
3066
3069{
3070 LPPROPSHEETPAGEW ppsp;
3071 CShellLink *pThis = reinterpret_cast<CShellLink *>(GetWindowLongPtr(hwndDlg, DWLP_USER));
3072
3073 switch (uMsg)
3074 {
3075 case WM_INITDIALOG:
3076 ppsp = (LPPROPSHEETPAGEW)lParam;
3077 if (ppsp == NULL)
3078 break;
3079
3080 pThis = reinterpret_cast<CShellLink *>(ppsp->lParam);
3081 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pThis);
3082 return pThis->OnInitDialog(hwndDlg, (HWND)(wParam), lParam);
3083
3084 case WM_NOTIFY:
3085 return pThis->OnNotify(hwndDlg, (int)wParam, (NMHDR *)lParam);
3086
3087 case WM_COMMAND:
3088 pThis->OnCommand(hwndDlg, LOWORD(wParam), (HWND)lParam, HIWORD(wParam));
3089 break;
3090
3091 case WM_DESTROY:
3092 pThis->OnDestroy(hwndDlg);
3093 break;
3094
3095 default:
3096 break;
3097 }
3098
3099 return FALSE;
3100}
3101
3102/**************************************************************************
3103 * ShellLink_IShellPropSheetExt interface
3104 */
3105
3107{
3109 (LPARAM)this, NULL, &PropSheetPageLifetimeCallback<CShellLink>);
3110 HRESULT hr = AddPropSheetPage(hPage, pfnAddPage, lParam);
3112 return hr;
3113 else
3114 AddRef(); // For PropSheetPageLifetimeCallback
3115 enum { CShellLink_PageIndex_Shortcut = 0 };
3116 return 1 + CShellLink_PageIndex_Shortcut; // Make this page the default (one-based)
3117}
3118
3120{
3121 TRACE("(%p) (uPageID %u, pfnReplacePage %p lParam %p\n", this, uPageID, pfnReplacePage, lParam);
3122 return E_NOTIMPL;
3123}
3124
3126{
3127 TRACE("%p %p\n", this, punk);
3128
3129 m_site = punk;
3130
3131 return S_OK;
3132}
3133
3135{
3136 TRACE("%p %s %p\n", this, debugstr_guid(&iid), ppvSite);
3137
3138 if (m_site == NULL)
3139 return E_FAIL;
3140
3141 return m_site->QueryInterface(iid, ppvSite);
3142}
3143
3145 DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
3146{
3147 TRACE("(%p)->(DataObject=%p)\n", this, pDataObject);
3148
3149 if (*pdwEffect == DROPEFFECT_NONE)
3150 return S_OK;
3151
3153 if (SUCCEEDED(hr))
3154 hr = m_DropTarget->DragEnter(pDataObject, dwKeyState, pt, pdwEffect);
3155 else
3156 *pdwEffect = DROPEFFECT_NONE;
3157
3158 return S_OK;
3159}
3160
3162 DWORD *pdwEffect)
3163{
3164 TRACE("(%p)\n", this);
3165 HRESULT hr = S_OK;
3166 if (m_DropTarget)
3167 hr = m_DropTarget->DragOver(dwKeyState, pt, pdwEffect);
3168 return hr;
3169}
3170
3172{
3173 TRACE("(%p)\n", this);
3174 HRESULT hr = S_OK;
3175 if (m_DropTarget)
3176 {
3177 hr = m_DropTarget->DragLeave();
3179 }
3180
3181 return hr;
3182}
3183
3185 DWORD dwKeyState, POINTL pt, DWORD *pdwEffect)
3186{
3187 TRACE("(%p)\n", this);
3188 HRESULT hr = S_OK;
3189 if (m_DropTarget)
3190 hr = m_DropTarget->Drop(pDataObject, dwKeyState, pt, pdwEffect);
3191
3192 return hr;
3193}
3194
3195/**************************************************************************
3196 * IShellLink_ConstructFromFile
3197 */
3199{
3201 HRESULT hr = CShellLink::_CreatorClass::CreateInstance(NULL, IID_PPV_ARG(IPersistFile, &ppf));
3202 if (FAILED(hr))
3203 return hr;
3204
3205 hr = ppf->Load(path, 0);
3206 if (FAILED(hr))
3207 return hr;
3208
3209 return ppf->QueryInterface(riid, ppv);
3210}
3211
3213{
3215 if (!ILGetDisplayNameExW(psf, pidl, path, 0))
3216 return E_FAIL;
3217
3219}
3220
3222{
3224 const COLORREF crMask = GetSysColor(COLOR_3DFACE);
3225 WCHAR wszLnkIcon[MAX_PATH];
3226 int lnk_idx;
3227 HDC hDC;
3229 HICON hIcon = NULL, hNewIcon = NULL, hShortcut;
3230
3231 if (HLM_GetIconW(IDI_SHELL_SHORTCUT - 1, wszLnkIcon, _countof(wszLnkIcon), &lnk_idx))
3232 {
3233 ::ExtractIconExW(wszLnkIcon, lnk_idx, &hShortcut, NULL, 1);
3234 }
3235 else
3236 {
3238 IMAGE_ICON, cx, cy, 0);
3239 }
3240
3241 ::ExtractIconExW(wszIconPath, IconIndex, &hIcon, NULL, 1);
3242 if (!hIcon || !hShortcut || !himl)
3243 goto cleanup;
3244
3246 if (hDC)
3247 {
3248 // create 32bpp bitmap
3249 BITMAPINFO bi;
3250 ZeroMemory(&bi, sizeof(bi));
3251 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
3252 bi.bmiHeader.biWidth = cx;
3253 bi.bmiHeader.biHeight = cy;
3254 bi.bmiHeader.biPlanes = 1;
3255 bi.bmiHeader.biBitCount = 32;
3256 LPVOID pvBits;
3257 HBITMAP hbm = CreateDIBSection(hDC, &bi, DIB_RGB_COLORS, &pvBits, NULL, 0);
3258 if (hbm)
3259 {
3260 // draw the icon image
3261 HGDIOBJ hbmOld = SelectObject(hDC, hbm);
3262 {
3263 HBRUSH hbr = CreateSolidBrush(crMask);
3264 RECT rc = { 0, 0, cx, cy };
3265 FillRect(hDC, &rc, hbr);
3266 DeleteObject(hbr);
3267
3268 DrawIconEx(hDC, 0, 0, hIcon, cx, cy, 0, NULL, DI_NORMAL);
3269 DrawIconEx(hDC, 0, 0, hShortcut, cx, cy, 0, NULL, DI_NORMAL);
3270 }
3271 SelectObject(hDC, hbmOld);
3272
3273 INT iAdded = ImageList_AddMasked(himl, hbm, crMask);
3274 hNewIcon = ImageList_GetIcon(himl, iAdded, ILD_NORMAL | ILD_TRANSPARENT);
3275
3277 }
3278 DeleteDC(hDC);
3279 }
3280
3281cleanup:
3282 if (hIcon)
3284 if (hShortcut)
3285 DestroyIcon(hShortcut);
3286 if (himl)
3288
3289 return hNewIcon;
3290}
static HDC hDC
Definition: 3dtext.c:33
#define PRF_TRYPROGRAMEXTENSIONS
Definition: PathResolve.cpp:40
#define shell32_hInstance
UINT cchMax
#define __inline
Definition: _wctype.cpp:15
unsigned int dir
Definition: maze.c:112
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static WCHAR * strdupW(const WCHAR *src)
Definition: main.c:92
#define CF_HDROP
Definition: constants.h:410
void shell(int argc, const char *argv[])
Definition: cmds.c:1231
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
#define STDMETHODCALLTYPE
Definition: bdasup.h:9
HIMAGELIST himl
EXTERN_C void WINAPI SHChangeNotify(LONG wEventId, UINT uFlags, LPCVOID dwItem1, LPCVOID dwItem2)
void Release()
Definition: atlcomcli.h:170
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
wcsncpy
wcscpy
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
void pdump(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:322
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
DWORD WINAPI CommandLineFromMsiDescriptor(WCHAR *szDescriptor, WCHAR *szCommandLine, DWORD *pcchCommandLine)
Definition: msi.c:22
UINT uFlags
Definition: api.c:59
BOOL WINAPI ImageList_Destroy(HIMAGELIST himl)
Definition: imagelist.c:941
HICON WINAPI ImageList_GetIcon(HIMAGELIST himl, INT i, UINT fStyle)
Definition: imagelist.c:1981
INT WINAPI ImageList_AddMasked(HIMAGELIST himl, HBITMAP hBitmap, COLORREF clrMask)
Definition: imagelist.c:573
HIMAGELIST WINAPI ImageList_Create(INT cx, INT cy, UINT flags, INT cInitial, INT cGrow)
Definition: imagelist.c:814
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define CP_ACP
Definition: compat.h:109
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define TRACE_ON(x)
Definition: compat.h:75
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define WideCharToMultiByte
Definition: compat.h:111
#define MultiByteToWideChar
Definition: compat.h:110
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
#define FAILED_UNEXPECTEDLY(hr)
Definition: debug.h:83
static void cleanup(void)
Definition: main.c:1335
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
UINT WINAPI GetDriveTypeW(IN LPCWSTR lpRootPathName)
Definition: disk.c:497
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
DWORD WINAPI GetShortPathNameW(IN LPCWSTR lpszLongPath, OUT LPWSTR lpszShortPath, IN DWORD cchBuffer)
Definition: path.c:1833
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
HRESULT WINAPI CLSIDFromString(LPCOLESTR idstr, LPCLSID id)
Definition: compobj.c:2338
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
static const WCHAR IconIndex[]
Definition: install.c:52
BOOL WINAPI PickIconDlg(HWND hWndOwner, LPWSTR lpstrFile, UINT nMaxFile, INT *lpdwIconIndex)
Definition: dialogs.cpp:351
HRESULT SHGetNameAndFlagsW(_In_ LPCITEMIDLIST pidl, _In_ DWORD dwFlags, _Out_opt_ LPWSTR pszText, _In_ UINT cchBuf, _Inout_opt_ DWORD *pdwAttributes)
Definition: utils.cpp:480
const GUID SHELL32_AdvtShortcutProduct
static HRESULT AddPropSheetPage(HPROPSHEETPAGE hPage, LPFNSVADDPROPSHEETPAGE pfnAddPage, LPARAM lParam)
Definition: precomp.h:151
EXTERN_C HRESULT SHELL_GetUIObjectOfAbsoluteItem(_In_opt_ HWND hWnd, _In_ PCIDLIST_ABSOLUTE pidl, _In_ REFIID riid, _Out_ void **ppvObj)
Definition: utils.cpp:380
const GUID SHELL32_AdvtShortcutComponent
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:326
UINT WINAPI DragQueryFileW(HDROP hDrop, UINT lFile, LPWSTR lpszwFile, UINT lLength)
Definition: shellole.c:622
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:304
BOOL WINAPI PathResolveW(_Inout_ LPWSTR path, _Inout_opt_ LPCWSTR *dirs, _In_ DWORD flags)
Definition: shellpath.c:1032
DATABLOCK_HEADER *WINAPI SHFindDataBlock(LPDBLIST lpList, DWORD dwSignature)
Definition: clist.c:424
HRESULT WINAPI SHReadDataBlockList(IStream *lpStream, LPDBLIST *lppList)
Definition: clist.c:235
VOID WINAPI SHFreeDataBlockList(LPDBLIST lpList)
Definition: clist.c:331
BOOL WINAPI SHAddDataBlock(LPDBLIST *lppList, const DATABLOCK_HEADER *lpNewItem)
Definition: clist.c:68
HRESULT WINAPI SHWriteDataBlockList(IStream *lpStream, LPDBLIST lpList)
Definition: clist.c:179
BOOL WINAPI SHRemoveDataBlock(LPDBLIST *lppList, DWORD dwSignature)
Definition: clist.c:355
HRESULT WINAPI SHCreateStreamOnFileW(LPCWSTR lpszPath, DWORD dwMode, IStream **lppStream)
Definition: istream.c:484
void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
Definition: path.c:779
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:629
LPWSTR WINAPI PathFindFileNameW(LPCWSTR lpszPath)
Definition: path.c:394
BOOL WINAPI PathUnExpandEnvStringsW(LPCWSTR path, LPWSTR buffer, UINT buf_len)
Definition: path.c:4181
LPWSTR WINAPI PathFindExtensionW(LPCWSTR lpszPath)
Definition: path.c:447
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1783
VOID WINAPI PathUnquoteSpacesW(LPWSTR lpszPath)
Definition: path.c:1040
BOOL WINAPI PathIsFileSpecW(LPCWSTR lpszPath)
Definition: path.c:2139
BOOL WINAPI PathFileExistsAndAttributesW(LPCWSTR lpszPath, DWORD *dwAttr)
Definition: path.c:1838
LPWSTR WINAPI PathGetArgsW(LPCWSTR lpszPath)
Definition: path.c:506
DWORD WINAPI SHAnsiToUnicode(LPCSTR lpSrcStr, LPWSTR lpDstStr, int iLen)
Definition: string.c:2673
BOOL WINAPI StrTrimW(LPWSTR lpszStr, LPCWSTR lpszTrim)
Definition: string.c:1883
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define assert(x)
Definition: debug.h:53
#define MAKE_HRESULT(sev, fac, code)
Definition: dmerror.h:30
#define pt(x, y)
Definition: drawing.c:79
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
pKey DeleteObject()
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint end
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLdouble n
Definition: glext.h:7729
GLuint res
Definition: glext.h:9613
GLenum src
Definition: glext.h:6340
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLuint index
Definition: glext.h:6031
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint64EXT * result
Definition: glext.h:11304
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLenum target
Definition: glext.h:7315
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
UINT WINAPI ExtractIconExW(LPCWSTR lpszFile, INT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIcons)
Definition: iconcache.cpp:855
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
struct IContextMenu::tagCMInvokeCommandInfoEx * LPCMINVOKECOMMANDINFOEX
HRESULT GetData([in, unique] FORMATETC *pformatetcIn, [out] STGMEDIUM *pmedium)
const DWORD DROPEFFECT_NONE
Definition: oleidl.idl:929
HRESULT Write([in, size_is(cb)] const void *pv, [in] ULONG cb, [out] ULONG *pcbWritten)
HRESULT Read([out, size_is(cb), length_is(*pcbRead)] void *pv, [in] ULONG cb, [out] ULONG *pcbRead)
ULONG AddRef()
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define LOBYTE(W)
Definition: jmemdos.c:487
#define NTDDI_VERSION
Definition: k32.h:33
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
INT WINAPI GetDateFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpDateStr, INT cchOut)
Definition: lcformat.c:989
if(dx< 0)
Definition: linetemp.h:194
const GUID * guid
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ASSERT(a)
Definition: mode.c:44
int DoOpen(void)
Definition: cmds.c:2168
LPCWSTR szPath
Definition: env.c:37
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
static HICON
Definition: imagelist.c:80
static const WCHAR label[]
Definition: itemdlg.c:1546
static DWORD DWORD void LPSTR DWORD cch
Definition: str.c:202
static char * dest
Definition: rtl.c:135
static const WCHAR szGuid[]
Definition: rtlstr.c:1892
static LPOLESTR
Definition: stg_prop.c:27
static const CLSID *static CLSID *static const GUID VARIANT VARIANT *static IServiceProvider DWORD *static HMENU
Definition: ordinal.c:63
HICON hIcon
Definition: msconfig.c:44
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED _In_opt_ LPTRANSMIT_FILE_BUFFERS _In_ DWORD dwReserved
Definition: mswsock.h:95
unsigned int UINT
Definition: ndis.h:50
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define LOCALE_USER_DEFAULT
#define UNICODE_NULL
_In_ HBITMAP hbm
Definition: ntgdi.h:2776
#define L(x)
Definition: ntvdm.h:50
#define MAKEINTRESOURCE(i)
Definition: ntverrsrc.c:25
#define STGM_CREATE
Definition: objbase.h:926
#define STGM_READWRITE
Definition: objbase.h:919
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:923
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:922
#define STGM_READ
Definition: objbase.h:917
#define PathAddBackslashW
Definition: pathcch.h:301
#define LOWORD(l)
Definition: pedump.c:82
unsigned short USHORT
Definition: pedump.c:61
LPITEMIDLIST WINAPI SHCloneSpecialIDList(HWND hwndOwner, int nFolder, BOOL fCreate)
Definition: pidl.c:445
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:237
void WINAPI ILFree(LPITEMIDLIST pidl)
Definition: pidl.c:1044
HRESULT WINAPI SHILCreateFromPathW(LPCWSTR path, LPITEMIDLIST *ppidl, DWORD *attributes)
Definition: pidl.c:403
LPITEMIDLIST WINAPI ILCombine(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
Definition: pidl.c:816
BOOL WINAPI ILRemoveLastID(LPITEMIDLIST pidl)
Definition: pidl.c:221
HRESULT WINAPI ILSaveToStream(IStream *pStream, LPCITEMIDLIST pPidl)
Definition: pidl.c:353
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1454
HRESULT WINAPI ILLoadFromStream(IStream *pStream, LPITEMIDLIST *ppPidl)
Definition: pidl.c:293
LPITEMIDLIST WINAPI SHSimpleIDListFromPathW(LPCWSTR lpszPath)
Definition: pidl.c:1238
BOOL ILGetDisplayNameExW(LPSHELLFOLDER psf, LPCITEMIDLIST pidl, LPWSTR path, DWORD type)
Definition: pidl.c:100
#define PSNRET_INVALID_NOCHANGEPAGE
Definition: prsht.h:131
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
#define PSN_APPLY
Definition: prsht.h:117
#define PSNRET_NOERROR
Definition: prsht.h:129
struct _PROPSHEETPAGEW * LPPROPSHEETPAGEW
BOOL(CALLBACK * LPFNADDPROPSHEETPAGE)(HPROPSHEETPAGE, LPARAM)
Definition: prsht.h:327
struct _PSHNOTIFY * LPPSHNOTIFY
_Out_opt_ int _Out_opt_ int * cy
Definition: commctrl.h:586
#define ILD_NORMAL
Definition: commctrl.h:417
_Out_opt_ int * cx
Definition: commctrl.h:585
#define ILC_COLOR32
Definition: commctrl.h:358
#define HKM_SETHOTKEY
Definition: commctrl.h:2236
#define ILD_TRANSPARENT
Definition: commctrl.h:418
#define ILC_MASK
Definition: commctrl.h:351
#define HKM_GETHOTKEY
Definition: commctrl.h:2237
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define REFIID
Definition: guiddef.h:118
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
#define WM_NOTIFY
Definition: richedit.h:61
const WCHAR * str
static calc_node_t temp
Definition: rpn_ieee.c:38
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcspbrk(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static HANDLE heap
Definition: heap.c:65
#define NTDDI_LONGHORN
Definition: sdkddkver.h:102
DWORD_PTR WINAPI SHGetFileInfoW(LPCWSTR path, DWORD dwFileAttributes, SHFILEINFOW *psfi, UINT sizeofpsfi, UINT flags)
Definition: shell32_main.c:430
static __inline LPWSTR __SHCloneStrAtoW(WCHAR **target, const char *source)
Definition: shell32_main.h:184
#define SEE_MASK_DOENVSUBST
Definition: shellapi.h:35
#define SHGFI_DISPLAYNAME
Definition: shellapi.h:167
#define SEE_MASK_UNICODE
Definition: shellapi.h:37
#define SHGFI_ICON
Definition: shellapi.h:165
#define SHGFI_TYPENAME
Definition: shellapi.h:168
#define SHGFI_USEFILEATTRIBUTES
Definition: shellapi.h:182
#define SEE_MASK_ASYNCOK
Definition: shellapi.h:54
#define SEE_MASK_NOASYNC
Definition: shellapi.h:33
_In_ LPCSTR pszDir
Definition: shellapi.h:585
#define SEE_MASK_INVOKEIDLIST
Definition: shellapi.h:28
#define SEE_MASK_FLAG_NO_UI
Definition: shellapi.h:36
#define SEE_MASK_HASLINKNAME
Definition: shellapi.h:49
#define ILGetSize
Definition: shellclasses.h:638
HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory, LPWSTR lpResult)
Definition: shlexec.cpp:1288
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2507
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2452
HRESULT hr
Definition: shlfolder.c:183
EXTERN_C HRESULT WINAPI SHOpenFolderAndSelectItems(PCIDLIST_ABSOLUTE pidlFolder, UINT cidl, PCUITEMID_CHILD_ARRAY apidl, DWORD dwFlags)
Definition: shlfolder.cpp:455
#define EXP_DARWIN_ID_SIG
Definition: shlobj.h:2063
#define SHCNE_UPDATEITEM
Definition: shlobj.h:1911
struct EXP_DARWIN_LINK * LPEXP_DARWIN_LINK
#define SHCNE_CREATE
Definition: shlobj.h:1899
#define EXP_SZ_LINK_SIG
Definition: shlobj.h:2059
@ SLDF_HAS_RELPATH
Definition: shlobj.h:1955
@ SLDF_HAS_EXP_SZ
Definition: shlobj.h:1961
@ SLDF_HAS_ID_LIST
Definition: shlobj.h:1952
@ SLDF_HAS_DARWINID
Definition: shlobj.h:1966
@ SLDF_RUN_IN_SEPARATE
Definition: shlobj.h:1962
@ SLDF_HAS_LINK_INFO
Definition: shlobj.h:1953
@ SLDF_HAS_WORKINGDIR
Definition: shlobj.h:1956
@ SLDF_HAS_ARGS
Definition: shlobj.h:1957
@ SLDF_FORCE_NO_LINKINFO
Definition: shlobj.h:1960
@ SLDF_HAS_EXP_ICON_SZ
Definition: shlobj.h:1968
@ SLDF_RUNAS_USER
Definition: shlobj.h:1967
@ SLDF_UNICODE
Definition: shlobj.h:1959
@ SLDF_RUN_WITH_SHIMLAYER
Definition: shlobj.h:1971
@ SLDF_HAS_ICONLOCATION
Definition: shlobj.h:1958
@ SLDF_HAS_NAME
Definition: shlobj.h:1954
#define EXP_SZ_ICON_SIG
Definition: shlobj.h:2067
#define EXP_SPECIAL_FOLDER_SIG
Definition: shlobj.h:2062
#define SHCNF_PATHW
Definition: shlobj.h:1933
struct EXP_SPECIAL_FOLDER * LPEXP_SPECIAL_FOLDER
struct EXP_SZ_LINK * LPEXP_SZ_LINK
HRESULT WINAPI SHAutoComplete(HWND hwndEdit, DWORD dwFlags)
Definition: autocomp.cpp:191
#define PathRemoveBackslash
Definition: shlwapi.h:1058
#define SHACF_DEFAULT
Definition: shlwapi.h:1956
#define PathIsDirectory
Definition: shlwapi.h:970
DWORD WINAPI SHExpandEnvironmentStringsW(LPCWSTR, LPWSTR, DWORD)
#define IDC_SHORTCUT_FIND
Definition: shresdef.h:502
#define IDS_SHORTCUT_RUN_MAX
Definition: shresdef.h:263
#define IDC_SHORTCUT_ADVANCED
Definition: shresdef.h:504
#define IDS_OPEN_VERB
Definition: shresdef.h:212
#define IDC_SHORTCUT_RUN_COMBO
Definition: shresdef.h:499
#define IDS_OPENFILELOCATION
Definition: shresdef.h:246
#define IDS_SHORTCUT_RUN_MIN
Definition: shresdef.h:262
#define IDC_SHORTCUT_LOCATION_EDIT
Definition: shresdef.h:491
#define IDC_SHORTCUT_TEXT
Definition: shresdef.h:487
#define IDC_SHORTCUT_TARGET_TEXT
Definition: shresdef.h:493
#define IDC_SHORTCUT_ICON
Definition: shresdef.h:486
#define IDC_SHORTCUT_KEY_HOTKEY
Definition: shresdef.h:497
#define IDC_SHORTEX_RUN_DIFFERENT
Definition: shresdef.h:507
#define IDI_SHELL_SHORTCUT
Definition: shresdef.h:608
#define IDS_SHORTCUT_RUN_NORMAL
Definition: shresdef.h:261
#define IDD_SHORTCUT_PROPERTIES
Definition: shresdef.h:427
#define IDC_SHORTCUT_CHANGE_ICON
Definition: shresdef.h:503
#define IDD_SHORTCUT_EXTENDED_PROPERTIES
Definition: shresdef.h:433
#define IDC_SHORTCUT_TYPE_EDIT
Definition: shresdef.h:489
#define IDC_SHORTCUT_COMMENT_EDIT
Definition: shresdef.h:501
#define IDC_SHORTCUT_START_IN_EDIT
Definition: shresdef.h:495
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
#define _countof(array)
Definition: sndvol32.h:70
#define TRACE(s)
Definition: solgame.cpp:4
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
STRSAFEAPI StringCchCopyExW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags)
Definition: strsafe.h:184
STRSAFEAPI StringCchCatW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:325
STRSAFEAPI StringCchPrintfExW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:585
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
STRSAFEAPI StringCbPrintfW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:557
DWORD idSpecialFolder
Definition: shlobj.h:2049
DWORD dwLocalPathOfs
Definition: CShellLink.cpp:167
DWORD dwHeaderSize
Definition: CShellLink.cpp:164
DWORD dwVolTableOfs
Definition: CShellLink.cpp:166
DWORD dwFinalPathOfs
Definition: CShellLink.cpp:169
DWORD dwNetworkVolTableOfs
Definition: CShellLink.cpp:168
LPARAM lParam
Definition: prsht.h:227
NMHDR hdr
Definition: prsht.h:330
LPCWSTR lpDirectory
Definition: shellapi.h:335
LPCWSTR lpParameters
Definition: shellapi.h:334
WCHAR szTypeName[80]
Definition: shellapi.h:377
WCHAR szDisplayName[MAX_PATH]
Definition: shellapi.h:376
HICON hIcon
Definition: shellapi.h:373
Definition: match.c:390
uint16_t size
Definition: btrfs_drv.h:563
Definition: fci.c:116
Definition: format.c:58
USHORT biBitCount
Definition: precomp.h:46
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
LPWSTR dwTypeData
Definition: winuser.h:3280
UINT code
Definition: winuser.h:3170
WCHAR label[12]
Definition: CShellLink.cpp:184
#define max(a, b)
Definition: svc.c:63
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT_PTR
Definition: typedefs.h:64
char * PSTR
Definition: typedefs.h:51
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
const char * PCSTR
Definition: typedefs.h:52
#define MAXUSHORT
Definition: typedefs.h:83
uint32_t ULONG
Definition: typedefs.h:59
#define HIWORD(l)
Definition: typedefs.h:247
WORD WORD PSZ PSZ pszFileName
Definition: vdmdbg.h:44
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
int ret
HPROPSHEETPAGE SH_CreatePropertySheetPageEx(WORD wDialogId, DLGPROC pfnDlgProc, LPARAM lParam, LPCWSTR pwszTitle, LPFNPSPCALLBACK Callback)
Definition: propsheet.cpp:223
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:245
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263
#define ZeroMemory
Definition: winbase.h:1743
#define LMEM_ZEROINIT
Definition: winbase.h:401
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define CopyMemory
Definition: winbase.h:1741
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
DWORD COLORREF
Definition: windef.h:300
#define WINAPI
Definition: msvc.h:6
#define STG_E_INVALIDPOINTER
Definition: winerror.h:2571
#define S_FALSE
Definition: winerror.h:2357
#define SEVERITY_SUCCESS
Definition: winerror.h:64
#define NOERROR
Definition: winerror.h:2354
#define E_POINTER
Definition: winerror.h:2365
#define DIB_RGB_COLORS
Definition: wingdi.h:367
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
#define DI_NORMAL
Definition: wingdi.h:72
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
BOOL WINAPI DeleteDC(_In_ HDC)
#define DATE_SHORTDATE
Definition: winnls.h:198
#define SW_SHOWNORMAL
Definition: winuser.h:781
#define SW_SHOWMAXIMIZED
Definition: winuser.h:784
DWORD WINAPI GetSysColor(_In_ int)
#define CB_SETITEMDATA
Definition: winuser.h:1977
#define DWLP_USER
Definition: winuser.h:883
#define MIIM_ID
Definition: winuser.h:733
#define STM_SETICON
Definition: winuser.h:2103
#define IDCANCEL
Definition: winuser.h:842
#define BST_UNCHECKED
Definition: winuser.h:199
#define IMAGE_ICON
Definition: winuser.h:212
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
UINT WINAPI PrivateExtractIconsW(_In_reads_(MAX_PATH) LPCWSTR szFileName, _In_ int nIconIndex, _In_ int cxIcon, _In_ int cyIcon, _Out_writes_opt_(nIcons) HICON *phicon, _Out_writes_opt_(nIcons) UINT *piconid, _In_ UINT nIcons, _In_ UINT flags)
#define WM_COMMAND
Definition: winuser.h:1751
#define CB_ERR
Definition: winuser.h:2446
HANDLE WINAPI LoadImageW(_In_opt_ HINSTANCE hInst, _In_ LPCWSTR name, _In_ UINT type, _In_ int cx, _In_ int cy, _In_ UINT fuLoad)
Definition: cursoricon.c:2540
#define CB_SETCURSEL
Definition: winuser.h:1972
#define VK_CONTROL
Definition: winuser.h:2214
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1750
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:841
#define CBN_SELCHANGE
Definition: winuser.h:1990
#define BM_SETCHECK
Definition: winuser.h:1932
#define MIIM_STATE
Definition: winuser.h:732
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define MFS_DEFAULT
Definition: winuser.h:759
#define MB_ICONERROR
Definition: winuser.h:798
#define SM_CYICON
Definition: winuser.h:984
BOOL WINAPI DrawIconEx(_In_ HDC, _In_ int, _In_ int, _In_ HICON, _In_ int, _In_ int, _In_ UINT, _In_opt_ HBRUSH, _In_ UINT)
Definition: cursoricon.c:2365
#define CB_ADDSTRING
Definition: winuser.h:1947
#define CB_GETITEMDATA
Definition: winuser.h:1961
#define SendMessage
Definition: winuser.h:5863
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define EM_SETSEL
Definition: winuser.h:2029
#define MFS_ENABLED
Definition: winuser.h:761
#define PostMessage
Definition: winuser.h:5852
HWND WINAPI GetParent(_In_ HWND)
#define DWLP_MSGRESULT
Definition: winuser.h:881
#define MFT_STRING
Definition: winuser.h:757
#define SW_SHOW
Definition: winuser.h:786
#define WM_DESTROY
Definition: winuser.h:1620
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define CB_GETCURSEL
Definition: winuser.h:1954
#define SM_CXICON
Definition: winuser.h:983
int WINAPI GetSystemMetrics(_In_ int)
#define SW_SHOWMINNOACTIVE
Definition: winuser.h:788
#define MIIM_TYPE
Definition: winuser.h:736
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BST_CHECKED
Definition: winuser.h:197
BOOL WINAPI InsertMenuItemW(_In_ HMENU, _In_ UINT, _In_ BOOL, _In_ LPCMENUITEMINFOW)
SHORT WINAPI GetKeyState(_In_ int)
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define BM_GETCHECK
Definition: winuser.h:1929
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2390
#define EN_CHANGE
Definition: winuser.h:2033
#define COLOR_3DFACE
Definition: winuser.h:940
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
#define IID_PPV_ARG(Itype, ppType)
const char * LPCSTR
Definition: xmlstorage.h:183
char * LPSTR
Definition: xmlstorage.h:182
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185