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 path
, INT icon
)
1469 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1470 WCHAR
*pathW
= NULL
;
1473 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_a(path
), icon
);
1477 pathW
= heap_strdupAtoW(path
);
1479 return E_OUTOFMEMORY
;
1482 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, path
? pathW
: NULL
, icon
);
1488 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1491 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1495 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1497 pathW
= heap_strdupAtoW(pszPathRel
);
1498 if (!pathW
) return E_OUTOFMEMORY
;
1500 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1506 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1508 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1510 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1512 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1515 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1517 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1521 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1523 if (!pszFile
) return E_INVALIDARG
;
1525 str
= heap_strdupAtoW(pszFile
);
1527 return E_OUTOFMEMORY
;
1529 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1535 /**************************************************************************
1536 * IShellLink Implementation
1539 static const IShellLinkAVtbl slvt
=
1541 IShellLinkA_fnQueryInterface
,
1542 IShellLinkA_fnAddRef
,
1543 IShellLinkA_fnRelease
,
1544 IShellLinkA_fnGetPath
,
1545 IShellLinkA_fnGetIDList
,
1546 IShellLinkA_fnSetIDList
,
1547 IShellLinkA_fnGetDescription
,
1548 IShellLinkA_fnSetDescription
,
1549 IShellLinkA_fnGetWorkingDirectory
,
1550 IShellLinkA_fnSetWorkingDirectory
,
1551 IShellLinkA_fnGetArguments
,
1552 IShellLinkA_fnSetArguments
,
1553 IShellLinkA_fnGetHotkey
,
1554 IShellLinkA_fnSetHotkey
,
1555 IShellLinkA_fnGetShowCmd
,
1556 IShellLinkA_fnSetShowCmd
,
1557 IShellLinkA_fnGetIconLocation
,
1558 IShellLinkA_fnSetIconLocation
,
1559 IShellLinkA_fnSetRelativePath
,
1560 IShellLinkA_fnResolve
,
1561 IShellLinkA_fnSetPath
1565 /**************************************************************************
1566 * IShellLinkW_fnQueryInterface
1568 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1569 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1571 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1573 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1577 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1579 *ppvObj
= &This
->IShellLinkA_iface
;
1581 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1583 *ppvObj
= &This
->IShellLinkW_iface
;
1585 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1587 *ppvObj
= &This
->IPersistFile_iface
;
1589 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1591 *ppvObj
= &This
->IPersistStream_iface
;
1593 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1595 *ppvObj
= &This
->IShellLinkDataList_iface
;
1597 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1599 *ppvObj
= &This
->IShellExtInit_iface
;
1601 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1603 *ppvObj
= &This
->IContextMenu_iface
;
1605 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1607 *ppvObj
= &This
->IObjectWithSite_iface
;
1609 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1611 *ppvObj
= &This
->IPropertyStore_iface
;
1616 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1617 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1620 ERR("-- Interface: E_NOINTERFACE\n");
1621 return E_NOINTERFACE
;
1624 /******************************************************************************
1625 * IShellLinkW_fnAddRef
1627 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1629 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1630 ULONG ref
= InterlockedIncrement(&This
->ref
);
1632 TRACE("(%p)->(count=%u)\n", This
, ref
- 1);
1637 /******************************************************************************
1638 * IShellLinkW_fnRelease
1640 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1642 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1643 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1645 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
1650 TRACE("-- destroying IShellLink(%p)\n",This
);
1652 heap_free(This
->sIcoPath
);
1653 heap_free(This
->sArgs
);
1654 heap_free(This
->sWorkDir
);
1655 heap_free(This
->sDescription
);
1656 heap_free(This
->sPath
);
1657 heap_free(This
->sPathRel
);
1658 heap_free(This
->sProduct
);
1659 heap_free(This
->sComponent
);
1660 heap_free(This
->filepath
);
1663 IUnknown_Release( This
->site
);
1666 ILFree(This
->pPidl
);
1673 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1675 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1678 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1679 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1681 if (This
->sComponent
|| This
->sProduct
)
1687 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1693 memset(pfd
, 0, sizeof(*pfd
));
1697 WCHAR path
[MAX_PATH
];
1698 WIN32_FILE_ATTRIBUTE_DATA fad
;
1700 if (GetFileAttributesExW(This
->sPath
, GetFileExInfoStandard
, &fad
))
1702 pfd
->dwFileAttributes
= fad
.dwFileAttributes
;
1703 pfd
->ftCreationTime
= fad
.ftCreationTime
;
1704 pfd
->ftLastAccessTime
= fad
.ftLastAccessTime
;
1705 pfd
->ftLastWriteTime
= fad
.ftLastWriteTime
;
1706 pfd
->nFileSizeHigh
= fad
.nFileSizeHigh
;
1707 pfd
->nFileSizeLow
= fad
.nFileSizeLow
;
1710 lstrcpyW(pfd
->cFileName
, PathFindFileNameW(This
->sPath
));
1712 if (GetShortPathNameW(This
->sPath
, path
, MAX_PATH
))
1714 lstrcpyW(pfd
->cAlternateFileName
, PathFindFileNameW(path
));
1718 TRACE("attr 0x%08x size 0x%08x%08x name %s shortname %s\n", pfd
->dwFileAttributes
,
1719 pfd
->nFileSizeHigh
, pfd
->nFileSizeLow
, wine_dbgstr_w(pfd
->cFileName
),
1720 wine_dbgstr_w(pfd
->cAlternateFileName
));
1726 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1728 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1730 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1737 *ppidl
= ILClone(This
->pPidl
);
1741 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1743 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1744 WCHAR path
[MAX_PATH
];
1746 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1749 ILFree( This
->pPidl
);
1750 This
->pPidl
= ILClone( pidl
);
1754 heap_free( This
->sPath
);
1757 if ( SHGetPathFromIDListW( pidl
, path
) )
1759 This
->sPath
= heap_alloc((lstrlenW(path
) + 1) * sizeof(WCHAR
));
1761 return E_OUTOFMEMORY
;
1763 lstrcpyW(This
->sPath
, path
);
1766 This
->bDirty
= TRUE
;
1771 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1773 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1775 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1778 if( This
->sDescription
)
1779 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1784 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1786 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1788 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1790 heap_free(This
->sDescription
);
1793 This
->sDescription
= heap_alloc((lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1794 if ( !This
->sDescription
)
1795 return E_OUTOFMEMORY
;
1797 lstrcpyW( This
->sDescription
, pszName
);
1800 This
->sDescription
= NULL
;
1801 This
->bDirty
= TRUE
;
1806 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1808 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1810 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1814 if( This
->sWorkDir
)
1815 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1820 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1822 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1824 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1826 heap_free(This
->sWorkDir
);
1827 This
->sWorkDir
= heap_alloc((lstrlenW( pszDir
) + 1) * sizeof (WCHAR
) );
1828 if ( !This
->sWorkDir
)
1829 return E_OUTOFMEMORY
;
1830 lstrcpyW( This
->sWorkDir
, pszDir
);
1831 This
->bDirty
= TRUE
;
1836 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1838 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1840 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1845 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1850 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1852 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1854 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1856 heap_free(This
->sArgs
);
1859 This
->sArgs
= heap_alloc((lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1861 return E_OUTOFMEMORY
;
1862 lstrcpyW( This
->sArgs
, pszArgs
);
1864 else This
->sArgs
= NULL
;
1866 This
->bDirty
= TRUE
;
1871 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1873 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1875 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1877 *pwHotkey
=This
->wHotKey
;
1882 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1884 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1886 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1888 This
->wHotKey
= wHotkey
;
1889 This
->bDirty
= TRUE
;
1894 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1896 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1898 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1900 *piShowCmd
= This
->iShowCmd
;
1905 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1907 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1909 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1911 This
->iShowCmd
= iShowCmd
;
1912 This
->bDirty
= TRUE
;
1917 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1919 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1921 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1923 *piIcon
= This
->iIcoNdx
;
1926 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1933 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, const WCHAR
*path
, INT icon
)
1935 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1937 TRACE("(%p)->(path=%s icon=%u)\n", This
, debugstr_w(path
), icon
);
1939 heap_free(This
->sIcoPath
);
1942 size_t len
= (strlenW(path
) + 1) * sizeof(WCHAR
);
1943 This
->sIcoPath
= heap_alloc(len
);
1944 if (!This
->sIcoPath
)
1945 return E_OUTOFMEMORY
;
1946 memcpy(This
->sIcoPath
, path
, len
);
1949 This
->sIcoPath
= NULL
;
1950 This
->iIcoNdx
= icon
;
1951 This
->bDirty
= TRUE
;
1956 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1958 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1960 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1962 heap_free(This
->sPathRel
);
1963 This
->sPathRel
= heap_alloc((lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1964 if ( !This
->sPathRel
)
1965 return E_OUTOFMEMORY
;
1966 lstrcpyW( This
->sPathRel
, pszPathRel
);
1967 This
->bDirty
= TRUE
;
1969 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1972 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1977 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1979 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1981 /*FIXME: use IResolveShellLink interface */
1983 if (!This
->sPath
&& This
->pPidl
) {
1984 WCHAR buffer
[MAX_PATH
];
1986 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1988 if (bSuccess
&& *buffer
) {
1989 This
->sPath
= heap_alloc((lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1991 return E_OUTOFMEMORY
;
1993 lstrcpyW(This
->sPath
, buffer
);
1995 This
->bDirty
= TRUE
;
1997 hr
= S_OK
; /* don't report an error occurred while just caching information */
2000 if (!This
->sIcoPath
&& This
->sPath
) {
2001 This
->sIcoPath
= heap_alloc((lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2002 if (!This
->sIcoPath
)
2003 return E_OUTOFMEMORY
;
2005 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2008 This
->bDirty
= TRUE
;
2014 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2023 p
= strchrW( str
, ':' );
2027 ret
= heap_alloc(sizeof(WCHAR
)*(len
+1));
2030 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2035 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2037 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2045 /* each segment must start with two colons */
2046 if( str
[0] != ':' || str
[1] != ':' )
2049 /* the last segment is just two colons */
2054 /* there must be a colon straight after a guid */
2055 p
= strchrW( str
, ':' );
2062 /* get the guid, and check it's validly formatted */
2063 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2065 r
= CLSIDFromString( szGuid
, &guid
);
2070 /* match it up to a guid that we care about */
2071 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2073 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2078 /* skip to the next field */
2079 str
= strchrW( str
, ':' );
2084 /* we have to have a component for an advertised shortcut */
2088 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2089 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2091 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2092 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2097 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2099 const int label_sz
= ARRAY_SIZE(volume
->label
);
2100 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2103 volume
->type
= GetDriveTypeW(drive
);
2104 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2105 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2106 TRACE("r = %d type %d serial %08x name %s\n", r
,
2107 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2111 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2113 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2114 WCHAR buffer
[MAX_PATH
];
2115 LPWSTR fname
, unquoted
= NULL
;
2119 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2121 if (!pszFile
) return E_INVALIDARG
;
2123 /* quotes at the ends of the string are stripped */
2124 len
= lstrlenW(pszFile
);
2125 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2127 unquoted
= strdupW(pszFile
);
2128 PathUnquoteSpacesW(unquoted
);
2132 /* any other quote marks are invalid */
2133 if (strchrW(pszFile
, '"'))
2135 heap_free(unquoted
);
2139 heap_free(This
->sPath
);
2142 heap_free(This
->sComponent
);
2143 This
->sComponent
= NULL
;
2146 ILFree(This
->pPidl
);
2149 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2151 if (*pszFile
== '\0')
2153 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2155 else if(!PathFileExistsW(buffer
) &&
2156 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2159 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2160 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2162 This
->sPath
= heap_alloc( (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2165 heap_free(unquoted
);
2166 return E_OUTOFMEMORY
;
2169 lstrcpyW(This
->sPath
, buffer
);
2171 This
->bDirty
= TRUE
;
2172 heap_free(unquoted
);
2177 /**************************************************************************
2178 * IShellLinkW Implementation
2181 static const IShellLinkWVtbl slvtw
=
2183 IShellLinkW_fnQueryInterface
,
2184 IShellLinkW_fnAddRef
,
2185 IShellLinkW_fnRelease
,
2186 IShellLinkW_fnGetPath
,
2187 IShellLinkW_fnGetIDList
,
2188 IShellLinkW_fnSetIDList
,
2189 IShellLinkW_fnGetDescription
,
2190 IShellLinkW_fnSetDescription
,
2191 IShellLinkW_fnGetWorkingDirectory
,
2192 IShellLinkW_fnSetWorkingDirectory
,
2193 IShellLinkW_fnGetArguments
,
2194 IShellLinkW_fnSetArguments
,
2195 IShellLinkW_fnGetHotkey
,
2196 IShellLinkW_fnSetHotkey
,
2197 IShellLinkW_fnGetShowCmd
,
2198 IShellLinkW_fnSetShowCmd
,
2199 IShellLinkW_fnGetIconLocation
,
2200 IShellLinkW_fnSetIconLocation
,
2201 IShellLinkW_fnSetRelativePath
,
2202 IShellLinkW_fnResolve
,
2203 IShellLinkW_fnSetPath
2206 static HRESULT WINAPI
2207 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2209 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2210 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2214 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2216 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2217 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2221 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2223 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2224 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2227 static HRESULT WINAPI
2228 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2230 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2234 static HRESULT WINAPI
2235 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2237 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2238 LPVOID block
= NULL
;
2241 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2245 case EXP_DARWIN_ID_SIG
:
2246 if (!This
->sComponent
)
2248 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2251 case EXP_SZ_LINK_SIG
:
2252 case NT_CONSOLE_PROPS_SIG
:
2253 case NT_FE_CONSOLE_PROPS_SIG
:
2254 case EXP_SPECIAL_FOLDER_SIG
:
2255 case EXP_SZ_ICON_SIG
:
2256 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2259 ERR("unknown datablock %08x\n", dwSig
);
2261 *ppDataBlock
= block
;
2265 static HRESULT WINAPI
2266 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2268 FIXME("(%p)->(%u): stub\n", iface
, dwSig
);
2272 static HRESULT WINAPI
2273 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2275 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2278 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2280 /* FIXME: add more */
2282 flags
|= SLDF_HAS_ARGS
;
2283 if (This
->sComponent
)
2284 flags
|= SLDF_HAS_DARWINID
;
2286 flags
|= SLDF_HAS_ICONLOCATION
;
2288 flags
|= SLDF_HAS_LOGO3ID
;
2290 flags
|= SLDF_HAS_ID_LIST
;
2297 static HRESULT WINAPI
2298 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2300 FIXME("(%p)->(%u): stub\n", iface
, dwFlags
);
2304 static const IShellLinkDataListVtbl dlvt
=
2306 ShellLink_DataList_QueryInterface
,
2307 ShellLink_DataList_AddRef
,
2308 ShellLink_DataList_Release
,
2309 ShellLink_AddDataBlock
,
2310 ShellLink_CopyDataBlock
,
2311 ShellLink_RemoveDataBlock
,
2316 static HRESULT WINAPI
2317 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2319 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2320 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2324 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2326 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2327 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2331 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2333 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2334 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2337 /**************************************************************************
2338 * ShellLink implementation of IShellExtInit::Initialize()
2340 * Loads the shelllink from the dataobject the shell is pointing to.
2342 static HRESULT WINAPI
2343 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2344 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2346 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2352 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2357 format
.cfFormat
= CF_HDROP
;
2359 format
.dwAspect
= DVASPECT_CONTENT
;
2361 format
.tymed
= TYMED_HGLOBAL
;
2363 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2366 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2371 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2373 path
= heap_alloc(count
*sizeof(WCHAR
) );
2376 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2378 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2379 r
= IPersistFile_Load( pf
, path
, 0 );
2383 ReleaseStgMedium( &stgm
);
2388 static const IShellExtInitVtbl eivt
=
2390 ShellLink_ExtInit_QueryInterface
,
2391 ShellLink_ExtInit_AddRef
,
2392 ShellLink_ExtInit_Release
,
2393 ShellLink_ExtInit_Initialize
2396 static HRESULT WINAPI
2397 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2399 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2400 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2404 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2406 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2407 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2411 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2413 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2414 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2417 static HRESULT WINAPI
2418 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2419 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2421 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2422 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2426 TRACE("%p %p %u %u %u %u\n", This
,
2427 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2430 return E_INVALIDARG
;
2432 memset( &mii
, 0, sizeof mii
);
2433 mii
.cbSize
= sizeof mii
;
2434 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2435 mii
.dwTypeData
= szOpen
;
2436 mii
.cch
= strlenW( mii
.dwTypeData
);
2437 mii
.wID
= idCmdFirst
+ id
++;
2438 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2439 mii
.fType
= MFT_STRING
;
2440 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2444 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2448 shelllink_get_msi_component_path( LPWSTR component
)
2453 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2454 if (r
!= ERROR_SUCCESS
)
2458 path
= heap_alloc( sz
*sizeof(WCHAR
) );
2459 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2460 if (r
!= ERROR_SUCCESS
)
2466 TRACE("returning %s\n", debugstr_w( path
) );
2471 static HRESULT WINAPI
2472 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2474 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2475 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2476 SHELLEXECUTEINFOW sei
;
2477 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2482 TRACE("%p %p\n", This
, lpici
);
2484 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2485 return E_INVALIDARG
;
2487 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2489 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2490 return E_INVALIDARG
;
2493 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2497 if ( This
->sComponent
)
2499 path
= shelllink_get_msi_component_path( This
->sComponent
);
2504 path
= strdupW( This
->sPath
);
2506 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2507 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2509 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2513 len
+= lstrlenW( This
->sArgs
);
2514 if ( iciex
->lpParametersW
)
2515 len
+= lstrlenW( iciex
->lpParametersW
);
2517 args
= heap_alloc( len
*sizeof(WCHAR
) );
2520 lstrcatW( args
, This
->sArgs
);
2521 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2523 static const WCHAR space
[] = { ' ', 0 };
2524 lstrcatW( args
, space
);
2525 lstrcatW( args
, iciex
->lpParametersW
);
2529 memset( &sei
, 0, sizeof sei
);
2530 sei
.cbSize
= sizeof sei
;
2531 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2533 sei
.nShow
= This
->iShowCmd
;
2534 sei
.lpIDList
= This
->pPidl
;
2535 sei
.lpDirectory
= This
->sWorkDir
;
2536 sei
.lpParameters
= args
;
2537 sei
.lpVerb
= szOpen
;
2539 if( ShellExecuteExW( &sei
) )
2550 static HRESULT WINAPI
2551 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2552 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2554 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2556 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This
,
2557 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2562 static const IContextMenuVtbl cmvt
=
2564 ShellLink_ContextMenu_QueryInterface
,
2565 ShellLink_ContextMenu_AddRef
,
2566 ShellLink_ContextMenu_Release
,
2567 ShellLink_QueryContextMenu
,
2568 ShellLink_InvokeCommand
,
2569 ShellLink_GetCommandString
2572 static HRESULT WINAPI
2573 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2575 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2576 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2580 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2582 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2583 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2587 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2589 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2590 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2593 static HRESULT WINAPI
2594 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2596 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2598 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2602 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2605 static HRESULT WINAPI
2606 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2608 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2610 TRACE("%p %p\n", iface
, punk
);
2613 IUnknown_AddRef( punk
);
2616 IUnknown_Release( This
->site
);
2623 static const IObjectWithSiteVtbl owsvt
=
2625 ShellLink_ObjectWithSite_QueryInterface
,
2626 ShellLink_ObjectWithSite_AddRef
,
2627 ShellLink_ObjectWithSite_Release
,
2632 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2634 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2635 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2638 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2640 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2641 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2644 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2646 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2647 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2650 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2652 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2653 FIXME("(%p)->(%p): stub\n", This
, props
);
2657 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2659 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2660 FIXME("(%p)->(%d %p): stub\n", This
, propid
, key
);
2664 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2666 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2667 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2671 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2673 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2674 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2678 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2680 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2681 FIXME("(%p): stub\n", This
);
2685 static const IPropertyStoreVtbl propertystorevtbl
= {
2686 propertystore_QueryInterface
,
2687 propertystore_AddRef
,
2688 propertystore_Release
,
2689 propertystore_GetCount
,
2690 propertystore_GetAt
,
2691 propertystore_GetValue
,
2692 propertystore_SetValue
,
2693 propertystore_Commit
2696 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2698 IShellLinkImpl
* sl
;
2701 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2706 return CLASS_E_NOAGGREGATION
;
2708 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2710 return E_OUTOFMEMORY
;
2713 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2714 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2715 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2716 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2717 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2718 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2719 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2720 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2721 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2722 sl
->iShowCmd
= SW_SHOWNORMAL
;
2726 sl
->filepath
= NULL
;
2728 TRACE("(%p)\n", sl
);
2730 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2731 IShellLinkW_Release( &sl
->IShellLinkW_iface
);