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 static const IShellLinkAVtbl slvt
;
119 static const IShellLinkWVtbl slvtw
;
120 static const IPersistFileVtbl pfvt
;
121 static const IPersistStreamVtbl psvt
;
122 static const IShellLinkDataListVtbl dlvt
;
123 static const IShellExtInitVtbl eivt
;
124 static const IContextMenuVtbl cmvt
;
125 static const IObjectWithSiteVtbl owsvt
;
127 /* IShellLink Implementation */
131 IShellLinkA IShellLinkA_iface
;
132 IShellLinkW IShellLinkW_iface
;
133 IPersistFile IPersistFile_iface
;
134 IPersistStream IPersistStream_iface
;
135 IShellLinkDataList IShellLinkDataList_iface
;
136 IShellExtInit IShellExtInit_iface
;
137 IContextMenu IContextMenu_iface
;
138 IObjectWithSite IObjectWithSite_iface
;
142 /* data structures according to the information in the link */
162 INT iIdOpen
; /* id of the "Open" entry in the context menu */
165 LPOLESTR filepath
; /* file path returned by IPersistFile::GetCurFile */
168 static inline IShellLinkImpl
*impl_from_IShellLinkA(IShellLinkA
*iface
)
170 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkA_iface
);
173 static inline IShellLinkImpl
*impl_from_IShellLinkW(IShellLinkW
*iface
)
175 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkW_iface
);
178 static inline IShellLinkImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
180 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistFile_iface
);
183 static inline IShellLinkImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
185 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistStream_iface
);
188 static inline IShellLinkImpl
*impl_from_IShellLinkDataList(IShellLinkDataList
*iface
)
190 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkDataList_iface
);
193 static inline IShellLinkImpl
*impl_from_IShellExtInit(IShellExtInit
*iface
)
195 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellExtInit_iface
);
198 static inline IShellLinkImpl
*impl_from_IContextMenu(IContextMenu
*iface
)
200 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IContextMenu_iface
);
203 static inline IShellLinkImpl
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
205 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IObjectWithSite_iface
);
208 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
210 /* strdup on the process heap */
211 static inline LPWSTR
heap_strdupAtoW( LPCSTR str
)
213 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
214 LPWSTR p
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof (WCHAR
) );
217 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
221 static inline LPWSTR
strdupW( LPCWSTR src
)
224 if (!src
) return NULL
;
225 dest
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(src
)+1)*sizeof(WCHAR
) );
231 /**************************************************************************
232 * IPersistFile_QueryInterface
234 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
239 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
240 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
243 /******************************************************************************
244 * IPersistFile_AddRef
246 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
248 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
249 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
252 /******************************************************************************
253 * IPersistFile_Release
255 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
257 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
258 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
261 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
263 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
265 TRACE("(%p)->(%p)\n", This
, pClassID
);
267 *pClassID
= CLSID_ShellLink
;
272 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
274 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
276 TRACE("(%p)\n",This
);
284 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
286 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
287 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
291 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
294 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
295 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
298 r
= IPersistStream_Load(StreamThis
, stm
);
299 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
300 IStream_Release( stm
);
302 /* update file path */
303 HeapFree(GetProcessHeap(), 0, This
->filepath
);
304 This
->filepath
= strdupW(pszFileName
);
306 This
->bDirty
= FALSE
;
308 TRACE("-- returning hr %08x\n", r
);
312 BOOL
run_winemenubuilder( const WCHAR
*args
)
314 static const WCHAR menubuilder
[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
318 PROCESS_INFORMATION pi
;
323 GetSystemDirectoryW( app
, MAX_PATH
- sizeof(menubuilder
)/sizeof(WCHAR
) );
324 strcatW( app
, menubuilder
);
326 len
= (strlenW( app
) + strlenW( args
) + 1) * sizeof(WCHAR
);
327 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
331 strcpyW( buffer
, app
);
332 strcatW( buffer
, args
);
334 TRACE("starting %s\n",debugstr_w(buffer
));
336 memset(&si
, 0, sizeof(si
));
339 Wow64DisableWow64FsRedirection( &redir
);
340 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
341 Wow64RevertWow64FsRedirection( redir
);
343 HeapFree( GetProcessHeap(), 0, buffer
);
347 CloseHandle( pi
.hProcess
);
348 CloseHandle( pi
.hThread
);
354 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
356 static const WCHAR szFormat
[] = {' ','-','w',' ','"','%','s','"',0 };
361 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
362 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
366 wsprintfW( buffer
, szFormat
, szLink
);
367 ret
= run_winemenubuilder( buffer
);
368 HeapFree( GetProcessHeap(), 0, buffer
);
372 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
374 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
375 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
379 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
384 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
387 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
388 IStream_Release( stm
);
392 StartLinkProcessor( pszFileName
);
394 /* update file path */
395 HeapFree(GetProcessHeap(), 0, This
->filepath
);
396 This
->filepath
= strdupW(pszFileName
);
398 This
->bDirty
= FALSE
;
402 DeleteFileW( pszFileName
);
403 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
410 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
412 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
413 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
417 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
419 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
422 TRACE("(%p)->(%p)\n", This
, filename
);
430 SHGetMalloc(&pMalloc
);
431 *filename
= IMalloc_Alloc(pMalloc
, (strlenW(This
->filepath
)+1)*sizeof(WCHAR
));
432 if (!*filename
) return E_OUTOFMEMORY
;
434 strcpyW(*filename
, This
->filepath
);
439 static const IPersistFileVtbl pfvt
=
441 IPersistFile_fnQueryInterface
,
442 IPersistFile_fnAddRef
,
443 IPersistFile_fnRelease
,
444 IPersistFile_fnGetClassID
,
445 IPersistFile_fnIsDirty
,
448 IPersistFile_fnSaveCompleted
,
449 IPersistFile_fnGetCurFile
452 /************************************************************************
453 * IPersistStream_QueryInterface
455 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
456 IPersistStream
* iface
,
460 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
461 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
464 /************************************************************************
465 * IPersistStream_Release
467 static ULONG WINAPI
IPersistStream_fnRelease(
468 IPersistStream
* iface
)
470 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
471 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
474 /************************************************************************
475 * IPersistStream_AddRef
477 static ULONG WINAPI
IPersistStream_fnAddRef(
478 IPersistStream
* iface
)
480 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
481 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
484 /************************************************************************
485 * IPersistStream_GetClassID
488 static HRESULT WINAPI
IPersistStream_fnGetClassID(
489 IPersistStream
* iface
,
492 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
493 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
496 /************************************************************************
497 * IPersistStream_IsDirty (IPersistStream)
499 static HRESULT WINAPI
IPersistStream_fnIsDirty(
500 IPersistStream
* iface
)
502 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
504 TRACE("(%p)\n", This
);
510 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
521 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
522 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
526 len
*= sizeof (WCHAR
);
528 TRACE("reading %d\n", len
);
529 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
531 return E_OUTOFMEMORY
;
533 r
= IStream_Read(stm
, temp
, len
, &count
);
534 if( FAILED (r
) || ( count
!= len
) )
536 HeapFree( GetProcessHeap(), 0, temp
);
540 TRACE("read %s\n", debugstr_an(temp
,len
));
542 /* convert to unicode if necessary */
545 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
546 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
549 HeapFree( GetProcessHeap(), 0, temp
);
550 return E_OUTOFMEMORY
;
552 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
553 HeapFree( GetProcessHeap(), 0, temp
);
567 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
574 unsigned char data
[1];
579 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
580 if( FAILED( r
) || count
!= sizeof(size
) )
583 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
585 return E_OUTOFMEMORY
;
588 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
589 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
591 HeapFree( GetProcessHeap(), 0, chunk
);
595 TRACE("Read %d bytes\n",chunk
->size
);
602 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
604 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
608 volume
->serial
= vol
->dwVolSerial
;
609 volume
->type
= vol
->dwType
;
611 if( !vol
->dwVolLabelOfs
)
613 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
615 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
618 label
+= vol
->dwVolLabelOfs
;
619 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
624 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
629 while( p
[len
] && (len
< maxlen
) )
632 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
633 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
634 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
640 static HRESULT
Stream_LoadLocation( IStream
*stm
,
641 volume_info
*volume
, LPWSTR
*path
)
648 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
652 loc
= (LOCATION_INFO
*) p
;
653 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
655 HeapFree( GetProcessHeap(), 0, p
);
659 /* if there's valid local volume information, load it */
660 if( loc
->dwVolTableOfs
&&
661 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
663 LOCAL_VOLUME_INFO
*volume_info
;
665 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
666 Stream_LoadVolume( volume_info
, volume
);
669 /* if there's a local path, load it */
670 n
= loc
->dwLocalPathOfs
;
671 if( n
&& (n
< loc
->dwTotalSize
) )
672 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
674 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
675 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
677 HeapFree( GetProcessHeap(), 0, p
);
682 * The format of the advertised shortcut info seems to be:
687 * 0 Length of the block (4 bytes, usually 0x314)
689 * 8 string data in ASCII
690 * 8+0x104 string data in UNICODE
692 * In the original Win32 implementation the buffers are not initialized
693 * to zero, so data trailing the string is random garbage.
695 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
700 EXP_DARWIN_LINK buffer
;
704 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
708 /* make sure that we read the size of the structure even on error */
709 size
= sizeof buffer
- sizeof (DWORD
);
710 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
712 ERR("Ooops. This structure is not as expected...\n");
716 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
723 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
725 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
727 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
731 *str
= HeapAlloc( GetProcessHeap(), 0,
732 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
733 lstrcpyW( *str
, buffer
.szwDarwinID
);
738 /************************************************************************
739 * IPersistStream_Load (IPersistStream)
741 static HRESULT WINAPI
IPersistStream_fnLoad(
742 IPersistStream
* iface
,
751 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
753 TRACE("%p %p\n", This
, stm
);
756 return STG_E_INVALIDPOINTER
;
759 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
763 if( dwBytesRead
!= sizeof(hdr
))
765 if( hdr
.dwSize
!= sizeof(hdr
))
767 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
770 /* free all the old stuff */
773 memset( &This
->volume
, 0, sizeof This
->volume
);
774 HeapFree(GetProcessHeap(), 0, This
->sPath
);
776 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
777 This
->sDescription
= NULL
;
778 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
779 This
->sPathRel
= NULL
;
780 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
781 This
->sWorkDir
= NULL
;
782 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
784 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
785 This
->sIcoPath
= NULL
;
786 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
787 This
->sProduct
= NULL
;
788 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
789 This
->sComponent
= NULL
;
791 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
792 This
->iIcoNdx
= hdr
.nIcon
;
793 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
794 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
795 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
798 WCHAR sTemp
[MAX_PATH
];
799 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
800 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
801 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
802 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
803 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
804 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
805 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
806 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
807 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
810 /* load all the new stuff */
811 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
813 r
= ILLoadFromStream( stm
, &This
->pPidl
);
819 /* load the location information */
820 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
821 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
825 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
826 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
828 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
829 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
834 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
836 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
837 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
842 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
844 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
845 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
850 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
852 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
853 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
858 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
860 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
861 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
866 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
868 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
869 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
874 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
876 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
877 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
882 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
883 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
885 /* Some lnk files have extra data blocks starting with a
886 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
887 * one with a 0xa0000003 signature. However these don't seem to matter
890 WARN("Last word was not zero\n");
902 /************************************************************************
905 * Helper function for IPersistStream_Save. Writes a unicode string
906 * with terminating nul byte to a stream, preceded by the its length.
908 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
910 USHORT len
= lstrlenW( str
) + 1;
914 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
918 len
*= sizeof(WCHAR
);
920 r
= IStream_Write( stm
, str
, len
, &count
);
927 /************************************************************************
928 * Stream_WriteLocationInfo
930 * Writes the location info to a stream
932 * FIXME: One day we might want to write the network volume information
933 * and the final path.
934 * Figure out how Windows deals with unicode paths here.
936 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
937 volume_info
*volume
)
939 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
940 LOCAL_VOLUME_INFO
*vol
;
942 LPSTR szLabel
, szPath
, szFinalPath
;
946 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
948 /* figure out the size of everything */
949 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
950 NULL
, 0, NULL
, NULL
);
951 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
952 NULL
, 0, NULL
, NULL
);
953 volume_info_size
= sizeof *vol
+ label_size
;
955 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
957 /* create pointers to everything */
958 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
959 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
960 szLabel
= (LPSTR
) &vol
[1];
961 szPath
= &szLabel
[label_size
];
962 szFinalPath
= &szPath
[path_size
];
964 /* fill in the location information header */
965 loc
->dwTotalSize
= total_size
;
966 loc
->dwHeaderSize
= sizeof (*loc
);
968 loc
->dwVolTableOfs
= sizeof (*loc
);
969 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
970 loc
->dwNetworkVolTableOfs
= 0;
971 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
973 /* fill in the volume information */
974 vol
->dwSize
= volume_info_size
;
975 vol
->dwType
= volume
->type
;
976 vol
->dwVolSerial
= volume
->serial
;
977 vol
->dwVolLabelOfs
= sizeof (*vol
);
979 /* copy in the strings */
980 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
981 szLabel
, label_size
, NULL
, NULL
);
982 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
983 szPath
, path_size
, NULL
, NULL
);
986 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
987 HeapFree(GetProcessHeap(), 0, loc
);
992 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
994 EXP_DARWIN_LINK
*buffer
;
996 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
997 buffer
->dbh
.cbSize
= sizeof *buffer
;
998 buffer
->dbh
.dwSignature
= magic
;
999 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
1000 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
1005 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
1007 EXP_DARWIN_LINK
*buffer
;
1012 buffer
= shelllink_build_darwinid( string
, magic
);
1014 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1017 /************************************************************************
1018 * IPersistStream_Save (IPersistStream)
1020 * FIXME: makes assumptions about byte order
1022 static HRESULT WINAPI
IPersistStream_fnSave(
1023 IPersistStream
* iface
,
1032 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1034 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1036 memset(&header
, 0, sizeof(header
));
1037 header
.dwSize
= sizeof(header
);
1038 header
.fStartup
= This
->iShowCmd
;
1039 header
.MagicGuid
= CLSID_ShellLink
;
1041 header
.wHotKey
= This
->wHotKey
;
1042 header
.nIcon
= This
->iIcoNdx
;
1043 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1045 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1047 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1048 if( This
->sDescription
)
1049 header
.dwFlags
|= SLDF_HAS_NAME
;
1050 if( This
->sWorkDir
)
1051 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1053 header
.dwFlags
|= SLDF_HAS_ARGS
;
1054 if( This
->sIcoPath
)
1055 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1056 if( This
->sProduct
)
1057 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1058 if( This
->sComponent
)
1059 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1061 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1062 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1063 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1065 /* write the Shortcut header */
1066 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1069 ERR("Write failed at %d\n",__LINE__
);
1073 TRACE("Writing pidl\n");
1075 /* write the PIDL to the shortcut */
1078 r
= ILSaveToStream( stm
, This
->pPidl
);
1081 ERR("Failed to write PIDL at %d\n",__LINE__
);
1087 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1089 if( This
->sDescription
)
1090 r
= Stream_WriteString( stm
, This
->sDescription
);
1092 if( This
->sPathRel
)
1093 r
= Stream_WriteString( stm
, This
->sPathRel
);
1095 if( This
->sWorkDir
)
1096 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1099 r
= Stream_WriteString( stm
, This
->sArgs
);
1101 if( This
->sIcoPath
)
1102 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1104 if( This
->sProduct
)
1105 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1107 if( This
->sComponent
)
1108 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1110 /* the last field is a single zero dword */
1112 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1117 /************************************************************************
1118 * IPersistStream_GetSizeMax (IPersistStream)
1120 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1121 IPersistStream
* iface
,
1122 ULARGE_INTEGER
* pcbSize
)
1124 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1126 TRACE("(%p)\n", This
);
1131 static const IPersistStreamVtbl psvt
=
1133 IPersistStream_fnQueryInterface
,
1134 IPersistStream_fnAddRef
,
1135 IPersistStream_fnRelease
,
1136 IPersistStream_fnGetClassID
,
1137 IPersistStream_fnIsDirty
,
1138 IPersistStream_fnLoad
,
1139 IPersistStream_fnSave
,
1140 IPersistStream_fnGetSizeMax
1143 /**************************************************************************
1144 * IShellLink_Constructor
1146 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1147 REFIID riid
, LPVOID
*ppv
)
1149 IShellLinkImpl
* sl
;
1152 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1157 return CLASS_E_NOAGGREGATION
;
1158 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1160 return E_OUTOFMEMORY
;
1163 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
1164 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
1165 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
1166 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
1167 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
1168 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
1169 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
1170 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
1171 sl
->iShowCmd
= SW_SHOWNORMAL
;
1175 sl
->filepath
= NULL
;
1177 TRACE("(%p)->()\n",sl
);
1179 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, ppv
);
1180 IShellLinkW_Release( &sl
->IShellLinkW_iface
);
1185 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1187 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1192 /**************************************************************************
1193 * ShellLink_UpdatePath
1194 * update absolute path in sPath using relative path in sPathRel
1196 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1198 if (!path
|| !psPath
)
1199 return E_INVALIDARG
;
1201 if (!*psPath
&& sPathRel
) {
1202 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1203 LPWSTR final
= NULL
;
1205 /* first try if [directory of link file] + [relative path] finds an existing file */
1207 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1210 lstrcpyW(final
, sPathRel
);
1214 if (SHELL_ExistsFileW(buffer
)) {
1215 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1216 lstrcpyW(abs_path
, buffer
);
1218 /* try if [working directory] + [relative path] finds an existing file */
1220 lstrcpyW(buffer
, sWorkDir
);
1221 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1223 if (SHELL_ExistsFileW(buffer
))
1224 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1225 lstrcpyW(abs_path
, buffer
);
1229 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1231 lstrcpyW(abs_path
, sPathRel
);
1233 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1235 return E_OUTOFMEMORY
;
1237 lstrcpyW(*psPath
, abs_path
);
1243 /**************************************************************************
1244 * IShellLink_ConstructFromFile
1246 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1247 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1251 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1253 if (SUCCEEDED(hr
)) {
1258 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1260 if (SUCCEEDED(hr
)) {
1261 WCHAR path
[MAX_PATH
];
1263 if (SHGetPathFromIDListW(pidl
, path
))
1264 hr
= IPersistFile_Load(ppf
, path
, 0);
1269 *ppv
= (IUnknown
*)psl
;
1271 IPersistFile_Release(ppf
);
1275 IShellLinkW_Release(psl
);
1281 /**************************************************************************
1282 * IShellLinkA_QueryInterface
1284 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1286 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1287 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1290 /******************************************************************************
1291 * IShellLinkA_AddRef
1293 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1295 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1296 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1299 /******************************************************************************
1300 * IShellLinkA_Release
1302 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1304 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1305 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1308 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1309 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1311 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1313 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1314 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1316 if (This
->sComponent
|| This
->sProduct
)
1322 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1323 pszFile
, cchMaxPath
, NULL
, NULL
);
1325 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1330 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1332 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1333 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1336 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1338 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1339 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1342 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1345 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1347 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1351 if( This
->sDescription
)
1352 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1353 pszName
, cchMaxName
, NULL
, NULL
);
1358 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1360 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1364 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1368 descrW
= heap_strdupAtoW(pszName
);
1369 if (!descrW
) return E_OUTOFMEMORY
;
1374 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1375 HeapFree(GetProcessHeap(), 0, descrW
);
1380 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1383 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1385 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1389 if( This
->sWorkDir
)
1390 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1391 pszDir
, cchMaxPath
, NULL
, NULL
);
1396 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1398 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1402 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1404 dirW
= heap_strdupAtoW(pszDir
);
1405 if (!dirW
) return E_OUTOFMEMORY
;
1407 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1408 HeapFree(GetProcessHeap(), 0, dirW
);
1413 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1415 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1417 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1422 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1423 pszArgs
, cchMaxPath
, NULL
, NULL
);
1428 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1430 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1434 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1438 argsW
= heap_strdupAtoW(pszArgs
);
1439 if (!argsW
) return E_OUTOFMEMORY
;
1444 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1445 HeapFree(GetProcessHeap(), 0, argsW
);
1450 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1452 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1453 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1456 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1458 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1459 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1462 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1464 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1465 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1468 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1470 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1471 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1474 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1475 INT cchIconPath
, INT
*piIcon
)
1477 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1479 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1481 *piIcon
= This
->iIcoNdx
;
1484 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1491 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR pszIconPath
,
1494 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1498 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1500 pathW
= heap_strdupAtoW(pszIconPath
);
1501 if (!pathW
) return E_OUTOFMEMORY
;
1503 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, pathW
, iIcon
);
1504 HeapFree(GetProcessHeap(), 0, pathW
);
1509 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1512 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1516 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1518 pathW
= heap_strdupAtoW(pszPathRel
);
1519 if (!pathW
) return E_OUTOFMEMORY
;
1521 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1522 HeapFree(GetProcessHeap(), 0, pathW
);
1527 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1529 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1531 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1533 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1536 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1538 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1542 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1544 if (!pszFile
) return E_INVALIDARG
;
1546 str
= heap_strdupAtoW(pszFile
);
1548 return E_OUTOFMEMORY
;
1550 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1551 HeapFree( GetProcessHeap(), 0, str
);
1556 /**************************************************************************
1557 * IShellLink Implementation
1560 static const IShellLinkAVtbl slvt
=
1562 IShellLinkA_fnQueryInterface
,
1563 IShellLinkA_fnAddRef
,
1564 IShellLinkA_fnRelease
,
1565 IShellLinkA_fnGetPath
,
1566 IShellLinkA_fnGetIDList
,
1567 IShellLinkA_fnSetIDList
,
1568 IShellLinkA_fnGetDescription
,
1569 IShellLinkA_fnSetDescription
,
1570 IShellLinkA_fnGetWorkingDirectory
,
1571 IShellLinkA_fnSetWorkingDirectory
,
1572 IShellLinkA_fnGetArguments
,
1573 IShellLinkA_fnSetArguments
,
1574 IShellLinkA_fnGetHotkey
,
1575 IShellLinkA_fnSetHotkey
,
1576 IShellLinkA_fnGetShowCmd
,
1577 IShellLinkA_fnSetShowCmd
,
1578 IShellLinkA_fnGetIconLocation
,
1579 IShellLinkA_fnSetIconLocation
,
1580 IShellLinkA_fnSetRelativePath
,
1581 IShellLinkA_fnResolve
,
1582 IShellLinkA_fnSetPath
1586 /**************************************************************************
1587 * IShellLinkW_fnQueryInterface
1589 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1590 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1592 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1594 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1598 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1600 *ppvObj
= &This
->IShellLinkA_iface
;
1602 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1604 *ppvObj
= &This
->IShellLinkW_iface
;
1606 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1608 *ppvObj
= &This
->IPersistFile_iface
;
1610 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1612 *ppvObj
= &This
->IPersistStream_iface
;
1614 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1616 *ppvObj
= &This
->IShellLinkDataList_iface
;
1618 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1620 *ppvObj
= &This
->IShellExtInit_iface
;
1622 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1624 *ppvObj
= &This
->IContextMenu_iface
;
1626 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1628 *ppvObj
= &This
->IObjectWithSite_iface
;
1633 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1634 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1637 ERR("-- Interface: E_NOINTERFACE\n");
1638 return E_NOINTERFACE
;
1641 /******************************************************************************
1642 * IShellLinkW_fnAddRef
1644 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1646 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1647 ULONG ref
= InterlockedIncrement(&This
->ref
);
1649 TRACE("(%p)->(count=%u)\n", This
, ref
- 1);
1654 /******************************************************************************
1655 * IShellLinkW_fnRelease
1657 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1659 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1660 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1662 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
1667 TRACE("-- destroying IShellLink(%p)\n",This
);
1669 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1670 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1671 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1672 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1673 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1674 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1675 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
1676 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
1677 HeapFree(GetProcessHeap(), 0, This
->filepath
);
1680 IUnknown_Release( This
->site
);
1683 ILFree(This
->pPidl
);
1690 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1692 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1694 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1695 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1697 if (This
->sComponent
|| This
->sProduct
)
1703 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1705 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1710 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1712 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1714 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1721 *ppidl
= ILClone(This
->pPidl
);
1725 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1727 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1729 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1732 ILFree( This
->pPidl
);
1733 This
->pPidl
= ILClone( pidl
);
1737 This
->bDirty
= TRUE
;
1742 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1744 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1746 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1749 if( This
->sDescription
)
1750 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1755 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1757 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1759 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1761 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1764 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1765 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1766 if ( !This
->sDescription
)
1767 return E_OUTOFMEMORY
;
1769 lstrcpyW( This
->sDescription
, pszName
);
1772 This
->sDescription
= NULL
;
1773 This
->bDirty
= TRUE
;
1778 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1780 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1782 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1786 if( This
->sWorkDir
)
1787 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1792 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1794 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1796 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1798 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1799 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1800 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1801 if ( !This
->sWorkDir
)
1802 return E_OUTOFMEMORY
;
1803 lstrcpyW( This
->sWorkDir
, pszDir
);
1804 This
->bDirty
= TRUE
;
1809 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1811 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1813 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1818 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1823 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1825 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1827 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1829 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1832 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1833 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1835 return E_OUTOFMEMORY
;
1836 lstrcpyW( This
->sArgs
, pszArgs
);
1838 else This
->sArgs
= NULL
;
1840 This
->bDirty
= TRUE
;
1845 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1847 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1849 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1851 *pwHotkey
=This
->wHotKey
;
1856 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1858 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1860 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1862 This
->wHotKey
= wHotkey
;
1863 This
->bDirty
= TRUE
;
1868 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1870 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1872 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1874 *piShowCmd
= This
->iShowCmd
;
1879 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1881 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1883 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1885 This
->iShowCmd
= iShowCmd
;
1886 This
->bDirty
= TRUE
;
1891 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1893 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1895 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1897 *piIcon
= This
->iIcoNdx
;
1900 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1907 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1909 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1911 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1913 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1914 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1915 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1916 if ( !This
->sIcoPath
)
1917 return E_OUTOFMEMORY
;
1918 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1920 This
->iIcoNdx
= iIcon
;
1921 This
->bDirty
= TRUE
;
1926 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1928 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1930 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1932 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1933 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1934 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1935 if ( !This
->sPathRel
)
1936 return E_OUTOFMEMORY
;
1937 lstrcpyW( This
->sPathRel
, pszPathRel
);
1938 This
->bDirty
= TRUE
;
1940 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1943 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1948 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1950 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1952 /*FIXME: use IResolveShellLink interface */
1954 if (!This
->sPath
&& This
->pPidl
) {
1955 WCHAR buffer
[MAX_PATH
];
1957 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1959 if (bSuccess
&& *buffer
) {
1960 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1962 return E_OUTOFMEMORY
;
1964 lstrcpyW(This
->sPath
, buffer
);
1966 This
->bDirty
= TRUE
;
1968 hr
= S_OK
; /* don't report an error occurred while just caching information */
1971 if (!This
->sIcoPath
&& This
->sPath
) {
1972 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1973 if (!This
->sIcoPath
)
1974 return E_OUTOFMEMORY
;
1976 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1979 This
->bDirty
= TRUE
;
1985 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
1994 p
= strchrW( str
, ':' );
1998 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2001 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2006 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2008 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2016 /* each segment must start with two colons */
2017 if( str
[0] != ':' || str
[1] != ':' )
2020 /* the last segment is just two colons */
2025 /* there must be a colon straight after a guid */
2026 p
= strchrW( str
, ':' );
2033 /* get the guid, and check it's validly formatted */
2034 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2036 r
= CLSIDFromString( szGuid
, &guid
);
2041 /* match it up to a guid that we care about */
2042 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2044 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2049 /* skip to the next field */
2050 str
= strchrW( str
, ':' );
2055 /* we have to have a component for an advertised shortcut */
2059 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2060 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2062 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2063 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2068 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2070 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2071 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2074 volume
->type
= GetDriveTypeW(drive
);
2075 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2076 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2077 TRACE("r = %d type %d serial %08x name %s\n", r
,
2078 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2082 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2084 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2085 WCHAR buffer
[MAX_PATH
];
2086 LPWSTR fname
, unquoted
= NULL
;
2090 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2092 if (!pszFile
) return E_INVALIDARG
;
2094 /* quotes at the ends of the string are stripped */
2095 len
= lstrlenW(pszFile
);
2096 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2098 unquoted
= strdupW(pszFile
);
2099 PathUnquoteSpacesW(unquoted
);
2103 /* any other quote marks are invalid */
2104 if (strchrW(pszFile
, '"'))
2106 HeapFree(GetProcessHeap(), 0, unquoted
);
2110 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2113 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2114 This
->sComponent
= NULL
;
2117 ILFree(This
->pPidl
);
2120 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2122 if (*pszFile
== '\0')
2124 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2126 else if(!PathFileExistsW(buffer
) &&
2127 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2130 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2131 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2133 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2134 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2137 HeapFree(GetProcessHeap(), 0, unquoted
);
2138 return E_OUTOFMEMORY
;
2141 lstrcpyW(This
->sPath
, buffer
);
2143 This
->bDirty
= TRUE
;
2144 HeapFree(GetProcessHeap(), 0, unquoted
);
2149 /**************************************************************************
2150 * IShellLinkW Implementation
2153 static const IShellLinkWVtbl slvtw
=
2155 IShellLinkW_fnQueryInterface
,
2156 IShellLinkW_fnAddRef
,
2157 IShellLinkW_fnRelease
,
2158 IShellLinkW_fnGetPath
,
2159 IShellLinkW_fnGetIDList
,
2160 IShellLinkW_fnSetIDList
,
2161 IShellLinkW_fnGetDescription
,
2162 IShellLinkW_fnSetDescription
,
2163 IShellLinkW_fnGetWorkingDirectory
,
2164 IShellLinkW_fnSetWorkingDirectory
,
2165 IShellLinkW_fnGetArguments
,
2166 IShellLinkW_fnSetArguments
,
2167 IShellLinkW_fnGetHotkey
,
2168 IShellLinkW_fnSetHotkey
,
2169 IShellLinkW_fnGetShowCmd
,
2170 IShellLinkW_fnSetShowCmd
,
2171 IShellLinkW_fnGetIconLocation
,
2172 IShellLinkW_fnSetIconLocation
,
2173 IShellLinkW_fnSetRelativePath
,
2174 IShellLinkW_fnResolve
,
2175 IShellLinkW_fnSetPath
2178 static HRESULT WINAPI
2179 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2181 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2182 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2186 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2188 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2189 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2193 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2195 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2196 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2199 static HRESULT WINAPI
2200 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2202 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2206 static HRESULT WINAPI
2207 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2209 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2210 LPVOID block
= NULL
;
2213 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2217 case EXP_DARWIN_ID_SIG
:
2218 if (!This
->sComponent
)
2220 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2223 case EXP_SZ_LINK_SIG
:
2224 case NT_CONSOLE_PROPS_SIG
:
2225 case NT_FE_CONSOLE_PROPS_SIG
:
2226 case EXP_SPECIAL_FOLDER_SIG
:
2227 case EXP_SZ_ICON_SIG
:
2228 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2231 ERR("unknown datablock %08x\n", dwSig
);
2233 *ppDataBlock
= block
;
2237 static HRESULT WINAPI
2238 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2240 FIXME("(%p)->(%u): stub\n", iface
, dwSig
);
2244 static HRESULT WINAPI
2245 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2247 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2250 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2252 /* FIXME: add more */
2254 flags
|= SLDF_HAS_ARGS
;
2255 if (This
->sComponent
)
2256 flags
|= SLDF_HAS_DARWINID
;
2258 flags
|= SLDF_HAS_ICONLOCATION
;
2260 flags
|= SLDF_HAS_LOGO3ID
;
2262 flags
|= SLDF_HAS_ID_LIST
;
2269 static HRESULT WINAPI
2270 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2272 FIXME("(%p)->(%u): stub\n", iface
, dwFlags
);
2276 static const IShellLinkDataListVtbl dlvt
=
2278 ShellLink_DataList_QueryInterface
,
2279 ShellLink_DataList_AddRef
,
2280 ShellLink_DataList_Release
,
2281 ShellLink_AddDataBlock
,
2282 ShellLink_CopyDataBlock
,
2283 ShellLink_RemoveDataBlock
,
2288 static HRESULT WINAPI
2289 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2291 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2292 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2296 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2298 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2299 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2303 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2305 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2306 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2309 /**************************************************************************
2310 * ShellLink implementation of IShellExtInit::Initialize()
2312 * Loads the shelllink from the dataobject the shell is pointing to.
2314 static HRESULT WINAPI
2315 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2316 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2318 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2324 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2329 format
.cfFormat
= CF_HDROP
;
2331 format
.dwAspect
= DVASPECT_CONTENT
;
2333 format
.tymed
= TYMED_HGLOBAL
;
2335 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2338 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2343 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2345 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2348 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2350 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2351 r
= IPersistFile_Load( pf
, path
, 0 );
2352 HeapFree( GetProcessHeap(), 0, path
);
2355 ReleaseStgMedium( &stgm
);
2360 static const IShellExtInitVtbl eivt
=
2362 ShellLink_ExtInit_QueryInterface
,
2363 ShellLink_ExtInit_AddRef
,
2364 ShellLink_ExtInit_Release
,
2365 ShellLink_ExtInit_Initialize
2368 static HRESULT WINAPI
2369 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2371 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2372 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2376 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2378 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2379 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2383 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2385 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2386 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2389 static HRESULT WINAPI
2390 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2391 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2393 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2394 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2398 TRACE("%p %p %u %u %u %u\n", This
,
2399 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2402 return E_INVALIDARG
;
2404 memset( &mii
, 0, sizeof mii
);
2405 mii
.cbSize
= sizeof mii
;
2406 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2407 mii
.dwTypeData
= szOpen
;
2408 mii
.cch
= strlenW( mii
.dwTypeData
);
2409 mii
.wID
= idCmdFirst
+ id
++;
2410 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2411 mii
.fType
= MFT_STRING
;
2412 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2416 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2420 shelllink_get_msi_component_path( LPWSTR component
)
2425 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2426 if (r
!= ERROR_SUCCESS
)
2430 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2431 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2432 if (r
!= ERROR_SUCCESS
)
2434 HeapFree( GetProcessHeap(), 0, path
);
2438 TRACE("returning %s\n", debugstr_w( path
) );
2443 static HRESULT WINAPI
2444 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2446 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2447 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2448 SHELLEXECUTEINFOW sei
;
2449 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2454 TRACE("%p %p\n", This
, lpici
);
2456 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2457 return E_INVALIDARG
;
2459 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2461 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2462 return E_INVALIDARG
;
2465 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2469 if ( This
->sComponent
)
2471 path
= shelllink_get_msi_component_path( This
->sComponent
);
2476 path
= strdupW( This
->sPath
);
2478 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2479 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2481 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2485 len
+= lstrlenW( This
->sArgs
);
2486 if ( iciex
->lpParametersW
)
2487 len
+= lstrlenW( iciex
->lpParametersW
);
2489 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2492 lstrcatW( args
, This
->sArgs
);
2493 if ( iciex
->lpParametersW
)
2495 static const WCHAR space
[] = { ' ', 0 };
2496 lstrcatW( args
, space
);
2497 lstrcatW( args
, iciex
->lpParametersW
);
2501 memset( &sei
, 0, sizeof sei
);
2502 sei
.cbSize
= sizeof sei
;
2503 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2505 sei
.nShow
= This
->iShowCmd
;
2506 sei
.lpIDList
= This
->pPidl
;
2507 sei
.lpDirectory
= This
->sWorkDir
;
2508 sei
.lpParameters
= args
;
2509 sei
.lpVerb
= szOpen
;
2511 if( ShellExecuteExW( &sei
) )
2516 HeapFree( GetProcessHeap(), 0, args
);
2517 HeapFree( GetProcessHeap(), 0, path
);
2522 static HRESULT WINAPI
2523 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2524 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2526 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2528 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This
,
2529 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2534 static const IContextMenuVtbl cmvt
=
2536 ShellLink_ContextMenu_QueryInterface
,
2537 ShellLink_ContextMenu_AddRef
,
2538 ShellLink_ContextMenu_Release
,
2539 ShellLink_QueryContextMenu
,
2540 ShellLink_InvokeCommand
,
2541 ShellLink_GetCommandString
2544 static HRESULT WINAPI
2545 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2547 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2548 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2552 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2554 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2555 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2559 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2561 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2562 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2565 static HRESULT WINAPI
2566 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2568 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2570 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2574 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2577 static HRESULT WINAPI
2578 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2580 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2582 TRACE("%p %p\n", iface
, punk
);
2585 IUnknown_AddRef( punk
);
2588 IUnknown_Release( This
->site
);
2595 static const IObjectWithSiteVtbl owsvt
=
2597 ShellLink_ObjectWithSite_QueryInterface
,
2598 ShellLink_ObjectWithSite_AddRef
,
2599 ShellLink_ObjectWithSite_Release
,