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
);
302 LocalFree((HANDLE
)This
);
307 static HRESULT
ShellLink_GetClassID( IShellLinkImpl
*This
, CLSID
*pclsid
)
309 TRACE("%p %p\n", This
, pclsid
);
311 memcpy( pclsid
, &CLSID_ShellLink
, sizeof (CLSID
) );
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
.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
.cbSize
!= sizeof buffer
)
745 ERR("Ooops. This structure is not as expected...\n");
749 r
= IStream_Read( stm
, &buffer
.dwSignature
, size
, &count
);
756 TRACE("magic %08x string = %s\n", buffer
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
758 if( (buffer
.dwSignature
&0xffff0000) != 0xa0000000 )
760 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.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
->cbSize
= sizeof *buffer
;
1035 buffer
->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
->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 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1656 return E_OUTOFMEMORY
;
1658 r
= IShellLinkW_SetPath((IShellLinkW
*)&(This
->lpvtblw
), str
);
1659 HeapFree( GetProcessHeap(), 0, str
);
1664 /**************************************************************************
1665 * IShellLink Implementation
1668 static const IShellLinkAVtbl slvt
=
1670 IShellLinkA_fnQueryInterface
,
1671 IShellLinkA_fnAddRef
,
1672 IShellLinkA_fnRelease
,
1673 IShellLinkA_fnGetPath
,
1674 IShellLinkA_fnGetIDList
,
1675 IShellLinkA_fnSetIDList
,
1676 IShellLinkA_fnGetDescription
,
1677 IShellLinkA_fnSetDescription
,
1678 IShellLinkA_fnGetWorkingDirectory
,
1679 IShellLinkA_fnSetWorkingDirectory
,
1680 IShellLinkA_fnGetArguments
,
1681 IShellLinkA_fnSetArguments
,
1682 IShellLinkA_fnGetHotkey
,
1683 IShellLinkA_fnSetHotkey
,
1684 IShellLinkA_fnGetShowCmd
,
1685 IShellLinkA_fnSetShowCmd
,
1686 IShellLinkA_fnGetIconLocation
,
1687 IShellLinkA_fnSetIconLocation
,
1688 IShellLinkA_fnSetRelativePath
,
1689 IShellLinkA_fnResolve
,
1690 IShellLinkA_fnSetPath
1694 /**************************************************************************
1695 * IShellLinkW_fnQueryInterface
1697 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1698 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1700 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1701 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1704 /******************************************************************************
1705 * IShellLinkW_fnAddRef
1707 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1709 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1710 return ShellLink_AddRef( This
);
1713 /******************************************************************************
1714 * IShellLinkW_fnRelease
1716 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1718 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1719 return ShellLink_Release( This
);
1722 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1724 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1726 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1727 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1729 if (This
->sComponent
|| This
->sProduct
)
1735 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1737 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1742 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1744 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1746 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1753 *ppidl
= ILClone(This
->pPidl
);
1757 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1759 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1761 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1764 ILFree( This
->pPidl
);
1765 This
->pPidl
= ILClone( pidl
);
1769 This
->bDirty
= TRUE
;
1774 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1776 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1778 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1781 if( This
->sDescription
)
1782 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1787 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1789 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1791 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1793 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1794 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1795 (wcslen( pszName
)+1)*sizeof(WCHAR
) );
1796 if ( !This
->sDescription
)
1797 return E_OUTOFMEMORY
;
1799 wcscpy( This
->sDescription
, pszName
);
1800 This
->bDirty
= TRUE
;
1805 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1807 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1809 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1813 if( This
->sWorkDir
)
1814 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1819 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1821 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1823 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1825 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1826 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1827 (wcslen( pszDir
)+1)*sizeof (WCHAR
) );
1828 if ( !This
->sWorkDir
)
1829 return E_OUTOFMEMORY
;
1830 wcscpy( This
->sWorkDir
, pszDir
);
1831 This
->bDirty
= TRUE
;
1836 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1838 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1840 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1845 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1850 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1852 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1854 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1856 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1857 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1858 (wcslen( pszArgs
)+1)*sizeof (WCHAR
) );
1860 return E_OUTOFMEMORY
;
1861 wcscpy( This
->sArgs
, pszArgs
);
1862 This
->bDirty
= TRUE
;
1867 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1869 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1871 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1873 *pwHotkey
=This
->wHotKey
;
1878 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1880 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1882 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1884 This
->wHotKey
= wHotkey
;
1885 This
->bDirty
= TRUE
;
1890 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1892 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1894 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1896 *piShowCmd
= This
->iShowCmd
;
1901 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1903 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1905 This
->iShowCmd
= iShowCmd
;
1906 This
->bDirty
= TRUE
;
1911 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPCITEMIDLIST pidl
,
1912 LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1914 LPCITEMIDLIST pidlLast
;
1917 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1919 if (SUCCEEDED(hr
)) {
1922 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, &pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1924 if (SUCCEEDED(hr
)) {
1925 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, &wFlags
);
1927 IExtractIconW_Release(pei
);
1930 IShellFolder_Release(psf
);
1936 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1938 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1940 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1943 *piIcon
= This
->iIcoNdx
;
1947 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1951 if (This
->pPidl
|| This
->sPath
)
1955 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1959 /* first look for an icon using the PIDL (if present) */
1961 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1965 /* if we couldn't find an icon yet, look for it using the file system path */
1966 if (FAILED(hr
) && This
->sPath
)
1970 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1974 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1980 IShellFolder_Release(pdsk
);
1987 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1989 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1991 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1993 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1994 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1995 (wcslen( pszIconPath
)+1)*sizeof (WCHAR
) );
1996 if ( !This
->sIcoPath
)
1997 return E_OUTOFMEMORY
;
1998 wcscpy( This
->sIcoPath
, pszIconPath
);
2000 This
->iIcoNdx
= iIcon
;
2001 This
->bDirty
= TRUE
;
2006 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
2008 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2010 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
2012 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
2013 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
2014 (wcslen( pszPathRel
)+1) * sizeof (WCHAR
) );
2015 if ( !This
->sPathRel
)
2016 return E_OUTOFMEMORY
;
2017 wcscpy( This
->sPathRel
, pszPathRel
);
2018 This
->bDirty
= TRUE
;
2020 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
2023 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
2028 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2030 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
2032 /*FIXME: use IResolveShellLink interface */
2034 if (!This
->sPath
&& This
->pPidl
) {
2035 WCHAR buffer
[MAX_PATH
];
2037 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
2039 if (bSuccess
&& *buffer
) {
2040 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (wcslen(buffer
)+1)*sizeof(WCHAR
));
2042 return E_OUTOFMEMORY
;
2044 wcscpy(This
->sPath
, buffer
);
2046 This
->bDirty
= TRUE
;
2048 hr
= S_OK
; /* don't report an error occurred while just caching information */
2051 if (!This
->sIcoPath
&& This
->sPath
) {
2052 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (wcslen(This
->sPath
)+1)*sizeof(WCHAR
));
2053 if (!This
->sIcoPath
)
2054 return E_OUTOFMEMORY
;
2056 wcscpy(This
->sIcoPath
, This
->sPath
);
2059 This
->bDirty
= TRUE
;
2065 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2074 p
= wcschr( str
, ':' );
2078 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2081 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2086 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2088 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2096 /* each segment must start with two colons */
2097 if( str
[0] != ':' || str
[1] != ':' )
2100 /* the last segment is just two colons */
2105 /* there must be a colon straight after a guid */
2106 p
= wcschr( str
, ':' );
2113 /* get the guid, and check it's validly formatted */
2114 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2116 r
= CLSIDFromString( szGuid
, &guid
);
2121 /* match it up to a guid that we care about */
2122 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2124 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2129 /* skip to the next field */
2130 str
= wcschr( str
, ':' );
2135 /* we have to have a component for an advertised shortcut */
2139 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2140 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2142 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2143 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2148 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2150 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2151 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
2154 volume
->type
= GetDriveTypeW(drive
);
2155 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2156 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2157 TRACE("r = %d type %d serial %08x name %s\n", r
,
2158 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2162 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2164 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2165 WCHAR buffer
[MAX_PATH
];
2166 LPWSTR fname
, unquoted
= NULL
;
2170 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2172 /* quotes at the ends of the string are stripped */
2173 len
= wcslen(pszFile
);
2174 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2176 unquoted
= strdupW(pszFile
);
2177 PathUnquoteSpacesW(unquoted
);
2181 /* any other quote marks are invalid */
2182 if (wcschr(pszFile
, '"'))
2185 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2188 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2189 This
->sComponent
= NULL
;
2192 ILFree(This
->pPidl
);
2195 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2197 if (*pszFile
== '\0')
2199 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2201 else if(!PathFileExistsW(buffer
) &&
2202 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2205 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2206 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2208 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2209 (wcslen( buffer
)+1) * sizeof (WCHAR
) );
2211 return E_OUTOFMEMORY
;
2213 wcscpy(This
->sPath
, buffer
);
2215 This
->bDirty
= TRUE
;
2216 HeapFree(GetProcessHeap(), 0, unquoted
);
2221 /**************************************************************************
2222 * IShellLinkW Implementation
2225 static const IShellLinkWVtbl slvtw
=
2227 IShellLinkW_fnQueryInterface
,
2228 IShellLinkW_fnAddRef
,
2229 IShellLinkW_fnRelease
,
2230 IShellLinkW_fnGetPath
,
2231 IShellLinkW_fnGetIDList
,
2232 IShellLinkW_fnSetIDList
,
2233 IShellLinkW_fnGetDescription
,
2234 IShellLinkW_fnSetDescription
,
2235 IShellLinkW_fnGetWorkingDirectory
,
2236 IShellLinkW_fnSetWorkingDirectory
,
2237 IShellLinkW_fnGetArguments
,
2238 IShellLinkW_fnSetArguments
,
2239 IShellLinkW_fnGetHotkey
,
2240 IShellLinkW_fnSetHotkey
,
2241 IShellLinkW_fnGetShowCmd
,
2242 IShellLinkW_fnSetShowCmd
,
2243 IShellLinkW_fnGetIconLocation
,
2244 IShellLinkW_fnSetIconLocation
,
2245 IShellLinkW_fnSetRelativePath
,
2246 IShellLinkW_fnResolve
,
2247 IShellLinkW_fnSetPath
2250 static HRESULT WINAPI
2251 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2253 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2254 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2258 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2260 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2261 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2265 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2267 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2268 return ShellLink_Release( This
);
2271 static HRESULT WINAPI
2272 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2278 static HRESULT WINAPI
2279 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2281 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2282 LPVOID block
= NULL
;
2285 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2289 case EXP_DARWIN_ID_SIG
:
2290 if (!This
->sComponent
)
2292 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2295 case EXP_SZ_LINK_SIG
:
2296 case NT_CONSOLE_PROPS_SIG
:
2297 case NT_FE_CONSOLE_PROPS_SIG
:
2298 case EXP_SPECIAL_FOLDER_SIG
:
2299 case EXP_SZ_ICON_SIG
:
2300 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2303 ERR("unknown datablock %08x\n", dwSig
);
2305 *ppDataBlock
= block
;
2309 static HRESULT WINAPI
2310 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2316 static HRESULT WINAPI
2317 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2319 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2322 FIXME("%p %p\n", This
, pdwFlags
);
2324 /* FIXME: add more */
2326 flags
|= SLDF_HAS_ARGS
;
2327 if (This
->sComponent
)
2328 flags
|= SLDF_HAS_DARWINID
;
2330 flags
|= SLDF_HAS_ICONLOCATION
;
2331 #if (NTDDI_VERSION < NTDDI_LONGHORN)
2333 flags
|= SLDF_HAS_LOGO3ID
;
2336 flags
|= SLDF_HAS_ID_LIST
;
2343 static HRESULT WINAPI
2344 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2350 static const IShellLinkDataListVtbl dlvt
=
2352 ShellLink_DataList_QueryInterface
,
2353 ShellLink_DataList_AddRef
,
2354 ShellLink_DataList_Release
,
2355 ShellLink_AddDataBlock
,
2356 ShellLink_CopyDataBlock
,
2357 ShellLink_RemoveDataBlock
,
2362 static HRESULT WINAPI
2363 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2365 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2366 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2370 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2372 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2373 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2377 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2379 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2380 return ShellLink_Release( This
);
2383 /**************************************************************************
2384 * ShellLink implementation of IShellExtInit::Initialize()
2386 * Loads the shelllink from the dataobject the shell is pointing to.
2388 static HRESULT WINAPI
2389 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2390 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2392 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2398 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2403 format
.cfFormat
= CF_HDROP
;
2405 format
.dwAspect
= DVASPECT_CONTENT
;
2407 format
.tymed
= TYMED_HGLOBAL
;
2409 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2412 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2417 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2419 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2422 IPersistFile
*pf
= (IPersistFile
*) &This
->lpvtblPersistFile
;
2424 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2425 r
= IPersistFile_Load( pf
, path
, 0 );
2426 HeapFree( GetProcessHeap(), 0, path
);
2429 ReleaseStgMedium( &stgm
);
2434 static const IShellExtInitVtbl eivt
=
2436 ShellLink_ExtInit_QueryInterface
,
2437 ShellLink_ExtInit_AddRef
,
2438 ShellLink_ExtInit_Release
,
2439 ShellLink_ExtInit_Initialize
2442 static HRESULT WINAPI
2443 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2445 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2446 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2450 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2452 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2453 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2457 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2459 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2460 return ShellLink_Release( This
);
2463 static HRESULT WINAPI
2464 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2465 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2467 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2472 TRACE("%p %p %u %u %u %u\n", This
,
2473 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2476 return E_INVALIDARG
;
2478 if (!LoadStringW(shell32_hInstance
, IDS_OPEN_VERB
, szOpen
, sizeof(szOpen
)/sizeof(WCHAR
)))
2481 szOpen
[(sizeof(szOpen
)/sizeof(WCHAR
))-1] = L
'\0';
2483 memset( &mii
, 0, sizeof(mii
) );
2484 mii
.cbSize
= sizeof (mii
);
2485 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2486 mii
.dwTypeData
= (LPWSTR
)szOpen
;
2487 mii
.cch
= wcslen( mii
.dwTypeData
);
2488 mii
.wID
= idCmdFirst
+ id
++;
2489 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2490 mii
.fType
= MFT_STRING
;
2491 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2495 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2499 shelllink_get_msi_component_path( LPWSTR component
)
2504 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2505 if (r
!= ERROR_SUCCESS
)
2509 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2510 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2511 if (r
!= ERROR_SUCCESS
)
2513 HeapFree( GetProcessHeap(), 0, path
);
2517 TRACE("returning %s\n", debugstr_w( path
) );
2522 INT_PTR CALLBACK
ExtendedShortcutProc(
2536 hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2537 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2541 hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2542 if (LOWORD(wParam
) == IDOK
)
2544 if ( SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2545 EndDialog(hwndDlg
, 1);
2547 EndDialog(hwndDlg
, 0);
2549 else if (LOWORD(wParam
) == IDCANCEL
)
2551 EndDialog(hwndDlg
, -1);
2553 else if (LOWORD(wParam
) == 14000)
2555 if ( SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2556 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2558 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2565 /**************************************************************************
2566 * SH_ShellLinkDlgProc
2568 * dialog proc of the shortcut property dialog
2573 SH_ShellLinkDlgProc(
2580 LPPROPSHEETPAGEW ppsp
;
2582 IShellLinkImpl
*This
;
2584 WCHAR szBuffer
[MAX_PATH
];
2589 This
= (IShellLinkImpl
*)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
2594 ppsp
= (LPPROPSHEETPAGEW
)lParam
;
2598 TRACE("ShellLink_DlgProc (WM_INITDIALOG hwnd %p lParam %p ppsplParam %x)\n",hwndDlg
, lParam
, ppsp
->lParam
);
2600 This
= (IShellLinkImpl
*)ppsp
->lParam
;
2601 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)This
);
2603 TRACE("sArgs: %S sComponent: %S sDescription: %S sIcoPath: %S sPath: %S sPathRel: %S sProduct: %S sWorkDir: %S\n", This
->sArgs
, This
->sComponent
,This
->sDescription
,
2604 This
->sIcoPath
, This
->sPath
, This
->sPathRel
, This
->sProduct
, This
->sWorkDir
);
2607 hDlgCtrl
= GetDlgItem( hwndDlg
, 14009 );
2608 if ( hDlgCtrl
!= NULL
)
2609 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sPath
);
2612 hDlgCtrl
= GetDlgItem( hwndDlg
, 14011 );
2613 if ( hDlgCtrl
!= NULL
)
2614 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sWorkDir
);
2617 hDlgCtrl
= GetDlgItem( hwndDlg
, 14019 );
2618 if ( hDlgCtrl
!= NULL
)
2619 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sDescription
);
2622 lppsn
= (LPPSHNOTIFY
) lParam
;
2623 if ( lppsn
->hdr
.code
== PSN_APPLY
)
2625 /* set working directory */
2626 hDlgCtrl
= GetDlgItem( hwndDlg
, 14011 );
2627 SendMessageW( hDlgCtrl
, WM_GETTEXT
, (WPARAM
)MAX_PATH
, (LPARAM
)szBuffer
);
2628 IShellLinkW_fnSetWorkingDirectory((IShellLinkW
*)&This
->lpvtblw
, szBuffer
);
2629 /* set link destination */
2630 hDlgCtrl
= GetDlgItem( hwndDlg
, 14009 );
2631 SendMessageW( hDlgCtrl
, WM_GETTEXT
, (WPARAM
)MAX_PATH
, (LPARAM
)szBuffer
);
2632 if ( !SHELL_ExistsFileW(szBuffer
) )
2634 //FIXME load localized error msg
2635 MessageBoxW( hwndDlg
, L
"file not existing", szBuffer
, MB_OK
);
2636 SetWindowLongPtr( hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2639 ptr
= wcsrchr(szBuffer
, L
'.');
2640 if (ptr
&& !_wcsnicmp(ptr
, L
".lnk", 4))
2642 // FIXME load localized error msg
2643 MessageBoxW( hwndDlg
, L
"You cannot create a link to a shortcut", L
"Error", MB_ICONERROR
);
2644 SetWindowLongPtr( hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2648 IShellLinkW_fnSetPath((IShellLinkW
*)&This
->lpvtblw
, szBuffer
);
2650 TRACE("This %p sLinkPath %S\n", This
, This
->sLinkPath
);
2651 IPersistFile_fnSave( (IPersistFile
*)&This
->lpvtblPersistFile
, This
->sLinkPath
, TRUE
);
2652 SetWindowLongPtr( hwndDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
2657 switch(LOWORD(wParam
))
2662 /// open target directory
2667 wcscpy(szBuffer
, This
->sIcoPath
);
2668 IconIndex
= This
->iIcoNdx
;
2669 if (PickIconDlg(hwndDlg
, szBuffer
, MAX_PATH
, &IconIndex
))
2671 IShellLinkW_fnSetIconLocation((IShellLinkW
*)&This
->lpvtblw
, szBuffer
, IconIndex
);
2673 /// FIXME redraw icon
2677 result
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(SHELL_EXTENDED_SHORTCUT_DLG
), hwndDlg
, ExtendedShortcutProc
, (LPARAM
)This
->bRunAs
);
2678 if (result
== 1 || result
== 0)
2680 if ( This
->bRunAs
!= result
)
2682 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2685 This
->bRunAs
= result
;
2689 switch(HIWORD(wParam
))
2692 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2702 /**************************************************************************
2703 * ShellLink_IShellPropSheetExt interface
2706 static HRESULT WINAPI
2707 ShellLink_IShellPropSheetExt_QueryInterface( IShellPropSheetExt
* iface
, REFIID riid
, void** ppvObject
)
2709 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2710 return ShellLink_QueryInterface( This
, riid
, ppvObject
);
2714 ShellLink_IShellPropSheetExt_AddRef( IShellPropSheetExt
* iface
)
2716 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2717 return ShellLink_AddRef( This
);
2721 ShellLink_IShellPropSheetExt_Release( IShellPropSheetExt
* iface
)
2723 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2724 return ShellLink_Release( This
);
2727 static HRESULT WINAPI
2728 ShellLink_IShellPropSheetExt_AddPages( IShellPropSheetExt
*iface
, LPFNADDPROPSHEETPAGE pfnAddPage
, LPARAM lParam
)
2730 HPROPSHEETPAGE hPage
;
2732 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2734 hPage
= SH_CreatePropertySheetPage("SHELL_GENERAL_SHORTCUT_DLG", SH_ShellLinkDlgProc
, (LPARAM
)This
, NULL
);
2737 ERR("failed to create property sheet page\n");
2741 bRet
= pfnAddPage(hPage
, lParam
);
2748 static HRESULT WINAPI
2749 ShellLink_IShellPropSheetExt_ReplacePages( IShellPropSheetExt
*iface
, UINT uPageID
, LPFNADDPROPSHEETPAGE pfnReplacePage
, LPARAM lParam
)
2751 IShellLinkImpl
*This
= impl_from_IShellPropSheetExt(iface
);
2752 TRACE("(%p) (uPageID %u, pfnReplacePage %p lParam %p\n", This
, uPageID
, pfnReplacePage
, lParam
);
2756 static const IShellPropSheetExtVtbl pse
=
2758 ShellLink_IShellPropSheetExt_QueryInterface
,
2759 ShellLink_IShellPropSheetExt_AddRef
,
2760 ShellLink_IShellPropSheetExt_Release
,
2761 ShellLink_IShellPropSheetExt_AddPages
,
2762 ShellLink_IShellPropSheetExt_ReplacePages
2765 static HRESULT WINAPI
2766 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2768 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2769 static const WCHAR szOpen
[] = { 'o','p','e','n',0 };
2770 static const WCHAR szCplOpen
[] = { 'c','p','l','o','p','e','n',0 };
2771 SHELLEXECUTEINFOW sei
;
2772 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2777 TRACE("%p %p\n", This
, lpici
);
2779 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2780 return E_INVALIDARG
;
2782 r
= IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, 0 );
2785 TRACE("failed to resolve component with error 0x%08x", r
);
2788 if ( This
->sComponent
)
2790 path
= shelllink_get_msi_component_path( This
->sComponent
);
2795 path
= strdupW( This
->sPath
);
2797 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2798 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2800 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2804 len
+= wcslen( This
->sArgs
);
2805 if ( iciex
->lpParametersW
)
2806 len
+= wcslen( iciex
->lpParametersW
);
2808 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2811 wcscat( args
, This
->sArgs
);
2812 if ( iciex
->lpParametersW
)
2814 static const WCHAR space
[] = { ' ', 0 };
2815 wcscat( args
, space
);
2816 wcscat( args
, iciex
->lpParametersW
);
2820 memset( &sei
, 0, sizeof sei
);
2821 sei
.cbSize
= sizeof sei
;
2822 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2824 sei
.nShow
= This
->iShowCmd
;
2825 sei
.lpDirectory
= This
->sWorkDir
;
2826 sei
.lpParameters
= args
;
2827 sei
.lpVerb
= szOpen
;
2829 // HACK for ShellExecuteExW
2830 if (!wcsstr(This
->sPath
, L
".cpl"))
2831 sei
.lpVerb
= szOpen
;
2833 sei
.lpVerb
= szCplOpen
;
2835 if( ShellExecuteExW( &sei
) )
2840 HeapFree( GetProcessHeap(), 0, args
);
2841 HeapFree( GetProcessHeap(), 0, path
);
2846 static HRESULT WINAPI
2847 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2848 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2850 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2852 FIXME("%p %lu %u %p %p %u\n", This
,
2853 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2858 static const IContextMenuVtbl cmvt
=
2860 ShellLink_ContextMenu_QueryInterface
,
2861 ShellLink_ContextMenu_AddRef
,
2862 ShellLink_ContextMenu_Release
,
2863 ShellLink_QueryContextMenu
,
2864 ShellLink_InvokeCommand
,
2865 ShellLink_GetCommandString
2868 static HRESULT WINAPI
2869 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2871 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2872 return ShellLink_QueryInterface( This
, riid
, ppvObject
);
2876 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2878 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2879 return ShellLink_AddRef( This
);
2883 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2885 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2886 return ShellLink_Release( This
);
2889 static HRESULT WINAPI
2890 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2892 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2894 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2898 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2901 static HRESULT WINAPI
2902 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2904 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2906 TRACE("%p %p\n", iface
, punk
);
2909 IUnknown_AddRef( punk
);
2915 static const IObjectWithSiteVtbl owsvt
=
2917 ShellLink_ObjectWithSite_QueryInterface
,
2918 ShellLink_ObjectWithSite_AddRef
,
2919 ShellLink_ObjectWithSite_Release
,