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"
50 #include "shell32_main.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
60 DEFINE_GUID( SHELL32_AdvtShortcutProduct
,
61 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
62 DEFINE_GUID( SHELL32_AdvtShortcutComponent
,
63 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
65 /* link file formats */
69 typedef struct _LINK_HEADER
71 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
72 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
73 DWORD dwFlags
; /* 0x14 describes elements following */
74 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
75 FILETIME CreationTime
; /* 0x1c creation time of target file */
76 FILETIME AccessTime
; /* 0x24 access time of target file */
77 FILETIME WriteTime
; /* 0x2c write time of target file */
78 DWORD dwFileSize
; /* 0x34 File size of target file */
79 DWORD nIcon
; /* 0x38 icon number or index */
80 DWORD fStartup
; /* 0x3c startup type or window state of application */
81 WORD wHotKey
; /* 0x40 hotkey */
82 WORD Reserved1
; /* 0x42 reserved = 0 */
83 DWORD Reserved2
; /* 0x44 reserved = 0 */
84 DWORD Reserved3
; /* 0x48 reserved = 0 */
85 } LINK_HEADER
, * PLINK_HEADER
;
87 #define SHLINK_LOCAL 0
88 #define SHLINK_REMOTE 1
90 typedef struct _LOCATION_INFO
97 DWORD dwNetworkVolTableOfs
;
101 typedef struct _LOCAL_VOLUME_INFO
109 typedef struct volume_info_t
113 WCHAR label
[12]; /* assume 8.3 */
118 /* IShellLink Implementation */
122 IShellLinkA IShellLinkA_iface
;
123 IShellLinkW IShellLinkW_iface
;
124 IPersistFile IPersistFile_iface
;
125 IPersistStream IPersistStream_iface
;
126 IShellLinkDataList IShellLinkDataList_iface
;
127 IShellExtInit IShellExtInit_iface
;
128 IContextMenu IContextMenu_iface
;
129 IObjectWithSite IObjectWithSite_iface
;
130 IPropertyStore IPropertyStore_iface
;
134 /* data structures according to the information in the link */
137 SYSTEMTIME CreationTime
;
138 SYSTEMTIME AccessTime
;
139 SYSTEMTIME WriteTime
;
154 INT iIdOpen
; /* id of the "Open" entry in the context menu */
157 LPOLESTR filepath
; /* file path returned by IPersistFile::GetCurFile */
160 static inline IShellLinkImpl
*impl_from_IShellLinkA(IShellLinkA
*iface
)
162 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkA_iface
);
165 static inline IShellLinkImpl
*impl_from_IShellLinkW(IShellLinkW
*iface
)
167 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkW_iface
);
170 static inline IShellLinkImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
172 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistFile_iface
);
175 static inline IShellLinkImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
177 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistStream_iface
);
180 static inline IShellLinkImpl
*impl_from_IShellLinkDataList(IShellLinkDataList
*iface
)
182 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkDataList_iface
);
185 static inline IShellLinkImpl
*impl_from_IShellExtInit(IShellExtInit
*iface
)
187 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellExtInit_iface
);
190 static inline IShellLinkImpl
*impl_from_IContextMenu(IContextMenu
*iface
)
192 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IContextMenu_iface
);
195 static inline IShellLinkImpl
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
197 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IObjectWithSite_iface
);
200 static inline IShellLinkImpl
*impl_from_IPropertyStore(IPropertyStore
*iface
)
202 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPropertyStore_iface
);
205 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
207 /* strdup on the process heap */
208 static inline LPWSTR
heap_strdupAtoW( LPCSTR str
)
210 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
211 WCHAR
*p
= malloc( len
* sizeof(WCHAR
) );
214 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
218 /**************************************************************************
219 * IPersistFile_QueryInterface
221 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
226 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
227 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
230 /******************************************************************************
231 * IPersistFile_AddRef
233 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
235 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
236 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
239 /******************************************************************************
240 * IPersistFile_Release
242 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
244 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
245 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
248 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
250 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
252 TRACE("(%p)->(%p)\n", This
, pClassID
);
254 *pClassID
= CLSID_ShellLink
;
259 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
261 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
263 TRACE("(%p)\n",This
);
271 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
273 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
274 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
278 TRACE("(%p, %s, %lx)\n",This
, debugstr_w(pszFileName
), dwMode
);
280 if( dwMode
== 0 ) dwMode
= STGM_READ
;
281 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
284 r
= IPersistStream_Load(StreamThis
, stm
);
285 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
286 IStream_Release( stm
);
288 /* update file path */
289 free(This
->filepath
);
290 This
->filepath
= wcsdup(pszFileName
);
292 This
->bDirty
= FALSE
;
294 TRACE("-- returning hr %08lx\n", r
);
298 BOOL
run_winemenubuilder( const WCHAR
*args
)
303 PROCESS_INFORMATION pi
;
308 GetSystemDirectoryW( app
, MAX_PATH
);
309 lstrcatW( app
, L
"\\winemenubuilder.exe" );
311 len
= (lstrlenW( app
) + lstrlenW( args
) + 1) * sizeof(WCHAR
);
312 buffer
= malloc( len
);
316 lstrcpyW( buffer
, app
);
317 lstrcatW( buffer
, args
);
319 TRACE("starting %s\n",debugstr_w(buffer
));
321 memset(&si
, 0, sizeof(si
));
324 Wow64DisableWow64FsRedirection( &redir
);
325 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
326 Wow64RevertWow64FsRedirection( redir
);
332 CloseHandle( pi
.hProcess
);
333 CloseHandle( pi
.hThread
);
339 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
345 len
= (lstrlenW( szLink
) + 7) * sizeof(WCHAR
);
346 buffer
= malloc( len
);
350 swprintf( buffer
, len
, L
" -w \"%s\"", szLink
);
351 ret
= run_winemenubuilder( buffer
);
356 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
358 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
359 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
363 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
367 if (!This
->filepath
) return S_OK
;
369 pszFileName
= This
->filepath
;
373 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_DENY_WRITE
, &stm
);
376 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
377 IStream_Release( stm
);
381 StartLinkProcessor( pszFileName
);
385 /* update file path */
386 free(This
->filepath
);
387 This
->filepath
= wcsdup(pszFileName
);
390 This
->bDirty
= FALSE
;
394 DeleteFileW( pszFileName
);
395 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
402 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
404 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
405 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
409 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
411 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
413 TRACE("(%p)->(%p)\n", This
, filename
);
421 *filename
= CoTaskMemAlloc((lstrlenW(This
->filepath
) + 1) * sizeof(WCHAR
));
422 if (!*filename
) return E_OUTOFMEMORY
;
424 lstrcpyW(*filename
, This
->filepath
);
429 static const IPersistFileVtbl pfvt
=
431 IPersistFile_fnQueryInterface
,
432 IPersistFile_fnAddRef
,
433 IPersistFile_fnRelease
,
434 IPersistFile_fnGetClassID
,
435 IPersistFile_fnIsDirty
,
438 IPersistFile_fnSaveCompleted
,
439 IPersistFile_fnGetCurFile
442 /************************************************************************
443 * IPersistStream_QueryInterface
445 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
446 IPersistStream
* iface
,
450 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
451 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
454 /************************************************************************
455 * IPersistStream_Release
457 static ULONG WINAPI
IPersistStream_fnRelease(
458 IPersistStream
* iface
)
460 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
461 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
464 /************************************************************************
465 * IPersistStream_AddRef
467 static ULONG WINAPI
IPersistStream_fnAddRef(
468 IPersistStream
* iface
)
470 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
471 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
474 /************************************************************************
475 * IPersistStream_GetClassID
478 static HRESULT WINAPI
IPersistStream_fnGetClassID(
479 IPersistStream
* iface
,
482 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
483 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
486 /************************************************************************
487 * IPersistStream_IsDirty (IPersistStream)
489 static HRESULT WINAPI
IPersistStream_fnIsDirty(
490 IPersistStream
* iface
)
492 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
494 TRACE("(%p)\n", This
);
500 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
511 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
512 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
516 len
*= sizeof (WCHAR
);
518 TRACE("reading %d\n", len
);
519 temp
= malloc(len
+ sizeof(WCHAR
));
521 return E_OUTOFMEMORY
;
523 r
= IStream_Read(stm
, temp
, len
, &count
);
524 if( FAILED (r
) || ( count
!= len
) )
530 TRACE("read %s\n", debugstr_an(temp
,len
));
532 /* convert to unicode if necessary */
535 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
536 str
= malloc( (count
+ 1) * sizeof(WCHAR
) );
540 return E_OUTOFMEMORY
;
542 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
557 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
564 unsigned char data
[1];
569 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
570 if( FAILED( r
) || count
!= sizeof(size
) )
573 chunk
= malloc( size
);
575 return E_OUTOFMEMORY
;
578 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
579 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
585 TRACE("Read %ld bytes\n",chunk
->size
);
592 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
594 const int label_sz
= ARRAY_SIZE(volume
->label
);
598 volume
->serial
= vol
->dwVolSerial
;
599 volume
->type
= vol
->dwType
;
601 if( !vol
->dwVolLabelOfs
)
603 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
605 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
608 label
+= vol
->dwVolLabelOfs
;
609 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
614 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
619 while( (len
< maxlen
) && p
[len
] )
622 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
623 path
= malloc((wlen
+ 1) * sizeof(WCHAR
));
624 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
630 static HRESULT
Stream_LoadLocation( IStream
*stm
,
631 volume_info
*volume
, LPWSTR
*path
)
638 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
642 loc
= (LOCATION_INFO
*) p
;
643 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
649 /* if there's valid local volume information, load it */
650 if( loc
->dwVolTableOfs
&&
651 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
653 LOCAL_VOLUME_INFO
*volume_info
;
655 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
656 Stream_LoadVolume( volume_info
, volume
);
659 /* if there's a local path, load it */
660 n
= loc
->dwLocalPathOfs
;
661 if( n
&& (n
< loc
->dwTotalSize
) )
662 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
664 TRACE("type %ld serial %08lx name %s path %s\n", volume
->type
,
665 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
672 * The format of the advertised shortcut info seems to be:
677 * 0 Length of the block (4 bytes, usually 0x314)
679 * 8 string data in ANSI
680 * 8+0x104 string data in UNICODE
682 * In the original Win32 implementation the buffers are not initialized
683 * to zero, so data trailing the string is random garbage.
685 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
690 EXP_DARWIN_LINK buffer
;
694 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
698 /* make sure that we read the size of the structure even on error */
699 size
= sizeof buffer
- sizeof (DWORD
);
700 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
702 ERR("Ooops. This structure is not as expected...\n");
706 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
713 TRACE("magic %08lx string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
715 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
717 ERR("Unknown magic number %08lx in advertised shortcut\n", buffer
.dbh
.dwSignature
);
721 *str
= malloc( (lstrlenW(buffer
.szwDarwinID
) + 1) * sizeof(WCHAR
) );
722 lstrcpyW( *str
, buffer
.szwDarwinID
);
727 /************************************************************************
728 * IPersistStream_Load (IPersistStream)
730 static HRESULT WINAPI
IPersistStream_fnLoad(
731 IPersistStream
* iface
,
740 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
742 TRACE("%p %p\n", This
, stm
);
745 return STG_E_INVALIDPOINTER
;
748 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
752 if( dwBytesRead
!= sizeof(hdr
))
754 if( hdr
.dwSize
!= sizeof(hdr
))
756 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
759 /* free all the old stuff */
762 memset( &This
->volume
, 0, sizeof This
->volume
);
765 free(This
->sDescription
);
766 This
->sDescription
= NULL
;
767 free(This
->sPathRel
);
768 This
->sPathRel
= NULL
;
769 free(This
->sWorkDir
);
770 This
->sWorkDir
= NULL
;
773 free(This
->sIcoPath
);
774 This
->sIcoPath
= NULL
;
775 free(This
->sProduct
);
776 This
->sProduct
= NULL
;
777 free(This
->sComponent
);
778 This
->sComponent
= NULL
;
780 This
->wHotKey
= hdr
.wHotKey
;
781 This
->iIcoNdx
= hdr
.nIcon
;
782 FileTimeToSystemTime (&hdr
.CreationTime
, &This
->CreationTime
);
783 FileTimeToSystemTime (&hdr
.AccessTime
, &This
->AccessTime
);
784 FileTimeToSystemTime (&hdr
.WriteTime
, &This
->WriteTime
);
787 WCHAR sTemp
[MAX_PATH
];
788 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->CreationTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
789 TRACE("-- CreationTime: %s\n", debugstr_w(sTemp
) );
790 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->AccessTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
791 TRACE("-- AccessTime: %s\n", debugstr_w(sTemp
) );
792 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->WriteTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
793 TRACE("-- WriteTime: %s\n", debugstr_w(sTemp
) );
796 /* load all the new stuff */
797 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
799 r
= ILLoadFromStream( stm
, &This
->pPidl
);
805 /* load the location information */
806 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
807 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
811 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
812 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
814 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
815 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
820 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
822 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
823 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
828 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
830 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
831 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
836 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
838 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
839 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
844 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
846 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
847 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
852 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
854 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
855 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
860 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
862 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
863 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
868 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
869 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
871 /* Some lnk files have extra data blocks starting with a
872 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
873 * one with a 0xa0000003 signature. However these don't seem to matter
876 WARN("Last word was not zero\n");
888 /************************************************************************
891 * Helper function for IPersistStream_Save. Writes a unicode string
892 * with terminating nul byte to a stream, preceded by the its length.
894 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
896 USHORT len
= lstrlenW( str
) + 1;
900 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
904 len
*= sizeof(WCHAR
);
906 r
= IStream_Write( stm
, str
, len
, &count
);
913 /************************************************************************
914 * Stream_WriteLocationInfo
916 * Writes the location info to a stream
918 * FIXME: One day we might want to write the network volume information
919 * and the final path.
920 * Figure out how Windows deals with unicode paths here.
922 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
923 volume_info
*volume
)
925 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
926 LOCAL_VOLUME_INFO
*vol
;
928 LPSTR szLabel
, szPath
, szFinalPath
;
932 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
934 /* figure out the size of everything */
935 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
936 NULL
, 0, NULL
, NULL
);
937 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
938 NULL
, 0, NULL
, NULL
);
939 volume_info_size
= sizeof *vol
+ label_size
;
941 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
943 /* create pointers to everything */
944 loc
= calloc(1, total_size
);
945 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
946 szLabel
= (LPSTR
) &vol
[1];
947 szPath
= &szLabel
[label_size
];
948 szFinalPath
= &szPath
[path_size
];
950 /* fill in the location information header */
951 loc
->dwTotalSize
= total_size
;
952 loc
->dwHeaderSize
= sizeof (*loc
);
954 loc
->dwVolTableOfs
= sizeof (*loc
);
955 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
956 loc
->dwNetworkVolTableOfs
= 0;
957 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
959 /* fill in the volume information */
960 vol
->dwSize
= volume_info_size
;
961 vol
->dwType
= volume
->type
;
962 vol
->dwVolSerial
= volume
->serial
;
963 vol
->dwVolLabelOfs
= sizeof (*vol
);
965 /* copy in the strings */
966 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
967 szLabel
, label_size
, NULL
, NULL
);
968 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
969 szPath
, path_size
, NULL
, NULL
);
972 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
978 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
980 EXP_DARWIN_LINK
*buffer
;
982 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
983 buffer
->dbh
.cbSize
= sizeof *buffer
;
984 buffer
->dbh
.dwSignature
= magic
;
985 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
986 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
991 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
993 EXP_DARWIN_LINK
*buffer
;
998 buffer
= shelllink_build_darwinid( string
, magic
);
1000 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1003 /************************************************************************
1004 * IPersistStream_Save (IPersistStream)
1006 * FIXME: makes assumptions about byte order
1008 static HRESULT WINAPI
IPersistStream_fnSave(
1009 IPersistStream
* iface
,
1018 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1020 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1022 memset(&header
, 0, sizeof(header
));
1023 header
.dwSize
= sizeof(header
);
1024 header
.fStartup
= This
->iShowCmd
;
1025 header
.MagicGuid
= CLSID_ShellLink
;
1027 header
.wHotKey
= This
->wHotKey
;
1028 header
.nIcon
= This
->iIcoNdx
;
1029 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1031 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1033 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1034 if( This
->sDescription
)
1035 header
.dwFlags
|= SLDF_HAS_NAME
;
1036 if( This
->sWorkDir
)
1037 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1039 header
.dwFlags
|= SLDF_HAS_ARGS
;
1040 if( This
->sIcoPath
)
1041 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1042 if( This
->sProduct
)
1043 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1044 if( This
->sComponent
)
1045 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1047 SystemTimeToFileTime ( &This
->CreationTime
, &header
.CreationTime
);
1048 SystemTimeToFileTime ( &This
->AccessTime
, &header
.AccessTime
);
1049 SystemTimeToFileTime ( &This
->WriteTime
, &header
.WriteTime
);
1051 /* write the Shortcut header */
1052 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1055 ERR("Write failed at %d\n",__LINE__
);
1059 TRACE("Writing pidl\n");
1061 /* write the PIDL to the shortcut */
1064 r
= ILSaveToStream( stm
, This
->pPidl
);
1067 ERR("Failed to write PIDL at %d\n",__LINE__
);
1073 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1075 if( This
->sDescription
)
1076 r
= Stream_WriteString( stm
, This
->sDescription
);
1078 if( This
->sPathRel
)
1079 r
= Stream_WriteString( stm
, This
->sPathRel
);
1081 if( This
->sWorkDir
)
1082 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1085 r
= Stream_WriteString( stm
, This
->sArgs
);
1087 if( This
->sIcoPath
)
1088 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1090 if( This
->sProduct
)
1091 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1093 if( This
->sComponent
)
1094 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1096 /* the last field is a single zero dword */
1098 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1103 /************************************************************************
1104 * IPersistStream_GetSizeMax (IPersistStream)
1106 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1107 IPersistStream
* iface
,
1108 ULARGE_INTEGER
* pcbSize
)
1110 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1112 TRACE("(%p)\n", This
);
1117 static const IPersistStreamVtbl psvt
=
1119 IPersistStream_fnQueryInterface
,
1120 IPersistStream_fnAddRef
,
1121 IPersistStream_fnRelease
,
1122 IPersistStream_fnGetClassID
,
1123 IPersistStream_fnIsDirty
,
1124 IPersistStream_fnLoad
,
1125 IPersistStream_fnSave
,
1126 IPersistStream_fnGetSizeMax
1129 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1131 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1136 /**************************************************************************
1137 * ShellLink_UpdatePath
1138 * update absolute path in sPath using relative path in sPathRel
1140 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1142 if (!path
|| !psPath
)
1143 return E_INVALIDARG
;
1145 if (!*psPath
&& sPathRel
) {
1146 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1147 LPWSTR final
= NULL
;
1149 /* first try if [directory of link file] + [relative path] finds an existing file */
1151 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1154 lstrcpyW(final
, sPathRel
);
1158 if (SHELL_ExistsFileW(buffer
)) {
1159 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1160 lstrcpyW(abs_path
, buffer
);
1162 /* try if [working directory] + [relative path] finds an existing file */
1164 lstrcpyW(buffer
, sWorkDir
);
1165 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1167 if (SHELL_ExistsFileW(buffer
))
1168 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1169 lstrcpyW(abs_path
, buffer
);
1173 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1175 lstrcpyW(abs_path
, sPathRel
);
1177 *psPath
= malloc((lstrlenW(abs_path
) + 1) * sizeof(WCHAR
));
1179 return E_OUTOFMEMORY
;
1181 lstrcpyW(*psPath
, abs_path
);
1187 /**************************************************************************
1188 * IShellLink_ConstructFromFile
1190 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1191 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1195 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1197 if (SUCCEEDED(hr
)) {
1202 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1204 if (SUCCEEDED(hr
)) {
1205 WCHAR path
[MAX_PATH
];
1207 if (SHGetPathFromIDListW(pidl
, path
))
1208 hr
= IPersistFile_Load(ppf
, path
, 0);
1213 *ppv
= (IUnknown
*)psl
;
1215 IPersistFile_Release(ppf
);
1219 IShellLinkW_Release(psl
);
1225 /**************************************************************************
1226 * IShellLinkA_QueryInterface
1228 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1230 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1231 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1234 /******************************************************************************
1235 * IShellLinkA_AddRef
1237 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1239 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1240 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1243 /******************************************************************************
1244 * IShellLinkA_Release
1246 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1248 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1249 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1252 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1253 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1255 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1258 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1259 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1261 if (This
->sComponent
|| This
->sProduct
)
1266 if (This
->sPath
&& This
->sPath
[0])
1267 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1268 pszFile
, cchMaxPath
, NULL
, NULL
);
1274 memset(pfd
, 0, sizeof(*pfd
));
1278 char path
[MAX_PATH
];
1279 WIN32_FILE_ATTRIBUTE_DATA fad
;
1281 WideCharToMultiByte(CP_ACP
, 0, This
->sPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
1283 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1285 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1286 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1287 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1288 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1289 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1290 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1293 lstrcpyA(pfd
->cFileName
, PathFindFileNameA(path
));
1295 if (GetShortPathNameA(path
, path
, MAX_PATH
))
1297 lstrcpyA(pfd
->cAlternateFileName
, PathFindFileNameA(path
));
1301 TRACE("attr 0x%08lx size 0x%08lx%08lx name %s shortname %s\n", pfd
->dwFileAttributes
,
1302 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_a(pfd
->cFileName
),
1303 wine_dbgstr_a(pfd
->cAlternateFileName
));
1309 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1311 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1312 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1315 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1317 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1318 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1321 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1324 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1326 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1330 if( This
->sDescription
)
1331 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1332 pszName
, cchMaxName
, NULL
, NULL
);
1337 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1339 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1343 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1347 descrW
= heap_strdupAtoW(pszName
);
1348 if (!descrW
) return E_OUTOFMEMORY
;
1353 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1359 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1362 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1364 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1368 if( This
->sWorkDir
)
1369 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1370 pszDir
, cchMaxPath
, NULL
, NULL
);
1375 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1377 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1381 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1383 dirW
= heap_strdupAtoW(pszDir
);
1384 if (!dirW
) return E_OUTOFMEMORY
;
1386 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1392 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1394 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1396 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1401 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1402 pszArgs
, cchMaxPath
, NULL
, NULL
);
1407 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1409 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1413 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1417 argsW
= heap_strdupAtoW(pszArgs
);
1418 if (!argsW
) return E_OUTOFMEMORY
;
1423 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1429 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1431 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1432 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1435 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1437 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1438 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1441 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1443 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1444 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1447 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1449 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1450 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1453 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1454 INT cchIconPath
, INT
*piIcon
)
1456 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1458 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1460 *piIcon
= This
->iIcoNdx
;
1463 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1470 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR path
, INT icon
)
1472 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1473 WCHAR
*pathW
= NULL
;
1476 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_a(path
), icon
);
1480 pathW
= heap_strdupAtoW(path
);
1482 return E_OUTOFMEMORY
;
1485 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, path
? pathW
: NULL
, icon
);
1491 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1494 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1498 TRACE("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1500 pathW
= heap_strdupAtoW(pszPathRel
);
1501 if (!pathW
) return E_OUTOFMEMORY
;
1503 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1509 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1511 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1513 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1515 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1518 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1520 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1524 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1526 if (!pszFile
) return E_INVALIDARG
;
1528 str
= heap_strdupAtoW(pszFile
);
1530 return E_OUTOFMEMORY
;
1532 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1538 /**************************************************************************
1539 * IShellLink Implementation
1542 static const IShellLinkAVtbl slvt
=
1544 IShellLinkA_fnQueryInterface
,
1545 IShellLinkA_fnAddRef
,
1546 IShellLinkA_fnRelease
,
1547 IShellLinkA_fnGetPath
,
1548 IShellLinkA_fnGetIDList
,
1549 IShellLinkA_fnSetIDList
,
1550 IShellLinkA_fnGetDescription
,
1551 IShellLinkA_fnSetDescription
,
1552 IShellLinkA_fnGetWorkingDirectory
,
1553 IShellLinkA_fnSetWorkingDirectory
,
1554 IShellLinkA_fnGetArguments
,
1555 IShellLinkA_fnSetArguments
,
1556 IShellLinkA_fnGetHotkey
,
1557 IShellLinkA_fnSetHotkey
,
1558 IShellLinkA_fnGetShowCmd
,
1559 IShellLinkA_fnSetShowCmd
,
1560 IShellLinkA_fnGetIconLocation
,
1561 IShellLinkA_fnSetIconLocation
,
1562 IShellLinkA_fnSetRelativePath
,
1563 IShellLinkA_fnResolve
,
1564 IShellLinkA_fnSetPath
1568 /**************************************************************************
1569 * IShellLinkW_fnQueryInterface
1571 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1572 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1574 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1576 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1580 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1582 *ppvObj
= &This
->IShellLinkA_iface
;
1584 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1586 *ppvObj
= &This
->IShellLinkW_iface
;
1588 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1590 *ppvObj
= &This
->IPersistFile_iface
;
1592 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1594 *ppvObj
= &This
->IPersistStream_iface
;
1596 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1598 *ppvObj
= &This
->IShellLinkDataList_iface
;
1600 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1602 *ppvObj
= &This
->IShellExtInit_iface
;
1604 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1606 *ppvObj
= &This
->IContextMenu_iface
;
1608 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1610 *ppvObj
= &This
->IObjectWithSite_iface
;
1612 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1614 *ppvObj
= &This
->IPropertyStore_iface
;
1619 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1620 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1623 ERR("-- Interface: E_NOINTERFACE\n");
1624 return E_NOINTERFACE
;
1627 /******************************************************************************
1628 * IShellLinkW_fnAddRef
1630 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1632 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1633 ULONG ref
= InterlockedIncrement(&This
->ref
);
1635 TRACE("(%p)->(count=%lu)\n", This
, ref
- 1);
1640 /******************************************************************************
1641 * IShellLinkW_fnRelease
1643 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1645 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1646 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1648 TRACE("(%p)->(count=%lu)\n", This
, refCount
+ 1);
1653 TRACE("-- destroying IShellLink(%p)\n",This
);
1655 free(This
->sIcoPath
);
1657 free(This
->sWorkDir
);
1658 free(This
->sDescription
);
1660 free(This
->sPathRel
);
1661 free(This
->sProduct
);
1662 free(This
->sComponent
);
1663 free(This
->filepath
);
1666 IUnknown_Release( This
->site
);
1669 ILFree(This
->pPidl
);
1676 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1678 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1681 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1682 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1684 if (This
->sComponent
|| This
->sProduct
)
1690 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1696 memset(pfd
, 0, sizeof(*pfd
));
1700 WCHAR path
[MAX_PATH
];
1701 WIN32_FILE_ATTRIBUTE_DATA fad
;
1703 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1705 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1706 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1707 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1708 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1709 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1710 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1713 lstrcpyW(pfd
->cFileName
, PathFindFileNameW(This
->sPath
));
1715 if (GetShortPathNameW(This
->sPath
, path
, MAX_PATH
))
1717 lstrcpyW(pfd
->cAlternateFileName
, PathFindFileNameW(path
));
1721 TRACE("attr 0x%08lx size 0x%08lx%08lx name %s shortname %s\n", pfd
->dwFileAttributes
,
1722 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_w(pfd
->cFileName
),
1723 wine_dbgstr_w(pfd
->cAlternateFileName
));
1729 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1731 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1733 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1740 *ppidl
= ILClone(This
->pPidl
);
1744 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1746 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1747 WCHAR path
[MAX_PATH
];
1749 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1752 ILFree( This
->pPidl
);
1753 This
->pPidl
= ILClone( pidl
);
1757 free( This
->sPath
);
1760 if ( SHGetPathFromIDListW( pidl
, path
) )
1762 This
->sPath
= malloc((lstrlenW(path
) + 1) * sizeof(WCHAR
));
1764 return E_OUTOFMEMORY
;
1766 lstrcpyW(This
->sPath
, path
);
1769 This
->bDirty
= TRUE
;
1774 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1776 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1778 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1781 if( This
->sDescription
)
1782 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1787 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1789 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1791 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1793 free(This
->sDescription
);
1796 This
->sDescription
= malloc( (lstrlenW( pszName
) + 1) * sizeof(WCHAR
) );
1797 if ( !This
->sDescription
)
1798 return E_OUTOFMEMORY
;
1800 lstrcpyW( This
->sDescription
, pszName
);
1803 This
->sDescription
= NULL
;
1804 This
->bDirty
= TRUE
;
1809 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1811 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1813 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1817 if( This
->sWorkDir
)
1818 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1823 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1825 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1827 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1829 free(This
->sWorkDir
);
1830 This
->sWorkDir
= malloc( (lstrlenW( pszDir
) + 1) * sizeof(WCHAR
) );
1831 if ( !This
->sWorkDir
)
1832 return E_OUTOFMEMORY
;
1833 lstrcpyW( This
->sWorkDir
, pszDir
);
1834 This
->bDirty
= TRUE
;
1839 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1841 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1843 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1848 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1853 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1855 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1857 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1862 This
->sArgs
= malloc( (lstrlenW( pszArgs
) + 1) * sizeof(WCHAR
) );
1864 return E_OUTOFMEMORY
;
1865 lstrcpyW( This
->sArgs
, pszArgs
);
1867 else This
->sArgs
= NULL
;
1869 This
->bDirty
= TRUE
;
1874 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1876 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1878 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1880 *pwHotkey
=This
->wHotKey
;
1885 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1887 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1889 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1891 This
->wHotKey
= wHotkey
;
1892 This
->bDirty
= TRUE
;
1897 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1899 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1901 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1903 *piShowCmd
= This
->iShowCmd
;
1908 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1910 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1912 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1914 This
->iShowCmd
= iShowCmd
;
1915 This
->bDirty
= TRUE
;
1920 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1922 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1924 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1926 *piIcon
= This
->iIcoNdx
;
1929 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1936 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, const WCHAR
*path
, INT icon
)
1938 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1940 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_w(path
), icon
);
1942 free(This
->sIcoPath
);
1945 size_t len
= (lstrlenW(path
) + 1) * sizeof(WCHAR
);
1946 This
->sIcoPath
= malloc(len
);
1947 if (!This
->sIcoPath
)
1948 return E_OUTOFMEMORY
;
1949 memcpy(This
->sIcoPath
, path
, len
);
1952 This
->sIcoPath
= NULL
;
1953 This
->iIcoNdx
= icon
;
1954 This
->bDirty
= TRUE
;
1959 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1961 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1963 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1965 free(This
->sPathRel
);
1966 This
->sPathRel
= malloc( (lstrlenW( pszPathRel
) + 1) * sizeof(WCHAR
) );
1967 if ( !This
->sPathRel
)
1968 return E_OUTOFMEMORY
;
1969 lstrcpyW( This
->sPathRel
, pszPathRel
);
1970 This
->bDirty
= TRUE
;
1972 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1975 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1980 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1982 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1984 /*FIXME: use IResolveShellLink interface */
1986 if (!This
->sPath
&& This
->pPidl
) {
1987 WCHAR buffer
[MAX_PATH
];
1989 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1991 if (bSuccess
&& *buffer
) {
1992 This
->sPath
= malloc((lstrlenW(buffer
) + 1) * sizeof(WCHAR
));
1994 return E_OUTOFMEMORY
;
1996 lstrcpyW(This
->sPath
, buffer
);
1998 This
->bDirty
= TRUE
;
2000 hr
= S_OK
; /* don't report an error occurred while just caching information */
2003 if (!This
->sIcoPath
&& This
->sPath
) {
2004 This
->sIcoPath
= malloc((lstrlenW(This
->sPath
) + 1) * sizeof(WCHAR
));
2005 if (!This
->sIcoPath
)
2006 return E_OUTOFMEMORY
;
2008 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2011 This
->bDirty
= TRUE
;
2017 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2026 p
= wcschr( str
, ':' );
2030 ret
= malloc(sizeof(WCHAR
) * (len
+ 1));
2033 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2038 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2040 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2048 /* each segment must start with two colons */
2049 if( str
[0] != ':' || str
[1] != ':' )
2052 /* the last segment is just two colons */
2057 /* there must be a colon straight after a guid */
2058 p
= wcschr( str
, ':' );
2065 /* get the guid, and check it's validly formatted */
2066 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2068 r
= CLSIDFromString( szGuid
, &guid
);
2073 /* match it up to a guid that we care about */
2074 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2076 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2081 /* skip to the next field */
2082 str
= wcschr( str
, ':' );
2087 /* we have to have a component for an advertised shortcut */
2091 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2092 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2094 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2095 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2100 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2102 const int label_sz
= ARRAY_SIZE(volume
->label
);
2103 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2106 volume
->type
= GetDriveTypeW(drive
);
2107 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2108 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2109 TRACE("r = %d type %ld serial %08lx name %s\n", r
,
2110 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2114 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2116 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2117 WCHAR buffer
[MAX_PATH
];
2118 LPWSTR fname
, unquoted
= NULL
;
2122 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2124 if (!pszFile
) return E_INVALIDARG
;
2126 /* quotes at the ends of the string are stripped */
2127 len
= lstrlenW(pszFile
);
2128 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2130 unquoted
= wcsdup(pszFile
);
2131 PathUnquoteSpacesW(unquoted
);
2135 /* any other quote marks are invalid */
2136 if (wcschr(pszFile
, '"'))
2145 free(This
->sComponent
);
2146 This
->sComponent
= NULL
;
2149 ILFree(This
->pPidl
);
2152 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2154 if (*pszFile
== '\0')
2156 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2161 else if(!PathFileExistsW(buffer
) &&
2162 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2165 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2166 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2168 This
->sPath
= malloc( (lstrlenW( buffer
) + 1) * sizeof(WCHAR
) );
2172 return E_OUTOFMEMORY
;
2175 lstrcpyW(This
->sPath
, buffer
);
2177 This
->bDirty
= TRUE
;
2183 /**************************************************************************
2184 * IShellLinkW Implementation
2187 static const IShellLinkWVtbl slvtw
=
2189 IShellLinkW_fnQueryInterface
,
2190 IShellLinkW_fnAddRef
,
2191 IShellLinkW_fnRelease
,
2192 IShellLinkW_fnGetPath
,
2193 IShellLinkW_fnGetIDList
,
2194 IShellLinkW_fnSetIDList
,
2195 IShellLinkW_fnGetDescription
,
2196 IShellLinkW_fnSetDescription
,
2197 IShellLinkW_fnGetWorkingDirectory
,
2198 IShellLinkW_fnSetWorkingDirectory
,
2199 IShellLinkW_fnGetArguments
,
2200 IShellLinkW_fnSetArguments
,
2201 IShellLinkW_fnGetHotkey
,
2202 IShellLinkW_fnSetHotkey
,
2203 IShellLinkW_fnGetShowCmd
,
2204 IShellLinkW_fnSetShowCmd
,
2205 IShellLinkW_fnGetIconLocation
,
2206 IShellLinkW_fnSetIconLocation
,
2207 IShellLinkW_fnSetRelativePath
,
2208 IShellLinkW_fnResolve
,
2209 IShellLinkW_fnSetPath
2212 static HRESULT WINAPI
2213 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2215 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2216 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2220 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2222 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2223 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2227 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2229 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2230 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2233 static HRESULT WINAPI
2234 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2236 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2240 static HRESULT WINAPI
2241 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2243 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2244 LPVOID block
= NULL
;
2247 TRACE("%p %08lx %p\n", iface
, dwSig
, ppDataBlock
);
2251 case EXP_DARWIN_ID_SIG
:
2252 if (!This
->sComponent
)
2254 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2257 case EXP_SZ_LINK_SIG
:
2258 case NT_CONSOLE_PROPS_SIG
:
2259 case NT_FE_CONSOLE_PROPS_SIG
:
2260 case EXP_SPECIAL_FOLDER_SIG
:
2261 case EXP_SZ_ICON_SIG
:
2262 FIXME("valid but unhandled datablock %08lx\n", dwSig
);
2265 ERR("unknown datablock %08lx\n", dwSig
);
2267 *ppDataBlock
= block
;
2271 static HRESULT WINAPI
2272 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2274 FIXME("(%p)->(%lu): stub\n", iface
, dwSig
);
2278 static HRESULT WINAPI
2279 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2281 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2284 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2286 /* FIXME: add more */
2288 flags
|= SLDF_HAS_ARGS
;
2289 if (This
->sComponent
)
2290 flags
|= SLDF_HAS_DARWINID
;
2292 flags
|= SLDF_HAS_ICONLOCATION
;
2294 flags
|= SLDF_HAS_LOGO3ID
;
2296 flags
|= SLDF_HAS_ID_LIST
;
2303 static HRESULT WINAPI
2304 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2306 FIXME("(%p)->(%lu): stub\n", iface
, dwFlags
);
2310 static const IShellLinkDataListVtbl dlvt
=
2312 ShellLink_DataList_QueryInterface
,
2313 ShellLink_DataList_AddRef
,
2314 ShellLink_DataList_Release
,
2315 ShellLink_AddDataBlock
,
2316 ShellLink_CopyDataBlock
,
2317 ShellLink_RemoveDataBlock
,
2322 static HRESULT WINAPI
2323 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2325 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2326 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2330 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2332 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2333 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2337 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2339 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2340 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2343 /**************************************************************************
2344 * ShellLink implementation of IShellExtInit::Initialize()
2346 * Loads the shelllink from the dataobject the shell is pointing to.
2348 static HRESULT WINAPI
2349 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2350 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2352 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2358 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2363 format
.cfFormat
= CF_HDROP
;
2365 format
.dwAspect
= DVASPECT_CONTENT
;
2367 format
.tymed
= TYMED_HGLOBAL
;
2369 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2372 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2377 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2379 path
= malloc( count
* sizeof(WCHAR
) );
2382 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2384 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2385 r
= IPersistFile_Load( pf
, path
, 0 );
2389 ReleaseStgMedium( &stgm
);
2394 static const IShellExtInitVtbl eivt
=
2396 ShellLink_ExtInit_QueryInterface
,
2397 ShellLink_ExtInit_AddRef
,
2398 ShellLink_ExtInit_Release
,
2399 ShellLink_ExtInit_Initialize
2402 static HRESULT WINAPI
2403 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2405 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2406 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2410 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2412 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2413 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2417 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2419 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2420 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2423 static HRESULT WINAPI
2424 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2425 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2427 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2431 TRACE("%p %p %u %u %u %u\n", This
,
2432 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2435 return E_INVALIDARG
;
2437 memset( &mii
, 0, sizeof mii
);
2438 mii
.cbSize
= sizeof mii
;
2439 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2440 mii
.dwTypeData
= (LPWSTR
)L
"Open";
2441 mii
.cch
= lstrlenW( mii
.dwTypeData
);
2442 mii
.wID
= idCmdFirst
+ id
++;
2443 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2444 mii
.fType
= MFT_STRING
;
2445 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2449 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2453 shelllink_get_msi_component_path( LPWSTR component
)
2458 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2459 if (r
!= ERROR_SUCCESS
)
2463 path
= malloc( sz
* sizeof(WCHAR
) );
2464 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2465 if (r
!= ERROR_SUCCESS
)
2471 TRACE("returning %s\n", debugstr_w( path
) );
2476 static HRESULT WINAPI
2477 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2479 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2480 SHELLEXECUTEINFOW sei
;
2481 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2486 TRACE("%p %p\n", This
, lpici
);
2488 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2489 return E_INVALIDARG
;
2491 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2493 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2494 return E_INVALIDARG
;
2497 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2501 if ( This
->sComponent
)
2503 path
= shelllink_get_msi_component_path( This
->sComponent
);
2508 path
= wcsdup( This
->sPath
);
2510 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2511 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2513 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2517 len
+= lstrlenW( This
->sArgs
);
2518 if ( iciex
->lpParametersW
)
2519 len
+= lstrlenW( iciex
->lpParametersW
);
2521 args
= malloc( len
* sizeof(WCHAR
) );
2524 lstrcatW( args
, This
->sArgs
);
2525 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2527 lstrcatW( args
, L
" " );
2528 lstrcatW( args
, iciex
->lpParametersW
);
2532 memset( &sei
, 0, sizeof sei
);
2533 sei
.cbSize
= sizeof sei
;
2534 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2536 sei
.nShow
= This
->iShowCmd
;
2537 sei
.lpIDList
= This
->pPidl
;
2538 sei
.lpDirectory
= This
->sWorkDir
;
2539 sei
.lpParameters
= args
;
2540 sei
.lpVerb
= L
"Open";
2542 if( ShellExecuteExW( &sei
) )
2553 static HRESULT WINAPI
2554 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2555 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2557 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2559 FIXME("(%p)->(%Iu %u %p %p %u): stub\n", This
,
2560 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2565 static const IContextMenuVtbl cmvt
=
2567 ShellLink_ContextMenu_QueryInterface
,
2568 ShellLink_ContextMenu_AddRef
,
2569 ShellLink_ContextMenu_Release
,
2570 ShellLink_QueryContextMenu
,
2571 ShellLink_InvokeCommand
,
2572 ShellLink_GetCommandString
2575 static HRESULT WINAPI
2576 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2578 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2579 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2583 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2585 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2586 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2590 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2592 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2593 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2596 static HRESULT WINAPI
2597 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2599 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2601 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2605 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2608 static HRESULT WINAPI
2609 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2611 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2613 TRACE("%p %p\n", iface
, punk
);
2616 IUnknown_AddRef( punk
);
2619 IUnknown_Release( This
->site
);
2626 static const IObjectWithSiteVtbl owsvt
=
2628 ShellLink_ObjectWithSite_QueryInterface
,
2629 ShellLink_ObjectWithSite_AddRef
,
2630 ShellLink_ObjectWithSite_Release
,
2635 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2637 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2638 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2641 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2643 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2644 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2647 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2649 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2650 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2653 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2655 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2656 FIXME("(%p)->(%p): stub\n", This
, props
);
2660 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2662 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2663 FIXME("(%p)->(%ld %p): stub\n", This
, propid
, key
);
2667 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2669 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2670 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2674 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2676 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2677 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2681 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2683 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2684 FIXME("(%p): stub\n", This
);
2688 static const IPropertyStoreVtbl propertystorevtbl
= {
2689 propertystore_QueryInterface
,
2690 propertystore_AddRef
,
2691 propertystore_Release
,
2692 propertystore_GetCount
,
2693 propertystore_GetAt
,
2694 propertystore_GetValue
,
2695 propertystore_SetValue
,
2696 propertystore_Commit
2699 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2701 IShellLinkImpl
* sl
;
2704 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2709 return CLASS_E_NOAGGREGATION
;
2711 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2713 return E_OUTOFMEMORY
;
2716 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2717 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2718 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2719 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2720 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2721 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2722 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2723 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2724 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2725 sl
->iShowCmd
= SW_SHOWNORMAL
;
2729 sl
->filepath
= NULL
;
2731 TRACE("(%p)\n", sl
);
2733 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2734 IShellLinkW_Release( &sl
->IShellLinkW_iface
);