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.
36 #define NONAMELESSUNION
38 #include "wine/debug.h"
48 #include "undocshell.h"
51 #include "shell32_main.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
61 DEFINE_GUID( SHELL32_AdvtShortcutProduct
,
62 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
63 DEFINE_GUID( SHELL32_AdvtShortcutComponent
,
64 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
66 /* link file formats */
70 typedef struct _LINK_HEADER
72 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
73 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
74 DWORD dwFlags
; /* 0x14 describes elements following */
75 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
76 FILETIME CreationTime
; /* 0x1c creation time of target file */
77 FILETIME AccessTime
; /* 0x24 access time of target file */
78 FILETIME WriteTime
; /* 0x2c write time of target file */
79 DWORD dwFileSize
; /* 0x34 File size of target file */
80 DWORD nIcon
; /* 0x38 icon number or index */
81 DWORD fStartup
; /* 0x3c startup type or window state of application */
82 WORD wHotKey
; /* 0x40 hotkey */
83 WORD Reserved1
; /* 0x42 reserved = 0 */
84 DWORD Reserved2
; /* 0x44 reserved = 0 */
85 DWORD Reserved3
; /* 0x48 reserved = 0 */
86 } LINK_HEADER
, * PLINK_HEADER
;
88 #define SHLINK_LOCAL 0
89 #define SHLINK_REMOTE 1
91 typedef struct _LOCATION_INFO
98 DWORD dwNetworkVolTableOfs
;
102 typedef struct _LOCAL_VOLUME_INFO
110 typedef struct volume_info_t
114 WCHAR label
[12]; /* assume 8.3 */
119 /* IShellLink Implementation */
123 IShellLinkA IShellLinkA_iface
;
124 IShellLinkW IShellLinkW_iface
;
125 IPersistFile IPersistFile_iface
;
126 IPersistStream IPersistStream_iface
;
127 IShellLinkDataList IShellLinkDataList_iface
;
128 IShellExtInit IShellExtInit_iface
;
129 IContextMenu IContextMenu_iface
;
130 IObjectWithSite IObjectWithSite_iface
;
131 IPropertyStore IPropertyStore_iface
;
135 /* data structures according to the information in the link */
138 SYSTEMTIME CreationTime
;
139 SYSTEMTIME AccessTime
;
140 SYSTEMTIME WriteTime
;
155 INT iIdOpen
; /* id of the "Open" entry in the context menu */
158 LPOLESTR filepath
; /* file path returned by IPersistFile::GetCurFile */
161 static inline IShellLinkImpl
*impl_from_IShellLinkA(IShellLinkA
*iface
)
163 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkA_iface
);
166 static inline IShellLinkImpl
*impl_from_IShellLinkW(IShellLinkW
*iface
)
168 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkW_iface
);
171 static inline IShellLinkImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
173 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistFile_iface
);
176 static inline IShellLinkImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
178 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistStream_iface
);
181 static inline IShellLinkImpl
*impl_from_IShellLinkDataList(IShellLinkDataList
*iface
)
183 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkDataList_iface
);
186 static inline IShellLinkImpl
*impl_from_IShellExtInit(IShellExtInit
*iface
)
188 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellExtInit_iface
);
191 static inline IShellLinkImpl
*impl_from_IContextMenu(IContextMenu
*iface
)
193 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IContextMenu_iface
);
196 static inline IShellLinkImpl
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
198 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IObjectWithSite_iface
);
201 static inline IShellLinkImpl
*impl_from_IPropertyStore(IPropertyStore
*iface
)
203 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPropertyStore_iface
);
206 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
208 /* strdup on the process heap */
209 static inline LPWSTR
heap_strdupAtoW( LPCSTR str
)
211 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
212 LPWSTR p
= heap_alloc( len
*sizeof (WCHAR
) );
215 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
219 /**************************************************************************
220 * IPersistFile_QueryInterface
222 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
227 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
228 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
231 /******************************************************************************
232 * IPersistFile_AddRef
234 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
236 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
237 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
240 /******************************************************************************
241 * IPersistFile_Release
243 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
245 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
246 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
249 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
251 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
253 TRACE("(%p)->(%p)\n", This
, pClassID
);
255 *pClassID
= CLSID_ShellLink
;
260 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
262 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
264 TRACE("(%p)\n",This
);
272 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
274 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
275 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
279 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
282 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
283 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
286 r
= IPersistStream_Load(StreamThis
, stm
);
287 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
288 IStream_Release( stm
);
290 /* update file path */
291 heap_free(This
->filepath
);
292 This
->filepath
= strdupW(pszFileName
);
294 This
->bDirty
= FALSE
;
296 TRACE("-- returning hr %08x\n", r
);
300 BOOL
run_winemenubuilder( const WCHAR
*args
)
302 static const WCHAR menubuilder
[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
306 PROCESS_INFORMATION pi
;
311 GetSystemDirectoryW( app
, MAX_PATH
- ARRAY_SIZE(menubuilder
) );
312 strcatW( app
, menubuilder
);
314 len
= (strlenW( app
) + strlenW( args
) + 1) * sizeof(WCHAR
);
315 buffer
= heap_alloc( len
);
319 strcpyW( buffer
, app
);
320 strcatW( buffer
, args
);
322 TRACE("starting %s\n",debugstr_w(buffer
));
324 memset(&si
, 0, sizeof(si
));
327 Wow64DisableWow64FsRedirection( &redir
);
328 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
329 Wow64RevertWow64FsRedirection( redir
);
335 CloseHandle( pi
.hProcess
);
336 CloseHandle( pi
.hThread
);
342 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
344 static const WCHAR szFormat
[] = {' ','-','w',' ','"','%','s','"',0 };
349 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
350 buffer
= heap_alloc( len
);
354 wsprintfW( buffer
, szFormat
, szLink
);
355 ret
= run_winemenubuilder( buffer
);
360 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
362 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
363 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
367 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
372 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
375 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
376 IStream_Release( stm
);
380 StartLinkProcessor( pszFileName
);
382 /* update file path */
383 heap_free(This
->filepath
);
384 This
->filepath
= strdupW(pszFileName
);
386 This
->bDirty
= FALSE
;
390 DeleteFileW( pszFileName
);
391 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
398 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
400 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
401 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
405 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
407 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
409 TRACE("(%p)->(%p)\n", This
, filename
);
417 *filename
= CoTaskMemAlloc((strlenW(This
->filepath
) + 1) * sizeof(WCHAR
));
418 if (!*filename
) return E_OUTOFMEMORY
;
420 strcpyW(*filename
, This
->filepath
);
425 static const IPersistFileVtbl pfvt
=
427 IPersistFile_fnQueryInterface
,
428 IPersistFile_fnAddRef
,
429 IPersistFile_fnRelease
,
430 IPersistFile_fnGetClassID
,
431 IPersistFile_fnIsDirty
,
434 IPersistFile_fnSaveCompleted
,
435 IPersistFile_fnGetCurFile
438 /************************************************************************
439 * IPersistStream_QueryInterface
441 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
442 IPersistStream
* iface
,
446 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
447 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
450 /************************************************************************
451 * IPersistStream_Release
453 static ULONG WINAPI
IPersistStream_fnRelease(
454 IPersistStream
* iface
)
456 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
457 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
460 /************************************************************************
461 * IPersistStream_AddRef
463 static ULONG WINAPI
IPersistStream_fnAddRef(
464 IPersistStream
* iface
)
466 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
467 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
470 /************************************************************************
471 * IPersistStream_GetClassID
474 static HRESULT WINAPI
IPersistStream_fnGetClassID(
475 IPersistStream
* iface
,
478 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
479 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
482 /************************************************************************
483 * IPersistStream_IsDirty (IPersistStream)
485 static HRESULT WINAPI
IPersistStream_fnIsDirty(
486 IPersistStream
* iface
)
488 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
490 TRACE("(%p)\n", This
);
496 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
507 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
508 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
512 len
*= sizeof (WCHAR
);
514 TRACE("reading %d\n", len
);
515 temp
= heap_alloc(len
+ sizeof(WCHAR
));
517 return E_OUTOFMEMORY
;
519 r
= IStream_Read(stm
, temp
, len
, &count
);
520 if( FAILED (r
) || ( count
!= len
) )
526 TRACE("read %s\n", debugstr_an(temp
,len
));
528 /* convert to unicode if necessary */
531 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
532 str
= heap_alloc( (count
+1)*sizeof (WCHAR
) );
536 return E_OUTOFMEMORY
;
538 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
553 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
560 unsigned char data
[1];
565 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
566 if( FAILED( r
) || count
!= sizeof(size
) )
569 chunk
= heap_alloc( size
);
571 return E_OUTOFMEMORY
;
574 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
575 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
581 TRACE("Read %d bytes\n",chunk
->size
);
588 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
590 const int label_sz
= ARRAY_SIZE(volume
->label
);
594 volume
->serial
= vol
->dwVolSerial
;
595 volume
->type
= vol
->dwType
;
597 if( !vol
->dwVolLabelOfs
)
599 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
601 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
604 label
+= vol
->dwVolLabelOfs
;
605 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
610 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
615 while( (len
< maxlen
) && p
[len
] )
618 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
619 path
= heap_alloc((wlen
+ 1) * sizeof(WCHAR
));
620 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
626 static HRESULT
Stream_LoadLocation( IStream
*stm
,
627 volume_info
*volume
, LPWSTR
*path
)
634 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
638 loc
= (LOCATION_INFO
*) p
;
639 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
645 /* if there's valid local volume information, load it */
646 if( loc
->dwVolTableOfs
&&
647 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
649 LOCAL_VOLUME_INFO
*volume_info
;
651 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
652 Stream_LoadVolume( volume_info
, volume
);
655 /* if there's a local path, load it */
656 n
= loc
->dwLocalPathOfs
;
657 if( n
&& (n
< loc
->dwTotalSize
) )
658 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
660 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
661 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
668 * The format of the advertised shortcut info seems to be:
673 * 0 Length of the block (4 bytes, usually 0x314)
675 * 8 string data in ASCII
676 * 8+0x104 string data in UNICODE
678 * In the original Win32 implementation the buffers are not initialized
679 * to zero, so data trailing the string is random garbage.
681 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
686 EXP_DARWIN_LINK buffer
;
690 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
694 /* make sure that we read the size of the structure even on error */
695 size
= sizeof buffer
- sizeof (DWORD
);
696 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
698 ERR("Ooops. This structure is not as expected...\n");
702 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
709 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
711 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
713 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
717 *str
= heap_alloc((lstrlenW(buffer
.szwDarwinID
) + 1) * sizeof(WCHAR
) );
718 lstrcpyW( *str
, buffer
.szwDarwinID
);
723 /************************************************************************
724 * IPersistStream_Load (IPersistStream)
726 static HRESULT WINAPI
IPersistStream_fnLoad(
727 IPersistStream
* iface
,
736 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
738 TRACE("%p %p\n", This
, stm
);
741 return STG_E_INVALIDPOINTER
;
744 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
748 if( dwBytesRead
!= sizeof(hdr
))
750 if( hdr
.dwSize
!= sizeof(hdr
))
752 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
755 /* free all the old stuff */
758 memset( &This
->volume
, 0, sizeof This
->volume
);
759 heap_free(This
->sPath
);
761 heap_free(This
->sDescription
);
762 This
->sDescription
= NULL
;
763 heap_free(This
->sPathRel
);
764 This
->sPathRel
= NULL
;
765 heap_free(This
->sWorkDir
);
766 This
->sWorkDir
= NULL
;
767 heap_free(This
->sArgs
);
769 heap_free(This
->sIcoPath
);
770 This
->sIcoPath
= NULL
;
771 heap_free(This
->sProduct
);
772 This
->sProduct
= NULL
;
773 heap_free(This
->sComponent
);
774 This
->sComponent
= NULL
;
776 This
->wHotKey
= hdr
.wHotKey
;
777 This
->iIcoNdx
= hdr
.nIcon
;
778 FileTimeToSystemTime (&hdr
.CreationTime
, &This
->CreationTime
);
779 FileTimeToSystemTime (&hdr
.AccessTime
, &This
->AccessTime
);
780 FileTimeToSystemTime (&hdr
.WriteTime
, &This
->WriteTime
);
783 WCHAR sTemp
[MAX_PATH
];
784 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->CreationTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
785 TRACE("-- CreationTime: %s\n", debugstr_w(sTemp
) );
786 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->AccessTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
787 TRACE("-- AccessTime: %s\n", debugstr_w(sTemp
) );
788 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->WriteTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
789 TRACE("-- WriteTime: %s\n", debugstr_w(sTemp
) );
792 /* load all the new stuff */
793 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
795 r
= ILLoadFromStream( stm
, &This
->pPidl
);
801 /* load the location information */
802 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
803 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
807 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
808 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
810 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
811 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
816 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
818 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
819 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
824 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
826 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
827 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
832 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
834 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
835 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
840 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
842 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
843 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
848 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
850 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
851 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
856 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
858 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
859 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
864 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
865 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
867 /* Some lnk files have extra data blocks starting with a
868 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
869 * one with a 0xa0000003 signature. However these don't seem to matter
872 WARN("Last word was not zero\n");
884 /************************************************************************
887 * Helper function for IPersistStream_Save. Writes a unicode string
888 * with terminating nul byte to a stream, preceded by the its length.
890 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
892 USHORT len
= lstrlenW( str
) + 1;
896 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
900 len
*= sizeof(WCHAR
);
902 r
= IStream_Write( stm
, str
, len
, &count
);
909 /************************************************************************
910 * Stream_WriteLocationInfo
912 * Writes the location info to a stream
914 * FIXME: One day we might want to write the network volume information
915 * and the final path.
916 * Figure out how Windows deals with unicode paths here.
918 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
919 volume_info
*volume
)
921 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
922 LOCAL_VOLUME_INFO
*vol
;
924 LPSTR szLabel
, szPath
, szFinalPath
;
928 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
930 /* figure out the size of everything */
931 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
932 NULL
, 0, NULL
, NULL
);
933 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
934 NULL
, 0, NULL
, NULL
);
935 volume_info_size
= sizeof *vol
+ label_size
;
937 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
939 /* create pointers to everything */
940 loc
= heap_alloc_zero(total_size
);
941 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
942 szLabel
= (LPSTR
) &vol
[1];
943 szPath
= &szLabel
[label_size
];
944 szFinalPath
= &szPath
[path_size
];
946 /* fill in the location information header */
947 loc
->dwTotalSize
= total_size
;
948 loc
->dwHeaderSize
= sizeof (*loc
);
950 loc
->dwVolTableOfs
= sizeof (*loc
);
951 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
952 loc
->dwNetworkVolTableOfs
= 0;
953 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
955 /* fill in the volume information */
956 vol
->dwSize
= volume_info_size
;
957 vol
->dwType
= volume
->type
;
958 vol
->dwVolSerial
= volume
->serial
;
959 vol
->dwVolLabelOfs
= sizeof (*vol
);
961 /* copy in the strings */
962 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
963 szLabel
, label_size
, NULL
, NULL
);
964 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
965 szPath
, path_size
, NULL
, NULL
);
968 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
974 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
976 EXP_DARWIN_LINK
*buffer
;
978 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
979 buffer
->dbh
.cbSize
= sizeof *buffer
;
980 buffer
->dbh
.dwSignature
= magic
;
981 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
982 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
987 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
989 EXP_DARWIN_LINK
*buffer
;
994 buffer
= shelllink_build_darwinid( string
, magic
);
996 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
999 /************************************************************************
1000 * IPersistStream_Save (IPersistStream)
1002 * FIXME: makes assumptions about byte order
1004 static HRESULT WINAPI
IPersistStream_fnSave(
1005 IPersistStream
* iface
,
1014 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1016 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1018 memset(&header
, 0, sizeof(header
));
1019 header
.dwSize
= sizeof(header
);
1020 header
.fStartup
= This
->iShowCmd
;
1021 header
.MagicGuid
= CLSID_ShellLink
;
1023 header
.wHotKey
= This
->wHotKey
;
1024 header
.nIcon
= This
->iIcoNdx
;
1025 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1027 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1029 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1030 if( This
->sDescription
)
1031 header
.dwFlags
|= SLDF_HAS_NAME
;
1032 if( This
->sWorkDir
)
1033 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1035 header
.dwFlags
|= SLDF_HAS_ARGS
;
1036 if( This
->sIcoPath
)
1037 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1038 if( This
->sProduct
)
1039 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1040 if( This
->sComponent
)
1041 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1043 SystemTimeToFileTime ( &This
->CreationTime
, &header
.CreationTime
);
1044 SystemTimeToFileTime ( &This
->AccessTime
, &header
.AccessTime
);
1045 SystemTimeToFileTime ( &This
->WriteTime
, &header
.WriteTime
);
1047 /* write the Shortcut header */
1048 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1051 ERR("Write failed at %d\n",__LINE__
);
1055 TRACE("Writing pidl\n");
1057 /* write the PIDL to the shortcut */
1060 r
= ILSaveToStream( stm
, This
->pPidl
);
1063 ERR("Failed to write PIDL at %d\n",__LINE__
);
1069 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1071 if( This
->sDescription
)
1072 r
= Stream_WriteString( stm
, This
->sDescription
);
1074 if( This
->sPathRel
)
1075 r
= Stream_WriteString( stm
, This
->sPathRel
);
1077 if( This
->sWorkDir
)
1078 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1081 r
= Stream_WriteString( stm
, This
->sArgs
);
1083 if( This
->sIcoPath
)
1084 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1086 if( This
->sProduct
)
1087 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1089 if( This
->sComponent
)
1090 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1092 /* the last field is a single zero dword */
1094 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1099 /************************************************************************
1100 * IPersistStream_GetSizeMax (IPersistStream)
1102 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1103 IPersistStream
* iface
,
1104 ULARGE_INTEGER
* pcbSize
)
1106 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1108 TRACE("(%p)\n", This
);
1113 static const IPersistStreamVtbl psvt
=
1115 IPersistStream_fnQueryInterface
,
1116 IPersistStream_fnAddRef
,
1117 IPersistStream_fnRelease
,
1118 IPersistStream_fnGetClassID
,
1119 IPersistStream_fnIsDirty
,
1120 IPersistStream_fnLoad
,
1121 IPersistStream_fnSave
,
1122 IPersistStream_fnGetSizeMax
1125 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1127 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1132 /**************************************************************************
1133 * ShellLink_UpdatePath
1134 * update absolute path in sPath using relative path in sPathRel
1136 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1138 if (!path
|| !psPath
)
1139 return E_INVALIDARG
;
1141 if (!*psPath
&& sPathRel
) {
1142 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1143 LPWSTR final
= NULL
;
1145 /* first try if [directory of link file] + [relative path] finds an existing file */
1147 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1150 lstrcpyW(final
, sPathRel
);
1154 if (SHELL_ExistsFileW(buffer
)) {
1155 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1156 lstrcpyW(abs_path
, buffer
);
1158 /* try if [working directory] + [relative path] finds an existing file */
1160 lstrcpyW(buffer
, sWorkDir
);
1161 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1163 if (SHELL_ExistsFileW(buffer
))
1164 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1165 lstrcpyW(abs_path
, buffer
);
1169 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1171 lstrcpyW(abs_path
, sPathRel
);
1173 *psPath
= heap_alloc((lstrlenW(abs_path
) + 1) * sizeof(WCHAR
));
1175 return E_OUTOFMEMORY
;
1177 lstrcpyW(*psPath
, abs_path
);
1183 /**************************************************************************
1184 * IShellLink_ConstructFromFile
1186 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1187 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1191 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1193 if (SUCCEEDED(hr
)) {
1198 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1200 if (SUCCEEDED(hr
)) {
1201 WCHAR path
[MAX_PATH
];
1203 if (SHGetPathFromIDListW(pidl
, path
))
1204 hr
= IPersistFile_Load(ppf
, path
, 0);
1209 *ppv
= (IUnknown
*)psl
;
1211 IPersistFile_Release(ppf
);
1215 IShellLinkW_Release(psl
);
1221 /**************************************************************************
1222 * IShellLinkA_QueryInterface
1224 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1226 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1227 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1230 /******************************************************************************
1231 * IShellLinkA_AddRef
1233 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1235 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1236 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1239 /******************************************************************************
1240 * IShellLinkA_Release
1242 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1244 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1245 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1248 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1249 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1251 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1254 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1255 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1257 if (This
->sComponent
|| This
->sProduct
)
1262 if (This
->sPath
&& This
->sPath
[0])
1263 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1264 pszFile
, cchMaxPath
, NULL
, NULL
);
1270 memset(pfd
, 0, sizeof(*pfd
));
1274 char path
[MAX_PATH
];
1275 WIN32_FILE_ATTRIBUTE_DATA fad
;
1277 WideCharToMultiByte(CP_ACP
, 0, This
->sPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
1279 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1281 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1282 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1283 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1284 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1285 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1286 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1289 lstrcpyA(pfd
->cFileName
, PathFindFileNameA(path
));
1291 if (GetShortPathNameA(path
, path
, MAX_PATH
))
1293 lstrcpyA(pfd
->cAlternateFileName
, PathFindFileNameA(path
));
1297 TRACE("attr 0x%08x size 0x%08x%08x name %s shortname %s\n", pfd
->dwFileAttributes
,
1298 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_a(pfd
->cFileName
),
1299 wine_dbgstr_a(pfd
->cAlternateFileName
));
1305 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1307 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1308 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1311 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1313 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1314 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1317 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1320 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1322 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1326 if( This
->sDescription
)
1327 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1328 pszName
, cchMaxName
, NULL
, NULL
);
1333 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1335 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1339 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1343 descrW
= heap_strdupAtoW(pszName
);
1344 if (!descrW
) return E_OUTOFMEMORY
;
1349 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1355 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1358 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1360 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1364 if( This
->sWorkDir
)
1365 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1366 pszDir
, cchMaxPath
, NULL
, NULL
);
1371 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1373 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1377 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1379 dirW
= heap_strdupAtoW(pszDir
);
1380 if (!dirW
) return E_OUTOFMEMORY
;
1382 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1388 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1390 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1392 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1397 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1398 pszArgs
, cchMaxPath
, NULL
, NULL
);
1403 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1405 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1409 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1413 argsW
= heap_strdupAtoW(pszArgs
);
1414 if (!argsW
) return E_OUTOFMEMORY
;
1419 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1425 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1427 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1428 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1431 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1433 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1434 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1437 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1439 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1440 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1443 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1445 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1446 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1449 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1450 INT cchIconPath
, INT
*piIcon
)
1452 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1454 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1456 *piIcon
= This
->iIcoNdx
;
1459 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1466 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR path
, INT icon
)
1468 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1469 WCHAR
*pathW
= NULL
;
1472 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_a(path
), icon
);
1476 pathW
= heap_strdupAtoW(path
);
1478 return E_OUTOFMEMORY
;
1481 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, path
? pathW
: NULL
, icon
);
1487 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1490 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1494 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1496 pathW
= heap_strdupAtoW(pszPathRel
);
1497 if (!pathW
) return E_OUTOFMEMORY
;
1499 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1505 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1507 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1509 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1511 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1514 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1516 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1520 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1522 if (!pszFile
) return E_INVALIDARG
;
1524 str
= heap_strdupAtoW(pszFile
);
1526 return E_OUTOFMEMORY
;
1528 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1534 /**************************************************************************
1535 * IShellLink Implementation
1538 static const IShellLinkAVtbl slvt
=
1540 IShellLinkA_fnQueryInterface
,
1541 IShellLinkA_fnAddRef
,
1542 IShellLinkA_fnRelease
,
1543 IShellLinkA_fnGetPath
,
1544 IShellLinkA_fnGetIDList
,
1545 IShellLinkA_fnSetIDList
,
1546 IShellLinkA_fnGetDescription
,
1547 IShellLinkA_fnSetDescription
,
1548 IShellLinkA_fnGetWorkingDirectory
,
1549 IShellLinkA_fnSetWorkingDirectory
,
1550 IShellLinkA_fnGetArguments
,
1551 IShellLinkA_fnSetArguments
,
1552 IShellLinkA_fnGetHotkey
,
1553 IShellLinkA_fnSetHotkey
,
1554 IShellLinkA_fnGetShowCmd
,
1555 IShellLinkA_fnSetShowCmd
,
1556 IShellLinkA_fnGetIconLocation
,
1557 IShellLinkA_fnSetIconLocation
,
1558 IShellLinkA_fnSetRelativePath
,
1559 IShellLinkA_fnResolve
,
1560 IShellLinkA_fnSetPath
1564 /**************************************************************************
1565 * IShellLinkW_fnQueryInterface
1567 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1568 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1570 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1572 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1576 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1578 *ppvObj
= &This
->IShellLinkA_iface
;
1580 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1582 *ppvObj
= &This
->IShellLinkW_iface
;
1584 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1586 *ppvObj
= &This
->IPersistFile_iface
;
1588 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1590 *ppvObj
= &This
->IPersistStream_iface
;
1592 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1594 *ppvObj
= &This
->IShellLinkDataList_iface
;
1596 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1598 *ppvObj
= &This
->IShellExtInit_iface
;
1600 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1602 *ppvObj
= &This
->IContextMenu_iface
;
1604 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1606 *ppvObj
= &This
->IObjectWithSite_iface
;
1608 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1610 *ppvObj
= &This
->IPropertyStore_iface
;
1615 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1616 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1619 ERR("-- Interface: E_NOINTERFACE\n");
1620 return E_NOINTERFACE
;
1623 /******************************************************************************
1624 * IShellLinkW_fnAddRef
1626 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1628 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1629 ULONG ref
= InterlockedIncrement(&This
->ref
);
1631 TRACE("(%p)->(count=%u)\n", This
, ref
- 1);
1636 /******************************************************************************
1637 * IShellLinkW_fnRelease
1639 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1641 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1642 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1644 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
1649 TRACE("-- destroying IShellLink(%p)\n",This
);
1651 heap_free(This
->sIcoPath
);
1652 heap_free(This
->sArgs
);
1653 heap_free(This
->sWorkDir
);
1654 heap_free(This
->sDescription
);
1655 heap_free(This
->sPath
);
1656 heap_free(This
->sPathRel
);
1657 heap_free(This
->sProduct
);
1658 heap_free(This
->sComponent
);
1659 heap_free(This
->filepath
);
1662 IUnknown_Release( This
->site
);
1665 ILFree(This
->pPidl
);
1672 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1674 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1677 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1678 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1680 if (This
->sComponent
|| This
->sProduct
)
1686 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1692 memset(pfd
, 0, sizeof(*pfd
));
1696 WCHAR path
[MAX_PATH
];
1697 WIN32_FILE_ATTRIBUTE_DATA fad
;
1699 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1701 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1702 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1703 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1704 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1705 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1706 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1709 lstrcpyW(pfd
->cFileName
, PathFindFileNameW(This
->sPath
));
1711 if (GetShortPathNameW(This
->sPath
, path
, MAX_PATH
))
1713 lstrcpyW(pfd
->cAlternateFileName
, PathFindFileNameW(path
));
1717 TRACE("attr 0x%08x size 0x%08x%08x name %s shortname %s\n", pfd
->dwFileAttributes
,
1718 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_w(pfd
->cFileName
),
1719 wine_dbgstr_w(pfd
->cAlternateFileName
));
1725 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1727 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1729 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1736 *ppidl
= ILClone(This
->pPidl
);
1740 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1742 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1743 WCHAR path
[MAX_PATH
];
1745 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1748 ILFree( This
->pPidl
);
1749 This
->pPidl
= ILClone( pidl
);
1753 heap_free( This
->sPath
);
1756 if ( SHGetPathFromIDListW( pidl
, path
) )
1758 This
->sPath
= heap_alloc((lstrlenW(path
) + 1) * sizeof(WCHAR
));
1760 return E_OUTOFMEMORY
;
1762 lstrcpyW(This
->sPath
, path
);
1765 This
->bDirty
= TRUE
;
1770 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1772 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1774 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1777 if( This
->sDescription
)
1778 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1783 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1785 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1787 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1789 heap_free(This
->sDescription
);
1792 This
->sDescription
= heap_alloc((lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1793 if ( !This
->sDescription
)
1794 return E_OUTOFMEMORY
;
1796 lstrcpyW( This
->sDescription
, pszName
);
1799 This
->sDescription
= NULL
;
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 heap_free(This
->sWorkDir
);
1826 This
->sWorkDir
= heap_alloc((lstrlenW( pszDir
) + 1) * sizeof (WCHAR
) );
1827 if ( !This
->sWorkDir
)
1828 return E_OUTOFMEMORY
;
1829 lstrcpyW( This
->sWorkDir
, pszDir
);
1830 This
->bDirty
= TRUE
;
1835 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1837 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1839 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1844 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1849 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1851 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1853 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1855 heap_free(This
->sArgs
);
1858 This
->sArgs
= heap_alloc((lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1860 return E_OUTOFMEMORY
;
1861 lstrcpyW( This
->sArgs
, pszArgs
);
1863 else This
->sArgs
= NULL
;
1865 This
->bDirty
= TRUE
;
1870 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1872 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1874 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1876 *pwHotkey
=This
->wHotKey
;
1881 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1883 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1885 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1887 This
->wHotKey
= wHotkey
;
1888 This
->bDirty
= TRUE
;
1893 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1895 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1897 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1899 *piShowCmd
= This
->iShowCmd
;
1904 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1906 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1908 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1910 This
->iShowCmd
= iShowCmd
;
1911 This
->bDirty
= TRUE
;
1916 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1918 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1920 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1922 *piIcon
= This
->iIcoNdx
;
1925 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1932 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, const WCHAR
*path
, INT icon
)
1934 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1936 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_w(path
), icon
);
1938 heap_free(This
->sIcoPath
);
1941 size_t len
= (strlenW(path
) + 1) * sizeof(WCHAR
);
1942 This
->sIcoPath
= heap_alloc(len
);
1943 if (!This
->sIcoPath
)
1944 return E_OUTOFMEMORY
;
1945 memcpy(This
->sIcoPath
, path
, len
);
1948 This
->sIcoPath
= NULL
;
1949 This
->iIcoNdx
= icon
;
1950 This
->bDirty
= TRUE
;
1955 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1957 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1959 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1961 heap_free(This
->sPathRel
);
1962 This
->sPathRel
= heap_alloc((lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1963 if ( !This
->sPathRel
)
1964 return E_OUTOFMEMORY
;
1965 lstrcpyW( This
->sPathRel
, pszPathRel
);
1966 This
->bDirty
= TRUE
;
1968 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1971 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1976 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1978 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1980 /*FIXME: use IResolveShellLink interface */
1982 if (!This
->sPath
&& This
->pPidl
) {
1983 WCHAR buffer
[MAX_PATH
];
1985 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1987 if (bSuccess
&& *buffer
) {
1988 This
->sPath
= heap_alloc((lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1990 return E_OUTOFMEMORY
;
1992 lstrcpyW(This
->sPath
, buffer
);
1994 This
->bDirty
= TRUE
;
1996 hr
= S_OK
; /* don't report an error occurred while just caching information */
1999 if (!This
->sIcoPath
&& This
->sPath
) {
2000 This
->sIcoPath
= heap_alloc((lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2001 if (!This
->sIcoPath
)
2002 return E_OUTOFMEMORY
;
2004 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2007 This
->bDirty
= TRUE
;
2013 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2022 p
= strchrW( str
, ':' );
2026 ret
= heap_alloc(sizeof(WCHAR
)*(len
+1));
2029 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2034 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2036 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2044 /* each segment must start with two colons */
2045 if( str
[0] != ':' || str
[1] != ':' )
2048 /* the last segment is just two colons */
2053 /* there must be a colon straight after a guid */
2054 p
= strchrW( str
, ':' );
2061 /* get the guid, and check it's validly formatted */
2062 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2064 r
= CLSIDFromString( szGuid
, &guid
);
2069 /* match it up to a guid that we care about */
2070 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2072 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2077 /* skip to the next field */
2078 str
= strchrW( str
, ':' );
2083 /* we have to have a component for an advertised shortcut */
2087 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2088 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2090 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2091 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2096 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2098 const int label_sz
= ARRAY_SIZE(volume
->label
);
2099 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2102 volume
->type
= GetDriveTypeW(drive
);
2103 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2104 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2105 TRACE("r = %d type %d serial %08x name %s\n", r
,
2106 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2110 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2112 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2113 WCHAR buffer
[MAX_PATH
];
2114 LPWSTR fname
, unquoted
= NULL
;
2118 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2120 if (!pszFile
) return E_INVALIDARG
;
2122 /* quotes at the ends of the string are stripped */
2123 len
= lstrlenW(pszFile
);
2124 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2126 unquoted
= strdupW(pszFile
);
2127 PathUnquoteSpacesW(unquoted
);
2131 /* any other quote marks are invalid */
2132 if (strchrW(pszFile
, '"'))
2134 heap_free(unquoted
);
2138 heap_free(This
->sPath
);
2141 heap_free(This
->sComponent
);
2142 This
->sComponent
= NULL
;
2145 ILFree(This
->pPidl
);
2148 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2150 if (*pszFile
== '\0')
2152 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2154 else if(!PathFileExistsW(buffer
) &&
2155 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2158 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2159 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2161 This
->sPath
= heap_alloc( (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2164 heap_free(unquoted
);
2165 return E_OUTOFMEMORY
;
2168 lstrcpyW(This
->sPath
, buffer
);
2170 This
->bDirty
= TRUE
;
2171 heap_free(unquoted
);
2176 /**************************************************************************
2177 * IShellLinkW Implementation
2180 static const IShellLinkWVtbl slvtw
=
2182 IShellLinkW_fnQueryInterface
,
2183 IShellLinkW_fnAddRef
,
2184 IShellLinkW_fnRelease
,
2185 IShellLinkW_fnGetPath
,
2186 IShellLinkW_fnGetIDList
,
2187 IShellLinkW_fnSetIDList
,
2188 IShellLinkW_fnGetDescription
,
2189 IShellLinkW_fnSetDescription
,
2190 IShellLinkW_fnGetWorkingDirectory
,
2191 IShellLinkW_fnSetWorkingDirectory
,
2192 IShellLinkW_fnGetArguments
,
2193 IShellLinkW_fnSetArguments
,
2194 IShellLinkW_fnGetHotkey
,
2195 IShellLinkW_fnSetHotkey
,
2196 IShellLinkW_fnGetShowCmd
,
2197 IShellLinkW_fnSetShowCmd
,
2198 IShellLinkW_fnGetIconLocation
,
2199 IShellLinkW_fnSetIconLocation
,
2200 IShellLinkW_fnSetRelativePath
,
2201 IShellLinkW_fnResolve
,
2202 IShellLinkW_fnSetPath
2205 static HRESULT WINAPI
2206 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2208 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2209 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2213 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2215 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2216 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2220 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2222 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2223 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2226 static HRESULT WINAPI
2227 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2229 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2233 static HRESULT WINAPI
2234 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2236 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2237 LPVOID block
= NULL
;
2240 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2244 case EXP_DARWIN_ID_SIG
:
2245 if (!This
->sComponent
)
2247 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2250 case EXP_SZ_LINK_SIG
:
2251 case NT_CONSOLE_PROPS_SIG
:
2252 case NT_FE_CONSOLE_PROPS_SIG
:
2253 case EXP_SPECIAL_FOLDER_SIG
:
2254 case EXP_SZ_ICON_SIG
:
2255 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2258 ERR("unknown datablock %08x\n", dwSig
);
2260 *ppDataBlock
= block
;
2264 static HRESULT WINAPI
2265 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2267 FIXME("(%p)->(%u): stub\n", iface
, dwSig
);
2271 static HRESULT WINAPI
2272 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2274 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2277 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2279 /* FIXME: add more */
2281 flags
|= SLDF_HAS_ARGS
;
2282 if (This
->sComponent
)
2283 flags
|= SLDF_HAS_DARWINID
;
2285 flags
|= SLDF_HAS_ICONLOCATION
;
2287 flags
|= SLDF_HAS_LOGO3ID
;
2289 flags
|= SLDF_HAS_ID_LIST
;
2296 static HRESULT WINAPI
2297 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2299 FIXME("(%p)->(%u): stub\n", iface
, dwFlags
);
2303 static const IShellLinkDataListVtbl dlvt
=
2305 ShellLink_DataList_QueryInterface
,
2306 ShellLink_DataList_AddRef
,
2307 ShellLink_DataList_Release
,
2308 ShellLink_AddDataBlock
,
2309 ShellLink_CopyDataBlock
,
2310 ShellLink_RemoveDataBlock
,
2315 static HRESULT WINAPI
2316 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2318 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2319 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2323 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2325 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2326 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2330 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2332 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2333 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2336 /**************************************************************************
2337 * ShellLink implementation of IShellExtInit::Initialize()
2339 * Loads the shelllink from the dataobject the shell is pointing to.
2341 static HRESULT WINAPI
2342 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2343 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2345 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2351 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2356 format
.cfFormat
= CF_HDROP
;
2358 format
.dwAspect
= DVASPECT_CONTENT
;
2360 format
.tymed
= TYMED_HGLOBAL
;
2362 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2365 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2370 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2372 path
= heap_alloc(count
*sizeof(WCHAR
) );
2375 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2377 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2378 r
= IPersistFile_Load( pf
, path
, 0 );
2382 ReleaseStgMedium( &stgm
);
2387 static const IShellExtInitVtbl eivt
=
2389 ShellLink_ExtInit_QueryInterface
,
2390 ShellLink_ExtInit_AddRef
,
2391 ShellLink_ExtInit_Release
,
2392 ShellLink_ExtInit_Initialize
2395 static HRESULT WINAPI
2396 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2398 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2399 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2403 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2405 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2406 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2410 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2412 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2413 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2416 static HRESULT WINAPI
2417 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2418 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2420 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2421 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2425 TRACE("%p %p %u %u %u %u\n", This
,
2426 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2429 return E_INVALIDARG
;
2431 memset( &mii
, 0, sizeof mii
);
2432 mii
.cbSize
= sizeof mii
;
2433 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2434 mii
.dwTypeData
= szOpen
;
2435 mii
.cch
= strlenW( mii
.dwTypeData
);
2436 mii
.wID
= idCmdFirst
+ id
++;
2437 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2438 mii
.fType
= MFT_STRING
;
2439 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2443 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2447 shelllink_get_msi_component_path( LPWSTR component
)
2452 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2453 if (r
!= ERROR_SUCCESS
)
2457 path
= heap_alloc( sz
*sizeof(WCHAR
) );
2458 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2459 if (r
!= ERROR_SUCCESS
)
2465 TRACE("returning %s\n", debugstr_w( path
) );
2470 static HRESULT WINAPI
2471 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2473 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2474 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2475 SHELLEXECUTEINFOW sei
;
2476 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2481 TRACE("%p %p\n", This
, lpici
);
2483 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2484 return E_INVALIDARG
;
2486 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2488 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2489 return E_INVALIDARG
;
2492 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2496 if ( This
->sComponent
)
2498 path
= shelllink_get_msi_component_path( This
->sComponent
);
2503 path
= strdupW( This
->sPath
);
2505 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2506 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2508 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2512 len
+= lstrlenW( This
->sArgs
);
2513 if ( iciex
->lpParametersW
)
2514 len
+= lstrlenW( iciex
->lpParametersW
);
2516 args
= heap_alloc( len
*sizeof(WCHAR
) );
2519 lstrcatW( args
, This
->sArgs
);
2520 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2522 static const WCHAR space
[] = { ' ', 0 };
2523 lstrcatW( args
, space
);
2524 lstrcatW( args
, iciex
->lpParametersW
);
2528 memset( &sei
, 0, sizeof sei
);
2529 sei
.cbSize
= sizeof sei
;
2530 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2532 sei
.nShow
= This
->iShowCmd
;
2533 sei
.lpIDList
= This
->pPidl
;
2534 sei
.lpDirectory
= This
->sWorkDir
;
2535 sei
.lpParameters
= args
;
2536 sei
.lpVerb
= szOpen
;
2538 if( ShellExecuteExW( &sei
) )
2549 static HRESULT WINAPI
2550 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2551 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2553 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2555 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This
,
2556 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2561 static const IContextMenuVtbl cmvt
=
2563 ShellLink_ContextMenu_QueryInterface
,
2564 ShellLink_ContextMenu_AddRef
,
2565 ShellLink_ContextMenu_Release
,
2566 ShellLink_QueryContextMenu
,
2567 ShellLink_InvokeCommand
,
2568 ShellLink_GetCommandString
2571 static HRESULT WINAPI
2572 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2574 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2575 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2579 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2581 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2582 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2586 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2588 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2589 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2592 static HRESULT WINAPI
2593 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2595 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2597 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2601 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2604 static HRESULT WINAPI
2605 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2607 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2609 TRACE("%p %p\n", iface
, punk
);
2612 IUnknown_AddRef( punk
);
2615 IUnknown_Release( This
->site
);
2622 static const IObjectWithSiteVtbl owsvt
=
2624 ShellLink_ObjectWithSite_QueryInterface
,
2625 ShellLink_ObjectWithSite_AddRef
,
2626 ShellLink_ObjectWithSite_Release
,
2631 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2633 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2634 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2637 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2639 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2640 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2643 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2645 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2646 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2649 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2651 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2652 FIXME("(%p)->(%p): stub\n", This
, props
);
2656 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2658 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2659 FIXME("(%p)->(%d %p): stub\n", This
, propid
, key
);
2663 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2665 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2666 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2670 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2672 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2673 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2677 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2679 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2680 FIXME("(%p): stub\n", This
);
2684 static const IPropertyStoreVtbl propertystorevtbl
= {
2685 propertystore_QueryInterface
,
2686 propertystore_AddRef
,
2687 propertystore_Release
,
2688 propertystore_GetCount
,
2689 propertystore_GetAt
,
2690 propertystore_GetValue
,
2691 propertystore_SetValue
,
2692 propertystore_Commit
2695 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2697 IShellLinkImpl
* sl
;
2700 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2705 return CLASS_E_NOAGGREGATION
;
2707 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2709 return E_OUTOFMEMORY
;
2712 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2713 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2714 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2715 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2716 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2717 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2718 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2719 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2720 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2721 sl
->iShowCmd
= SW_SHOWNORMAL
;
2725 sl
->filepath
= NULL
;
2727 TRACE("(%p)\n", sl
);
2729 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2730 IShellLinkW_Release( &sl
->IShellLinkW_iface
);