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"
60 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
62 DEFINE_GUID( SHELL32_AdvtShortcutProduct
,
63 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
64 DEFINE_GUID( SHELL32_AdvtShortcutComponent
,
65 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
67 /* link file formats */
71 typedef struct _LINK_HEADER
73 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
74 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
75 DWORD dwFlags
; /* 0x14 describes elements following */
76 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
77 FILETIME Time1
; /* 0x1c */
78 FILETIME Time2
; /* 0x24 */
79 FILETIME Time3
; /* 0x2c */
80 DWORD dwFileLength
; /* 0x34 File length */
81 DWORD nIcon
; /* 0x38 icon number */
82 DWORD fStartup
; /* 0x3c startup type */
83 DWORD wHotKey
; /* 0x40 hotkey */
84 DWORD Unknown5
; /* 0x44 */
85 DWORD Unknown6
; /* 0x48 */
86 } LINK_HEADER
, * PLINK_HEADER
;
88 #define SHLINK_LOCAL 0
89 #define SHLINK_REMOTE 1
90 #define MAX_PROPERTY_SHEET_PAGE 32
92 typedef struct _LOCATION_INFO
99 DWORD dwNetworkVolTableOfs
;
100 DWORD dwFinalPathOfs
;
103 typedef struct _LOCAL_VOLUME_INFO
111 typedef struct volume_info_t
115 WCHAR label
[12]; /* assume 8.3 */
120 static const IShellLinkAVtbl slvt
;
121 static const IShellLinkWVtbl slvtw
;
122 static const IPersistFileVtbl pfvt
;
123 static const IPersistStreamVtbl psvt
;
124 static const IShellLinkDataListVtbl dlvt
;
125 static const IShellExtInitVtbl eivt
;
126 static const IContextMenuVtbl cmvt
;
127 static const IObjectWithSiteVtbl owsvt
;
129 /* IShellLink Implementation */
133 const IShellLinkAVtbl
*lpVtbl
;
134 const IShellLinkWVtbl
*lpvtblw
;
135 const IPersistFileVtbl
*lpvtblPersistFile
;
136 const IPersistStreamVtbl
*lpvtblPersistStream
;
137 const IShellLinkDataListVtbl
*lpvtblShellLinkDataList
;
138 const IShellExtInitVtbl
*lpvtblShellExtInit
;
139 const IContextMenuVtbl
*lpvtblContextMenu
;
140 const IObjectWithSiteVtbl
*lpvtblObjectWithSite
;
144 /* data structures according to the information in the link */
165 INT iIdOpen
; /* id of the "Open" entry in the context menu */
166 INT iIdProperties
; /* id of the "Properties" entry in the context menu */
170 static inline IShellLinkImpl
*impl_from_IShellLinkW( IShellLinkW
*iface
)
172 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblw
));
175 static inline IShellLinkImpl
*impl_from_IPersistFile( IPersistFile
*iface
)
177 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistFile
));
180 static inline IShellLinkImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
182 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistStream
));
185 static inline IShellLinkImpl
*impl_from_IShellLinkDataList( IShellLinkDataList
*iface
)
187 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellLinkDataList
));
190 static inline IShellLinkImpl
*impl_from_IShellExtInit( IShellExtInit
*iface
)
192 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellExtInit
));
195 static inline IShellLinkImpl
*impl_from_IContextMenu( IContextMenu
*iface
)
197 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblContextMenu
));
200 static inline IShellLinkImpl
*impl_from_IObjectWithSite( IObjectWithSite
*iface
)
202 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblObjectWithSite
));
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( HANDLE heap
, DWORD flags
, LPCSTR str
)
210 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
211 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
214 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
218 static inline LPWSTR
strdupW( LPCWSTR src
)
221 if (!src
) return NULL
;
222 dest
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(src
)+1)*sizeof(WCHAR
) );
228 /**************************************************************************
229 * ShellLink::QueryInterface implementation
231 static HRESULT
ShellLink_QueryInterface( IShellLinkImpl
*This
, REFIID riid
, LPVOID
*ppvObj
)
233 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
237 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
241 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
243 *ppvObj
= &(This
->lpvtblw
);
245 else if(IsEqualIID(riid
, &IID_IPersistFile
))
247 *ppvObj
= &(This
->lpvtblPersistFile
);
249 else if(IsEqualIID(riid
, &IID_IPersistStream
))
251 *ppvObj
= &(This
->lpvtblPersistStream
);
253 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
255 *ppvObj
= &(This
->lpvtblShellLinkDataList
);
257 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
259 *ppvObj
= &(This
->lpvtblShellExtInit
);
261 else if(IsEqualIID(riid
, &IID_IContextMenu
))
263 *ppvObj
= &(This
->lpvtblContextMenu
);
265 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
267 *ppvObj
= &(This
->lpvtblObjectWithSite
);
272 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
273 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
276 ERR("-- Interface: E_NOINTERFACE\n");
277 return E_NOINTERFACE
;
280 /**************************************************************************
281 * ShellLink::AddRef implementation
283 static ULONG
ShellLink_AddRef( IShellLinkImpl
*This
)
285 ULONG refCount
= InterlockedIncrement(&This
->ref
);
287 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
292 /**************************************************************************
293 * ShellLink::Release implementation
295 static ULONG
ShellLink_Release( IShellLinkImpl
*This
)
297 ULONG refCount
= InterlockedDecrement(&This
->ref
);
299 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
304 TRACE("-- destroying IShellLink(%p)\n",This
);
306 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
307 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
308 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
309 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
310 HeapFree(GetProcessHeap(),0,This
->sPath
);
311 HeapFree(GetProcessHeap(),0,This
->sLinkPath
);
314 IUnknown_Release( This
->site
);
319 LocalFree((HANDLE
)This
);
324 static HRESULT
ShellLink_GetClassID( IShellLinkImpl
*This
, CLSID
*pclsid
)
326 TRACE("%p %p\n", This
, pclsid
);
328 memcpy( pclsid
, &CLSID_ShellLink
, sizeof (CLSID
) );
332 /**************************************************************************
333 * IPersistFile_QueryInterface
335 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
340 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
341 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
344 /******************************************************************************
345 * IPersistFile_AddRef
347 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
349 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
350 return ShellLink_AddRef( This
);
353 /******************************************************************************
354 * IPersistFile_Release
356 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
358 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
359 return IShellLinkA_Release((IShellLinkA
*)This
);
362 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
364 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
365 return ShellLink_GetClassID( This
, pClassID
);
368 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
370 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
372 TRACE("(%p)\n",This
);
380 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
382 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
383 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
387 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
390 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
391 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
394 HeapFree(GetProcessHeap(), 0, This
->sLinkPath
);
395 This
->sLinkPath
= strdupW(pszFileName
);
396 r
= IPersistStream_Load(StreamThis
, stm
);
397 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
398 IStream_Release( stm
);
399 This
->bDirty
= FALSE
;
401 TRACE("-- returning hr %08x\n", r
);
405 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
407 static const WCHAR szFormat
[] = {
408 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
409 ' ','-','w',' ','"','%','s','"',0 };
413 PROCESS_INFORMATION pi
;
416 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
417 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
421 wsprintfW( buffer
, szFormat
, szLink
);
423 TRACE("starting %s\n",debugstr_w(buffer
));
425 memset(&si
, 0, sizeof(si
));
428 ret
= CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
430 HeapFree( GetProcessHeap(), 0, buffer
);
434 CloseHandle( pi
.hProcess
);
435 CloseHandle( pi
.hThread
);
441 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
443 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
444 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
448 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
453 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
456 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
457 IStream_Release( stm
);
461 StartLinkProcessor( pszFileName
);
463 This
->bDirty
= FALSE
;
467 DeleteFileW( pszFileName
);
468 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
475 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
477 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
478 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
482 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
484 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
485 FIXME("(%p)\n",This
);
489 static const IPersistFileVtbl pfvt
=
491 IPersistFile_fnQueryInterface
,
492 IPersistFile_fnAddRef
,
493 IPersistFile_fnRelease
,
494 IPersistFile_fnGetClassID
,
495 IPersistFile_fnIsDirty
,
498 IPersistFile_fnSaveCompleted
,
499 IPersistFile_fnGetCurFile
502 /************************************************************************
503 * IPersistStream_QueryInterface
505 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
506 IPersistStream
* iface
,
510 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
511 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
514 /************************************************************************
515 * IPersistStream_Release
517 static ULONG WINAPI
IPersistStream_fnRelease(
518 IPersistStream
* iface
)
520 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
521 return IShellLinkA_Release((IShellLinkA
*)This
);
524 /************************************************************************
525 * IPersistStream_AddRef
527 static ULONG WINAPI
IPersistStream_fnAddRef(
528 IPersistStream
* iface
)
530 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
531 return ShellLink_AddRef( This
);
534 /************************************************************************
535 * IPersistStream_GetClassID
538 static HRESULT WINAPI
IPersistStream_fnGetClassID(
539 IPersistStream
* iface
,
542 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
543 return ShellLink_GetClassID( This
, pClassID
);
546 /************************************************************************
547 * IPersistStream_IsDirty (IPersistStream)
549 static HRESULT WINAPI
IPersistStream_fnIsDirty(
550 IPersistStream
* iface
)
552 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
554 TRACE("(%p)\n", This
);
560 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
571 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
572 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
576 len
*= sizeof (WCHAR
);
578 TRACE("reading %d\n", len
);
579 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
581 return E_OUTOFMEMORY
;
583 r
= IStream_Read(stm
, temp
, len
, &count
);
584 if( FAILED (r
) || ( count
!= len
) )
586 HeapFree( GetProcessHeap(), 0, temp
);
590 TRACE("read %s\n", debugstr_an(temp
,len
));
592 /* convert to unicode if necessary */
595 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
596 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
599 HeapFree( GetProcessHeap(), 0, temp
);
600 return E_OUTOFMEMORY
;
602 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
603 HeapFree( GetProcessHeap(), 0, temp
);
617 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
624 unsigned char data
[1];
629 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
630 if( FAILED( r
) || count
!= sizeof(size
) )
633 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
635 return E_OUTOFMEMORY
;
638 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
639 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
641 HeapFree( GetProcessHeap(), 0, chunk
);
645 TRACE("Read %d bytes\n",chunk
->size
);
647 *data
= (LPVOID
) chunk
;
652 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
654 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
658 volume
->serial
= vol
->dwVolSerial
;
659 volume
->type
= vol
->dwType
;
661 if( !vol
->dwVolLabelOfs
)
663 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
665 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
668 label
+= vol
->dwVolLabelOfs
;
669 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
674 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
679 while( p
[len
] && (len
< maxlen
) )
682 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
683 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
684 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
690 static HRESULT
Stream_LoadLocation( IStream
*stm
,
691 volume_info
*volume
, LPWSTR
*path
)
698 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
702 loc
= (LOCATION_INFO
*) p
;
703 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
705 HeapFree( GetProcessHeap(), 0, p
);
709 /* if there's valid local volume information, load it */
710 if( loc
->dwVolTableOfs
&&
711 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
713 LOCAL_VOLUME_INFO
*volume_info
;
715 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
716 Stream_LoadVolume( volume_info
, volume
);
719 /* if there's a local path, load it */
720 n
= loc
->dwLocalPathOfs
;
721 if( n
&& (n
< loc
->dwTotalSize
) )
722 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
724 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
725 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
727 HeapFree( GetProcessHeap(), 0, p
);
732 * The format of the advertised shortcut info seems to be:
737 * 0 Length of the block (4 bytes, usually 0x314)
739 * 8 string data in ASCII
740 * 8+0x104 string data in UNICODE
742 * In the original Win32 implementation the buffers are not initialized
743 * to zero, so data trailing the string is random garbage.
745 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
750 EXP_DARWIN_LINK buffer
;
754 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
758 /* make sure that we read the size of the structure even on error */
759 size
= sizeof buffer
- sizeof (DWORD
);
760 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
762 ERR("Ooops. This structure is not as expected...\n");
766 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
773 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
775 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
777 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
781 *str
= HeapAlloc( GetProcessHeap(), 0,
782 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
783 lstrcpyW( *str
, buffer
.szwDarwinID
);
788 /************************************************************************
789 * IPersistStream_Load (IPersistStream)
791 static HRESULT WINAPI
IPersistStream_fnLoad(
792 IPersistStream
* iface
,
801 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
803 TRACE("%p %p\n", This
, stm
);
806 return STG_E_INVALIDPOINTER
;
809 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
813 if( dwBytesRead
!= sizeof(hdr
))
815 if( hdr
.dwSize
!= sizeof(hdr
))
817 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
820 /* free all the old stuff */
823 memset( &This
->volume
, 0, sizeof This
->volume
);
824 HeapFree(GetProcessHeap(), 0, This
->sPath
);
826 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
827 This
->sDescription
= NULL
;
828 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
829 This
->sPathRel
= NULL
;
830 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
831 This
->sWorkDir
= NULL
;
832 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
834 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
835 This
->sIcoPath
= NULL
;
836 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
837 This
->sProduct
= NULL
;
838 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
839 This
->sComponent
= NULL
;
841 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
842 This
->iIcoNdx
= hdr
.nIcon
;
843 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
844 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
845 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
848 WCHAR sTemp
[MAX_PATH
];
849 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
850 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
851 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
852 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
853 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
854 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
855 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
856 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
857 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
860 /* load all the new stuff */
861 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
863 r
= ILLoadFromStream( stm
, &This
->pPidl
);
869 /* load the location information */
870 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
871 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
875 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
876 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
878 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
879 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
884 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
886 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
887 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
892 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
894 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
895 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
900 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
902 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
903 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
908 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
910 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
911 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
916 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
918 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
919 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
924 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
926 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
927 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
929 if( hdr
.dwFlags
& SLDF_RUNAS_USER
)
935 This
->bRunAs
= FALSE
;
941 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
942 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
943 ERR("Last word was not zero\n");
954 /************************************************************************
957 * Helper function for IPersistStream_Save. Writes a unicode string
958 * with terminating nul byte to a stream, preceded by the its length.
960 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
962 USHORT len
= lstrlenW( str
) + 1;
966 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
970 len
*= sizeof(WCHAR
);
972 r
= IStream_Write( stm
, str
, len
, &count
);
979 /************************************************************************
980 * Stream_WriteLocationInfo
982 * Writes the location info to a stream
984 * FIXME: One day we might want to write the network volume information
985 * and the final path.
986 * Figure out how Windows deals with unicode paths here.
988 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
989 volume_info
*volume
)
991 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
992 LOCAL_VOLUME_INFO
*vol
;
994 LPSTR szLabel
, szPath
, szFinalPath
;
997 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
999 /* figure out the size of everything */
1000 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
1001 NULL
, 0, NULL
, NULL
);
1002 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
1003 NULL
, 0, NULL
, NULL
);
1004 volume_info_size
= sizeof *vol
+ label_size
;
1005 final_path_size
= 1;
1006 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
1008 /* create pointers to everything */
1009 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
1010 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
1011 szLabel
= (LPSTR
) &vol
[1];
1012 szPath
= &szLabel
[label_size
];
1013 szFinalPath
= &szPath
[path_size
];
1015 /* fill in the location information header */
1016 loc
->dwTotalSize
= total_size
;
1017 loc
->dwHeaderSize
= sizeof (*loc
);
1019 loc
->dwVolTableOfs
= sizeof (*loc
);
1020 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
1021 loc
->dwNetworkVolTableOfs
= 0;
1022 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
1024 /* fill in the volume information */
1025 vol
->dwSize
= volume_info_size
;
1026 vol
->dwType
= volume
->type
;
1027 vol
->dwVolSerial
= volume
->serial
;
1028 vol
->dwVolLabelOfs
= sizeof (*vol
);
1030 /* copy in the strings */
1031 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
1032 szLabel
, label_size
, NULL
, NULL
);
1033 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
1034 szPath
, path_size
, NULL
, NULL
);
1037 return IStream_Write( stm
, loc
, total_size
, &count
);
1040 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
1042 EXP_DARWIN_LINK
*buffer
;
1044 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
1045 buffer
->dbh
.cbSize
= sizeof *buffer
;
1046 buffer
->dbh
.dwSignature
= magic
;
1047 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
1048 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
1053 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
1055 EXP_DARWIN_LINK
*buffer
;
1060 buffer
= shelllink_build_darwinid( string
, magic
);
1062 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1065 /************************************************************************
1066 * IPersistStream_Save (IPersistStream)
1068 * FIXME: makes assumptions about byte order
1070 static HRESULT WINAPI
IPersistStream_fnSave(
1071 IPersistStream
* iface
,
1080 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1082 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1084 memset(&header
, 0, sizeof(header
));
1085 header
.dwSize
= sizeof(header
);
1086 header
.fStartup
= This
->iShowCmd
;
1087 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
1089 header
.wHotKey
= This
->wHotKey
;
1090 header
.nIcon
= This
->iIcoNdx
;
1091 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1093 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1095 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1096 if( This
->sDescription
)
1097 header
.dwFlags
|= SLDF_HAS_NAME
;
1098 if( This
->sWorkDir
)
1099 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1101 header
.dwFlags
|= SLDF_HAS_ARGS
;
1102 if( This
->sIcoPath
)
1103 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1104 if( This
->sProduct
)
1105 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1106 if( This
->sComponent
)
1107 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1109 header
.dwFlags
|= SLDF_RUNAS_USER
;
1111 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1112 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1113 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1115 /* write the Shortcut header */
1116 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1119 ERR("Write failed at %d\n",__LINE__
);
1123 TRACE("Writing pidl\n");
1125 /* write the PIDL to the shortcut */
1128 r
= ILSaveToStream( stm
, This
->pPidl
);
1131 ERR("Failed to write PIDL at %d\n",__LINE__
);
1137 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1139 if( This
->sDescription
)
1140 r
= Stream_WriteString( stm
, This
->sDescription
);
1142 if( This
->sPathRel
)
1143 r
= Stream_WriteString( stm
, This
->sPathRel
);
1145 if( This
->sWorkDir
)
1146 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1149 r
= Stream_WriteString( stm
, This
->sArgs
);
1151 if( This
->sIcoPath
)
1152 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1154 if( This
->sProduct
)
1155 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1157 if( This
->sComponent
)
1158 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1160 /* the last field is a single zero dword */
1162 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1167 /************************************************************************
1168 * IPersistStream_GetSizeMax (IPersistStream)
1170 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1171 IPersistStream
* iface
,
1172 ULARGE_INTEGER
* pcbSize
)
1174 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1176 TRACE("(%p)\n", This
);
1181 static const IPersistStreamVtbl psvt
=
1183 IPersistStream_fnQueryInterface
,
1184 IPersistStream_fnAddRef
,
1185 IPersistStream_fnRelease
,
1186 IPersistStream_fnGetClassID
,
1187 IPersistStream_fnIsDirty
,
1188 IPersistStream_fnLoad
,
1189 IPersistStream_fnSave
,
1190 IPersistStream_fnGetSizeMax
1193 /**************************************************************************
1194 * IShellLink_Constructor
1196 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1197 REFIID riid
, LPVOID
*ppv
)
1199 IShellLinkImpl
* sl
;
1202 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1207 return CLASS_E_NOAGGREGATION
;
1208 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1210 return E_OUTOFMEMORY
;
1214 sl
->lpvtblw
= &slvtw
;
1215 sl
->lpvtblPersistFile
= &pfvt
;
1216 sl
->lpvtblPersistStream
= &psvt
;
1217 sl
->lpvtblShellLinkDataList
= &dlvt
;
1218 sl
->lpvtblShellExtInit
= &eivt
;
1219 sl
->lpvtblContextMenu
= &cmvt
;
1220 sl
->lpvtblObjectWithSite
= &owsvt
;
1221 sl
->iShowCmd
= SW_SHOWNORMAL
;
1227 TRACE("(%p)->()\n",sl
);
1229 r
= ShellLink_QueryInterface( sl
, riid
, ppv
);
1230 ShellLink_Release( sl
);
1235 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1237 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1242 /**************************************************************************
1243 * ShellLink_UpdatePath
1244 * update absolute path in sPath using relative path in sPathRel
1246 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1248 if (!path
|| !psPath
)
1249 return E_INVALIDARG
;
1251 if (!*psPath
&& sPathRel
) {
1252 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1253 LPWSTR final
= NULL
;
1255 /* first try if [directory of link file] + [relative path] finds an existing file */
1257 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1260 lstrcpyW(final
, sPathRel
);
1264 if (SHELL_ExistsFileW(buffer
)) {
1265 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1266 lstrcpyW(abs_path
, buffer
);
1268 /* try if [working directory] + [relative path] finds an existing file */
1270 lstrcpyW(buffer
, sWorkDir
);
1271 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1273 if (SHELL_ExistsFileW(buffer
))
1274 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1275 lstrcpyW(abs_path
, buffer
);
1279 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1281 lstrcpyW(abs_path
, sPathRel
);
1283 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1285 return E_OUTOFMEMORY
;
1287 lstrcpyW(*psPath
, abs_path
);
1293 /**************************************************************************
1294 * IShellLink_ConstructFromFile
1296 HRESULT WINAPI
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1297 LPCITEMIDLIST pidl
, LPVOID
* ppv
)
1301 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1303 if (SUCCEEDED(hr
)) {
1308 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1310 if (SUCCEEDED(hr
)) {
1311 WCHAR path
[MAX_PATH
];
1313 if (SHGetPathFromIDListW(pidl
, path
))
1314 hr
= IPersistFile_Load(ppf
, path
, 0);
1319 *ppv
= (IUnknown
*) psl
;
1321 IPersistFile_Release(ppf
);
1325 IShellLinkW_Release(psl
);
1331 /**************************************************************************
1332 * IShellLinkA_QueryInterface
1334 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1336 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1337 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1340 /******************************************************************************
1341 * IShellLinkA_AddRef
1343 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
1345 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1346 return ShellLink_AddRef( This
);
1349 /******************************************************************************
1350 * IShellLinkA_Release
1352 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1354 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1355 return ShellLink_Release( This
);
1358 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1359 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1361 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1363 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1364 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1366 if (This
->sComponent
|| This
->sProduct
)
1372 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1373 pszFile
, cchMaxPath
, NULL
, NULL
);
1375 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1380 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1382 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1384 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1386 return IShellLinkW_GetIDList((IShellLinkW
*)&(This
->lpvtblw
), ppidl
);
1389 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1391 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1393 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1396 ILFree(This
->pPidl
);
1397 This
->pPidl
= ILClone (pidl
);
1398 This
->bDirty
= TRUE
;
1403 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1405 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1407 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1411 if( This
->sDescription
)
1412 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1413 pszName
, cchMaxName
, NULL
, NULL
);
1418 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1420 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1422 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1424 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1425 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1426 if ( !This
->sDescription
)
1427 return E_OUTOFMEMORY
;
1429 This
->bDirty
= TRUE
;
1434 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1436 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1438 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1442 if( This
->sWorkDir
)
1443 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1444 pszDir
, cchMaxPath
, NULL
, NULL
);
1449 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1451 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1453 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1455 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1456 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1457 if ( !This
->sWorkDir
)
1458 return E_OUTOFMEMORY
;
1460 This
->bDirty
= TRUE
;
1465 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1467 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1469 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1474 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1475 pszArgs
, cchMaxPath
, NULL
, NULL
);
1480 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1482 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1484 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1486 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1487 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1489 return E_OUTOFMEMORY
;
1491 This
->bDirty
= TRUE
;
1496 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1498 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1500 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1502 *pwHotkey
= This
->wHotKey
;
1507 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1509 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1511 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1513 This
->wHotKey
= wHotkey
;
1514 This
->bDirty
= TRUE
;
1519 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1521 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1523 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1524 *piShowCmd
= This
->iShowCmd
;
1528 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1530 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1532 TRACE("(%p) %d\n",This
, iShowCmd
);
1534 This
->iShowCmd
= iShowCmd
;
1535 This
->bDirty
= TRUE
;
1540 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPCITEMIDLIST pidl
,
1541 LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1543 LPCITEMIDLIST pidlLast
;
1545 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1547 if (SUCCEEDED(hr
)) {
1550 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1552 if (SUCCEEDED(hr
)) {
1553 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1555 IExtractIconA_Release(pei
);
1558 IShellFolder_Release(psf
);
1564 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1566 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1568 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1571 *piIcon
= This
->iIcoNdx
;
1575 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1579 if (This
->pPidl
|| This
->sPath
)
1583 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1587 /* first look for an icon using the PIDL (if present) */
1589 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1593 /* if we couldn't find an icon yet, look for it using the file system path */
1594 if (FAILED(hr
) && This
->sPath
)
1598 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1600 if (SUCCEEDED(hr
)) {
1601 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1607 IShellFolder_Release(pdsk
);
1615 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1617 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1619 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1621 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1622 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1623 if ( !This
->sIcoPath
)
1624 return E_OUTOFMEMORY
;
1626 This
->iIcoNdx
= iIcon
;
1627 This
->bDirty
= TRUE
;
1632 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1634 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1636 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1638 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1639 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1640 This
->bDirty
= TRUE
;
1642 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1645 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1647 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1649 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1651 return IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, fFlags
);
1654 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1658 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1660 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1662 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1664 return E_OUTOFMEMORY
;
1666 r
= IShellLinkW_SetPath((IShellLinkW
*)&(This
->lpvtblw
), str
);
1667 HeapFree( GetProcessHeap(), 0, str
);
1672 /**************************************************************************
1673 * IShellLink Implementation
1676 static const IShellLinkAVtbl slvt
=
1678 IShellLinkA_fnQueryInterface
,
1679 IShellLinkA_fnAddRef
,
1680 IShellLinkA_fnRelease
,
1681 IShellLinkA_fnGetPath
,
1682 IShellLinkA_fnGetIDList
,
1683 IShellLinkA_fnSetIDList
,
1684 IShellLinkA_fnGetDescription
,
1685 IShellLinkA_fnSetDescription
,
1686 IShellLinkA_fnGetWorkingDirectory
,
1687 IShellLinkA_fnSetWorkingDirectory
,
1688 IShellLinkA_fnGetArguments
,
1689 IShellLinkA_fnSetArguments
,
1690 IShellLinkA_fnGetHotkey
,
1691 IShellLinkA_fnSetHotkey
,
1692 IShellLinkA_fnGetShowCmd
,
1693 IShellLinkA_fnSetShowCmd
,
1694 IShellLinkA_fnGetIconLocation
,
1695 IShellLinkA_fnSetIconLocation
,
1696 IShellLinkA_fnSetRelativePath
,
1697 IShellLinkA_fnResolve
,
1698 IShellLinkA_fnSetPath
1702 /**************************************************************************
1703 * IShellLinkW_fnQueryInterface
1705 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1706 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1708 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1709 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1712 /******************************************************************************
1713 * IShellLinkW_fnAddRef
1715 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1717 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1718 return ShellLink_AddRef( This
);
1721 /******************************************************************************
1722 * IShellLinkW_fnRelease
1724 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1726 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1727 return ShellLink_Release( This
);
1730 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1732 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1734 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1735 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1737 if (This
->sComponent
|| This
->sProduct
)
1743 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1745 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1750 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1752 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1754 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1761 *ppidl
= ILClone(This
->pPidl
);
1765 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1767 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1769 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1772 ILFree( This
->pPidl
);
1773 This
->pPidl
= ILClone( pidl
);
1777 This
->bDirty
= TRUE
;
1782 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1784 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1786 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1789 if( This
->sDescription
)
1790 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1795 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1797 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1799 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1801 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1802 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1803 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1804 if ( !This
->sDescription
)
1805 return E_OUTOFMEMORY
;
1807 lstrcpyW( This
->sDescription
, pszName
);
1808 This
->bDirty
= TRUE
;
1813 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1815 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1817 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1821 if( This
->sWorkDir
)
1822 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1827 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1829 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1831 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1833 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1834 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1835 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1836 if ( !This
->sWorkDir
)
1837 return E_OUTOFMEMORY
;
1838 lstrcpyW( This
->sWorkDir
, pszDir
);
1839 This
->bDirty
= TRUE
;
1844 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1846 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1848 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1853 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1858 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1860 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1862 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1864 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1865 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1866 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1868 return E_OUTOFMEMORY
;
1869 lstrcpyW( This
->sArgs
, pszArgs
);
1870 This
->bDirty
= TRUE
;
1875 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1877 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1879 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1881 *pwHotkey
=This
->wHotKey
;
1886 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1888 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1890 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1892 This
->wHotKey
= wHotkey
;
1893 This
->bDirty
= TRUE
;
1898 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1900 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1902 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1904 *piShowCmd
= This
->iShowCmd
;
1909 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1911 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1913 This
->iShowCmd
= iShowCmd
;
1914 This
->bDirty
= TRUE
;
1919 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPCITEMIDLIST pidl
,
1920 LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1922 LPCITEMIDLIST pidlLast
;
1925 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1927 if (SUCCEEDED(hr
)) {
1930 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1932 if (SUCCEEDED(hr
)) {
1933 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, &wFlags
);
1935 IExtractIconW_Release(pei
);
1938 IShellFolder_Release(psf
);
1944 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1946 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1948 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1951 *piIcon
= This
->iIcoNdx
;
1955 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1959 if (This
->pPidl
|| This
->sPath
)
1963 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1967 /* first look for an icon using the PIDL (if present) */
1969 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1973 /* if we couldn't find an icon yet, look for it using the file system path */
1974 if (FAILED(hr
) && This
->sPath
)
1978 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1982 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1988 IShellFolder_Release(pdsk
);
1995 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1997 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1999 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
2001 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
2002 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
2003 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
2004 if ( !This
->sIcoPath
)
2005 return E_OUTOFMEMORY
;
2006 lstrcpyW( This
->sIcoPath
, pszIconPath
);
2008 This
->iIcoNdx
= iIcon
;
2009 This
->bDirty
= TRUE
;
2014 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
2016 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2018 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
2020 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
2021 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
2022 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
2023 if ( !This
->sPathRel
)
2024 return E_OUTOFMEMORY
;
2025 lstrcpyW( This
->sPathRel
, pszPathRel
);
2026 This
->bDirty
= TRUE
;
2028 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
2031 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
2036 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2038 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
2040 /*FIXME: use IResolveShellLink interface */
2042 if (!This
->sPath
&& This
->pPidl
) {
2043 WCHAR buffer
[MAX_PATH
];
2045 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
2047 if (bSuccess
&& *buffer
) {
2048 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
2050 return E_OUTOFMEMORY
;
2052 lstrcpyW(This
->sPath
, buffer
);
2054 This
->bDirty
= TRUE
;
2056 hr
= S_OK
; /* don't report an error occurred while just caching information */
2059 if (!This
->sIcoPath
&& This
->sPath
) {
2060 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2061 if (!This
->sIcoPath
)
2062 return E_OUTOFMEMORY
;
2064 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2067 This
->bDirty
= TRUE
;
2073 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2082 p
= strchrW( str
, ':' );
2086 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2089 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2094 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2096 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2104 /* each segment must start with two colons */
2105 if( str
[0] != ':' || str
[1] != ':' )
2108 /* the last segment is just two colons */
2113 /* there must be a colon straight after a guid */
2114 p
= strchrW( str
, ':' );
2121 /* get the guid, and check it's validly formatted */
2122 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2124 r
= CLSIDFromString( szGuid
, &guid
);
2129 /* match it up to a guid that we care about */
2130 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2132 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2137 /* skip to the next field */
2138 str
= strchrW( str
, ':' );
2143 /* we have to have a component for an advertised shortcut */
2147 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2148 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2150 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2151 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2156 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2158 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2159 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
2162 volume
->type
= GetDriveTypeW(drive
);
2163 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2164 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2165 TRACE("r = %d type %d serial %08x name %s\n", r
,
2166 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2170 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2172 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2173 WCHAR buffer
[MAX_PATH
];
2174 LPWSTR fname
, unquoted
= NULL
;
2178 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2180 /* quotes at the ends of the string are stripped */
2181 len
= lstrlenW(pszFile
);
2182 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2184 unquoted
= strdupW(pszFile
);
2185 PathUnquoteSpacesW(unquoted
);
2189 /* any other quote marks are invalid */
2190 if (strchrW(pszFile
, '"'))
2193 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2196 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2197 This
->sComponent
= NULL
;
2200 ILFree(This
->pPidl
);
2203 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2205 if (*pszFile
== '\0')
2207 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2209 else if(!PathFileExistsW(buffer
) &&
2210 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2213 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2214 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2216 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2217 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2219 return E_OUTOFMEMORY
;
2221 lstrcpyW(This
->sPath
, buffer
);
2223 This
->bDirty
= TRUE
;
2224 HeapFree(GetProcessHeap(), 0, unquoted
);
2229 /**************************************************************************
2230 * IShellLinkW Implementation
2233 static const IShellLinkWVtbl slvtw
=
2235 IShellLinkW_fnQueryInterface
,
2236 IShellLinkW_fnAddRef
,
2237 IShellLinkW_fnRelease
,
2238 IShellLinkW_fnGetPath
,
2239 IShellLinkW_fnGetIDList
,
2240 IShellLinkW_fnSetIDList
,
2241 IShellLinkW_fnGetDescription
,
2242 IShellLinkW_fnSetDescription
,
2243 IShellLinkW_fnGetWorkingDirectory
,
2244 IShellLinkW_fnSetWorkingDirectory
,
2245 IShellLinkW_fnGetArguments
,
2246 IShellLinkW_fnSetArguments
,
2247 IShellLinkW_fnGetHotkey
,
2248 IShellLinkW_fnSetHotkey
,
2249 IShellLinkW_fnGetShowCmd
,
2250 IShellLinkW_fnSetShowCmd
,
2251 IShellLinkW_fnGetIconLocation
,
2252 IShellLinkW_fnSetIconLocation
,
2253 IShellLinkW_fnSetRelativePath
,
2254 IShellLinkW_fnResolve
,
2255 IShellLinkW_fnSetPath
2258 static HRESULT WINAPI
2259 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2261 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2262 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2266 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2268 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2269 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2273 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2275 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2276 return ShellLink_Release( This
);
2279 static HRESULT WINAPI
2280 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2286 static HRESULT WINAPI
2287 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2289 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2290 LPVOID block
= NULL
;
2293 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2297 case EXP_DARWIN_ID_SIG
:
2298 if (!This
->sComponent
)
2300 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2303 case EXP_SZ_LINK_SIG
:
2304 case NT_CONSOLE_PROPS_SIG
:
2305 case NT_FE_CONSOLE_PROPS_SIG
:
2306 case EXP_SPECIAL_FOLDER_SIG
:
2307 case EXP_SZ_ICON_SIG
:
2308 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2311 ERR("unknown datablock %08x\n", dwSig
);
2313 *ppDataBlock
= block
;
2317 static HRESULT WINAPI
2318 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2324 static HRESULT WINAPI
2325 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2327 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2330 FIXME("%p %p\n", This
, pdwFlags
);
2332 /* FIXME: add more */
2334 flags
|= SLDF_HAS_ARGS
;
2335 if (This
->sComponent
)
2336 flags
|= SLDF_HAS_DARWINID
;
2338 flags
|= SLDF_HAS_ICONLOCATION
;
2340 flags
|= SLDF_HAS_LOGO3ID
;
2342 flags
|= SLDF_HAS_ID_LIST
;
2349 static HRESULT WINAPI
2350 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2356 static const IShellLinkDataListVtbl dlvt
=
2358 ShellLink_DataList_QueryInterface
,
2359 ShellLink_DataList_AddRef
,
2360 ShellLink_DataList_Release
,
2361 ShellLink_AddDataBlock
,
2362 ShellLink_CopyDataBlock
,
2363 ShellLink_RemoveDataBlock
,
2368 static HRESULT WINAPI
2369 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2371 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2372 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2376 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2378 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2379 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2383 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2385 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2386 return ShellLink_Release( This
);
2389 /**************************************************************************
2390 * ShellLink implementation of IShellExtInit::Initialize()
2392 * Loads the shelllink from the dataobject the shell is pointing to.
2394 static HRESULT WINAPI
2395 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2396 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2398 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2404 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2409 format
.cfFormat
= CF_HDROP
;
2411 format
.dwAspect
= DVASPECT_CONTENT
;
2413 format
.tymed
= TYMED_HGLOBAL
;
2415 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2418 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2423 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2425 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2428 IPersistFile
*pf
= (IPersistFile
*) &This
->lpvtblPersistFile
;
2430 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2431 r
= IPersistFile_Load( pf
, path
, 0 );
2432 HeapFree( GetProcessHeap(), 0, path
);
2435 ReleaseStgMedium( &stgm
);
2440 static const IShellExtInitVtbl eivt
=
2442 ShellLink_ExtInit_QueryInterface
,
2443 ShellLink_ExtInit_AddRef
,
2444 ShellLink_ExtInit_Release
,
2445 ShellLink_ExtInit_Initialize
2448 static HRESULT WINAPI
2449 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2451 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2452 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2456 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2458 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2459 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2463 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2465 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2466 return ShellLink_Release( This
);
2469 static HRESULT WINAPI
2470 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2471 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2473 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2474 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2475 static WCHAR szProperties
[] = { 'P','r','o','p','e','r','t','i','e','s',0 };
2479 TRACE("%p %p %u %u %u %u\n", This
,
2480 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2483 return E_INVALIDARG
;
2485 memset( &mii
, 0, sizeof(mii
) );
2486 mii
.cbSize
= sizeof (mii
);
2487 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2488 mii
.dwTypeData
= (LPWSTR
)szOpen
;
2489 mii
.cch
= strlenW( mii
.dwTypeData
);
2490 mii
.wID
= idCmdFirst
+ id
++;
2491 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2492 mii
.fType
= MFT_STRING
;
2493 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2497 mii
.fState
= MFS_ENABLED
;
2498 mii
.dwTypeData
= (LPWSTR
)szProperties
;
2499 mii
.cch
= strlenW( mii
.dwTypeData
);
2500 mii
.wID
= idCmdFirst
+ id
++;
2501 if (!InsertMenuItemW( hmenu
, idCmdLast
, TRUE
, &mii
))
2503 TRACE("ShellLink_QueryContextMenu failed to insert item properties");
2506 This
->iIdProperties
= 1;
2509 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2513 shelllink_get_msi_component_path( LPWSTR component
)
2518 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2519 if (r
!= ERROR_SUCCESS
)
2523 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2524 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2525 if (r
!= ERROR_SUCCESS
)
2527 HeapFree( GetProcessHeap(), 0, path
);
2531 TRACE("returning %s\n", debugstr_w( path
) );
2536 INT_PTR CALLBACK
ExtendedShortcutProc(
2550 hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2551 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2555 hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2556 if (LOWORD(wParam
) == IDOK
)
2558 if ( SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2559 EndDialog(hwndDlg
, 1);
2561 EndDialog(hwndDlg
, 0);
2563 else if (LOWORD(wParam
) == IDCANCEL
)
2565 EndDialog(hwndDlg
, -1);
2567 else if (LOWORD(wParam
) == 14000)
2569 if ( SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2570 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2572 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2579 /**************************************************************************
2580 * SH_ShellLinkDlgProc
2582 * dialog proc of the shortcut property dialog
2587 SH_ShellLinkDlgProc(
2594 LPPROPSHEETPAGEW ppsp
;
2596 IShellLinkImpl
*This
;
2598 WCHAR szBuffer
[MAX_PATH
];
2603 This
= (IShellLinkImpl
*)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
2608 ppsp
= (LPPROPSHEETPAGEW
)lParam
;
2612 TRACE("ShellLink_DlgProc (WM_INITDIALOG hwnd %p lParam %p ppsplParam %x)\n",hwndDlg
, lParam
, ppsp
->lParam
);
2614 This
= (IShellLinkImpl
*)ppsp
->lParam
;
2615 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)This
);
2617 TRACE("sArgs: %S sComponent: %S sDescription: %S sIcoPath: %S sPath: %S sPathRel: %S sProduct: %S sWorkDir: %S\n", This
->sArgs
, This
->sComponent
,This
->sDescription
,
2618 This
->sIcoPath
, This
->sPath
, This
->sPathRel
, This
->sProduct
, This
->sWorkDir
);
2621 hDlgCtrl
= GetDlgItem( hwndDlg
, 14009 );
2622 if ( hDlgCtrl
!= NULL
)
2623 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sPath
);
2626 hDlgCtrl
= GetDlgItem( hwndDlg
, 14011 );
2627 if ( hDlgCtrl
!= NULL
)
2628 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sWorkDir
);
2631 hDlgCtrl
= GetDlgItem( hwndDlg
, 14019 );
2632 if ( hDlgCtrl
!= NULL
)
2633 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sDescription
);
2636 lppsn
= (LPPSHNOTIFY
) lParam
;
2637 if ( lppsn
->hdr
.code
== PSN_APPLY
)
2639 /* set working directory */
2640 hDlgCtrl
= GetDlgItem( hwndDlg
, 14011 );
2641 SendMessageW( hDlgCtrl
, WM_GETTEXT
, (WPARAM
)MAX_PATH
, (LPARAM
)szBuffer
);
2642 IShellLinkW_fnSetWorkingDirectory((IShellLinkW
*)&This
->lpvtblw
, szBuffer
);
2643 /* set link destination */
2644 hDlgCtrl
= GetDlgItem( hwndDlg
, 14009 );
2645 SendMessageW( hDlgCtrl
, WM_GETTEXT
, (WPARAM
)MAX_PATH
, (LPARAM
)szBuffer
);
2646 if ( !SHELL_ExistsFileW(szBuffer
) )
2648 //FIXME load localized error msg
2649 MessageBoxW( hwndDlg
, L
"file not existing", szBuffer
, MB_OK
);
2650 SetWindowLong( hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2653 ptr
= wcsrchr(szBuffer
, L
'.');
2654 if (ptr
&& !wcsnicmp(ptr
, L
".lnk", 4))
2656 // FIXME load localized error msg
2657 MessageBoxW( hwndDlg
, L
"You cannot create a link to a shortcut", L
"Error", MB_ICONERROR
);
2658 SetWindowLong( hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2662 IShellLinkW_fnSetPath((IShellLinkW
*)&This
->lpvtblw
, szBuffer
);
2664 TRACE("This %p sLinkPath %S\n", This
, This
->sLinkPath
);
2665 IPersistFile_fnSave( (IPersistFile
*)&This
->lpvtblPersistFile
, This
->sLinkPath
, TRUE
);
2666 SetWindowLong( hwndDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
2671 switch(LOWORD(wParam
))
2676 /// open target directory
2680 if (PickIconDlg(hwndDlg
, szBuffer
, MAX_PATH
, &IconIndex
))
2682 IShellLinkW_fnSetIconLocation((IShellLinkW
*)&This
->lpvtblw
, szBuffer
, IconIndex
);
2684 /// FIXME redraw icon
2688 result
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(SHELL_EXTENDED_SHORTCUT_DLG
), hwndDlg
, ExtendedShortcutProc
, (LPARAM
)This
->bRunAs
);
2689 if (result
== 1 || result
== 0)
2691 if ( This
->bRunAs
!= result
)
2693 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2696 This
->bRunAs
= result
;
2700 switch(HIWORD(wParam
))
2703 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2713 /**************************************************************************
2714 * ShellLink_ShortcutDialog [Internal]
2716 * creates a shortcut property dialog
2719 static HRESULT WINAPI
2720 ShellLink_ShowProperties( IShellLinkImpl
*This
)
2722 PROPSHEETHEADERW pinfo
;
2723 HPROPSHEETPAGE hppages
[MAX_PROPERTY_SHEET_PAGE
];
2724 HPROPSHEETPAGE hpage
;
2727 TRACE("ShellLink_ShortcutDialog entered\n");
2729 memset(hppages
, 0x0, sizeof(HPROPSHEETPAGE
) * MAX_PROPERTY_SHEET_PAGE
);
2731 hpage
= SH_CreatePropertySheetPage("SHELL_FILE_GENERAL_DLG", SH_FileGeneralDlgProc
, (LPARAM
)This
->sLinkPath
, NULL
);
2732 if ( hpage
== NULL
)
2735 hppages
[numpages
++] = hpage
;
2737 hpage
= SH_CreatePropertySheetPage("SHELL_GENERAL_SHORTCUT_DLG", SH_ShellLinkDlgProc
, (LPARAM
)This
, NULL
);
2738 if ( hpage
== NULL
)
2740 ERR("SH_CreatePropertySheetPage failed\n");
2741 DestroyPropertySheetPage(hppages
[0]);
2744 hppages
[numpages
++] = hpage
;
2749 memset(&pinfo
, 0x0, sizeof(PROPSHEETHEADERW
));
2750 pinfo
.dwSize
= sizeof(PROPSHEETHEADERW
);
2751 pinfo
.dwFlags
= PSH_NOCONTEXTHELP
| PSH_PROPTITLE
;
2752 pinfo
.nPages
= numpages
;
2753 pinfo
.u3
.phpage
= hppages
;
2754 pinfo
.pszCaption
= This
->sDescription
;
2755 pinfo
.u2
.nStartPage
= 1;
2757 if ( PropertySheetW(&pinfo
) < 0 )
2763 static HRESULT WINAPI
2764 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2766 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2767 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2768 SHELLEXECUTEINFOW sei
;
2769 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2774 TRACE("%p %p\n", This
, lpici
);
2776 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2777 return E_INVALIDARG
;
2779 if ( lpici
->lpVerb
== MAKEINTRESOURCEA(This
->iIdProperties
))
2781 ShellLink_ShowProperties(This
);
2785 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2787 ERR("Unknown id %d != %d\n", (INT
)lpici
->lpVerb
, This
->iIdOpen
);
2788 return E_INVALIDARG
;
2791 r
= IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, 0 );
2795 if ( This
->sComponent
)
2797 path
= shelllink_get_msi_component_path( This
->sComponent
);
2802 path
= strdupW( This
->sPath
);
2804 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2805 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2807 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2811 len
+= lstrlenW( This
->sArgs
);
2812 if ( iciex
->lpParametersW
)
2813 len
+= lstrlenW( iciex
->lpParametersW
);
2815 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2818 lstrcatW( args
, This
->sArgs
);
2819 if ( iciex
->lpParametersW
)
2821 static const WCHAR space
[] = { ' ', 0 };
2822 lstrcatW( args
, space
);
2823 lstrcatW( args
, iciex
->lpParametersW
);
2827 memset( &sei
, 0, sizeof sei
);
2828 sei
.cbSize
= sizeof sei
;
2829 sei
.fMask
= SEE_MASK_UNICODE
| SEE_MASK_NOCLOSEPROCESS
;
2831 sei
.nShow
= This
->iShowCmd
;
2832 sei
.lpIDList
= This
->pPidl
;
2833 sei
.lpDirectory
= This
->sWorkDir
;
2834 sei
.lpParameters
= args
;
2835 sei
.lpVerb
= szOpen
;
2837 if( ShellExecuteExW( &sei
) )
2841 WaitForSingleObject( sei
.hProcess
, 10000 );
2842 CloseHandle( sei
.hProcess
);
2849 HeapFree( GetProcessHeap(), 0, args
);
2850 HeapFree( GetProcessHeap(), 0, path
);
2855 static HRESULT WINAPI
2856 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2857 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2859 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2861 FIXME("%p %lu %u %p %p %u\n", This
,
2862 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2867 static const IContextMenuVtbl cmvt
=
2869 ShellLink_ContextMenu_QueryInterface
,
2870 ShellLink_ContextMenu_AddRef
,
2871 ShellLink_ContextMenu_Release
,
2872 ShellLink_QueryContextMenu
,
2873 ShellLink_InvokeCommand
,
2874 ShellLink_GetCommandString
2877 static HRESULT WINAPI
2878 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2880 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2881 return ShellLink_QueryInterface( This
, riid
, ppvObject
);
2885 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2887 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2888 return ShellLink_AddRef( This
);
2892 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2894 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2895 return ShellLink_Release( This
);
2898 static HRESULT WINAPI
2899 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2901 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2903 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2907 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2910 static HRESULT WINAPI
2911 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2913 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2915 TRACE("%p %p\n", iface
, punk
);
2918 IUnknown_AddRef( punk
);
2924 static const IObjectWithSiteVtbl owsvt
=
2926 ShellLink_ObjectWithSite_QueryInterface
,
2927 ShellLink_ObjectWithSite_AddRef
,
2928 ShellLink_ObjectWithSite_Release
,