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 #include "wine/debug.h"
48 #include "shell32_main.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
58 DEFINE_GUID( SHELL32_AdvtShortcutProduct
,
59 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
60 DEFINE_GUID( SHELL32_AdvtShortcutComponent
,
61 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
63 /* link file formats */
67 typedef struct _LINK_HEADER
69 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
70 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
71 DWORD dwFlags
; /* 0x14 describes elements following */
72 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
73 FILETIME CreationTime
; /* 0x1c creation time of target file */
74 FILETIME AccessTime
; /* 0x24 access time of target file */
75 FILETIME WriteTime
; /* 0x2c write time of target file */
76 DWORD dwFileSize
; /* 0x34 File size of target file */
77 DWORD nIcon
; /* 0x38 icon number or index */
78 DWORD fStartup
; /* 0x3c startup type or window state of application */
79 WORD wHotKey
; /* 0x40 hotkey */
80 WORD Reserved1
; /* 0x42 reserved = 0 */
81 DWORD Reserved2
; /* 0x44 reserved = 0 */
82 DWORD Reserved3
; /* 0x48 reserved = 0 */
83 } LINK_HEADER
, * PLINK_HEADER
;
85 #define SHLINK_LOCAL 0
86 #define SHLINK_REMOTE 1
88 typedef struct _LOCATION_INFO
95 DWORD dwNetworkVolTableOfs
;
99 typedef struct _LOCAL_VOLUME_INFO
107 typedef struct volume_info_t
111 WCHAR label
[12]; /* assume 8.3 */
116 /* IShellLink Implementation */
120 IShellLinkA IShellLinkA_iface
;
121 IShellLinkW IShellLinkW_iface
;
122 IPersistFile IPersistFile_iface
;
123 IPersistStream IPersistStream_iface
;
124 IShellLinkDataList IShellLinkDataList_iface
;
125 IShellExtInit IShellExtInit_iface
;
126 IContextMenu IContextMenu_iface
;
127 IObjectWithSite IObjectWithSite_iface
;
128 IPropertyStore IPropertyStore_iface
;
132 /* data structures according to the information in the link */
135 SYSTEMTIME CreationTime
;
136 SYSTEMTIME AccessTime
;
137 SYSTEMTIME WriteTime
;
152 INT iIdOpen
; /* id of the "Open" entry in the context menu */
155 LPOLESTR filepath
; /* file path returned by IPersistFile::GetCurFile */
158 static inline IShellLinkImpl
*impl_from_IShellLinkA(IShellLinkA
*iface
)
160 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkA_iface
);
163 static inline IShellLinkImpl
*impl_from_IShellLinkW(IShellLinkW
*iface
)
165 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkW_iface
);
168 static inline IShellLinkImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
170 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistFile_iface
);
173 static inline IShellLinkImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
175 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistStream_iface
);
178 static inline IShellLinkImpl
*impl_from_IShellLinkDataList(IShellLinkDataList
*iface
)
180 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkDataList_iface
);
183 static inline IShellLinkImpl
*impl_from_IShellExtInit(IShellExtInit
*iface
)
185 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellExtInit_iface
);
188 static inline IShellLinkImpl
*impl_from_IContextMenu(IContextMenu
*iface
)
190 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IContextMenu_iface
);
193 static inline IShellLinkImpl
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
195 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IObjectWithSite_iface
);
198 static inline IShellLinkImpl
*impl_from_IPropertyStore(IPropertyStore
*iface
)
200 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPropertyStore_iface
);
203 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
205 /**************************************************************************
206 * IPersistFile_QueryInterface
208 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
213 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
214 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
217 /******************************************************************************
218 * IPersistFile_AddRef
220 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
222 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
223 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
226 /******************************************************************************
227 * IPersistFile_Release
229 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
231 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
232 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
235 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
237 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
239 TRACE("(%p)->(%p)\n", This
, pClassID
);
241 *pClassID
= CLSID_ShellLink
;
246 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
248 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
250 TRACE("(%p)\n",This
);
258 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
260 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
261 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
265 TRACE("(%p, %s, %lx)\n",This
, debugstr_w(pszFileName
), dwMode
);
267 if( dwMode
== 0 ) dwMode
= STGM_READ
;
268 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
271 r
= IPersistStream_Load(StreamThis
, stm
);
272 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
273 IStream_Release( stm
);
275 /* update file path */
276 free(This
->filepath
);
277 This
->filepath
= wcsdup(pszFileName
);
279 This
->bDirty
= FALSE
;
281 TRACE("-- returning hr %08lx\n", r
);
285 BOOL
run_winemenubuilder( const WCHAR
*args
)
290 PROCESS_INFORMATION pi
;
295 GetSystemDirectoryW( app
, MAX_PATH
);
296 lstrcatW( app
, L
"\\winemenubuilder.exe" );
298 len
= (lstrlenW( app
) + lstrlenW( args
) + 1) * sizeof(WCHAR
);
299 buffer
= malloc( len
);
303 lstrcpyW( buffer
, app
);
304 lstrcatW( buffer
, args
);
306 TRACE("starting %s\n",debugstr_w(buffer
));
308 memset(&si
, 0, sizeof(si
));
311 Wow64DisableWow64FsRedirection( &redir
);
312 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
313 Wow64RevertWow64FsRedirection( redir
);
319 CloseHandle( pi
.hProcess
);
320 CloseHandle( pi
.hThread
);
326 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
332 len
= (lstrlenW( szLink
) + 7) * sizeof(WCHAR
);
333 buffer
= malloc( len
);
337 swprintf( buffer
, len
, L
" -w \"%s\"", szLink
);
338 ret
= run_winemenubuilder( buffer
);
343 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
345 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
346 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
350 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
354 if (!This
->filepath
) return S_OK
;
356 pszFileName
= This
->filepath
;
360 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_DENY_WRITE
, &stm
);
363 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
364 IStream_Release( stm
);
368 StartLinkProcessor( pszFileName
);
372 /* update file path */
373 free(This
->filepath
);
374 This
->filepath
= wcsdup(pszFileName
);
377 This
->bDirty
= FALSE
;
381 DeleteFileW( pszFileName
);
382 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
389 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
391 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
392 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
396 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
398 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
400 TRACE("(%p)->(%p)\n", This
, filename
);
408 *filename
= CoTaskMemAlloc((lstrlenW(This
->filepath
) + 1) * sizeof(WCHAR
));
409 if (!*filename
) return E_OUTOFMEMORY
;
411 lstrcpyW(*filename
, This
->filepath
);
416 static const IPersistFileVtbl pfvt
=
418 IPersistFile_fnQueryInterface
,
419 IPersistFile_fnAddRef
,
420 IPersistFile_fnRelease
,
421 IPersistFile_fnGetClassID
,
422 IPersistFile_fnIsDirty
,
425 IPersistFile_fnSaveCompleted
,
426 IPersistFile_fnGetCurFile
429 /************************************************************************
430 * IPersistStream_QueryInterface
432 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
433 IPersistStream
* iface
,
437 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
438 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
441 /************************************************************************
442 * IPersistStream_Release
444 static ULONG WINAPI
IPersistStream_fnRelease(
445 IPersistStream
* iface
)
447 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
448 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
451 /************************************************************************
452 * IPersistStream_AddRef
454 static ULONG WINAPI
IPersistStream_fnAddRef(
455 IPersistStream
* iface
)
457 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
458 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
461 /************************************************************************
462 * IPersistStream_GetClassID
465 static HRESULT WINAPI
IPersistStream_fnGetClassID(
466 IPersistStream
* iface
,
469 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
470 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
473 /************************************************************************
474 * IPersistStream_IsDirty (IPersistStream)
476 static HRESULT WINAPI
IPersistStream_fnIsDirty(
477 IPersistStream
* iface
)
479 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
481 TRACE("(%p)\n", This
);
487 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
498 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
499 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
503 len
*= sizeof (WCHAR
);
505 TRACE("reading %d\n", len
);
506 temp
= malloc(len
+ sizeof(WCHAR
));
508 return E_OUTOFMEMORY
;
510 r
= IStream_Read(stm
, temp
, len
, &count
);
511 if( FAILED (r
) || ( count
!= len
) )
517 TRACE("read %s\n", debugstr_an(temp
,len
));
519 /* convert to unicode if necessary */
522 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
523 str
= malloc( (count
+ 1) * sizeof(WCHAR
) );
527 return E_OUTOFMEMORY
;
529 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
544 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
551 unsigned char data
[1];
556 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
557 if( FAILED( r
) || count
!= sizeof(size
) )
560 chunk
= malloc( size
);
562 return E_OUTOFMEMORY
;
565 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
566 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
572 TRACE("Read %ld bytes\n",chunk
->size
);
579 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
581 const int label_sz
= ARRAY_SIZE(volume
->label
);
585 volume
->serial
= vol
->dwVolSerial
;
586 volume
->type
= vol
->dwType
;
588 if( !vol
->dwVolLabelOfs
)
590 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
592 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
595 label
+= vol
->dwVolLabelOfs
;
596 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
601 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
606 while( (len
< maxlen
) && p
[len
] )
609 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
610 path
= malloc((wlen
+ 1) * sizeof(WCHAR
));
611 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
617 static HRESULT
Stream_LoadLocation( IStream
*stm
,
618 volume_info
*volume
, LPWSTR
*path
)
625 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
629 loc
= (LOCATION_INFO
*) p
;
630 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
636 /* if there's valid local volume information, load it */
637 if( loc
->dwVolTableOfs
&&
638 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
640 LOCAL_VOLUME_INFO
*volume_info
;
642 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
643 Stream_LoadVolume( volume_info
, volume
);
646 /* if there's a local path, load it */
647 n
= loc
->dwLocalPathOfs
;
648 if( n
&& (n
< loc
->dwTotalSize
) )
649 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
651 TRACE("type %ld serial %08lx name %s path %s\n", volume
->type
,
652 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
659 * The format of the advertised shortcut info seems to be:
664 * 0 Length of the block (4 bytes, usually 0x314)
666 * 8 string data in ANSI
667 * 8+0x104 string data in UNICODE
669 * In the original Win32 implementation the buffers are not initialized
670 * to zero, so data trailing the string is random garbage.
672 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
677 EXP_DARWIN_LINK buffer
;
681 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
685 /* make sure that we read the size of the structure even on error */
686 size
= sizeof buffer
- sizeof (DWORD
);
687 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
689 ERR("Ooops. This structure is not as expected...\n");
693 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
700 TRACE("magic %08lx string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
702 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
704 ERR("Unknown magic number %08lx in advertised shortcut\n", buffer
.dbh
.dwSignature
);
708 *str
= wcsdup( buffer
.szwDarwinID
);
713 /************************************************************************
714 * IPersistStream_Load (IPersistStream)
716 static HRESULT WINAPI
IPersistStream_fnLoad(
717 IPersistStream
* iface
,
726 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
728 TRACE("%p %p\n", This
, stm
);
731 return STG_E_INVALIDPOINTER
;
734 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
738 if( dwBytesRead
!= sizeof(hdr
))
740 if( hdr
.dwSize
!= sizeof(hdr
))
742 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
745 /* free all the old stuff */
748 memset( &This
->volume
, 0, sizeof This
->volume
);
751 free(This
->sDescription
);
752 This
->sDescription
= NULL
;
753 free(This
->sPathRel
);
754 This
->sPathRel
= NULL
;
755 free(This
->sWorkDir
);
756 This
->sWorkDir
= NULL
;
759 free(This
->sIcoPath
);
760 This
->sIcoPath
= NULL
;
761 free(This
->sProduct
);
762 This
->sProduct
= NULL
;
763 free(This
->sComponent
);
764 This
->sComponent
= NULL
;
766 This
->wHotKey
= hdr
.wHotKey
;
767 This
->iIcoNdx
= hdr
.nIcon
;
768 FileTimeToSystemTime (&hdr
.CreationTime
, &This
->CreationTime
);
769 FileTimeToSystemTime (&hdr
.AccessTime
, &This
->AccessTime
);
770 FileTimeToSystemTime (&hdr
.WriteTime
, &This
->WriteTime
);
773 WCHAR sTemp
[MAX_PATH
];
774 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->CreationTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
775 TRACE("-- CreationTime: %s\n", debugstr_w(sTemp
) );
776 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->AccessTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
777 TRACE("-- AccessTime: %s\n", debugstr_w(sTemp
) );
778 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->WriteTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
779 TRACE("-- WriteTime: %s\n", debugstr_w(sTemp
) );
782 /* load all the new stuff */
783 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
785 r
= ILLoadFromStream( stm
, &This
->pPidl
);
791 /* load the location information */
792 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
793 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
797 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
798 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
800 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
801 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
806 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
808 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
809 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
814 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
816 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
817 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
822 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
824 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
825 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
830 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
832 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
833 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
838 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
840 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
841 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
846 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
848 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
849 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
854 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
855 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
857 /* Some lnk files have extra data blocks starting with a
858 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
859 * one with a 0xa0000003 signature. However these don't seem to matter
862 WARN("Last word was not zero\n");
874 /************************************************************************
877 * Helper function for IPersistStream_Save. Writes a unicode string
878 * with terminating nul byte to a stream, preceded by the its length.
880 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
882 USHORT len
= lstrlenW( str
) + 1;
886 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
890 len
*= sizeof(WCHAR
);
892 r
= IStream_Write( stm
, str
, len
, &count
);
899 /************************************************************************
900 * Stream_WriteLocationInfo
902 * Writes the location info to a stream
904 * FIXME: One day we might want to write the network volume information
905 * and the final path.
906 * Figure out how Windows deals with unicode paths here.
908 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
909 volume_info
*volume
)
911 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
912 LOCAL_VOLUME_INFO
*vol
;
914 LPSTR szLabel
, szPath
, szFinalPath
;
918 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
920 /* figure out the size of everything */
921 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
922 NULL
, 0, NULL
, NULL
);
923 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
924 NULL
, 0, NULL
, NULL
);
925 volume_info_size
= sizeof *vol
+ label_size
;
927 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
929 /* create pointers to everything */
930 loc
= calloc(1, total_size
);
931 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
932 szLabel
= (LPSTR
) &vol
[1];
933 szPath
= &szLabel
[label_size
];
934 szFinalPath
= &szPath
[path_size
];
936 /* fill in the location information header */
937 loc
->dwTotalSize
= total_size
;
938 loc
->dwHeaderSize
= sizeof (*loc
);
940 loc
->dwVolTableOfs
= sizeof (*loc
);
941 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
942 loc
->dwNetworkVolTableOfs
= 0;
943 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
945 /* fill in the volume information */
946 vol
->dwSize
= volume_info_size
;
947 vol
->dwType
= volume
->type
;
948 vol
->dwVolSerial
= volume
->serial
;
949 vol
->dwVolLabelOfs
= sizeof (*vol
);
951 /* copy in the strings */
952 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
953 szLabel
, label_size
, NULL
, NULL
);
954 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
955 szPath
, path_size
, NULL
, NULL
);
958 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
964 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
966 EXP_DARWIN_LINK
*buffer
;
968 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
969 buffer
->dbh
.cbSize
= sizeof *buffer
;
970 buffer
->dbh
.dwSignature
= magic
;
971 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
972 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
977 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
979 EXP_DARWIN_LINK
*buffer
;
984 buffer
= shelllink_build_darwinid( string
, magic
);
986 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
989 /************************************************************************
990 * IPersistStream_Save (IPersistStream)
992 * FIXME: makes assumptions about byte order
994 static HRESULT WINAPI
IPersistStream_fnSave(
995 IPersistStream
* iface
,
1004 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1006 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1008 memset(&header
, 0, sizeof(header
));
1009 header
.dwSize
= sizeof(header
);
1010 header
.fStartup
= This
->iShowCmd
;
1011 header
.MagicGuid
= CLSID_ShellLink
;
1013 header
.wHotKey
= This
->wHotKey
;
1014 header
.nIcon
= This
->iIcoNdx
;
1015 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1017 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1019 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1020 if( This
->sDescription
)
1021 header
.dwFlags
|= SLDF_HAS_NAME
;
1022 if( This
->sWorkDir
)
1023 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1025 header
.dwFlags
|= SLDF_HAS_ARGS
;
1026 if( This
->sIcoPath
)
1027 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1028 if( This
->sProduct
)
1029 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1030 if( This
->sComponent
)
1031 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1033 SystemTimeToFileTime ( &This
->CreationTime
, &header
.CreationTime
);
1034 SystemTimeToFileTime ( &This
->AccessTime
, &header
.AccessTime
);
1035 SystemTimeToFileTime ( &This
->WriteTime
, &header
.WriteTime
);
1037 /* write the Shortcut header */
1038 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1041 ERR("Write failed at %d\n",__LINE__
);
1045 TRACE("Writing pidl\n");
1047 /* write the PIDL to the shortcut */
1050 r
= ILSaveToStream( stm
, This
->pPidl
);
1053 ERR("Failed to write PIDL at %d\n",__LINE__
);
1059 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1061 if( This
->sDescription
)
1062 r
= Stream_WriteString( stm
, This
->sDescription
);
1064 if( This
->sPathRel
)
1065 r
= Stream_WriteString( stm
, This
->sPathRel
);
1067 if( This
->sWorkDir
)
1068 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1071 r
= Stream_WriteString( stm
, This
->sArgs
);
1073 if( This
->sIcoPath
)
1074 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1076 if( This
->sProduct
)
1077 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1079 if( This
->sComponent
)
1080 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1082 /* the last field is a single zero dword */
1084 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1089 /************************************************************************
1090 * IPersistStream_GetSizeMax (IPersistStream)
1092 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1093 IPersistStream
* iface
,
1094 ULARGE_INTEGER
* pcbSize
)
1096 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1098 TRACE("(%p)\n", This
);
1103 static const IPersistStreamVtbl psvt
=
1105 IPersistStream_fnQueryInterface
,
1106 IPersistStream_fnAddRef
,
1107 IPersistStream_fnRelease
,
1108 IPersistStream_fnGetClassID
,
1109 IPersistStream_fnIsDirty
,
1110 IPersistStream_fnLoad
,
1111 IPersistStream_fnSave
,
1112 IPersistStream_fnGetSizeMax
1115 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1117 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1122 /**************************************************************************
1123 * ShellLink_UpdatePath
1124 * update absolute path in sPath using relative path in sPathRel
1126 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1128 if (!path
|| !psPath
)
1129 return E_INVALIDARG
;
1131 if (!*psPath
&& sPathRel
) {
1132 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1133 LPWSTR final
= NULL
;
1135 /* first try if [directory of link file] + [relative path] finds an existing file */
1137 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1140 lstrcpyW(final
, sPathRel
);
1144 if (SHELL_ExistsFileW(buffer
)) {
1145 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1146 lstrcpyW(abs_path
, buffer
);
1148 /* try if [working directory] + [relative path] finds an existing file */
1150 lstrcpyW(buffer
, sWorkDir
);
1151 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1153 if (SHELL_ExistsFileW(buffer
))
1154 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1155 lstrcpyW(abs_path
, buffer
);
1159 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1161 lstrcpyW(abs_path
, sPathRel
);
1163 *psPath
= wcsdup(abs_path
);
1165 return E_OUTOFMEMORY
;
1171 /**************************************************************************
1172 * IShellLink_ConstructFromFile
1174 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1175 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1179 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1181 if (SUCCEEDED(hr
)) {
1186 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1188 if (SUCCEEDED(hr
)) {
1189 WCHAR path
[MAX_PATH
];
1191 if (SHGetPathFromIDListW(pidl
, path
))
1192 hr
= IPersistFile_Load(ppf
, path
, 0);
1197 *ppv
= (IUnknown
*)psl
;
1199 IPersistFile_Release(ppf
);
1203 IShellLinkW_Release(psl
);
1209 /**************************************************************************
1210 * IShellLinkA_QueryInterface
1212 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1214 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1215 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1218 /******************************************************************************
1219 * IShellLinkA_AddRef
1221 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1223 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1224 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1227 /******************************************************************************
1228 * IShellLinkA_Release
1230 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1232 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1233 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1236 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1237 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1239 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1242 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1243 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1245 if (This
->sComponent
|| This
->sProduct
)
1250 if (This
->sPath
&& This
->sPath
[0])
1251 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1252 pszFile
, cchMaxPath
, NULL
, NULL
);
1258 memset(pfd
, 0, sizeof(*pfd
));
1262 char path
[MAX_PATH
];
1263 WIN32_FILE_ATTRIBUTE_DATA fad
;
1265 WideCharToMultiByte(CP_ACP
, 0, This
->sPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
1267 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1269 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1270 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1271 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1272 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1273 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1274 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1277 lstrcpyA(pfd
->cFileName
, PathFindFileNameA(path
));
1279 if (GetShortPathNameA(path
, path
, MAX_PATH
))
1281 lstrcpyA(pfd
->cAlternateFileName
, PathFindFileNameA(path
));
1285 TRACE("attr 0x%08lx size 0x%08lx%08lx name %s shortname %s\n", pfd
->dwFileAttributes
,
1286 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_a(pfd
->cFileName
),
1287 wine_dbgstr_a(pfd
->cAlternateFileName
));
1293 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1295 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1296 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1299 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1301 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1302 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1305 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1308 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1310 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1314 if( This
->sDescription
)
1315 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1316 pszName
, cchMaxName
, NULL
, NULL
);
1321 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1323 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1327 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1331 descrW
= strdupAtoW(pszName
);
1332 if (!descrW
) return E_OUTOFMEMORY
;
1337 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1343 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1346 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1348 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1352 if( This
->sWorkDir
)
1353 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1354 pszDir
, cchMaxPath
, NULL
, NULL
);
1359 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1361 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1365 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1367 dirW
= strdupAtoW(pszDir
);
1368 if (!dirW
) return E_OUTOFMEMORY
;
1370 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1376 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1378 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1380 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1385 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1386 pszArgs
, cchMaxPath
, NULL
, NULL
);
1391 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1393 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1397 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1401 argsW
= strdupAtoW(pszArgs
);
1402 if (!argsW
) return E_OUTOFMEMORY
;
1407 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1413 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1415 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1416 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1419 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1421 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1422 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1425 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1427 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1428 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1431 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1433 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1434 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1437 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1438 INT cchIconPath
, INT
*piIcon
)
1440 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1442 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1444 *piIcon
= This
->iIcoNdx
;
1447 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1454 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR path
, INT icon
)
1456 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1457 WCHAR
*pathW
= NULL
;
1460 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_a(path
), icon
);
1464 pathW
= strdupAtoW(path
);
1466 return E_OUTOFMEMORY
;
1469 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, path
? pathW
: NULL
, icon
);
1475 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1478 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1482 TRACE("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1484 pathW
= strdupAtoW(pszPathRel
);
1485 if (!pathW
) return E_OUTOFMEMORY
;
1487 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1493 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1495 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1497 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1499 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1502 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1504 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1508 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1510 if (!pszFile
) return E_INVALIDARG
;
1512 str
= strdupAtoW(pszFile
);
1513 if (!str
) return E_OUTOFMEMORY
;
1515 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1521 /**************************************************************************
1522 * IShellLink Implementation
1525 static const IShellLinkAVtbl slvt
=
1527 IShellLinkA_fnQueryInterface
,
1528 IShellLinkA_fnAddRef
,
1529 IShellLinkA_fnRelease
,
1530 IShellLinkA_fnGetPath
,
1531 IShellLinkA_fnGetIDList
,
1532 IShellLinkA_fnSetIDList
,
1533 IShellLinkA_fnGetDescription
,
1534 IShellLinkA_fnSetDescription
,
1535 IShellLinkA_fnGetWorkingDirectory
,
1536 IShellLinkA_fnSetWorkingDirectory
,
1537 IShellLinkA_fnGetArguments
,
1538 IShellLinkA_fnSetArguments
,
1539 IShellLinkA_fnGetHotkey
,
1540 IShellLinkA_fnSetHotkey
,
1541 IShellLinkA_fnGetShowCmd
,
1542 IShellLinkA_fnSetShowCmd
,
1543 IShellLinkA_fnGetIconLocation
,
1544 IShellLinkA_fnSetIconLocation
,
1545 IShellLinkA_fnSetRelativePath
,
1546 IShellLinkA_fnResolve
,
1547 IShellLinkA_fnSetPath
1551 /**************************************************************************
1552 * IShellLinkW_fnQueryInterface
1554 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1555 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1557 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1559 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1563 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1565 *ppvObj
= &This
->IShellLinkA_iface
;
1567 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1569 *ppvObj
= &This
->IShellLinkW_iface
;
1571 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1573 *ppvObj
= &This
->IPersistFile_iface
;
1575 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1577 *ppvObj
= &This
->IPersistStream_iface
;
1579 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1581 *ppvObj
= &This
->IShellLinkDataList_iface
;
1583 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1585 *ppvObj
= &This
->IShellExtInit_iface
;
1587 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1589 *ppvObj
= &This
->IContextMenu_iface
;
1591 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1593 *ppvObj
= &This
->IObjectWithSite_iface
;
1595 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1597 *ppvObj
= &This
->IPropertyStore_iface
;
1602 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1603 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1606 ERR("-- Interface: E_NOINTERFACE\n");
1607 return E_NOINTERFACE
;
1610 /******************************************************************************
1611 * IShellLinkW_fnAddRef
1613 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1615 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1616 ULONG ref
= InterlockedIncrement(&This
->ref
);
1618 TRACE("(%p)->(count=%lu)\n", This
, ref
- 1);
1623 /******************************************************************************
1624 * IShellLinkW_fnRelease
1626 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1628 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1629 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1631 TRACE("(%p)->(count=%lu)\n", This
, refCount
+ 1);
1636 TRACE("-- destroying IShellLink(%p)\n",This
);
1638 free(This
->sIcoPath
);
1640 free(This
->sWorkDir
);
1641 free(This
->sDescription
);
1643 free(This
->sPathRel
);
1644 free(This
->sProduct
);
1645 free(This
->sComponent
);
1646 free(This
->filepath
);
1649 IUnknown_Release( This
->site
);
1652 ILFree(This
->pPidl
);
1659 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1661 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1664 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1665 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1667 if (This
->sComponent
|| This
->sProduct
)
1673 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1679 memset(pfd
, 0, sizeof(*pfd
));
1683 WCHAR path
[MAX_PATH
];
1684 WIN32_FILE_ATTRIBUTE_DATA fad
;
1686 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1688 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1689 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1690 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1691 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1692 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1693 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1696 lstrcpyW(pfd
->cFileName
, PathFindFileNameW(This
->sPath
));
1698 if (GetShortPathNameW(This
->sPath
, path
, MAX_PATH
))
1700 lstrcpyW(pfd
->cAlternateFileName
, PathFindFileNameW(path
));
1704 TRACE("attr 0x%08lx size 0x%08lx%08lx name %s shortname %s\n", pfd
->dwFileAttributes
,
1705 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_w(pfd
->cFileName
),
1706 wine_dbgstr_w(pfd
->cAlternateFileName
));
1712 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1714 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1716 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1723 *ppidl
= ILClone(This
->pPidl
);
1727 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1729 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1730 WCHAR path
[MAX_PATH
];
1732 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1735 ILFree( This
->pPidl
);
1736 This
->pPidl
= ILClone( pidl
);
1740 free( This
->sPath
);
1743 if ( SHGetPathFromIDListW( pidl
, path
) )
1745 This
->sPath
= wcsdup(path
);
1747 return E_OUTOFMEMORY
;
1750 This
->bDirty
= TRUE
;
1755 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1757 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1759 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1762 if( This
->sDescription
)
1763 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1768 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1770 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1772 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1774 free(This
->sDescription
);
1777 This
->sDescription
= wcsdup(pszName
);
1778 if ( !This
->sDescription
)
1779 return E_OUTOFMEMORY
;
1782 This
->sDescription
= NULL
;
1783 This
->bDirty
= TRUE
;
1788 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1790 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1792 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1796 if( This
->sWorkDir
)
1797 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1802 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1804 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1806 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1808 free(This
->sWorkDir
);
1809 This
->sWorkDir
= wcsdup(pszDir
);
1810 if ( !This
->sWorkDir
)
1811 return E_OUTOFMEMORY
;
1812 This
->bDirty
= TRUE
;
1817 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1819 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1821 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1826 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1831 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1833 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1835 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1840 This
->sArgs
= wcsdup(pszArgs
);
1842 return E_OUTOFMEMORY
;
1844 else This
->sArgs
= NULL
;
1846 This
->bDirty
= TRUE
;
1851 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1853 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1855 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1857 *pwHotkey
=This
->wHotKey
;
1862 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1864 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1866 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1868 This
->wHotKey
= wHotkey
;
1869 This
->bDirty
= TRUE
;
1874 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1876 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1878 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1880 *piShowCmd
= This
->iShowCmd
;
1885 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1887 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1889 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1891 This
->iShowCmd
= iShowCmd
;
1892 This
->bDirty
= TRUE
;
1897 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1899 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1901 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1903 *piIcon
= This
->iIcoNdx
;
1906 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1913 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, const WCHAR
*path
, INT icon
)
1915 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1917 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_w(path
), icon
);
1919 free(This
->sIcoPath
);
1922 This
->sIcoPath
= wcsdup(path
);
1923 if (!This
->sIcoPath
)
1924 return E_OUTOFMEMORY
;
1927 This
->sIcoPath
= NULL
;
1928 This
->iIcoNdx
= icon
;
1929 This
->bDirty
= TRUE
;
1934 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1936 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1938 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1940 free(This
->sPathRel
);
1941 This
->sPathRel
= wcsdup(pszPathRel
);
1942 if ( !This
->sPathRel
)
1943 return E_OUTOFMEMORY
;
1944 This
->bDirty
= TRUE
;
1946 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1949 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1954 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1956 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1958 /*FIXME: use IResolveShellLink interface */
1960 if (!This
->sPath
&& This
->pPidl
) {
1961 WCHAR buffer
[MAX_PATH
];
1963 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1965 if (bSuccess
&& *buffer
) {
1966 This
->sPath
= wcsdup(buffer
);
1968 return E_OUTOFMEMORY
;
1970 This
->bDirty
= TRUE
;
1972 hr
= S_OK
; /* don't report an error occurred while just caching information */
1975 if (!This
->sIcoPath
&& This
->sPath
) {
1976 This
->sIcoPath
= wcsdup(This
->sPath
);
1977 if (!This
->sIcoPath
)
1978 return E_OUTOFMEMORY
;
1982 This
->bDirty
= TRUE
;
1988 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
1997 p
= wcschr( str
, ':' );
2001 ret
= malloc(sizeof(WCHAR
) * (len
+ 1));
2004 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2009 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2011 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2019 /* each segment must start with two colons */
2020 if( str
[0] != ':' || str
[1] != ':' )
2023 /* the last segment is just two colons */
2028 /* there must be a colon straight after a guid */
2029 p
= wcschr( str
, ':' );
2036 /* get the guid, and check it's validly formatted */
2037 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2039 r
= CLSIDFromString( szGuid
, &guid
);
2044 /* match it up to a guid that we care about */
2045 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2047 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2052 /* skip to the next field */
2053 str
= wcschr( str
, ':' );
2058 /* we have to have a component for an advertised shortcut */
2062 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2063 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2065 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2066 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2071 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2073 const int label_sz
= ARRAY_SIZE(volume
->label
);
2074 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2077 volume
->type
= GetDriveTypeW(drive
);
2078 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2079 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2080 TRACE("r = %d type %ld serial %08lx name %s\n", r
,
2081 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2085 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2087 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2088 WCHAR buffer
[MAX_PATH
];
2089 LPWSTR fname
, unquoted
= NULL
;
2093 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2095 if (!pszFile
) return E_INVALIDARG
;
2097 /* quotes at the ends of the string are stripped */
2098 len
= lstrlenW(pszFile
);
2099 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2101 unquoted
= wcsdup(pszFile
);
2102 PathUnquoteSpacesW(unquoted
);
2106 /* any other quote marks are invalid */
2107 if (wcschr(pszFile
, '"'))
2116 free(This
->sComponent
);
2117 This
->sComponent
= NULL
;
2120 ILFree(This
->pPidl
);
2123 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2125 if (*pszFile
== '\0')
2127 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2132 else if(!PathFileExistsW(buffer
) &&
2133 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2136 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2137 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2139 This
->sPath
= wcsdup(buffer
);
2143 return E_OUTOFMEMORY
;
2146 This
->bDirty
= TRUE
;
2152 /**************************************************************************
2153 * IShellLinkW Implementation
2156 static const IShellLinkWVtbl slvtw
=
2158 IShellLinkW_fnQueryInterface
,
2159 IShellLinkW_fnAddRef
,
2160 IShellLinkW_fnRelease
,
2161 IShellLinkW_fnGetPath
,
2162 IShellLinkW_fnGetIDList
,
2163 IShellLinkW_fnSetIDList
,
2164 IShellLinkW_fnGetDescription
,
2165 IShellLinkW_fnSetDescription
,
2166 IShellLinkW_fnGetWorkingDirectory
,
2167 IShellLinkW_fnSetWorkingDirectory
,
2168 IShellLinkW_fnGetArguments
,
2169 IShellLinkW_fnSetArguments
,
2170 IShellLinkW_fnGetHotkey
,
2171 IShellLinkW_fnSetHotkey
,
2172 IShellLinkW_fnGetShowCmd
,
2173 IShellLinkW_fnSetShowCmd
,
2174 IShellLinkW_fnGetIconLocation
,
2175 IShellLinkW_fnSetIconLocation
,
2176 IShellLinkW_fnSetRelativePath
,
2177 IShellLinkW_fnResolve
,
2178 IShellLinkW_fnSetPath
2181 static HRESULT WINAPI
2182 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2184 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2185 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2189 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2191 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2192 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2196 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2198 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2199 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2202 static HRESULT WINAPI
2203 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2205 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2209 static HRESULT WINAPI
2210 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2212 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2213 LPVOID block
= NULL
;
2216 TRACE("%p %08lx %p\n", iface
, dwSig
, ppDataBlock
);
2220 case EXP_DARWIN_ID_SIG
:
2221 if (!This
->sComponent
)
2223 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2226 case EXP_SZ_LINK_SIG
:
2227 case NT_CONSOLE_PROPS_SIG
:
2228 case NT_FE_CONSOLE_PROPS_SIG
:
2229 case EXP_SPECIAL_FOLDER_SIG
:
2230 case EXP_SZ_ICON_SIG
:
2231 FIXME("valid but unhandled datablock %08lx\n", dwSig
);
2234 ERR("unknown datablock %08lx\n", dwSig
);
2236 *ppDataBlock
= block
;
2240 static HRESULT WINAPI
2241 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2243 FIXME("(%p)->(%lu): stub\n", iface
, dwSig
);
2247 static HRESULT WINAPI
2248 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2250 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2253 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2255 /* FIXME: add more */
2257 flags
|= SLDF_HAS_ARGS
;
2258 if (This
->sComponent
)
2259 flags
|= SLDF_HAS_DARWINID
;
2261 flags
|= SLDF_HAS_ICONLOCATION
;
2263 flags
|= SLDF_HAS_LOGO3ID
;
2265 flags
|= SLDF_HAS_ID_LIST
;
2272 static HRESULT WINAPI
2273 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2275 FIXME("(%p)->(%lu): stub\n", iface
, dwFlags
);
2279 static const IShellLinkDataListVtbl dlvt
=
2281 ShellLink_DataList_QueryInterface
,
2282 ShellLink_DataList_AddRef
,
2283 ShellLink_DataList_Release
,
2284 ShellLink_AddDataBlock
,
2285 ShellLink_CopyDataBlock
,
2286 ShellLink_RemoveDataBlock
,
2291 static HRESULT WINAPI
2292 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2294 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2295 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2299 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2301 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2302 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2306 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2308 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2309 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2312 /**************************************************************************
2313 * ShellLink implementation of IShellExtInit::Initialize()
2315 * Loads the shelllink from the dataobject the shell is pointing to.
2317 static HRESULT WINAPI
2318 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2319 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2321 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2327 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2332 format
.cfFormat
= CF_HDROP
;
2334 format
.dwAspect
= DVASPECT_CONTENT
;
2336 format
.tymed
= TYMED_HGLOBAL
;
2338 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2341 count
= DragQueryFileW( stgm
.hGlobal
, -1, NULL
, 0 );
2346 count
= DragQueryFileW( stgm
.hGlobal
, 0, NULL
, 0 );
2348 path
= malloc( count
* sizeof(WCHAR
) );
2351 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2353 count
= DragQueryFileW( stgm
.hGlobal
, 0, path
, count
);
2354 r
= IPersistFile_Load( pf
, path
, 0 );
2358 ReleaseStgMedium( &stgm
);
2363 static const IShellExtInitVtbl eivt
=
2365 ShellLink_ExtInit_QueryInterface
,
2366 ShellLink_ExtInit_AddRef
,
2367 ShellLink_ExtInit_Release
,
2368 ShellLink_ExtInit_Initialize
2371 static HRESULT WINAPI
2372 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2374 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2375 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2379 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2381 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2382 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2386 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2388 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2389 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2392 static HRESULT WINAPI
2393 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2394 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2396 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2400 TRACE("%p %p %u %u %u %u\n", This
,
2401 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2404 return E_INVALIDARG
;
2406 memset( &mii
, 0, sizeof mii
);
2407 mii
.cbSize
= sizeof mii
;
2408 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2409 mii
.dwTypeData
= (LPWSTR
)L
"Open";
2410 mii
.cch
= lstrlenW( mii
.dwTypeData
);
2411 mii
.wID
= idCmdFirst
+ id
++;
2412 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2413 mii
.fType
= MFT_STRING
;
2414 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2418 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2422 shelllink_get_msi_component_path( LPWSTR component
)
2427 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2428 if (r
!= ERROR_SUCCESS
)
2432 path
= malloc( sz
* sizeof(WCHAR
) );
2433 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2434 if (r
!= ERROR_SUCCESS
)
2440 TRACE("returning %s\n", debugstr_w( path
) );
2445 static HRESULT WINAPI
2446 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2448 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2449 SHELLEXECUTEINFOW sei
;
2450 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2455 TRACE("%p %p\n", This
, lpici
);
2457 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2458 return E_INVALIDARG
;
2460 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2462 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2463 return E_INVALIDARG
;
2466 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2470 if ( This
->sComponent
)
2472 path
= shelllink_get_msi_component_path( This
->sComponent
);
2477 path
= wcsdup( This
->sPath
);
2479 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2480 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2482 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2486 len
+= lstrlenW( This
->sArgs
);
2487 if ( iciex
->lpParametersW
)
2488 len
+= lstrlenW( iciex
->lpParametersW
);
2490 args
= malloc( len
* sizeof(WCHAR
) );
2493 lstrcatW( args
, This
->sArgs
);
2494 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2496 lstrcatW( args
, L
" " );
2497 lstrcatW( args
, iciex
->lpParametersW
);
2501 memset( &sei
, 0, sizeof sei
);
2502 sei
.cbSize
= sizeof sei
;
2503 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2505 sei
.nShow
= This
->iShowCmd
;
2506 sei
.lpIDList
= This
->pPidl
;
2507 sei
.lpDirectory
= This
->sWorkDir
;
2508 sei
.lpParameters
= args
;
2509 sei
.lpVerb
= L
"Open";
2511 if( ShellExecuteExW( &sei
) )
2522 static HRESULT WINAPI
2523 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2524 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2526 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2528 FIXME("(%p)->(%Iu %u %p %p %u): stub\n", This
,
2529 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2534 static const IContextMenuVtbl cmvt
=
2536 ShellLink_ContextMenu_QueryInterface
,
2537 ShellLink_ContextMenu_AddRef
,
2538 ShellLink_ContextMenu_Release
,
2539 ShellLink_QueryContextMenu
,
2540 ShellLink_InvokeCommand
,
2541 ShellLink_GetCommandString
2544 static HRESULT WINAPI
2545 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2547 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2548 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2552 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2554 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2555 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2559 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2561 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2562 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2565 static HRESULT WINAPI
2566 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2568 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2570 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2574 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2577 static HRESULT WINAPI
2578 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2580 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2582 TRACE("%p %p\n", iface
, punk
);
2585 IUnknown_AddRef( punk
);
2588 IUnknown_Release( This
->site
);
2595 static const IObjectWithSiteVtbl owsvt
=
2597 ShellLink_ObjectWithSite_QueryInterface
,
2598 ShellLink_ObjectWithSite_AddRef
,
2599 ShellLink_ObjectWithSite_Release
,
2604 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2606 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2607 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2610 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2612 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2613 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2616 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2618 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2619 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2622 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2624 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2625 FIXME("(%p)->(%p): stub\n", This
, props
);
2629 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2631 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2632 FIXME("(%p)->(%ld %p): stub\n", This
, propid
, key
);
2636 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2638 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2639 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2643 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2645 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2646 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2650 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2652 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2653 FIXME("(%p): stub\n", This
);
2657 static const IPropertyStoreVtbl propertystorevtbl
= {
2658 propertystore_QueryInterface
,
2659 propertystore_AddRef
,
2660 propertystore_Release
,
2661 propertystore_GetCount
,
2662 propertystore_GetAt
,
2663 propertystore_GetValue
,
2664 propertystore_SetValue
,
2665 propertystore_Commit
2668 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2670 IShellLinkImpl
* sl
;
2673 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2678 return CLASS_E_NOAGGREGATION
;
2680 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2682 return E_OUTOFMEMORY
;
2685 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2686 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2687 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2688 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2689 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2690 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2691 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2692 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2693 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2694 sl
->iShowCmd
= SW_SHOWNORMAL
;
2698 sl
->filepath
= NULL
;
2700 TRACE("(%p)\n", sl
);
2702 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2703 IShellLinkW_Release( &sl
->IShellLinkW_iface
);