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
148 /* link file formats */
150 #include "pshpack1.h"
158 DWORD dwLocalPathOfs
;
159 DWORD dwNetworkVolTableOfs
;
160 DWORD dwFinalPathOfs
;
163 struct LOCAL_VOLUME_INFO
175 WCHAR label
[12]; /* assume 8.3 */
180 /* IShellLink Implementation */
182 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
184 /* strdup on the process heap */
185 static LPWSTR __inline
HEAP_strdupAtoW(HANDLE heap
, DWORD flags
, LPCSTR str
)
192 len
= MultiByteToWideChar(CP_ACP
, 0, str
, -1, NULL
, 0);
193 p
= (LPWSTR
)HeapAlloc(heap
, flags
, len
* sizeof(WCHAR
));
196 MultiByteToWideChar(CP_ACP
, 0, str
, -1, p
, len
);
200 static LPWSTR __inline
strdupW(LPCWSTR src
)
203 if (!src
) return NULL
;
204 dest
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(src
) + 1) * sizeof(WCHAR
));
210 // TODO: Use it for constructor & destructor too
211 VOID
CShellLink::Reset()
216 HeapFree(GetProcessHeap(), 0, m_sPath
);
218 ZeroMemory(&volume
, sizeof(volume
));
220 HeapFree(GetProcessHeap(), 0, m_sDescription
);
221 m_sDescription
= NULL
;
222 HeapFree(GetProcessHeap(), 0, m_sPathRel
);
224 HeapFree(GetProcessHeap(), 0, m_sWorkDir
);
226 HeapFree(GetProcessHeap(), 0, m_sArgs
);
228 HeapFree(GetProcessHeap(), 0, m_sIcoPath
);
235 SHFreeDataBlockList(m_pDBList
);
238 /**/sProduct
= sComponent
= NULL
;/**/
241 CShellLink::CShellLink()
243 m_Header
.dwSize
= sizeof(m_Header
);
244 m_Header
.clsid
= CLSID_ShellLink
;
245 m_Header
.dwFlags
= 0;
247 m_Header
.dwFileAttributes
= 0;
248 ZeroMemory(&m_Header
.ftCreationTime
, sizeof(m_Header
.ftCreationTime
));
249 ZeroMemory(&m_Header
.ftLastAccessTime
, sizeof(m_Header
.ftLastAccessTime
));
250 ZeroMemory(&m_Header
.ftLastWriteTime
, sizeof(m_Header
.ftLastWriteTime
));
251 m_Header
.nFileSizeLow
= 0;
253 m_Header
.nIconIndex
= 0;
254 m_Header
.nShowCommand
= SW_SHOWNORMAL
;
255 m_Header
.wHotKey
= 0;
260 ZeroMemory(&volume
, sizeof(volume
));
262 m_sDescription
= NULL
;
274 /**/sProduct
= sComponent
= NULL
;/**/
277 CShellLink::~CShellLink()
279 TRACE("-- destroying IShellLink(%p)\n", this);
283 HeapFree(GetProcessHeap(), 0, m_sPath
);
285 HeapFree(GetProcessHeap(), 0, m_sDescription
);
286 HeapFree(GetProcessHeap(), 0, m_sPathRel
);
287 HeapFree(GetProcessHeap(), 0, m_sWorkDir
);
288 HeapFree(GetProcessHeap(), 0, m_sArgs
);
289 HeapFree(GetProcessHeap(), 0, m_sIcoPath
);
290 HeapFree(GetProcessHeap(), 0, m_sLinkPath
);
291 SHFreeDataBlockList(m_pDBList
);
294 HRESULT STDMETHODCALLTYPE
CShellLink::GetClassID(CLSID
*pclsid
)
296 TRACE("%p %p\n", this, pclsid
);
300 *pclsid
= CLSID_ShellLink
;
304 /************************************************************************
305 * IPersistStream_IsDirty (IPersistStream)
307 HRESULT STDMETHODCALLTYPE
CShellLink::IsDirty()
309 TRACE("(%p)\n", this);
310 return (m_bDirty
? S_OK
: S_FALSE
);
313 HRESULT STDMETHODCALLTYPE
CShellLink::Load(LPCOLESTR pszFileName
, DWORD dwMode
)
315 TRACE("(%p, %s, %x)\n", this, debugstr_w(pszFileName
), dwMode
);
318 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
320 CComPtr
<IStream
> stm
;
321 HRESULT hr
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
324 HeapFree(GetProcessHeap(), 0, m_sLinkPath
);
325 m_sLinkPath
= strdupW(pszFileName
);
327 ShellLink_UpdatePath(m_sPathRel
, pszFileName
, m_sWorkDir
, &m_sPath
);
330 TRACE("-- returning hr %08x\n", hr
);
334 HRESULT STDMETHODCALLTYPE
CShellLink::Save(LPCOLESTR pszFileName
, BOOL fRemember
)
336 TRACE("(%p)->(%s)\n", this, debugstr_w(pszFileName
));
341 CComPtr
<IStream
> stm
;
342 HRESULT hr
= SHCreateStreamOnFileW(pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
345 hr
= Save(stm
, FALSE
);
350 HeapFree(GetProcessHeap(), 0, m_sLinkPath
);
352 m_sLinkPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(pszFileName
) + 1) * sizeof(WCHAR
));
354 wcscpy(m_sLinkPath
, pszFileName
);
360 DeleteFileW(pszFileName
);
361 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
));
368 HRESULT STDMETHODCALLTYPE
CShellLink::SaveCompleted(LPCOLESTR pszFileName
)
370 FIXME("(%p)->(%s)\n", this, debugstr_w(pszFileName
));
374 HRESULT STDMETHODCALLTYPE
CShellLink::GetCurFile(LPOLESTR
*ppszFileName
)
376 *ppszFileName
= NULL
;
380 /* IPersistFile::GetCurFile called before IPersistFile::Save */
384 *ppszFileName
= (LPOLESTR
)CoTaskMemAlloc((wcslen(m_sLinkPath
) + 1) * sizeof(WCHAR
));
388 return E_OUTOFMEMORY
;
391 /* copy last saved filename */
392 wcscpy(*ppszFileName
, m_sLinkPath
);
397 static HRESULT
Stream_LoadString(IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
403 HRESULT hr
= stm
->Read(&len
, sizeof(len
), &count
);
404 if (FAILED(hr
) || count
!= sizeof(len
))
408 len
*= sizeof(WCHAR
);
410 TRACE("reading %d\n", len
);
411 LPSTR temp
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, len
+ sizeof(WCHAR
));
413 return E_OUTOFMEMORY
;
415 hr
= stm
->Read(temp
, len
, &count
);
416 if (FAILED(hr
) || count
!= len
)
418 HeapFree(GetProcessHeap(), 0, temp
);
422 TRACE("read %s\n", debugstr_an(temp
, len
));
424 /* convert to unicode if necessary */
428 count
= MultiByteToWideChar(CP_ACP
, 0, temp
, len
, NULL
, 0);
429 str
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (count
+ 1) * sizeof(WCHAR
));
432 HeapFree(GetProcessHeap(), 0, temp
);
433 return E_OUTOFMEMORY
;
435 MultiByteToWideChar(CP_ACP
, 0, temp
, len
, str
, count
);
436 HeapFree(GetProcessHeap(), 0, temp
);
440 count
/= sizeof(WCHAR
);
452 * NOTE: The following 5 functions are part of LINKINFO.DLL
454 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, CShellLink::volume_info
*volume
)
456 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
458 volume
->type
= GetDriveTypeW(drive
);
459 BOOL bRet
= GetVolumeInformationW(drive
, volume
->label
, _countof(volume
->label
), &volume
->serial
, NULL
, NULL
, NULL
, 0);
460 TRACE("ret = %d type %d serial %08x name %s\n", bRet
,
461 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
465 static HRESULT
Stream_ReadChunk(IStream
* stm
, LPVOID
*data
)
470 unsigned char data
[1];
477 HRESULT hr
= stm
->Read(&size
, sizeof(size
), &count
);
478 if (FAILED(hr
) || count
!= sizeof(size
))
481 chunk
= static_cast<sized_chunk
*>(HeapAlloc(GetProcessHeap(), 0, size
));
483 return E_OUTOFMEMORY
;
486 hr
= stm
->Read(chunk
->data
, size
- sizeof(size
), &count
);
487 if (FAILED(hr
) || count
!= (size
- sizeof(size
)))
489 HeapFree(GetProcessHeap(), 0, chunk
);
493 TRACE("Read %d bytes\n", chunk
->size
);
500 static BOOL
Stream_LoadVolume(LOCAL_VOLUME_INFO
*vol
, CShellLink::volume_info
*volume
)
502 volume
->serial
= vol
->dwVolSerial
;
503 volume
->type
= vol
->dwType
;
505 if (!vol
->dwVolLabelOfs
)
507 if (vol
->dwSize
<= vol
->dwVolLabelOfs
)
509 INT len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
511 LPSTR label
= (LPSTR
)vol
;
512 label
+= vol
->dwVolLabelOfs
;
513 MultiByteToWideChar(CP_ACP
, 0, label
, len
, volume
->label
, _countof(volume
->label
));
518 static LPWSTR
Stream_LoadPath(LPCSTR p
, DWORD maxlen
)
522 while (p
[len
] && len
< maxlen
)
525 UINT wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
526 LPWSTR path
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wlen
+ 1) * sizeof(WCHAR
));
529 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
535 static HRESULT
Stream_LoadLocation(IStream
*stm
,
536 CShellLink::volume_info
*volume
, LPWSTR
*path
)
539 HRESULT hr
= Stream_ReadChunk(stm
, (LPVOID
*) &p
);
543 LOCATION_INFO
*loc
= reinterpret_cast<LOCATION_INFO
*>(p
);
544 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
546 HeapFree(GetProcessHeap(), 0, p
);
550 /* if there's valid local volume information, load it */
551 if (loc
->dwVolTableOfs
&&
552 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
))
554 LOCAL_VOLUME_INFO
*volume_info
;
556 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
557 Stream_LoadVolume(volume_info
, volume
);
560 /* if there's a local path, load it */
561 DWORD n
= loc
->dwLocalPathOfs
;
562 if (n
&& n
< loc
->dwTotalSize
)
563 *path
= Stream_LoadPath(&p
[n
], loc
->dwTotalSize
- n
);
565 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
566 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
568 HeapFree(GetProcessHeap(), 0, p
);
574 * The format of the advertised shortcut info is:
578 * 0 Length of the block (4 bytes, usually 0x314)
580 * 8 string data in ASCII
581 * 8+0x104 string data in UNICODE
583 * In the original Win32 implementation the buffers are not initialized
584 * to zero, so data trailing the string is random garbage.
586 HRESULT
CShellLink::GetAdvertiseInfo(LPWSTR
*str
, DWORD dwSig
)
588 LPEXP_DARWIN_LINK pInfo
;
592 pInfo
= (LPEXP_DARWIN_LINK
)SHFindDataBlock(m_pDBList
, dwSig
);
596 /* Make sure that the size of the structure is valid */
597 if (pInfo
->dbh
.cbSize
!= sizeof(*pInfo
))
599 ERR("Ooops. This structure is not as expected...\n");
603 TRACE("dwSig %08x string = '%s'\n", pInfo
->dbh
.dwSignature
, debugstr_w(pInfo
->szwDarwinID
));
605 *str
= pInfo
->szwDarwinID
;
609 /************************************************************************
610 * IPersistStream_Load (IPersistStream)
612 HRESULT STDMETHODCALLTYPE
CShellLink::Load(IStream
*stm
)
614 TRACE("%p %p\n", this, stm
);
617 return STG_E_INVALIDPOINTER
;
619 /* Free all the old stuff */
622 ULONG dwBytesRead
= 0;
623 HRESULT hr
= stm
->Read(&m_Header
, sizeof(m_Header
), &dwBytesRead
);
627 if (dwBytesRead
!= sizeof(m_Header
))
629 if (m_Header
.dwSize
!= sizeof(m_Header
))
631 if (!IsEqualIID(m_Header
.clsid
, CLSID_ShellLink
))
634 /* Load the new data in order */
638 SYSTEMTIME stCreationTime
;
639 SYSTEMTIME stLastAccessTime
;
640 SYSTEMTIME stLastWriteTime
;
641 WCHAR sTemp
[MAX_PATH
];
643 FileTimeToSystemTime(&m_Header
.ftCreationTime
, &stCreationTime
);
644 FileTimeToSystemTime(&m_Header
.ftLastAccessTime
, &stLastAccessTime
);
645 FileTimeToSystemTime(&m_Header
.ftLastWriteTime
, &stLastWriteTime
);
647 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &stCreationTime
,
648 NULL
, sTemp
, _countof(sTemp
));
649 TRACE("-- stCreationTime: %s\n", debugstr_w(sTemp
));
650 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &stLastAccessTime
,
651 NULL
, sTemp
, _countof(sTemp
));
652 TRACE("-- stLastAccessTime: %s\n", debugstr_w(sTemp
));
653 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &stLastWriteTime
,
654 NULL
, sTemp
, _countof(sTemp
));
655 TRACE("-- stLastWriteTime: %s\n", debugstr_w(sTemp
));
658 /* load all the new stuff */
659 if (m_Header
.dwFlags
& SLDF_HAS_ID_LIST
)
661 hr
= ILLoadFromStream(stm
, &m_pPidl
);
667 /* Load the location information... */
668 if (m_Header
.dwFlags
& SLDF_HAS_LINK_INFO
)
670 hr
= Stream_LoadLocation(stm
, &volume
, &m_sPath
);
674 /* ... but if it is required not to use it, clear it */
675 if (m_Header
.dwFlags
& SLDF_FORCE_NO_LINKINFO
)
677 HeapFree(GetProcessHeap(), 0, m_sPath
);
679 ZeroMemory(&volume
, sizeof(volume
));
682 BOOL unicode
= !!(m_Header
.dwFlags
& SLDF_UNICODE
);
684 if (m_Header
.dwFlags
& SLDF_HAS_NAME
)
686 hr
= Stream_LoadString(stm
, unicode
, &m_sDescription
);
689 TRACE("Description -> %s\n", debugstr_w(m_sDescription
));
692 if (m_Header
.dwFlags
& SLDF_HAS_RELPATH
)
694 hr
= Stream_LoadString(stm
, unicode
, &m_sPathRel
);
697 TRACE("Relative Path-> %s\n", debugstr_w(m_sPathRel
));
700 if (m_Header
.dwFlags
& SLDF_HAS_WORKINGDIR
)
702 hr
= Stream_LoadString(stm
, unicode
, &m_sWorkDir
);
705 PathRemoveBackslash(m_sWorkDir
);
706 TRACE("Working Dir -> %s\n", debugstr_w(m_sWorkDir
));
709 if (m_Header
.dwFlags
& SLDF_HAS_ARGS
)
711 hr
= Stream_LoadString(stm
, unicode
, &m_sArgs
);
714 TRACE("Arguments -> %s\n", debugstr_w(m_sArgs
));
717 if (m_Header
.dwFlags
& SLDF_HAS_ICONLOCATION
)
719 hr
= Stream_LoadString(stm
, unicode
, &m_sIcoPath
);
722 TRACE("Icon file -> %s\n", debugstr_w(m_sIcoPath
));
725 /* Now load the optional data block list */
726 hr
= SHReadDataBlockList(stm
, &m_pDBList
);
727 if (FAILED(hr
)) // FIXME: Should we fail?
732 #if (NTDDI_VERSION < NTDDI_LONGHORN)
733 if (m_Header
.dwFlags
& SLDF_HAS_LOGO3ID
)
735 hr
= GetAdvertiseInfo(&sProduct
, EXP_LOGO3_ID_SIG
);
737 TRACE("Product -> %s\n", debugstr_w(sProduct
));
740 if (m_Header
.dwFlags
& SLDF_HAS_DARWINID
)
742 hr
= GetAdvertiseInfo(&sComponent
, EXP_DARWIN_ID_SIG
);
744 TRACE("Component -> %s\n", debugstr_w(sComponent
));
748 if (m_Header
.dwFlags
& SLDF_RUNAS_USER
)
760 /************************************************************************
763 * Helper function for IPersistStream_Save. Writes a unicode string
764 * with terminating nul byte to a stream, preceded by the its length.
766 static HRESULT
Stream_WriteString(IStream
* stm
, LPCWSTR str
)
768 USHORT len
= wcslen(str
) + 1; // FIXME: Possible overflows?
771 HRESULT hr
= stm
->Write(&len
, sizeof(len
), &count
);
775 len
*= sizeof(WCHAR
);
777 hr
= stm
->Write(str
, len
, &count
);
784 /************************************************************************
785 * Stream_WriteLocationInfo
787 * Writes the location info to a stream
789 * FIXME: One day we might want to write the network volume information
790 * and the final path.
791 * Figure out how Windows deals with unicode paths here.
793 static HRESULT
Stream_WriteLocationInfo(IStream
* stm
, LPCWSTR path
,
794 CShellLink::volume_info
*volume
)
796 LOCAL_VOLUME_INFO
*vol
;
799 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
801 /* figure out the size of everything */
802 DWORD label_size
= WideCharToMultiByte(CP_ACP
, 0, volume
->label
, -1,
803 NULL
, 0, NULL
, NULL
);
804 DWORD path_size
= WideCharToMultiByte(CP_ACP
, 0, path
, -1,
805 NULL
, 0, NULL
, NULL
);
806 DWORD volume_info_size
= sizeof(*vol
) + label_size
;
807 DWORD final_path_size
= 1;
808 DWORD total_size
= sizeof(*loc
) + volume_info_size
+ path_size
+ final_path_size
;
810 /* create pointers to everything */
811 loc
= static_cast<LOCATION_INFO
*>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
));
812 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
813 LPSTR szLabel
= (LPSTR
) &vol
[1];
814 LPSTR szPath
= &szLabel
[label_size
];
815 LPSTR szFinalPath
= &szPath
[path_size
];
817 /* fill in the location information header */
818 loc
->dwTotalSize
= total_size
;
819 loc
->dwHeaderSize
= sizeof(*loc
);
821 loc
->dwVolTableOfs
= sizeof(*loc
);
822 loc
->dwLocalPathOfs
= sizeof(*loc
) + volume_info_size
;
823 loc
->dwNetworkVolTableOfs
= 0;
824 loc
->dwFinalPathOfs
= sizeof(*loc
) + volume_info_size
+ path_size
;
826 /* fill in the volume information */
827 vol
->dwSize
= volume_info_size
;
828 vol
->dwType
= volume
->type
;
829 vol
->dwVolSerial
= volume
->serial
;
830 vol
->dwVolLabelOfs
= sizeof(*vol
);
832 /* copy in the strings */
833 WideCharToMultiByte(CP_ACP
, 0, volume
->label
, -1,
834 szLabel
, label_size
, NULL
, NULL
);
835 WideCharToMultiByte(CP_ACP
, 0, path
, -1,
836 szPath
, path_size
, NULL
, NULL
);
840 HRESULT hr
= stm
->Write(loc
, total_size
, &count
);
841 HeapFree(GetProcessHeap(), 0, loc
);
846 /************************************************************************
847 * IPersistStream_Save (IPersistStream)
849 * FIXME: makes assumptions about byte order
851 HRESULT STDMETHODCALLTYPE
CShellLink::Save(IStream
*stm
, BOOL fClearDirty
)
853 TRACE("%p %p %x\n", this, stm
, fClearDirty
);
855 m_Header
.dwSize
= sizeof(m_Header
);
856 m_Header
.clsid
= CLSID_ShellLink
;
859 * Reset the flags: keep only the flags related to data blocks as they were
860 * already set in accordance by the different mutator member functions.
861 * The other flags will be determined now by the presence or absence of data.
863 m_Header
.dwFlags
&= (SLDF_RUN_WITH_SHIMLAYER
| SLDF_RUNAS_USER
|
864 SLDF_RUN_IN_SEPARATE
| SLDF_HAS_DARWINID
|
865 #if (NTDDI_VERSION < NTDDI_LONGHORN)
868 SLDF_HAS_EXP_ICON_SZ
| SLDF_HAS_EXP_SZ
);
869 // TODO: When we will support Vista+ functionality, add other flags to this list.
871 /* The stored strings are in UNICODE */
872 m_Header
.dwFlags
|= SLDF_UNICODE
;
875 m_Header
.dwFlags
|= SLDF_HAS_ID_LIST
;
877 m_Header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
878 if (m_sDescription
&& *m_sDescription
)
879 m_Header
.dwFlags
|= SLDF_HAS_NAME
;
880 if (m_sPathRel
&& *m_sPathRel
)
881 m_Header
.dwFlags
|= SLDF_HAS_RELPATH
;
882 if (m_sWorkDir
&& *m_sWorkDir
)
883 m_Header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
884 if (m_sArgs
&& *m_sArgs
)
885 m_Header
.dwFlags
|= SLDF_HAS_ARGS
;
886 if (m_sIcoPath
&& *m_sIcoPath
)
887 m_Header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
889 m_Header
.dwFlags
|= SLDF_RUNAS_USER
;
891 /* Write the shortcut header */
893 HRESULT hr
= stm
->Write(&m_Header
, sizeof(m_Header
), &count
);
896 ERR("Write failed\n");
900 /* Save the data in order */
904 hr
= ILSaveToStream(stm
, m_pPidl
);
907 ERR("Failed to write PIDL\n");
914 hr
= Stream_WriteLocationInfo(stm
, m_sPath
, &volume
);
919 if (m_Header
.dwFlags
& SLDF_HAS_NAME
)
921 hr
= Stream_WriteString(stm
, m_sDescription
);
926 if (m_Header
.dwFlags
& SLDF_HAS_RELPATH
)
928 hr
= Stream_WriteString(stm
, m_sPathRel
);
933 if (m_Header
.dwFlags
& SLDF_HAS_WORKINGDIR
)
935 hr
= Stream_WriteString(stm
, m_sWorkDir
);
940 if (m_Header
.dwFlags
& SLDF_HAS_ARGS
)
942 hr
= Stream_WriteString(stm
, m_sArgs
);
947 if (m_Header
.dwFlags
& SLDF_HAS_ICONLOCATION
)
949 hr
= Stream_WriteString(stm
, m_sIcoPath
);
955 * Now save the data block list.
957 * NOTE that both advertised Product and Component are already saved
958 * inside Logo3 and Darwin data blocks in the m_pDBList list, and the
959 * m_Header.dwFlags is suitably initialized.
961 hr
= SHWriteDataBlockList(stm
, m_pDBList
);
965 /* Clear the dirty bit if requested */
972 /************************************************************************
973 * IPersistStream_GetSizeMax (IPersistStream)
975 HRESULT STDMETHODCALLTYPE
CShellLink::GetSizeMax(ULARGE_INTEGER
*pcbSize
)
977 TRACE("(%p)\n", this);
981 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
983 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
989 /**************************************************************************
990 * ShellLink_UpdatePath
991 * update absolute path in sPath using relative path in sPathRel
993 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
995 if (!path
|| !psPath
)
998 if (!*psPath
&& sPathRel
)
1000 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1001 LPWSTR final
= NULL
;
1003 /* first try if [directory of link file] + [relative path] finds an existing file */
1005 GetFullPathNameW(path
, MAX_PATH
* 2, buffer
, &final
);
1008 wcscpy(final
, sPathRel
);
1012 if (SHELL_ExistsFileW(buffer
))
1014 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1015 wcscpy(abs_path
, buffer
);
1019 /* try if [working directory] + [relative path] finds an existing file */
1022 wcscpy(buffer
, sWorkDir
);
1023 wcscpy(PathAddBackslashW(buffer
), sPathRel
);
1025 if (SHELL_ExistsFileW(buffer
))
1026 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1027 wcscpy(abs_path
, buffer
);
1031 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1033 wcscpy(abs_path
, sPathRel
);
1035 *psPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(abs_path
) + 1) * sizeof(WCHAR
));
1037 return E_OUTOFMEMORY
;
1039 wcscpy(*psPath
, abs_path
);
1045 HRESULT STDMETHODCALLTYPE
CShellLink::GetPath(LPSTR pszFile
, INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1049 WIN32_FIND_DATAW wfd
;
1051 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1052 this, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(m_sPath
));
1054 /* Allocate a temporary UNICODE buffer */
1055 pszFileW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, cchMaxPath
* sizeof(WCHAR
));
1057 return E_OUTOFMEMORY
;
1059 /* Call the UNICODE function */
1060 hr
= GetPath(pszFileW
, cchMaxPath
, &wfd
, fFlags
);
1062 /* Convert the file path back to ANSI */
1063 WideCharToMultiByte(CP_ACP
, 0, pszFileW
, -1,
1064 pszFile
, cchMaxPath
, NULL
, NULL
);
1066 /* Free the temporary buffer */
1067 HeapFree(GetProcessHeap(), 0, pszFileW
);
1071 ZeroMemory(pfd
, sizeof(*pfd
));
1073 /* Copy the file data if a file path was returned */
1078 /* Copy the fixed part */
1079 CopyMemory(pfd
, &wfd
, FIELD_OFFSET(WIN32_FIND_DATAA
, cFileName
));
1081 /* Convert the file names to ANSI */
1082 len
= lstrlenW(wfd
.cFileName
);
1083 WideCharToMultiByte(CP_ACP
, 0, wfd
.cFileName
, len
+ 1,
1084 pfd
->cFileName
, sizeof(pfd
->cFileName
), NULL
, NULL
);
1085 len
= lstrlenW(wfd
.cAlternateFileName
);
1086 WideCharToMultiByte(CP_ACP
, 0, wfd
.cAlternateFileName
, len
+ 1,
1087 pfd
->cAlternateFileName
, sizeof(pfd
->cAlternateFileName
), NULL
, NULL
);
1094 HRESULT STDMETHODCALLTYPE
CShellLink::GetIDList(LPITEMIDLIST
*ppidl
)
1096 TRACE("(%p)->(ppidl=%p)\n", this, ppidl
);
1104 *ppidl
= ILClone(m_pPidl
);
1108 HRESULT STDMETHODCALLTYPE
CShellLink::SetIDList(LPCITEMIDLIST pidl
)
1110 TRACE("(%p)->(pidl=%p)\n", this, pidl
);
1111 return SetTargetFromPIDLOrPath(pidl
, NULL
);
1114 HRESULT STDMETHODCALLTYPE
CShellLink::GetDescription(LPSTR pszName
, INT cchMaxName
)
1116 TRACE("(%p)->(%p len=%u)\n", this, pszName
, cchMaxName
);
1122 WideCharToMultiByte(CP_ACP
, 0, m_sDescription
, -1,
1123 pszName
, cchMaxName
, NULL
, NULL
);
1128 HRESULT STDMETHODCALLTYPE
CShellLink::SetDescription(LPCSTR pszName
)
1130 TRACE("(%p)->(pName=%s)\n", this, pszName
);
1132 HeapFree(GetProcessHeap(), 0, m_sDescription
);
1133 m_sDescription
= NULL
;
1137 m_sDescription
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszName
);
1138 if (!m_sDescription
)
1139 return E_OUTOFMEMORY
;
1146 HRESULT STDMETHODCALLTYPE
CShellLink::GetWorkingDirectory(LPSTR pszDir
, INT cchMaxPath
)
1148 TRACE("(%p)->(%p len=%u)\n", this, pszDir
, cchMaxPath
);
1154 WideCharToMultiByte(CP_ACP
, 0, m_sWorkDir
, -1,
1155 pszDir
, cchMaxPath
, NULL
, NULL
);
1160 HRESULT STDMETHODCALLTYPE
CShellLink::SetWorkingDirectory(LPCSTR pszDir
)
1162 TRACE("(%p)->(dir=%s)\n", this, pszDir
);
1164 HeapFree(GetProcessHeap(), 0, m_sWorkDir
);
1169 m_sWorkDir
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszDir
);
1171 return E_OUTOFMEMORY
;
1178 HRESULT STDMETHODCALLTYPE
CShellLink::GetArguments(LPSTR pszArgs
, INT cchMaxPath
)
1180 TRACE("(%p)->(%p len=%u)\n", this, pszArgs
, cchMaxPath
);
1186 WideCharToMultiByte(CP_ACP
, 0, m_sArgs
, -1,
1187 pszArgs
, cchMaxPath
, NULL
, NULL
);
1192 HRESULT STDMETHODCALLTYPE
CShellLink::SetArguments(LPCSTR pszArgs
)
1194 TRACE("(%p)->(args=%s)\n", this, pszArgs
);
1196 HeapFree(GetProcessHeap(), 0, m_sArgs
);
1201 m_sArgs
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszArgs
);
1203 return E_OUTOFMEMORY
;
1211 HRESULT STDMETHODCALLTYPE
CShellLink::GetHotkey(WORD
*pwHotkey
)
1213 TRACE("(%p)->(%p)(0x%08x)\n", this, pwHotkey
, m_Header
.wHotKey
);
1214 *pwHotkey
= m_Header
.wHotKey
;
1218 HRESULT STDMETHODCALLTYPE
CShellLink::SetHotkey(WORD wHotkey
)
1220 TRACE("(%p)->(hotkey=%x)\n", this, wHotkey
);
1222 m_Header
.wHotKey
= wHotkey
;
1228 HRESULT STDMETHODCALLTYPE
CShellLink::GetShowCmd(INT
*piShowCmd
)
1230 TRACE("(%p)->(%p) %d\n", this, piShowCmd
, m_Header
.nShowCommand
);
1231 *piShowCmd
= m_Header
.nShowCommand
;
1235 HRESULT STDMETHODCALLTYPE
CShellLink::SetShowCmd(INT iShowCmd
)
1237 TRACE("(%p) %d\n", this, iShowCmd
);
1239 m_Header
.nShowCommand
= iShowCmd
;
1245 HRESULT STDMETHODCALLTYPE
CShellLink::GetIconLocation(LPSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1248 LPWSTR pszIconPathW
;
1250 TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath
, cchIconPath
, piIcon
);
1252 /* Allocate a temporary UNICODE buffer */
1253 pszIconPathW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, cchIconPath
* sizeof(WCHAR
));
1255 return E_OUTOFMEMORY
;
1257 /* Call the UNICODE function */
1258 hr
= GetIconLocation(pszIconPathW
, cchIconPath
, piIcon
);
1260 /* Convert the file path back to ANSI */
1261 WideCharToMultiByte(CP_ACP
, 0, pszIconPathW
, -1,
1262 pszIconPath
, cchIconPath
, NULL
, NULL
);
1264 /* Free the temporary buffer */
1265 HeapFree(GetProcessHeap(), 0, pszIconPathW
);
1270 HRESULT STDMETHODCALLTYPE
CShellLink::GetIconLocation(UINT uFlags
, PSTR pszIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
1273 LPWSTR pszIconFileW
;
1275 TRACE("(%p)->(%u %p len=%u piIndex=%p pwFlags=%p)\n", this, uFlags
, pszIconFile
, cchMax
, piIndex
, pwFlags
);
1277 /* Allocate a temporary UNICODE buffer */
1278 pszIconFileW
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, cchMax
* sizeof(WCHAR
));
1280 return E_OUTOFMEMORY
;
1282 /* Call the UNICODE function */
1283 hr
= GetIconLocation(uFlags
, pszIconFileW
, cchMax
, piIndex
, pwFlags
);
1285 /* Convert the file path back to ANSI */
1286 WideCharToMultiByte(CP_ACP
, 0, pszIconFileW
, -1,
1287 pszIconFile
, cchMax
, NULL
, NULL
);
1289 /* Free the temporary buffer */
1290 HeapFree(GetProcessHeap(), 0, pszIconFileW
);
1295 HRESULT STDMETHODCALLTYPE
CShellLink::Extract(PCSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
1297 TRACE("(%p)->(path=%s iicon=%u)\n", this, pszFile
, nIconIndex
);
1302 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1304 return E_OUTOFMEMORY
;
1307 HRESULT hr
= Extract(str
, nIconIndex
, phiconLarge
, phiconSmall
, nIconSize
);
1310 HeapFree(GetProcessHeap(), 0, str
);
1315 HRESULT STDMETHODCALLTYPE
CShellLink::SetIconLocation(LPCSTR pszIconPath
, INT iIcon
)
1317 TRACE("(%p)->(path=%s iicon=%u)\n", this, pszIconPath
, iIcon
);
1322 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1324 return E_OUTOFMEMORY
;
1327 HRESULT hr
= SetIconLocation(str
, iIcon
);
1330 HeapFree(GetProcessHeap(), 0, str
);
1335 HRESULT STDMETHODCALLTYPE
CShellLink::SetRelativePath(LPCSTR pszPathRel
, DWORD dwReserved
)
1337 TRACE("(%p)->(path=%s %x)\n", this, pszPathRel
, dwReserved
);
1339 HeapFree(GetProcessHeap(), 0, m_sPathRel
);
1344 m_sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1348 return ShellLink_UpdatePath(m_sPathRel
, m_sPath
, m_sWorkDir
, &m_sPath
);
1352 shelllink_get_msi_component_path(LPWSTR component
)
1354 DWORD Result
, sz
= 0;
1356 Result
= CommandLineFromMsiDescriptor(component
, NULL
, &sz
);
1357 if (Result
!= ERROR_SUCCESS
)
1361 LPWSTR path
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, sz
* sizeof(WCHAR
));
1362 Result
= CommandLineFromMsiDescriptor(component
, path
, &sz
);
1363 if (Result
!= ERROR_SUCCESS
)
1365 HeapFree(GetProcessHeap(), 0, path
);
1369 TRACE("returning %s\n", debugstr_w(path
));
1374 HRESULT STDMETHODCALLTYPE
CShellLink::Resolve(HWND hwnd
, DWORD fFlags
)
1379 TRACE("(%p)->(hwnd=%p flags=%x)\n", this, hwnd
, fFlags
);
1381 /* FIXME: use IResolveShellLink interface? */
1383 // FIXME: See InvokeCommand().
1385 #if (NTDDI_VERSION < NTDDI_LONGHORN)
1386 // NOTE: For Logo3 (EXP_LOGO3_ID_SIG), check also for SHRestricted(REST_NOLOGO3CHANNELNOTIFY)
1387 if (m_Header
.dwFlags
& SLDF_HAS_LOGO3ID
)
1389 FIXME("Logo3 links are not supported yet!\n");
1394 /* Resolve Darwin (MSI) target */
1395 if (m_Header
.dwFlags
& SLDF_HAS_DARWINID
)
1397 LPWSTR component
= NULL
;
1398 hr
= GetAdvertiseInfo(&component
, EXP_DARWIN_ID_SIG
);
1402 /* Clear the cached path */
1403 HeapFree(GetProcessHeap(), 0, m_sPath
);
1405 m_sPath
= shelllink_get_msi_component_path(component
);
1410 if (!m_sPath
&& m_pPidl
)
1412 WCHAR buffer
[MAX_PATH
];
1414 bSuccess
= SHGetPathFromIDListW(m_pPidl
, buffer
);
1415 if (bSuccess
&& *buffer
)
1417 m_sPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(buffer
) + 1) * sizeof(WCHAR
));
1419 return E_OUTOFMEMORY
;
1421 wcscpy(m_sPath
, buffer
);
1427 hr
= S_OK
; /* don't report an error occurred while just caching information */
1431 // FIXME: Strange to do that here...
1432 if (!m_sIcoPath
&& m_sPath
)
1434 m_sIcoPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, (wcslen(m_sPath
) + 1) * sizeof(WCHAR
));
1436 return E_OUTOFMEMORY
;
1438 wcscpy(m_sIcoPath
, m_sPath
);
1439 m_Header
.nIconIndex
= 0;
1447 HRESULT STDMETHODCALLTYPE
CShellLink::SetPath(LPCSTR pszFile
)
1449 TRACE("(%p)->(path=%s)\n", this, pszFile
);
1452 return E_INVALIDARG
;
1454 LPWSTR str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1456 return E_OUTOFMEMORY
;
1458 HRESULT hr
= SetPath(str
);
1459 HeapFree(GetProcessHeap(), 0, str
);
1464 HRESULT STDMETHODCALLTYPE
CShellLink::GetPath(LPWSTR pszFile
, INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1466 WCHAR buffer
[MAX_PATH
];
1468 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1469 this, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(m_sPath
));
1473 // FIXME: What if cchMaxPath == 0 , or pszFile == NULL ??
1475 // FIXME: What about Darwin??
1478 * Retrieve the path to the target from the PIDL (if we have one).
1479 * NOTE: Do NOT use the cached path (m_sPath from link info).
1481 if (m_pPidl
&& SHGetPathFromIDListW(m_pPidl
, buffer
))
1483 if (fFlags
& SLGP_SHORTPATH
)
1484 GetShortPathNameW(buffer
, buffer
, _countof(buffer
));
1485 // FIXME: Add support for SLGP_UNCPRIORITY
1492 /* If we have a FindData structure, initialize it */
1495 ZeroMemory(pfd
, sizeof(*pfd
));
1497 /* Copy the file data if the target is a file path */
1500 pfd
->dwFileAttributes
= m_Header
.dwFileAttributes
;
1501 pfd
->ftCreationTime
= m_Header
.ftCreationTime
;
1502 pfd
->ftLastAccessTime
= m_Header
.ftLastAccessTime
;
1503 pfd
->ftLastWriteTime
= m_Header
.ftLastWriteTime
;
1504 pfd
->nFileSizeHigh
= 0;
1505 pfd
->nFileSizeLow
= m_Header
.nFileSizeLow
;
1508 * Build temporarily a short path in pfd->cFileName (of size MAX_PATH),
1509 * then extract and store the short file name in pfd->cAlternateFileName.
1511 GetShortPathNameW(buffer
, pfd
->cFileName
, _countof(pfd
->cFileName
));
1512 lstrcpynW(pfd
->cAlternateFileName
,
1513 PathFindFileNameW(pfd
->cFileName
),
1514 _countof(pfd
->cAlternateFileName
));
1516 /* Now extract and store the long file name in pfd->cFileName */
1517 lstrcpynW(pfd
->cFileName
,
1518 PathFindFileNameW(buffer
),
1519 _countof(pfd
->cFileName
));
1523 /* Finally check if we have a raw path the user actually wants to retrieve */
1524 if ((fFlags
& SLGP_RAWPATH
) && (m_Header
.dwFlags
& SLDF_HAS_EXP_SZ
))
1526 /* Search for a target environment block */
1527 LPEXP_SZ_LINK pInfo
;
1528 pInfo
= (LPEXP_SZ_LINK
)SHFindDataBlock(m_pDBList
, EXP_SZ_LINK_SIG
);
1529 if (pInfo
&& (pInfo
->cbSize
== sizeof(*pInfo
)))
1530 lstrcpynW(buffer
, pInfo
->szwTarget
, cchMaxPath
);
1533 /* For diagnostics purposes only... */
1534 // NOTE: SLGP_UNCPRIORITY is unsupported
1535 fFlags
&= ~(SLGP_RAWPATH
| SLGP_SHORTPATH
);
1536 if (fFlags
) FIXME("(%p): Unsupported flags %lu\n", this, fFlags
);
1538 /* Copy the data back to the user */
1540 lstrcpynW(pszFile
, buffer
, cchMaxPath
);
1542 return (*buffer
? S_OK
: S_FALSE
);
1545 HRESULT STDMETHODCALLTYPE
CShellLink::GetDescription(LPWSTR pszName
, INT cchMaxName
)
1547 TRACE("(%p)->(%p len=%u)\n", this, pszName
, cchMaxName
);
1551 lstrcpynW(pszName
, m_sDescription
, cchMaxName
);
1556 HRESULT STDMETHODCALLTYPE
CShellLink::SetDescription(LPCWSTR pszName
)
1558 TRACE("(%p)->(desc=%s)\n", this, debugstr_w(pszName
));
1560 HeapFree(GetProcessHeap(), 0, m_sDescription
);
1563 m_sDescription
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1564 (wcslen(pszName
) + 1) * sizeof(WCHAR
));
1565 if (!m_sDescription
)
1566 return E_OUTOFMEMORY
;
1568 wcscpy(m_sDescription
, pszName
);
1571 m_sDescription
= NULL
;
1578 HRESULT STDMETHODCALLTYPE
CShellLink::GetWorkingDirectory(LPWSTR pszDir
, INT cchMaxPath
)
1580 TRACE("(%p)->(%p len %u)\n", this, pszDir
, cchMaxPath
);
1586 lstrcpynW(pszDir
, m_sWorkDir
, cchMaxPath
);
1591 HRESULT STDMETHODCALLTYPE
CShellLink::SetWorkingDirectory(LPCWSTR pszDir
)
1593 TRACE("(%p)->(dir=%s)\n", this, debugstr_w(pszDir
));
1595 HeapFree(GetProcessHeap(), 0, m_sWorkDir
);
1598 m_sWorkDir
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1599 (wcslen(pszDir
) + 1) * sizeof(WCHAR
));
1601 return E_OUTOFMEMORY
;
1602 wcscpy(m_sWorkDir
, pszDir
);
1612 HRESULT STDMETHODCALLTYPE
CShellLink::GetArguments(LPWSTR pszArgs
, INT cchMaxPath
)
1614 TRACE("(%p)->(%p len=%u)\n", this, pszArgs
, cchMaxPath
);
1620 lstrcpynW(pszArgs
, m_sArgs
, cchMaxPath
);
1625 HRESULT STDMETHODCALLTYPE
CShellLink::SetArguments(LPCWSTR pszArgs
)
1627 TRACE("(%p)->(args=%s)\n", this, debugstr_w(pszArgs
));
1629 HeapFree(GetProcessHeap(), 0, m_sArgs
);
1632 m_sArgs
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1633 (wcslen(pszArgs
) + 1) * sizeof(WCHAR
));
1635 return E_OUTOFMEMORY
;
1637 wcscpy(m_sArgs
, pszArgs
);
1647 HRESULT STDMETHODCALLTYPE
CShellLink::GetIconLocation(LPWSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1649 TRACE("(%p)->(%p len=%u iicon=%p)\n", this, pszIconPath
, cchIconPath
, piIcon
);
1656 /* Update the original icon path location */
1657 if (m_Header
.dwFlags
& SLDF_HAS_EXP_ICON_SZ
)
1659 WCHAR szPath
[MAX_PATH
];
1661 /* Search for an icon environment block */
1662 LPEXP_SZ_LINK pInfo
;
1663 pInfo
= (LPEXP_SZ_LINK
)SHFindDataBlock(m_pDBList
, EXP_SZ_ICON_SIG
);
1664 if (pInfo
&& (pInfo
->cbSize
== sizeof(*pInfo
)))
1666 m_Header
.dwFlags
&= ~SLDF_HAS_ICONLOCATION
;
1667 HeapFree(GetProcessHeap(), 0, m_sIcoPath
);
1670 SHExpandEnvironmentStringsW(pInfo
->szwTarget
, szPath
, _countof(szPath
));
1672 m_sIcoPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1673 (wcslen(szPath
) + 1) * sizeof(WCHAR
));
1675 return E_OUTOFMEMORY
;
1677 wcscpy(m_sIcoPath
, szPath
);
1678 m_Header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1684 *piIcon
= m_Header
.nIconIndex
;
1687 lstrcpynW(pszIconPath
, m_sIcoPath
, cchIconPath
);
1692 static HRESULT
SHELL_PidlGetIconLocationW(PCIDLIST_ABSOLUTE pidl
,
1693 UINT uFlags
, PWSTR pszIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
1695 LPCITEMIDLIST pidlLast
;
1696 CComPtr
<IShellFolder
> psf
;
1698 HRESULT hr
= SHBindToParent(pidl
, IID_PPV_ARG(IShellFolder
, &psf
), &pidlLast
);
1699 if (FAILED_UNEXPECTEDLY(hr
))
1702 CComPtr
<IExtractIconW
> pei
;
1703 hr
= psf
->GetUIObjectOf(0, 1, &pidlLast
, IID_NULL_PPV_ARG(IExtractIconW
, &pei
));
1704 if (FAILED_UNEXPECTEDLY(hr
))
1707 hr
= pei
->GetIconLocation(uFlags
, pszIconFile
, cchMax
, piIndex
, pwFlags
);
1708 if (FAILED_UNEXPECTEDLY(hr
))
1714 HRESULT STDMETHODCALLTYPE
CShellLink::GetIconLocation(UINT uFlags
, PWSTR pszIconFile
, UINT cchMax
, int *piIndex
, UINT
*pwFlags
)
1718 * It is possible for a shell link to point to another shell link,
1719 * and in particular there is the possibility to point to itself.
1720 * Now, suppose we ask such a link to retrieve its associated icon.
1721 * This function would be called, and due to COM would be called again
1722 * recursively. To solve this issue, we forbid calling GetIconLocation()
1723 * with GIL_FORSHORTCUT set in uFlags, as done by Windows (shown by tests).
1725 if (uFlags
& GIL_FORSHORTCUT
)
1726 return E_INVALIDARG
;
1729 * Now, we set GIL_FORSHORTCUT so that: i) we allow the icon extractor
1730 * of the target to give us a suited icon, and ii) we protect ourselves
1731 * against recursive call.
1733 uFlags
|= GIL_FORSHORTCUT
;
1735 if (m_pPidl
|| m_sPath
)
1737 /* first look for an icon using the PIDL (if present) */
1739 hr
= SHELL_PidlGetIconLocationW(m_pPidl
, uFlags
, pszIconFile
, cchMax
, piIndex
, pwFlags
);
1743 #if 0 // FIXME: Analyse further whether this is needed...
1744 /* if we couldn't find an icon yet, look for it using the file system path */
1745 if (FAILED(hr
) && m_sPath
)
1748 CComPtr
<IShellFolder
> pdsk
;
1750 hr
= SHGetDesktopFolder(&pdsk
);
1752 /* LPITEMIDLIST pidl = ILCreateFromPathW(sPath); */
1753 hr
= pdsk
->ParseDisplayName(0, NULL
, m_sPath
, NULL
, &pidl
, NULL
);
1756 hr
= SHELL_PidlGetIconLocationW(pidl
, uFlags
, pszIconFile
, cchMax
, piIndex
, pwFlags
);
1767 HRESULT STDMETHODCALLTYPE
CShellLink::Extract(PCWSTR pszFile
, UINT nIconIndex
, HICON
*phiconLarge
, HICON
*phiconSmall
, UINT nIconSize
)
1774 /* Extends the functionality of PathUnExpandEnvStringsW */
1775 BOOL
PathFullyUnExpandEnvStringsW(
1776 _In_ LPCWSTR pszPath
,
1777 _Out_ LPWSTR pszBuf
,
1780 BOOL Ret
= FALSE
; // Set to TRUE as soon as PathUnExpandEnvStrings starts unexpanding.
1785 while (*pszPath
&& cchBuf
> 0)
1787 /* Attempt unexpanding the path */
1788 res
= PathUnExpandEnvStringsW(pszPath
, pszBuf
, cchBuf
);
1791 /* The unexpansion failed. Try to find a path delimiter. */
1792 p
= wcspbrk(pszPath
, L
" /\\:*?\"<>|%");
1793 if (!p
) /* None found, we will copy the remaining path */
1794 p
= pszPath
+ wcslen(pszPath
);
1795 else /* Found one, we will copy the delimiter and skip it */
1797 /* If we overflow, we cannot unexpand more, so return FALSE */
1798 if (p
- pszPath
>= cchBuf
)
1799 return FALSE
; // *pszBuf = L'\0';
1801 /* Copy the untouched portion of path up to the delimiter, included */
1802 wcsncpy(pszBuf
, pszPath
, p
- pszPath
);
1803 pszBuf
[p
- pszPath
] = L
'\0'; // NULL-terminate
1805 /* Advance the pointers and decrease the remaining buffer size */
1806 cchBuf
-= (p
- pszPath
);
1807 pszBuf
+= (p
- pszPath
);
1808 pszPath
+= (p
- pszPath
);
1813 * The unexpansion succeeded. Skip the unexpanded part by trying
1814 * to find where the original path and the unexpanded string
1816 * NOTE: An alternative(?) would be to stop also at the last
1817 * path delimiter encountered in the loop (i.e. would be the
1818 * first path delimiter in the strings).
1823 * The algorithm starts at the end of the strings and loops back
1824 * while the characters are equal, until it finds a discrepancy.
1826 p
= pszPath
+ wcslen(pszPath
);
1827 q
= pszBuf
+ wcslen(pszBuf
); // This wcslen should be < cchBuf
1828 while ((*p
== *q
) && (p
> pszPath
) && (q
> pszBuf
))
1832 /* Skip discrepancy */
1835 /* Advance the pointers and decrease the remaining buffer size */
1836 cchBuf
-= (q
- pszBuf
);
1848 HRESULT STDMETHODCALLTYPE
CShellLink::SetIconLocation(LPCWSTR pszIconPath
, INT iIcon
)
1850 HRESULT hr
= E_FAIL
;
1851 WCHAR szUnExpIconPath
[MAX_PATH
];
1853 TRACE("(%p)->(path=%s iicon=%u)\n", this, debugstr_w(pszIconPath
), iIcon
);
1857 /* Try to fully unexpand the icon path */
1860 * Check whether the user-given file path contains unexpanded
1861 * environment variables. If so, create a target environment block.
1862 * Note that in this block we will store the user-given path.
1863 * It will contain the unexpanded environment variables, but
1864 * it can also contain already expanded path that the user does
1865 * not want to see them unexpanded (e.g. so that they always
1866 * refer to the same place even if the would-be corresponding
1867 * environment variable could change).
1869 // FIXME: http://stackoverflow.com/questions/2976489/ishelllinkseticonlocation-translates-my-icon-path-into-program-files-which-i
1870 // if (PathFullyUnExpandEnvStringsW(pszIconPath, szUnExpIconPath, _countof(szUnExpIconPath)))
1871 SHExpandEnvironmentStringsW(pszIconPath
, szUnExpIconPath
, _countof(szUnExpIconPath
));
1872 if (wcscmp(pszIconPath
, szUnExpIconPath
) != 0)
1874 /* Unexpansion succeeded, so we need an icon environment block */
1876 LPEXP_SZ_LINK pInfo
;
1878 pInfo
= (LPEXP_SZ_LINK
)SHFindDataBlock(m_pDBList
, EXP_SZ_ICON_SIG
);
1881 /* Make sure that the size of the structure is valid */
1882 if (pInfo
->cbSize
!= sizeof(*pInfo
))
1884 ERR("Ooops. This structure is not as expected...\n");
1886 /* Invalid structure, remove it altogether */
1887 m_Header
.dwFlags
&= ~SLDF_HAS_EXP_ICON_SZ
;
1888 RemoveDataBlock(EXP_SZ_ICON_SIG
);
1890 /* Reset the pointer and go use the static buffer */
1896 /* Use the static buffer */
1898 buffer
.cbSize
= sizeof(buffer
);
1899 buffer
.dwSignature
= EXP_SZ_ICON_SIG
;
1902 lstrcpynW(pInfo
->szwTarget
, szUnExpIconPath
, _countof(pInfo
->szwTarget
));
1903 WideCharToMultiByte(CP_ACP
, 0, szUnExpIconPath
, -1,
1904 pInfo
->szTarget
, _countof(pInfo
->szTarget
), NULL
, NULL
);
1907 if (pInfo
== &buffer
)
1908 hr
= AddDataBlock(pInfo
);
1910 m_Header
.dwFlags
|= SLDF_HAS_EXP_ICON_SZ
;
1914 /* Unexpansion failed, so we need to remove any icon environment block */
1915 m_Header
.dwFlags
&= ~SLDF_HAS_EXP_ICON_SZ
;
1916 RemoveDataBlock(EXP_SZ_ICON_SIG
);
1920 /* Store the original icon path location (this one may contain unexpanded environment strings) */
1923 m_Header
.dwFlags
&= ~SLDF_HAS_ICONLOCATION
;
1924 HeapFree(GetProcessHeap(), 0, m_sIcoPath
);
1927 m_sIcoPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1928 (wcslen(pszIconPath
) + 1) * sizeof(WCHAR
));
1930 return E_OUTOFMEMORY
;
1932 wcscpy(m_sIcoPath
, pszIconPath
);
1933 m_Header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1938 m_Header
.nIconIndex
= iIcon
;
1944 HRESULT STDMETHODCALLTYPE
CShellLink::SetRelativePath(LPCWSTR pszPathRel
, DWORD dwReserved
)
1946 TRACE("(%p)->(path=%s %x)\n", this, debugstr_w(pszPathRel
), dwReserved
);
1948 HeapFree(GetProcessHeap(), 0, m_sPathRel
);
1951 m_sPathRel
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
1952 (wcslen(pszPathRel
) + 1) * sizeof(WCHAR
));
1954 return E_OUTOFMEMORY
;
1955 wcscpy(m_sPathRel
, pszPathRel
);
1962 return ShellLink_UpdatePath(m_sPathRel
, m_sPath
, m_sWorkDir
, &m_sPath
);
1965 static LPWSTR
GetAdvertisedArg(LPCWSTR str
)
1970 LPCWSTR p
= wcschr(str
, L
':');
1974 DWORD len
= p
- str
;
1975 LPWSTR ret
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * (len
+ 1));
1979 memcpy(ret
, str
, sizeof(WCHAR
)*len
);
1984 HRESULT
CShellLink::WriteAdvertiseInfo(LPCWSTR string
, DWORD dwSig
)
1986 EXP_DARWIN_LINK buffer
;
1987 LPEXP_DARWIN_LINK pInfo
;
1989 if ( (dwSig
!= EXP_DARWIN_ID_SIG
)
1990 #if (NTDDI_VERSION < NTDDI_LONGHORN)
1991 && (dwSig
!= EXP_LOGO3_ID_SIG
)
1995 return E_INVALIDARG
;
2001 pInfo
= (LPEXP_DARWIN_LINK
)SHFindDataBlock(m_pDBList
, dwSig
);
2004 /* Make sure that the size of the structure is valid */
2005 if (pInfo
->dbh
.cbSize
!= sizeof(*pInfo
))
2007 ERR("Ooops. This structure is not as expected...\n");
2009 /* Invalid structure, remove it altogether */
2010 if (dwSig
== EXP_DARWIN_ID_SIG
)
2011 m_Header
.dwFlags
&= ~SLDF_HAS_DARWINID
;
2012 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2013 else if (dwSig
== EXP_LOGO3_ID_SIG
)
2014 m_Header
.dwFlags
&= ~SLDF_HAS_LOGO3ID
;
2016 RemoveDataBlock(dwSig
);
2018 /* Reset the pointer and go use the static buffer */
2024 /* Use the static buffer */
2026 buffer
.dbh
.cbSize
= sizeof(buffer
);
2027 buffer
.dbh
.dwSignature
= dwSig
;
2030 lstrcpynW(pInfo
->szwDarwinID
, string
, _countof(pInfo
->szwDarwinID
));
2031 WideCharToMultiByte(CP_ACP
, 0, string
, -1,
2032 pInfo
->szDarwinID
, _countof(pInfo
->szDarwinID
), NULL
, NULL
);
2035 if (pInfo
== &buffer
)
2036 hr
= AddDataBlock(pInfo
);
2039 if (dwSig
== EXP_DARWIN_ID_SIG
)
2040 m_Header
.dwFlags
|= SLDF_HAS_DARWINID
;
2041 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2042 else if (dwSig
== EXP_LOGO3_ID_SIG
)
2043 m_Header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
2050 HRESULT
CShellLink::SetAdvertiseInfo(LPCWSTR str
)
2053 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2058 /**/sProduct
= sComponent
= NULL
;/**/
2062 /* each segment must start with two colons */
2063 if (str
[0] != ':' || str
[1] != ':')
2066 /* the last segment is just two colons */
2071 /* there must be a colon straight after a guid */
2072 p
= wcschr(str
, L
':');
2079 /* get the guid, and check if it's validly formatted */
2080 memcpy(szGuid
, str
, sizeof(WCHAR
)*len
);
2083 hr
= CLSIDFromString(szGuid
, &guid
);
2088 /* match it up to a guid that we care about */
2089 if (IsEqualGUID(guid
, SHELL32_AdvtShortcutComponent
) && !szComponent
)
2090 szComponent
= str
; /* Darwin */
2091 else if (IsEqualGUID(guid
, SHELL32_AdvtShortcutProduct
) && !szProduct
)
2092 szProduct
= str
; /* Logo3 */
2096 /* skip to the next field */
2097 str
= wcschr(str
, L
':');
2102 /* we have to have a component for an advertised shortcut */
2106 szComponent
= GetAdvertisedArg(szComponent
);
2107 szProduct
= GetAdvertisedArg(szProduct
);
2109 hr
= WriteAdvertiseInfo(szComponent
, EXP_DARWIN_ID_SIG
);
2112 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2113 hr
= WriteAdvertiseInfo(szProduct
, EXP_LOGO3_ID_SIG
);
2118 HeapFree(GetProcessHeap(), 0, (PVOID
)szComponent
);
2119 HeapFree(GetProcessHeap(), 0, (PVOID
)szProduct
);
2121 if (TRACE_ON(shell
))
2123 GetAdvertiseInfo(&sComponent
, EXP_DARWIN_ID_SIG
);
2124 TRACE("Component = %s\n", debugstr_w(sComponent
));
2125 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2126 GetAdvertiseInfo(&sProduct
, EXP_LOGO3_ID_SIG
);
2127 TRACE("Product = %s\n", debugstr_w(sProduct
));
2135 * Since the real PathResolve (from Wine) is unimplemented at the moment,
2136 * we use this local implementation, until a better one is written (using
2137 * code parts of the SHELL_xxx helpers in Wine's shellpath.c).
2139 static BOOL
HACKISH_PathResolve(
2140 IN OUT PWSTR pszPath
,
2141 IN PZPCWSTR dirs OPTIONAL
,
2144 // FIXME: This is unimplemented!!!
2146 return PathResolve(pszPath
, dirs
, fFlags
);
2148 BOOL Success
= FALSE
;
2150 LPWSTR fname
= NULL
;
2151 WCHAR szPath
[MAX_PATH
];
2153 /* First, search for a valid existing path */
2155 // NOTE: See also: SHELL_FindExecutable()
2158 * List of extensions searched for, by PathResolve with the flag
2159 * PRF_TRYPROGRAMEXTENSIONS == PRF_EXECUTABLE | PRF_VERIFYEXISTS set,
2160 * according to MSDN: https://msdn.microsoft.com/en-us/library/windows/desktop/bb776478(v=vs.85).aspx
2162 static PCWSTR Extensions
[] = {L
".pif", L
".com", L
".bat", L
".cmd", L
".lnk", L
".exe", NULL
};
2163 #define LNK_EXT_INDEX 4 // ".lnk" has index 4 in the array above
2166 * Start at the beginning of the list if PRF_EXECUTABLE is set, otherwise
2167 * just use the last element 'NULL' (no extension checking).
2169 i
= ((fFlags
& PRF_EXECUTABLE
) ? 0 : _countof(Extensions
) - 1);
2170 for (; i
< _countof(Extensions
); ++i
)
2172 /* Ignore shell links ".lnk" if needed */
2173 if ((fFlags
& PRF_DONTFINDLNK
) && (i
== LNK_EXT_INDEX
))
2176 Success
= (SearchPathW(NULL
, pszPath
, Extensions
[i
],
2177 _countof(szPath
), szPath
, NULL
) != 0);
2180 ERR("SearchPathW(pszPath = '%S') failed\n", pszPath
);
2184 ERR("SearchPathW(pszPath = '%S', szPath = '%S') succeeded\n", pszPath
, szPath
);
2191 ERR("SearchPathW(pszPath = '%S') failed\n", pszPath
);
2193 /* We failed, try with PathFindOnPath, as explained by MSDN */
2194 // Success = PathFindOnPathW(pszPath, dirs);
2195 StringCchCopyW(szPath
, _countof(szPath
), pszPath
);
2196 Success
= PathFindOnPathW(szPath
, dirs
);
2199 ERR("PathFindOnPathW(pszPath = '%S') failed\n", pszPath
);
2201 /* We failed again, fall back to building a possible non-existing path */
2202 if (!GetFullPathNameW(pszPath
, _countof(szPath
), szPath
, &fname
))
2204 ERR("GetFullPathNameW(pszPath = '%S') failed\n", pszPath
);
2208 Success
= PathFileExistsW(szPath
);
2210 ERR("PathFileExistsW(szPath = '%S') failed\n", szPath
);
2212 /******************************************************/
2213 /* Question: Why this line is needed only for files?? */
2214 if (fname
&& (_wcsicmp(pszPath
, fname
) == 0))
2216 /******************************************************/
2220 ERR("PathFindOnPathW(pszPath = '%S' ==> '%S') succeeded\n", pszPath
, szPath
);
2224 /* Copy back the results to the caller */
2225 StringCchCopyW(pszPath
, MAX_PATH
, szPath
);
2228 * Since the called functions always checked whether the file path existed,
2229 * we do not need to redo a final check: we can use instead the cached
2230 * result in 'Success'.
2232 return ((fFlags
& PRF_VERIFYEXISTS
) ? Success
: TRUE
);
2236 HRESULT
CShellLink::SetTargetFromPIDLOrPath(LPCITEMIDLIST pidl
, LPCWSTR pszFile
)
2239 LPITEMIDLIST pidlNew
= NULL
;
2240 WCHAR szPath
[MAX_PATH
];
2243 * Not both 'pidl' and 'pszFile' should be set.
2244 * But either one or both can be NULL.
2246 if (pidl
&& pszFile
)
2251 /* Clone the PIDL */
2252 pidlNew
= ILClone(pidl
);
2258 /* Build a PIDL for this path target */
2259 hr
= SHILCreateFromPathW(pszFile
, &pidlNew
, NULL
);
2262 /* This failed, try to resolve the path, then create a simple PIDL */
2264 StringCchCopyW(szPath
, _countof(szPath
), pszFile
);
2265 // FIXME: Because PathResolve is unimplemented, we use our hackish implementation!
2266 HACKISH_PathResolve(szPath
, NULL
, PRF_TRYPROGRAMEXTENSIONS
);
2268 pidlNew
= SHSimpleIDListFromPathW(szPath
);
2269 /******************************************************/
2270 /* Question: Why this line is needed only for files?? */
2271 hr
= (*szPath
? S_OK
: E_INVALIDARG
); // S_FALSE
2272 /******************************************************/
2275 // else if (!pidl && !pszFile) { pidlNew = NULL; hr = S_OK; }
2282 if (SHGetPathFromIDListW(pidlNew
, szPath
))
2286 // TODO: Fully update link info, tracker, file attribs...
2295 /* Update the cached path (for link info) */
2296 ShellLink_GetVolumeInfo(pszFile
, &volume
);
2297 m_sPath
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0,
2298 (wcslen(pszFile
) + 1) * sizeof(WCHAR
));
2300 return E_OUTOFMEMORY
;
2301 wcscpy(m_sPath
, pszFile
);
2307 HRESULT STDMETHODCALLTYPE
CShellLink::SetPath(LPCWSTR pszFile
)
2309 LPWSTR unquoted
= NULL
;
2312 TRACE("(%p)->(path=%s)\n", this, debugstr_w(pszFile
));
2315 return E_INVALIDARG
;
2318 * Allow upgrading Logo3 shortcuts (m_Header.dwFlags & SLDF_HAS_LOGO3ID),
2319 * but forbid upgrading Darwin ones.
2321 if (m_Header
.dwFlags
& SLDF_HAS_DARWINID
)
2324 /* quotes at the ends of the string are stripped */
2325 SIZE_T len
= wcslen(pszFile
);
2326 if (pszFile
[0] == L
'"' && pszFile
[len
-1] == L
'"')
2328 unquoted
= strdupW(pszFile
);
2329 PathUnquoteSpacesW(unquoted
);
2333 /* any other quote marks are invalid */
2334 if (wcschr(pszFile
, L
'"'))
2340 /* Clear the cached path */
2341 HeapFree(GetProcessHeap(), 0, m_sPath
);
2344 /* Check for an advertised target (Logo3 or Darwin) */
2345 if (SetAdvertiseInfo(pszFile
) != S_OK
)
2347 /* This is not an advertised target, but a regular path */
2348 WCHAR szPath
[MAX_PATH
];
2351 * Check whether the user-given file path contains unexpanded
2352 * environment variables. If so, create a target environment block.
2353 * Note that in this block we will store the user-given path.
2354 * It will contain the unexpanded environment variables, but
2355 * it can also contain already expanded path that the user does
2356 * not want to see them unexpanded (e.g. so that they always
2357 * refer to the same place even if the would-be corresponding
2358 * environment variable could change).
2361 SHExpandEnvironmentStringsW(pszFile
, szPath
, _countof(szPath
));
2365 if (*pszFile
&& (wcscmp(pszFile
, szPath
) != 0))
2368 * The user-given file path contains unexpanded environment
2369 * variables, so we need a target environment block.
2372 LPEXP_SZ_LINK pInfo
;
2374 pInfo
= (LPEXP_SZ_LINK
)SHFindDataBlock(m_pDBList
, EXP_SZ_LINK_SIG
);
2377 /* Make sure that the size of the structure is valid */
2378 if (pInfo
->cbSize
!= sizeof(*pInfo
))
2380 ERR("Ooops. This structure is not as expected...\n");
2382 /* Invalid structure, remove it altogether */
2383 m_Header
.dwFlags
&= ~SLDF_HAS_EXP_SZ
;
2384 RemoveDataBlock(EXP_SZ_LINK_SIG
);
2386 /* Reset the pointer and go use the static buffer */
2392 /* Use the static buffer */
2394 buffer
.cbSize
= sizeof(buffer
);
2395 buffer
.dwSignature
= EXP_SZ_LINK_SIG
;
2398 lstrcpynW(pInfo
->szwTarget
, pszFile
, _countof(pInfo
->szwTarget
));
2399 WideCharToMultiByte(CP_ACP
, 0, pszFile
, -1,
2400 pInfo
->szTarget
, _countof(pInfo
->szTarget
), NULL
, NULL
);
2403 if (pInfo
== &buffer
)
2404 hr
= AddDataBlock(pInfo
);
2406 m_Header
.dwFlags
|= SLDF_HAS_EXP_SZ
;
2408 /* Now, make pszFile point to the expanded buffer */
2414 * The user-given file path does not contain unexpanded environment
2415 * variables, so we need to remove any target environment block.
2417 m_Header
.dwFlags
&= ~SLDF_HAS_EXP_SZ
;
2418 RemoveDataBlock(EXP_SZ_LINK_SIG
);
2420 /* pszFile points to the user path */
2423 /* Set the target */
2424 hr
= SetTargetFromPIDLOrPath(NULL
, pszFile
);
2430 HeapFree(GetProcessHeap(), 0, unquoted
);
2434 HRESULT STDMETHODCALLTYPE
CShellLink::AddDataBlock(void* pDataBlock
)
2436 if (SHAddDataBlock(&m_pDBList
, (DATABLOCK_HEADER
*)pDataBlock
))
2444 HRESULT STDMETHODCALLTYPE
CShellLink::CopyDataBlock(DWORD dwSig
, void** ppDataBlock
)
2446 DATABLOCK_HEADER
* pBlock
;
2449 TRACE("%p %08x %p\n", this, dwSig
, ppDataBlock
);
2451 *ppDataBlock
= NULL
;
2453 pBlock
= SHFindDataBlock(m_pDBList
, dwSig
);
2456 ERR("unknown datablock %08x (not found)\n", dwSig
);
2460 pDataBlock
= LocalAlloc(LMEM_ZEROINIT
, pBlock
->cbSize
);
2462 return E_OUTOFMEMORY
;
2464 CopyMemory(pDataBlock
, pBlock
, pBlock
->cbSize
);
2466 *ppDataBlock
= pDataBlock
;
2470 HRESULT STDMETHODCALLTYPE
CShellLink::RemoveDataBlock(DWORD dwSig
)
2472 if (SHRemoveDataBlock(&m_pDBList
, dwSig
))
2480 HRESULT STDMETHODCALLTYPE
CShellLink::GetFlags(DWORD
*pdwFlags
)
2482 TRACE("%p %p\n", this, pdwFlags
);
2483 *pdwFlags
= m_Header
.dwFlags
;
2487 HRESULT STDMETHODCALLTYPE
CShellLink::SetFlags(DWORD dwFlags
)
2490 m_Header
.dwFlags
= dwFlags
;
2499 /**************************************************************************
2500 * CShellLink implementation of IShellExtInit::Initialize()
2502 * Loads the shelllink from the dataobject the shell is pointing to.
2504 HRESULT STDMETHODCALLTYPE
CShellLink::Initialize(LPCITEMIDLIST pidlFolder
, IDataObject
*pdtobj
, HKEY hkeyProgID
)
2506 TRACE("%p %p %p %p\n", this, pidlFolder
, pdtobj
, hkeyProgID
);
2512 format
.cfFormat
= CF_HDROP
;
2514 format
.dwAspect
= DVASPECT_CONTENT
;
2516 format
.tymed
= TYMED_HGLOBAL
;
2519 HRESULT hr
= pdtobj
->GetData(&format
, &stgm
);
2523 UINT count
= DragQueryFileW((HDROP
)stgm
.hGlobal
, -1, NULL
, 0);
2526 count
= DragQueryFileW((HDROP
)stgm
.hGlobal
, 0, NULL
, 0);
2528 LPWSTR path
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
));
2531 count
= DragQueryFileW((HDROP
)stgm
.hGlobal
, 0, path
, count
);
2533 HeapFree(GetProcessHeap(), 0, path
);
2536 ReleaseStgMedium(&stgm
);
2541 HRESULT STDMETHODCALLTYPE
CShellLink::QueryContextMenu(HMENU hMenu
, UINT indexMenu
, UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2545 TRACE("%p %p %u %u %u %u\n", this,
2546 hMenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2549 return E_INVALIDARG
;
2552 if (!LoadStringW(shell32_hInstance
, IDS_OPEN_VERB
, wszOpen
, _countof(wszOpen
)))
2556 ZeroMemory(&mii
, sizeof(mii
));
2557 mii
.cbSize
= sizeof(mii
);
2558 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2559 mii
.dwTypeData
= wszOpen
;
2560 mii
.cch
= wcslen(mii
.dwTypeData
);
2561 mii
.wID
= idCmdFirst
+ id
++;
2562 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2563 mii
.fType
= MFT_STRING
;
2564 if (!InsertMenuItemW(hMenu
, indexMenu
, TRUE
, &mii
))
2568 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, id
);
2571 HRESULT STDMETHODCALLTYPE
CShellLink::InvokeCommand(LPCMINVOKECOMMANDINFO lpici
)
2576 TRACE("%p %p\n", this, lpici
);
2578 if (lpici
->cbSize
< sizeof(CMINVOKECOMMANDINFO
))
2579 return E_INVALIDARG
;
2581 // NOTE: We could use lpici->hwnd (certainly in case lpici->fMask doesn't contain CMIC_MASK_FLAG_NO_UI)
2582 // as the parent window handle... ?
2583 /* FIXME: get using interface set from IObjectWithSite?? */
2584 // NOTE: We might need an extended version of Resolve that provides us with paths...
2585 HRESULT hr
= Resolve(lpici
->hwnd
, 0);
2588 TRACE("failed to resolve component with error 0x%08x", hr
);
2592 path
= strdupW(m_sPath
);
2594 if ( lpici
->cbSize
== sizeof(CMINVOKECOMMANDINFOEX
) &&
2595 (lpici
->fMask
& CMIC_MASK_UNICODE
) )
2597 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
)lpici
;
2601 len
+= wcslen(m_sArgs
);
2602 if (iciex
->lpParametersW
)
2603 len
+= wcslen(iciex
->lpParametersW
);
2605 args
= (LPWSTR
)HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
2608 wcscat(args
, m_sArgs
);
2609 if (iciex
->lpParametersW
)
2612 wcscat(args
, iciex
->lpParametersW
);
2615 else if (m_sArgs
!= NULL
)
2617 args
= strdupW(m_sArgs
);
2620 SHELLEXECUTEINFOW sei
;
2621 ZeroMemory(&sei
, sizeof(sei
));
2622 sei
.cbSize
= sizeof(sei
);
2623 sei
.fMask
= SEE_MASK_HASLINKNAME
| SEE_MASK_UNICODE
|
2624 (lpici
->fMask
& (SEE_MASK_NOASYNC
| SEE_MASK_ASYNCOK
| SEE_MASK_FLAG_NO_UI
));
2626 sei
.lpClass
= m_sLinkPath
;
2627 sei
.nShow
= m_Header
.nShowCommand
;
2628 sei
.lpDirectory
= m_sWorkDir
;
2629 sei
.lpParameters
= args
;
2630 sei
.lpVerb
= L
"open";
2632 // HACK for ShellExecuteExW
2633 if (m_sPath
&& wcsstr(m_sPath
, L
".cpl"))
2634 sei
.lpVerb
= L
"cplopen";
2636 if (ShellExecuteExW(&sei
))
2641 HeapFree(GetProcessHeap(), 0, args
);
2642 HeapFree(GetProcessHeap(), 0, path
);
2647 HRESULT STDMETHODCALLTYPE
CShellLink::GetCommandString(UINT_PTR idCmd
, UINT uType
, UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2649 FIXME("%p %lu %u %p %p %u\n", this, idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2653 INT_PTR CALLBACK
ExtendedShortcutProc(HWND hwndDlg
, UINT uMsg
,
2654 WPARAM wParam
, LPARAM lParam
)
2661 HWND hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2662 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2667 HWND hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2668 if (LOWORD(wParam
) == IDOK
)
2670 if (SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2671 EndDialog(hwndDlg
, 1);
2673 EndDialog(hwndDlg
, 0);
2675 else if (LOWORD(wParam
) == IDCANCEL
)
2677 EndDialog(hwndDlg
, -1);
2679 else if (LOWORD(wParam
) == 14000)
2681 if (SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2682 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2684 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2693 SHOpenFolderAndSelectItems(LPITEMIDLIST pidlFolder
,
2695 PCUITEMID_CHILD_ARRAY apidl
,
2698 /**************************************************************************
2699 * SH_GetTargetTypeByPath
2701 * Function to get target type by passing full path to it
2703 LPWSTR
SH_GetTargetTypeByPath(LPCWSTR lpcwFullPath
)
2706 static WCHAR wszBuf
[MAX_PATH
];
2708 /* Get file information */
2710 if (!SHGetFileInfoW(lpcwFullPath
, 0, &fi
, sizeof(fi
), SHGFI_TYPENAME
| SHGFI_USEFILEATTRIBUTES
))
2712 ERR("SHGetFileInfoW failed for %ls (%lu)\n", lpcwFullPath
, GetLastError());
2713 fi
.szTypeName
[0] = L
'\0';
2717 pwszExt
= PathFindExtensionW(lpcwFullPath
);
2720 if (!fi
.szTypeName
[0])
2722 /* The file type is unknown, so default to string "FileExtension File" */
2723 size_t cchRemaining
= 0;
2724 LPWSTR pwszEnd
= NULL
;
2726 StringCchPrintfExW(wszBuf
, _countof(wszBuf
), &pwszEnd
, &cchRemaining
, 0, L
"%s ", pwszExt
+ 1);
2730 /* Update file type */
2731 StringCbPrintfW(wszBuf
, sizeof(wszBuf
), L
"%s (%s)", fi
.szTypeName
, pwszExt
);
2738 /**************************************************************************
2739 * SH_ShellLinkDlgProc
2741 * dialog proc of the shortcut property dialog
2744 INT_PTR CALLBACK
CShellLink::SH_ShellLinkDlgProc(HWND hwndDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
2746 CShellLink
*pThis
= reinterpret_cast<CShellLink
*>(GetWindowLongPtr(hwndDlg
, DWLP_USER
));
2752 LPPROPSHEETPAGEW ppsp
= (LPPROPSHEETPAGEW
)lParam
;
2756 TRACE("ShellLink_DlgProc (WM_INITDIALOG hwnd %p lParam %p ppsplParam %x)\n", hwndDlg
, lParam
, ppsp
->lParam
);
2758 pThis
= reinterpret_cast<CShellLink
*>(ppsp
->lParam
);
2759 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pThis
);
2761 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
,
2762 pThis
->m_sIcoPath
, pThis
->m_sPath
, pThis
->m_sPathRel
, pThis
->sProduct
, pThis
->m_sWorkDir
);
2764 /* Get file information */
2765 // FIXME! FIXME! Shouldn't we use pThis->m_sIcoPath, pThis->m_Header.nIconIndex instead???
2767 if (!SHGetFileInfoW(pThis
->m_sLinkPath
, 0, &fi
, sizeof(fi
), SHGFI_TYPENAME
| SHGFI_ICON
))
2769 ERR("SHGetFileInfoW failed for %ls (%lu)\n", pThis
->m_sLinkPath
, GetLastError());
2770 fi
.szTypeName
[0] = L
'\0';
2774 if (fi
.hIcon
) // TODO: destroy icon
2775 SendDlgItemMessageW(hwndDlg
, 14000, STM_SETICON
, (WPARAM
)fi
.hIcon
, 0);
2777 ERR("ExtractIconW failed %ls %u\n", pThis
->m_sIcoPath
, pThis
->m_Header
.nIconIndex
);
2781 SetDlgItemTextW(hwndDlg
, 14005, SH_GetTargetTypeByPath(pThis
->m_sPath
));
2783 /* Target location */
2786 WCHAR target
[MAX_PATH
];
2787 StringCchCopyW(target
, _countof(target
), pThis
->m_sPath
);
2788 PathRemoveFileSpecW(target
);
2789 SetDlgItemTextW(hwndDlg
, 14007, PathFindFileNameW(target
));
2795 WCHAR newpath
[2*MAX_PATH
] = L
"\0";
2796 if (wcschr(pThis
->m_sPath
, ' '))
2797 StringCchPrintfExW(newpath
, _countof(newpath
), NULL
, NULL
, 0, L
"\"%ls\"", pThis
->m_sPath
);
2799 StringCchCopyExW(newpath
, _countof(newpath
), pThis
->m_sPath
, NULL
, NULL
, 0);
2801 if (pThis
->m_sArgs
&& pThis
->m_sArgs
[0])
2803 StringCchCatW(newpath
, _countof(newpath
), L
" ");
2804 StringCchCatW(newpath
, _countof(newpath
), pThis
->m_sArgs
);
2806 SetDlgItemTextW(hwndDlg
, 14009, newpath
);
2810 if (pThis
->m_sWorkDir
)
2811 SetDlgItemTextW(hwndDlg
, 14011, pThis
->m_sWorkDir
);
2814 if (pThis
->m_sDescription
)
2815 SetDlgItemTextW(hwndDlg
, 14019, pThis
->m_sDescription
);
2822 LPPSHNOTIFY lppsn
= (LPPSHNOTIFY
)lParam
;
2823 if (lppsn
->hdr
.code
== PSN_APPLY
)
2825 WCHAR wszBuf
[MAX_PATH
];
2826 /* set working directory */
2827 GetDlgItemTextW(hwndDlg
, 14011, wszBuf
, _countof(wszBuf
));
2828 pThis
->SetWorkingDirectory(wszBuf
);
2829 /* set link destination */
2830 GetDlgItemTextW(hwndDlg
, 14009, wszBuf
, _countof(wszBuf
));
2831 LPWSTR lpszArgs
= NULL
;
2832 LPWSTR unquoted
= strdupW(wszBuf
);
2833 StrTrimW(unquoted
, L
" ");
2834 if (!PathFileExistsW(unquoted
))
2836 lpszArgs
= PathGetArgsW(unquoted
);
2837 PathRemoveArgsW(unquoted
);
2838 StrTrimW(lpszArgs
, L
" ");
2840 if (unquoted
[0] == '"' && unquoted
[wcslen(unquoted
)-1] == '"')
2841 PathUnquoteSpacesW(unquoted
);
2844 WCHAR
*pwszExt
= PathFindExtensionW(unquoted
);
2845 if (!wcsicmp(pwszExt
, L
".lnk"))
2847 // FIXME load localized error msg
2848 MessageBoxW(hwndDlg
, L
"You cannot create a link to a shortcut", L
"Error", MB_ICONERROR
);
2849 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2853 if (!PathFileExistsW(unquoted
))
2855 // FIXME load localized error msg
2856 MessageBoxW(hwndDlg
, L
"The specified file name in the target box is invalid", L
"Error", MB_ICONERROR
);
2857 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2861 pThis
->SetPath(unquoted
);
2863 pThis
->SetArguments(lpszArgs
);
2865 pThis
->SetArguments(L
"\0");
2867 HeapFree(GetProcessHeap(), 0, unquoted
);
2869 TRACE("This %p m_sLinkPath %S\n", pThis
, pThis
->m_sLinkPath
);
2870 pThis
->Save(pThis
->m_sLinkPath
, TRUE
);
2871 SetWindowLongPtr(hwndDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
2878 switch(LOWORD(wParam
))
2881 SHOpenFolderAndSelectItems(pThis
->m_pPidl
, 0, NULL
, 0);
2884 /// open target directory
2890 WCHAR wszPath
[MAX_PATH
] = L
"";
2892 if (pThis
->m_sIcoPath
)
2893 wcscpy(wszPath
, pThis
->m_sIcoPath
);
2894 INT IconIndex
= pThis
->m_Header
.nIconIndex
;
2895 if (PickIconDlg(hwndDlg
, wszPath
, _countof(wszPath
), &IconIndex
))
2897 pThis
->SetIconLocation(wszPath
, IconIndex
);
2899 /// FIXME redraw icon
2907 INT_PTR result
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(IDD_SHORTCUT_EXTENDED_PROPERTIES
), hwndDlg
, ExtendedShortcutProc
, (LPARAM
)pThis
->m_bRunAs
);
2908 if (result
== 1 || result
== 0)
2910 if (pThis
->m_bRunAs
!= result
)
2912 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2915 pThis
->m_bRunAs
= result
;
2920 if (HIWORD(wParam
) == EN_CHANGE
)
2921 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2930 /**************************************************************************
2931 * ShellLink_IShellPropSheetExt interface
2934 HRESULT STDMETHODCALLTYPE
CShellLink::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage
, LPARAM lParam
)
2936 HPROPSHEETPAGE hPage
= SH_CreatePropertySheetPage(IDD_SHORTCUT_PROPERTIES
, SH_ShellLinkDlgProc
, (LPARAM
)this, NULL
);
2939 ERR("failed to create property sheet page\n");
2943 if (!pfnAddPage(hPage
, lParam
))
2949 HRESULT STDMETHODCALLTYPE
CShellLink::ReplacePage(UINT uPageID
, LPFNADDPROPSHEETPAGE pfnReplacePage
, LPARAM lParam
)
2951 TRACE("(%p) (uPageID %u, pfnReplacePage %p lParam %p\n", this, uPageID
, pfnReplacePage
, lParam
);
2955 HRESULT STDMETHODCALLTYPE
CShellLink::SetSite(IUnknown
*punk
)
2957 TRACE("%p %p\n", this, punk
);
2964 HRESULT STDMETHODCALLTYPE
CShellLink::GetSite(REFIID iid
, void ** ppvSite
)
2966 TRACE("%p %s %p\n", this, debugstr_guid(&iid
), ppvSite
);
2971 return m_site
->QueryInterface(iid
, ppvSite
);
2974 HRESULT STDMETHODCALLTYPE
CShellLink::DragEnter(IDataObject
*pDataObject
,
2975 DWORD dwKeyState
, POINTL pt
, DWORD
*pdwEffect
)
2977 TRACE("(%p)->(DataObject=%p)\n", this, pDataObject
);
2978 LPCITEMIDLIST pidlLast
;
2979 CComPtr
<IShellFolder
> psf
;
2981 HRESULT hr
= SHBindToParent(m_pPidl
, IID_PPV_ARG(IShellFolder
, &psf
), &pidlLast
);
2985 hr
= psf
->GetUIObjectOf(0, 1, &pidlLast
, IID_NULL_PPV_ARG(IDropTarget
, &m_DropTarget
));
2988 hr
= m_DropTarget
->DragEnter(pDataObject
, dwKeyState
, pt
, pdwEffect
);
2990 *pdwEffect
= DROPEFFECT_NONE
;
2993 *pdwEffect
= DROPEFFECT_NONE
;
2998 HRESULT STDMETHODCALLTYPE
CShellLink::DragOver(DWORD dwKeyState
, POINTL pt
,
3001 TRACE("(%p)\n", this);
3004 hr
= m_DropTarget
->DragOver(dwKeyState
, pt
, pdwEffect
);
3008 HRESULT STDMETHODCALLTYPE
CShellLink::DragLeave()
3010 TRACE("(%p)\n", this);
3014 hr
= m_DropTarget
->DragLeave();
3015 m_DropTarget
.Release();
3021 HRESULT STDMETHODCALLTYPE
CShellLink::Drop(IDataObject
*pDataObject
,
3022 DWORD dwKeyState
, POINTL pt
, DWORD
*pdwEffect
)
3024 TRACE("(%p)\n", this);
3027 hr
= m_DropTarget
->Drop(pDataObject
, dwKeyState
, pt
, pdwEffect
);
3032 /**************************************************************************
3033 * IShellLink_ConstructFromFile
3035 HRESULT WINAPI
IShellLink_ConstructFromPath(WCHAR
*path
, REFIID riid
, LPVOID
*ppv
)
3037 CComPtr
<IPersistFile
> ppf
;
3038 HRESULT hr
= CShellLink::_CreatorClass::CreateInstance(NULL
, IID_PPV_ARG(IPersistFile
, &ppf
));
3042 hr
= ppf
->Load(path
, 0);
3046 return ppf
->QueryInterface(riid
, ppv
);
3049 HRESULT WINAPI
IShellLink_ConstructFromFile(IShellFolder
* psf
, LPCITEMIDLIST pidl
, REFIID riid
, LPVOID
*ppv
)
3051 WCHAR path
[MAX_PATH
];
3052 if (!ILGetDisplayNameExW(psf
, pidl
, path
, 0))
3055 return IShellLink_ConstructFromPath(path
, riid
, ppv
);