3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Nearly complete information about the binary formats
23 * of .lnk files available at http://www.wotsit.org
25 * You can use winedump to examine the contents of a link file:
28 * MSI advertised shortcuts are totally undocumented. They provide an
29 * icon for a program that is not yet installed, and invoke MSI to
30 * install the program when the shortcut is clicked on. They are
31 * created by passing a special string to SetPath, and the information
32 * in that string is parsed an stored.
36 #define NONAMELESSUNION
38 #include "wine/debug.h"
48 #include "undocshell.h"
51 #include "shell32_main.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
61 DEFINE_GUID( SHELL32_AdvtShortcutProduct
,
62 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
63 DEFINE_GUID( SHELL32_AdvtShortcutComponent
,
64 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
66 /* link file formats */
70 typedef struct _LINK_HEADER
72 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
73 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
74 DWORD dwFlags
; /* 0x14 describes elements following */
75 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
76 FILETIME Time1
; /* 0x1c */
77 FILETIME Time2
; /* 0x24 */
78 FILETIME Time3
; /* 0x2c */
79 DWORD dwFileLength
; /* 0x34 File length */
80 DWORD nIcon
; /* 0x38 icon number */
81 DWORD fStartup
; /* 0x3c startup type */
82 DWORD wHotKey
; /* 0x40 hotkey */
83 DWORD Unknown5
; /* 0x44 */
84 DWORD Unknown6
; /* 0x48 */
85 } LINK_HEADER
, * PLINK_HEADER
;
87 #define SHLINK_LOCAL 0
88 #define SHLINK_REMOTE 1
90 typedef struct _LOCATION_INFO
97 DWORD dwNetworkVolTableOfs
;
101 typedef struct _LOCAL_VOLUME_INFO
109 typedef struct volume_info_t
113 WCHAR label
[12]; /* assume 8.3 */
118 /* IShellLink Implementation */
122 IShellLinkA IShellLinkA_iface
;
123 IShellLinkW IShellLinkW_iface
;
124 IPersistFile IPersistFile_iface
;
125 IPersistStream IPersistStream_iface
;
126 IShellLinkDataList IShellLinkDataList_iface
;
127 IShellExtInit IShellExtInit_iface
;
128 IContextMenu IContextMenu_iface
;
129 IObjectWithSite IObjectWithSite_iface
;
130 IPropertyStore IPropertyStore_iface
;
134 /* data structures according to the information in the link */
154 INT iIdOpen
; /* id of the "Open" entry in the context menu */
157 LPOLESTR filepath
; /* file path returned by IPersistFile::GetCurFile */
160 static inline IShellLinkImpl
*impl_from_IShellLinkA(IShellLinkA
*iface
)
162 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkA_iface
);
165 static inline IShellLinkImpl
*impl_from_IShellLinkW(IShellLinkW
*iface
)
167 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkW_iface
);
170 static inline IShellLinkImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
172 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistFile_iface
);
175 static inline IShellLinkImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
177 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistStream_iface
);
180 static inline IShellLinkImpl
*impl_from_IShellLinkDataList(IShellLinkDataList
*iface
)
182 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkDataList_iface
);
185 static inline IShellLinkImpl
*impl_from_IShellExtInit(IShellExtInit
*iface
)
187 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellExtInit_iface
);
190 static inline IShellLinkImpl
*impl_from_IContextMenu(IContextMenu
*iface
)
192 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IContextMenu_iface
);
195 static inline IShellLinkImpl
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
197 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IObjectWithSite_iface
);
200 static inline IShellLinkImpl
*impl_from_IPropertyStore(IPropertyStore
*iface
)
202 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPropertyStore_iface
);
205 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
207 /* strdup on the process heap */
208 static inline LPWSTR
heap_strdupAtoW( LPCSTR str
)
210 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
211 LPWSTR p
= heap_alloc( len
*sizeof (WCHAR
) );
214 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
218 /**************************************************************************
219 * IPersistFile_QueryInterface
221 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
226 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
227 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
230 /******************************************************************************
231 * IPersistFile_AddRef
233 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
235 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
236 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
239 /******************************************************************************
240 * IPersistFile_Release
242 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
244 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
245 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
248 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
250 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
252 TRACE("(%p)->(%p)\n", This
, pClassID
);
254 *pClassID
= CLSID_ShellLink
;
259 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
261 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
263 TRACE("(%p)\n",This
);
271 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
273 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
274 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
278 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
281 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
282 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
285 r
= IPersistStream_Load(StreamThis
, stm
);
286 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
287 IStream_Release( stm
);
289 /* update file path */
290 heap_free(This
->filepath
);
291 This
->filepath
= strdupW(pszFileName
);
293 This
->bDirty
= FALSE
;
295 TRACE("-- returning hr %08x\n", r
);
299 BOOL
run_winemenubuilder( const WCHAR
*args
)
301 static const WCHAR menubuilder
[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
305 PROCESS_INFORMATION pi
;
310 GetSystemDirectoryW( app
, MAX_PATH
- ARRAY_SIZE(menubuilder
) );
311 strcatW( app
, menubuilder
);
313 len
= (strlenW( app
) + strlenW( args
) + 1) * sizeof(WCHAR
);
314 buffer
= heap_alloc( len
);
318 strcpyW( buffer
, app
);
319 strcatW( buffer
, args
);
321 TRACE("starting %s\n",debugstr_w(buffer
));
323 memset(&si
, 0, sizeof(si
));
326 Wow64DisableWow64FsRedirection( &redir
);
327 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
328 Wow64RevertWow64FsRedirection( redir
);
334 CloseHandle( pi
.hProcess
);
335 CloseHandle( pi
.hThread
);
341 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
343 static const WCHAR szFormat
[] = {' ','-','w',' ','"','%','s','"',0 };
348 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
349 buffer
= heap_alloc( len
);
353 wsprintfW( buffer
, szFormat
, szLink
);
354 ret
= run_winemenubuilder( buffer
);
359 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
361 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
362 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
366 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
371 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
374 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
375 IStream_Release( stm
);
379 StartLinkProcessor( pszFileName
);
381 /* update file path */
382 heap_free(This
->filepath
);
383 This
->filepath
= strdupW(pszFileName
);
385 This
->bDirty
= FALSE
;
389 DeleteFileW( pszFileName
);
390 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
397 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
399 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
400 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
404 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
406 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
409 TRACE("(%p)->(%p)\n", This
, filename
);
417 SHGetMalloc(&pMalloc
);
418 *filename
= IMalloc_Alloc(pMalloc
, (strlenW(This
->filepath
)+1)*sizeof(WCHAR
));
419 if (!*filename
) return E_OUTOFMEMORY
;
421 strcpyW(*filename
, This
->filepath
);
426 static const IPersistFileVtbl pfvt
=
428 IPersistFile_fnQueryInterface
,
429 IPersistFile_fnAddRef
,
430 IPersistFile_fnRelease
,
431 IPersistFile_fnGetClassID
,
432 IPersistFile_fnIsDirty
,
435 IPersistFile_fnSaveCompleted
,
436 IPersistFile_fnGetCurFile
439 /************************************************************************
440 * IPersistStream_QueryInterface
442 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
443 IPersistStream
* iface
,
447 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
448 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
451 /************************************************************************
452 * IPersistStream_Release
454 static ULONG WINAPI
IPersistStream_fnRelease(
455 IPersistStream
* iface
)
457 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
458 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
461 /************************************************************************
462 * IPersistStream_AddRef
464 static ULONG WINAPI
IPersistStream_fnAddRef(
465 IPersistStream
* iface
)
467 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
468 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
471 /************************************************************************
472 * IPersistStream_GetClassID
475 static HRESULT WINAPI
IPersistStream_fnGetClassID(
476 IPersistStream
* iface
,
479 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
480 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
483 /************************************************************************
484 * IPersistStream_IsDirty (IPersistStream)
486 static HRESULT WINAPI
IPersistStream_fnIsDirty(
487 IPersistStream
* iface
)
489 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
491 TRACE("(%p)\n", This
);
497 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
508 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
509 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
513 len
*= sizeof (WCHAR
);
515 TRACE("reading %d\n", len
);
516 temp
= heap_alloc(len
+ sizeof(WCHAR
));
518 return E_OUTOFMEMORY
;
520 r
= IStream_Read(stm
, temp
, len
, &count
);
521 if( FAILED (r
) || ( count
!= len
) )
527 TRACE("read %s\n", debugstr_an(temp
,len
));
529 /* convert to unicode if necessary */
532 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
533 str
= heap_alloc( (count
+1)*sizeof (WCHAR
) );
537 return E_OUTOFMEMORY
;
539 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
554 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
561 unsigned char data
[1];
566 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
567 if( FAILED( r
) || count
!= sizeof(size
) )
570 chunk
= heap_alloc( size
);
572 return E_OUTOFMEMORY
;
575 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
576 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
582 TRACE("Read %d bytes\n",chunk
->size
);
589 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
591 const int label_sz
= ARRAY_SIZE(volume
->label
);
595 volume
->serial
= vol
->dwVolSerial
;
596 volume
->type
= vol
->dwType
;
598 if( !vol
->dwVolLabelOfs
)
600 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
602 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
605 label
+= vol
->dwVolLabelOfs
;
606 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
611 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
616 while( (len
< maxlen
) && p
[len
] )
619 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
620 path
= heap_alloc((wlen
+ 1) * sizeof(WCHAR
));
621 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
627 static HRESULT
Stream_LoadLocation( IStream
*stm
,
628 volume_info
*volume
, LPWSTR
*path
)
635 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
639 loc
= (LOCATION_INFO
*) p
;
640 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
646 /* if there's valid local volume information, load it */
647 if( loc
->dwVolTableOfs
&&
648 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
650 LOCAL_VOLUME_INFO
*volume_info
;
652 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
653 Stream_LoadVolume( volume_info
, volume
);
656 /* if there's a local path, load it */
657 n
= loc
->dwLocalPathOfs
;
658 if( n
&& (n
< loc
->dwTotalSize
) )
659 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
661 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
662 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
669 * The format of the advertised shortcut info seems to be:
674 * 0 Length of the block (4 bytes, usually 0x314)
676 * 8 string data in ASCII
677 * 8+0x104 string data in UNICODE
679 * In the original Win32 implementation the buffers are not initialized
680 * to zero, so data trailing the string is random garbage.
682 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
687 EXP_DARWIN_LINK buffer
;
691 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
695 /* make sure that we read the size of the structure even on error */
696 size
= sizeof buffer
- sizeof (DWORD
);
697 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
699 ERR("Ooops. This structure is not as expected...\n");
703 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
710 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
712 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
714 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
718 *str
= heap_alloc((lstrlenW(buffer
.szwDarwinID
) + 1) * sizeof(WCHAR
) );
719 lstrcpyW( *str
, buffer
.szwDarwinID
);
724 /************************************************************************
725 * IPersistStream_Load (IPersistStream)
727 static HRESULT WINAPI
IPersistStream_fnLoad(
728 IPersistStream
* iface
,
737 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
739 TRACE("%p %p\n", This
, stm
);
742 return STG_E_INVALIDPOINTER
;
745 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
749 if( dwBytesRead
!= sizeof(hdr
))
751 if( hdr
.dwSize
!= sizeof(hdr
))
753 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
756 /* free all the old stuff */
759 memset( &This
->volume
, 0, sizeof This
->volume
);
760 heap_free(This
->sPath
);
762 heap_free(This
->sDescription
);
763 This
->sDescription
= NULL
;
764 heap_free(This
->sPathRel
);
765 This
->sPathRel
= NULL
;
766 heap_free(This
->sWorkDir
);
767 This
->sWorkDir
= NULL
;
768 heap_free(This
->sArgs
);
770 heap_free(This
->sIcoPath
);
771 This
->sIcoPath
= NULL
;
772 heap_free(This
->sProduct
);
773 This
->sProduct
= NULL
;
774 heap_free(This
->sComponent
);
775 This
->sComponent
= NULL
;
777 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
778 This
->iIcoNdx
= hdr
.nIcon
;
779 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
780 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
781 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
784 WCHAR sTemp
[MAX_PATH
];
785 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->time1
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
786 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
787 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->time2
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
788 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
789 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &This
->time3
, NULL
, sTemp
, ARRAY_SIZE(sTemp
));
790 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
793 /* load all the new stuff */
794 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
796 r
= ILLoadFromStream( stm
, &This
->pPidl
);
802 /* load the location information */
803 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
804 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
808 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
809 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
811 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
812 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
817 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
819 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
820 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
825 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
827 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
828 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
833 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
835 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
836 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
841 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
843 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
844 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
849 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
851 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
852 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
857 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
859 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
860 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
865 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
866 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
868 /* Some lnk files have extra data blocks starting with a
869 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
870 * one with a 0xa0000003 signature. However these don't seem to matter
873 WARN("Last word was not zero\n");
885 /************************************************************************
888 * Helper function for IPersistStream_Save. Writes a unicode string
889 * with terminating nul byte to a stream, preceded by the its length.
891 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
893 USHORT len
= lstrlenW( str
) + 1;
897 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
901 len
*= sizeof(WCHAR
);
903 r
= IStream_Write( stm
, str
, len
, &count
);
910 /************************************************************************
911 * Stream_WriteLocationInfo
913 * Writes the location info to a stream
915 * FIXME: One day we might want to write the network volume information
916 * and the final path.
917 * Figure out how Windows deals with unicode paths here.
919 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
920 volume_info
*volume
)
922 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
923 LOCAL_VOLUME_INFO
*vol
;
925 LPSTR szLabel
, szPath
, szFinalPath
;
929 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
931 /* figure out the size of everything */
932 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
933 NULL
, 0, NULL
, NULL
);
934 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
935 NULL
, 0, NULL
, NULL
);
936 volume_info_size
= sizeof *vol
+ label_size
;
938 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
940 /* create pointers to everything */
941 loc
= heap_alloc_zero(total_size
);
942 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
943 szLabel
= (LPSTR
) &vol
[1];
944 szPath
= &szLabel
[label_size
];
945 szFinalPath
= &szPath
[path_size
];
947 /* fill in the location information header */
948 loc
->dwTotalSize
= total_size
;
949 loc
->dwHeaderSize
= sizeof (*loc
);
951 loc
->dwVolTableOfs
= sizeof (*loc
);
952 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
953 loc
->dwNetworkVolTableOfs
= 0;
954 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
956 /* fill in the volume information */
957 vol
->dwSize
= volume_info_size
;
958 vol
->dwType
= volume
->type
;
959 vol
->dwVolSerial
= volume
->serial
;
960 vol
->dwVolLabelOfs
= sizeof (*vol
);
962 /* copy in the strings */
963 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
964 szLabel
, label_size
, NULL
, NULL
);
965 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
966 szPath
, path_size
, NULL
, NULL
);
969 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
975 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
977 EXP_DARWIN_LINK
*buffer
;
979 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
980 buffer
->dbh
.cbSize
= sizeof *buffer
;
981 buffer
->dbh
.dwSignature
= magic
;
982 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
983 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
988 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
990 EXP_DARWIN_LINK
*buffer
;
995 buffer
= shelllink_build_darwinid( string
, magic
);
997 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1000 /************************************************************************
1001 * IPersistStream_Save (IPersistStream)
1003 * FIXME: makes assumptions about byte order
1005 static HRESULT WINAPI
IPersistStream_fnSave(
1006 IPersistStream
* iface
,
1015 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1017 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1019 memset(&header
, 0, sizeof(header
));
1020 header
.dwSize
= sizeof(header
);
1021 header
.fStartup
= This
->iShowCmd
;
1022 header
.MagicGuid
= CLSID_ShellLink
;
1024 header
.wHotKey
= This
->wHotKey
;
1025 header
.nIcon
= This
->iIcoNdx
;
1026 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1028 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1030 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1031 if( This
->sDescription
)
1032 header
.dwFlags
|= SLDF_HAS_NAME
;
1033 if( This
->sWorkDir
)
1034 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1036 header
.dwFlags
|= SLDF_HAS_ARGS
;
1037 if( This
->sIcoPath
)
1038 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1039 if( This
->sProduct
)
1040 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1041 if( This
->sComponent
)
1042 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1044 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1045 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1046 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1048 /* write the Shortcut header */
1049 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1052 ERR("Write failed at %d\n",__LINE__
);
1056 TRACE("Writing pidl\n");
1058 /* write the PIDL to the shortcut */
1061 r
= ILSaveToStream( stm
, This
->pPidl
);
1064 ERR("Failed to write PIDL at %d\n",__LINE__
);
1070 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1072 if( This
->sDescription
)
1073 r
= Stream_WriteString( stm
, This
->sDescription
);
1075 if( This
->sPathRel
)
1076 r
= Stream_WriteString( stm
, This
->sPathRel
);
1078 if( This
->sWorkDir
)
1079 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1082 r
= Stream_WriteString( stm
, This
->sArgs
);
1084 if( This
->sIcoPath
)
1085 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1087 if( This
->sProduct
)
1088 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1090 if( This
->sComponent
)
1091 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1093 /* the last field is a single zero dword */
1095 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1100 /************************************************************************
1101 * IPersistStream_GetSizeMax (IPersistStream)
1103 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1104 IPersistStream
* iface
,
1105 ULARGE_INTEGER
* pcbSize
)
1107 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1109 TRACE("(%p)\n", This
);
1114 static const IPersistStreamVtbl psvt
=
1116 IPersistStream_fnQueryInterface
,
1117 IPersistStream_fnAddRef
,
1118 IPersistStream_fnRelease
,
1119 IPersistStream_fnGetClassID
,
1120 IPersistStream_fnIsDirty
,
1121 IPersistStream_fnLoad
,
1122 IPersistStream_fnSave
,
1123 IPersistStream_fnGetSizeMax
1126 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1128 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1133 /**************************************************************************
1134 * ShellLink_UpdatePath
1135 * update absolute path in sPath using relative path in sPathRel
1137 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1139 if (!path
|| !psPath
)
1140 return E_INVALIDARG
;
1142 if (!*psPath
&& sPathRel
) {
1143 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1144 LPWSTR final
= NULL
;
1146 /* first try if [directory of link file] + [relative path] finds an existing file */
1148 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1151 lstrcpyW(final
, sPathRel
);
1155 if (SHELL_ExistsFileW(buffer
)) {
1156 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1157 lstrcpyW(abs_path
, buffer
);
1159 /* try if [working directory] + [relative path] finds an existing file */
1161 lstrcpyW(buffer
, sWorkDir
);
1162 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1164 if (SHELL_ExistsFileW(buffer
))
1165 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1166 lstrcpyW(abs_path
, buffer
);
1170 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1172 lstrcpyW(abs_path
, sPathRel
);
1174 *psPath
= heap_alloc((lstrlenW(abs_path
) + 1) * sizeof(WCHAR
));
1176 return E_OUTOFMEMORY
;
1178 lstrcpyW(*psPath
, abs_path
);
1184 /**************************************************************************
1185 * IShellLink_ConstructFromFile
1187 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1188 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1192 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1194 if (SUCCEEDED(hr
)) {
1199 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1201 if (SUCCEEDED(hr
)) {
1202 WCHAR path
[MAX_PATH
];
1204 if (SHGetPathFromIDListW(pidl
, path
))
1205 hr
= IPersistFile_Load(ppf
, path
, 0);
1210 *ppv
= (IUnknown
*)psl
;
1212 IPersistFile_Release(ppf
);
1216 IShellLinkW_Release(psl
);
1222 /**************************************************************************
1223 * IShellLinkA_QueryInterface
1225 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1227 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1228 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1231 /******************************************************************************
1232 * IShellLinkA_AddRef
1234 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1236 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1237 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1240 /******************************************************************************
1241 * IShellLinkA_Release
1243 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1245 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1246 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1249 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1250 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1252 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1255 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1256 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1258 if (This
->sComponent
|| This
->sProduct
)
1263 if (This
->sPath
&& This
->sPath
[0])
1264 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1265 pszFile
, cchMaxPath
, NULL
, NULL
);
1271 memset(pfd
, 0, sizeof(*pfd
));
1275 char path
[MAX_PATH
];
1276 WIN32_FILE_ATTRIBUTE_DATA fad
;
1278 WideCharToMultiByte(CP_ACP
, 0, This
->sPath
, -1, path
, MAX_PATH
, NULL
, NULL
);
1280 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1282 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1283 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1284 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1285 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1286 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1287 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1290 lstrcpyA(pfd
->cFileName
, PathFindFileNameA(path
));
1292 if (GetShortPathNameA(path
, path
, MAX_PATH
))
1294 lstrcpyA(pfd
->cAlternateFileName
, PathFindFileNameA(path
));
1298 TRACE("attr 0x%08x size 0x%08x%08x name %s shortname %s\n", pfd
->dwFileAttributes
,
1299 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_a(pfd
->cFileName
),
1300 wine_dbgstr_a(pfd
->cAlternateFileName
));
1306 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1308 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1309 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1312 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1314 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1315 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1318 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1321 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1323 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1327 if( This
->sDescription
)
1328 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1329 pszName
, cchMaxName
, NULL
, NULL
);
1334 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1336 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1340 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1344 descrW
= heap_strdupAtoW(pszName
);
1345 if (!descrW
) return E_OUTOFMEMORY
;
1350 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1356 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1359 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1361 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1365 if( This
->sWorkDir
)
1366 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1367 pszDir
, cchMaxPath
, NULL
, NULL
);
1372 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1374 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1378 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1380 dirW
= heap_strdupAtoW(pszDir
);
1381 if (!dirW
) return E_OUTOFMEMORY
;
1383 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1389 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1391 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1393 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1398 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1399 pszArgs
, cchMaxPath
, NULL
, NULL
);
1404 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1406 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1410 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1414 argsW
= heap_strdupAtoW(pszArgs
);
1415 if (!argsW
) return E_OUTOFMEMORY
;
1420 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1426 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1428 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1429 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1432 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1434 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1435 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1438 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1440 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1441 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1444 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1446 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1447 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1450 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1451 INT cchIconPath
, INT
*piIcon
)
1453 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1455 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1457 *piIcon
= This
->iIcoNdx
;
1460 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1467 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR pszIconPath
,
1470 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1474 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1476 pathW
= heap_strdupAtoW(pszIconPath
);
1477 if (!pathW
) return E_OUTOFMEMORY
;
1479 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, pathW
, iIcon
);
1485 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1488 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1492 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1494 pathW
= heap_strdupAtoW(pszPathRel
);
1495 if (!pathW
) return E_OUTOFMEMORY
;
1497 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1503 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1505 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1507 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1509 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1512 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1514 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1518 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1520 if (!pszFile
) return E_INVALIDARG
;
1522 str
= heap_strdupAtoW(pszFile
);
1524 return E_OUTOFMEMORY
;
1526 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1532 /**************************************************************************
1533 * IShellLink Implementation
1536 static const IShellLinkAVtbl slvt
=
1538 IShellLinkA_fnQueryInterface
,
1539 IShellLinkA_fnAddRef
,
1540 IShellLinkA_fnRelease
,
1541 IShellLinkA_fnGetPath
,
1542 IShellLinkA_fnGetIDList
,
1543 IShellLinkA_fnSetIDList
,
1544 IShellLinkA_fnGetDescription
,
1545 IShellLinkA_fnSetDescription
,
1546 IShellLinkA_fnGetWorkingDirectory
,
1547 IShellLinkA_fnSetWorkingDirectory
,
1548 IShellLinkA_fnGetArguments
,
1549 IShellLinkA_fnSetArguments
,
1550 IShellLinkA_fnGetHotkey
,
1551 IShellLinkA_fnSetHotkey
,
1552 IShellLinkA_fnGetShowCmd
,
1553 IShellLinkA_fnSetShowCmd
,
1554 IShellLinkA_fnGetIconLocation
,
1555 IShellLinkA_fnSetIconLocation
,
1556 IShellLinkA_fnSetRelativePath
,
1557 IShellLinkA_fnResolve
,
1558 IShellLinkA_fnSetPath
1562 /**************************************************************************
1563 * IShellLinkW_fnQueryInterface
1565 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1566 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1568 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1570 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1574 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1576 *ppvObj
= &This
->IShellLinkA_iface
;
1578 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1580 *ppvObj
= &This
->IShellLinkW_iface
;
1582 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1584 *ppvObj
= &This
->IPersistFile_iface
;
1586 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1588 *ppvObj
= &This
->IPersistStream_iface
;
1590 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1592 *ppvObj
= &This
->IShellLinkDataList_iface
;
1594 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1596 *ppvObj
= &This
->IShellExtInit_iface
;
1598 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1600 *ppvObj
= &This
->IContextMenu_iface
;
1602 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1604 *ppvObj
= &This
->IObjectWithSite_iface
;
1606 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1608 *ppvObj
= &This
->IPropertyStore_iface
;
1613 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1614 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1617 ERR("-- Interface: E_NOINTERFACE\n");
1618 return E_NOINTERFACE
;
1621 /******************************************************************************
1622 * IShellLinkW_fnAddRef
1624 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1626 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1627 ULONG ref
= InterlockedIncrement(&This
->ref
);
1629 TRACE("(%p)->(count=%u)\n", This
, ref
- 1);
1634 /******************************************************************************
1635 * IShellLinkW_fnRelease
1637 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1639 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1640 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1642 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
1647 TRACE("-- destroying IShellLink(%p)\n",This
);
1649 heap_free(This
->sIcoPath
);
1650 heap_free(This
->sArgs
);
1651 heap_free(This
->sWorkDir
);
1652 heap_free(This
->sDescription
);
1653 heap_free(This
->sPath
);
1654 heap_free(This
->sPathRel
);
1655 heap_free(This
->sProduct
);
1656 heap_free(This
->sComponent
);
1657 heap_free(This
->filepath
);
1660 IUnknown_Release( This
->site
);
1663 ILFree(This
->pPidl
);
1670 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1672 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1675 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1676 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1678 if (This
->sComponent
|| This
->sProduct
)
1684 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1690 memset(pfd
, 0, sizeof(*pfd
));
1694 WCHAR path
[MAX_PATH
];
1695 WIN32_FILE_ATTRIBUTE_DATA fad
;
1697 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1699 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1700 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1701 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1702 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1703 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1704 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1707 lstrcpyW(pfd
->cFileName
, PathFindFileNameW(This
->sPath
));
1709 if (GetShortPathNameW(This
->sPath
, path
, MAX_PATH
))
1711 lstrcpyW(pfd
->cAlternateFileName
, PathFindFileNameW(path
));
1715 TRACE("attr 0x%08x size 0x%08x%08x name %s shortname %s\n", pfd
->dwFileAttributes
,
1716 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_w(pfd
->cFileName
),
1717 wine_dbgstr_w(pfd
->cAlternateFileName
));
1723 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1725 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1727 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1734 *ppidl
= ILClone(This
->pPidl
);
1738 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1740 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1741 WCHAR path
[MAX_PATH
];
1743 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1746 ILFree( This
->pPidl
);
1747 This
->pPidl
= ILClone( pidl
);
1751 heap_free( This
->sPath
);
1754 if ( SHGetPathFromIDListW( pidl
, path
) )
1756 This
->sPath
= heap_alloc((lstrlenW(path
) + 1) * sizeof(WCHAR
));
1758 return E_OUTOFMEMORY
;
1760 lstrcpyW(This
->sPath
, path
);
1763 This
->bDirty
= TRUE
;
1768 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1770 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1772 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1775 if( This
->sDescription
)
1776 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1781 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1783 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1785 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1787 heap_free(This
->sDescription
);
1790 This
->sDescription
= heap_alloc((lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1791 if ( !This
->sDescription
)
1792 return E_OUTOFMEMORY
;
1794 lstrcpyW( This
->sDescription
, pszName
);
1797 This
->sDescription
= NULL
;
1798 This
->bDirty
= TRUE
;
1803 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1805 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1807 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1811 if( This
->sWorkDir
)
1812 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1817 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1819 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1821 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1823 heap_free(This
->sWorkDir
);
1824 This
->sWorkDir
= heap_alloc((lstrlenW( pszDir
) + 1) * sizeof (WCHAR
) );
1825 if ( !This
->sWorkDir
)
1826 return E_OUTOFMEMORY
;
1827 lstrcpyW( This
->sWorkDir
, pszDir
);
1828 This
->bDirty
= TRUE
;
1833 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1835 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1837 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1842 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1847 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1849 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1851 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1853 heap_free(This
->sArgs
);
1856 This
->sArgs
= heap_alloc((lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1858 return E_OUTOFMEMORY
;
1859 lstrcpyW( This
->sArgs
, pszArgs
);
1861 else This
->sArgs
= NULL
;
1863 This
->bDirty
= TRUE
;
1868 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1870 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1872 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1874 *pwHotkey
=This
->wHotKey
;
1879 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1881 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1883 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1885 This
->wHotKey
= wHotkey
;
1886 This
->bDirty
= TRUE
;
1891 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1893 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1895 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1897 *piShowCmd
= This
->iShowCmd
;
1902 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1904 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1906 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1908 This
->iShowCmd
= iShowCmd
;
1909 This
->bDirty
= TRUE
;
1914 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1916 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1918 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1920 *piIcon
= This
->iIcoNdx
;
1923 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1930 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1932 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1934 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1936 heap_free(This
->sIcoPath
);
1937 This
->sIcoPath
= heap_alloc((lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1938 if ( !This
->sIcoPath
)
1939 return E_OUTOFMEMORY
;
1940 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1942 This
->iIcoNdx
= iIcon
;
1943 This
->bDirty
= TRUE
;
1948 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1950 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1952 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1954 heap_free(This
->sPathRel
);
1955 This
->sPathRel
= heap_alloc((lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1956 if ( !This
->sPathRel
)
1957 return E_OUTOFMEMORY
;
1958 lstrcpyW( This
->sPathRel
, pszPathRel
);
1959 This
->bDirty
= TRUE
;
1961 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1964 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1969 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1971 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1973 /*FIXME: use IResolveShellLink interface */
1975 if (!This
->sPath
&& This
->pPidl
) {
1976 WCHAR buffer
[MAX_PATH
];
1978 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1980 if (bSuccess
&& *buffer
) {
1981 This
->sPath
= heap_alloc((lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1983 return E_OUTOFMEMORY
;
1985 lstrcpyW(This
->sPath
, buffer
);
1987 This
->bDirty
= TRUE
;
1989 hr
= S_OK
; /* don't report an error occurred while just caching information */
1992 if (!This
->sIcoPath
&& This
->sPath
) {
1993 This
->sIcoPath
= heap_alloc((lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1994 if (!This
->sIcoPath
)
1995 return E_OUTOFMEMORY
;
1997 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2000 This
->bDirty
= TRUE
;
2006 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2015 p
= strchrW( str
, ':' );
2019 ret
= heap_alloc(sizeof(WCHAR
)*(len
+1));
2022 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2027 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2029 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2037 /* each segment must start with two colons */
2038 if( str
[0] != ':' || str
[1] != ':' )
2041 /* the last segment is just two colons */
2046 /* there must be a colon straight after a guid */
2047 p
= strchrW( str
, ':' );
2054 /* get the guid, and check it's validly formatted */
2055 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2057 r
= CLSIDFromString( szGuid
, &guid
);
2062 /* match it up to a guid that we care about */
2063 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2065 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2070 /* skip to the next field */
2071 str
= strchrW( str
, ':' );
2076 /* we have to have a component for an advertised shortcut */
2080 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2081 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2083 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2084 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2089 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2091 const int label_sz
= ARRAY_SIZE(volume
->label
);
2092 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2095 volume
->type
= GetDriveTypeW(drive
);
2096 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2097 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2098 TRACE("r = %d type %d serial %08x name %s\n", r
,
2099 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2103 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2105 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2106 WCHAR buffer
[MAX_PATH
];
2107 LPWSTR fname
, unquoted
= NULL
;
2111 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2113 if (!pszFile
) return E_INVALIDARG
;
2115 /* quotes at the ends of the string are stripped */
2116 len
= lstrlenW(pszFile
);
2117 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2119 unquoted
= strdupW(pszFile
);
2120 PathUnquoteSpacesW(unquoted
);
2124 /* any other quote marks are invalid */
2125 if (strchrW(pszFile
, '"'))
2127 heap_free(unquoted
);
2131 heap_free(This
->sPath
);
2134 heap_free(This
->sComponent
);
2135 This
->sComponent
= NULL
;
2138 ILFree(This
->pPidl
);
2141 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2143 if (*pszFile
== '\0')
2145 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
= heap_alloc( (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2157 heap_free(unquoted
);
2158 return E_OUTOFMEMORY
;
2161 lstrcpyW(This
->sPath
, buffer
);
2163 This
->bDirty
= TRUE
;
2164 heap_free(unquoted
);
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 %08x %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 %08x\n", dwSig
);
2251 ERR("unknown datablock %08x\n", dwSig
);
2253 *ppDataBlock
= block
;
2257 static HRESULT WINAPI
2258 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2260 FIXME("(%p)->(%u): 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)->(%u): 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
.u
.hGlobal
, -1, NULL
, 0 );
2363 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2365 path
= heap_alloc(count
*sizeof(WCHAR
) );
2368 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2370 count
= DragQueryFileW( stgm
.u
.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
);
2414 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2418 TRACE("%p %p %u %u %u %u\n", This
,
2419 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2422 return E_INVALIDARG
;
2424 memset( &mii
, 0, sizeof mii
);
2425 mii
.cbSize
= sizeof mii
;
2426 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2427 mii
.dwTypeData
= szOpen
;
2428 mii
.cch
= strlenW( mii
.dwTypeData
);
2429 mii
.wID
= idCmdFirst
+ id
++;
2430 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2431 mii
.fType
= MFT_STRING
;
2432 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2436 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2440 shelllink_get_msi_component_path( LPWSTR component
)
2445 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2446 if (r
!= ERROR_SUCCESS
)
2450 path
= heap_alloc( sz
*sizeof(WCHAR
) );
2451 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2452 if (r
!= ERROR_SUCCESS
)
2458 TRACE("returning %s\n", debugstr_w( path
) );
2463 static HRESULT WINAPI
2464 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2466 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2467 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2468 SHELLEXECUTEINFOW sei
;
2469 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2474 TRACE("%p %p\n", This
, lpici
);
2476 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2477 return E_INVALIDARG
;
2479 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2481 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2482 return E_INVALIDARG
;
2485 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2489 if ( This
->sComponent
)
2491 path
= shelllink_get_msi_component_path( This
->sComponent
);
2496 path
= strdupW( This
->sPath
);
2498 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2499 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2501 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2505 len
+= lstrlenW( This
->sArgs
);
2506 if ( iciex
->lpParametersW
)
2507 len
+= lstrlenW( iciex
->lpParametersW
);
2509 args
= heap_alloc( len
*sizeof(WCHAR
) );
2512 lstrcatW( args
, This
->sArgs
);
2513 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2515 static const WCHAR space
[] = { ' ', 0 };
2516 lstrcatW( args
, space
);
2517 lstrcatW( args
, iciex
->lpParametersW
);
2521 memset( &sei
, 0, sizeof sei
);
2522 sei
.cbSize
= sizeof sei
;
2523 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2525 sei
.nShow
= This
->iShowCmd
;
2526 sei
.lpIDList
= This
->pPidl
;
2527 sei
.lpDirectory
= This
->sWorkDir
;
2528 sei
.lpParameters
= args
;
2529 sei
.lpVerb
= szOpen
;
2531 if( ShellExecuteExW( &sei
) )
2542 static HRESULT WINAPI
2543 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2544 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2546 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2548 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This
,
2549 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2554 static const IContextMenuVtbl cmvt
=
2556 ShellLink_ContextMenu_QueryInterface
,
2557 ShellLink_ContextMenu_AddRef
,
2558 ShellLink_ContextMenu_Release
,
2559 ShellLink_QueryContextMenu
,
2560 ShellLink_InvokeCommand
,
2561 ShellLink_GetCommandString
2564 static HRESULT WINAPI
2565 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2567 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2568 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2572 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2574 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2575 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2579 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2581 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2582 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2585 static HRESULT WINAPI
2586 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2588 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2590 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2594 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2597 static HRESULT WINAPI
2598 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2600 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2602 TRACE("%p %p\n", iface
, punk
);
2605 IUnknown_AddRef( punk
);
2608 IUnknown_Release( This
->site
);
2615 static const IObjectWithSiteVtbl owsvt
=
2617 ShellLink_ObjectWithSite_QueryInterface
,
2618 ShellLink_ObjectWithSite_AddRef
,
2619 ShellLink_ObjectWithSite_Release
,
2624 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2626 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2627 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2630 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2632 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2633 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2636 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2638 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2639 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2642 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2644 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2645 FIXME("(%p)->(%p): stub\n", This
, props
);
2649 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2651 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2652 FIXME("(%p)->(%d %p): stub\n", This
, propid
, key
);
2656 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2658 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2659 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2663 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2665 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2666 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2670 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2672 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2673 FIXME("(%p): stub\n", This
);
2677 static const IPropertyStoreVtbl propertystorevtbl
= {
2678 propertystore_QueryInterface
,
2679 propertystore_AddRef
,
2680 propertystore_Release
,
2681 propertystore_GetCount
,
2682 propertystore_GetAt
,
2683 propertystore_GetValue
,
2684 propertystore_SetValue
,
2685 propertystore_Commit
2688 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2690 IShellLinkImpl
* sl
;
2693 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2698 return CLASS_E_NOAGGREGATION
;
2700 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2702 return E_OUTOFMEMORY
;
2705 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2706 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2707 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2708 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2709 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2710 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2711 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2712 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2713 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2714 sl
->iShowCmd
= SW_SHOWNORMAL
;
2718 sl
->filepath
= NULL
;
2720 TRACE("(%p)\n", sl
);
2722 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2723 IShellLinkW_Release( &sl
->IShellLinkW_iface
);