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
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * Nearly complete information about the binary formats
26 * of .lnk files available at http://www.wotsit.org
28 * You can use winedump to examine the contents of a link file:
31 * MSI advertised shortcuts are totally undocumented. They provide an
32 * icon for a program that is not yet installed, and invoke MSI to
33 * install the program when the shortcut is clicked on. They are
34 * created by passing a special string to SetPath, and the information
35 * in that string is parsed an stored.
38 * In the following is listed more documentation about the Shell Link file format,
39 * as well as its interface.
41 * General introduction about "Shell Links" (MSDN):
42 * https://msdn.microsoft.com/en-us/library/windows/desktop/bb776891(v=vs.85).aspx
45 * Details of the file format:
47 * - Official MSDN documentation "[MS-SHLLINK]: Shell Link (.LNK) Binary File Format":
48 * https://msdn.microsoft.com/en-us/library/dd871305.aspx
51 * http://forensicswiki.org/wiki/LNK
52 * http://computerforensics.parsonage.co.uk/downloads/TheMeaningofLIFE.pdf
53 * https://ithreats.files.wordpress.com/2009/05/lnk_the_windows_shortcut_file_format.pdf
54 * https://github.com/libyal/liblnk/blob/master/documentation/Windows%20Shortcut%20File%20(LNK)%20format.asciidoc
56 * - List of possible shell link header flags (SHELL_LINK_DATA_FLAGS enumeration):
57 * https://msdn.microsoft.com/en-us/library/windows/desktop/bb762540(v=vs.85).aspx
58 * https://msdn.microsoft.com/en-us/library/dd891314.aspx
61 * In addition to storing its target by using a PIDL, a shell link file also
62 * stores metadata to make the shell able to track the link target, in situations
63 * where the link target is moved amongst local or network directories, or moved
64 * to different volumes. For this, two structures are used:
66 * - The first and oldest one (from NewShell/WinNT4) is the "LinkInfo" structure,
67 * stored in a serialized manner at the beginning of the shell link file:
68 * https://msdn.microsoft.com/en-us/library/dd871404.aspx
69 * The official API for manipulating this is located in LINKINFO.DLL .
71 * - The second, more recent one, is an extra binary block appended to the
72 * extra-data list of the shell link file: this is the "TrackerDataBlock":
73 * https://msdn.microsoft.com/en-us/library/dd891376.aspx
74 * Its purpose is for link tracking, and works in coordination with the
75 * "Distributed Link Tracking" service ('TrkWks' client, 'TrkSvr' server).
76 * See a detailed explanation at:
77 * http://www.serverwatch.com/tutorials/article.php/1476701/Searching-for-the-Missing-Link-Distributed-Link-Tracking.htm
80 * MSI installations most of the time create so-called "advertised shortcuts".
81 * They provide an icon for a program that may not be installed yet, and invoke
82 * MSI to install the program when the shortcut is opened (resolved).
83 * The philosophy of this approach is explained in detail inside the MSDN article
84 * "Application Resiliency: Unlock the Hidden Features of Windows Installer"
85 * (by Michael Sanford), here:
86 * https://msdn.microsoft.com/en-us/library/aa302344.aspx
88 * This functionality is implemented by adding a binary "Darwin" data block
89 * of type "EXP_DARWIN_LINK", signature EXP_DARWIN_ID_SIG == 0xA0000006,
90 * to the shell link file:
91 * https://msdn.microsoft.com/en-us/library/dd871369.aspx
92 * or, this could be done more simply by specifying a special link target path
93 * with the IShellLink::SetPath() function. Defining the following GUID:
94 * SHELL32_AdvtShortcutComponent = "::{9db1186e-40df-11d1-aa8c-00c04fb67863}:"
95 * setting a target of the form:
96 * "::{SHELL32_AdvtShortcutComponent}:<MSI_App_ID>"
97 * would automatically create the necessary binary block.
99 * With that, the target of the shortcut now becomes the MSI data. The latter
100 * is parsed from MSI and retrieved by the shell that then can run the program.
102 * This MSI functionality, dubbed "link blessing", actually originates from an
103 * older technology introduced in Internet Explorer 3 (and now obsolete since
104 * Internet Explorer 7), called "MS Internet Component Download (MSICD)", see
105 * this MSDN introductory article:
106 * https://msdn.microsoft.com/en-us/library/aa741198(v=vs.85).aspx
107 * and leveraged in Internet Explorer 4 with "Software Update Channels", see:
108 * https://msdn.microsoft.com/en-us/library/aa740931(v=vs.85).aspx
109 * Applications supporting this technology could present shell links having
110 * a special target, see subsection "Modifying the Shortcut" in the article:
111 * https://msdn.microsoft.com/en-us/library/aa741201(v=vs.85).aspx#pub_shor
113 * Similarly as for the MSI shortcuts, these MSICD shortcuts are created by
114 * specifying a special link target path with the IShellLink::SetPath() function,
115 * defining the following GUID:
116 * SHELL32_AdvtShortcutProduct = "::{9db1186f-40df-11d1-aa8c-00c04fb67863}:"
117 * and setting a target of the form:
118 * "::{SHELL32_AdvtShortcutProduct}:<AppName>::<Path>" .
119 * A tool, called "blesslnk.exe", was also provided for automatizing the process;
120 * its ReadMe can be found in the (now outdated) MS "Internet Client SDK" (INetSDK,
121 * for MS Windows 95 and NT), whose contents can be read at:
122 * http://www.msfn.org/board/topic/145352-new-windows-lnk-vulnerability/?page=4#comment-944223
123 * The MS INetSDK can be found at:
124 * https://web.archive.org/web/20100924000013/http://support.microsoft.com/kb/177877
126 * Internally the shell link target of these MSICD shortcuts is converted into
127 * a binary data block of a type similar to Darwin / "EXP_DARWIN_LINK", but with
128 * a different signature EXP_LOGO3_ID_SIG == 0xA0000007 . Such shell links are
129 * called "Logo3" shortcuts. They were evoked in this user comment in "The Old
131 * https://blogs.msdn.microsoft.com/oldnewthing/20121210-00/?p=5883#comment-1025083
133 * The shell exports the API 'SoftwareUpdateMessageBox' (in shdocvw.dll) that
134 * displays a message when an update for an application supporting this
135 * technology is available.
143 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
145 #define SHLINK_LOCAL 0
146 #define SHLINK_REMOTE 1
147 #define MAX_PROPERTY_SHEET_PAGE 32
149 /* link file formats */
151 #include "pshpack1.h"
159 DWORD dwLocalPathOfs
;
160 DWORD dwNetworkVolTableOfs
;
161 DWORD dwFinalPathOfs
;
164 struct LOCAL_VOLUME_INFO
176 WCHAR label
[12]; /* assume 8.3 */
181 /* IShellLink Implementation */
183 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
185 /* strdup on the process heap */
186 static LPWSTR __inline
HEAP_strdupAtoW(HANDLE heap
, DWORD flags
, LPCSTR str
)
193 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
194 p
= (LPWSTR
)HeapAlloc(heap
, flags
, len
* sizeof(WCHAR
));
197 MultiByteToWideChar(CP_ACP
, 0, str
, -1, p
, len
);
201 static LPWSTR __inline
strdupW(LPCWSTR src
)
204 if (!src
) return NULL
;
205 dest
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(src
) + 1) * sizeof(WCHAR
));
211 // TODO: Use it for constructor & destructor too
212 VOID
CShellLink::Reset()
217 HeapFree(GetProcessHeap(), 0, m_sPath
);
219 ZeroMemory(&volume
, sizeof(volume
));
221 HeapFree(GetProcessHeap(), 0, m_sDescription
);
222 m_sDescription
= NULL
;
223 HeapFree(GetProcessHeap(), 0, m_sPathRel
);
225 HeapFree(GetProcessHeap(), 0, m_sWorkDir
);
227 HeapFree(GetProcessHeap(), 0, m_sArgs
);
229 HeapFree(GetProcessHeap(), 0, m_sIcoPath
);
236 SHFreeDataBlockList(m_pDBList
);
239 /**/sProduct
= sComponent
= NULL
;/**/
242 CShellLink::CShellLink()
244 m_Header
.dwSize
= sizeof(m_Header
);
245 m_Header
.clsid
= CLSID_ShellLink
;
246 m_Header
.dwFlags
= 0;
248 m_Header
.dwFileAttributes
= 0;
249 ZeroMemory(&m_Header
.ftCreationTime
, sizeof(m_Header
.ftCreationTime
));
250 ZeroMemory(&m_Header
.ftLastAccessTime
, sizeof(m_Header
.ftLastAccessTime
));
251 ZeroMemory(&m_Header
.ftLastWriteTime
, sizeof(m_Header
.ftLastWriteTime
));
252 m_Header
.nFileSizeLow
= 0;
254 m_Header
.nIconIndex
= 0;
255 m_Header
.nShowCommand
= SW_SHOWNORMAL
;
256 m_Header
.wHotKey
= 0;
261 ZeroMemory(&volume
, sizeof(volume
));
263 m_sDescription
= NULL
;
275 /**/sProduct
= sComponent
= NULL
;/**/
278 CShellLink::~CShellLink()
280 TRACE("-- destroying IShellLink(%p)\n", this);
284 HeapFree(GetProcessHeap(), 0, m_sPath
);
286 HeapFree(GetProcessHeap(), 0, m_sDescription
);
287 HeapFree(GetProcessHeap(), 0, m_sPathRel
);
288 HeapFree(GetProcessHeap(), 0, m_sWorkDir
);
289 HeapFree(GetProcessHeap(), 0, m_sArgs
);
290 HeapFree(GetProcessHeap(), 0, m_sIcoPath
);
291 HeapFree(GetProcessHeap(), 0, m_sLinkPath
);
292 SHFreeDataBlockList(m_pDBList
);
295 HRESULT STDMETHODCALLTYPE
CShellLink::GetClassID(CLSID
*pclsid
)
297 TRACE("%p %p\n", this, pclsid
);
301 *pclsid
= CLSID_ShellLink
;
305 /************************************************************************
306 * IPersistStream_IsDirty (IPersistStream)
308 HRESULT STDMETHODCALLTYPE
CShellLink::IsDirty()
310 TRACE("(%p)\n", this);
311 return (m_bDirty
? S_OK
: S_FALSE
);
314 HRESULT STDMETHODCALLTYPE
CShellLink::Load(LPCOLESTR pszFileName
, DWORD dwMode
)
316 TRACE("(%p, %s, %x)\n", this, debugstr_w(pszFileName
), dwMode
);
319 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
321 CComPtr
<IStream
> stm
;
322 HRESULT hr
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
325 HeapFree(GetProcessHeap(), 0, m_sLinkPath
);
326 m_sLinkPath
= strdupW(pszFileName
);
328 ShellLink_UpdatePath(m_sPathRel
, pszFileName
, m_sWorkDir
, &m_sPath
);
331 TRACE("-- returning hr %08x\n", hr
);
335 HRESULT STDMETHODCALLTYPE
CShellLink::Save(LPCOLESTR pszFileName
, BOOL fRemember
)
337 TRACE("(%p)->(%s)\n", this, debugstr_w(pszFileName
));
342 CComPtr
<IStream
> stm
;
343 HRESULT hr
= SHCreateStreamOnFileW(pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
346 hr
= Save(stm
, FALSE
);
351 HeapFree(GetProcessHeap(), 0, m_sLinkPath
);
353 m_sLinkPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(pszFileName
) + 1) * sizeof(WCHAR
));
355 wcscpy(m_sLinkPath
, pszFileName
);
361 DeleteFileW(pszFileName
);
362 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
));
369 HRESULT STDMETHODCALLTYPE
CShellLink::SaveCompleted(LPCOLESTR pszFileName
)
371 FIXME("(%p)->(%s)\n", this, debugstr_w(pszFileName
));
375 HRESULT STDMETHODCALLTYPE
CShellLink::GetCurFile(LPOLESTR
*ppszFileName
)
377 *ppszFileName
= NULL
;
381 /* IPersistFile::GetCurFile called before IPersistFile::Save */
385 *ppszFileName
= (LPOLESTR
)CoTaskMemAlloc((wcslen(m_sLinkPath
) + 1) * sizeof(WCHAR
));
389 return E_OUTOFMEMORY
;
392 /* copy last saved filename */
393 wcscpy(*ppszFileName
, m_sLinkPath
);
398 static HRESULT
Stream_LoadString(IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
404 HRESULT hr
= stm
->Read(&len
, sizeof(len
), &count
);
405 if (FAILED(hr
) || count
!= sizeof(len
))
409 len
*= sizeof(WCHAR
);
411 TRACE("reading %d\n", len
);
412 LPSTR temp
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len
+ sizeof(WCHAR
));
414 return E_OUTOFMEMORY
;
416 hr
= stm
->Read(temp
, len
, &count
);
417 if (FAILED(hr
) || count
!= len
)
419 HeapFree(GetProcessHeap(), 0, temp
);
423 TRACE("read %s\n", debugstr_an(temp
, len
));
425 /* convert to unicode if necessary */
429 count
= MultiByteToWideChar(CP_ACP
, 0, temp
, len
, NULL
, 0);
430 str
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (count
+ 1) * sizeof(WCHAR
));
433 HeapFree(GetProcessHeap(), 0, temp
);
434 return E_OUTOFMEMORY
;
436 MultiByteToWideChar(CP_ACP
, 0, temp
, len
, str
, count
);
437 HeapFree(GetProcessHeap(), 0, temp
);
441 count
/= sizeof(WCHAR
);
453 * NOTE: The following 5 functions are part of LINKINFO.DLL
455 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, CShellLink::volume_info
*volume
)
457 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
459 volume
->type
= GetDriveTypeW(drive
);
460 BOOL bRet
= GetVolumeInformationW(drive
, volume
->label
, _countof(volume
->label
), &volume
->serial
, NULL
, NULL
, NULL
, 0);
461 TRACE("ret = %d type %d serial %08x name %s\n", bRet
,
462 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
466 static HRESULT
Stream_ReadChunk(IStream
* stm
, LPVOID
*data
)
471 unsigned char data
[1];
478 HRESULT hr
= stm
->Read(&size
, sizeof(size
), &count
);
479 if (FAILED(hr
) || count
!= sizeof(size
))
482 chunk
= static_cast<sized_chunk
*>(HeapAlloc(GetProcessHeap(), 0, size
));
484 return E_OUTOFMEMORY
;
487 hr
= stm
->Read(chunk
->data
, size
- sizeof(size
), &count
);
488 if (FAILED(hr
) || count
!= (size
- sizeof(size
)))
490 HeapFree(GetProcessHeap(), 0, chunk
);
494 TRACE("Read %d bytes\n", chunk
->size
);
501 static BOOL
Stream_LoadVolume(LOCAL_VOLUME_INFO
*vol
, CShellLink::volume_info
*volume
)
503 volume
->serial
= vol
->dwVolSerial
;
504 volume
->type
= vol
->dwType
;
506 if (!vol
->dwVolLabelOfs
)
508 if (vol
->dwSize
<= vol
->dwVolLabelOfs
)
510 INT len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
512 LPSTR label
= (LPSTR
)vol
;
513 label
+= vol
->dwVolLabelOfs
;
514 MultiByteToWideChar(CP_ACP
, 0, label
, len
, volume
->label
, _countof(volume
->label
));
519 static LPWSTR
Stream_LoadPath(LPCSTR p
, DWORD maxlen
)
523 while (p
[len
] && len
< maxlen
)
526 UINT wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
527 LPWSTR path
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wlen
+ 1) * sizeof(WCHAR
));
530 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
536 static HRESULT
Stream_LoadLocation(IStream
*stm
,
537 CShellLink::volume_info
*volume
, LPWSTR
*path
)
540 HRESULT hr
= Stream_ReadChunk(stm
, (LPVOID
*) &p
);
544 LOCATION_INFO
*loc
= reinterpret_cast<LOCATION_INFO
*>(p
);
545 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
547 HeapFree(GetProcessHeap(), 0, p
);
551 /* if there's valid local volume information, load it */
552 if (loc
->dwVolTableOfs
&&
553 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
))
555 LOCAL_VOLUME_INFO
*volume_info
;
557 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
558 Stream_LoadVolume(volume_info
, volume
);
561 /* if there's a local path, load it */
562 DWORD n
= loc
->dwLocalPathOfs
;
563 if (n
&& n
< loc
->dwTotalSize
)
564 *path
= Stream_LoadPath(&p
[n
], loc
->dwTotalSize
- n
);
566 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
567 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
569 HeapFree(GetProcessHeap(), 0, p
);
575 * The format of the advertised shortcut info is:
579 * 0 Length of the block (4 bytes, usually 0x314)
581 * 8 string data in ASCII
582 * 8+0x104 string data in UNICODE
584 * In the original Win32 implementation the buffers are not initialized
585 * to zero, so data trailing the string is random garbage.
587 HRESULT
CShellLink::GetAdvertiseInfo(LPWSTR
*str
, DWORD dwSig
)
589 LPEXP_DARWIN_LINK pInfo
;
593 pInfo
= (LPEXP_DARWIN_LINK
)SHFindDataBlock(m_pDBList
, dwSig
);
597 /* Make sure that the size of the structure is valid */
598 if (pInfo
->dbh
.cbSize
!= sizeof(*pInfo
))
600 ERR("Ooops. This structure is not as expected...\n");
604 TRACE("dwSig %08x string = '%s'\n", pInfo
->dbh
.dwSignature
, debugstr_w(pInfo
->szwDarwinID
));
606 *str
= pInfo
->szwDarwinID
;
610 /************************************************************************
611 * IPersistStream_Load (IPersistStream)
613 HRESULT STDMETHODCALLTYPE
CShellLink::Load(IStream
*stm
)
615 TRACE("%p %p\n", this, stm
);
618 return STG_E_INVALIDPOINTER
;
620 /* Free all the old stuff */
623 ULONG dwBytesRead
= 0;
624 HRESULT hr
= stm
->Read(&m_Header
, sizeof(m_Header
), &dwBytesRead
);
628 if (dwBytesRead
!= sizeof(m_Header
))
630 if (m_Header
.dwSize
!= sizeof(m_Header
))
632 if (!IsEqualIID(m_Header
.clsid
, CLSID_ShellLink
))
635 /* Load the new data in order */
639 SYSTEMTIME stCreationTime
;
640 SYSTEMTIME stLastAccessTime
;
641 SYSTEMTIME stLastWriteTime
;
642 WCHAR sTemp
[MAX_PATH
];
644 FileTimeToSystemTime(&m_Header
.ftCreationTime
, &stCreationTime
);
645 FileTimeToSystemTime(&m_Header
.ftLastAccessTime
, &stLastAccessTime
);
646 FileTimeToSystemTime(&m_Header
.ftLastWriteTime
, &stLastWriteTime
);
648 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &stCreationTime
,
649 NULL
, sTemp
, _countof(sTemp
));
650 TRACE("-- stCreationTime: %s\n", debugstr_w(sTemp
));
651 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &stLastAccessTime
,
652 NULL
, sTemp
, _countof(sTemp
));
653 TRACE("-- stLastAccessTime: %s\n", debugstr_w(sTemp
));
654 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &stLastWriteTime
,
655 NULL
, sTemp
, _countof(sTemp
));
656 TRACE("-- stLastWriteTime: %s\n", debugstr_w(sTemp
));
659 /* load all the new stuff */
660 if (m_Header
.dwFlags
& SLDF_HAS_ID_LIST
)
662 hr
= ILLoadFromStream(stm
, &m_pPidl
);
668 /* Load the location information... */
669 if (m_Header
.dwFlags
& SLDF_HAS_LINK_INFO
)
671 hr
= Stream_LoadLocation(stm
, &volume
, &m_sPath
);
675 /* ... but if it is required not to use it, clear it */
676 if (m_Header
.dwFlags
& SLDF_FORCE_NO_LINKINFO
)
678 HeapFree(GetProcessHeap(), 0, m_sPath
);
680 ZeroMemory(&volume
, sizeof(volume
));
683 BOOL unicode
= !!(m_Header
.dwFlags
& SLDF_UNICODE
);
685 if (m_Header
.dwFlags
& SLDF_HAS_NAME
)
687 hr
= Stream_LoadString(stm
, unicode
, &m_sDescription
);
690 TRACE("Description -> %s\n", debugstr_w(m_sDescription
));
693 if (m_Header
.dwFlags
& SLDF_HAS_RELPATH
)
695 hr
= Stream_LoadString(stm
, unicode
, &m_sPathRel
);
698 TRACE("Relative Path-> %s\n", debugstr_w(m_sPathRel
));
701 if (m_Header
.dwFlags
& SLDF_HAS_WORKINGDIR
)
703 hr
= Stream_LoadString(stm
, unicode
, &m_sWorkDir
);
706 PathRemoveBackslash(m_sWorkDir
);
707 TRACE("Working Dir -> %s\n", debugstr_w(m_sWorkDir
));
710 if (m_Header
.dwFlags
& SLDF_HAS_ARGS
)
712 hr
= Stream_LoadString(stm
, unicode
, &m_sArgs
);
715 TRACE("Arguments -> %s\n", debugstr_w(m_sArgs
));
718 if (m_Header
.dwFlags
& SLDF_HAS_ICONLOCATION
)
720 hr
= Stream_LoadString(stm
, unicode
, &m_sIcoPath
);
723 TRACE("Icon file -> %s\n", debugstr_w(m_sIcoPath
));
726 /* Now load the optional data block list */
727 hr
= SHReadDataBlockList(stm
, &m_pDBList
);
728 if (FAILED(hr
)) // FIXME: Should we fail?
733 #if (NTDDI_VERSION < NTDDI_LONGHORN)
734 if (m_Header
.dwFlags
& SLDF_HAS_LOGO3ID
)
736 hr
= GetAdvertiseInfo(&sProduct
, EXP_LOGO3_ID_SIG
);
738 TRACE("Product -> %s\n", debugstr_w(sProduct
));
741 if (m_Header
.dwFlags
& SLDF_HAS_DARWINID
)
743 hr
= GetAdvertiseInfo(&sComponent
, EXP_DARWIN_ID_SIG
);
745 TRACE("Component -> %s\n", debugstr_w(sComponent
));
749 if (m_Header
.dwFlags
& SLDF_RUNAS_USER
)
755 hr
= stm
->Read(&dwZero
, sizeof(dwZero
), &dwBytesRead
);
756 if (FAILED(hr
) || dwZero
|| dwBytesRead
!= sizeof(dwZero
))
757 ERR("Last word was not zero\n");
766 /************************************************************************
769 * Helper function for IPersistStream_Save. Writes a unicode string
770 * with terminating nul byte to a stream, preceded by the its length.
772 static HRESULT
Stream_WriteString(IStream
* stm
, LPCWSTR str
)
774 USHORT len
= wcslen(str
) + 1; // FIXME: Possible overflows?
777 HRESULT hr
= stm
->Write(&len
, sizeof(len
), &count
);
781 len
*= sizeof(WCHAR
);
783 hr
= stm
->Write(str
, len
, &count
);
790 /************************************************************************
791 * Stream_WriteLocationInfo
793 * Writes the location info to a stream
795 * FIXME: One day we might want to write the network volume information
796 * and the final path.
797 * Figure out how Windows deals with unicode paths here.
799 static HRESULT
Stream_WriteLocationInfo(IStream
* stm
, LPCWSTR path
,
800 CShellLink::volume_info
*volume
)
802 LOCAL_VOLUME_INFO
*vol
;
805 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
807 /* figure out the size of everything */
808 DWORD label_size
= WideCharToMultiByte(CP_ACP
, 0, volume
->label
, -1,
809 NULL
, 0, NULL
, NULL
);
810 DWORD path_size
= WideCharToMultiByte(CP_ACP
, 0, path
, -1,
811 NULL
, 0, NULL
, NULL
);
812 DWORD volume_info_size
= sizeof(*vol
) + label_size
;
813 DWORD final_path_size
= 1;
814 DWORD total_size
= sizeof(*loc
) + volume_info_size
+ path_size
+ final_path_size
;
816 /* create pointers to everything */
817 loc
= static_cast<LOCATION_INFO
*>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
));
818 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
819 LPSTR szLabel
= (LPSTR
) &vol
[1];
820 LPSTR szPath
= &szLabel
[label_size
];
821 LPSTR szFinalPath
= &szPath
[path_size
];
823 /* fill in the location information header */
824 loc
->dwTotalSize
= total_size
;
825 loc
->dwHeaderSize
= sizeof(*loc
);
827 loc
->dwVolTableOfs
= sizeof(*loc
);
828 loc
->dwLocalPathOfs
= sizeof(*loc
) + volume_info_size
;
829 loc
->dwNetworkVolTableOfs
= 0;
830 loc
->dwFinalPathOfs
= sizeof(*loc
) + volume_info_size
+ path_size
;
832 /* fill in the volume information */
833 vol
->dwSize
= volume_info_size
;
834 vol
->dwType
= volume
->type
;
835 vol
->dwVolSerial
= volume
->serial
;
836 vol
->dwVolLabelOfs
= sizeof(*vol
);
838 /* copy in the strings */
839 WideCharToMultiByte(CP_ACP
, 0, volume
->label
, -1,
840 szLabel
, label_size
, NULL
, NULL
);
841 WideCharToMultiByte(CP_ACP
, 0, path
, -1,
842 szPath
, path_size
, NULL
, NULL
);
846 HRESULT hr
= stm
->Write(loc
, total_size
, &count
);
847 HeapFree(GetProcessHeap(), 0, loc
);
852 /************************************************************************
853 * IPersistStream_Save (IPersistStream)
855 * FIXME: makes assumptions about byte order
857 HRESULT STDMETHODCALLTYPE
CShellLink::Save(IStream
*stm
, BOOL fClearDirty
)
859 TRACE("%p %p %x\n", this, stm
, fClearDirty
);
861 m_Header
.dwSize
= sizeof(m_Header
);
862 m_Header
.clsid
= CLSID_ShellLink
;
865 * Reset the flags: keep only the flags related to data blocks as they were
866 * already set in accordance by the different mutator member functions.
867 * The other flags will be determined now by the presence or absence of data.
869 m_Header
.dwFlags
&= (SLDF_RUN_WITH_SHIMLAYER
| SLDF_RUNAS_USER
|
870 SLDF_RUN_IN_SEPARATE
| SLDF_HAS_DARWINID
|
871 #if (NTDDI_VERSION < NTDDI_LONGHORN)
874 SLDF_HAS_EXP_ICON_SZ
| SLDF_HAS_EXP_SZ
);
875 // TODO: When we will support Vista+ functionality, add other flags to this list.
877 /* The stored strings are in UNICODE */
878 m_Header
.dwFlags
|= SLDF_UNICODE
;
881 m_Header
.dwFlags
|= SLDF_HAS_ID_LIST
;
883 m_Header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
884 if (m_sDescription
&& *m_sDescription
)
885 m_Header
.dwFlags
|= SLDF_HAS_NAME
;
886 if (m_sPathRel
&& *m_sPathRel
)
887 m_Header
.dwFlags
|= SLDF_HAS_RELPATH
;
888 if (m_sWorkDir
&& *m_sWorkDir
)
889 m_Header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
890 if (m_sArgs
&& *m_sArgs
)
891 m_Header
.dwFlags
|= SLDF_HAS_ARGS
;
892 if (m_sIcoPath
&& *m_sIcoPath
)
893 m_Header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
895 m_Header
.dwFlags
|= SLDF_RUNAS_USER
;
897 /* Write the shortcut header */
899 HRESULT hr
= stm
->Write(&m_Header
, sizeof(m_Header
), &count
);
902 ERR("Write failed\n");
906 /* Save the data in order */
910 hr
= ILSaveToStream(stm
, m_pPidl
);
913 ERR("Failed to write PIDL\n");
920 hr
= Stream_WriteLocationInfo(stm
, m_sPath
, &volume
);
925 if (m_Header
.dwFlags
& SLDF_HAS_NAME
)
927 hr
= Stream_WriteString(stm
, m_sDescription
);
932 if (m_Header
.dwFlags
& SLDF_HAS_RELPATH
)
934 hr
= Stream_WriteString(stm
, m_sPathRel
);
939 if (m_Header
.dwFlags
& SLDF_HAS_WORKINGDIR
)
941 hr
= Stream_WriteString(stm
, m_sWorkDir
);
946 if (m_Header
.dwFlags
& SLDF_HAS_ARGS
)
948 hr
= Stream_WriteString(stm
, m_sArgs
);
953 if (m_Header
.dwFlags
& SLDF_HAS_ICONLOCATION
)
955 hr
= Stream_WriteString(stm
, m_sIcoPath
);
961 * Now save the data block list.
963 * NOTE that both advertised Product and Component are already saved
964 * inside Logo3 and Darwin data blocks in the m_pDBList list, and the
965 * m_Header.dwFlags is suitably initialized.
967 hr
= SHWriteDataBlockList(stm
, m_pDBList
);
971 /* Clear the dirty bit if requested */
975 /* The last field is a single zero dword */
977 hr
= stm
->Write(&dwZero
, sizeof(dwZero
), &count
);
982 /************************************************************************
983 * IPersistStream_GetSizeMax (IPersistStream)
985 HRESULT STDMETHODCALLTYPE
CShellLink::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
987 TRACE("(%p)\n", this);
991 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
993 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
999 /**************************************************************************
1000 * ShellLink_UpdatePath
1001 * update absolute path in sPath using relative path in sPathRel
1003 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1005 if (!path
|| !psPath
)
1006 return E_INVALIDARG
;
1008 if (!*psPath
&& sPathRel
)
1010 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1011 LPWSTR final
= NULL
;
1013 /* first try if [directory of link file] + [relative path] finds an existing file */
1015 GetFullPathNameW(path
, MAX_PATH
* 2, buffer
, &final
);
1018 wcscpy(final
, sPathRel
);
1022 if (SHELL_ExistsFileW(buffer
))
1024 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1025 wcscpy(abs_path
, buffer
);
1029 /* try if [working directory] + [relative path] finds an existing file */
1032 wcscpy(buffer
, sWorkDir
);
1033 wcscpy(PathAddBackslashW(buffer
), sPathRel
);
1035 if (SHELL_ExistsFileW(buffer
))
1036 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1037 wcscpy(abs_path
, buffer
);
1041 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1043 wcscpy(abs_path
, sPathRel
);
1045 *psPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(abs_path
) + 1) * sizeof(WCHAR
));
1047 return E_OUTOFMEMORY
;
1049 wcscpy(*psPath
, abs_path
);
1055 HRESULT STDMETHODCALLTYPE
CShellLink::GetPath(LPSTR pszFile
, INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1059 WIN32_FIND_DATAW wfd
;
1061 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1062 this, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(m_sPath
));
1064 /* Allocate a temporary UNICODE buffer */
1065 pszFileW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, cchMaxPath
* sizeof(WCHAR
));
1067 return E_OUTOFMEMORY
;
1069 /* Call the UNICODE function */
1070 hr
= GetPath(pszFileW
, cchMaxPath
, &wfd
, fFlags
);
1072 /* Convert the file path back to ANSI */
1073 WideCharToMultiByte(CP_ACP
, 0, pszFileW
, -1,
1074 pszFile
, cchMaxPath
, NULL
, NULL
);
1076 /* Free the temporary buffer */
1077 HeapFree(GetProcessHeap(), 0, pszFileW
);
1081 ZeroMemory(pfd
, sizeof(*pfd
));
1083 /* Copy the file data if a file path was returned */
1086 /* Copy the fixed part */
1087 CopyMemory(pfd
, &wfd
, FIELD_OFFSET(WIN32_FIND_DATAA
, cFileName
));
1089 /* Convert the file names to ANSI */
1090 WideCharToMultiByte(CP_ACP
, 0, wfd
.cFileName
, sizeof(wfd
.cFileName
),
1091 pfd
->cFileName
, sizeof(pfd
->cFileName
), NULL
, NULL
);
1092 WideCharToMultiByte(CP_ACP
, 0, wfd
.cAlternateFileName
, sizeof(wfd
.cAlternateFileName
),
1093 pfd
->cAlternateFileName
, sizeof(pfd
->cAlternateFileName
), NULL
, NULL
);
1100 HRESULT STDMETHODCALLTYPE
CShellLink::GetIDList(LPITEMIDLIST
*ppidl
)
1102 TRACE("(%p)->(ppidl=%p)\n", this, ppidl
);
1110 *ppidl
= ILClone(m_pPidl
);
1114 HRESULT STDMETHODCALLTYPE
CShellLink::SetIDList(LPCITEMIDLIST pidl
)
1116 TRACE("(%p)->(pidl=%p)\n", this, pidl
);
1117 return SetTargetFromPIDLOrPath(pidl
, NULL
);
1120 HRESULT STDMETHODCALLTYPE
CShellLink::GetDescription(LPSTR pszName
, INT cchMaxName
)
1122 TRACE("(%p)->(%p len=%u)\n", this, pszName
, cchMaxName
);
1128 WideCharToMultiByte(CP_ACP
, 0, m_sDescription
, -1,
1129 pszName
, cchMaxName
, NULL
, NULL
);
1134 HRESULT STDMETHODCALLTYPE
CShellLink::SetDescription(LPCSTR pszName
)
1136 TRACE("(%p)->(pName=%s)\n", this, pszName
);
1138 HeapFree(GetProcessHeap(), 0, m_sDescription
);
1139 m_sDescription
= NULL
;
1143 m_sDescription
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszName
);
1144 if (!m_sDescription
)
1145 return E_OUTOFMEMORY
;
1152 HRESULT STDMETHODCALLTYPE
CShellLink::GetWorkingDirectory(LPSTR pszDir
, INT cchMaxPath
)
1154 TRACE("(%p)->(%p len=%u)\n", this, pszDir
, cchMaxPath
);
1160 WideCharToMultiByte(CP_ACP
, 0, m_sWorkDir
, -1,
1161 pszDir
, cchMaxPath
, NULL
, NULL
);
1166 HRESULT STDMETHODCALLTYPE
CShellLink::SetWorkingDirectory(LPCSTR pszDir
)
1168 TRACE("(%p)->(dir=%s)\n", this, pszDir
);
1170 HeapFree(GetProcessHeap(), 0, m_sWorkDir
);
1175 m_sWorkDir
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszDir
);
1177 return E_OUTOFMEMORY
;
1184 HRESULT STDMETHODCALLTYPE
CShellLink::GetArguments(LPSTR pszArgs
, INT cchMaxPath
)
1186 TRACE("(%p)->(%p len=%u)\n", this, pszArgs
, cchMaxPath
);
1192 WideCharToMultiByte(CP_ACP
, 0, m_sArgs
, -1,
1193 pszArgs
, cchMaxPath
, NULL
, NULL
);
1198 HRESULT STDMETHODCALLTYPE
CShellLink::SetArguments(LPCSTR pszArgs
)
1200 TRACE("(%p)->(args=%s)\n", this, pszArgs
);
1202 HeapFree(GetProcessHeap(), 0, m_sArgs
);
1207 m_sArgs
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszArgs
);
1209 return E_OUTOFMEMORY
;
1217 HRESULT STDMETHODCALLTYPE
CShellLink::GetHotkey(WORD
*pwHotkey
)
1219 TRACE("(%p)->(%p)(0x%08x)\n", this, pwHotkey
, m_Header
.wHotKey
);
1220 *pwHotkey
= m_Header
.wHotKey
;
1224 HRESULT STDMETHODCALLTYPE
CShellLink::SetHotkey(WORD wHotkey
)
1226 TRACE("(%p)->(hotkey=%x)\n", this, wHotkey
);
1228 m_Header
.wHotKey
= wHotkey
;
1234 HRESULT STDMETHODCALLTYPE
CShellLink::GetShowCmd(INT
*piShowCmd
)
1236 TRACE("(%p)->(%p) %d\n", this, piShowCmd
, m_Header
.nShowCommand
);
1237 *piShowCmd
= m_Header
.nShowCommand
;
1241 HRESULT STDMETHODCALLTYPE
CShellLink::SetShowCmd(INT iShowCmd
)
1243 TRACE("(%p) %d\n", this, iShowCmd
);
1245 m_Header
.nShowCommand
= iShowCmd
;
1251 HRESULT STDMETHODCALLTYPE
CShellLink::GetIconLocation(LPSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1254 LPWSTR pszIconPathW
;
1256 TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath
, cchIconPath
, piIcon
);
1258 /* Allocate a temporary UNICODE buffer */
1259 pszIconPathW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, cchIconPath
* sizeof(WCHAR
));
1261 return E_OUTOFMEMORY
;
1263 /* Call the UNICODE function */
1264 hr
= GetIconLocation(pszIconPathW
, cchIconPath
, piIcon
);
1266 /* Convert the file path back to ANSI */
1267 WideCharToMultiByte(CP_ACP
, 0, pszIconPathW
, -1,
1268 pszIconPath
, cchIconPath
, NULL
, NULL
);
1270 /* Free the temporary buffer */
1271 HeapFree(GetProcessHeap(), 0, pszIconPathW
);
1276 HRESULT STDMETHODCALLTYPE
CShellLink::GetIconLocation(UINT uFlags
, PSTR pszIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
1279 LPWSTR pszIconFileW
;
1281 TRACE("(%p)->(%u %p len=%u piIndex=%p pwFlags=%p)\n", this, uFlags
, pszIconFile
, cchMax
, piIndex
, pwFlags
);
1283 /* Allocate a temporary UNICODE buffer */
1284 pszIconFileW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, cchMax
* sizeof(WCHAR
));
1286 return E_OUTOFMEMORY
;
1288 /* Call the UNICODE function */
1289 hr
= GetIconLocation(uFlags
, pszIconFileW
, cchMax
, piIndex
, pwFlags
);
1291 /* Convert the file path back to ANSI */
1292 WideCharToMultiByte(CP_ACP
, 0, pszIconFileW
, -1,
1293 pszIconFile
, cchMax
, NULL
, NULL
);
1295 /* Free the temporary buffer */
1296 HeapFree(GetProcessHeap(), 0, pszIconFileW
);
1301 HRESULT STDMETHODCALLTYPE
CShellLink::Extract(PCSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
1303 TRACE("(%p)->(path=%s iicon=%u)\n", this, pszFile
, nIconIndex
);
1308 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1310 return E_OUTOFMEMORY
;
1313 HRESULT hr
= Extract(str
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
1316 HeapFree(GetProcessHeap(), 0, str
);
1321 HRESULT STDMETHODCALLTYPE
CShellLink::SetIconLocation(LPCSTR pszIconPath
, INT iIcon
)
1323 TRACE("(%p)->(path=%s iicon=%u)\n", this, pszIconPath
, iIcon
);
1328 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1330 return E_OUTOFMEMORY
;
1333 HRESULT hr
= SetIconLocation(str
, iIcon
);
1336 HeapFree(GetProcessHeap(), 0, str
);
1341 HRESULT STDMETHODCALLTYPE
CShellLink::SetRelativePath(LPCSTR pszPathRel
, DWORD dwReserved
)
1343 TRACE("(%p)->(path=%s %x)\n", this, pszPathRel
, dwReserved
);
1345 HeapFree(GetProcessHeap(), 0, m_sPathRel
);
1350 m_sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1354 return ShellLink_UpdatePath(m_sPathRel
, m_sPath
, m_sWorkDir
, &m_sPath
);
1358 shelllink_get_msi_component_path(LPWSTR component
)
1360 DWORD Result
, sz
= 0;
1362 Result
= CommandLineFromMsiDescriptor(component
, NULL
, &sz
);
1363 if (Result
!= ERROR_SUCCESS
)
1367 LPWSTR path
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
));
1368 Result
= CommandLineFromMsiDescriptor(component
, path
, &sz
);
1369 if (Result
!= ERROR_SUCCESS
)
1371 HeapFree(GetProcessHeap(), 0, path
);
1375 TRACE("returning %s\n", debugstr_w(path
));
1380 HRESULT STDMETHODCALLTYPE
CShellLink::Resolve(HWND hwnd
, DWORD fFlags
)
1385 TRACE("(%p)->(hwnd=%p flags=%x)\n", this, hwnd
, fFlags
);
1387 /* FIXME: use IResolveShellLink interface? */
1389 // FIXME: See InvokeCommand().
1391 #if (NTDDI_VERSION < NTDDI_LONGHORN)
1392 // NOTE: For Logo3 (EXP_LOGO3_ID_SIG), check also for SHRestricted(REST_NOLOGO3CHANNELNOTIFY)
1393 if (m_Header
.dwFlags
& SLDF_HAS_LOGO3ID
)
1395 FIXME("Logo3 links are not supported yet!\n");
1400 /* Resolve Darwin (MSI) target */
1401 if (m_Header
.dwFlags
& SLDF_HAS_DARWINID
)
1403 LPWSTR component
= NULL
;
1404 hr
= GetAdvertiseInfo(&component
, EXP_DARWIN_ID_SIG
);
1408 /* Clear the cached path */
1409 HeapFree(GetProcessHeap(), 0, m_sPath
);
1411 m_sPath
= shelllink_get_msi_component_path(component
);
1416 if (!m_sPath
&& m_pPidl
)
1418 WCHAR buffer
[MAX_PATH
];
1420 bSuccess
= SHGetPathFromIDListW(m_pPidl
, buffer
);
1421 if (bSuccess
&& *buffer
)
1423 m_sPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(buffer
) + 1) * sizeof(WCHAR
));
1425 return E_OUTOFMEMORY
;
1427 wcscpy(m_sPath
, buffer
);
1433 hr
= S_OK
; /* don't report an error occurred while just caching information */
1437 // FIXME: Strange to do that here...
1438 if (!m_sIcoPath
&& m_sPath
)
1440 m_sIcoPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(m_sPath
) + 1) * sizeof(WCHAR
));
1442 return E_OUTOFMEMORY
;
1444 wcscpy(m_sIcoPath
, m_sPath
);
1445 m_Header
.nIconIndex
= 0;
1453 HRESULT STDMETHODCALLTYPE
CShellLink::SetPath(LPCSTR pszFile
)
1455 TRACE("(%p)->(path=%s)\n", this, pszFile
);
1458 return E_INVALIDARG
;
1460 LPWSTR str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1462 return E_OUTOFMEMORY
;
1464 HRESULT hr
= SetPath(str
);
1465 HeapFree(GetProcessHeap(), 0, str
);
1470 HRESULT STDMETHODCALLTYPE
CShellLink::GetPath(LPWSTR pszFile
, INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1472 WCHAR buffer
[MAX_PATH
];
1474 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1475 this, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(m_sPath
));
1479 // FIXME: What if cchMaxPath == 0 , or pszFile == NULL ??
1481 // FIXME: What about Darwin??
1484 * Retrieve the path to the target from the PIDL (if we have one).
1485 * NOTE: Do NOT use the cached path (m_sPath from link info).
1487 if (m_pPidl
&& SHGetPathFromIDListW(m_pPidl
, buffer
))
1489 if (fFlags
& SLGP_SHORTPATH
)
1490 GetShortPathNameW(buffer
, buffer
, _countof(buffer
));
1491 // FIXME: Add support for SLGP_UNCPRIORITY
1498 /* If we have a FindData structure, initialize it */
1501 ZeroMemory(pfd
, sizeof(*pfd
));
1503 /* Copy the file data if the target is a file path */
1506 pfd
->dwFileAttributes
= m_Header
.dwFileAttributes
;
1507 pfd
->ftCreationTime
= m_Header
.ftCreationTime
;
1508 pfd
->ftLastAccessTime
= m_Header
.ftLastAccessTime
;
1509 pfd
->ftLastWriteTime
= m_Header
.ftLastWriteTime
;
1510 pfd
->nFileSizeHigh
= 0;
1511 pfd
->nFileSizeLow
= m_Header
.nFileSizeLow
;
1514 * Build temporarily a short path in pfd->cFileName (of size MAX_PATH),
1515 * then extract and store the short file name in pfd->cAlternateFileName.
1517 GetShortPathNameW(buffer
, pfd
->cFileName
, _countof(pfd
->cFileName
));
1518 lstrcpynW(pfd
->cAlternateFileName
,
1519 PathFindFileNameW(pfd
->cFileName
),
1520 _countof(pfd
->cAlternateFileName
));
1522 /* Now extract and store the long file name in pfd->cFileName */
1523 lstrcpynW(pfd
->cFileName
,
1524 PathFindFileNameW(buffer
),
1525 _countof(pfd
->cFileName
));
1529 /* Finally check if we have a raw path the user actually wants to retrieve */
1530 if ((fFlags
& SLGP_RAWPATH
) && (m_Header
.dwFlags
& SLDF_HAS_EXP_SZ
))
1532 /* Search for a target environment block */
1533 LPEXP_SZ_LINK pInfo
;
1534 pInfo
= (LPEXP_SZ_LINK
)SHFindDataBlock(m_pDBList
, EXP_SZ_LINK_SIG
);
1535 if (pInfo
&& (pInfo
->cbSize
== sizeof(*pInfo
)))
1536 lstrcpynW(buffer
, pInfo
->szwTarget
, cchMaxPath
);
1539 /* For diagnostics purposes only... */
1540 // NOTE: SLGP_UNCPRIORITY is unsupported
1541 fFlags
&= ~(SLGP_RAWPATH
| SLGP_SHORTPATH
);
1542 if (fFlags
) FIXME("(%p): Unsupported flags %lu\n", this, fFlags
);
1544 /* Copy the data back to the user */
1546 lstrcpynW(pszFile
, buffer
, cchMaxPath
);
1548 return (*buffer
? S_OK
: S_FALSE
);
1551 HRESULT STDMETHODCALLTYPE
CShellLink::GetDescription(LPWSTR pszName
, INT cchMaxName
)
1553 TRACE("(%p)->(%p len=%u)\n", this, pszName
, cchMaxName
);
1557 lstrcpynW(pszName
, m_sDescription
, cchMaxName
);
1562 HRESULT STDMETHODCALLTYPE
CShellLink::SetDescription(LPCWSTR pszName
)
1564 TRACE("(%p)->(desc=%s)\n", this, debugstr_w(pszName
));
1566 HeapFree(GetProcessHeap(), 0, m_sDescription
);
1569 m_sDescription
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1570 (wcslen(pszName
) + 1) * sizeof(WCHAR
));
1571 if (!m_sDescription
)
1572 return E_OUTOFMEMORY
;
1574 wcscpy(m_sDescription
, pszName
);
1577 m_sDescription
= NULL
;
1584 HRESULT STDMETHODCALLTYPE
CShellLink::GetWorkingDirectory(LPWSTR pszDir
, INT cchMaxPath
)
1586 TRACE("(%p)->(%p len %u)\n", this, pszDir
, cchMaxPath
);
1592 lstrcpynW(pszDir
, m_sWorkDir
, cchMaxPath
);
1597 HRESULT STDMETHODCALLTYPE
CShellLink::SetWorkingDirectory(LPCWSTR pszDir
)
1599 TRACE("(%p)->(dir=%s)\n", this, debugstr_w(pszDir
));
1601 HeapFree(GetProcessHeap(), 0, m_sWorkDir
);
1604 m_sWorkDir
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1605 (wcslen(pszDir
) + 1) * sizeof(WCHAR
));
1607 return E_OUTOFMEMORY
;
1608 wcscpy(m_sWorkDir
, pszDir
);
1618 HRESULT STDMETHODCALLTYPE
CShellLink::GetArguments(LPWSTR pszArgs
, INT cchMaxPath
)
1620 TRACE("(%p)->(%p len=%u)\n", this, pszArgs
, cchMaxPath
);
1626 lstrcpynW(pszArgs
, m_sArgs
, cchMaxPath
);
1631 HRESULT STDMETHODCALLTYPE
CShellLink::SetArguments(LPCWSTR pszArgs
)
1633 TRACE("(%p)->(args=%s)\n", this, debugstr_w(pszArgs
));
1635 HeapFree(GetProcessHeap(), 0, m_sArgs
);
1638 m_sArgs
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1639 (wcslen(pszArgs
) + 1) * sizeof(WCHAR
));
1641 return E_OUTOFMEMORY
;
1643 wcscpy(m_sArgs
, pszArgs
);
1653 HRESULT STDMETHODCALLTYPE
CShellLink::GetIconLocation(LPWSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1655 TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath
, cchIconPath
, piIcon
);
1662 /* Update the original icon path location */
1663 if (m_Header
.dwFlags
& SLDF_HAS_EXP_ICON_SZ
)
1665 WCHAR szPath
[MAX_PATH
];
1667 /* Search for an icon environment block */
1668 LPEXP_SZ_LINK pInfo
;
1669 pInfo
= (LPEXP_SZ_LINK
)SHFindDataBlock(m_pDBList
, EXP_SZ_ICON_SIG
);
1670 if (pInfo
&& (pInfo
->cbSize
== sizeof(*pInfo
)))
1672 m_Header
.dwFlags
&= ~SLDF_HAS_ICONLOCATION
;
1673 HeapFree(GetProcessHeap(), 0, m_sIcoPath
);
1676 SHExpandEnvironmentStringsW(pInfo
->szwTarget
, szPath
, _countof(szPath
));
1678 m_sIcoPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1679 (wcslen(szPath
) + 1) * sizeof(WCHAR
));
1681 return E_OUTOFMEMORY
;
1683 wcscpy(m_sIcoPath
, szPath
);
1684 m_Header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1690 *piIcon
= m_Header
.nIconIndex
;
1693 lstrcpynW(pszIconPath
, m_sIcoPath
, cchIconPath
);
1698 static HRESULT
SHELL_PidlGetIconLocationW(IShellFolder
* psf
, LPCITEMIDLIST pidl
,
1699 UINT uFlags
, PWSTR pszIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
1701 LPCITEMIDLIST pidlLast
;
1703 HRESULT hr
= SHBindToParent(pidl
, IID_PPV_ARG(IShellFolder
, &psf
), &pidlLast
);
1706 CComPtr
<IExtractIconW
> pei
;
1708 hr
= psf
->GetUIObjectOf(0, 1, &pidlLast
, IID_NULL_PPV_ARG(IExtractIconW
, &pei
));
1710 hr
= pei
->GetIconLocation(uFlags
, pszIconFile
, cchMax
, piIndex
, pwFlags
);
1718 HRESULT STDMETHODCALLTYPE
CShellLink::GetIconLocation(UINT uFlags
, PWSTR pszIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
1721 * It is possible for a shell link to point to another shell link,
1722 * and in particular there is the possibility to point to itself.
1723 * Now, suppose we ask such a link to retrieve its associated icon.
1724 * This function would be called, and due to COM would be called again
1725 * recursively. To solve this issue, we forbid calling GetIconLocation()
1726 * with GIL_FORSHORTCUT set in uFlags, as done by Windows (shown by tests).
1728 if (uFlags
& GIL_FORSHORTCUT
)
1729 return E_INVALIDARG
;
1732 * Now, we set GIL_FORSHORTCUT so that: i) we allow the icon extractor
1733 * of the target to give us a suited icon, and ii) we protect ourselves
1734 * against recursive call.
1736 uFlags
|= GIL_FORSHORTCUT
;
1738 if (m_pPidl
|| m_sPath
)
1740 CComPtr
<IShellFolder
> pdsk
;
1742 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1745 /* first look for an icon using the PIDL (if present) */
1747 hr
= SHELL_PidlGetIconLocationW(pdsk
, m_pPidl
, uFlags
, pszIconFile
, cchMax
, piIndex
, pwFlags
);
1751 #if 0 // FIXME: Analyse further whether this is needed...
1752 /* if we couldn't find an icon yet, look for it using the file system path */
1753 if (FAILED(hr
) && m_sPath
)
1757 /* LPITEMIDLIST pidl = ILCreateFromPathW(sPath); */
1758 hr
= pdsk
->ParseDisplayName(0, NULL
, m_sPath
, NULL
, &pidl
, NULL
);
1761 hr
= SHELL_PidlGetIconLocationW(pdsk
, pidl
, uFlags
, pszIconFile
, cchMax
, piIndex
, pwFlags
);
1773 HRESULT STDMETHODCALLTYPE
CShellLink::Extract(PCWSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
1780 /* Extends the functionality of PathUnExpandEnvStringsW */
1781 BOOL
PathFullyUnExpandEnvStringsW(
1782 _In_ LPCWSTR pszPath
,
1783 _Out_ LPWSTR pszBuf
,
1786 BOOL Ret
= FALSE
; // Set to TRUE as soon as PathUnExpandEnvStrings starts unexpanding.
1791 while (*pszPath
&& cchBuf
> 0)
1793 /* Attempt unexpanding the path */
1794 res
= PathUnExpandEnvStringsW(pszPath
, pszBuf
, cchBuf
);
1797 /* The unexpansion failed. Try to find a path delimiter. */
1798 p
= wcspbrk(pszPath
, L
" /\\:*?\"<>|%");
1799 if (!p
) /* None found, we will copy the remaining path */
1800 p
= pszPath
+ wcslen(pszPath
);
1801 else /* Found one, we will copy the delimiter and skip it */
1803 /* If we overflow, we cannot unexpand more, so return FALSE */
1804 if (p
- pszPath
>= cchBuf
)
1805 return FALSE
; // *pszBuf = L'\0';
1807 /* Copy the untouched portion of path up to the delimiter, included */
1808 wcsncpy(pszBuf
, pszPath
, p
- pszPath
);
1809 pszBuf
[p
- pszPath
] = L
'\0'; // NULL-terminate
1811 /* Advance the pointers and decrease the remaining buffer size */
1812 cchBuf
-= (p
- pszPath
);
1813 pszBuf
+= (p
- pszPath
);
1814 pszPath
+= (p
- pszPath
);
1819 * The unexpansion succeeded. Skip the unexpanded part by trying
1820 * to find where the original path and the unexpanded string
1822 * NOTE: An alternative(?) would be to stop also at the last
1823 * path delimiter encountered in the loop (i.e. would be the
1824 * first path delimiter in the strings).
1829 * The algorithm starts at the end of the strings and loops back
1830 * while the characters are equal, until it finds a discrepancy.
1832 p
= pszPath
+ wcslen(pszPath
);
1833 q
= pszBuf
+ wcslen(pszBuf
); // This wcslen should be < cchBuf
1834 while ((*p
== *q
) && (p
> pszPath
) && (q
> pszBuf
))
1838 /* Skip discrepancy */
1841 /* Advance the pointers and decrease the remaining buffer size */
1842 cchBuf
-= (q
- pszBuf
);
1854 HRESULT STDMETHODCALLTYPE
CShellLink::SetIconLocation(LPCWSTR pszIconPath
, INT iIcon
)
1856 HRESULT hr
= E_FAIL
;
1857 WCHAR szUnExpIconPath
[MAX_PATH
];
1859 TRACE("(%p)->(path=%s iicon=%u)\n", this, debugstr_w(pszIconPath
), iIcon
);
1863 /* Try to fully unexpand the icon path */
1866 * Check whether the user-given file path contains unexpanded
1867 * environment variables. If so, create a target environment block.
1868 * Note that in this block we will store the user-given path.
1869 * It will contain the unexpanded environment variables, but
1870 * it can also contain already expanded path that the user does
1871 * not want to see them unexpanded (e.g. so that they always
1872 * refer to the same place even if the would-be corresponding
1873 * environment variable could change).
1875 // FIXME: http://stackoverflow.com/questions/2976489/ishelllinkseticonlocation-translates-my-icon-path-into-program-files-which-i
1876 // if (PathFullyUnExpandEnvStringsW(pszIconPath, szUnExpIconPath, _countof(szUnExpIconPath)))
1877 SHExpandEnvironmentStringsW(pszIconPath
, szUnExpIconPath
, _countof(szUnExpIconPath
));
1878 if (wcscmp(pszIconPath
, szUnExpIconPath
) != 0)
1880 /* Unexpansion succeeded, so we need an icon environment block */
1882 LPEXP_SZ_LINK pInfo
;
1884 pInfo
= (LPEXP_SZ_LINK
)SHFindDataBlock(m_pDBList
, EXP_SZ_ICON_SIG
);
1887 /* Make sure that the size of the structure is valid */
1888 if (pInfo
->cbSize
!= sizeof(*pInfo
))
1890 ERR("Ooops. This structure is not as expected...\n");
1892 /* Invalid structure, remove it altogether */
1893 m_Header
.dwFlags
&= ~SLDF_HAS_EXP_ICON_SZ
;
1894 RemoveDataBlock(EXP_SZ_ICON_SIG
);
1896 /* Reset the pointer and go use the static buffer */
1902 /* Use the static buffer */
1904 buffer
.cbSize
= sizeof(buffer
);
1905 buffer
.dwSignature
= EXP_SZ_ICON_SIG
;
1908 lstrcpynW(pInfo
->szwTarget
, szUnExpIconPath
, _countof(pInfo
->szwTarget
));
1909 WideCharToMultiByte(CP_ACP
, 0, szUnExpIconPath
, -1,
1910 pInfo
->szTarget
, _countof(pInfo
->szTarget
), NULL
, NULL
);
1913 if (pInfo
== &buffer
)
1914 hr
= AddDataBlock(pInfo
);
1916 m_Header
.dwFlags
|= SLDF_HAS_EXP_ICON_SZ
;
1920 /* Unexpansion failed, so we need to remove any icon environment block */
1921 m_Header
.dwFlags
&= ~SLDF_HAS_EXP_ICON_SZ
;
1922 RemoveDataBlock(EXP_SZ_ICON_SIG
);
1926 /* Store the original icon path location (this one may contain unexpanded environment strings) */
1929 m_Header
.dwFlags
&= ~SLDF_HAS_ICONLOCATION
;
1930 HeapFree(GetProcessHeap(), 0, m_sIcoPath
);
1933 m_sIcoPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1934 (wcslen(pszIconPath
) + 1) * sizeof(WCHAR
));
1936 return E_OUTOFMEMORY
;
1938 wcscpy(m_sIcoPath
, pszIconPath
);
1939 m_Header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1944 m_Header
.nIconIndex
= iIcon
;
1950 HRESULT STDMETHODCALLTYPE
CShellLink::SetRelativePath(LPCWSTR pszPathRel
, DWORD dwReserved
)
1952 TRACE("(%p)->(path=%s %x)\n", this, debugstr_w(pszPathRel
), dwReserved
);
1954 HeapFree(GetProcessHeap(), 0, m_sPathRel
);
1957 m_sPathRel
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1958 (wcslen(pszPathRel
) + 1) * sizeof(WCHAR
));
1960 return E_OUTOFMEMORY
;
1961 wcscpy(m_sPathRel
, pszPathRel
);
1968 return ShellLink_UpdatePath(m_sPathRel
, m_sPath
, m_sWorkDir
, &m_sPath
);
1971 static LPWSTR
GetAdvertisedArg(LPCWSTR str
)
1976 LPCWSTR p
= wcschr(str
, L
':');
1980 DWORD len
= p
- str
;
1981 LPWSTR ret
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * (len
+ 1));
1985 memcpy(ret
, str
, sizeof(WCHAR
)*len
);
1990 HRESULT
CShellLink::WriteAdvertiseInfo(LPCWSTR string
, DWORD dwSig
)
1992 EXP_DARWIN_LINK buffer
;
1993 LPEXP_DARWIN_LINK pInfo
;
1995 if ( (dwSig
!= EXP_DARWIN_ID_SIG
)
1996 #if (NTDDI_VERSION < NTDDI_LONGHORN)
1997 && (dwSig
!= EXP_LOGO3_ID_SIG
)
2001 return E_INVALIDARG
;
2007 pInfo
= (LPEXP_DARWIN_LINK
)SHFindDataBlock(m_pDBList
, dwSig
);
2010 /* Make sure that the size of the structure is valid */
2011 if (pInfo
->dbh
.cbSize
!= sizeof(*pInfo
))
2013 ERR("Ooops. This structure is not as expected...\n");
2015 /* Invalid structure, remove it altogether */
2016 if (dwSig
== EXP_DARWIN_ID_SIG
)
2017 m_Header
.dwFlags
&= ~SLDF_HAS_DARWINID
;
2018 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2019 else if (dwSig
== EXP_LOGO3_ID_SIG
)
2020 m_Header
.dwFlags
&= ~SLDF_HAS_LOGO3ID
;
2022 RemoveDataBlock(dwSig
);
2024 /* Reset the pointer and go use the static buffer */
2030 /* Use the static buffer */
2032 buffer
.dbh
.cbSize
= sizeof(buffer
);
2033 buffer
.dbh
.dwSignature
= dwSig
;
2036 lstrcpynW(pInfo
->szwDarwinID
, string
, _countof(pInfo
->szwDarwinID
));
2037 WideCharToMultiByte(CP_ACP
, 0, string
, -1,
2038 pInfo
->szDarwinID
, _countof(pInfo
->szDarwinID
), NULL
, NULL
);
2041 if (pInfo
== &buffer
)
2042 hr
= AddDataBlock(pInfo
);
2045 if (dwSig
== EXP_DARWIN_ID_SIG
)
2046 m_Header
.dwFlags
|= SLDF_HAS_DARWINID
;
2047 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2048 else if (dwSig
== EXP_LOGO3_ID_SIG
)
2049 m_Header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
2056 HRESULT
CShellLink::SetAdvertiseInfo(LPCWSTR str
)
2059 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2064 /**/sProduct
= sComponent
= NULL
;/**/
2068 /* each segment must start with two colons */
2069 if (str
[0] != ':' || str
[1] != ':')
2072 /* the last segment is just two colons */
2077 /* there must be a colon straight after a guid */
2078 p
= wcschr(str
, L
':');
2085 /* get the guid, and check if it's validly formatted */
2086 memcpy(szGuid
, str
, sizeof(WCHAR
)*len
);
2089 hr
= CLSIDFromString(szGuid
, &guid
);
2094 /* match it up to a guid that we care about */
2095 if (IsEqualGUID(guid
, SHELL32_AdvtShortcutComponent
) && !szComponent
)
2096 szComponent
= str
; /* Darwin */
2097 else if (IsEqualGUID(guid
, SHELL32_AdvtShortcutProduct
) && !szProduct
)
2098 szProduct
= str
; /* Logo3 */
2102 /* skip to the next field */
2103 str
= wcschr(str
, L
':');
2108 /* we have to have a component for an advertised shortcut */
2112 szComponent
= GetAdvertisedArg(szComponent
);
2113 szProduct
= GetAdvertisedArg(szProduct
);
2115 hr
= WriteAdvertiseInfo(szComponent
, EXP_DARWIN_ID_SIG
);
2118 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2119 hr
= WriteAdvertiseInfo(szProduct
, EXP_LOGO3_ID_SIG
);
2124 HeapFree(GetProcessHeap(), 0, (PVOID
)szComponent
);
2125 HeapFree(GetProcessHeap(), 0, (PVOID
)szProduct
);
2127 if (TRACE_ON(shell
))
2129 GetAdvertiseInfo(&sComponent
, EXP_DARWIN_ID_SIG
);
2130 TRACE("Component = %s\n", debugstr_w(sComponent
));
2131 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2132 GetAdvertiseInfo(&sProduct
, EXP_LOGO3_ID_SIG
);
2133 TRACE("Product = %s\n", debugstr_w(sProduct
));
2141 * Since the real PathResolve (from Wine) is unimplemented at the moment,
2142 * we use this local implementation, until a better one is written (using
2143 * code parts of the SHELL_xxx helpers in Wine's shellpath.c).
2145 static BOOL
HACKISH_PathResolve(
2146 IN OUT PWSTR pszPath
,
2147 IN PZPCWSTR dirs OPTIONAL
,
2150 // FIXME: This is unimplemented!!!
2151 FIXME("PathResolve() is UNIMPLEMENTED, using HACKISH_PathResolve() instead!\n");
2153 return PathResolve(pszPath
, dirs
, fFlags
);
2155 BOOL Success
= FALSE
;
2157 LPWSTR fname
= NULL
;
2158 WCHAR szPath
[MAX_PATH
];
2160 /* First, search for a valid existing path */
2162 // NOTE: See also: SHELL_FindExecutable()
2165 * List of extensions searched for, by PathResolve with the flag
2166 * PRF_TRYPROGRAMEXTENSIONS == PRF_EXECUTABLE | PRF_VERIFYEXISTS set,
2167 * according to MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/bb776478(v=vs.85).aspx
2169 static PCWSTR Extensions
[] = {L
".pif", L
".com", L
".bat", L
".cmd", L
".lnk", L
".exe", NULL
};
2170 #define LNK_EXT_INDEX 4 // ".lnk" has index 4 in the array above
2173 * Start at the beginning of the list if PRF_EXECUTABLE is set, otherwise
2174 * just use the last element 'NULL' (no extension checking).
2176 i
= ((fFlags
& PRF_EXECUTABLE
) ? 0 : _countof(Extensions
) - 1);
2177 for (; i
< _countof(Extensions
); ++i
)
2179 /* Ignore shell links ".lnk" if needed */
2180 if ((fFlags
& PRF_DONTFINDLNK
) && (i
== LNK_EXT_INDEX
))
2183 Success
= (SearchPathW(NULL
, pszPath
, Extensions
[i
],
2184 _countof(szPath
), szPath
, NULL
) != 0);
2187 ERR("SearchPathW(pszPath = '%S') failed\n", pszPath
);
2191 ERR("SearchPathW(pszPath = '%S', szPath = '%S') succeeded\n", pszPath
, szPath
);
2198 ERR("SearchPathW(pszPath = '%S') failed\n", pszPath
);
2200 /* We failed, try with PathFindOnPath, as explained by MSDN */
2201 // Success = PathFindOnPathW(pszPath, dirs);
2202 StringCchCopyW(szPath
, _countof(szPath
), pszPath
);
2203 Success
= PathFindOnPathW(szPath
, dirs
);
2206 ERR("PathFindOnPathW(pszPath = '%S') failed\n", pszPath
);
2208 /* We failed again, fall back to building a possible non-existing path */
2209 if (!GetFullPathNameW(pszPath
, _countof(szPath
), szPath
, &fname
))
2211 ERR("GetFullPathNameW(pszPath = '%S') failed\n", pszPath
);
2215 Success
= PathFileExistsW(szPath
);
2217 ERR("PathFileExistsW(szPath = '%S') failed\n", szPath
);
2219 /******************************************************/
2220 /* Question: Why this line is needed only for files?? */
2221 if (fname
&& (_wcsicmp(pszPath
, fname
) == 0))
2223 /******************************************************/
2227 ERR("PathFindOnPathW(pszPath = '%S' ==> '%S') succeeded\n", pszPath
, szPath
);
2231 /* Copy back the results to the caller */
2232 StringCchCopyW(pszPath
, MAX_PATH
, szPath
);
2235 * Since the called functions always checked whether the file path existed,
2236 * we do not need to redo a final check: we can use instead the cached
2237 * result in 'Success'.
2239 return ((fFlags
& PRF_VERIFYEXISTS
) ? Success
: TRUE
);
2243 HRESULT
CShellLink::SetTargetFromPIDLOrPath(LPCITEMIDLIST pidl
, LPCWSTR pszFile
)
2246 LPITEMIDLIST pidlNew
= NULL
;
2247 WCHAR szPath
[MAX_PATH
];
2250 * Not both 'pidl' and 'pszFile' should be set.
2251 * But either one or both can be NULL.
2253 if (pidl
&& pszFile
)
2258 /* Clone the PIDL */
2259 pidlNew
= ILClone(pidl
);
2265 /* Build a PIDL for this path target */
2266 hr
= SHILCreateFromPathW(pszFile
, &pidlNew
, NULL
);
2269 /* This failed, try to resolve the path, then create a simple PIDL */
2271 StringCchCopyW(szPath
, _countof(szPath
), pszFile
);
2272 // FIXME: Because PathResolve is unimplemented, we use our hackish implementation!
2273 HACKISH_PathResolve(szPath
, NULL
, PRF_TRYPROGRAMEXTENSIONS
);
2275 pidlNew
= SHSimpleIDListFromPathW(szPath
);
2276 /******************************************************/
2277 /* Question: Why this line is needed only for files?? */
2278 hr
= (*szPath
? S_OK
: E_INVALIDARG
); // S_FALSE
2279 /******************************************************/
2282 // else if (!pidl && !pszFile) { pidlNew = NULL; hr = S_OK; }
2289 if (SHGetPathFromIDListW(pidlNew
, szPath
))
2293 // TODO: Fully update link info, tracker, file attribs...
2302 /* Update the cached path (for link info) */
2303 ShellLink_GetVolumeInfo(pszFile
, &volume
);
2304 m_sPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
2305 (wcslen(pszFile
) + 1) * sizeof(WCHAR
));
2307 return E_OUTOFMEMORY
;
2308 wcscpy(m_sPath
, pszFile
);
2314 HRESULT STDMETHODCALLTYPE
CShellLink::SetPath(LPCWSTR pszFile
)
2316 LPWSTR unquoted
= NULL
;
2319 TRACE("(%p)->(path=%s)\n", this, debugstr_w(pszFile
));
2322 return E_INVALIDARG
;
2325 * Allow upgrading Logo3 shortcuts (m_Header.dwFlags & SLDF_HAS_LOGO3ID),
2326 * but forbid upgrading Darwin ones.
2328 if (m_Header
.dwFlags
& SLDF_HAS_DARWINID
)
2331 /* quotes at the ends of the string are stripped */
2332 SIZE_T len
= wcslen(pszFile
);
2333 if (pszFile
[0] == L
'"' && pszFile
[len
-1] == L
'"')
2335 unquoted
= strdupW(pszFile
);
2336 PathUnquoteSpacesW(unquoted
);
2340 /* any other quote marks are invalid */
2341 if (wcschr(pszFile
, L
'"'))
2347 /* Clear the cached path */
2348 HeapFree(GetProcessHeap(), 0, m_sPath
);
2351 /* Check for an advertised target (Logo3 or Darwin) */
2352 if (SetAdvertiseInfo(pszFile
) != S_OK
)
2354 /* This is not an advertised target, but a regular path */
2355 WCHAR szPath
[MAX_PATH
];
2358 * Check whether the user-given file path contains unexpanded
2359 * environment variables. If so, create a target environment block.
2360 * Note that in this block we will store the user-given path.
2361 * It will contain the unexpanded environment variables, but
2362 * it can also contain already expanded path that the user does
2363 * not want to see them unexpanded (e.g. so that they always
2364 * refer to the same place even if the would-be corresponding
2365 * environment variable could change).
2368 SHExpandEnvironmentStringsW(pszFile
, szPath
, _countof(szPath
));
2372 if (*pszFile
&& (wcscmp(pszFile
, szPath
) != 0))
2375 * The user-given file path contains unexpanded environment
2376 * variables, so we need a target environment block.
2379 LPEXP_SZ_LINK pInfo
;
2381 pInfo
= (LPEXP_SZ_LINK
)SHFindDataBlock(m_pDBList
, EXP_SZ_LINK_SIG
);
2384 /* Make sure that the size of the structure is valid */
2385 if (pInfo
->cbSize
!= sizeof(*pInfo
))
2387 ERR("Ooops. This structure is not as expected...\n");
2389 /* Invalid structure, remove it altogether */
2390 m_Header
.dwFlags
&= ~SLDF_HAS_EXP_SZ
;
2391 RemoveDataBlock(EXP_SZ_LINK_SIG
);
2393 /* Reset the pointer and go use the static buffer */
2399 /* Use the static buffer */
2401 buffer
.cbSize
= sizeof(buffer
);
2402 buffer
.dwSignature
= EXP_SZ_LINK_SIG
;
2405 lstrcpynW(pInfo
->szwTarget
, pszFile
, _countof(pInfo
->szwTarget
));
2406 WideCharToMultiByte(CP_ACP
, 0, pszFile
, -1,
2407 pInfo
->szTarget
, _countof(pInfo
->szTarget
), NULL
, NULL
);
2410 if (pInfo
== &buffer
)
2411 hr
= AddDataBlock(pInfo
);
2413 m_Header
.dwFlags
|= SLDF_HAS_EXP_SZ
;
2415 /* Now, make pszFile point to the expanded buffer */
2421 * The user-given file path does not contain unexpanded environment
2422 * variables, so we need to remove any target environment block.
2424 m_Header
.dwFlags
&= ~SLDF_HAS_EXP_SZ
;
2425 RemoveDataBlock(EXP_SZ_LINK_SIG
);
2427 /* pszFile points to the user path */
2430 /* Set the target */
2431 hr
= SetTargetFromPIDLOrPath(NULL
, pszFile
);
2437 HeapFree(GetProcessHeap(), 0, unquoted
);
2441 HRESULT STDMETHODCALLTYPE
CShellLink::AddDataBlock(void* pDataBlock
)
2443 if (SHAddDataBlock(&m_pDBList
, (DATABLOCK_HEADER
*)pDataBlock
))
2451 HRESULT STDMETHODCALLTYPE
CShellLink::CopyDataBlock(DWORD dwSig
, void** ppDataBlock
)
2453 DATABLOCK_HEADER
* pBlock
;
2456 TRACE("%p %08x %p\n", this, dwSig
, ppDataBlock
);
2458 *ppDataBlock
= NULL
;
2460 pBlock
= SHFindDataBlock(m_pDBList
, dwSig
);
2463 ERR("unknown datablock %08x (not found)\n", dwSig
);
2467 pDataBlock
= LocalAlloc(LMEM_ZEROINIT
, pBlock
->cbSize
);
2469 return E_OUTOFMEMORY
;
2471 CopyMemory(pDataBlock
, pBlock
, pBlock
->cbSize
);
2473 *ppDataBlock
= pDataBlock
;
2477 HRESULT STDMETHODCALLTYPE
CShellLink::RemoveDataBlock(DWORD dwSig
)
2479 if (SHRemoveDataBlock(&m_pDBList
, dwSig
))
2487 HRESULT STDMETHODCALLTYPE
CShellLink::GetFlags(DWORD
*pdwFlags
)
2489 TRACE("%p %p\n", this, pdwFlags
);
2490 *pdwFlags
= m_Header
.dwFlags
;
2494 HRESULT STDMETHODCALLTYPE
CShellLink::SetFlags(DWORD dwFlags
)
2497 m_Header
.dwFlags
= dwFlags
;
2506 /**************************************************************************
2507 * CShellLink implementation of IShellExtInit::Initialize()
2509 * Loads the shelllink from the dataobject the shell is pointing to.
2511 HRESULT STDMETHODCALLTYPE
CShellLink::Initialize(LPCITEMIDLIST pidlFolder
, IDataObject
*pdtobj
, HKEY hkeyProgID
)
2513 TRACE("%p %p %p %p\n", this, pidlFolder
, pdtobj
, hkeyProgID
);
2519 format
.cfFormat
= CF_HDROP
;
2521 format
.dwAspect
= DVASPECT_CONTENT
;
2523 format
.tymed
= TYMED_HGLOBAL
;
2526 HRESULT hr
= pdtobj
->GetData(&format
, &stgm
);
2530 UINT count
= DragQueryFileW((HDROP
)stgm
.hGlobal
, -1, NULL
, 0);
2533 count
= DragQueryFileW((HDROP
)stgm
.hGlobal
, 0, NULL
, 0);
2535 LPWSTR path
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
));
2538 count
= DragQueryFileW((HDROP
)stgm
.hGlobal
, 0, path
, count
);
2540 HeapFree(GetProcessHeap(), 0, path
);
2543 ReleaseStgMedium(&stgm
);
2548 HRESULT STDMETHODCALLTYPE
CShellLink::QueryContextMenu(HMENU hMenu
, UINT indexMenu
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2552 TRACE("%p %p %u %u %u %u\n", this,
2553 hMenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2556 return E_INVALIDARG
;
2559 if (!LoadStringW(shell32_hInstance
, IDS_OPEN_VERB
, wszOpen
, _countof(wszOpen
)))
2563 ZeroMemory(&mii
, sizeof(mii
));
2564 mii
.cbSize
= sizeof(mii
);
2565 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2566 mii
.dwTypeData
= wszOpen
;
2567 mii
.cch
= wcslen(mii
.dwTypeData
);
2568 mii
.wID
= idCmdFirst
+ id
++;
2569 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2570 mii
.fType
= MFT_STRING
;
2571 if (!InsertMenuItemW(hMenu
, indexMenu
, TRUE
, &mii
))
2575 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, id
);
2578 HRESULT STDMETHODCALLTYPE
CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici
)
2583 TRACE("%p %p\n", this, lpici
);
2585 if (lpici
->cbSize
< sizeof(CMINVOKECOMMANDINFO
))
2586 return E_INVALIDARG
;
2588 // NOTE: We could use lpici->hwnd (certainly in case lpici->fMask doesn't contain CMIC_MASK_FLAG_NO_UI)
2589 // as the parent window handle... ?
2590 /* FIXME: get using interface set from IObjectWithSite?? */
2591 // NOTE: We might need an extended version of Resolve that provides us with paths...
2592 HRESULT hr
= Resolve(lpici
->hwnd
, 0);
2595 TRACE("failed to resolve component with error 0x%08x", hr
);
2599 path
= strdupW(m_sPath
);
2601 if ( lpici
->cbSize
== sizeof(CMINVOKECOMMANDINFOEX
) &&
2602 (lpici
->fMask
& CMIC_MASK_UNICODE
) )
2604 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
)lpici
;
2608 len
+= wcslen(m_sArgs
);
2609 if (iciex
->lpParametersW
)
2610 len
+= wcslen(iciex
->lpParametersW
);
2612 args
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2615 wcscat(args
, m_sArgs
);
2616 if (iciex
->lpParametersW
)
2619 wcscat(args
, iciex
->lpParametersW
);
2622 else if (m_sArgs
!= NULL
)
2624 args
= strdupW(m_sArgs
);
2627 SHELLEXECUTEINFOW sei
;
2628 ZeroMemory(&sei
, sizeof(sei
));
2629 sei
.cbSize
= sizeof(sei
);
2630 sei
.fMask
= SEE_MASK_HASLINKNAME
| SEE_MASK_UNICODE
|
2631 (lpici
->fMask
& (SEE_MASK_NOASYNC
| SEE_MASK_ASYNCOK
| SEE_MASK_FLAG_NO_UI
));
2633 sei
.lpClass
= m_sLinkPath
;
2634 sei
.nShow
= m_Header
.nShowCommand
;
2635 sei
.lpDirectory
= m_sWorkDir
;
2636 sei
.lpParameters
= args
;
2637 sei
.lpVerb
= L
"open";
2639 // HACK for ShellExecuteExW
2640 if (m_sPath
&& wcsstr(m_sPath
, L
".cpl"))
2641 sei
.lpVerb
= L
"cplopen";
2643 if (ShellExecuteExW(&sei
))
2648 HeapFree(GetProcessHeap(), 0, args
);
2649 HeapFree(GetProcessHeap(), 0, path
);
2654 HRESULT STDMETHODCALLTYPE
CShellLink::GetCommandString(UINT_PTR idCmd
, UINT uType
, UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2656 FIXME("%p %lu %u %p %p %u\n", this, idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2660 INT_PTR CALLBACK
ExtendedShortcutProc(HWND hwndDlg
, UINT uMsg
,
2661 WPARAM wParam
, LPARAM lParam
)
2668 HWND hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2669 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2674 HWND hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2675 if (LOWORD(wParam
) == IDOK
)
2677 if (SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2678 EndDialog(hwndDlg
, 1);
2680 EndDialog(hwndDlg
, 0);
2682 else if (LOWORD(wParam
) == IDCANCEL
)
2684 EndDialog(hwndDlg
, -1);
2686 else if (LOWORD(wParam
) == 14000)
2688 if (SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2689 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2691 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2700 SHOpenFolderAndSelectItems(LPITEMIDLIST pidlFolder
,
2702 PCUITEMID_CHILD_ARRAY apidl
,
2705 /**************************************************************************
2706 * SH_GetTargetTypeByPath
2708 * Function to get target type by passing full path to it
2710 LPWSTR
SH_GetTargetTypeByPath(LPCWSTR lpcwFullPath
)
2713 static WCHAR wszBuf
[MAX_PATH
];
2715 /* Get file information */
2717 if (!SHGetFileInfoW(lpcwFullPath
, 0, &fi
, sizeof(fi
), SHGFI_TYPENAME
| SHGFI_USEFILEATTRIBUTES
))
2719 ERR("SHGetFileInfoW failed for %ls (%lu)\n", lpcwFullPath
, GetLastError());
2720 fi
.szTypeName
[0] = L
'\0';
2724 pwszExt
= PathFindExtensionW(lpcwFullPath
);
2727 if (!fi
.szTypeName
[0])
2729 /* The file type is unknown, so default to string "FileExtension File" */
2730 size_t cchRemaining
= 0;
2731 LPWSTR pwszEnd
= NULL
;
2733 StringCchPrintfExW(wszBuf
, _countof(wszBuf
), &pwszEnd
, &cchRemaining
, 0, L
"%s ", pwszExt
+ 1);
2736 StringCbPrintfW(wszBuf
, sizeof(wszBuf
), L
"%s (%s)", fi
.szTypeName
, pwszExt
); /* Update file type */
2742 /**************************************************************************
2743 * SH_ShellLinkDlgProc
2745 * dialog proc of the shortcut property dialog
2748 INT_PTR CALLBACK
CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2750 CShellLink
*pThis
= reinterpret_cast<CShellLink
*>(GetWindowLongPtr(hwndDlg
, DWLP_USER
));
2756 LPPROPSHEETPAGEW ppsp
= (LPPROPSHEETPAGEW
)lParam
;
2760 TRACE("ShellLink_DlgProc (WM_INITDIALOG hwnd %p lParam %p ppsplParam %x)\n", hwndDlg
, lParam
, ppsp
->lParam
);
2762 pThis
= reinterpret_cast<CShellLink
*>(ppsp
->lParam
);
2763 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pThis
);
2765 TRACE("m_sArgs: %S sComponent: %S m_sDescription: %S m_sIcoPath: %S m_sPath: %S m_sPathRel: %S sProduct: %S m_sWorkDir: %S\n", pThis
->m_sArgs
, pThis
->sComponent
, pThis
->m_sDescription
,
2766 pThis
->m_sIcoPath
, pThis
->m_sPath
, pThis
->m_sPathRel
, pThis
->sProduct
, pThis
->m_sWorkDir
);
2768 /* Get file information */
2769 // FIXME! FIXME! Shouldn't we use pThis->m_sIcoPath, pThis->m_Header.nIconIndex instead???
2771 if (!SHGetFileInfoW(pThis
->m_sLinkPath
, 0, &fi
, sizeof(fi
), SHGFI_TYPENAME
|SHGFI_ICON
))
2773 ERR("SHGetFileInfoW failed for %ls (%lu)\n", pThis
->m_sLinkPath
, GetLastError());
2774 fi
.szTypeName
[0] = L
'\0';
2778 if (fi
.hIcon
) // TODO: destroy icon
2779 SendDlgItemMessageW(hwndDlg
, 14000, STM_SETICON
, (WPARAM
)fi
.hIcon
, 0);
2781 ERR("ExtractIconW failed %ls %u\n", pThis
->m_sIcoPath
, pThis
->m_Header
.nIconIndex
);
2785 SetDlgItemTextW(hwndDlg
, 14005, SH_GetTargetTypeByPath(pThis
->m_sPath
));
2787 /* target location */
2788 if (pThis
->m_sWorkDir
)
2789 SetDlgItemTextW(hwndDlg
, 14007, PathFindFileName(pThis
->m_sWorkDir
));
2794 WCHAR newpath
[2*MAX_PATH
] = L
"\0";
2795 if (wcschr(pThis
->m_sPath
, ' '))
2796 StringCchPrintfExW(newpath
, _countof(newpath
), NULL
, NULL
, 0, L
"\"%ls\"", pThis
->m_sPath
);
2798 StringCchCopyExW(newpath
, _countof(newpath
), pThis
->m_sPath
, NULL
, NULL
, 0);
2800 if (pThis
->m_sArgs
&& pThis
->m_sArgs
[0])
2802 StringCchCatW(newpath
, _countof(newpath
), L
" ");
2803 StringCchCatW(newpath
, _countof(newpath
), pThis
->m_sArgs
);
2805 SetDlgItemTextW(hwndDlg
, 14009, newpath
);
2808 if (pThis
->m_sWorkDir
)
2809 SetDlgItemTextW(hwndDlg
, 14011, pThis
->m_sWorkDir
);
2812 if (pThis
->m_sDescription
)
2813 SetDlgItemTextW(hwndDlg
, 14019, pThis
->m_sDescription
);
2819 LPPSHNOTIFY lppsn
= (LPPSHNOTIFY
)lParam
;
2820 if (lppsn
->hdr
.code
== PSN_APPLY
)
2822 WCHAR wszBuf
[MAX_PATH
];
2823 /* set working directory */
2824 GetDlgItemTextW(hwndDlg
, 14011, wszBuf
, _countof(wszBuf
));
2825 pThis
->SetWorkingDirectory(wszBuf
);
2826 /* set link destination */
2827 GetDlgItemTextW(hwndDlg
, 14009, wszBuf
, _countof(wszBuf
));
2828 LPWSTR lpszArgs
= NULL
;
2829 LPWSTR unquoted
= strdupW(wszBuf
);
2830 StrTrimW(unquoted
, L
" ");
2831 if (!PathFileExistsW(unquoted
))
2833 lpszArgs
= PathGetArgsW(unquoted
);
2834 PathRemoveArgsW(unquoted
);
2835 StrTrimW(lpszArgs
, L
" ");
2837 if (unquoted
[0] == '"' && unquoted
[wcslen(unquoted
)-1] == '"')
2838 PathUnquoteSpacesW(unquoted
);
2841 WCHAR
*pwszExt
= PathFindExtensionW(unquoted
);
2842 if (!wcsicmp(pwszExt
, L
".lnk"))
2844 // FIXME load localized error msg
2845 MessageBoxW(hwndDlg
, L
"You cannot create a link to a shortcut", L
"Error", MB_ICONERROR
);
2846 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2850 if (!PathFileExistsW(unquoted
))
2852 //FIXME load localized error msg
2853 MessageBoxW(hwndDlg
, L
"The specified file name in the target box is invalid", L
"Error", MB_ICONERROR
);
2854 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2858 pThis
->SetPath(unquoted
);
2860 pThis
->SetArguments(lpszArgs
);
2862 pThis
->SetArguments(L
"\0");
2864 HeapFree(GetProcessHeap(), 0, unquoted
);
2866 TRACE("This %p m_sLinkPath %S\n", pThis
, pThis
->m_sLinkPath
);
2867 pThis
->Save(pThis
->m_sLinkPath
, TRUE
);
2868 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
2874 switch(LOWORD(wParam
))
2877 SHOpenFolderAndSelectItems(pThis
->m_pPidl
, 0, NULL
, 0);
2880 /// open target directory
2885 WCHAR wszPath
[MAX_PATH
] = L
"";
2887 if (pThis
->m_sIcoPath
)
2888 wcscpy(wszPath
, pThis
->m_sIcoPath
);
2889 INT IconIndex
= pThis
->m_Header
.nIconIndex
;
2890 if (PickIconDlg(hwndDlg
, wszPath
, _countof(wszPath
), &IconIndex
))
2892 pThis
->SetIconLocation(wszPath
, IconIndex
);
2894 /// FIXME redraw icon
2901 INT_PTR result
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_SHORTCUT_EXTENDED_PROPERTIES
), hwndDlg
, ExtendedShortcutProc
, (LPARAM
)pThis
->m_bRunAs
);
2902 if (result
== 1 || result
== 0)
2904 if (pThis
->m_bRunAs
!= result
)
2906 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2909 pThis
->m_bRunAs
= result
;
2914 if (HIWORD(wParam
) == EN_CHANGE
)
2915 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2923 /**************************************************************************
2924 * ShellLink_IShellPropSheetExt interface
2927 HRESULT STDMETHODCALLTYPE
CShellLink::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage
, LPARAM lParam
)
2929 HPROPSHEETPAGE hPage
= SH_CreatePropertySheetPage(IDD_SHORTCUT_PROPERTIES
, SH_ShellLinkDlgProc
, (LPARAM
)this, NULL
);
2932 ERR("failed to create property sheet page\n");
2936 if (!pfnAddPage(hPage
, lParam
))
2942 HRESULT STDMETHODCALLTYPE
CShellLink::ReplacePage(UINT uPageID
, LPFNADDPROPSHEETPAGE pfnReplacePage
, LPARAM lParam
)
2944 TRACE("(%p) (uPageID %u, pfnReplacePage %p lParam %p\n", this, uPageID
, pfnReplacePage
, lParam
);
2948 HRESULT STDMETHODCALLTYPE
CShellLink::SetSite(IUnknown
*punk
)
2950 TRACE("%p %p\n", this, punk
);
2957 HRESULT STDMETHODCALLTYPE
CShellLink::GetSite(REFIID iid
, void ** ppvSite
)
2959 TRACE("%p %s %p\n", this, debugstr_guid(&iid
), ppvSite
);
2964 return m_site
->QueryInterface(iid
, ppvSite
);
2967 HRESULT STDMETHODCALLTYPE
CShellLink::DragEnter(IDataObject
*pDataObject
,
2968 DWORD dwKeyState
, POINTL pt
, DWORD
*pdwEffect
)
2970 TRACE("(%p)->(DataObject=%p)\n", this, pDataObject
);
2971 LPCITEMIDLIST pidlLast
;
2972 CComPtr
<IShellFolder
> psf
;
2974 HRESULT hr
= SHBindToParent(m_pPidl
, IID_PPV_ARG(IShellFolder
, &psf
), &pidlLast
);
2978 hr
= psf
->GetUIObjectOf(0, 1, &pidlLast
, IID_NULL_PPV_ARG(IDropTarget
, &m_DropTarget
));
2981 hr
= m_DropTarget
->DragEnter(pDataObject
, dwKeyState
, pt
, pdwEffect
);
2983 *pdwEffect
= DROPEFFECT_NONE
;
2986 *pdwEffect
= DROPEFFECT_NONE
;
2991 HRESULT STDMETHODCALLTYPE
CShellLink::DragOver(DWORD dwKeyState
, POINTL pt
,
2994 TRACE("(%p)\n", this);
2997 hr
= m_DropTarget
->DragOver(dwKeyState
, pt
, pdwEffect
);
3001 HRESULT STDMETHODCALLTYPE
CShellLink::DragLeave()
3003 TRACE("(%p)\n", this);
3007 hr
= m_DropTarget
->DragLeave();
3008 m_DropTarget
.Release();
3014 HRESULT STDMETHODCALLTYPE
CShellLink::Drop(IDataObject
*pDataObject
,
3015 DWORD dwKeyState
, POINTL pt
, DWORD
*pdwEffect
)
3017 TRACE("(%p)\n", this);
3020 hr
= m_DropTarget
->Drop(pDataObject
, dwKeyState
, pt
, pdwEffect
);
3025 /**************************************************************************
3026 * IShellLink_ConstructFromFile
3028 HRESULT WINAPI
IShellLink_ConstructFromPath(WCHAR
*path
, REFIID riid
, LPVOID
*ppv
)
3030 CComPtr
<IPersistFile
> ppf
;
3031 HRESULT hr
= CShellLink::_CreatorClass::CreateInstance(NULL
, IID_PPV_ARG(IPersistFile
, &ppf
));
3035 hr
= ppf
->Load(path
, 0);
3039 return ppf
->QueryInterface(riid
, ppv
);
3042 HRESULT WINAPI
IShellLink_ConstructFromFile(IShellFolder
* psf
, LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
)
3044 WCHAR path
[MAX_PATH
];
3045 if (!ILGetDisplayNameExW(psf
, pidl
, path
, 0))
3048 return IShellLink_ConstructFromPath(path
, riid
, ppv
);