3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Nearly complete information about the binary formats
23 * of .lnk files available at http://www.wotsit.org
25 * You can use winedump to examine the contents of a link file:
28 * MSI advertised shortcuts are totally undocumented. They provide an
29 * icon for a program that is not yet installed, and invoke MSI to
30 * install the program when the shortcut is clicked on. They are
31 * created by passing a special string to SetPath, and the information
32 * in that string is parsed an stored.
37 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
39 /* link file formats */
43 typedef struct _LINK_HEADER
45 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
46 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
47 DWORD dwFlags
; /* 0x14 describes elements following */
48 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
49 FILETIME Time1
; /* 0x1c */
50 FILETIME Time2
; /* 0x24 */
51 FILETIME Time3
; /* 0x2c */
52 DWORD dwFileLength
; /* 0x34 File length */
53 DWORD nIcon
; /* 0x38 icon number */
54 DWORD fStartup
; /* 0x3c startup type */
55 DWORD wHotKey
; /* 0x40 hotkey */
56 DWORD Unknown5
; /* 0x44 */
57 DWORD Unknown6
; /* 0x48 */
58 } LINK_HEADER
, * PLINK_HEADER
;
60 #define SHLINK_LOCAL 0
61 #define SHLINK_REMOTE 1
62 #define MAX_PROPERTY_SHEET_PAGE 32
64 typedef struct _LOCATION_INFO
71 DWORD dwNetworkVolTableOfs
;
75 typedef struct _LOCAL_VOLUME_INFO
83 typedef struct volume_info_t
87 WCHAR label
[12]; /* assume 8.3 */
92 static const IShellLinkAVtbl slvt
;
93 static const IShellLinkWVtbl slvtw
;
94 static const IPersistFileVtbl pfvt
;
95 static const IPersistStreamVtbl psvt
;
96 static const IShellLinkDataListVtbl dlvt
;
97 static const IShellExtInitVtbl eivt
;
98 static const IContextMenuVtbl cmvt
;
99 static const IObjectWithSiteVtbl owsvt
;
100 static const IShellPropSheetExtVtbl pse
;
102 /* IShellLink Implementation */
106 const IShellLinkAVtbl
*lpVtbl
;
107 const IShellLinkWVtbl
*lpvtblw
;
108 const IPersistFileVtbl
*lpvtblPersistFile
;
109 const IPersistStreamVtbl
*lpvtblPersistStream
;
110 const IShellLinkDataListVtbl
*lpvtblShellLinkDataList
;
111 const IShellExtInitVtbl
*lpvtblShellExtInit
;
112 const IContextMenuVtbl
*lpvtblContextMenu
;
113 const IObjectWithSiteVtbl
*lpvtblObjectWithSite
;
114 const IShellPropSheetExtVtbl
* lpvtblPropSheetExt
;
118 /* data structures according to the information in the link */
139 INT iIdOpen
; /* id of the "Open" entry in the context menu */
141 } IShellLinkImpl
, *LPIShellLinkImpl
;
143 static LPIShellLinkImpl __inline
impl_from_IShellLinkW( IShellLinkW
*iface
)
145 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblw
));
148 static LPIShellLinkImpl __inline
impl_from_IPersistFile( IPersistFile
*iface
)
150 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistFile
));
153 static LPIShellLinkImpl __inline
impl_from_IPersistStream( IPersistStream
*iface
)
155 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistStream
));
158 static LPIShellLinkImpl __inline
impl_from_IShellLinkDataList( IShellLinkDataList
*iface
)
160 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellLinkDataList
));
163 static LPIShellLinkImpl __inline
impl_from_IShellExtInit( IShellExtInit
*iface
)
165 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellExtInit
));
168 static LPIShellLinkImpl __inline
impl_from_IContextMenu( IContextMenu
*iface
)
170 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblContextMenu
));
173 static LPIShellLinkImpl __inline
impl_from_IObjectWithSite( IObjectWithSite
*iface
)
175 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblObjectWithSite
));
178 static LPIShellLinkImpl __inline
impl_from_IShellPropSheetExt( IShellPropSheetExt
*iface
)
180 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPropSheetExt
));
184 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
186 /* strdup on the process heap */
187 static LPWSTR __inline
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
189 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
190 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
193 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
197 static LPWSTR __inline
strdupW( LPCWSTR src
)
200 if (!src
) return NULL
;
201 dest
= HeapAlloc( GetProcessHeap(), 0, (wcslen(src
)+1)*sizeof(WCHAR
) );
207 /**************************************************************************
208 * ShellLink::QueryInterface implementation
210 static HRESULT
ShellLink_QueryInterface( IShellLinkImpl
*This
, REFIID riid
, LPVOID
*ppvObj
)
212 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
216 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
220 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
222 *ppvObj
= &(This
->lpvtblw
);
224 else if(IsEqualIID(riid
, &IID_IPersistFile
))
226 *ppvObj
= &(This
->lpvtblPersistFile
);
228 else if(IsEqualIID(riid
, &IID_IPersistStream
))
230 *ppvObj
= &(This
->lpvtblPersistStream
);
232 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
234 *ppvObj
= &(This
->lpvtblShellLinkDataList
);
236 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
238 *ppvObj
= &(This
->lpvtblShellExtInit
);
240 else if(IsEqualIID(riid
, &IID_IContextMenu
))
242 *ppvObj
= &(This
->lpvtblContextMenu
);
244 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
246 *ppvObj
= &(This
->lpvtblObjectWithSite
);
248 else if(IsEqualIID(riid
, &IID_IShellPropSheetExt
))
250 *ppvObj
= &(This
->lpvtblPropSheetExt
);
255 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
256 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
259 ERR("-- Interface: E_NOINTERFACE\n");
260 return E_NOINTERFACE
;
263 /**************************************************************************
264 * ShellLink::AddRef implementation
266 static ULONG
ShellLink_AddRef( IShellLinkImpl
*This
)
268 ULONG refCount
= InterlockedIncrement(&This
->ref
);
270 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
275 /**************************************************************************
276 * ShellLink::Release implementation
278 static ULONG
ShellLink_Release( IShellLinkImpl
*This
)
280 ULONG refCount
= InterlockedDecrement(&This
->ref
);
282 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
287 TRACE("-- destroying IShellLink(%p)\n",This
);
289 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
290 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
291 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
292 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
293 HeapFree(GetProcessHeap(),0,This
->sPath
);
294 HeapFree(GetProcessHeap(),0,This
->sLinkPath
);
297 IUnknown_Release( This
->site
);
307 static HRESULT
ShellLink_GetClassID( IShellLinkImpl
*This
, CLSID
*pclsid
)
309 TRACE("%p %p\n", This
, pclsid
);
311 *pclsid
= CLSID_ShellLink
;
315 /**************************************************************************
316 * IPersistFile_QueryInterface
318 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
323 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
324 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
327 /******************************************************************************
328 * IPersistFile_AddRef
330 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
332 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
333 return ShellLink_AddRef( This
);
336 /******************************************************************************
337 * IPersistFile_Release
339 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
341 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
342 return IShellLinkA_Release((IShellLinkA
*)This
);
345 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
347 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
348 return ShellLink_GetClassID( This
, pClassID
);
351 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
353 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
355 TRACE("(%p)\n",This
);
363 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
365 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
366 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
370 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
373 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
374 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
377 HeapFree(GetProcessHeap(), 0, This
->sLinkPath
);
378 This
->sLinkPath
= strdupW(pszFileName
);
379 r
= IPersistStream_Load(StreamThis
, stm
);
380 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
381 IStream_Release( stm
);
382 This
->bDirty
= FALSE
;
384 TRACE("-- returning hr %08x\n", r
);
388 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
390 static const WCHAR szFormat
[] = {
391 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
392 ' ','-','w',' ','"','%','s','"',0 };
396 PROCESS_INFORMATION pi
;
399 len
= sizeof(szFormat
) + wcslen( szLink
) * sizeof(WCHAR
);
400 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
404 swprintf( buffer
, szFormat
, szLink
);
406 TRACE("starting %s\n",debugstr_w(buffer
));
408 memset(&si
, 0, sizeof(si
));
411 ret
= CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
413 HeapFree( GetProcessHeap(), 0, buffer
);
417 CloseHandle( pi
.hProcess
);
418 CloseHandle( pi
.hThread
);
424 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
426 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
427 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
431 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
436 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
439 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
440 IStream_Release( stm
);
444 StartLinkProcessor( pszFileName
);
446 This
->bDirty
= FALSE
;
450 DeleteFileW( pszFileName
);
451 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
458 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
460 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
461 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
465 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
467 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
468 FIXME("(%p)\n",This
);
472 static const IPersistFileVtbl pfvt
=
474 IPersistFile_fnQueryInterface
,
475 IPersistFile_fnAddRef
,
476 IPersistFile_fnRelease
,
477 IPersistFile_fnGetClassID
,
478 IPersistFile_fnIsDirty
,
481 IPersistFile_fnSaveCompleted
,
482 IPersistFile_fnGetCurFile
485 /************************************************************************
486 * IPersistStream_QueryInterface
488 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
489 IPersistStream
* iface
,
493 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
494 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
497 /************************************************************************
498 * IPersistStream_Release
500 static ULONG WINAPI
IPersistStream_fnRelease(
501 IPersistStream
* iface
)
503 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
504 return IShellLinkA_Release((IShellLinkA
*)This
);
507 /************************************************************************
508 * IPersistStream_AddRef
510 static ULONG WINAPI
IPersistStream_fnAddRef(
511 IPersistStream
* iface
)
513 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
514 return ShellLink_AddRef( This
);
517 /************************************************************************
518 * IPersistStream_GetClassID
521 static HRESULT WINAPI
IPersistStream_fnGetClassID(
522 IPersistStream
* iface
,
525 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
526 return ShellLink_GetClassID( This
, pClassID
);
529 /************************************************************************
530 * IPersistStream_IsDirty (IPersistStream)
532 static HRESULT WINAPI
IPersistStream_fnIsDirty(
533 IPersistStream
* iface
)
535 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
537 TRACE("(%p)\n", This
);
543 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
554 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
555 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
559 len
*= sizeof (WCHAR
);
561 TRACE("reading %d\n", len
);
562 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
564 return E_OUTOFMEMORY
;
566 r
= IStream_Read(stm
, temp
, len
, &count
);
567 if( FAILED (r
) || ( count
!= len
) )
569 HeapFree( GetProcessHeap(), 0, temp
);
573 TRACE("read %s\n", debugstr_an(temp
,len
));
575 /* convert to unicode if necessary */
578 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
579 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
582 HeapFree( GetProcessHeap(), 0, temp
);
583 return E_OUTOFMEMORY
;
585 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
586 HeapFree( GetProcessHeap(), 0, temp
);
600 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
607 unsigned char data
[1];
612 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
613 if( FAILED( r
) || count
!= sizeof(size
) )
616 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
618 return E_OUTOFMEMORY
;
621 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
622 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
624 HeapFree( GetProcessHeap(), 0, chunk
);
628 TRACE("Read %d bytes\n",chunk
->size
);
635 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
637 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
641 volume
->serial
= vol
->dwVolSerial
;
642 volume
->type
= vol
->dwType
;
644 if( !vol
->dwVolLabelOfs
)
646 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
648 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
651 label
+= vol
->dwVolLabelOfs
;
652 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
657 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
662 while( p
[len
] && (len
< maxlen
) )
665 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
666 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
667 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
673 static HRESULT
Stream_LoadLocation( IStream
*stm
,
674 volume_info
*volume
, LPWSTR
*path
)
681 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
685 loc
= (LOCATION_INFO
*) p
;
686 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
688 HeapFree( GetProcessHeap(), 0, p
);
692 /* if there's valid local volume information, load it */
693 if( loc
->dwVolTableOfs
&&
694 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
696 LOCAL_VOLUME_INFO
*volume_info
;
698 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
699 Stream_LoadVolume( volume_info
, volume
);
702 /* if there's a local path, load it */
703 n
= loc
->dwLocalPathOfs
;
704 if( n
&& (n
< loc
->dwTotalSize
) )
705 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
707 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
708 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
710 HeapFree( GetProcessHeap(), 0, p
);
715 * The format of the advertised shortcut info seems to be:
720 * 0 Length of the block (4 bytes, usually 0x314)
722 * 8 string data in ASCII
723 * 8+0x104 string data in UNICODE
725 * In the original Win32 implementation the buffers are not initialized
726 * to zero, so data trailing the string is random garbage.
728 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
733 EXP_DARWIN_LINK buffer
;
737 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
741 /* make sure that we read the size of the structure even on error */
742 size
= sizeof buffer
- sizeof (DWORD
);
743 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
745 ERR("Ooops. This structure is not as expected...\n");
749 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
756 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
758 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
760 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
764 *str
= HeapAlloc( GetProcessHeap(), 0,
765 (wcslen(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
766 wcscpy( *str
, buffer
.szwDarwinID
);
771 /************************************************************************
772 * IPersistStream_Load (IPersistStream)
774 static HRESULT WINAPI
IPersistStream_fnLoad(
775 IPersistStream
* iface
,
784 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
786 TRACE("%p %p\n", This
, stm
);
789 return STG_E_INVALIDPOINTER
;
792 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
796 if( dwBytesRead
!= sizeof(hdr
))
798 if( hdr
.dwSize
!= sizeof(hdr
))
800 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
803 /* free all the old stuff */
806 memset( &This
->volume
, 0, sizeof This
->volume
);
807 HeapFree(GetProcessHeap(), 0, This
->sPath
);
809 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
810 This
->sDescription
= NULL
;
811 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
812 This
->sPathRel
= NULL
;
813 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
814 This
->sWorkDir
= NULL
;
815 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
817 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
818 This
->sIcoPath
= NULL
;
819 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
820 This
->sProduct
= NULL
;
821 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
822 This
->sComponent
= NULL
;
824 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
825 This
->iIcoNdx
= hdr
.nIcon
;
826 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
827 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
828 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
831 WCHAR sTemp
[MAX_PATH
];
832 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
833 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
834 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
835 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
836 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
837 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
838 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
839 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
840 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
843 /* load all the new stuff */
844 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
846 r
= ILLoadFromStream( stm
, &This
->pPidl
);
852 /* load the location information */
853 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
854 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
858 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
859 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
861 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
862 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
867 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
869 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
870 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
875 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
877 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
878 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
883 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
885 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
886 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
891 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
893 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
894 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
899 #if (NTDDI_VERSION < NTDDI_LONGHORN)
900 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
902 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
903 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
909 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
911 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
912 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
914 if( hdr
.dwFlags
& SLDF_RUNAS_USER
)
920 This
->bRunAs
= FALSE
;
926 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
927 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
928 ERR("Last word was not zero\n");
939 /************************************************************************
942 * Helper function for IPersistStream_Save. Writes a unicode string
943 * with terminating nul byte to a stream, preceded by the its length.
945 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
947 USHORT len
= wcslen( str
) + 1;
951 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
955 len
*= sizeof(WCHAR
);
957 r
= IStream_Write( stm
, str
, len
, &count
);
964 /************************************************************************
965 * Stream_WriteLocationInfo
967 * Writes the location info to a stream
969 * FIXME: One day we might want to write the network volume information
970 * and the final path.
971 * Figure out how Windows deals with unicode paths here.
973 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
974 volume_info
*volume
)
976 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
977 LOCAL_VOLUME_INFO
*vol
;
979 LPSTR szLabel
, szPath
, szFinalPath
;
983 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
985 /* figure out the size of everything */
986 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
987 NULL
, 0, NULL
, NULL
);
988 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
989 NULL
, 0, NULL
, NULL
);
990 volume_info_size
= sizeof *vol
+ label_size
;
992 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
994 /* create pointers to everything */
995 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
996 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
997 szLabel
= (LPSTR
) &vol
[1];
998 szPath
= &szLabel
[label_size
];
999 szFinalPath
= &szPath
[path_size
];
1001 /* fill in the location information header */
1002 loc
->dwTotalSize
= total_size
;
1003 loc
->dwHeaderSize
= sizeof (*loc
);
1005 loc
->dwVolTableOfs
= sizeof (*loc
);
1006 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
1007 loc
->dwNetworkVolTableOfs
= 0;
1008 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
1010 /* fill in the volume information */
1011 vol
->dwSize
= volume_info_size
;
1012 vol
->dwType
= volume
->type
;
1013 vol
->dwVolSerial
= volume
->serial
;
1014 vol
->dwVolLabelOfs
= sizeof (*vol
);
1016 /* copy in the strings */
1017 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
1018 szLabel
, label_size
, NULL
, NULL
);
1019 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
1020 szPath
, path_size
, NULL
, NULL
);
1023 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
1024 HeapFree(GetProcessHeap(), 0, loc
);
1029 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
1031 EXP_DARWIN_LINK
*buffer
;
1033 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
1034 buffer
->dbh
.cbSize
= sizeof *buffer
;
1035 buffer
->dbh
.dwSignature
= magic
;
1036 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
1037 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
1042 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
1044 EXP_DARWIN_LINK
*buffer
;
1049 buffer
= shelllink_build_darwinid( string
, magic
);
1051 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1054 /************************************************************************
1055 * IPersistStream_Save (IPersistStream)
1057 * FIXME: makes assumptions about byte order
1059 static HRESULT WINAPI
IPersistStream_fnSave(
1060 IPersistStream
* iface
,
1069 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1071 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1073 memset(&header
, 0, sizeof(header
));
1074 header
.dwSize
= sizeof(header
);
1075 header
.fStartup
= This
->iShowCmd
;
1076 header
.MagicGuid
= CLSID_ShellLink
;
1078 header
.wHotKey
= This
->wHotKey
;
1079 header
.nIcon
= This
->iIcoNdx
;
1080 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1082 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1084 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1085 if( This
->sDescription
)
1086 header
.dwFlags
|= SLDF_HAS_NAME
;
1087 if( This
->sWorkDir
)
1088 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1090 header
.dwFlags
|= SLDF_HAS_ARGS
;
1091 if( This
->sIcoPath
)
1092 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1093 #if (NTDDI_VERSION < NTDDI_LONGHORN)
1094 if( This
->sProduct
)
1095 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1097 if( This
->sComponent
)
1098 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1100 header
.dwFlags
|= SLDF_RUNAS_USER
;
1102 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1103 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1104 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1106 /* write the Shortcut header */
1107 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1110 ERR("Write failed at %d\n",__LINE__
);
1114 TRACE("Writing pidl\n");
1116 /* write the PIDL to the shortcut */
1119 r
= ILSaveToStream( stm
, This
->pPidl
);
1122 ERR("Failed to write PIDL at %d\n",__LINE__
);
1128 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1130 if( This
->sDescription
)
1131 r
= Stream_WriteString( stm
, This
->sDescription
);
1133 if( This
->sPathRel
)
1134 r
= Stream_WriteString( stm
, This
->sPathRel
);
1136 if( This
->sWorkDir
)
1137 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1140 r
= Stream_WriteString( stm
, This
->sArgs
);
1142 if( This
->sIcoPath
)
1143 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1145 if( This
->sProduct
)
1146 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1148 if( This
->sComponent
)
1149 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1151 /* the last field is a single zero dword */
1153 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1158 /************************************************************************
1159 * IPersistStream_GetSizeMax (IPersistStream)
1161 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1162 IPersistStream
* iface
,
1163 ULARGE_INTEGER
* pcbSize
)
1165 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1167 TRACE("(%p)\n", This
);
1172 static const IPersistStreamVtbl psvt
=
1174 IPersistStream_fnQueryInterface
,
1175 IPersistStream_fnAddRef
,
1176 IPersistStream_fnRelease
,
1177 IPersistStream_fnGetClassID
,
1178 IPersistStream_fnIsDirty
,
1179 IPersistStream_fnLoad
,
1180 IPersistStream_fnSave
,
1181 IPersistStream_fnGetSizeMax
1184 /**************************************************************************
1185 * IShellLink_Constructor
1187 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1188 REFIID riid
, LPVOID
*ppv
)
1190 IShellLinkImpl
* sl
;
1193 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1198 return CLASS_E_NOAGGREGATION
;
1199 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1201 return E_OUTOFMEMORY
;
1205 sl
->lpvtblw
= &slvtw
;
1206 sl
->lpvtblPersistFile
= &pfvt
;
1207 sl
->lpvtblPersistStream
= &psvt
;
1208 sl
->lpvtblShellLinkDataList
= &dlvt
;
1209 sl
->lpvtblShellExtInit
= &eivt
;
1210 sl
->lpvtblContextMenu
= &cmvt
;
1211 sl
->lpvtblObjectWithSite
= &owsvt
;
1212 sl
->lpvtblPropSheetExt
= &pse
;
1213 sl
->iShowCmd
= SW_SHOWNORMAL
;
1219 TRACE("(%p)->()\n",sl
);
1221 r
= ShellLink_QueryInterface( sl
, riid
, ppv
);
1222 ShellLink_Release( sl
);
1227 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1229 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1234 /**************************************************************************
1235 * ShellLink_UpdatePath
1236 * update absolute path in sPath using relative path in sPathRel
1238 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1240 if (!path
|| !psPath
)
1241 return E_INVALIDARG
;
1243 if (!*psPath
&& sPathRel
) {
1244 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1245 LPWSTR final
= NULL
;
1247 /* first try if [directory of link file] + [relative path] finds an existing file */
1249 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1252 wcscpy(final
, sPathRel
);
1256 if (SHELL_ExistsFileW(buffer
)) {
1257 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1258 wcscpy(abs_path
, buffer
);
1260 /* try if [working directory] + [relative path] finds an existing file */
1262 wcscpy(buffer
, sWorkDir
);
1263 wcscpy(PathAddBackslashW(buffer
), sPathRel
);
1265 if (SHELL_ExistsFileW(buffer
))
1266 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1267 wcscpy(abs_path
, buffer
);
1271 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1273 wcscpy(abs_path
, sPathRel
);
1275 *psPath
= HeapAlloc(GetProcessHeap(), 0, (wcslen(abs_path
)+1)*sizeof(WCHAR
));
1277 return E_OUTOFMEMORY
;
1279 wcscpy(*psPath
, abs_path
);
1285 /**************************************************************************
1286 * IShellLink_ConstructFromFile
1288 HRESULT WINAPI
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1289 LPCITEMIDLIST pidl
, LPVOID
* ppv
)
1293 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1295 if (SUCCEEDED(hr
)) {
1300 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1302 if (SUCCEEDED(hr
)) {
1303 WCHAR path
[MAX_PATH
];
1305 if (SHGetPathFromIDListW(pidl
, path
))
1306 hr
= IPersistFile_Load(ppf
, path
, 0);
1313 IPersistFile_Release(ppf
);
1317 IShellLinkW_Release(psl
);
1323 /**************************************************************************
1324 * IShellLinkA_QueryInterface
1326 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1328 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1329 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1332 /******************************************************************************
1333 * IShellLinkA_AddRef
1335 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
1337 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1338 return ShellLink_AddRef( This
);
1341 /******************************************************************************
1342 * IShellLinkA_Release
1344 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1346 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1347 return ShellLink_Release( This
);
1350 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1351 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1353 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1355 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1356 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1358 if (This
->sComponent
|| This
->sProduct
)
1364 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1365 pszFile
, cchMaxPath
, NULL
, NULL
);
1367 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1372 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1374 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1376 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1378 return IShellLinkW_GetIDList((IShellLinkW
*)&(This
->lpvtblw
), ppidl
);
1381 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1383 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1385 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1388 ILFree(This
->pPidl
);
1389 This
->pPidl
= ILClone (pidl
);
1390 This
->bDirty
= TRUE
;
1395 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1397 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1399 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1403 if( This
->sDescription
)
1404 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1405 pszName
, cchMaxName
, NULL
, NULL
);
1410 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1412 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1414 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1416 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1417 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1418 if ( !This
->sDescription
)
1419 return E_OUTOFMEMORY
;
1421 This
->bDirty
= TRUE
;
1426 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1428 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1430 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1434 if( This
->sWorkDir
)
1435 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1436 pszDir
, cchMaxPath
, NULL
, NULL
);
1441 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1443 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1445 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1447 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1448 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1449 if ( !This
->sWorkDir
)
1450 return E_OUTOFMEMORY
;
1452 This
->bDirty
= TRUE
;
1457 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1459 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1461 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1466 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1467 pszArgs
, cchMaxPath
, NULL
, NULL
);
1472 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1474 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1476 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1478 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1479 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1481 return E_OUTOFMEMORY
;
1483 This
->bDirty
= TRUE
;
1488 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1490 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1492 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1494 *pwHotkey
= This
->wHotKey
;
1499 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1501 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1503 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1505 This
->wHotKey
= wHotkey
;
1506 This
->bDirty
= TRUE
;
1511 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1513 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1515 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1516 *piShowCmd
= This
->iShowCmd
;
1520 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1522 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1524 TRACE("(%p) %d\n",This
, iShowCmd
);
1526 This
->iShowCmd
= iShowCmd
;
1527 This
->bDirty
= TRUE
;
1532 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPCITEMIDLIST pidl
,
1533 LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1535 LPCITEMIDLIST pidlLast
;
1537 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1539 if (SUCCEEDED(hr
)) {
1542 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, &pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1544 if (SUCCEEDED(hr
)) {
1545 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1547 IExtractIconA_Release(pei
);
1550 IShellFolder_Release(psf
);
1556 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1558 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1560 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1563 *piIcon
= This
->iIcoNdx
;
1567 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1571 if (This
->pPidl
|| This
->sPath
)
1575 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1579 /* first look for an icon using the PIDL (if present) */
1581 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1585 /* if we couldn't find an icon yet, look for it using the file system path */
1586 if (FAILED(hr
) && This
->sPath
)
1590 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1592 if (SUCCEEDED(hr
)) {
1593 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1599 IShellFolder_Release(pdsk
);
1607 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1609 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1611 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1613 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1614 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1615 if ( !This
->sIcoPath
)
1616 return E_OUTOFMEMORY
;
1618 This
->iIcoNdx
= iIcon
;
1619 This
->bDirty
= TRUE
;
1624 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1626 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1628 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1630 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1631 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1632 This
->bDirty
= TRUE
;
1634 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1637 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1639 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1641 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1643 return IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, fFlags
);
1646 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1650 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1652 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1654 if (!pszFile
) return E_INVALIDARG
;
1656 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1658 return E_OUTOFMEMORY
;
1660 r
= IShellLinkW_SetPath((IShellLinkW
*)&(This
->lpvtblw
), str
);
1661 HeapFree( GetProcessHeap(), 0, str
);
1666 /**************************************************************************
1667 * IShellLink Implementation
1670 static const IShellLinkAVtbl slvt
=
1672 IShellLinkA_fnQueryInterface
,
1673 IShellLinkA_fnAddRef
,
1674 IShellLinkA_fnRelease
,
1675 IShellLinkA_fnGetPath
,
1676 IShellLinkA_fnGetIDList
,
1677 IShellLinkA_fnSetIDList
,
1678 IShellLinkA_fnGetDescription
,
1679 IShellLinkA_fnSetDescription
,
1680 IShellLinkA_fnGetWorkingDirectory
,
1681 IShellLinkA_fnSetWorkingDirectory
,
1682 IShellLinkA_fnGetArguments
,
1683 IShellLinkA_fnSetArguments
,
1684 IShellLinkA_fnGetHotkey
,
1685 IShellLinkA_fnSetHotkey
,
1686 IShellLinkA_fnGetShowCmd
,
1687 IShellLinkA_fnSetShowCmd
,
1688 IShellLinkA_fnGetIconLocation
,
1689 IShellLinkA_fnSetIconLocation
,
1690 IShellLinkA_fnSetRelativePath
,
1691 IShellLinkA_fnResolve
,
1692 IShellLinkA_fnSetPath
1696 /**************************************************************************
1697 * IShellLinkW_fnQueryInterface
1699 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1700 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1702 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1703 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1706 /******************************************************************************
1707 * IShellLinkW_fnAddRef
1709 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1711 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1712 return ShellLink_AddRef( This
);
1715 /******************************************************************************
1716 * IShellLinkW_fnRelease
1718 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1720 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1721 return ShellLink_Release( This
);
1724 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1726 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1728 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1729 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1731 if (This
->sComponent
|| This
->sProduct
)
1737 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1739 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1744 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1746 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1748 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1755 *ppidl
= ILClone(This
->pPidl
);
1759 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1761 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1763 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1766 ILFree( This
->pPidl
);
1767 This
->pPidl
= ILClone( pidl
);
1771 This
->bDirty
= TRUE
;
1776 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1778 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1780 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1783 if( This
->sDescription
)
1784 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1789 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1791 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1793 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1795 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1796 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1797 (wcslen( pszName
)+1)*sizeof(WCHAR
) );
1798 if ( !This
->sDescription
)
1799 return E_OUTOFMEMORY
;
1801 wcscpy( This
->sDescription
, pszName
);
1802 This
->bDirty
= TRUE
;
1807 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1809 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1811 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1815 if( This
->sWorkDir
)
1816 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1821 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1823 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1825 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1827 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1828 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1829 (wcslen( pszDir
)+1)*sizeof (WCHAR
) );
1830 if ( !This
->sWorkDir
)
1831 return E_OUTOFMEMORY
;
1832 wcscpy( This
->sWorkDir
, pszDir
);
1833 This
->bDirty
= TRUE
;
1838 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1840 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1842 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1847 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1852 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1854 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1856 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1858 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1859 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1860 (wcslen( pszArgs
)+1)*sizeof (WCHAR
) );
1862 return E_OUTOFMEMORY
;
1863 wcscpy( This
->sArgs
, pszArgs
);
1864 This
->bDirty
= TRUE
;
1869 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1871 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1873 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1875 *pwHotkey
=This
->wHotKey
;
1880 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1882 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1884 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1886 This
->wHotKey
= wHotkey
;
1887 This
->bDirty
= TRUE
;
1892 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1894 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1896 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1898 *piShowCmd
= This
->iShowCmd
;
1903 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1905 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1907 This
->iShowCmd
= iShowCmd
;
1908 This
->bDirty
= TRUE
;
1913 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPCITEMIDLIST pidl
,
1914 LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1916 LPCITEMIDLIST pidlLast
;
1919 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1921 if (SUCCEEDED(hr
)) {
1924 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, &pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1926 if (SUCCEEDED(hr
)) {
1927 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, &wFlags
);
1929 IExtractIconW_Release(pei
);
1932 IShellFolder_Release(psf
);
1938 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1940 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1942 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1945 *piIcon
= This
->iIcoNdx
;
1949 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1953 if (This
->pPidl
|| This
->sPath
)
1957 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1961 /* first look for an icon using the PIDL (if present) */
1963 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1967 /* if we couldn't find an icon yet, look for it using the file system path */
1968 if (FAILED(hr
) && This
->sPath
)
1972 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1976 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1982 IShellFolder_Release(pdsk
);
1989 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1991 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1993 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1995 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1996 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1997 (wcslen( pszIconPath
)+1)*sizeof (WCHAR
) );
1998 if ( !This
->sIcoPath
)
1999 return E_OUTOFMEMORY
;
2000 wcscpy( This
->sIcoPath
, pszIconPath
);
2002 This
->iIcoNdx
= iIcon
;
2003 This
->bDirty
= TRUE
;
2008 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
2010 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2012 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
2014 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
2015 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
2016 (wcslen( pszPathRel
)+1) * sizeof (WCHAR
) );
2017 if ( !This
->sPathRel
)
2018 return E_OUTOFMEMORY
;
2019 wcscpy( This
->sPathRel
, pszPathRel
);
2020 This
->bDirty
= TRUE
;
2022 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
2025 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
2030 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2032 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
2034 /*FIXME: use IResolveShellLink interface */
2036 if (!This
->sPath
&& This
->pPidl
) {
2037 WCHAR buffer
[MAX_PATH
];
2039 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
2041 if (bSuccess
&& *buffer
) {
2042 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (wcslen(buffer
)+1)*sizeof(WCHAR
));
2044 return E_OUTOFMEMORY
;
2046 wcscpy(This
->sPath
, buffer
);
2048 This
->bDirty
= TRUE
;
2050 hr
= S_OK
; /* don't report an error occurred while just caching information */
2053 if (!This
->sIcoPath
&& This
->sPath
) {
2054 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (wcslen(This
->sPath
)+1)*sizeof(WCHAR
));
2055 if (!This
->sIcoPath
)
2056 return E_OUTOFMEMORY
;
2058 wcscpy(This
->sIcoPath
, This
->sPath
);
2061 This
->bDirty
= TRUE
;
2067 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2076 p
= wcschr( str
, ':' );
2080 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2083 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2088 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2090 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2098 /* each segment must start with two colons */
2099 if( str
[0] != ':' || str
[1] != ':' )
2102 /* the last segment is just two colons */
2107 /* there must be a colon straight after a guid */
2108 p
= wcschr( str
, ':' );
2115 /* get the guid, and check it's validly formatted */
2116 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2118 r
= CLSIDFromString( szGuid
, &guid
);
2123 /* match it up to a guid that we care about */
2124 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2126 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2131 /* skip to the next field */
2132 str
= wcschr( str
, ':' );
2137 /* we have to have a component for an advertised shortcut */
2141 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2142 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2144 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2145 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2150 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2152 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2153 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
2156 volume
->type
= GetDriveTypeW(drive
);
2157 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2158 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2159 TRACE("r = %d type %d serial %08x name %s\n", r
,
2160 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2164 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2166 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2167 WCHAR buffer
[MAX_PATH
];
2168 LPWSTR fname
, unquoted
= NULL
;
2172 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2174 if (!pszFile
) return E_INVALIDARG
;
2176 /* quotes at the ends of the string are stripped */
2177 len
= wcslen(pszFile
);
2178 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2180 unquoted
= strdupW(pszFile
);
2181 PathUnquoteSpacesW(unquoted
);
2185 /* any other quote marks are invalid */
2186 if (wcschr(pszFile
, '"'))
2188 HeapFree(GetProcessHeap(), 0, unquoted
);
2192 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2195 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2196 This
->sComponent
= NULL
;
2199 ILFree(This
->pPidl
);
2202 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2204 if (*pszFile
== '\0')
2206 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2208 else if(!PathFileExistsW(buffer
) &&
2209 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2212 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2213 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2215 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2216 (wcslen( buffer
)+1) * sizeof (WCHAR
) );
2218 return E_OUTOFMEMORY
;
2220 wcscpy(This
->sPath
, buffer
);
2222 This
->bDirty
= TRUE
;
2223 HeapFree(GetProcessHeap(), 0, unquoted
);
2228 /**************************************************************************
2229 * IShellLinkW Implementation
2232 static const IShellLinkWVtbl slvtw
=
2234 IShellLinkW_fnQueryInterface
,
2235 IShellLinkW_fnAddRef
,
2236 IShellLinkW_fnRelease
,
2237 IShellLinkW_fnGetPath
,
2238 IShellLinkW_fnGetIDList
,
2239 IShellLinkW_fnSetIDList
,
2240 IShellLinkW_fnGetDescription
,
2241 IShellLinkW_fnSetDescription
,
2242 IShellLinkW_fnGetWorkingDirectory
,
2243 IShellLinkW_fnSetWorkingDirectory
,
2244 IShellLinkW_fnGetArguments
,
2245 IShellLinkW_fnSetArguments
,
2246 IShellLinkW_fnGetHotkey
,
2247 IShellLinkW_fnSetHotkey
,
2248 IShellLinkW_fnGetShowCmd
,
2249 IShellLinkW_fnSetShowCmd
,
2250 IShellLinkW_fnGetIconLocation
,
2251 IShellLinkW_fnSetIconLocation
,
2252 IShellLinkW_fnSetRelativePath
,
2253 IShellLinkW_fnResolve
,
2254 IShellLinkW_fnSetPath
2257 static HRESULT WINAPI
2258 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2260 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2261 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2265 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2267 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2268 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2272 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2274 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2275 return ShellLink_Release( This
);
2278 static HRESULT WINAPI
2279 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2285 static HRESULT WINAPI
2286 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2288 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2289 LPVOID block
= NULL
;
2292 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2296 case EXP_DARWIN_ID_SIG
:
2297 if (!This
->sComponent
)
2299 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2302 case EXP_SZ_LINK_SIG
:
2303 case NT_CONSOLE_PROPS_SIG
:
2304 case NT_FE_CONSOLE_PROPS_SIG
:
2305 case EXP_SPECIAL_FOLDER_SIG
:
2306 case EXP_SZ_ICON_SIG
:
2307 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2310 ERR("unknown datablock %08x\n", dwSig
);
2312 *ppDataBlock
= block
;
2316 static HRESULT WINAPI
2317 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2323 static HRESULT WINAPI
2324 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2326 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2329 FIXME("%p %p\n", This
, pdwFlags
);
2331 /* FIXME: add more */
2333 flags
|= SLDF_HAS_ARGS
;
2334 if (This
->sComponent
)
2335 flags
|= SLDF_HAS_DARWINID
;
2337 flags
|= SLDF_HAS_ICONLOCATION
;
2338 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2340 flags
|= SLDF_HAS_LOGO3ID
;
2343 flags
|= SLDF_HAS_ID_LIST
;
2350 static HRESULT WINAPI
2351 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2357 static const IShellLinkDataListVtbl dlvt
=
2359 ShellLink_DataList_QueryInterface
,
2360 ShellLink_DataList_AddRef
,
2361 ShellLink_DataList_Release
,
2362 ShellLink_AddDataBlock
,
2363 ShellLink_CopyDataBlock
,
2364 ShellLink_RemoveDataBlock
,
2369 static HRESULT WINAPI
2370 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2372 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2373 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2377 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2379 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2380 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2384 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2386 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2387 return ShellLink_Release( This
);
2390 /**************************************************************************
2391 * ShellLink implementation of IShellExtInit::Initialize()
2393 * Loads the shelllink from the dataobject the shell is pointing to.
2395 static HRESULT WINAPI
2396 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2397 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2399 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2405 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2410 format
.cfFormat
= CF_HDROP
;
2412 format
.dwAspect
= DVASPECT_CONTENT
;
2414 format
.tymed
= TYMED_HGLOBAL
;
2416 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2419 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2424 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2426 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2429 IPersistFile
*pf
= (IPersistFile
*) &This
->lpvtblPersistFile
;
2431 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2432 r
= IPersistFile_Load( pf
, path
, 0 );
2433 HeapFree( GetProcessHeap(), 0, path
);
2436 ReleaseStgMedium( &stgm
);
2441 static const IShellExtInitVtbl eivt
=
2443 ShellLink_ExtInit_QueryInterface
,
2444 ShellLink_ExtInit_AddRef
,
2445 ShellLink_ExtInit_Release
,
2446 ShellLink_ExtInit_Initialize
2449 static HRESULT WINAPI
2450 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2452 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2453 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2457 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2459 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2460 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2464 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2466 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2467 return ShellLink_Release( This
);
2470 static HRESULT WINAPI
2471 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2472 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2474 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2479 TRACE("%p %p %u %u %u %u\n", This
,
2480 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2483 return E_INVALIDARG
;
2485 if (!LoadStringW(shell32_hInstance
, IDS_OPEN_VERB
, szOpen
, sizeof(szOpen
)/sizeof(WCHAR
)))
2488 szOpen
[(sizeof(szOpen
)/sizeof(WCHAR
))-1] = L
'\0';
2490 memset( &mii
, 0, sizeof(mii
) );
2491 mii
.cbSize
= sizeof (mii
);
2492 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2493 mii
.dwTypeData
= (LPWSTR
)szOpen
;
2494 mii
.cch
= wcslen( mii
.dwTypeData
);
2495 mii
.wID
= idCmdFirst
+ id
++;
2496 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2497 mii
.fType
= MFT_STRING
;
2498 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2502 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2506 shelllink_get_msi_component_path( LPWSTR component
)
2511 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2512 if (r
!= ERROR_SUCCESS
)
2516 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2517 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2518 if (r
!= ERROR_SUCCESS
)
2520 HeapFree( GetProcessHeap(), 0, path
);
2524 TRACE("returning %s\n", debugstr_w( path
) );
2529 INT_PTR CALLBACK
ExtendedShortcutProc(
2543 hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2544 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2548 hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2549 if (LOWORD(wParam
) == IDOK
)
2551 if ( SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2552 EndDialog(hwndDlg
, 1);
2554 EndDialog(hwndDlg
, 0);
2556 else if (LOWORD(wParam
) == IDCANCEL
)
2558 EndDialog(hwndDlg
, -1);
2560 else if (LOWORD(wParam
) == 14000)
2562 if ( SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2563 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2565 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2572 /**************************************************************************
2573 * SH_ShellLinkDlgProc
2575 * dialog proc of the shortcut property dialog
2580 SH_ShellLinkDlgProc(
2587 LPPROPSHEETPAGEW ppsp
;
2589 IShellLinkImpl
*This
;
2591 WCHAR szBuffer
[MAX_PATH
];
2596 This
= (IShellLinkImpl
*)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
2601 ppsp
= (LPPROPSHEETPAGEW
)lParam
;
2605 TRACE("ShellLink_DlgProc (WM_INITDIALOG hwnd %p lParam %p ppsplParam %x)\n",hwndDlg
, lParam
, ppsp
->lParam
);
2607 This
= (IShellLinkImpl
*)ppsp
->lParam
;
2608 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)This
);
2610 TRACE("sArgs: %S sComponent: %S sDescription: %S sIcoPath: %S sPath: %S sPathRel: %S sProduct: %S sWorkDir: %S\n", This
->sArgs
, This
->sComponent
,This
->sDescription
,
2611 This
->sIcoPath
, This
->sPath
, This
->sPathRel
, This
->sProduct
, This
->sWorkDir
);
2614 hDlgCtrl
= GetDlgItem( hwndDlg
, 14009 );
2615 if ( hDlgCtrl
!= NULL
)
2616 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sPath
);
2619 hDlgCtrl
= GetDlgItem( hwndDlg
, 14011 );
2620 if ( hDlgCtrl
!= NULL
)
2621 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sWorkDir
);
2624 hDlgCtrl
= GetDlgItem( hwndDlg
, 14019 );
2625 if ( hDlgCtrl
!= NULL
)
2626 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sDescription
);
2629 lppsn
= (LPPSHNOTIFY
) lParam
;
2630 if ( lppsn
->hdr
.code
== PSN_APPLY
)
2632 /* set working directory */
2633 hDlgCtrl
= GetDlgItem( hwndDlg
, 14011 );
2634 SendMessageW( hDlgCtrl
, WM_GETTEXT
, (WPARAM
)MAX_PATH
, (LPARAM
)szBuffer
);
2635 IShellLinkW_fnSetWorkingDirectory((IShellLinkW
*)&This
->lpvtblw
, szBuffer
);
2636 /* set link destination */
2637 hDlgCtrl
= GetDlgItem( hwndDlg
, 14009 );
2638 SendMessageW( hDlgCtrl
, WM_GETTEXT
, (WPARAM
)MAX_PATH
, (LPARAM
)szBuffer
);
2639 if ( !SHELL_ExistsFileW(szBuffer
) )
2641 //FIXME load localized error msg
2642 MessageBoxW( hwndDlg
, L
"file not existing", szBuffer
, MB_OK
);
2643 SetWindowLongPtr( hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2646 ptr
= wcsrchr(szBuffer
, L
'.');
2647 if (ptr
&& !_wcsnicmp(ptr
, L
".lnk", 4))
2649 // FIXME load localized error msg
2650 MessageBoxW( hwndDlg
, L
"You cannot create a link to a shortcut", L
"Error", MB_ICONERROR
);
2651 SetWindowLongPtr( hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2655 IShellLinkW_fnSetPath((IShellLinkW
*)&This
->lpvtblw
, szBuffer
);
2657 TRACE("This %p sLinkPath %S\n", This
, This
->sLinkPath
);
2658 IPersistFile_fnSave( (IPersistFile
*)&This
->lpvtblPersistFile
, This
->sLinkPath
, TRUE
);
2659 SetWindowLongPtr( hwndDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
2664 switch(LOWORD(wParam
))
2669 /// open target directory
2674 wcscpy(szBuffer
, This
->sIcoPath
);
2676 wcscpy(szBuffer
, This
->sPath
);
2678 IconIndex
= This
->iIcoNdx
;
2679 if (PickIconDlg(hwndDlg
, szBuffer
, MAX_PATH
, &IconIndex
))
2681 IShellLinkW_fnSetIconLocation((IShellLinkW
*)&This
->lpvtblw
, szBuffer
, IconIndex
);
2683 /// FIXME redraw icon
2687 result
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(SHELL_EXTENDED_SHORTCUT_DLG
), hwndDlg
, ExtendedShortcutProc
, (LPARAM
)This
->bRunAs
);
2688 if (result
== 1 || result
== 0)
2690 if ( This
->bRunAs
!= result
)
2692 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2695 This
->bRunAs
= result
;
2699 switch(HIWORD(wParam
))
2702 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2712 /**************************************************************************
2713 * ShellLink_IShellPropSheetExt interface
2716 static HRESULT WINAPI
2717 ShellLink_IShellPropSheetExt_QueryInterface( IShellPropSheetExt
* iface
, REFIID riid
, void** ppvObject
)
2719 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2720 return ShellLink_QueryInterface( This
, riid
, ppvObject
);
2724 ShellLink_IShellPropSheetExt_AddRef( IShellPropSheetExt
* iface
)
2726 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2727 return ShellLink_AddRef( This
);
2731 ShellLink_IShellPropSheetExt_Release( IShellPropSheetExt
* iface
)
2733 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2734 return ShellLink_Release( This
);
2737 static HRESULT WINAPI
2738 ShellLink_IShellPropSheetExt_AddPages( IShellPropSheetExt
*iface
, LPFNADDPROPSHEETPAGE pfnAddPage
, LPARAM lParam
)
2740 HPROPSHEETPAGE hPage
;
2742 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2744 hPage
= SH_CreatePropertySheetPage("SHELL_GENERAL_SHORTCUT_DLG", SH_ShellLinkDlgProc
, (LPARAM
)This
, NULL
);
2747 ERR("failed to create property sheet page\n");
2751 bRet
= pfnAddPage(hPage
, lParam
);
2758 static HRESULT WINAPI
2759 ShellLink_IShellPropSheetExt_ReplacePages( IShellPropSheetExt
*iface
, UINT uPageID
, LPFNADDPROPSHEETPAGE pfnReplacePage
, LPARAM lParam
)
2761 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2762 TRACE("(%p) (uPageID %u, pfnReplacePage %p lParam %p\n", This
, uPageID
, pfnReplacePage
, lParam
);
2766 static const IShellPropSheetExtVtbl pse
=
2768 ShellLink_IShellPropSheetExt_QueryInterface
,
2769 ShellLink_IShellPropSheetExt_AddRef
,
2770 ShellLink_IShellPropSheetExt_Release
,
2771 ShellLink_IShellPropSheetExt_AddPages
,
2772 ShellLink_IShellPropSheetExt_ReplacePages
2775 static HRESULT WINAPI
2776 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2778 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2779 static const WCHAR szOpen
[] = { 'o','p','e','n',0 };
2780 static const WCHAR szCplOpen
[] = { 'c','p','l','o','p','e','n',0 };
2781 SHELLEXECUTEINFOW sei
;
2782 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2787 TRACE("%p %p\n", This
, lpici
);
2789 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2790 return E_INVALIDARG
;
2792 r
= IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, 0 );
2795 TRACE("failed to resolve component with error 0x%08x", r
);
2798 if ( This
->sComponent
)
2800 path
= shelllink_get_msi_component_path( This
->sComponent
);
2805 path
= strdupW( This
->sPath
);
2807 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2808 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2810 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2814 len
+= wcslen( This
->sArgs
);
2815 if ( iciex
->lpParametersW
)
2816 len
+= wcslen( iciex
->lpParametersW
);
2818 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2821 wcscat( args
, This
->sArgs
);
2822 if ( iciex
->lpParametersW
)
2824 static const WCHAR space
[] = { ' ', 0 };
2825 wcscat( args
, space
);
2826 wcscat( args
, iciex
->lpParametersW
);
2829 else if (This
->sArgs
!= NULL
)
2834 memset( &sei
, 0, sizeof sei
);
2835 sei
.cbSize
= sizeof sei
;
2836 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2838 sei
.nShow
= This
->iShowCmd
;
2839 sei
.lpDirectory
= This
->sWorkDir
;
2840 sei
.lpParameters
= args
;
2841 sei
.lpVerb
= szOpen
;
2843 // HACK for ShellExecuteExW
2844 if (!wcsstr(This
->sPath
, L
".cpl"))
2845 sei
.lpVerb
= szOpen
;
2847 sei
.lpVerb
= szCplOpen
;
2849 if( ShellExecuteExW( &sei
) )
2854 HeapFree( GetProcessHeap(), 0, args
);
2855 HeapFree( GetProcessHeap(), 0, path
);
2860 static HRESULT WINAPI
2861 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2862 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2864 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2866 FIXME("%p %lu %u %p %p %u\n", This
,
2867 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2872 static const IContextMenuVtbl cmvt
=
2874 ShellLink_ContextMenu_QueryInterface
,
2875 ShellLink_ContextMenu_AddRef
,
2876 ShellLink_ContextMenu_Release
,
2877 ShellLink_QueryContextMenu
,
2878 ShellLink_InvokeCommand
,
2879 ShellLink_GetCommandString
2882 static HRESULT WINAPI
2883 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2885 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2886 return ShellLink_QueryInterface( This
, riid
, ppvObject
);
2890 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2892 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2893 return ShellLink_AddRef( This
);
2897 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2899 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2900 return ShellLink_Release( This
);
2903 static HRESULT WINAPI
2904 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2906 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2908 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2912 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2915 static HRESULT WINAPI
2916 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2918 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2920 TRACE("%p %p\n", iface
, punk
);
2923 IUnknown_AddRef( punk
);
2929 static const IObjectWithSiteVtbl owsvt
=
2931 ShellLink_ObjectWithSite_QueryInterface
,
2932 ShellLink_ObjectWithSite_AddRef
,
2933 ShellLink_ObjectWithSite_Release
,