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
= malloc( (lstrlenW(buffer
.szwDarwinID
) + 1) * sizeof(WCHAR
) );
709 lstrcpyW( *str
, buffer
.szwDarwinID
);
714 /************************************************************************
715 * IPersistStream_Load (IPersistStream)
717 static HRESULT WINAPI
IPersistStream_fnLoad(
718 IPersistStream
* iface
,
727 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
729 TRACE("%p %p\n", This
, stm
);
732 return STG_E_INVALIDPOINTER
;
735 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
739 if( dwBytesRead
!= sizeof(hdr
))
741 if( hdr
.dwSize
!= sizeof(hdr
))
743 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
746 /* free all the old stuff */
749 memset( &This
->volume
, 0, sizeof This
->volume
);
752 free(This
->sDescription
);
753 This
->sDescription
= NULL
;
754 free(This
->sPathRel
);
755 This
->sPathRel
= NULL
;
756 free(This
->sWorkDir
);
757 This
->sWorkDir
= NULL
;
760 free(This
->sIcoPath
);
761 This
->sIcoPath
= NULL
;
762 free(This
->sProduct
);
763 This
->sProduct
= NULL
;
764 free(This
->sComponent
);
765 This
->sComponent
= NULL
;
767 This
->wHotKey
= hdr
.wHotKey
;
768 This
->iIcoNdx
= hdr
.nIcon
;
769 FileTimeToSystemTime (&hdr
.CreationTime
, &This
->CreationTime
);
770 FileTimeToSystemTime (&hdr
.AccessTime
, &This
->AccessTime
);
771 FileTimeToSystemTime (&hdr
.WriteTime
, &This
->WriteTime
);
774 WCHAR sTemp
[MAX_PATH
];
775 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->CreationTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
776 TRACE("-- CreationTime: %s\n", debugstr_w(sTemp
) );
777 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->AccessTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
778 TRACE("-- AccessTime: %s\n", debugstr_w(sTemp
) );
779 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->WriteTime
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
780 TRACE("-- WriteTime: %s\n", debugstr_w(sTemp
) );
783 /* load all the new stuff */
784 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
786 r
= ILLoadFromStream( stm
, &This
->pPidl
);
792 /* load the location information */
793 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
794 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
798 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
799 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
801 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
802 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
807 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
809 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
810 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
815 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
817 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
818 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
823 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
825 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
826 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
831 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
833 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
834 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
839 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
841 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
842 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
847 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
849 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
850 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
855 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
856 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
858 /* Some lnk files have extra data blocks starting with a
859 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
860 * one with a 0xa0000003 signature. However these don't seem to matter
863 WARN("Last word was not zero\n");
875 /************************************************************************
878 * Helper function for IPersistStream_Save. Writes a unicode string
879 * with terminating nul byte to a stream, preceded by the its length.
881 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
883 USHORT len
= lstrlenW( str
) + 1;
887 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
891 len
*= sizeof(WCHAR
);
893 r
= IStream_Write( stm
, str
, len
, &count
);
900 /************************************************************************
901 * Stream_WriteLocationInfo
903 * Writes the location info to a stream
905 * FIXME: One day we might want to write the network volume information
906 * and the final path.
907 * Figure out how Windows deals with unicode paths here.
909 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
910 volume_info
*volume
)
912 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
913 LOCAL_VOLUME_INFO
*vol
;
915 LPSTR szLabel
, szPath
, szFinalPath
;
919 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
921 /* figure out the size of everything */
922 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
923 NULL
, 0, NULL
, NULL
);
924 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
925 NULL
, 0, NULL
, NULL
);
926 volume_info_size
= sizeof *vol
+ label_size
;
928 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
930 /* create pointers to everything */
931 loc
= calloc(1, total_size
);
932 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
933 szLabel
= (LPSTR
) &vol
[1];
934 szPath
= &szLabel
[label_size
];
935 szFinalPath
= &szPath
[path_size
];
937 /* fill in the location information header */
938 loc
->dwTotalSize
= total_size
;
939 loc
->dwHeaderSize
= sizeof (*loc
);
941 loc
->dwVolTableOfs
= sizeof (*loc
);
942 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
943 loc
->dwNetworkVolTableOfs
= 0;
944 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
946 /* fill in the volume information */
947 vol
->dwSize
= volume_info_size
;
948 vol
->dwType
= volume
->type
;
949 vol
->dwVolSerial
= volume
->serial
;
950 vol
->dwVolLabelOfs
= sizeof (*vol
);
952 /* copy in the strings */
953 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
954 szLabel
, label_size
, NULL
, NULL
);
955 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
956 szPath
, path_size
, NULL
, NULL
);
959 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
965 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
967 EXP_DARWIN_LINK
*buffer
;
969 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
970 buffer
->dbh
.cbSize
= sizeof *buffer
;
971 buffer
->dbh
.dwSignature
= magic
;
972 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
973 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
978 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
980 EXP_DARWIN_LINK
*buffer
;
985 buffer
= shelllink_build_darwinid( string
, magic
);
987 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
990 /************************************************************************
991 * IPersistStream_Save (IPersistStream)
993 * FIXME: makes assumptions about byte order
995 static HRESULT WINAPI
IPersistStream_fnSave(
996 IPersistStream
* iface
,
1005 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1007 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1009 memset(&header
, 0, sizeof(header
));
1010 header
.dwSize
= sizeof(header
);
1011 header
.fStartup
= This
->iShowCmd
;
1012 header
.MagicGuid
= CLSID_ShellLink
;
1014 header
.wHotKey
= This
->wHotKey
;
1015 header
.nIcon
= This
->iIcoNdx
;
1016 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1018 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1020 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1021 if( This
->sDescription
)
1022 header
.dwFlags
|= SLDF_HAS_NAME
;
1023 if( This
->sWorkDir
)
1024 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1026 header
.dwFlags
|= SLDF_HAS_ARGS
;
1027 if( This
->sIcoPath
)
1028 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1029 if( This
->sProduct
)
1030 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1031 if( This
->sComponent
)
1032 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1034 SystemTimeToFileTime ( &This
->CreationTime
, &header
.CreationTime
);
1035 SystemTimeToFileTime ( &This
->AccessTime
, &header
.AccessTime
);
1036 SystemTimeToFileTime ( &This
->WriteTime
, &header
.WriteTime
);
1038 /* write the Shortcut header */
1039 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1042 ERR("Write failed at %d\n",__LINE__
);
1046 TRACE("Writing pidl\n");
1048 /* write the PIDL to the shortcut */
1051 r
= ILSaveToStream( stm
, This
->pPidl
);
1054 ERR("Failed to write PIDL at %d\n",__LINE__
);
1060 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1062 if( This
->sDescription
)
1063 r
= Stream_WriteString( stm
, This
->sDescription
);
1065 if( This
->sPathRel
)
1066 r
= Stream_WriteString( stm
, This
->sPathRel
);
1068 if( This
->sWorkDir
)
1069 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1072 r
= Stream_WriteString( stm
, This
->sArgs
);
1074 if( This
->sIcoPath
)
1075 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1077 if( This
->sProduct
)
1078 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1080 if( This
->sComponent
)
1081 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1083 /* the last field is a single zero dword */
1085 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1090 /************************************************************************
1091 * IPersistStream_GetSizeMax (IPersistStream)
1093 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1094 IPersistStream
* iface
,
1095 ULARGE_INTEGER
* pcbSize
)
1097 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1099 TRACE("(%p)\n", This
);
1104 static const IPersistStreamVtbl psvt
=
1106 IPersistStream_fnQueryInterface
,
1107 IPersistStream_fnAddRef
,
1108 IPersistStream_fnRelease
,
1109 IPersistStream_fnGetClassID
,
1110 IPersistStream_fnIsDirty
,
1111 IPersistStream_fnLoad
,
1112 IPersistStream_fnSave
,
1113 IPersistStream_fnGetSizeMax
1116 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1118 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1123 /**************************************************************************
1124 * ShellLink_UpdatePath
1125 * update absolute path in sPath using relative path in sPathRel
1127 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1129 if (!path
|| !psPath
)
1130 return E_INVALIDARG
;
1132 if (!*psPath
&& sPathRel
) {
1133 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1134 LPWSTR final
= NULL
;
1136 /* first try if [directory of link file] + [relative path] finds an existing file */
1138 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1141 lstrcpyW(final
, sPathRel
);
1145 if (SHELL_ExistsFileW(buffer
)) {
1146 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1147 lstrcpyW(abs_path
, buffer
);
1149 /* try if [working directory] + [relative path] finds an existing file */
1151 lstrcpyW(buffer
, sWorkDir
);
1152 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1154 if (SHELL_ExistsFileW(buffer
))
1155 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1156 lstrcpyW(abs_path
, buffer
);
1160 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1162 lstrcpyW(abs_path
, sPathRel
);
1164 *psPath
= malloc((lstrlenW(abs_path
) + 1) * sizeof(WCHAR
));
1166 return E_OUTOFMEMORY
;
1168 lstrcpyW(*psPath
, abs_path
);
1174 /**************************************************************************
1175 * IShellLink_ConstructFromFile
1177 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1178 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1182 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1184 if (SUCCEEDED(hr
)) {
1189 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1191 if (SUCCEEDED(hr
)) {
1192 WCHAR path
[MAX_PATH
];
1194 if (SHGetPathFromIDListW(pidl
, path
))
1195 hr
= IPersistFile_Load(ppf
, path
, 0);
1200 *ppv
= (IUnknown
*)psl
;
1202 IPersistFile_Release(ppf
);
1206 IShellLinkW_Release(psl
);
1212 /**************************************************************************
1213 * IShellLinkA_QueryInterface
1215 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1217 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1218 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1221 /******************************************************************************
1222 * IShellLinkA_AddRef
1224 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1226 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1227 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1230 /******************************************************************************
1231 * IShellLinkA_Release
1233 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1235 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1236 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1239 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1240 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1242 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1245 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1246 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1248 if (This
->sComponent
|| This
->sProduct
)
1253 if (This
->sPath
&& This
->sPath
[0])
1254 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1255 pszFile
, cchMaxPath
, NULL
, NULL
);
1261 memset(pfd
, 0, sizeof(*pfd
));
1265 char path
[MAX_PATH
];
1266 WIN32_FILE_ATTRIBUTE_DATA fad
;
1268 WideCharToMultiByte(CP_ACP
, 0, This
->sPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
1270 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1272 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1273 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1274 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1275 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1276 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1277 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1280 lstrcpyA(pfd
->cFileName
, PathFindFileNameA(path
));
1282 if (GetShortPathNameA(path
, path
, MAX_PATH
))
1284 lstrcpyA(pfd
->cAlternateFileName
, PathFindFileNameA(path
));
1288 TRACE("attr 0x%08lx size 0x%08lx%08lx name %s shortname %s\n", pfd
->dwFileAttributes
,
1289 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_a(pfd
->cFileName
),
1290 wine_dbgstr_a(pfd
->cAlternateFileName
));
1296 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1298 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1299 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1302 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1304 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1305 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1308 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1311 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1313 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1317 if( This
->sDescription
)
1318 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1319 pszName
, cchMaxName
, NULL
, NULL
);
1324 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1326 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1330 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1334 descrW
= strdupAtoW(pszName
);
1335 if (!descrW
) return E_OUTOFMEMORY
;
1340 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1346 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1349 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1351 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1355 if( This
->sWorkDir
)
1356 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1357 pszDir
, cchMaxPath
, NULL
, NULL
);
1362 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1364 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1368 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1370 dirW
= strdupAtoW(pszDir
);
1371 if (!dirW
) return E_OUTOFMEMORY
;
1373 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1379 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1381 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1383 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1388 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1389 pszArgs
, cchMaxPath
, NULL
, NULL
);
1394 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1396 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1400 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1404 argsW
= strdupAtoW(pszArgs
);
1405 if (!argsW
) return E_OUTOFMEMORY
;
1410 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1416 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1418 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1419 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1422 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1424 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1425 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1428 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1430 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1431 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1434 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1436 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1437 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1440 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1441 INT cchIconPath
, INT
*piIcon
)
1443 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1445 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1447 *piIcon
= This
->iIcoNdx
;
1450 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1457 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR path
, INT icon
)
1459 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1460 WCHAR
*pathW
= NULL
;
1463 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_a(path
), icon
);
1467 pathW
= strdupAtoW(path
);
1469 return E_OUTOFMEMORY
;
1472 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, path
? pathW
: NULL
, icon
);
1478 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1481 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1485 TRACE("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1487 pathW
= strdupAtoW(pszPathRel
);
1488 if (!pathW
) return E_OUTOFMEMORY
;
1490 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1496 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1498 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1500 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1502 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1505 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1507 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1511 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1513 if (!pszFile
) return E_INVALIDARG
;
1515 str
= strdupAtoW(pszFile
);
1516 if (!str
) return E_OUTOFMEMORY
;
1518 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1524 /**************************************************************************
1525 * IShellLink Implementation
1528 static const IShellLinkAVtbl slvt
=
1530 IShellLinkA_fnQueryInterface
,
1531 IShellLinkA_fnAddRef
,
1532 IShellLinkA_fnRelease
,
1533 IShellLinkA_fnGetPath
,
1534 IShellLinkA_fnGetIDList
,
1535 IShellLinkA_fnSetIDList
,
1536 IShellLinkA_fnGetDescription
,
1537 IShellLinkA_fnSetDescription
,
1538 IShellLinkA_fnGetWorkingDirectory
,
1539 IShellLinkA_fnSetWorkingDirectory
,
1540 IShellLinkA_fnGetArguments
,
1541 IShellLinkA_fnSetArguments
,
1542 IShellLinkA_fnGetHotkey
,
1543 IShellLinkA_fnSetHotkey
,
1544 IShellLinkA_fnGetShowCmd
,
1545 IShellLinkA_fnSetShowCmd
,
1546 IShellLinkA_fnGetIconLocation
,
1547 IShellLinkA_fnSetIconLocation
,
1548 IShellLinkA_fnSetRelativePath
,
1549 IShellLinkA_fnResolve
,
1550 IShellLinkA_fnSetPath
1554 /**************************************************************************
1555 * IShellLinkW_fnQueryInterface
1557 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1558 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1560 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1562 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1566 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1568 *ppvObj
= &This
->IShellLinkA_iface
;
1570 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1572 *ppvObj
= &This
->IShellLinkW_iface
;
1574 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1576 *ppvObj
= &This
->IPersistFile_iface
;
1578 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1580 *ppvObj
= &This
->IPersistStream_iface
;
1582 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1584 *ppvObj
= &This
->IShellLinkDataList_iface
;
1586 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1588 *ppvObj
= &This
->IShellExtInit_iface
;
1590 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1592 *ppvObj
= &This
->IContextMenu_iface
;
1594 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1596 *ppvObj
= &This
->IObjectWithSite_iface
;
1598 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1600 *ppvObj
= &This
->IPropertyStore_iface
;
1605 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1606 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1609 ERR("-- Interface: E_NOINTERFACE\n");
1610 return E_NOINTERFACE
;
1613 /******************************************************************************
1614 * IShellLinkW_fnAddRef
1616 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1618 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1619 ULONG ref
= InterlockedIncrement(&This
->ref
);
1621 TRACE("(%p)->(count=%lu)\n", This
, ref
- 1);
1626 /******************************************************************************
1627 * IShellLinkW_fnRelease
1629 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1631 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1632 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1634 TRACE("(%p)->(count=%lu)\n", This
, refCount
+ 1);
1639 TRACE("-- destroying IShellLink(%p)\n",This
);
1641 free(This
->sIcoPath
);
1643 free(This
->sWorkDir
);
1644 free(This
->sDescription
);
1646 free(This
->sPathRel
);
1647 free(This
->sProduct
);
1648 free(This
->sComponent
);
1649 free(This
->filepath
);
1652 IUnknown_Release( This
->site
);
1655 ILFree(This
->pPidl
);
1662 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1664 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1667 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1668 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1670 if (This
->sComponent
|| This
->sProduct
)
1676 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1682 memset(pfd
, 0, sizeof(*pfd
));
1686 WCHAR path
[MAX_PATH
];
1687 WIN32_FILE_ATTRIBUTE_DATA fad
;
1689 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1691 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1692 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1693 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1694 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1695 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1696 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1699 lstrcpyW(pfd
->cFileName
, PathFindFileNameW(This
->sPath
));
1701 if (GetShortPathNameW(This
->sPath
, path
, MAX_PATH
))
1703 lstrcpyW(pfd
->cAlternateFileName
, PathFindFileNameW(path
));
1707 TRACE("attr 0x%08lx size 0x%08lx%08lx name %s shortname %s\n", pfd
->dwFileAttributes
,
1708 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_w(pfd
->cFileName
),
1709 wine_dbgstr_w(pfd
->cAlternateFileName
));
1715 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1717 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1719 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1726 *ppidl
= ILClone(This
->pPidl
);
1730 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1732 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1733 WCHAR path
[MAX_PATH
];
1735 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1738 ILFree( This
->pPidl
);
1739 This
->pPidl
= ILClone( pidl
);
1743 free( This
->sPath
);
1746 if ( SHGetPathFromIDListW( pidl
, path
) )
1748 This
->sPath
= malloc((lstrlenW(path
) + 1) * sizeof(WCHAR
));
1750 return E_OUTOFMEMORY
;
1752 lstrcpyW(This
->sPath
, path
);
1755 This
->bDirty
= TRUE
;
1760 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1762 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1764 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1767 if( This
->sDescription
)
1768 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1773 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1775 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1777 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1779 free(This
->sDescription
);
1782 This
->sDescription
= malloc( (lstrlenW( pszName
) + 1) * sizeof(WCHAR
) );
1783 if ( !This
->sDescription
)
1784 return E_OUTOFMEMORY
;
1786 lstrcpyW( This
->sDescription
, pszName
);
1789 This
->sDescription
= NULL
;
1790 This
->bDirty
= TRUE
;
1795 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1797 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1799 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1803 if( This
->sWorkDir
)
1804 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1809 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1811 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1813 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1815 free(This
->sWorkDir
);
1816 This
->sWorkDir
= malloc( (lstrlenW( pszDir
) + 1) * sizeof(WCHAR
) );
1817 if ( !This
->sWorkDir
)
1818 return E_OUTOFMEMORY
;
1819 lstrcpyW( This
->sWorkDir
, pszDir
);
1820 This
->bDirty
= TRUE
;
1825 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1827 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1829 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1834 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1839 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1841 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1843 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1848 This
->sArgs
= malloc( (lstrlenW( pszArgs
) + 1) * sizeof(WCHAR
) );
1850 return E_OUTOFMEMORY
;
1851 lstrcpyW( This
->sArgs
, pszArgs
);
1853 else This
->sArgs
= NULL
;
1855 This
->bDirty
= TRUE
;
1860 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1862 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1864 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1866 *pwHotkey
=This
->wHotKey
;
1871 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1873 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1875 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1877 This
->wHotKey
= wHotkey
;
1878 This
->bDirty
= TRUE
;
1883 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1885 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1887 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1889 *piShowCmd
= This
->iShowCmd
;
1894 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1896 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1898 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1900 This
->iShowCmd
= iShowCmd
;
1901 This
->bDirty
= TRUE
;
1906 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1908 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1910 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1912 *piIcon
= This
->iIcoNdx
;
1915 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1922 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, const WCHAR
*path
, INT icon
)
1924 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1926 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_w(path
), icon
);
1928 free(This
->sIcoPath
);
1931 size_t len
= (lstrlenW(path
) + 1) * sizeof(WCHAR
);
1932 This
->sIcoPath
= malloc(len
);
1933 if (!This
->sIcoPath
)
1934 return E_OUTOFMEMORY
;
1935 memcpy(This
->sIcoPath
, path
, len
);
1938 This
->sIcoPath
= NULL
;
1939 This
->iIcoNdx
= icon
;
1940 This
->bDirty
= TRUE
;
1945 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1947 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1949 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1951 free(This
->sPathRel
);
1952 This
->sPathRel
= malloc( (lstrlenW( pszPathRel
) + 1) * sizeof(WCHAR
) );
1953 if ( !This
->sPathRel
)
1954 return E_OUTOFMEMORY
;
1955 lstrcpyW( This
->sPathRel
, pszPathRel
);
1956 This
->bDirty
= TRUE
;
1958 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1961 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1966 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1968 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1970 /*FIXME: use IResolveShellLink interface */
1972 if (!This
->sPath
&& This
->pPidl
) {
1973 WCHAR buffer
[MAX_PATH
];
1975 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1977 if (bSuccess
&& *buffer
) {
1978 This
->sPath
= malloc((lstrlenW(buffer
) + 1) * sizeof(WCHAR
));
1980 return E_OUTOFMEMORY
;
1982 lstrcpyW(This
->sPath
, buffer
);
1984 This
->bDirty
= TRUE
;
1986 hr
= S_OK
; /* don't report an error occurred while just caching information */
1989 if (!This
->sIcoPath
&& This
->sPath
) {
1990 This
->sIcoPath
= malloc((lstrlenW(This
->sPath
) + 1) * sizeof(WCHAR
));
1991 if (!This
->sIcoPath
)
1992 return E_OUTOFMEMORY
;
1994 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1997 This
->bDirty
= TRUE
;
2003 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2012 p
= wcschr( str
, ':' );
2016 ret
= malloc(sizeof(WCHAR
) * (len
+ 1));
2019 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2024 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2026 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2034 /* each segment must start with two colons */
2035 if( str
[0] != ':' || str
[1] != ':' )
2038 /* the last segment is just two colons */
2043 /* there must be a colon straight after a guid */
2044 p
= wcschr( str
, ':' );
2051 /* get the guid, and check it's validly formatted */
2052 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2054 r
= CLSIDFromString( szGuid
, &guid
);
2059 /* match it up to a guid that we care about */
2060 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2062 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2067 /* skip to the next field */
2068 str
= wcschr( str
, ':' );
2073 /* we have to have a component for an advertised shortcut */
2077 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2078 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2080 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2081 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2086 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2088 const int label_sz
= ARRAY_SIZE(volume
->label
);
2089 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2092 volume
->type
= GetDriveTypeW(drive
);
2093 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2094 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2095 TRACE("r = %d type %ld serial %08lx name %s\n", r
,
2096 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2100 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2102 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2103 WCHAR buffer
[MAX_PATH
];
2104 LPWSTR fname
, unquoted
= NULL
;
2108 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2110 if (!pszFile
) return E_INVALIDARG
;
2112 /* quotes at the ends of the string are stripped */
2113 len
= lstrlenW(pszFile
);
2114 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2116 unquoted
= wcsdup(pszFile
);
2117 PathUnquoteSpacesW(unquoted
);
2121 /* any other quote marks are invalid */
2122 if (wcschr(pszFile
, '"'))
2131 free(This
->sComponent
);
2132 This
->sComponent
= NULL
;
2135 ILFree(This
->pPidl
);
2138 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2140 if (*pszFile
== '\0')
2142 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2147 else if(!PathFileExistsW(buffer
) &&
2148 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2151 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2152 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2154 This
->sPath
= malloc( (lstrlenW( buffer
) + 1) * sizeof(WCHAR
) );
2158 return E_OUTOFMEMORY
;
2161 lstrcpyW(This
->sPath
, buffer
);
2163 This
->bDirty
= TRUE
;
2169 /**************************************************************************
2170 * IShellLinkW Implementation
2173 static const IShellLinkWVtbl slvtw
=
2175 IShellLinkW_fnQueryInterface
,
2176 IShellLinkW_fnAddRef
,
2177 IShellLinkW_fnRelease
,
2178 IShellLinkW_fnGetPath
,
2179 IShellLinkW_fnGetIDList
,
2180 IShellLinkW_fnSetIDList
,
2181 IShellLinkW_fnGetDescription
,
2182 IShellLinkW_fnSetDescription
,
2183 IShellLinkW_fnGetWorkingDirectory
,
2184 IShellLinkW_fnSetWorkingDirectory
,
2185 IShellLinkW_fnGetArguments
,
2186 IShellLinkW_fnSetArguments
,
2187 IShellLinkW_fnGetHotkey
,
2188 IShellLinkW_fnSetHotkey
,
2189 IShellLinkW_fnGetShowCmd
,
2190 IShellLinkW_fnSetShowCmd
,
2191 IShellLinkW_fnGetIconLocation
,
2192 IShellLinkW_fnSetIconLocation
,
2193 IShellLinkW_fnSetRelativePath
,
2194 IShellLinkW_fnResolve
,
2195 IShellLinkW_fnSetPath
2198 static HRESULT WINAPI
2199 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2201 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2202 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2206 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2208 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2209 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2213 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2215 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2216 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2219 static HRESULT WINAPI
2220 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2222 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2226 static HRESULT WINAPI
2227 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2229 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2230 LPVOID block
= NULL
;
2233 TRACE("%p %08lx %p\n", iface
, dwSig
, ppDataBlock
);
2237 case EXP_DARWIN_ID_SIG
:
2238 if (!This
->sComponent
)
2240 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2243 case EXP_SZ_LINK_SIG
:
2244 case NT_CONSOLE_PROPS_SIG
:
2245 case NT_FE_CONSOLE_PROPS_SIG
:
2246 case EXP_SPECIAL_FOLDER_SIG
:
2247 case EXP_SZ_ICON_SIG
:
2248 FIXME("valid but unhandled datablock %08lx\n", dwSig
);
2251 ERR("unknown datablock %08lx\n", dwSig
);
2253 *ppDataBlock
= block
;
2257 static HRESULT WINAPI
2258 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2260 FIXME("(%p)->(%lu): stub\n", iface
, dwSig
);
2264 static HRESULT WINAPI
2265 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2267 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2270 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2272 /* FIXME: add more */
2274 flags
|= SLDF_HAS_ARGS
;
2275 if (This
->sComponent
)
2276 flags
|= SLDF_HAS_DARWINID
;
2278 flags
|= SLDF_HAS_ICONLOCATION
;
2280 flags
|= SLDF_HAS_LOGO3ID
;
2282 flags
|= SLDF_HAS_ID_LIST
;
2289 static HRESULT WINAPI
2290 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2292 FIXME("(%p)->(%lu): stub\n", iface
, dwFlags
);
2296 static const IShellLinkDataListVtbl dlvt
=
2298 ShellLink_DataList_QueryInterface
,
2299 ShellLink_DataList_AddRef
,
2300 ShellLink_DataList_Release
,
2301 ShellLink_AddDataBlock
,
2302 ShellLink_CopyDataBlock
,
2303 ShellLink_RemoveDataBlock
,
2308 static HRESULT WINAPI
2309 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2311 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2312 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2316 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2318 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2319 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2323 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2325 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2326 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2329 /**************************************************************************
2330 * ShellLink implementation of IShellExtInit::Initialize()
2332 * Loads the shelllink from the dataobject the shell is pointing to.
2334 static HRESULT WINAPI
2335 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2336 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2338 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2344 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2349 format
.cfFormat
= CF_HDROP
;
2351 format
.dwAspect
= DVASPECT_CONTENT
;
2353 format
.tymed
= TYMED_HGLOBAL
;
2355 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2358 count
= DragQueryFileW( stgm
.hGlobal
, -1, NULL
, 0 );
2363 count
= DragQueryFileW( stgm
.hGlobal
, 0, NULL
, 0 );
2365 path
= malloc( count
* sizeof(WCHAR
) );
2368 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2370 count
= DragQueryFileW( stgm
.hGlobal
, 0, path
, count
);
2371 r
= IPersistFile_Load( pf
, path
, 0 );
2375 ReleaseStgMedium( &stgm
);
2380 static const IShellExtInitVtbl eivt
=
2382 ShellLink_ExtInit_QueryInterface
,
2383 ShellLink_ExtInit_AddRef
,
2384 ShellLink_ExtInit_Release
,
2385 ShellLink_ExtInit_Initialize
2388 static HRESULT WINAPI
2389 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2391 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2392 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2396 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2398 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2399 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2403 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2405 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2406 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2409 static HRESULT WINAPI
2410 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2411 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2413 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2417 TRACE("%p %p %u %u %u %u\n", This
,
2418 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2421 return E_INVALIDARG
;
2423 memset( &mii
, 0, sizeof mii
);
2424 mii
.cbSize
= sizeof mii
;
2425 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2426 mii
.dwTypeData
= (LPWSTR
)L
"Open";
2427 mii
.cch
= lstrlenW( mii
.dwTypeData
);
2428 mii
.wID
= idCmdFirst
+ id
++;
2429 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2430 mii
.fType
= MFT_STRING
;
2431 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2435 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2439 shelllink_get_msi_component_path( LPWSTR component
)
2444 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2445 if (r
!= ERROR_SUCCESS
)
2449 path
= malloc( sz
* sizeof(WCHAR
) );
2450 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2451 if (r
!= ERROR_SUCCESS
)
2457 TRACE("returning %s\n", debugstr_w( path
) );
2462 static HRESULT WINAPI
2463 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2465 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2466 SHELLEXECUTEINFOW sei
;
2467 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2472 TRACE("%p %p\n", This
, lpici
);
2474 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2475 return E_INVALIDARG
;
2477 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2479 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2480 return E_INVALIDARG
;
2483 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2487 if ( This
->sComponent
)
2489 path
= shelllink_get_msi_component_path( This
->sComponent
);
2494 path
= wcsdup( This
->sPath
);
2496 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2497 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2499 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2503 len
+= lstrlenW( This
->sArgs
);
2504 if ( iciex
->lpParametersW
)
2505 len
+= lstrlenW( iciex
->lpParametersW
);
2507 args
= malloc( len
* sizeof(WCHAR
) );
2510 lstrcatW( args
, This
->sArgs
);
2511 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2513 lstrcatW( args
, L
" " );
2514 lstrcatW( args
, iciex
->lpParametersW
);
2518 memset( &sei
, 0, sizeof sei
);
2519 sei
.cbSize
= sizeof sei
;
2520 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2522 sei
.nShow
= This
->iShowCmd
;
2523 sei
.lpIDList
= This
->pPidl
;
2524 sei
.lpDirectory
= This
->sWorkDir
;
2525 sei
.lpParameters
= args
;
2526 sei
.lpVerb
= L
"Open";
2528 if( ShellExecuteExW( &sei
) )
2539 static HRESULT WINAPI
2540 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2541 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2543 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2545 FIXME("(%p)->(%Iu %u %p %p %u): stub\n", This
,
2546 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2551 static const IContextMenuVtbl cmvt
=
2553 ShellLink_ContextMenu_QueryInterface
,
2554 ShellLink_ContextMenu_AddRef
,
2555 ShellLink_ContextMenu_Release
,
2556 ShellLink_QueryContextMenu
,
2557 ShellLink_InvokeCommand
,
2558 ShellLink_GetCommandString
2561 static HRESULT WINAPI
2562 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2564 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2565 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2569 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2571 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2572 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2576 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2578 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2579 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2582 static HRESULT WINAPI
2583 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2585 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2587 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2591 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2594 static HRESULT WINAPI
2595 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2597 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2599 TRACE("%p %p\n", iface
, punk
);
2602 IUnknown_AddRef( punk
);
2605 IUnknown_Release( This
->site
);
2612 static const IObjectWithSiteVtbl owsvt
=
2614 ShellLink_ObjectWithSite_QueryInterface
,
2615 ShellLink_ObjectWithSite_AddRef
,
2616 ShellLink_ObjectWithSite_Release
,
2621 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2623 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2624 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2627 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2629 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2630 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2633 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2635 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2636 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2639 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2641 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2642 FIXME("(%p)->(%p): stub\n", This
, props
);
2646 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2648 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2649 FIXME("(%p)->(%ld %p): stub\n", This
, propid
, key
);
2653 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2655 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2656 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2660 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2662 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2663 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2667 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2669 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2670 FIXME("(%p): stub\n", This
);
2674 static const IPropertyStoreVtbl propertystorevtbl
= {
2675 propertystore_QueryInterface
,
2676 propertystore_AddRef
,
2677 propertystore_Release
,
2678 propertystore_GetCount
,
2679 propertystore_GetAt
,
2680 propertystore_GetValue
,
2681 propertystore_SetValue
,
2682 propertystore_Commit
2685 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2687 IShellLinkImpl
* sl
;
2690 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2695 return CLASS_E_NOAGGREGATION
;
2697 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2699 return E_OUTOFMEMORY
;
2702 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2703 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2704 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2705 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2706 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2707 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2708 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2709 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2710 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2711 sl
->iShowCmd
= SW_SHOWNORMAL
;
2715 sl
->filepath
= NULL
;
2717 TRACE("(%p)\n", sl
);
2719 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2720 IShellLinkW_Release( &sl
->IShellLinkW_iface
);