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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Nearly complete informations 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
91 typedef struct _LOCATION_INFO
98 DWORD dwNetworkVolTableOfs
;
102 typedef struct _LOCAL_VOLUME_INFO
110 typedef struct volume_info_t
114 WCHAR label
[12]; /* assume 8.3 */
119 static const IShellLinkAVtbl slvt
;
120 static const IShellLinkWVtbl slvtw
;
121 static const IPersistFileVtbl pfvt
;
122 static const IPersistStreamVtbl psvt
;
123 static const IShellLinkDataListVtbl dlvt
;
124 static const IShellExtInitVtbl eivt
;
125 static const IContextMenuVtbl cmvt
;
126 static const IObjectWithSiteVtbl owsvt
;
128 /* IShellLink Implementation */
132 const IShellLinkAVtbl
*lpVtbl
;
133 const IShellLinkWVtbl
*lpvtblw
;
134 const IPersistFileVtbl
*lpvtblPersistFile
;
135 const IPersistStreamVtbl
*lpvtblPersistStream
;
136 const IShellLinkDataListVtbl
*lpvtblShellLinkDataList
;
137 const IShellExtInitVtbl
*lpvtblShellExtInit
;
138 const IContextMenuVtbl
*lpvtblContextMenu
;
139 const IObjectWithSiteVtbl
*lpvtblObjectWithSite
;
143 /* data structures according to the informations in the link */
165 INT iIdOpen
; /* id of the "Open" 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(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
207 /* strdup on the process heap */
208 inline static 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 inline static 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=%lu)\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=%lu)\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
);
315 IUnknown_Release( This
->site
);
320 LocalFree((HANDLE
)This
);
325 static HRESULT
ShellLink_GetClassID( IShellLinkImpl
*This
, CLSID
*pclsid
)
327 TRACE("%p %p\n", This
, pclsid
);
329 memcpy( pclsid
, &CLSID_ShellLink
, sizeof (CLSID
) );
333 /**************************************************************************
334 * IPersistFile_QueryInterface
336 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
341 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
342 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
345 /******************************************************************************
346 * IPersistFile_AddRef
348 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
350 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
351 return ShellLink_AddRef( This
);
354 /******************************************************************************
355 * IPersistFile_Release
357 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
359 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
360 return IShellLinkA_Release((IShellLinkA
*)This
);
363 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
365 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
366 return ShellLink_GetClassID( This
, pClassID
);
369 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
371 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
373 TRACE("(%p)\n",This
);
381 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
383 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
384 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
388 TRACE("(%p, %s, %lx)\n",This
, debugstr_w(pszFileName
), dwMode
);
391 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
392 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
395 HeapFree(GetProcessHeap(), 0, This
->sLinkPath
);
396 This
->sLinkPath
= _wcsdup(pszFileName
);
397 r
= IPersistStream_Load(StreamThis
, stm
);
398 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
399 IStream_Release( stm
);
400 This
->bDirty
= FALSE
;
402 TRACE("-- returning hr %08lx\n", r
);
406 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
408 static const WCHAR szFormat
[] = {
409 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
410 ' ','-','r',' ','"','%','s','"',0 };
414 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
));
427 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
429 /* wait for a while to throttle the creation of linker processes */
430 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
431 WARN("Timed out waiting for shell linker\n");
433 CloseHandle( pi
.hProcess
);
434 CloseHandle( pi
.hThread
);
439 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
441 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
442 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
446 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
451 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
454 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
455 IStream_Release( stm
);
459 StartLinkProcessor( pszFileName
);
461 This
->bDirty
= FALSE
;
465 DeleteFileW( pszFileName
);
466 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
473 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
475 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
476 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
480 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
482 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
483 FIXME("(%p)\n",This
);
487 static const IPersistFileVtbl pfvt
=
489 IPersistFile_fnQueryInterface
,
490 IPersistFile_fnAddRef
,
491 IPersistFile_fnRelease
,
492 IPersistFile_fnGetClassID
,
493 IPersistFile_fnIsDirty
,
496 IPersistFile_fnSaveCompleted
,
497 IPersistFile_fnGetCurFile
500 /************************************************************************
501 * IPersistStream_QueryInterface
503 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
504 IPersistStream
* iface
,
508 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
509 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
512 /************************************************************************
513 * IPersistStream_Release
515 static ULONG WINAPI
IPersistStream_fnRelease(
516 IPersistStream
* iface
)
518 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
519 return IShellLinkA_Release((IShellLinkA
*)This
);
522 /************************************************************************
523 * IPersistStream_AddRef
525 static ULONG WINAPI
IPersistStream_fnAddRef(
526 IPersistStream
* iface
)
528 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
529 return ShellLink_AddRef( This
);
532 /************************************************************************
533 * IPersistStream_GetClassID
536 static HRESULT WINAPI
IPersistStream_fnGetClassID(
537 IPersistStream
* iface
,
540 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
541 return ShellLink_GetClassID( This
, pClassID
);
544 /************************************************************************
545 * IPersistStream_IsDirty (IPersistStream)
547 static HRESULT WINAPI
IPersistStream_fnIsDirty(
548 IPersistStream
* iface
)
550 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
552 TRACE("(%p)\n", This
);
558 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
569 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
570 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
574 len
*= sizeof (WCHAR
);
576 TRACE("reading %d\n", len
);
577 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
579 return E_OUTOFMEMORY
;
581 r
= IStream_Read(stm
, temp
, len
, &count
);
582 if( FAILED (r
) || ( count
!= len
) )
584 HeapFree( GetProcessHeap(), 0, temp
);
588 TRACE("read %s\n", debugstr_an(temp
,len
));
590 /* convert to unicode if necessary */
593 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
594 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
596 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
597 HeapFree( GetProcessHeap(), 0, temp
);
611 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
618 unsigned char data
[1];
623 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
624 if( FAILED( r
) || count
!= sizeof(size
) )
627 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
629 return E_OUTOFMEMORY
;
632 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
633 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
635 HeapFree( GetProcessHeap(), 0, chunk
);
639 TRACE("Read %ld bytes\n",chunk
->size
);
641 *data
= (LPVOID
) chunk
;
646 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
648 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
652 volume
->serial
= vol
->dwVolSerial
;
653 volume
->type
= vol
->dwType
;
655 if( !vol
->dwVolLabelOfs
)
657 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
659 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
662 label
+= vol
->dwVolLabelOfs
;
663 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
668 static LPWSTR
Stream_LoadPath( LPSTR p
, DWORD maxlen
)
673 while( p
[len
] && (len
< maxlen
) )
676 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
677 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
678 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
684 static HRESULT
Stream_LoadLocation( IStream
*stm
,
685 volume_info
*volume
, LPWSTR
*path
)
692 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
696 loc
= (LOCATION_INFO
*) p
;
697 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
) - sizeof(DWORD
))
699 HeapFree( GetProcessHeap(), 0, p
);
703 /* if there's valid local volume information, load it */
704 if( loc
->dwVolTableOfs
&&
705 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
707 LOCAL_VOLUME_INFO
*volume_info
;
709 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
710 Stream_LoadVolume( volume_info
, volume
);
713 /* if there's a local path, load it */
714 n
= loc
->dwLocalPathOfs
;
715 if( n
&& (n
< loc
->dwTotalSize
) )
716 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
718 TRACE("type %ld serial %08lx name %s path %s\n", volume
->type
,
719 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
721 HeapFree( GetProcessHeap(), 0, p
);
726 * The format of the advertised shortcut info seems to be:
731 * 0 Length of the block (4 bytes, usually 0x314)
733 * 8 string data in ASCII
734 * 8+0x104 string data in UNICODE
736 * In the original Win32 implementation the buffers are not initialized
737 * to zero, so data trailing the string is random garbage.
739 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
744 EXP_DARWIN_LINK buffer
;
748 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
752 /* make sure that we read the size of the structure even on error */
753 size
= sizeof buffer
- sizeof (DWORD
);
754 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
756 ERR("Ooops. This structure is not as expected...\n");
760 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
767 TRACE("magic %08lx string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
769 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
771 ERR("Unknown magic number %08lx in advertised shortcut\n", buffer
.dbh
.dwSignature
);
775 *str
= HeapAlloc( GetProcessHeap(), 0,
776 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
777 lstrcpyW( *str
, buffer
.szwDarwinID
);
782 /************************************************************************
783 * IPersistStream_Load (IPersistStream)
785 static HRESULT WINAPI
IPersistStream_fnLoad(
786 IPersistStream
* iface
,
795 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
797 TRACE("%p %p\n", This
, stm
);
800 return STG_E_INVALIDPOINTER
;
803 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
807 if( dwBytesRead
!= sizeof(hdr
))
809 if( hdr
.dwSize
!= sizeof(hdr
))
811 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
814 /* free all the old stuff */
817 memset( &This
->volume
, 0, sizeof This
->volume
);
818 HeapFree(GetProcessHeap(), 0, This
->sPath
);
820 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
821 This
->sDescription
= NULL
;
822 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
823 This
->sPathRel
= NULL
;
824 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
825 This
->sWorkDir
= NULL
;
826 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
828 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
829 This
->sIcoPath
= NULL
;
830 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
831 This
->sProduct
= NULL
;
832 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
833 This
->sComponent
= NULL
;
835 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
836 This
->iIcoNdx
= hdr
.nIcon
;
837 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
838 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
839 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
842 WCHAR sTemp
[MAX_PATH
];
843 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
844 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
845 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
846 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
847 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
848 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
849 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
850 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
851 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
854 /* load all the new stuff */
855 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
857 r
= ILLoadFromStream( stm
, &This
->pPidl
);
863 /* load the location information */
864 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
865 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
869 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
870 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
872 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
873 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
878 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
880 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
881 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
886 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
888 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
889 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
894 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
896 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
897 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
902 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
904 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
905 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
910 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
912 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
913 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
918 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
920 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
921 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
923 if( hdr
.dwFlags
& SLDF_RUNAS_USER
)
929 This
->bRunAs
= FALSE
;
935 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
936 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
937 ERR("Last word was not zero\n");
948 /************************************************************************
951 * Helper function for IPersistStream_Save. Writes a unicode string
952 * with terminating nul byte to a stream, preceded by the its length.
954 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
956 USHORT len
= lstrlenW( str
) + 1;
960 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
964 len
*= sizeof(WCHAR
);
966 r
= IStream_Write( stm
, str
, len
, &count
);
973 /************************************************************************
974 * Stream_WriteLocationInfo
976 * Writes the location info to a stream
978 * FIXME: One day we might want to write the network volume information
979 * and the final path.
980 * Figure out how Windows deals with unicode paths here.
982 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
983 volume_info
*volume
)
985 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
986 LOCAL_VOLUME_INFO
*vol
;
988 LPSTR szLabel
, szPath
, szFinalPath
;
991 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
993 /* figure out the size of everything */
994 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
995 NULL
, 0, NULL
, NULL
);
996 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
997 NULL
, 0, NULL
, NULL
);
998 volume_info_size
= sizeof *vol
+ label_size
;
1000 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
1002 /* create pointers to everything */
1003 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
1004 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
1005 szLabel
= (LPSTR
) &vol
[1];
1006 szPath
= &szLabel
[label_size
];
1007 szFinalPath
= &szPath
[path_size
];
1009 /* fill in the location information header */
1010 loc
->dwTotalSize
= total_size
;
1011 loc
->dwHeaderSize
= sizeof (*loc
);
1013 loc
->dwVolTableOfs
= sizeof (*loc
);
1014 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
1015 loc
->dwNetworkVolTableOfs
= 0;
1016 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
1018 /* fill in the volume information */
1019 vol
->dwSize
= volume_info_size
;
1020 vol
->dwType
= volume
->type
;
1021 vol
->dwVolSerial
= volume
->serial
;
1022 vol
->dwVolLabelOfs
= sizeof (*vol
);
1024 /* copy in the strings */
1025 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
1026 szLabel
, label_size
, NULL
, NULL
);
1027 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
1028 szPath
, path_size
, NULL
, NULL
);
1031 return IStream_Write( stm
, loc
, total_size
, &count
);
1034 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
1036 EXP_DARWIN_LINK
*buffer
;
1038 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
1039 buffer
->dbh
.cbSize
= sizeof *buffer
;
1040 buffer
->dbh
.dwSignature
= magic
;
1041 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
1042 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
1047 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
1049 EXP_DARWIN_LINK
*buffer
;
1054 buffer
= shelllink_build_darwinid( string
, magic
);
1056 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1059 /************************************************************************
1060 * IPersistStream_Save (IPersistStream)
1062 * FIXME: makes assumptions about byte order
1064 static HRESULT WINAPI
IPersistStream_fnSave(
1065 IPersistStream
* iface
,
1069 static const WCHAR wOpen
[] = {'o','p','e','n',0};
1072 WCHAR exePath
[MAX_PATH
];
1077 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1079 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1085 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, MAX_PATH
,
1086 NULL
, NULL
, NULL
, NULL
);
1088 * windows can create lnk files to executables that do not exist yet
1089 * so if the executable does not exist the just trust the path they
1092 if (!*exePath
) lstrcpyW(exePath
,This
->sPath
);
1095 memset(&header
, 0, sizeof(header
));
1096 header
.dwSize
= sizeof(header
);
1097 header
.fStartup
= This
->iShowCmd
;
1098 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
1100 header
.wHotKey
= This
->wHotKey
;
1101 header
.nIcon
= This
->iIcoNdx
;
1102 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1104 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1106 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1107 if( This
->sDescription
)
1108 header
.dwFlags
|= SLDF_HAS_NAME
;
1109 if( This
->sWorkDir
)
1110 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1112 header
.dwFlags
|= SLDF_HAS_ARGS
;
1113 if( This
->sIcoPath
)
1114 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1115 if( This
->sProduct
)
1116 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1117 if( This
->sComponent
)
1118 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1120 header
.dwFlags
|= SLDF_RUNAS_USER
;
1122 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1123 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1124 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1126 /* write the Shortcut header */
1127 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1130 ERR("Write failed at %d\n",__LINE__
);
1134 TRACE("Writing pidl\n");
1136 /* write the PIDL to the shortcut */
1139 r
= ILSaveToStream( stm
, This
->pPidl
);
1142 ERR("Failed to write PIDL at %d\n",__LINE__
);
1148 Stream_WriteLocationInfo( stm
, exePath
, &This
->volume
);
1150 if( This
->sDescription
)
1151 r
= Stream_WriteString( stm
, This
->sDescription
);
1153 if( This
->sPathRel
)
1154 r
= Stream_WriteString( stm
, This
->sPathRel
);
1156 if( This
->sWorkDir
)
1157 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1160 r
= Stream_WriteString( stm
, This
->sArgs
);
1162 if( This
->sIcoPath
)
1163 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1165 if( This
->sProduct
)
1166 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1168 if( This
->sComponent
)
1169 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1171 /* the last field is a single zero dword */
1173 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1178 /************************************************************************
1179 * IPersistStream_GetSizeMax (IPersistStream)
1181 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1182 IPersistStream
* iface
,
1183 ULARGE_INTEGER
* pcbSize
)
1185 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1187 TRACE("(%p)\n", This
);
1192 static const IPersistStreamVtbl psvt
=
1194 IPersistStream_fnQueryInterface
,
1195 IPersistStream_fnAddRef
,
1196 IPersistStream_fnRelease
,
1197 IPersistStream_fnGetClassID
,
1198 IPersistStream_fnIsDirty
,
1199 IPersistStream_fnLoad
,
1200 IPersistStream_fnSave
,
1201 IPersistStream_fnGetSizeMax
1204 /**************************************************************************
1205 * IShellLink_Constructor
1207 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1208 REFIID riid
, LPVOID
*ppv
)
1210 IShellLinkImpl
* sl
;
1213 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1218 return CLASS_E_NOAGGREGATION
;
1219 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1221 return E_OUTOFMEMORY
;
1225 sl
->lpvtblw
= &slvtw
;
1226 sl
->lpvtblPersistFile
= &pfvt
;
1227 sl
->lpvtblPersistStream
= &psvt
;
1228 sl
->lpvtblShellLinkDataList
= &dlvt
;
1229 sl
->lpvtblShellExtInit
= &eivt
;
1230 sl
->lpvtblContextMenu
= &cmvt
;
1231 sl
->lpvtblObjectWithSite
= &owsvt
;
1232 sl
->iShowCmd
= SW_SHOWNORMAL
;
1238 TRACE("(%p)->()\n",sl
);
1240 r
= ShellLink_QueryInterface( sl
, riid
, ppv
);
1241 ShellLink_Release( sl
);
1246 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1248 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1253 /**************************************************************************
1254 * ShellLink_UpdatePath
1255 * update absolute path in sPath using relative path in sPathRel
1257 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1259 if (!path
|| !psPath
)
1260 return E_INVALIDARG
;
1262 if (!*psPath
&& sPathRel
) {
1263 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1264 LPWSTR final
= NULL
;
1266 /* first try if [directory of link file] + [relative path] finds an existing file */
1268 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1271 lstrcpyW(final
, sPathRel
);
1275 if (SHELL_ExistsFileW(buffer
)) {
1276 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1277 lstrcpyW(abs_path
, buffer
);
1279 /* try if [working directory] + [relative path] finds an existing file */
1281 lstrcpyW(buffer
, sWorkDir
);
1282 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1284 if (SHELL_ExistsFileW(buffer
))
1285 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1286 lstrcpyW(abs_path
, buffer
);
1290 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1292 lstrcpyW(abs_path
, sPathRel
);
1294 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1296 return E_OUTOFMEMORY
;
1298 lstrcpyW(*psPath
, abs_path
);
1304 /**************************************************************************
1305 * IShellLink_ConstructFromFile
1307 HRESULT WINAPI
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1308 LPCITEMIDLIST pidl
, LPVOID
* ppv
)
1312 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1314 if (SUCCEEDED(hr
)) {
1319 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1321 if (SUCCEEDED(hr
)) {
1322 WCHAR path
[MAX_PATH
];
1324 if (SHGetPathFromIDListW(pidl
, path
))
1325 hr
= IPersistFile_Load(ppf
, path
, 0);
1330 *ppv
= (IUnknown
*) psl
;
1332 IPersistFile_Release(ppf
);
1336 IShellLinkW_Release(psl
);
1342 /**************************************************************************
1343 * IShellLinkA_QueryInterface
1345 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1347 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1348 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1351 /******************************************************************************
1352 * IShellLinkA_AddRef
1354 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
1356 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1357 return ShellLink_AddRef( This
);
1360 /******************************************************************************
1361 * IShellLinkA_Release
1363 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1365 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1366 return ShellLink_Release( This
);
1369 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1370 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1372 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1374 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1375 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1377 if (This
->sComponent
|| This
->sProduct
)
1383 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1384 pszFile
, cchMaxPath
, NULL
, NULL
);
1386 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1391 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1393 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1395 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1397 return IShellLinkW_GetIDList((IShellLinkW
*)&(This
->lpvtblw
), ppidl
);
1400 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1402 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1404 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1407 ILFree(This
->pPidl
);
1408 This
->pPidl
= ILClone (pidl
);
1409 This
->bDirty
= TRUE
;
1414 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1416 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1418 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1422 if( This
->sDescription
)
1423 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1424 pszName
, cchMaxName
, NULL
, NULL
);
1429 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1431 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1433 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1435 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1436 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1437 if ( !This
->sDescription
)
1438 return E_OUTOFMEMORY
;
1440 This
->bDirty
= TRUE
;
1445 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1447 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1449 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1453 if( This
->sWorkDir
)
1454 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1455 pszDir
, cchMaxPath
, NULL
, NULL
);
1460 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1462 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1464 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1466 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1467 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1468 if ( !This
->sWorkDir
)
1469 return E_OUTOFMEMORY
;
1471 This
->bDirty
= TRUE
;
1476 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1478 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1480 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1485 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1486 pszArgs
, cchMaxPath
, NULL
, NULL
);
1491 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1493 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1495 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1497 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1498 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1500 return E_OUTOFMEMORY
;
1502 This
->bDirty
= TRUE
;
1507 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1509 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1511 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1513 *pwHotkey
= This
->wHotKey
;
1518 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1520 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1522 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1524 This
->wHotKey
= wHotkey
;
1525 This
->bDirty
= TRUE
;
1530 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1532 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1534 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1535 *piShowCmd
= This
->iShowCmd
;
1539 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1541 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1543 TRACE("(%p) %d\n",This
, iShowCmd
);
1545 This
->iShowCmd
= iShowCmd
;
1546 This
->bDirty
= TRUE
;
1551 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1553 LPCITEMIDLIST pidlLast
;
1555 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1557 if (SUCCEEDED(hr
)) {
1560 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1562 if (SUCCEEDED(hr
)) {
1563 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1565 IExtractIconA_Release(pei
);
1568 IShellFolder_Release(psf
);
1574 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1576 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1578 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1581 *piIcon
= This
->iIcoNdx
;
1585 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1589 if (This
->pPidl
|| This
->sPath
)
1593 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1597 /* first look for an icon using the PIDL (if present) */
1599 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1603 /* if we couldn't find an icon yet, look for it using the file system path */
1604 if (FAILED(hr
) && This
->sPath
)
1608 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1610 if (SUCCEEDED(hr
)) {
1611 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1617 IShellFolder_Release(pdsk
);
1625 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1627 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1629 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1631 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1632 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1633 if ( !This
->sIcoPath
)
1634 return E_OUTOFMEMORY
;
1636 This
->iIcoNdx
= iIcon
;
1637 This
->bDirty
= TRUE
;
1642 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1644 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1646 TRACE("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1648 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1649 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1650 This
->bDirty
= TRUE
;
1652 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1655 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1657 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1659 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1661 return IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, fFlags
);
1664 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1668 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1670 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1672 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1674 return E_OUTOFMEMORY
;
1676 r
= IShellLinkW_SetPath((IShellLinkW
*)&(This
->lpvtblw
), str
);
1677 HeapFree( GetProcessHeap(), 0, str
);
1682 /**************************************************************************
1683 * IShellLink Implementation
1686 static const IShellLinkAVtbl slvt
=
1688 IShellLinkA_fnQueryInterface
,
1689 IShellLinkA_fnAddRef
,
1690 IShellLinkA_fnRelease
,
1691 IShellLinkA_fnGetPath
,
1692 IShellLinkA_fnGetIDList
,
1693 IShellLinkA_fnSetIDList
,
1694 IShellLinkA_fnGetDescription
,
1695 IShellLinkA_fnSetDescription
,
1696 IShellLinkA_fnGetWorkingDirectory
,
1697 IShellLinkA_fnSetWorkingDirectory
,
1698 IShellLinkA_fnGetArguments
,
1699 IShellLinkA_fnSetArguments
,
1700 IShellLinkA_fnGetHotkey
,
1701 IShellLinkA_fnSetHotkey
,
1702 IShellLinkA_fnGetShowCmd
,
1703 IShellLinkA_fnSetShowCmd
,
1704 IShellLinkA_fnGetIconLocation
,
1705 IShellLinkA_fnSetIconLocation
,
1706 IShellLinkA_fnSetRelativePath
,
1707 IShellLinkA_fnResolve
,
1708 IShellLinkA_fnSetPath
1712 /**************************************************************************
1713 * IShellLinkW_fnQueryInterface
1715 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1716 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1718 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1719 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1722 /******************************************************************************
1723 * IShellLinkW_fnAddRef
1725 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1727 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1728 return ShellLink_AddRef( This
);
1731 /******************************************************************************
1732 * IShellLinkW_fnRelease
1734 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1736 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1737 return ShellLink_Release( This
);
1740 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1742 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1744 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1745 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1747 if (This
->sComponent
|| This
->sProduct
)
1753 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1755 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1760 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1762 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1764 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1768 *ppidl
= ILClone(This
->pPidl
);
1772 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1774 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1776 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1779 ILFree( This
->pPidl
);
1780 This
->pPidl
= ILClone( pidl
);
1784 This
->bDirty
= TRUE
;
1789 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1791 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1793 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1796 if( This
->sDescription
)
1797 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1802 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1804 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1806 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1808 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1809 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1810 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1811 if ( !This
->sDescription
)
1812 return E_OUTOFMEMORY
;
1814 lstrcpyW( This
->sDescription
, pszName
);
1815 This
->bDirty
= TRUE
;
1820 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1822 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1824 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1828 if( This
->sWorkDir
)
1829 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1834 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1836 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1838 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1840 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1841 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1842 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1843 if ( !This
->sWorkDir
)
1844 return E_OUTOFMEMORY
;
1845 lstrcpyW( This
->sWorkDir
, pszDir
);
1846 This
->bDirty
= TRUE
;
1851 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1853 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1855 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1860 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1865 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1867 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1869 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1871 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1872 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1873 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1875 return E_OUTOFMEMORY
;
1876 lstrcpyW( This
->sArgs
, pszArgs
);
1877 This
->bDirty
= TRUE
;
1882 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1884 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1886 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1888 *pwHotkey
=This
->wHotKey
;
1893 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1895 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1897 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1899 This
->wHotKey
= wHotkey
;
1900 This
->bDirty
= TRUE
;
1905 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1907 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1909 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1911 *piShowCmd
= This
->iShowCmd
;
1916 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1918 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1920 This
->iShowCmd
= iShowCmd
;
1921 This
->bDirty
= TRUE
;
1926 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1928 LPCITEMIDLIST pidlLast
;
1930 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1932 if (SUCCEEDED(hr
)) {
1935 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1937 if (SUCCEEDED(hr
)) {
1938 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1940 IExtractIconW_Release(pei
);
1943 IShellFolder_Release(psf
);
1949 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1951 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1953 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1956 *piIcon
= This
->iIcoNdx
;
1960 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1964 if (This
->pPidl
|| This
->sPath
)
1968 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1972 /* first look for an icon using the PIDL (if present) */
1974 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1978 /* if we couldn't find an icon yet, look for it using the file system path */
1979 if (FAILED(hr
) && This
->sPath
)
1983 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1987 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1993 IShellFolder_Release(pdsk
);
2000 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
2002 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2004 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
2006 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
2007 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
2008 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
2009 if ( !This
->sIcoPath
)
2010 return E_OUTOFMEMORY
;
2011 lstrcpyW( This
->sIcoPath
, pszIconPath
);
2013 This
->iIcoNdx
= iIcon
;
2014 This
->bDirty
= TRUE
;
2019 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
2021 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2023 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
2025 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
2026 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
2027 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
2028 if ( !This
->sPathRel
)
2029 return E_OUTOFMEMORY
;
2030 lstrcpyW( This
->sPathRel
, pszPathRel
);
2031 This
->bDirty
= TRUE
;
2033 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
2036 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
2041 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2043 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
2045 /*FIXME: use IResolveShellLink interface */
2047 if (!This
->sPath
&& This
->pPidl
) {
2048 WCHAR buffer
[MAX_PATH
];
2050 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
2052 if (bSuccess
&& *buffer
) {
2053 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
2055 return E_OUTOFMEMORY
;
2057 lstrcpyW(This
->sPath
, buffer
);
2059 This
->bDirty
= TRUE
;
2061 hr
= S_OK
; /* don't report an error occurred while just caching information */
2064 if (!This
->sIcoPath
&& This
->sPath
) {
2065 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2066 if (!This
->sIcoPath
)
2067 return E_OUTOFMEMORY
;
2069 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2072 This
->bDirty
= TRUE
;
2078 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2087 p
= strchrW( str
, ':' );
2091 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2094 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2099 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2101 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2109 /* each segment must start with two colons */
2110 if( str
[0] != ':' || str
[1] != ':' )
2113 /* the last segment is just two colons */
2118 /* there must be a colon straight after a guid */
2119 p
= strchrW( str
, ':' );
2126 /* get the guid, and check it's validly formatted */
2127 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2129 r
= CLSIDFromString( szGuid
, &guid
);
2134 /* match it up to a guid that we care about */
2135 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2137 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2142 /* skip to the next field */
2143 str
= strchrW( str
, ':' );
2148 /* we have to have a component for an advertised shortcut */
2152 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2153 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2155 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2156 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2161 static BOOL
ShellLink_GetVolumeInfo(LPWSTR path
, volume_info
*volume
)
2163 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2164 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
2167 volume
->type
= GetDriveTypeW(drive
);
2168 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2169 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2170 TRACE("r = %d type %ld serial %08lx name %s\n", r
,
2171 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2175 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2177 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2178 WCHAR buffer
[MAX_PATH
];
2182 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2184 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2187 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2188 This
->sComponent
= NULL
;
2191 ILFree(This
->pPidl
);
2194 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2196 if (*pszFile
== '\0')
2198 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2200 else if(!PathFileExistsW(buffer
))
2203 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2204 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2206 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2207 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2209 return E_OUTOFMEMORY
;
2211 lstrcpyW(This
->sPath
, buffer
);
2213 This
->bDirty
= TRUE
;
2218 /**************************************************************************
2219 * IShellLinkW Implementation
2222 static const IShellLinkWVtbl slvtw
=
2224 IShellLinkW_fnQueryInterface
,
2225 IShellLinkW_fnAddRef
,
2226 IShellLinkW_fnRelease
,
2227 IShellLinkW_fnGetPath
,
2228 IShellLinkW_fnGetIDList
,
2229 IShellLinkW_fnSetIDList
,
2230 IShellLinkW_fnGetDescription
,
2231 IShellLinkW_fnSetDescription
,
2232 IShellLinkW_fnGetWorkingDirectory
,
2233 IShellLinkW_fnSetWorkingDirectory
,
2234 IShellLinkW_fnGetArguments
,
2235 IShellLinkW_fnSetArguments
,
2236 IShellLinkW_fnGetHotkey
,
2237 IShellLinkW_fnSetHotkey
,
2238 IShellLinkW_fnGetShowCmd
,
2239 IShellLinkW_fnSetShowCmd
,
2240 IShellLinkW_fnGetIconLocation
,
2241 IShellLinkW_fnSetIconLocation
,
2242 IShellLinkW_fnSetRelativePath
,
2243 IShellLinkW_fnResolve
,
2244 IShellLinkW_fnSetPath
2247 static HRESULT WINAPI
2248 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2250 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2251 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2255 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2257 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2258 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2262 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2264 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2265 return ShellLink_Release( This
);
2268 static HRESULT WINAPI
2269 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2275 static HRESULT WINAPI
2276 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2278 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2279 LPVOID block
= NULL
;
2282 TRACE("%p %08lx %p\n", iface
, dwSig
, ppDataBlock
);
2286 case EXP_DARWIN_ID_SIG
:
2287 if (!This
->sComponent
)
2289 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2292 case EXP_SZ_LINK_SIG
:
2293 case NT_CONSOLE_PROPS_SIG
:
2294 case NT_FE_CONSOLE_PROPS_SIG
:
2295 case EXP_SPECIAL_FOLDER_SIG
:
2296 case EXP_SZ_ICON_SIG
:
2297 FIXME("valid but unhandled datablock %08lx\n", dwSig
);
2300 ERR("unknown datablock %08lx\n", dwSig
);
2302 *ppDataBlock
= block
;
2306 static HRESULT WINAPI
2307 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2313 static HRESULT WINAPI
2314 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2316 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2319 FIXME("%p %p\n", This
, pdwFlags
);
2321 /* FIXME: add more */
2323 flags
|= SLDF_HAS_ARGS
;
2324 if (This
->sComponent
)
2325 flags
|= SLDF_HAS_DARWINID
;
2327 flags
|= SLDF_HAS_ICONLOCATION
;
2329 flags
|= SLDF_HAS_LOGO3ID
;
2331 flags
|= SLDF_HAS_ID_LIST
;
2338 static HRESULT WINAPI
2339 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2345 static const IShellLinkDataListVtbl dlvt
=
2347 ShellLink_DataList_QueryInterface
,
2348 ShellLink_DataList_AddRef
,
2349 ShellLink_DataList_Release
,
2350 ShellLink_AddDataBlock
,
2351 ShellLink_CopyDataBlock
,
2352 ShellLink_RemoveDataBlock
,
2357 static HRESULT WINAPI
2358 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2360 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2361 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2365 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2367 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2368 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2372 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2374 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2375 return ShellLink_Release( This
);
2378 /**************************************************************************
2379 * ShellLink implementation of IShellExtInit::Initialize()
2381 * Loads the shelllink from the dataobject the shell is pointing to.
2383 static HRESULT WINAPI
2384 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2385 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2387 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2393 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2398 format
.cfFormat
= CF_HDROP
;
2400 format
.dwAspect
= DVASPECT_CONTENT
;
2402 format
.tymed
= TYMED_HGLOBAL
;
2404 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2407 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2412 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2414 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2417 IPersistFile
*pf
= (IPersistFile
*) &This
->lpvtblPersistFile
;
2419 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2420 r
= IPersistFile_Load( pf
, path
, 0 );
2421 HeapFree( GetProcessHeap(), 0, path
);
2424 ReleaseStgMedium( &stgm
);
2429 static const IShellExtInitVtbl eivt
=
2431 ShellLink_ExtInit_QueryInterface
,
2432 ShellLink_ExtInit_AddRef
,
2433 ShellLink_ExtInit_Release
,
2434 ShellLink_ExtInit_Initialize
2437 static HRESULT WINAPI
2438 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2440 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2441 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2445 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2447 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2448 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2452 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2454 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2455 return ShellLink_Release( This
);
2458 static HRESULT WINAPI
2459 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2460 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2462 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2463 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2464 static const WCHAR szProperties
[] = { 'P','r','o','p','e','r','t','i','e','s',0 };
2468 TRACE("ShellLink_QueryContextMenu %p %p %u %u %u %u\n", This
,
2469 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2472 return E_INVALIDARG
;
2474 memset( &mii
, 0, sizeof(mii
) );
2475 mii
.cbSize
= sizeof (mii
);
2476 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2477 mii
.dwTypeData
= (LPWSTR
)szOpen
;
2478 mii
.cch
= strlenW( mii
.dwTypeData
);
2479 mii
.wID
= idCmdFirst
+ id
++;
2480 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2481 mii
.fType
= MFT_STRING
;
2482 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2484 TRACE("ShellLink_QueryContextMenu failed to insert item open");
2490 mii
.fState
= MFS_ENABLED
;
2491 mii
.dwTypeData
= (LPWSTR
)szProperties
;
2492 mii
.cch
= strlenW( mii
.dwTypeData
);
2493 mii
.wID
= idCmdFirst
+ id
++;
2494 if (!InsertMenuItemW( hmenu
, idCmdLast
, TRUE
, &mii
))
2496 TRACE("ShellLink_QueryContextMenu failed to insert item properties");
2499 This
->iIdProperties
= 1;
2501 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2505 shelllink_get_msi_component_path( LPWSTR component
)
2510 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2511 if (r
!= ERROR_SUCCESS
)
2515 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2516 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2517 if (r
!= ERROR_SUCCESS
)
2519 HeapFree( GetProcessHeap(), 0, path
);
2523 TRACE("returning %s\n", debugstr_w( path
) );
2528 /*************************************************************************
2530 * SH_CreatePropertySheetPage [Internal]
2532 * creates a property sheet page from an resource name
2537 SH_CreatePropertySheetPage(LPSTR resname
, DLGPROC dlgproc
, LPARAM lParam
)
2540 LPVOID lpsztemplate
;
2541 PROPSHEETPAGEW ppage
;
2543 if (resname
== NULL
)
2544 return (HPROPSHEETPAGE
)0;
2546 hRes
= FindResourceA(shell32_hInstance
, resname
, (LPSTR
)RT_DIALOG
);
2550 ERR("failed to find resource name\n");
2551 return (HPROPSHEETPAGE
)0;
2553 lpsztemplate
= LoadResource(shell32_hInstance
, hRes
);
2554 if (lpsztemplate
== NULL
)
2555 return (HPROPSHEETPAGE
)0;
2557 memset(&ppage
, 0x0, sizeof(PROPSHEETPAGE
));
2558 ppage
.dwSize
= sizeof(PROPSHEETPAGEW
);
2559 ppage
.dwFlags
= PSP_DLGINDIRECT
;
2560 ppage
.u
.pResource
= lpsztemplate
;
2561 ppage
.pfnDlgProc
= dlgproc
;
2562 ppage
.lParam
= lParam
;
2563 return CreatePropertySheetPageW(&ppage
);
2567 INT_PTR CALLBACK
ExtendedShortcutProc(
2581 hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2582 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2586 hDlgCtrl
= GetDlgItem(hwndDlg
, 14000);
2587 if (LOWORD(wParam
) == IDOK
)
2589 if ( SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2590 EndDialog(hwndDlg
, 1);
2592 EndDialog(hwndDlg
, 0);
2594 else if (LOWORD(wParam
) == IDCANCEL
)
2596 EndDialog(hwndDlg
, -1);
2598 else if (LOWORD(wParam
) == 14000)
2600 if ( SendMessage(hDlgCtrl
, BM_GETCHECK
, 0, 0) == BST_CHECKED
)
2601 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2603 SendMessage(hDlgCtrl
, BM_SETCHECK
, BST_CHECKED
, 0);
2610 /**************************************************************************
2611 * SH_ShellLinkDlgProc
2613 * dialog proc of the shortcut property dialog
2618 SH_ShellLinkDlgProc(
2625 LPPROPSHEETPAGEW ppsp
;
2627 IShellLinkImpl
*This
;
2629 WCHAR szBuffer
[MAX_PATH
];
2633 This
= (IShellLinkImpl
*)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
2638 ppsp
= (LPPROPSHEETPAGEW
)lParam
;
2642 TRACE("ShellLink_DlgProc (WM_INITDIALOG hwnd %p lParam %p ppsplParam %x)\n",hwndDlg
, lParam
, ppsp
->lParam
);
2644 This
= (IShellLinkImpl
*)ppsp
->lParam
;
2645 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)This
);
2647 TRACE("sArgs: %S sComponent: %S sDescription: %S sIcoPath: %S sPath: %S sPathRel: %S sProduct: %S sWorkDir: %S\n", This
->sArgs
, This
->sComponent
,This
->sDescription
,
2648 This
->sIcoPath
, This
->sPath
, This
->sPathRel
, This
->sProduct
, This
->sWorkDir
);
2651 hDlgCtrl
= GetDlgItem( hwndDlg
, 14009 );
2652 if ( hDlgCtrl
!= NULL
)
2653 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sPath
);
2656 hDlgCtrl
= GetDlgItem( hwndDlg
, 14011 );
2657 if ( hDlgCtrl
!= NULL
)
2658 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sWorkDir
);
2661 hDlgCtrl
= GetDlgItem( hwndDlg
, 14019 );
2662 if ( hDlgCtrl
!= NULL
)
2663 SendMessageW( hDlgCtrl
, WM_SETTEXT
, (WPARAM
)NULL
, (LPARAM
)This
->sDescription
);
2666 lppsn
= (LPPSHNOTIFY
) lParam
;
2667 if ( lppsn
->hdr
.code
== PSN_APPLY
)
2669 /* set working directory */
2670 hDlgCtrl
= GetDlgItem( hwndDlg
, 14011 );
2671 SendMessageW( hDlgCtrl
, WM_GETTEXT
, (WPARAM
)MAX_PATH
, (LPARAM
)szBuffer
);
2672 IShellLinkW_fnSetWorkingDirectory((IShellLinkW
*)&This
->lpvtblw
, szBuffer
);
2673 /* set link destination */
2674 hDlgCtrl
= GetDlgItem( hwndDlg
, 14009 );
2675 SendMessageW( hDlgCtrl
, WM_GETTEXT
, (WPARAM
)MAX_PATH
, (LPARAM
)szBuffer
);
2676 if ( !SHELL_ExistsFileW(szBuffer
) )
2678 MessageBoxW( hwndDlg
, L
"file not existing", szBuffer
, MB_OK
);
2679 SetWindowLong( hwndDlg
, DWL_MSGRESULT
, PSNRET_INVALID_NOCHANGEPAGE
);
2682 IShellLinkW_fnSetPath((IShellLinkW
*)&This
->lpvtblw
, szBuffer
);
2684 TRACE("This %p sLinkPath %S\n", This
, This
->sLinkPath
);
2685 IPersistFile_fnSave( (IPersistFile
*)&This
->lpvtblPersistFile
, This
->sLinkPath
, TRUE
);
2686 SetWindowLong( hwndDlg
, DWL_MSGRESULT
, PSNRET_NOERROR
);
2691 switch(LOWORD(wParam
))
2696 /// open target directory
2700 if (PickIconDlg(hwndDlg
, szBuffer
, MAX_PATH
, &IconIndex
))
2702 IShellLinkW_fnSetIconLocation((IShellLinkW
*)&This
->lpvtblw
, szBuffer
, IconIndex
);
2704 /// FIXME redraw icon
2708 result
= DialogBoxParamW(shell32_hInstance
, MAKEINTRESOURCEW(SHELL_EXTENDED_SHORTCUT_DLG
), hwndDlg
, ExtendedShortcutProc
, (LPARAM
)This
->bRunAs
);
2709 if (result
== 1 || result
== 0)
2711 if ( This
->bRunAs
!= result
)
2713 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2716 This
->bRunAs
= result
;
2720 switch(HIWORD(wParam
))
2723 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
2733 /**************************************************************************
2734 * ShellLink_ShortcutDialog [Internal]
2736 * creates a shortcut property dialog
2739 static HRESULT WINAPI
2740 ShellLink_ShowProperties( IShellLinkImpl
*This
)
2742 PROPSHEETHEADERW pinfo
;
2743 HPROPSHEETPAGE hppages
[MAX_PROPERTY_SHEET_PAGE
];
2744 HPROPSHEETPAGE hpage
;
2747 TRACE("ShellLink_ShortcutDialog entered\n");
2749 memset(hppages
, 0x0, sizeof(HPROPSHEETPAGE
) * MAX_PROPERTY_SHEET_PAGE
);
2751 hpage
= SH_CreatePropertySheetPage("SHELL_FILE_GENERAL_DLG", SH_FileGeneralDlgProc
, (LPARAM
)This
->sLinkPath
);
2752 if ( hpage
== NULL
)
2755 hppages
[numpages
++] = hpage
;
2757 hpage
= SH_CreatePropertySheetPage("SHELL_GENERAL_SHORTCUT_DLG", SH_ShellLinkDlgProc
, (LPARAM
)This
);
2758 if ( hpage
== NULL
)
2760 ERR("SH_CreatePropertySheetPage failed\n");
2761 DestroyPropertySheetPage(hppages
[0]);
2764 hppages
[numpages
++] = hpage
;
2769 memset(&pinfo
, 0x0, sizeof(PROPSHEETHEADERW
));
2770 pinfo
.dwSize
= sizeof(PROPSHEETHEADERW
);
2771 pinfo
.dwFlags
= PSH_NOCONTEXTHELP
| PSH_PROPTITLE
;
2772 pinfo
.nPages
= numpages
;
2773 pinfo
.u3
.phpage
= hppages
;
2774 pinfo
.pszCaption
= This
->sDescription
;
2775 pinfo
.u2
.nStartPage
= 1;
2777 if ( PropertySheetW(&pinfo
) < 0 )
2783 static HRESULT WINAPI
2784 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2786 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2787 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2788 SHELLEXECUTEINFOW sei
;
2789 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2794 TRACE("ShellLink_InvokeCommand %p %p\n", This
, lpici
);
2796 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2797 return E_INVALIDARG
;
2799 if ( lpici
->lpVerb
== MAKEINTRESOURCEA(This
->iIdProperties
))
2801 ShellLink_ShowProperties(This
);
2806 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2808 ERR("Unknown id %d != %d\n", (INT
)lpici
->lpVerb
, This
->iIdOpen
);
2809 return E_INVALIDARG
;
2812 r
= IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, 0 );
2816 if ( This
->sComponent
)
2818 path
= shelllink_get_msi_component_path( This
->sComponent
);
2823 path
= strdupW( This
->sPath
);
2825 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2826 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2828 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2832 len
+= lstrlenW( This
->sArgs
);
2833 if ( iciex
->lpParametersW
)
2834 len
+= lstrlenW( iciex
->lpParametersW
);
2836 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2839 lstrcatW( args
, This
->sArgs
);
2840 if ( iciex
->lpParametersW
)
2842 static const WCHAR space
[] = { ' ', 0 };
2843 lstrcatW( args
, space
);
2844 lstrcatW( args
, iciex
->lpParametersW
);
2848 memset( &sei
, 0, sizeof sei
);
2849 sei
.cbSize
= sizeof sei
;
2850 sei
.fMask
= SEE_MASK_UNICODE
;
2852 sei
.nShow
= This
->iShowCmd
;
2853 sei
.lpIDList
= This
->pPidl
;
2854 sei
.lpDirectory
= This
->sWorkDir
;
2855 sei
.lpParameters
= args
;
2856 sei
.lpVerb
= szOpen
;
2858 if ( ShellExecuteExW( &sei
) && (UINT
)sei
.hInstApp
> 32 )
2863 HeapFree( GetProcessHeap(), 0, args
);
2864 HeapFree( GetProcessHeap(), 0, path
);
2869 static HRESULT WINAPI
2870 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2871 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2873 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2875 FIXME("%p %u %u %p %p %u\n", This
,
2876 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2881 static const IContextMenuVtbl cmvt
=
2883 ShellLink_ContextMenu_QueryInterface
,
2884 ShellLink_ContextMenu_AddRef
,
2885 ShellLink_ContextMenu_Release
,
2886 ShellLink_QueryContextMenu
,
2887 ShellLink_InvokeCommand
,
2888 ShellLink_GetCommandString
2891 static HRESULT WINAPI
2892 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2894 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2895 return ShellLink_QueryInterface( This
, riid
, ppvObject
);
2899 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2901 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2902 return ShellLink_AddRef( This
);
2906 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2908 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2909 return ShellLink_Release( This
);
2912 static HRESULT WINAPI
2913 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2915 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2917 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2921 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2924 static HRESULT WINAPI
2925 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2927 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2929 TRACE("%p %p\n", iface
, punk
);
2932 IUnknown_AddRef( punk
);
2938 static const IObjectWithSiteVtbl owsvt
=
2940 ShellLink_ObjectWithSite_QueryInterface
,
2941 ShellLink_ObjectWithSite_AddRef
,
2942 ShellLink_ObjectWithSite_Release
,