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
));
371 if (!This
->filepath
) return S_OK
;
373 pszFileName
= This
->filepath
;
377 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
380 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
381 IStream_Release( stm
);
385 StartLinkProcessor( pszFileName
);
389 /* update file path */
390 heap_free(This
->filepath
);
391 This
->filepath
= strdupW(pszFileName
);
394 This
->bDirty
= FALSE
;
398 DeleteFileW( pszFileName
);
399 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
406 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
408 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
409 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
413 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
415 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
417 TRACE("(%p)->(%p)\n", This
, filename
);
425 *filename
= CoTaskMemAlloc((strlenW(This
->filepath
) + 1) * sizeof(WCHAR
));
426 if (!*filename
) return E_OUTOFMEMORY
;
428 strcpyW(*filename
, This
->filepath
);
433 static const IPersistFileVtbl pfvt
=
435 IPersistFile_fnQueryInterface
,
436 IPersistFile_fnAddRef
,
437 IPersistFile_fnRelease
,
438 IPersistFile_fnGetClassID
,
439 IPersistFile_fnIsDirty
,
442 IPersistFile_fnSaveCompleted
,
443 IPersistFile_fnGetCurFile
446 /************************************************************************
447 * IPersistStream_QueryInterface
449 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
450 IPersistStream
* iface
,
454 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
455 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
458 /************************************************************************
459 * IPersistStream_Release
461 static ULONG WINAPI
IPersistStream_fnRelease(
462 IPersistStream
* iface
)
464 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
465 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
468 /************************************************************************
469 * IPersistStream_AddRef
471 static ULONG WINAPI
IPersistStream_fnAddRef(
472 IPersistStream
* iface
)
474 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
475 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
478 /************************************************************************
479 * IPersistStream_GetClassID
482 static HRESULT WINAPI
IPersistStream_fnGetClassID(
483 IPersistStream
* iface
,
486 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
487 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
490 /************************************************************************
491 * IPersistStream_IsDirty (IPersistStream)
493 static HRESULT WINAPI
IPersistStream_fnIsDirty(
494 IPersistStream
* iface
)
496 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
498 TRACE("(%p)\n", This
);
504 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
515 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
516 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
520 len
*= sizeof (WCHAR
);
522 TRACE("reading %d\n", len
);
523 temp
= heap_alloc(len
+ sizeof(WCHAR
));
525 return E_OUTOFMEMORY
;
527 r
= IStream_Read(stm
, temp
, len
, &count
);
528 if( FAILED (r
) || ( count
!= len
) )
534 TRACE("read %s\n", debugstr_an(temp
,len
));
536 /* convert to unicode if necessary */
539 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
540 str
= heap_alloc( (count
+1)*sizeof (WCHAR
) );
544 return E_OUTOFMEMORY
;
546 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
561 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
568 unsigned char data
[1];
573 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
574 if( FAILED( r
) || count
!= sizeof(size
) )
577 chunk
= heap_alloc( size
);
579 return E_OUTOFMEMORY
;
582 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
583 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
589 TRACE("Read %d bytes\n",chunk
->size
);
596 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
598 const int label_sz
= ARRAY_SIZE(volume
->label
);
602 volume
->serial
= vol
->dwVolSerial
;
603 volume
->type
= vol
->dwType
;
605 if( !vol
->dwVolLabelOfs
)
607 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
609 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
612 label
+= vol
->dwVolLabelOfs
;
613 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
618 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
623 while( (len
< maxlen
) && p
[len
] )
626 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
627 path
= heap_alloc((wlen
+ 1) * sizeof(WCHAR
));
628 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
634 static HRESULT
Stream_LoadLocation( IStream
*stm
,
635 volume_info
*volume
, LPWSTR
*path
)
642 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
646 loc
= (LOCATION_INFO
*) p
;
647 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
653 /* if there's valid local volume information, load it */
654 if( loc
->dwVolTableOfs
&&
655 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
657 LOCAL_VOLUME_INFO
*volume_info
;
659 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
660 Stream_LoadVolume( volume_info
, volume
);
663 /* if there's a local path, load it */
664 n
= loc
->dwLocalPathOfs
;
665 if( n
&& (n
< loc
->dwTotalSize
) )
666 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
668 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
669 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
676 * The format of the advertised shortcut info seems to be:
681 * 0 Length of the block (4 bytes, usually 0x314)
683 * 8 string data in ASCII
684 * 8+0x104 string data in UNICODE
686 * In the original Win32 implementation the buffers are not initialized
687 * to zero, so data trailing the string is random garbage.
689 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
694 EXP_DARWIN_LINK buffer
;
698 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
702 /* make sure that we read the size of the structure even on error */
703 size
= sizeof buffer
- sizeof (DWORD
);
704 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
706 ERR("Ooops. This structure is not as expected...\n");
710 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
717 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
719 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
721 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
725 *str
= heap_alloc((lstrlenW(buffer
.szwDarwinID
) + 1) * sizeof(WCHAR
) );
726 lstrcpyW( *str
, buffer
.szwDarwinID
);
731 /************************************************************************
732 * IPersistStream_Load (IPersistStream)
734 static HRESULT WINAPI
IPersistStream_fnLoad(
735 IPersistStream
* iface
,
744 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
746 TRACE("%p %p\n", This
, stm
);
749 return STG_E_INVALIDPOINTER
;
752 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
756 if( dwBytesRead
!= sizeof(hdr
))
758 if( hdr
.dwSize
!= sizeof(hdr
))
760 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
763 /* free all the old stuff */
766 memset( &This
->volume
, 0, sizeof This
->volume
);
767 heap_free(This
->sPath
);
769 heap_free(This
->sDescription
);
770 This
->sDescription
= NULL
;
771 heap_free(This
->sPathRel
);
772 This
->sPathRel
= NULL
;
773 heap_free(This
->sWorkDir
);
774 This
->sWorkDir
= NULL
;
775 heap_free(This
->sArgs
);
777 heap_free(This
->sIcoPath
);
778 This
->sIcoPath
= NULL
;
779 heap_free(This
->sProduct
);
780 This
->sProduct
= NULL
;
781 heap_free(This
->sComponent
);
782 This
->sComponent
= NULL
;
784 This
->wHotKey
= hdr
.wHotKey
;
785 This
->iIcoNdx
= hdr
.nIcon
;
786 FileTimeToSystemTime (&hdr
.CreationTime
, &This
->CreationTime
);
787 FileTimeToSystemTime (&hdr
.AccessTime
, &This
->AccessTime
);
788 FileTimeToSystemTime (&hdr
.WriteTime
, &This
->WriteTime
);
791 WCHAR sTemp
[MAX_PATH
];
792 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->CreationTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
793 TRACE("-- CreationTime: %s\n", debugstr_w(sTemp
) );
794 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->AccessTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
795 TRACE("-- AccessTime: %s\n", debugstr_w(sTemp
) );
796 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->WriteTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
797 TRACE("-- WriteTime: %s\n", debugstr_w(sTemp
) );
800 /* load all the new stuff */
801 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
803 r
= ILLoadFromStream( stm
, &This
->pPidl
);
809 /* load the location information */
810 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
811 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
815 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
816 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
818 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
819 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
824 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
826 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
827 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
832 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
834 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
835 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
840 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
842 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
843 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
848 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
850 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
851 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
856 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
858 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
859 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
864 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
866 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
867 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
872 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
873 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
875 /* Some lnk files have extra data blocks starting with a
876 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
877 * one with a 0xa0000003 signature. However these don't seem to matter
880 WARN("Last word was not zero\n");
892 /************************************************************************
895 * Helper function for IPersistStream_Save. Writes a unicode string
896 * with terminating nul byte to a stream, preceded by the its length.
898 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
900 USHORT len
= lstrlenW( str
) + 1;
904 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
908 len
*= sizeof(WCHAR
);
910 r
= IStream_Write( stm
, str
, len
, &count
);
917 /************************************************************************
918 * Stream_WriteLocationInfo
920 * Writes the location info to a stream
922 * FIXME: One day we might want to write the network volume information
923 * and the final path.
924 * Figure out how Windows deals with unicode paths here.
926 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
927 volume_info
*volume
)
929 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
930 LOCAL_VOLUME_INFO
*vol
;
932 LPSTR szLabel
, szPath
, szFinalPath
;
936 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
938 /* figure out the size of everything */
939 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
940 NULL
, 0, NULL
, NULL
);
941 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
942 NULL
, 0, NULL
, NULL
);
943 volume_info_size
= sizeof *vol
+ label_size
;
945 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
947 /* create pointers to everything */
948 loc
= heap_alloc_zero(total_size
);
949 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
950 szLabel
= (LPSTR
) &vol
[1];
951 szPath
= &szLabel
[label_size
];
952 szFinalPath
= &szPath
[path_size
];
954 /* fill in the location information header */
955 loc
->dwTotalSize
= total_size
;
956 loc
->dwHeaderSize
= sizeof (*loc
);
958 loc
->dwVolTableOfs
= sizeof (*loc
);
959 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
960 loc
->dwNetworkVolTableOfs
= 0;
961 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
963 /* fill in the volume information */
964 vol
->dwSize
= volume_info_size
;
965 vol
->dwType
= volume
->type
;
966 vol
->dwVolSerial
= volume
->serial
;
967 vol
->dwVolLabelOfs
= sizeof (*vol
);
969 /* copy in the strings */
970 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
971 szLabel
, label_size
, NULL
, NULL
);
972 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
973 szPath
, path_size
, NULL
, NULL
);
976 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
982 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
984 EXP_DARWIN_LINK
*buffer
;
986 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
987 buffer
->dbh
.cbSize
= sizeof *buffer
;
988 buffer
->dbh
.dwSignature
= magic
;
989 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
990 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
995 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
997 EXP_DARWIN_LINK
*buffer
;
1002 buffer
= shelllink_build_darwinid( string
, magic
);
1004 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1007 /************************************************************************
1008 * IPersistStream_Save (IPersistStream)
1010 * FIXME: makes assumptions about byte order
1012 static HRESULT WINAPI
IPersistStream_fnSave(
1013 IPersistStream
* iface
,
1022 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1024 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1026 memset(&header
, 0, sizeof(header
));
1027 header
.dwSize
= sizeof(header
);
1028 header
.fStartup
= This
->iShowCmd
;
1029 header
.MagicGuid
= CLSID_ShellLink
;
1031 header
.wHotKey
= This
->wHotKey
;
1032 header
.nIcon
= This
->iIcoNdx
;
1033 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1035 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1037 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1038 if( This
->sDescription
)
1039 header
.dwFlags
|= SLDF_HAS_NAME
;
1040 if( This
->sWorkDir
)
1041 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1043 header
.dwFlags
|= SLDF_HAS_ARGS
;
1044 if( This
->sIcoPath
)
1045 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1046 if( This
->sProduct
)
1047 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1048 if( This
->sComponent
)
1049 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1051 SystemTimeToFileTime ( &This
->CreationTime
, &header
.CreationTime
);
1052 SystemTimeToFileTime ( &This
->AccessTime
, &header
.AccessTime
);
1053 SystemTimeToFileTime ( &This
->WriteTime
, &header
.WriteTime
);
1055 /* write the Shortcut header */
1056 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1059 ERR("Write failed at %d\n",__LINE__
);
1063 TRACE("Writing pidl\n");
1065 /* write the PIDL to the shortcut */
1068 r
= ILSaveToStream( stm
, This
->pPidl
);
1071 ERR("Failed to write PIDL at %d\n",__LINE__
);
1077 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1079 if( This
->sDescription
)
1080 r
= Stream_WriteString( stm
, This
->sDescription
);
1082 if( This
->sPathRel
)
1083 r
= Stream_WriteString( stm
, This
->sPathRel
);
1085 if( This
->sWorkDir
)
1086 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1089 r
= Stream_WriteString( stm
, This
->sArgs
);
1091 if( This
->sIcoPath
)
1092 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1094 if( This
->sProduct
)
1095 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1097 if( This
->sComponent
)
1098 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1100 /* the last field is a single zero dword */
1102 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1107 /************************************************************************
1108 * IPersistStream_GetSizeMax (IPersistStream)
1110 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1111 IPersistStream
* iface
,
1112 ULARGE_INTEGER
* pcbSize
)
1114 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1116 TRACE("(%p)\n", This
);
1121 static const IPersistStreamVtbl psvt
=
1123 IPersistStream_fnQueryInterface
,
1124 IPersistStream_fnAddRef
,
1125 IPersistStream_fnRelease
,
1126 IPersistStream_fnGetClassID
,
1127 IPersistStream_fnIsDirty
,
1128 IPersistStream_fnLoad
,
1129 IPersistStream_fnSave
,
1130 IPersistStream_fnGetSizeMax
1133 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1135 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1140 /**************************************************************************
1141 * ShellLink_UpdatePath
1142 * update absolute path in sPath using relative path in sPathRel
1144 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1146 if (!path
|| !psPath
)
1147 return E_INVALIDARG
;
1149 if (!*psPath
&& sPathRel
) {
1150 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1151 LPWSTR final
= NULL
;
1153 /* first try if [directory of link file] + [relative path] finds an existing file */
1155 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1158 lstrcpyW(final
, sPathRel
);
1162 if (SHELL_ExistsFileW(buffer
)) {
1163 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1164 lstrcpyW(abs_path
, buffer
);
1166 /* try if [working directory] + [relative path] finds an existing file */
1168 lstrcpyW(buffer
, sWorkDir
);
1169 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1171 if (SHELL_ExistsFileW(buffer
))
1172 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1173 lstrcpyW(abs_path
, buffer
);
1177 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1179 lstrcpyW(abs_path
, sPathRel
);
1181 *psPath
= heap_alloc((lstrlenW(abs_path
) + 1) * sizeof(WCHAR
));
1183 return E_OUTOFMEMORY
;
1185 lstrcpyW(*psPath
, abs_path
);
1191 /**************************************************************************
1192 * IShellLink_ConstructFromFile
1194 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1195 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1199 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1201 if (SUCCEEDED(hr
)) {
1206 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1208 if (SUCCEEDED(hr
)) {
1209 WCHAR path
[MAX_PATH
];
1211 if (SHGetPathFromIDListW(pidl
, path
))
1212 hr
= IPersistFile_Load(ppf
, path
, 0);
1217 *ppv
= (IUnknown
*)psl
;
1219 IPersistFile_Release(ppf
);
1223 IShellLinkW_Release(psl
);
1229 /**************************************************************************
1230 * IShellLinkA_QueryInterface
1232 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1234 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1235 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1238 /******************************************************************************
1239 * IShellLinkA_AddRef
1241 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1243 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1244 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1247 /******************************************************************************
1248 * IShellLinkA_Release
1250 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1252 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1253 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1256 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1257 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1259 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1262 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1263 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1265 if (This
->sComponent
|| This
->sProduct
)
1270 if (This
->sPath
&& This
->sPath
[0])
1271 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1272 pszFile
, cchMaxPath
, NULL
, NULL
);
1278 memset(pfd
, 0, sizeof(*pfd
));
1282 char path
[MAX_PATH
];
1283 WIN32_FILE_ATTRIBUTE_DATA fad
;
1285 WideCharToMultiByte(CP_ACP
, 0, This
->sPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
1287 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1289 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1290 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1291 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1292 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1293 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1294 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1297 lstrcpyA(pfd
->cFileName
, PathFindFileNameA(path
));
1299 if (GetShortPathNameA(path
, path
, MAX_PATH
))
1301 lstrcpyA(pfd
->cAlternateFileName
, PathFindFileNameA(path
));
1305 TRACE("attr 0x%08x size 0x%08x%08x name %s shortname %s\n", pfd
->dwFileAttributes
,
1306 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_a(pfd
->cFileName
),
1307 wine_dbgstr_a(pfd
->cAlternateFileName
));
1313 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1315 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1316 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1319 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1321 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1322 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1325 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1328 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1330 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1334 if( This
->sDescription
)
1335 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1336 pszName
, cchMaxName
, NULL
, NULL
);
1341 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1343 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1347 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1351 descrW
= heap_strdupAtoW(pszName
);
1352 if (!descrW
) return E_OUTOFMEMORY
;
1357 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1363 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1366 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1368 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1372 if( This
->sWorkDir
)
1373 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1374 pszDir
, cchMaxPath
, NULL
, NULL
);
1379 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1381 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1385 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1387 dirW
= heap_strdupAtoW(pszDir
);
1388 if (!dirW
) return E_OUTOFMEMORY
;
1390 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1396 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1398 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1400 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1405 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1406 pszArgs
, cchMaxPath
, NULL
, NULL
);
1411 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1413 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1417 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1421 argsW
= heap_strdupAtoW(pszArgs
);
1422 if (!argsW
) return E_OUTOFMEMORY
;
1427 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1433 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1435 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1436 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1439 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1441 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1442 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1445 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1447 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1448 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1451 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1453 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1454 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1457 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1458 INT cchIconPath
, INT
*piIcon
)
1460 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1462 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1464 *piIcon
= This
->iIcoNdx
;
1467 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1474 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR path
, INT icon
)
1476 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1477 WCHAR
*pathW
= NULL
;
1480 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_a(path
), icon
);
1484 pathW
= heap_strdupAtoW(path
);
1486 return E_OUTOFMEMORY
;
1489 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, path
? pathW
: NULL
, icon
);
1495 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1498 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1502 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1504 pathW
= heap_strdupAtoW(pszPathRel
);
1505 if (!pathW
) return E_OUTOFMEMORY
;
1507 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1513 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1515 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1517 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1519 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1522 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1524 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1528 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1530 if (!pszFile
) return E_INVALIDARG
;
1532 str
= heap_strdupAtoW(pszFile
);
1534 return E_OUTOFMEMORY
;
1536 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1542 /**************************************************************************
1543 * IShellLink Implementation
1546 static const IShellLinkAVtbl slvt
=
1548 IShellLinkA_fnQueryInterface
,
1549 IShellLinkA_fnAddRef
,
1550 IShellLinkA_fnRelease
,
1551 IShellLinkA_fnGetPath
,
1552 IShellLinkA_fnGetIDList
,
1553 IShellLinkA_fnSetIDList
,
1554 IShellLinkA_fnGetDescription
,
1555 IShellLinkA_fnSetDescription
,
1556 IShellLinkA_fnGetWorkingDirectory
,
1557 IShellLinkA_fnSetWorkingDirectory
,
1558 IShellLinkA_fnGetArguments
,
1559 IShellLinkA_fnSetArguments
,
1560 IShellLinkA_fnGetHotkey
,
1561 IShellLinkA_fnSetHotkey
,
1562 IShellLinkA_fnGetShowCmd
,
1563 IShellLinkA_fnSetShowCmd
,
1564 IShellLinkA_fnGetIconLocation
,
1565 IShellLinkA_fnSetIconLocation
,
1566 IShellLinkA_fnSetRelativePath
,
1567 IShellLinkA_fnResolve
,
1568 IShellLinkA_fnSetPath
1572 /**************************************************************************
1573 * IShellLinkW_fnQueryInterface
1575 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1576 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1578 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1580 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1584 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1586 *ppvObj
= &This
->IShellLinkA_iface
;
1588 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1590 *ppvObj
= &This
->IShellLinkW_iface
;
1592 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1594 *ppvObj
= &This
->IPersistFile_iface
;
1596 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1598 *ppvObj
= &This
->IPersistStream_iface
;
1600 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1602 *ppvObj
= &This
->IShellLinkDataList_iface
;
1604 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1606 *ppvObj
= &This
->IShellExtInit_iface
;
1608 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1610 *ppvObj
= &This
->IContextMenu_iface
;
1612 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1614 *ppvObj
= &This
->IObjectWithSite_iface
;
1616 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1618 *ppvObj
= &This
->IPropertyStore_iface
;
1623 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1624 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1627 ERR("-- Interface: E_NOINTERFACE\n");
1628 return E_NOINTERFACE
;
1631 /******************************************************************************
1632 * IShellLinkW_fnAddRef
1634 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1636 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1637 ULONG ref
= InterlockedIncrement(&This
->ref
);
1639 TRACE("(%p)->(count=%u)\n", This
, ref
- 1);
1644 /******************************************************************************
1645 * IShellLinkW_fnRelease
1647 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1649 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1650 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1652 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
1657 TRACE("-- destroying IShellLink(%p)\n",This
);
1659 heap_free(This
->sIcoPath
);
1660 heap_free(This
->sArgs
);
1661 heap_free(This
->sWorkDir
);
1662 heap_free(This
->sDescription
);
1663 heap_free(This
->sPath
);
1664 heap_free(This
->sPathRel
);
1665 heap_free(This
->sProduct
);
1666 heap_free(This
->sComponent
);
1667 heap_free(This
->filepath
);
1670 IUnknown_Release( This
->site
);
1673 ILFree(This
->pPidl
);
1680 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1682 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1685 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1686 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1688 if (This
->sComponent
|| This
->sProduct
)
1694 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1700 memset(pfd
, 0, sizeof(*pfd
));
1704 WCHAR path
[MAX_PATH
];
1705 WIN32_FILE_ATTRIBUTE_DATA fad
;
1707 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1709 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1710 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1711 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1712 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1713 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1714 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1717 lstrcpyW(pfd
->cFileName
, PathFindFileNameW(This
->sPath
));
1719 if (GetShortPathNameW(This
->sPath
, path
, MAX_PATH
))
1721 lstrcpyW(pfd
->cAlternateFileName
, PathFindFileNameW(path
));
1725 TRACE("attr 0x%08x size 0x%08x%08x name %s shortname %s\n", pfd
->dwFileAttributes
,
1726 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_w(pfd
->cFileName
),
1727 wine_dbgstr_w(pfd
->cAlternateFileName
));
1733 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1735 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1737 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1744 *ppidl
= ILClone(This
->pPidl
);
1748 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1750 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1751 WCHAR path
[MAX_PATH
];
1753 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1756 ILFree( This
->pPidl
);
1757 This
->pPidl
= ILClone( pidl
);
1761 heap_free( This
->sPath
);
1764 if ( SHGetPathFromIDListW( pidl
, path
) )
1766 This
->sPath
= heap_alloc((lstrlenW(path
) + 1) * sizeof(WCHAR
));
1768 return E_OUTOFMEMORY
;
1770 lstrcpyW(This
->sPath
, path
);
1773 This
->bDirty
= TRUE
;
1778 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1780 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1782 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1785 if( This
->sDescription
)
1786 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1791 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1793 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1795 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1797 heap_free(This
->sDescription
);
1800 This
->sDescription
= heap_alloc((lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1801 if ( !This
->sDescription
)
1802 return E_OUTOFMEMORY
;
1804 lstrcpyW( This
->sDescription
, pszName
);
1807 This
->sDescription
= NULL
;
1808 This
->bDirty
= TRUE
;
1813 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1815 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1817 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1821 if( This
->sWorkDir
)
1822 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1827 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1829 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1831 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1833 heap_free(This
->sWorkDir
);
1834 This
->sWorkDir
= heap_alloc((lstrlenW( pszDir
) + 1) * sizeof (WCHAR
) );
1835 if ( !This
->sWorkDir
)
1836 return E_OUTOFMEMORY
;
1837 lstrcpyW( This
->sWorkDir
, pszDir
);
1838 This
->bDirty
= TRUE
;
1843 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1845 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1847 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1852 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1857 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1859 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1861 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1863 heap_free(This
->sArgs
);
1866 This
->sArgs
= heap_alloc((lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1868 return E_OUTOFMEMORY
;
1869 lstrcpyW( This
->sArgs
, pszArgs
);
1871 else This
->sArgs
= NULL
;
1873 This
->bDirty
= TRUE
;
1878 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1880 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1882 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1884 *pwHotkey
=This
->wHotKey
;
1889 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1891 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1893 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1895 This
->wHotKey
= wHotkey
;
1896 This
->bDirty
= TRUE
;
1901 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1903 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1905 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1907 *piShowCmd
= This
->iShowCmd
;
1912 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1914 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1916 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1918 This
->iShowCmd
= iShowCmd
;
1919 This
->bDirty
= TRUE
;
1924 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1926 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1928 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1930 *piIcon
= This
->iIcoNdx
;
1933 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1940 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, const WCHAR
*path
, INT icon
)
1942 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1944 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_w(path
), icon
);
1946 heap_free(This
->sIcoPath
);
1949 size_t len
= (strlenW(path
) + 1) * sizeof(WCHAR
);
1950 This
->sIcoPath
= heap_alloc(len
);
1951 if (!This
->sIcoPath
)
1952 return E_OUTOFMEMORY
;
1953 memcpy(This
->sIcoPath
, path
, len
);
1956 This
->sIcoPath
= NULL
;
1957 This
->iIcoNdx
= icon
;
1958 This
->bDirty
= TRUE
;
1963 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1965 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1967 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1969 heap_free(This
->sPathRel
);
1970 This
->sPathRel
= heap_alloc((lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1971 if ( !This
->sPathRel
)
1972 return E_OUTOFMEMORY
;
1973 lstrcpyW( This
->sPathRel
, pszPathRel
);
1974 This
->bDirty
= TRUE
;
1976 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1979 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1984 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1986 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1988 /*FIXME: use IResolveShellLink interface */
1990 if (!This
->sPath
&& This
->pPidl
) {
1991 WCHAR buffer
[MAX_PATH
];
1993 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1995 if (bSuccess
&& *buffer
) {
1996 This
->sPath
= heap_alloc((lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1998 return E_OUTOFMEMORY
;
2000 lstrcpyW(This
->sPath
, buffer
);
2002 This
->bDirty
= TRUE
;
2004 hr
= S_OK
; /* don't report an error occurred while just caching information */
2007 if (!This
->sIcoPath
&& This
->sPath
) {
2008 This
->sIcoPath
= heap_alloc((lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2009 if (!This
->sIcoPath
)
2010 return E_OUTOFMEMORY
;
2012 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2015 This
->bDirty
= TRUE
;
2021 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2030 p
= strchrW( str
, ':' );
2034 ret
= heap_alloc(sizeof(WCHAR
)*(len
+1));
2037 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2042 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2044 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2052 /* each segment must start with two colons */
2053 if( str
[0] != ':' || str
[1] != ':' )
2056 /* the last segment is just two colons */
2061 /* there must be a colon straight after a guid */
2062 p
= strchrW( str
, ':' );
2069 /* get the guid, and check it's validly formatted */
2070 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2072 r
= CLSIDFromString( szGuid
, &guid
);
2077 /* match it up to a guid that we care about */
2078 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2080 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2085 /* skip to the next field */
2086 str
= strchrW( str
, ':' );
2091 /* we have to have a component for an advertised shortcut */
2095 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2096 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2098 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2099 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2104 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2106 const int label_sz
= ARRAY_SIZE(volume
->label
);
2107 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2110 volume
->type
= GetDriveTypeW(drive
);
2111 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2112 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2113 TRACE("r = %d type %d serial %08x name %s\n", r
,
2114 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2118 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2120 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2121 WCHAR buffer
[MAX_PATH
];
2122 LPWSTR fname
, unquoted
= NULL
;
2126 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2128 if (!pszFile
) return E_INVALIDARG
;
2130 /* quotes at the ends of the string are stripped */
2131 len
= lstrlenW(pszFile
);
2132 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2134 unquoted
= strdupW(pszFile
);
2135 PathUnquoteSpacesW(unquoted
);
2139 /* any other quote marks are invalid */
2140 if (strchrW(pszFile
, '"'))
2142 heap_free(unquoted
);
2146 heap_free(This
->sPath
);
2149 heap_free(This
->sComponent
);
2150 This
->sComponent
= NULL
;
2153 ILFree(This
->pPidl
);
2156 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2158 if (*pszFile
== '\0')
2160 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2162 else if(!PathFileExistsW(buffer
) &&
2163 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2166 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2167 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2169 This
->sPath
= heap_alloc( (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2172 heap_free(unquoted
);
2173 return E_OUTOFMEMORY
;
2176 lstrcpyW(This
->sPath
, buffer
);
2178 This
->bDirty
= TRUE
;
2179 heap_free(unquoted
);
2184 /**************************************************************************
2185 * IShellLinkW Implementation
2188 static const IShellLinkWVtbl slvtw
=
2190 IShellLinkW_fnQueryInterface
,
2191 IShellLinkW_fnAddRef
,
2192 IShellLinkW_fnRelease
,
2193 IShellLinkW_fnGetPath
,
2194 IShellLinkW_fnGetIDList
,
2195 IShellLinkW_fnSetIDList
,
2196 IShellLinkW_fnGetDescription
,
2197 IShellLinkW_fnSetDescription
,
2198 IShellLinkW_fnGetWorkingDirectory
,
2199 IShellLinkW_fnSetWorkingDirectory
,
2200 IShellLinkW_fnGetArguments
,
2201 IShellLinkW_fnSetArguments
,
2202 IShellLinkW_fnGetHotkey
,
2203 IShellLinkW_fnSetHotkey
,
2204 IShellLinkW_fnGetShowCmd
,
2205 IShellLinkW_fnSetShowCmd
,
2206 IShellLinkW_fnGetIconLocation
,
2207 IShellLinkW_fnSetIconLocation
,
2208 IShellLinkW_fnSetRelativePath
,
2209 IShellLinkW_fnResolve
,
2210 IShellLinkW_fnSetPath
2213 static HRESULT WINAPI
2214 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2216 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2217 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2221 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2223 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2224 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2228 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2230 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2231 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2234 static HRESULT WINAPI
2235 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2237 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2241 static HRESULT WINAPI
2242 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2244 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2245 LPVOID block
= NULL
;
2248 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2252 case EXP_DARWIN_ID_SIG
:
2253 if (!This
->sComponent
)
2255 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2258 case EXP_SZ_LINK_SIG
:
2259 case NT_CONSOLE_PROPS_SIG
:
2260 case NT_FE_CONSOLE_PROPS_SIG
:
2261 case EXP_SPECIAL_FOLDER_SIG
:
2262 case EXP_SZ_ICON_SIG
:
2263 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2266 ERR("unknown datablock %08x\n", dwSig
);
2268 *ppDataBlock
= block
;
2272 static HRESULT WINAPI
2273 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2275 FIXME("(%p)->(%u): stub\n", iface
, dwSig
);
2279 static HRESULT WINAPI
2280 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2282 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2285 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2287 /* FIXME: add more */
2289 flags
|= SLDF_HAS_ARGS
;
2290 if (This
->sComponent
)
2291 flags
|= SLDF_HAS_DARWINID
;
2293 flags
|= SLDF_HAS_ICONLOCATION
;
2295 flags
|= SLDF_HAS_LOGO3ID
;
2297 flags
|= SLDF_HAS_ID_LIST
;
2304 static HRESULT WINAPI
2305 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2307 FIXME("(%p)->(%u): stub\n", iface
, dwFlags
);
2311 static const IShellLinkDataListVtbl dlvt
=
2313 ShellLink_DataList_QueryInterface
,
2314 ShellLink_DataList_AddRef
,
2315 ShellLink_DataList_Release
,
2316 ShellLink_AddDataBlock
,
2317 ShellLink_CopyDataBlock
,
2318 ShellLink_RemoveDataBlock
,
2323 static HRESULT WINAPI
2324 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2326 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2327 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2331 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2333 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2334 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2338 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2340 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2341 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2344 /**************************************************************************
2345 * ShellLink implementation of IShellExtInit::Initialize()
2347 * Loads the shelllink from the dataobject the shell is pointing to.
2349 static HRESULT WINAPI
2350 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2351 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2353 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2359 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2364 format
.cfFormat
= CF_HDROP
;
2366 format
.dwAspect
= DVASPECT_CONTENT
;
2368 format
.tymed
= TYMED_HGLOBAL
;
2370 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2373 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2378 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2380 path
= heap_alloc(count
*sizeof(WCHAR
) );
2383 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2385 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2386 r
= IPersistFile_Load( pf
, path
, 0 );
2390 ReleaseStgMedium( &stgm
);
2395 static const IShellExtInitVtbl eivt
=
2397 ShellLink_ExtInit_QueryInterface
,
2398 ShellLink_ExtInit_AddRef
,
2399 ShellLink_ExtInit_Release
,
2400 ShellLink_ExtInit_Initialize
2403 static HRESULT WINAPI
2404 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2406 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2407 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2411 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2413 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2414 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2418 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2420 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2421 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2424 static HRESULT WINAPI
2425 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2426 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2428 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2429 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2433 TRACE("%p %p %u %u %u %u\n", This
,
2434 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2437 return E_INVALIDARG
;
2439 memset( &mii
, 0, sizeof mii
);
2440 mii
.cbSize
= sizeof mii
;
2441 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2442 mii
.dwTypeData
= szOpen
;
2443 mii
.cch
= strlenW( mii
.dwTypeData
);
2444 mii
.wID
= idCmdFirst
+ id
++;
2445 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2446 mii
.fType
= MFT_STRING
;
2447 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2451 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2455 shelllink_get_msi_component_path( LPWSTR component
)
2460 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2461 if (r
!= ERROR_SUCCESS
)
2465 path
= heap_alloc( sz
*sizeof(WCHAR
) );
2466 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2467 if (r
!= ERROR_SUCCESS
)
2473 TRACE("returning %s\n", debugstr_w( path
) );
2478 static HRESULT WINAPI
2479 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2481 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2482 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2483 SHELLEXECUTEINFOW sei
;
2484 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2489 TRACE("%p %p\n", This
, lpici
);
2491 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2492 return E_INVALIDARG
;
2494 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2496 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2497 return E_INVALIDARG
;
2500 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2504 if ( This
->sComponent
)
2506 path
= shelllink_get_msi_component_path( This
->sComponent
);
2511 path
= strdupW( This
->sPath
);
2513 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2514 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2516 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2520 len
+= lstrlenW( This
->sArgs
);
2521 if ( iciex
->lpParametersW
)
2522 len
+= lstrlenW( iciex
->lpParametersW
);
2524 args
= heap_alloc( len
*sizeof(WCHAR
) );
2527 lstrcatW( args
, This
->sArgs
);
2528 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2530 static const WCHAR space
[] = { ' ', 0 };
2531 lstrcatW( args
, space
);
2532 lstrcatW( args
, iciex
->lpParametersW
);
2536 memset( &sei
, 0, sizeof sei
);
2537 sei
.cbSize
= sizeof sei
;
2538 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2540 sei
.nShow
= This
->iShowCmd
;
2541 sei
.lpIDList
= This
->pPidl
;
2542 sei
.lpDirectory
= This
->sWorkDir
;
2543 sei
.lpParameters
= args
;
2544 sei
.lpVerb
= szOpen
;
2546 if( ShellExecuteExW( &sei
) )
2557 static HRESULT WINAPI
2558 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2559 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2561 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2563 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This
,
2564 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2569 static const IContextMenuVtbl cmvt
=
2571 ShellLink_ContextMenu_QueryInterface
,
2572 ShellLink_ContextMenu_AddRef
,
2573 ShellLink_ContextMenu_Release
,
2574 ShellLink_QueryContextMenu
,
2575 ShellLink_InvokeCommand
,
2576 ShellLink_GetCommandString
2579 static HRESULT WINAPI
2580 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2582 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2583 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2587 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2589 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2590 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2594 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2596 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2597 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2600 static HRESULT WINAPI
2601 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2603 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2605 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2609 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2612 static HRESULT WINAPI
2613 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2615 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2617 TRACE("%p %p\n", iface
, punk
);
2620 IUnknown_AddRef( punk
);
2623 IUnknown_Release( This
->site
);
2630 static const IObjectWithSiteVtbl owsvt
=
2632 ShellLink_ObjectWithSite_QueryInterface
,
2633 ShellLink_ObjectWithSite_AddRef
,
2634 ShellLink_ObjectWithSite_Release
,
2639 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2641 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2642 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2645 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2647 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2648 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2651 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2653 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2654 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2657 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2659 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2660 FIXME("(%p)->(%p): stub\n", This
, props
);
2664 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2666 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2667 FIXME("(%p)->(%d %p): stub\n", This
, propid
, key
);
2671 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2673 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2674 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2678 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2680 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2681 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2685 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2687 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2688 FIXME("(%p): stub\n", This
);
2692 static const IPropertyStoreVtbl propertystorevtbl
= {
2693 propertystore_QueryInterface
,
2694 propertystore_AddRef
,
2695 propertystore_Release
,
2696 propertystore_GetCount
,
2697 propertystore_GetAt
,
2698 propertystore_GetValue
,
2699 propertystore_SetValue
,
2700 propertystore_Commit
2703 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2705 IShellLinkImpl
* sl
;
2708 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2713 return CLASS_E_NOAGGREGATION
;
2715 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2717 return E_OUTOFMEMORY
;
2720 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2721 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2722 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2723 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2724 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2725 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2726 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2727 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2728 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2729 sl
->iShowCmd
= SW_SHOWNORMAL
;
2733 sl
->filepath
= NULL
;
2735 TRACE("(%p)\n", sl
);
2737 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2738 IShellLinkW_Release( &sl
->IShellLinkW_iface
);