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"
57 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
59 DEFINE_GUID( SHELL32_AdvtShortcutProduct
,
60 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
61 DEFINE_GUID( SHELL32_AdvtShortcutComponent
,
62 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
64 /* link file formats */
68 typedef struct _LINK_HEADER
70 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
71 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
72 DWORD dwFlags
; /* 0x14 describes elements following */
73 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
74 FILETIME Time1
; /* 0x1c */
75 FILETIME Time2
; /* 0x24 */
76 FILETIME Time3
; /* 0x2c */
77 DWORD dwFileLength
; /* 0x34 File length */
78 DWORD nIcon
; /* 0x38 icon number */
79 DWORD fStartup
; /* 0x3c startup type */
80 DWORD wHotKey
; /* 0x40 hotkey */
81 DWORD Unknown5
; /* 0x44 */
82 DWORD Unknown6
; /* 0x48 */
83 } LINK_HEADER
, * PLINK_HEADER
;
85 #define SHLINK_LOCAL 0
86 #define SHLINK_REMOTE 1
88 typedef struct _LOCATION_INFO
95 DWORD dwNetworkVolTableOfs
;
99 typedef struct _LOCAL_VOLUME_INFO
107 typedef struct volume_info_t
111 WCHAR label
[12]; /* assume 8.3 */
116 static const IShellLinkAVtbl slvt
;
117 static const IShellLinkWVtbl slvtw
;
118 static const IPersistFileVtbl pfvt
;
119 static const IPersistStreamVtbl psvt
;
120 static const IShellLinkDataListVtbl dlvt
;
121 static const IShellExtInitVtbl eivt
;
122 static const IContextMenuVtbl cmvt
;
124 /* IShellLink Implementation */
128 const IShellLinkAVtbl
*lpVtbl
;
129 const IShellLinkWVtbl
*lpvtblw
;
130 const IPersistFileVtbl
*lpvtblPersistFile
;
131 const IPersistStreamVtbl
*lpvtblPersistStream
;
132 const IShellLinkDataListVtbl
*lpvtblShellLinkDataList
;
133 const IShellExtInitVtbl
*lpvtblShellExtInit
;
134 const IContextMenuVtbl
*lpvtblContextMenu
;
138 /* data structures according to the informations in the link */
160 static inline IShellLinkImpl
*impl_from_IShellLinkW( IShellLinkW
*iface
)
162 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblw
));
164 #define _ICOM_THIS_From_IShellLinkW(class, iface) \
165 class* This = impl_from_IShellLinkW( iface )
167 static inline IShellLinkImpl
*impl_from_IPersistFile( IPersistFile
*iface
)
169 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistFile
));
171 #define _ICOM_THIS_From_IPersistFile(class, iface) \
172 class* This = impl_from_IPersistFile( iface )
174 static inline IShellLinkImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
176 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistStream
));
178 #define _ICOM_THIS_From_IPersistStream(class, iface) \
179 class* This = impl_from_IPersistStream( iface )
181 static inline IShellLinkImpl
*impl_from_IShellLinkDataList( IShellLinkDataList
*iface
)
183 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellLinkDataList
));
185 #define _ICOM_THIS_From_IShellLinkDataList(class, iface) \
186 class* This = impl_from_IShellLinkDataList( iface )
188 static inline IShellLinkImpl
*impl_from_IShellExtInit( IShellExtInit
*iface
)
190 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellExtInit
));
192 #define _ICOM_THIS_From_IShellExtInit(class, iface) \
193 class* This = impl_from_IShellExtInit( iface )
195 static inline IShellLinkImpl
*impl_from_IContextMenu( IContextMenu
*iface
)
197 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblContextMenu
));
199 #define _ICOM_THIS_From_IContextMenu(class, iface) \
200 class* This = impl_from_IContextMenu( iface )
202 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
204 /* strdup on the process heap */
205 inline static LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
207 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
208 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
211 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
215 /**************************************************************************
216 * ShellLink::QueryInterface implementation
218 static HRESULT
ShellLink_QueryInterface( IShellLinkImpl
*This
, REFIID riid
, LPVOID
*ppvObj
)
220 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
224 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
228 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
230 *ppvObj
= &(This
->lpvtblw
);
232 else if(IsEqualIID(riid
, &IID_IPersistFile
))
234 *ppvObj
= &(This
->lpvtblPersistFile
);
236 else if(IsEqualIID(riid
, &IID_IPersistStream
))
238 *ppvObj
= &(This
->lpvtblPersistStream
);
240 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
242 *ppvObj
= &(This
->lpvtblShellLinkDataList
);
244 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
246 *ppvObj
= &(This
->lpvtblShellExtInit
);
248 else if(IsEqualIID(riid
, &IID_IContextMenu
))
250 *ppvObj
= &(This
->lpvtblContextMenu
);
255 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
256 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
259 ERR("-- Interface: E_NOINTERFACE\n");
260 return E_NOINTERFACE
;
263 /**************************************************************************
264 * ShellLink::AddRef implementation
266 static ULONG
ShellLink_AddRef( IShellLinkImpl
*This
)
268 ULONG refCount
= InterlockedIncrement(&This
->ref
);
270 TRACE("(%p)->(count=%lu)\n", This
, refCount
- 1);
275 /**************************************************************************
276 * ShellLink::Release implementation
278 static ULONG
ShellLink_Release( IShellLinkImpl
*This
)
280 ULONG refCount
= InterlockedDecrement(&This
->ref
);
282 TRACE("(%p)->(count=%lu)\n", This
, refCount
+ 1);
287 TRACE("-- destroying IShellLink(%p)\n",This
);
289 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
290 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
291 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
292 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
293 HeapFree(GetProcessHeap(),0,This
->sPath
);
298 LocalFree((HANDLE
)This
);
303 static HRESULT
ShellLink_GetClassID( IShellLinkImpl
*This
, CLSID
*pclsid
)
305 TRACE("%p %p\n", This
, pclsid
);
307 memcpy( pclsid
, &CLSID_ShellLink
, sizeof (CLSID
) );
311 /**************************************************************************
312 * IPersistFile_QueryInterface
314 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
319 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
320 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
323 /******************************************************************************
324 * IPersistFile_AddRef
326 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
328 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
329 return ShellLink_AddRef( This
);
332 /******************************************************************************
333 * IPersistFile_Release
335 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
337 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
338 return IShellLinkA_Release((IShellLinkA
*)This
);
341 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
343 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
344 return ShellLink_GetClassID( This
, pClassID
);
347 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
349 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
351 TRACE("(%p)\n",This
);
359 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
361 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
362 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
366 TRACE("(%p, %s, %lx)\n",This
, debugstr_w(pszFileName
), dwMode
);
369 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
370 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
373 r
= IPersistStream_Load(StreamThis
, stm
);
374 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
375 IStream_Release( stm
);
376 This
->bDirty
= FALSE
;
378 TRACE("-- returning hr %08lx\n", r
);
382 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
384 static const WCHAR szFormat
[] = {
385 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
386 ' ','-','r',' ','"','%','s','"',0 };
390 PROCESS_INFORMATION pi
;
392 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
393 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
397 wsprintfW( buffer
, szFormat
, szLink
);
399 TRACE("starting %s\n",debugstr_w(buffer
));
401 memset(&si
, 0, sizeof(si
));
403 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
405 /* wait for a while to throttle the creation of linker processes */
406 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
407 WARN("Timed out waiting for shell linker\n");
409 CloseHandle( pi
.hProcess
);
410 CloseHandle( pi
.hThread
);
415 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
417 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
418 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
422 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
427 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
430 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
431 IStream_Release( stm
);
435 StartLinkProcessor( pszFileName
);
437 This
->bDirty
= FALSE
;
441 DeleteFileW( pszFileName
);
442 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
449 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
451 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
452 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
456 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
458 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
459 FIXME("(%p)\n",This
);
463 static const IPersistFileVtbl pfvt
=
465 IPersistFile_fnQueryInterface
,
466 IPersistFile_fnAddRef
,
467 IPersistFile_fnRelease
,
468 IPersistFile_fnGetClassID
,
469 IPersistFile_fnIsDirty
,
472 IPersistFile_fnSaveCompleted
,
473 IPersistFile_fnGetCurFile
476 /************************************************************************
477 * IPersistStream_QueryInterface
479 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
480 IPersistStream
* iface
,
484 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
485 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
488 /************************************************************************
489 * IPersistStream_Release
491 static ULONG WINAPI
IPersistStream_fnRelease(
492 IPersistStream
* iface
)
494 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
495 return IShellLinkA_Release((IShellLinkA
*)This
);
498 /************************************************************************
499 * IPersistStream_AddRef
501 static ULONG WINAPI
IPersistStream_fnAddRef(
502 IPersistStream
* iface
)
504 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
505 return ShellLink_AddRef( This
);
508 /************************************************************************
509 * IPersistStream_GetClassID
512 static HRESULT WINAPI
IPersistStream_fnGetClassID(
513 IPersistStream
* iface
,
516 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
517 return ShellLink_GetClassID( This
, pClassID
);
520 /************************************************************************
521 * IPersistStream_IsDirty (IPersistStream)
523 static HRESULT WINAPI
IPersistStream_fnIsDirty(
524 IPersistStream
* iface
)
526 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
528 TRACE("(%p)\n", This
);
534 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
545 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
546 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
550 len
*= sizeof (WCHAR
);
552 TRACE("reading %d\n", len
);
553 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
555 return E_OUTOFMEMORY
;
557 r
= IStream_Read(stm
, temp
, len
, &count
);
558 if( FAILED (r
) || ( count
!= len
) )
560 HeapFree( GetProcessHeap(), 0, temp
);
564 TRACE("read %s\n", debugstr_an(temp
,len
));
566 /* convert to unicode if necessary */
569 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
570 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
572 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
573 HeapFree( GetProcessHeap(), 0, temp
);
587 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
594 unsigned char data
[1];
599 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
600 if( FAILED( r
) || count
!= sizeof(size
) )
603 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
605 return E_OUTOFMEMORY
;
608 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
609 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
611 HeapFree( GetProcessHeap(), 0, chunk
);
615 TRACE("Read %ld bytes\n",chunk
->size
);
617 *data
= (LPVOID
) chunk
;
622 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
624 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
628 volume
->serial
= vol
->dwVolSerial
;
629 volume
->type
= vol
->dwType
;
631 if( !vol
->dwVolLabelOfs
)
633 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
635 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
638 label
+= vol
->dwVolLabelOfs
;
639 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
644 static LPWSTR
Stream_LoadPath( LPSTR p
, DWORD maxlen
)
649 while( p
[len
] && (len
< maxlen
) )
652 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
653 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
654 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
660 static HRESULT
Stream_LoadLocation( IStream
*stm
,
661 volume_info
*volume
, LPWSTR
*path
)
668 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
672 loc
= (LOCATION_INFO
*) p
;
673 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
675 HeapFree( GetProcessHeap(), 0, p
);
679 /* if there's valid local volume information, load it */
680 if( loc
->dwVolTableOfs
&&
681 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
683 LOCAL_VOLUME_INFO
*volume_info
;
685 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
686 Stream_LoadVolume( volume_info
, volume
);
689 /* if there's a local path, load it */
690 n
= loc
->dwLocalPathOfs
;
691 if( n
&& (n
< loc
->dwTotalSize
) )
692 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
694 TRACE("type %ld serial %08lx name %s path %s\n", volume
->type
,
695 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
697 HeapFree( GetProcessHeap(), 0, p
);
702 * The format of the advertised shortcut info seems to be:
707 * 0 Length of the block (4 bytes, usually 0x314)
709 * 8 string data in ASCII
710 * 8+0x104 string data in UNICODE
712 * In the original Win32 implementation the buffers are not initialized
713 * to zero, so data trailing the string is random garbage.
715 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
720 EXP_DARWIN_LINK buffer
;
724 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
728 /* make sure that we read the size of the structure even on error */
729 size
= sizeof buffer
- sizeof (DWORD
);
730 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
732 ERR("Ooops. This structure is not as expected...\n");
736 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
743 TRACE("magic %08lx string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
745 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
747 ERR("Unknown magic number %08lx in advertised shortcut\n", buffer
.dbh
.dwSignature
);
751 *str
= HeapAlloc( GetProcessHeap(), 0,
752 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
753 lstrcpyW( *str
, buffer
.szwDarwinID
);
758 /************************************************************************
759 * IPersistStream_Load (IPersistStream)
761 static HRESULT WINAPI
IPersistStream_fnLoad(
762 IPersistStream
* iface
,
771 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
773 TRACE("%p %p\n", This
, stm
);
776 return STG_E_INVALIDPOINTER
;
779 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
783 if( dwBytesRead
!= sizeof(hdr
))
785 if( hdr
.dwSize
!= sizeof(hdr
))
787 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
790 /* free all the old stuff */
793 memset( &This
->volume
, 0, sizeof This
->volume
);
794 HeapFree(GetProcessHeap(), 0, This
->sPath
);
796 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
797 This
->sDescription
= NULL
;
798 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
799 This
->sPathRel
= NULL
;
800 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
801 This
->sWorkDir
= NULL
;
802 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
804 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
805 This
->sIcoPath
= NULL
;
806 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
807 This
->sProduct
= NULL
;
808 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
809 This
->sComponent
= NULL
;
811 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
812 This
->iIcoNdx
= hdr
.nIcon
;
813 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
814 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
815 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
818 WCHAR sTemp
[MAX_PATH
];
819 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
820 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
821 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
822 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
823 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
824 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
825 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
826 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
827 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
830 /* load all the new stuff */
831 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
833 r
= ILLoadFromStream( stm
, &This
->pPidl
);
839 /* load the location information */
840 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
841 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
845 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
846 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
848 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
849 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
854 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
856 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
857 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
862 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
864 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
865 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
870 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
872 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
873 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
878 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
880 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
881 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
886 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
888 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
889 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
894 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
896 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
897 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
902 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
903 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
904 ERR("Last word was not zero\n");
915 /************************************************************************
918 * Helper function for IPersistStream_Save. Writes a unicode string
919 * with terminating nul byte to a stream, preceded by the its length.
921 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
923 USHORT len
= lstrlenW( str
) + 1;
927 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
931 len
*= sizeof(WCHAR
);
933 r
= IStream_Write( stm
, str
, len
, &count
);
940 /************************************************************************
941 * Stream_WriteLocationInfo
943 * Writes the location info to a stream
945 * FIXME: One day we might want to write the network volume information
946 * and the final path.
947 * Figure out how Windows deals with unicode paths here.
949 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
950 volume_info
*volume
)
952 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
953 LOCAL_VOLUME_INFO
*vol
;
955 LPSTR szLabel
, szPath
, szFinalPath
;
958 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
960 /* figure out the size of everything */
961 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
962 NULL
, 0, NULL
, NULL
);
963 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
964 NULL
, 0, NULL
, NULL
);
965 volume_info_size
= sizeof *vol
+ label_size
;
967 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
969 /* create pointers to everything */
970 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
971 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
972 szLabel
= (LPSTR
) &vol
[1];
973 szPath
= &szLabel
[label_size
];
974 szFinalPath
= &szPath
[path_size
];
976 /* fill in the location information header */
977 loc
->dwTotalSize
= total_size
;
978 loc
->dwHeaderSize
= sizeof (*loc
);
980 loc
->dwVolTableOfs
= sizeof (*loc
);
981 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
982 loc
->dwNetworkVolTableOfs
= 0;
983 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
985 /* fill in the volume information */
986 vol
->dwSize
= volume_info_size
;
987 vol
->dwType
= volume
->type
;
988 vol
->dwVolSerial
= volume
->serial
;
989 vol
->dwVolLabelOfs
= sizeof (*vol
);
991 /* copy in the strings */
992 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
993 szLabel
, label_size
, NULL
, NULL
);
994 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
995 szPath
, path_size
, NULL
, NULL
);
998 return IStream_Write( stm
, loc
, total_size
, &count
);
1001 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
1004 EXP_DARWIN_LINK buffer
;
1008 memset( &buffer
, 0, sizeof buffer
);
1009 buffer
.dbh
.cbSize
= sizeof buffer
;
1010 buffer
.dbh
.dwSignature
= magic
;
1011 lstrcpynW( buffer
.szwDarwinID
, string
, MAX_PATH
);
1012 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
.szDarwinID
, MAX_PATH
, NULL
, NULL
);
1014 return IStream_Write( stm
, &buffer
, buffer
.dbh
.cbSize
, &count
);
1017 /************************************************************************
1018 * IPersistStream_Save (IPersistStream)
1020 * FIXME: makes assumptions about byte order
1022 static HRESULT WINAPI
IPersistStream_fnSave(
1023 IPersistStream
* iface
,
1027 static const WCHAR wOpen
[] = {'o','p','e','n',0};
1030 WCHAR exePath
[MAX_PATH
];
1035 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
1037 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1043 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, MAX_PATH
,
1044 NULL
, NULL
, NULL
, NULL
);
1046 * windows can create lnk files to executables that do not exist yet
1047 * so if the executable does not exist the just trust the path they
1050 if (!*exePath
) lstrcpyW(exePath
,This
->sPath
);
1053 memset(&header
, 0, sizeof(header
));
1054 header
.dwSize
= sizeof(header
);
1055 header
.fStartup
= This
->iShowCmd
;
1056 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
1058 header
.wHotKey
= This
->wHotKey
;
1059 header
.nIcon
= This
->iIcoNdx
;
1060 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1062 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1064 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1065 if( This
->sDescription
)
1066 header
.dwFlags
|= SLDF_HAS_NAME
;
1067 if( This
->sWorkDir
)
1068 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1070 header
.dwFlags
|= SLDF_HAS_ARGS
;
1071 if( This
->sIcoPath
)
1072 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1073 if( This
->sProduct
)
1074 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1075 if( This
->sComponent
)
1076 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1078 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1079 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1080 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1082 /* write the Shortcut header */
1083 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1086 ERR("Write failed at %d\n",__LINE__
);
1090 TRACE("Writing pidl \n");
1092 /* write the PIDL to the shortcut */
1095 r
= ILSaveToStream( stm
, This
->pPidl
);
1098 ERR("Failed to write PIDL at %d\n",__LINE__
);
1104 Stream_WriteLocationInfo( stm
, exePath
, &This
->volume
);
1106 if( This
->sDescription
)
1107 r
= Stream_WriteString( stm
, This
->sDescription
);
1109 if( This
->sPathRel
)
1110 r
= Stream_WriteString( stm
, This
->sPathRel
);
1112 if( This
->sWorkDir
)
1113 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1116 r
= Stream_WriteString( stm
, This
->sArgs
);
1118 if( This
->sIcoPath
)
1119 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1121 if( This
->sProduct
)
1122 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1124 if( This
->sComponent
)
1125 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1127 /* the last field is a single zero dword */
1129 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1134 /************************************************************************
1135 * IPersistStream_GetSizeMax (IPersistStream)
1137 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1138 IPersistStream
* iface
,
1139 ULARGE_INTEGER
* pcbSize
)
1141 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
1143 TRACE("(%p)\n", This
);
1148 static const IPersistStreamVtbl psvt
=
1150 IPersistStream_fnQueryInterface
,
1151 IPersistStream_fnAddRef
,
1152 IPersistStream_fnRelease
,
1153 IPersistStream_fnGetClassID
,
1154 IPersistStream_fnIsDirty
,
1155 IPersistStream_fnLoad
,
1156 IPersistStream_fnSave
,
1157 IPersistStream_fnGetSizeMax
1160 /**************************************************************************
1161 * IShellLink_Constructor
1163 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1164 REFIID riid
, LPVOID
*ppv
)
1166 IShellLinkImpl
* sl
;
1168 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1173 return CLASS_E_NOAGGREGATION
;
1174 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1176 return E_OUTOFMEMORY
;
1180 sl
->lpvtblw
= &slvtw
;
1181 sl
->lpvtblPersistFile
= &pfvt
;
1182 sl
->lpvtblPersistStream
= &psvt
;
1183 sl
->lpvtblShellLinkDataList
= &dlvt
;
1184 sl
->lpvtblShellExtInit
= &eivt
;
1185 sl
->lpvtblContextMenu
= &cmvt
;
1186 sl
->iShowCmd
= SW_SHOWNORMAL
;
1189 TRACE("(%p)->()\n",sl
);
1191 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1192 IsEqualIID(riid
, &IID_IShellLinkA
))
1194 else if (IsEqualIID(riid
, &IID_IShellLinkW
))
1195 *ppv
= &(sl
->lpvtblw
);
1197 LocalFree((HLOCAL
)sl
);
1198 ERR("E_NOINTERFACE\n");
1199 return E_NOINTERFACE
;
1206 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1208 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1213 /**************************************************************************
1214 * ShellLink_UpdatePath
1215 * update absolute path in sPath using relative path in sPathRel
1217 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1219 if (!path
|| !psPath
)
1220 return E_INVALIDARG
;
1222 if (!*psPath
&& sPathRel
) {
1223 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1224 LPWSTR final
= NULL
;
1226 /* first try if [directory of link file] + [relative path] finds an existing file */
1228 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1231 lstrcpyW(final
, sPathRel
);
1235 if (SHELL_ExistsFileW(buffer
)) {
1236 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1237 lstrcpyW(abs_path
, buffer
);
1239 /* try if [working directory] + [relative path] finds an existing file */
1241 lstrcpyW(buffer
, sWorkDir
);
1242 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1244 if (SHELL_ExistsFileW(buffer
))
1245 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1246 lstrcpyW(abs_path
, buffer
);
1250 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1252 lstrcpyW(abs_path
, sPathRel
);
1254 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1256 return E_OUTOFMEMORY
;
1258 lstrcpyW(*psPath
, abs_path
);
1264 /**************************************************************************
1265 * IShellLink_ConstructFromFile
1267 HRESULT WINAPI
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1268 LPCITEMIDLIST pidl
, LPVOID
* ppv
)
1272 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1274 if (SUCCEEDED(hr
)) {
1279 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1281 if (SUCCEEDED(hr
)) {
1282 WCHAR path
[MAX_PATH
];
1284 if (SHGetPathFromIDListW(pidl
, path
))
1285 hr
= IPersistFile_Load(ppf
, path
, 0);
1290 *ppv
= (IUnknown
*) psl
;
1292 IPersistFile_Release(ppf
);
1296 IShellLinkW_Release(psl
);
1302 /**************************************************************************
1303 * IShellLinkA_QueryInterface
1305 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1307 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1308 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1311 /******************************************************************************
1312 * IShellLinkA_AddRef
1314 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
1316 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1317 return ShellLink_AddRef( This
);
1320 /******************************************************************************
1321 * IShellLinkA_Release
1323 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1325 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1326 return ShellLink_Release( This
);
1329 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1330 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1332 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1334 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1335 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1337 if (This
->sComponent
|| This
->sProduct
)
1343 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1344 pszFile
, cchMaxPath
, NULL
, NULL
);
1346 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1351 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1353 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1355 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1357 return IShellLinkW_GetIDList((IShellLinkW
*)&(This
->lpvtblw
), ppidl
);
1360 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1362 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1364 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1367 ILFree(This
->pPidl
);
1368 This
->pPidl
= ILClone (pidl
);
1369 This
->bDirty
= TRUE
;
1374 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1376 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1378 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1382 if( This
->sDescription
)
1383 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1384 pszName
, cchMaxName
, NULL
, NULL
);
1389 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1391 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1393 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1395 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1396 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1397 if ( !This
->sDescription
)
1398 return E_OUTOFMEMORY
;
1400 This
->bDirty
= TRUE
;
1405 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1407 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1409 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1413 if( This
->sWorkDir
)
1414 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1415 pszDir
, cchMaxPath
, NULL
, NULL
);
1420 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1422 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1424 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1426 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1427 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1428 if ( !This
->sWorkDir
)
1429 return E_OUTOFMEMORY
;
1431 This
->bDirty
= TRUE
;
1436 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1438 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1440 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1445 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1446 pszArgs
, cchMaxPath
, NULL
, NULL
);
1451 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1453 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1455 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1457 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1458 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1460 return E_OUTOFMEMORY
;
1462 This
->bDirty
= TRUE
;
1467 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1469 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1471 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1473 *pwHotkey
= This
->wHotKey
;
1478 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1480 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1482 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1484 This
->wHotKey
= wHotkey
;
1485 This
->bDirty
= TRUE
;
1490 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1492 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1494 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1495 *piShowCmd
= This
->iShowCmd
;
1499 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1501 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1503 TRACE("(%p) %d\n",This
, iShowCmd
);
1505 This
->iShowCmd
= iShowCmd
;
1506 This
->bDirty
= TRUE
;
1511 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1513 LPCITEMIDLIST pidlLast
;
1515 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1517 if (SUCCEEDED(hr
)) {
1520 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1522 if (SUCCEEDED(hr
)) {
1523 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1525 IExtractIconA_Release(pei
);
1528 IShellFolder_Release(psf
);
1534 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1536 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1538 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1541 *piIcon
= This
->iIcoNdx
;
1545 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1549 if (This
->pPidl
|| This
->sPath
)
1553 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1557 /* first look for an icon using the PIDL (if present) */
1559 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1563 /* if we couldn't find an icon yet, look for it using the file system path */
1564 if (FAILED(hr
) && This
->sPath
)
1568 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1570 if (SUCCEEDED(hr
)) {
1571 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1577 IShellFolder_Release(pdsk
);
1585 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1587 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1589 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1591 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1592 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1593 if ( !This
->sIcoPath
)
1594 return E_OUTOFMEMORY
;
1596 This
->iIcoNdx
= iIcon
;
1597 This
->bDirty
= TRUE
;
1602 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1604 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1606 TRACE("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1608 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1609 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1610 This
->bDirty
= TRUE
;
1612 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1615 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1617 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1619 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1621 return IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, fFlags
);
1624 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1628 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1630 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1632 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1634 return E_OUTOFMEMORY
;
1636 r
= IShellLinkW_SetPath((IShellLinkW
*)&(This
->lpvtblw
), str
);
1637 HeapFree( GetProcessHeap(), 0, str
);
1642 /**************************************************************************
1643 * IShellLink Implementation
1646 static const IShellLinkAVtbl slvt
=
1648 IShellLinkA_fnQueryInterface
,
1649 IShellLinkA_fnAddRef
,
1650 IShellLinkA_fnRelease
,
1651 IShellLinkA_fnGetPath
,
1652 IShellLinkA_fnGetIDList
,
1653 IShellLinkA_fnSetIDList
,
1654 IShellLinkA_fnGetDescription
,
1655 IShellLinkA_fnSetDescription
,
1656 IShellLinkA_fnGetWorkingDirectory
,
1657 IShellLinkA_fnSetWorkingDirectory
,
1658 IShellLinkA_fnGetArguments
,
1659 IShellLinkA_fnSetArguments
,
1660 IShellLinkA_fnGetHotkey
,
1661 IShellLinkA_fnSetHotkey
,
1662 IShellLinkA_fnGetShowCmd
,
1663 IShellLinkA_fnSetShowCmd
,
1664 IShellLinkA_fnGetIconLocation
,
1665 IShellLinkA_fnSetIconLocation
,
1666 IShellLinkA_fnSetRelativePath
,
1667 IShellLinkA_fnResolve
,
1668 IShellLinkA_fnSetPath
1672 /**************************************************************************
1673 * IShellLinkW_fnQueryInterface
1675 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1676 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1678 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1679 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1682 /******************************************************************************
1683 * IShellLinkW_fnAddRef
1685 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1687 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1688 return ShellLink_AddRef( This
);
1691 /******************************************************************************
1692 * IShellLinkW_fnRelease
1694 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1696 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1697 return ShellLink_Release( This
);
1700 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1702 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1704 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1705 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1707 if (This
->sComponent
|| This
->sProduct
)
1713 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1715 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1720 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1722 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1724 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1728 *ppidl
= ILClone(This
->pPidl
);
1732 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1734 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1736 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1739 ILFree( This
->pPidl
);
1740 This
->pPidl
= ILClone( pidl
);
1744 This
->bDirty
= TRUE
;
1749 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1751 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1753 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1756 if( This
->sDescription
)
1757 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1762 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1764 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1766 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1768 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1769 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1770 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1771 if ( !This
->sDescription
)
1772 return E_OUTOFMEMORY
;
1774 lstrcpyW( This
->sDescription
, pszName
);
1775 This
->bDirty
= TRUE
;
1780 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1782 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1784 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1788 if( This
->sWorkDir
)
1789 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1794 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1796 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1798 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1800 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1801 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1802 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1803 if ( !This
->sWorkDir
)
1804 return E_OUTOFMEMORY
;
1805 lstrcpyW( This
->sWorkDir
, pszDir
);
1806 This
->bDirty
= TRUE
;
1811 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1813 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1815 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1820 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1825 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1827 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1829 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1831 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1832 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1833 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1835 return E_OUTOFMEMORY
;
1836 lstrcpyW( This
->sArgs
, pszArgs
);
1837 This
->bDirty
= TRUE
;
1842 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1844 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1846 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1848 *pwHotkey
=This
->wHotKey
;
1853 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1855 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1857 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1859 This
->wHotKey
= wHotkey
;
1860 This
->bDirty
= TRUE
;
1865 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1867 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1869 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1871 *piShowCmd
= This
->iShowCmd
;
1876 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1878 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1880 This
->iShowCmd
= iShowCmd
;
1881 This
->bDirty
= TRUE
;
1886 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1888 LPCITEMIDLIST pidlLast
;
1890 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1892 if (SUCCEEDED(hr
)) {
1895 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1897 if (SUCCEEDED(hr
)) {
1898 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1900 IExtractIconW_Release(pei
);
1903 IShellFolder_Release(psf
);
1909 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1911 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1913 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1916 *piIcon
= This
->iIcoNdx
;
1920 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1924 if (This
->pPidl
|| This
->sPath
)
1928 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1932 /* first look for an icon using the PIDL (if present) */
1934 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1938 /* if we couldn't find an icon yet, look for it using the file system path */
1939 if (FAILED(hr
) && This
->sPath
)
1943 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1947 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1953 IShellFolder_Release(pdsk
);
1960 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1962 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1964 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1966 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1967 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1968 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1969 if ( !This
->sIcoPath
)
1970 return E_OUTOFMEMORY
;
1971 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1973 This
->iIcoNdx
= iIcon
;
1974 This
->bDirty
= TRUE
;
1979 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1981 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1983 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1985 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1986 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1987 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1988 if ( !This
->sPathRel
)
1989 return E_OUTOFMEMORY
;
1990 lstrcpyW( This
->sPathRel
, pszPathRel
);
1991 This
->bDirty
= TRUE
;
1993 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1996 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
2001 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
2003 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
2005 /*FIXME: use IResolveShellLink interface */
2007 if (!This
->sPath
&& This
->pPidl
) {
2008 WCHAR buffer
[MAX_PATH
];
2010 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
2012 if (bSuccess
&& *buffer
) {
2013 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
2015 return E_OUTOFMEMORY
;
2017 lstrcpyW(This
->sPath
, buffer
);
2019 This
->bDirty
= TRUE
;
2021 hr
= S_OK
; /* don't report an error occurred while just caching information */
2024 if (!This
->sIcoPath
&& This
->sPath
) {
2025 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2026 if (!This
->sIcoPath
)
2027 return E_OUTOFMEMORY
;
2029 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2032 This
->bDirty
= TRUE
;
2038 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2047 p
= strchrW( str
, ':' );
2051 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2054 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2059 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2061 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2069 /* each segment must start with two colons */
2070 if( str
[0] != ':' || str
[1] != ':' )
2073 /* the last segment is just two colons */
2078 /* there must be a colon straight after a guid */
2079 p
= strchrW( str
, ':' );
2086 /* get the guid, and check it's validly formatted */
2087 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2089 r
= CLSIDFromString( szGuid
, &guid
);
2094 /* match it up to a guid that we care about */
2095 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2097 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2102 /* skip to the next field */
2103 str
= strchrW( str
, ':' );
2108 /* we have to have a component for an advertised shortcut */
2112 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2113 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2115 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2116 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2121 static BOOL
ShellLink_GetVolumeInfo(LPWSTR path
, volume_info
*volume
)
2123 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2124 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
2127 volume
->type
= GetDriveTypeW(drive
);
2128 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2129 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2130 TRACE("r = %d type %ld serial %08lx name %s\n", r
,
2131 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2135 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2137 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
2138 WCHAR buffer
[MAX_PATH
];
2142 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2144 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2147 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2148 This
->sComponent
= NULL
;
2151 ILFree(This
->pPidl
);
2154 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2156 if (*pszFile
== '\0')
2158 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2160 else if(!PathFileExistsW(buffer
))
2163 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2164 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2166 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2167 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2169 return E_OUTOFMEMORY
;
2171 lstrcpyW(This
->sPath
, buffer
);
2173 This
->bDirty
= TRUE
;
2178 /**************************************************************************
2179 * IShellLinkW Implementation
2182 static const IShellLinkWVtbl slvtw
=
2184 IShellLinkW_fnQueryInterface
,
2185 IShellLinkW_fnAddRef
,
2186 IShellLinkW_fnRelease
,
2187 IShellLinkW_fnGetPath
,
2188 IShellLinkW_fnGetIDList
,
2189 IShellLinkW_fnSetIDList
,
2190 IShellLinkW_fnGetDescription
,
2191 IShellLinkW_fnSetDescription
,
2192 IShellLinkW_fnGetWorkingDirectory
,
2193 IShellLinkW_fnSetWorkingDirectory
,
2194 IShellLinkW_fnGetArguments
,
2195 IShellLinkW_fnSetArguments
,
2196 IShellLinkW_fnGetHotkey
,
2197 IShellLinkW_fnSetHotkey
,
2198 IShellLinkW_fnGetShowCmd
,
2199 IShellLinkW_fnSetShowCmd
,
2200 IShellLinkW_fnGetIconLocation
,
2201 IShellLinkW_fnSetIconLocation
,
2202 IShellLinkW_fnSetRelativePath
,
2203 IShellLinkW_fnResolve
,
2204 IShellLinkW_fnSetPath
2207 static HRESULT WINAPI
2208 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2210 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl
, iface
);
2211 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2215 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2217 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl
, iface
);
2218 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2222 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2224 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl
, iface
);
2225 return ShellLink_Release( This
);
2228 static HRESULT WINAPI
2229 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2235 static HRESULT WINAPI
2236 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2242 static HRESULT WINAPI
2243 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2249 static HRESULT WINAPI
2250 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2256 static HRESULT WINAPI
2257 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2263 static const IShellLinkDataListVtbl dlvt
=
2265 ShellLink_DataList_QueryInterface
,
2266 ShellLink_DataList_AddRef
,
2267 ShellLink_DataList_Release
,
2268 ShellLink_AddDataBlock
,
2269 ShellLink_CopyDataBlock
,
2270 ShellLink_RemoveDataBlock
,
2275 static HRESULT WINAPI
2276 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2278 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl
, iface
);
2279 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2283 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2285 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl
, iface
);
2286 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2290 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2292 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl
, iface
);
2293 return ShellLink_Release( This
);
2296 /**************************************************************************
2297 * ShellLink implementation of IShellExtInit::Initialize()
2299 * Loads the shelllink from the dataobject the shell is pointing to.
2301 static HRESULT WINAPI
2302 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2303 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2305 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl
, iface
);
2311 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2316 format
.cfFormat
= CF_HDROP
;
2318 format
.dwAspect
= DVASPECT_CONTENT
;
2320 format
.tymed
= TYMED_HGLOBAL
;
2322 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2325 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2330 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2332 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2335 IPersistFile
*pf
= (IPersistFile
*) &This
->lpvtblPersistFile
;
2337 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2338 r
= IPersistFile_Load( pf
, path
, 0 );
2339 HeapFree( GetProcessHeap(), 0, path
);
2342 ReleaseStgMedium( &stgm
);
2347 static const IShellExtInitVtbl eivt
=
2349 ShellLink_ExtInit_QueryInterface
,
2350 ShellLink_ExtInit_AddRef
,
2351 ShellLink_ExtInit_Release
,
2352 ShellLink_ExtInit_Initialize
2355 static HRESULT WINAPI
2356 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2358 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2359 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2363 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2365 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2366 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2370 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2372 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2373 return ShellLink_Release( This
);
2376 static HRESULT WINAPI
2377 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2378 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2380 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2382 FIXME("%p %p %u %u %u %u\n", This
,
2383 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2388 static HRESULT WINAPI
2389 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2391 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2393 FIXME("%p %p\n", This
, lpici
);
2398 static HRESULT WINAPI
2399 ShellLink_GetCommandString( IContextMenu
* iface
, UINT idCmd
, UINT uType
,
2400 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2402 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2404 FIXME("%p %u %u %p %p %u\n", This
,
2405 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2410 static const IContextMenuVtbl cmvt
=
2412 ShellLink_ContextMenu_QueryInterface
,
2413 ShellLink_ContextMenu_AddRef
,
2414 ShellLink_ContextMenu_Release
,
2415 ShellLink_QueryContextMenu
,
2416 ShellLink_InvokeCommand
,
2417 ShellLink_GetCommandString