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 * IPersistFile_QueryInterface
218 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
223 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
224 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
227 /******************************************************************************
228 * IPersistFile_AddRef
230 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
232 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
233 return IShellLinkA_AddRef((IShellLinkA
*)This
);
236 /******************************************************************************
237 * IPersistFile_Release
239 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
241 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
242 return IShellLinkA_Release((IShellLinkA
*)This
);
245 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
247 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
248 FIXME("(%p)\n",This
);
252 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
254 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
256 TRACE("(%p)\n",This
);
264 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
266 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
267 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
271 TRACE("(%p, %s, %lx)\n",This
, debugstr_w(pszFileName
), dwMode
);
274 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
275 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
278 r
= IPersistStream_Load(StreamThis
, stm
);
279 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
280 IStream_Release( stm
);
281 This
->bDirty
= FALSE
;
283 TRACE("-- returning hr %08lx\n", r
);
287 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
289 static const WCHAR szFormat
[] = {
290 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
291 ' ','-','r',' ','"','%','s','"',0 };
295 PROCESS_INFORMATION pi
;
297 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
298 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
302 wsprintfW( buffer
, szFormat
, szLink
);
304 TRACE("starting %s\n",debugstr_w(buffer
));
306 memset(&si
, 0, sizeof(si
));
308 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
310 /* wait for a while to throttle the creation of linker processes */
311 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
312 WARN("Timed out waiting for shell linker\n");
314 CloseHandle( pi
.hProcess
);
315 CloseHandle( pi
.hThread
);
320 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
322 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
323 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
327 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
332 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
335 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
336 IStream_Release( stm
);
340 StartLinkProcessor( pszFileName
);
342 This
->bDirty
= FALSE
;
346 DeleteFileW( pszFileName
);
347 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
354 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
356 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
357 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
361 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
363 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
364 FIXME("(%p)\n",This
);
368 static const IPersistFileVtbl pfvt
=
370 IPersistFile_fnQueryInterface
,
371 IPersistFile_fnAddRef
,
372 IPersistFile_fnRelease
,
373 IPersistFile_fnGetClassID
,
374 IPersistFile_fnIsDirty
,
377 IPersistFile_fnSaveCompleted
,
378 IPersistFile_fnGetCurFile
381 /************************************************************************
382 * IPersistStream_QueryInterface
384 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
385 IPersistStream
* iface
,
389 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
390 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvoid
);
393 /************************************************************************
394 * IPersistStream_Release
396 static ULONG WINAPI
IPersistStream_fnRelease(
397 IPersistStream
* iface
)
399 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
400 return IShellLinkA_Release((IShellLinkA
*)This
);
403 /************************************************************************
404 * IPersistStream_AddRef
406 static ULONG WINAPI
IPersistStream_fnAddRef(
407 IPersistStream
* iface
)
409 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
410 return IShellLinkA_AddRef((IShellLinkA
*)This
);
413 /************************************************************************
414 * IPersistStream_GetClassID
417 static HRESULT WINAPI
IPersistStream_fnGetClassID(
418 IPersistStream
* iface
,
421 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
423 TRACE("(%p)\n", This
);
428 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
433 /************************************************************************
434 * IPersistStream_IsDirty (IPersistStream)
436 static HRESULT WINAPI
IPersistStream_fnIsDirty(
437 IPersistStream
* iface
)
439 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
441 TRACE("(%p)\n", This
);
447 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
458 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
459 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
463 len
*= sizeof (WCHAR
);
465 TRACE("reading %d\n", len
);
466 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
468 return E_OUTOFMEMORY
;
470 r
= IStream_Read(stm
, temp
, len
, &count
);
471 if( FAILED (r
) || ( count
!= len
) )
473 HeapFree( GetProcessHeap(), 0, temp
);
477 TRACE("read %s\n", debugstr_an(temp
,len
));
479 /* convert to unicode if necessary */
482 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
483 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
485 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
486 HeapFree( GetProcessHeap(), 0, temp
);
500 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
507 unsigned char data
[1];
512 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
513 if( FAILED( r
) || count
!= sizeof(size
) )
516 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
518 return E_OUTOFMEMORY
;
521 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
522 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
524 HeapFree( GetProcessHeap(), 0, chunk
);
528 TRACE("Read %ld bytes\n",chunk
->size
);
530 *data
= (LPVOID
) chunk
;
535 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
537 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
541 volume
->serial
= vol
->dwVolSerial
;
542 volume
->type
= vol
->dwType
;
544 if( !vol
->dwVolLabelOfs
)
546 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
548 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
551 label
+= vol
->dwVolLabelOfs
;
552 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
557 static LPWSTR
Stream_LoadPath( LPSTR p
, DWORD maxlen
)
562 while( p
[len
] && (len
< maxlen
) )
565 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
566 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
567 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
573 static HRESULT
Stream_LoadLocation( IStream
*stm
,
574 volume_info
*volume
, LPWSTR
*path
)
576 unsigned char *p
= NULL
;
581 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
585 loc
= (LOCATION_INFO
*) p
;
586 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
588 HeapFree( GetProcessHeap(), 0, p
);
592 /* if there's valid local volume information, load it */
593 if( loc
->dwVolTableOfs
&&
594 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
596 LOCAL_VOLUME_INFO
*volume_info
;
598 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
599 Stream_LoadVolume( volume_info
, volume
);
602 /* if there's a local path, load it */
603 n
= loc
->dwLocalPathOfs
;
604 if( n
&& (n
< loc
->dwTotalSize
) )
605 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
607 TRACE("type %ld serial %08lx name %s path %s\n", volume
->type
,
608 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
610 HeapFree( GetProcessHeap(), 0, p
);
615 * The format of the advertised shortcut info seems to be:
620 * 0 Length of the block (4 bytes, usually 0x314)
622 * 8 string data in ASCII
623 * 8+0x104 string data in UNICODE
625 * In the original Win32 implementation the buffers are not initialized
626 * to zero, so data trailing the string is random garbage.
628 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
633 EXP_DARWIN_LINK buffer
;
637 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
641 /* make sure that we read the size of the structure even on error */
642 size
= sizeof buffer
- sizeof (DWORD
);
643 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
645 ERR("Ooops. This structure is not as expected...\n");
649 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
656 TRACE("magic %08lx string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
658 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
660 ERR("Unknown magic number %08lx in advertised shortcut\n", buffer
.dbh
.dwSignature
);
664 *str
= HeapAlloc( GetProcessHeap(), 0,
665 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
666 lstrcpyW( *str
, buffer
.szwDarwinID
);
671 /************************************************************************
672 * IPersistStream_Load (IPersistStream)
674 static HRESULT WINAPI
IPersistStream_fnLoad(
675 IPersistStream
* iface
,
684 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
686 TRACE("%p %p\n", This
, stm
);
689 return STG_E_INVALIDPOINTER
;
692 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
696 if( dwBytesRead
!= sizeof(hdr
))
698 if( hdr
.dwSize
!= sizeof(hdr
))
700 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
703 /* free all the old stuff */
706 memset( &This
->volume
, 0, sizeof This
->volume
);
707 HeapFree(GetProcessHeap(), 0, This
->sPath
);
709 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
710 This
->sDescription
= NULL
;
711 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
712 This
->sPathRel
= NULL
;
713 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
714 This
->sWorkDir
= NULL
;
715 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
717 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
718 This
->sIcoPath
= NULL
;
719 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
720 This
->sProduct
= NULL
;
721 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
722 This
->sComponent
= NULL
;
724 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
725 This
->iIcoNdx
= hdr
.nIcon
;
726 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
727 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
728 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
731 WCHAR sTemp
[MAX_PATH
];
732 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
733 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
734 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
735 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
736 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
737 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
738 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
739 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
740 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
743 /* load all the new stuff */
744 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
746 r
= ILLoadFromStream( stm
, &This
->pPidl
);
752 /* load the location information */
753 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
754 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
758 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
759 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
761 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
762 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
767 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
769 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
770 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
775 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
777 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
778 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
783 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
785 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
786 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
791 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
793 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
794 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
799 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
801 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
802 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
807 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
809 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
810 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
815 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
816 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
817 ERR("Last word was not zero\n");
828 /************************************************************************
831 * Helper function for IPersistStream_Save. Writes a unicode string
832 * with terminating nul byte to a stream, preceded by the its length.
834 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
836 USHORT len
= lstrlenW( str
) + 1;
840 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
844 len
*= sizeof(WCHAR
);
846 r
= IStream_Write( stm
, str
, len
, &count
);
853 /************************************************************************
854 * Stream_WriteLocationInfo
856 * Writes the location info to a stream
858 * FIXME: One day we might want to write the network volume information
859 * and the final path.
860 * Figure out how Windows deals with unicode paths here.
862 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
863 volume_info
*volume
)
865 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
866 LOCAL_VOLUME_INFO
*vol
;
868 LPSTR szLabel
, szPath
, szFinalPath
;
871 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
873 /* figure out the size of everything */
874 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
875 NULL
, 0, NULL
, NULL
);
876 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
877 NULL
, 0, NULL
, NULL
);
878 volume_info_size
= sizeof *vol
+ label_size
;
880 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
882 /* create pointers to everything */
883 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
884 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
885 szLabel
= (LPSTR
) &vol
[1];
886 szPath
= &szLabel
[label_size
];
887 szFinalPath
= &szPath
[path_size
];
889 /* fill in the location information header */
890 loc
->dwTotalSize
= total_size
;
891 loc
->dwHeaderSize
= sizeof (*loc
);
893 loc
->dwVolTableOfs
= sizeof (*loc
);
894 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
895 loc
->dwNetworkVolTableOfs
= 0;
896 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
898 /* fill in the volume information */
899 vol
->dwSize
= volume_info_size
;
900 vol
->dwType
= volume
->type
;
901 vol
->dwVolSerial
= volume
->serial
;
902 vol
->dwVolLabelOfs
= sizeof (*vol
);
904 /* copy in the strings */
905 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
906 szLabel
, label_size
, NULL
, NULL
);
907 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
908 szPath
, path_size
, NULL
, NULL
);
911 return IStream_Write( stm
, loc
, total_size
, &count
);
914 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
917 EXP_DARWIN_LINK buffer
;
921 memset( &buffer
, 0, sizeof buffer
);
922 buffer
.dbh
.cbSize
= sizeof buffer
;
923 buffer
.dbh
.dwSignature
= magic
;
924 lstrcpynW( buffer
.szwDarwinID
, string
, MAX_PATH
);
925 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
.szDarwinID
, MAX_PATH
, NULL
, NULL
);
927 return IStream_Write( stm
, &buffer
, buffer
.dbh
.cbSize
, &count
);
930 /************************************************************************
931 * IPersistStream_Save (IPersistStream)
933 * FIXME: makes assumptions about byte order
935 static HRESULT WINAPI
IPersistStream_fnSave(
936 IPersistStream
* iface
,
940 static const WCHAR wOpen
[] = {'o','p','e','n',0};
943 WCHAR exePath
[MAX_PATH
];
948 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
950 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
956 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, MAX_PATH
,
957 NULL
, NULL
, NULL
, NULL
);
959 * windows can create lnk files to executables that do not exist yet
960 * so if the executable does not exist the just trust the path they
963 if (!*exePath
) lstrcpyW(exePath
,This
->sPath
);
966 memset(&header
, 0, sizeof(header
));
967 header
.dwSize
= sizeof(header
);
968 header
.fStartup
= This
->iShowCmd
;
969 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
971 header
.wHotKey
= This
->wHotKey
;
972 header
.nIcon
= This
->iIcoNdx
;
973 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
975 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
977 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
978 if( This
->sDescription
)
979 header
.dwFlags
|= SLDF_HAS_NAME
;
981 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
983 header
.dwFlags
|= SLDF_HAS_ARGS
;
985 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
987 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
988 if( This
->sComponent
)
989 header
.dwFlags
|= SLDF_HAS_DARWINID
;
991 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
992 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
993 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
995 /* write the Shortcut header */
996 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
999 ERR("Write failed at %d\n",__LINE__
);
1003 TRACE("Writing pidl \n");
1005 /* write the PIDL to the shortcut */
1008 r
= ILSaveToStream( stm
, This
->pPidl
);
1011 ERR("Failed to write PIDL at %d\n",__LINE__
);
1017 Stream_WriteLocationInfo( stm
, exePath
, &This
->volume
);
1019 if( This
->sDescription
)
1020 r
= Stream_WriteString( stm
, This
->sDescription
);
1022 if( This
->sPathRel
)
1023 r
= Stream_WriteString( stm
, This
->sPathRel
);
1025 if( This
->sWorkDir
)
1026 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1029 r
= Stream_WriteString( stm
, This
->sArgs
);
1031 if( This
->sIcoPath
)
1032 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1034 if( This
->sProduct
)
1035 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1037 if( This
->sComponent
)
1038 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1040 /* the last field is a single zero dword */
1042 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1047 /************************************************************************
1048 * IPersistStream_GetSizeMax (IPersistStream)
1050 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1051 IPersistStream
* iface
,
1052 ULARGE_INTEGER
* pcbSize
)
1054 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
1056 TRACE("(%p)\n", This
);
1061 static const IPersistStreamVtbl psvt
=
1063 IPersistStream_fnQueryInterface
,
1064 IPersistStream_fnAddRef
,
1065 IPersistStream_fnRelease
,
1066 IPersistStream_fnGetClassID
,
1067 IPersistStream_fnIsDirty
,
1068 IPersistStream_fnLoad
,
1069 IPersistStream_fnSave
,
1070 IPersistStream_fnGetSizeMax
1073 /**************************************************************************
1074 * IShellLink_Constructor
1076 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1077 REFIID riid
, LPVOID
*ppv
)
1079 IShellLinkImpl
* sl
;
1081 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1086 return CLASS_E_NOAGGREGATION
;
1087 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1089 return E_OUTOFMEMORY
;
1093 sl
->lpvtblw
= &slvtw
;
1094 sl
->lpvtblPersistFile
= &pfvt
;
1095 sl
->lpvtblPersistStream
= &psvt
;
1096 sl
->lpvtblShellLinkDataList
= &dlvt
;
1097 sl
->lpvtblShellExtInit
= &eivt
;
1098 sl
->lpvtblContextMenu
= &cmvt
;
1099 sl
->iShowCmd
= SW_SHOWNORMAL
;
1102 TRACE("(%p)->()\n",sl
);
1104 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1105 IsEqualIID(riid
, &IID_IShellLinkA
))
1107 else if (IsEqualIID(riid
, &IID_IShellLinkW
))
1108 *ppv
= &(sl
->lpvtblw
);
1110 LocalFree((HLOCAL
)sl
);
1111 ERR("E_NOINTERFACE\n");
1112 return E_NOINTERFACE
;
1119 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1121 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1126 /**************************************************************************
1127 * ShellLink_UpdatePath
1128 * update absolute path in sPath using relative path in sPathRel
1130 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1132 if (!path
|| !psPath
)
1133 return E_INVALIDARG
;
1135 if (!*psPath
&& sPathRel
) {
1136 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1137 LPWSTR final
= NULL
;
1139 /* first try if [directory of link file] + [relative path] finds an existing file */
1141 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1144 lstrcpyW(final
, sPathRel
);
1148 if (SHELL_ExistsFileW(buffer
)) {
1149 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1150 lstrcpyW(abs_path
, buffer
);
1152 /* try if [working directory] + [relative path] finds an existing file */
1154 lstrcpyW(buffer
, sWorkDir
);
1155 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1157 if (SHELL_ExistsFileW(buffer
))
1158 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1159 lstrcpyW(abs_path
, buffer
);
1163 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1165 lstrcpyW(abs_path
, sPathRel
);
1167 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1169 return E_OUTOFMEMORY
;
1171 lstrcpyW(*psPath
, abs_path
);
1177 /**************************************************************************
1178 * IShellLink_ConstructFromFile
1180 HRESULT WINAPI
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1181 LPCITEMIDLIST pidl
, LPVOID
* ppv
)
1185 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1187 if (SUCCEEDED(hr
)) {
1192 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1194 if (SUCCEEDED(hr
)) {
1195 WCHAR path
[MAX_PATH
];
1197 if (SHGetPathFromIDListW(pidl
, path
))
1198 hr
= IPersistFile_Load(ppf
, path
, 0);
1203 *ppv
= (IUnknown
*) psl
;
1205 IPersistFile_Release(ppf
);
1209 IShellLinkW_Release(psl
);
1215 /**************************************************************************
1216 * IShellLinkA_QueryInterface
1218 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1220 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1222 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
1226 if(IsEqualIID(riid
, &IID_IUnknown
) ||
1227 IsEqualIID(riid
, &IID_IShellLinkA
))
1231 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1233 *ppvObj
= &(This
->lpvtblw
);
1235 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1237 *ppvObj
= &(This
->lpvtblPersistFile
);
1239 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1241 *ppvObj
= &(This
->lpvtblPersistStream
);
1243 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1245 *ppvObj
= &(This
->lpvtblShellLinkDataList
);
1247 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1249 *ppvObj
= &(This
->lpvtblShellExtInit
);
1251 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1253 *ppvObj
= &(This
->lpvtblContextMenu
);
1258 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
1259 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
1262 ERR("-- Interface: E_NOINTERFACE\n");
1263 return E_NOINTERFACE
;
1266 /******************************************************************************
1267 * IShellLinkA_AddRef
1269 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
1271 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1272 ULONG refCount
= InterlockedIncrement(&This
->ref
);
1274 TRACE("(%p)->(count=%lu)\n", This
, refCount
- 1);
1279 /******************************************************************************
1280 * IShellLinkA_Release
1282 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1284 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1285 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1287 TRACE("(%p)->(count=%lu)\n", This
, refCount
+ 1);
1292 TRACE("-- destroying IShellLink(%p)\n",This
);
1294 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1295 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1296 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1297 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1298 HeapFree(GetProcessHeap(),0,This
->sPath
);
1301 ILFree(This
->pPidl
);
1303 LocalFree((HANDLE
)This
);
1308 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1309 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1311 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1313 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1314 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1316 if (This
->sComponent
|| This
->sProduct
)
1322 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1323 pszFile
, cchMaxPath
, NULL
, NULL
);
1325 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1330 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1332 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1334 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1336 return IShellLinkW_GetIDList((IShellLinkW
*)&(This
->lpvtblw
), ppidl
);
1339 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1341 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1343 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1346 ILFree(This
->pPidl
);
1347 This
->pPidl
= ILClone (pidl
);
1348 This
->bDirty
= TRUE
;
1353 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1355 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1357 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1361 if( This
->sDescription
)
1362 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1363 pszName
, cchMaxName
, NULL
, NULL
);
1368 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1370 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1372 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1374 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1375 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1376 if ( !This
->sDescription
)
1377 return E_OUTOFMEMORY
;
1379 This
->bDirty
= TRUE
;
1384 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1386 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1388 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1392 if( This
->sWorkDir
)
1393 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1394 pszDir
, cchMaxPath
, NULL
, NULL
);
1399 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1401 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1403 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1405 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1406 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1407 if ( !This
->sWorkDir
)
1408 return E_OUTOFMEMORY
;
1410 This
->bDirty
= TRUE
;
1415 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1417 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1419 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1424 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1425 pszArgs
, cchMaxPath
, NULL
, NULL
);
1430 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1432 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1434 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1436 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1437 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1439 return E_OUTOFMEMORY
;
1441 This
->bDirty
= TRUE
;
1446 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1448 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1450 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1452 *pwHotkey
= This
->wHotKey
;
1457 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1459 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1461 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1463 This
->wHotKey
= wHotkey
;
1464 This
->bDirty
= TRUE
;
1469 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1471 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1473 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1474 *piShowCmd
= This
->iShowCmd
;
1478 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1480 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1482 TRACE("(%p) %d\n",This
, iShowCmd
);
1484 This
->iShowCmd
= iShowCmd
;
1485 This
->bDirty
= TRUE
;
1490 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1492 LPCITEMIDLIST pidlLast
;
1494 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1496 if (SUCCEEDED(hr
)) {
1499 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1501 if (SUCCEEDED(hr
)) {
1502 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1504 IExtractIconA_Release(pei
);
1507 IShellFolder_Release(psf
);
1513 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1515 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1517 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1520 *piIcon
= This
->iIcoNdx
;
1524 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1528 if (This
->pPidl
|| This
->sPath
)
1532 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1536 /* first look for an icon using the PIDL (if present) */
1538 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1542 /* if we couldn't find an icon yet, look for it using the file system path */
1543 if (FAILED(hr
) && This
->sPath
)
1547 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1549 if (SUCCEEDED(hr
)) {
1550 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1556 IShellFolder_Release(pdsk
);
1564 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1566 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1568 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1570 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1571 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1572 if ( !This
->sIcoPath
)
1573 return E_OUTOFMEMORY
;
1575 This
->iIcoNdx
= iIcon
;
1576 This
->bDirty
= TRUE
;
1581 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1583 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1585 TRACE("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1587 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1588 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1589 This
->bDirty
= TRUE
;
1591 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1594 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1596 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1598 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1600 return IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, fFlags
);
1603 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1607 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1609 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1611 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1613 return E_OUTOFMEMORY
;
1615 r
= IShellLinkW_SetPath((IShellLinkW
*)&(This
->lpvtblw
), str
);
1616 HeapFree( GetProcessHeap(), 0, str
);
1621 /**************************************************************************
1622 * IShellLink Implementation
1625 static const IShellLinkAVtbl slvt
=
1627 IShellLinkA_fnQueryInterface
,
1628 IShellLinkA_fnAddRef
,
1629 IShellLinkA_fnRelease
,
1630 IShellLinkA_fnGetPath
,
1631 IShellLinkA_fnGetIDList
,
1632 IShellLinkA_fnSetIDList
,
1633 IShellLinkA_fnGetDescription
,
1634 IShellLinkA_fnSetDescription
,
1635 IShellLinkA_fnGetWorkingDirectory
,
1636 IShellLinkA_fnSetWorkingDirectory
,
1637 IShellLinkA_fnGetArguments
,
1638 IShellLinkA_fnSetArguments
,
1639 IShellLinkA_fnGetHotkey
,
1640 IShellLinkA_fnSetHotkey
,
1641 IShellLinkA_fnGetShowCmd
,
1642 IShellLinkA_fnSetShowCmd
,
1643 IShellLinkA_fnGetIconLocation
,
1644 IShellLinkA_fnSetIconLocation
,
1645 IShellLinkA_fnSetRelativePath
,
1646 IShellLinkA_fnResolve
,
1647 IShellLinkA_fnSetPath
1651 /**************************************************************************
1652 * IShellLinkW_fnQueryInterface
1654 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1655 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1657 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1658 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
1661 /******************************************************************************
1662 * IShellLinkW_fnAddRef
1664 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1666 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1667 return IShellLinkA_AddRef((IShellLinkA
*)This
);
1669 /******************************************************************************
1670 * IShellLinkW_fnRelease
1673 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1675 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1676 return IShellLinkA_Release((IShellLinkA
*)This
);
1679 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1681 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1683 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1684 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1686 if (This
->sComponent
|| This
->sProduct
)
1692 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1694 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1699 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1701 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1703 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1707 *ppidl
= ILClone(This
->pPidl
);
1711 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1713 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1715 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1718 ILFree( This
->pPidl
);
1719 This
->pPidl
= ILClone( pidl
);
1723 This
->bDirty
= TRUE
;
1728 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1730 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1732 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1735 if( This
->sDescription
)
1736 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1741 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1743 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1745 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1747 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1748 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1749 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1750 if ( !This
->sDescription
)
1751 return E_OUTOFMEMORY
;
1753 lstrcpyW( This
->sDescription
, pszName
);
1754 This
->bDirty
= TRUE
;
1759 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1761 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1763 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1767 if( This
->sWorkDir
)
1768 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1773 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1775 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1777 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1779 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1780 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1781 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1782 if ( !This
->sWorkDir
)
1783 return E_OUTOFMEMORY
;
1784 lstrcpyW( This
->sWorkDir
, pszDir
);
1785 This
->bDirty
= TRUE
;
1790 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1792 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1794 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1799 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1804 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1806 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1808 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1810 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1811 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1812 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1814 return E_OUTOFMEMORY
;
1815 lstrcpyW( This
->sArgs
, pszArgs
);
1816 This
->bDirty
= TRUE
;
1821 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1823 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1825 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1827 *pwHotkey
=This
->wHotKey
;
1832 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1834 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1836 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1838 This
->wHotKey
= wHotkey
;
1839 This
->bDirty
= TRUE
;
1844 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1846 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1848 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1850 *piShowCmd
= This
->iShowCmd
;
1855 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1857 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1859 This
->iShowCmd
= iShowCmd
;
1860 This
->bDirty
= TRUE
;
1865 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1867 LPCITEMIDLIST pidlLast
;
1869 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1871 if (SUCCEEDED(hr
)) {
1874 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1876 if (SUCCEEDED(hr
)) {
1877 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1879 IExtractIconW_Release(pei
);
1882 IShellFolder_Release(psf
);
1888 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1890 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1892 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1895 *piIcon
= This
->iIcoNdx
;
1899 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1903 if (This
->pPidl
|| This
->sPath
)
1907 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1911 /* first look for an icon using the PIDL (if present) */
1913 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1917 /* if we couldn't find an icon yet, look for it using the file system path */
1918 if (FAILED(hr
) && This
->sPath
)
1922 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1926 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1932 IShellFolder_Release(pdsk
);
1939 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1941 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1943 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1945 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1946 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1947 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1948 if ( !This
->sIcoPath
)
1949 return E_OUTOFMEMORY
;
1950 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1952 This
->iIcoNdx
= iIcon
;
1953 This
->bDirty
= TRUE
;
1958 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1960 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1962 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1964 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1965 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1966 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1967 if ( !This
->sPathRel
)
1968 return E_OUTOFMEMORY
;
1969 lstrcpyW( This
->sPathRel
, pszPathRel
);
1970 This
->bDirty
= TRUE
;
1972 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1975 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1980 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1982 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1984 /*FIXME: use IResolveShellLink interface */
1986 if (!This
->sPath
&& This
->pPidl
) {
1987 WCHAR buffer
[MAX_PATH
];
1989 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1991 if (bSuccess
&& *buffer
) {
1992 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1994 return E_OUTOFMEMORY
;
1996 lstrcpyW(This
->sPath
, buffer
);
1998 This
->bDirty
= TRUE
;
2000 hr
= S_OK
; /* don't report an error occurred while just caching information */
2003 if (!This
->sIcoPath
&& This
->sPath
) {
2004 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2005 if (!This
->sIcoPath
)
2006 return E_OUTOFMEMORY
;
2008 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2011 This
->bDirty
= TRUE
;
2017 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2026 p
= strchrW( str
, ':' );
2030 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2033 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2038 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2040 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2048 /* each segment must start with two colons */
2049 if( str
[0] != ':' || str
[1] != ':' )
2052 /* the last segment is just two colons */
2057 /* there must be a colon straight after a guid */
2058 p
= strchrW( str
, ':' );
2065 /* get the guid, and check it's validly formatted */
2066 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2068 r
= CLSIDFromString( szGuid
, &guid
);
2073 /* match it up to a guid that we care about */
2074 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2076 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2081 /* skip to the next field */
2082 str
= strchrW( str
, ':' );
2087 /* we have to have a component for an advertised shortcut */
2091 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2092 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2094 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2095 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2100 static BOOL
ShellLink_GetVolumeInfo(LPWSTR path
, volume_info
*volume
)
2102 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2103 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
2106 volume
->type
= GetDriveTypeW(drive
);
2107 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2108 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2109 TRACE("r = %d type %ld serial %08lx name %s\n", r
,
2110 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2114 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2116 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
2117 WCHAR buffer
[MAX_PATH
];
2121 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2123 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2126 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2127 This
->sComponent
= NULL
;
2130 ILFree(This
->pPidl
);
2133 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2135 if (*pszFile
== '\0')
2137 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2139 else if(!PathFileExistsW(buffer
))
2142 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2143 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2145 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2146 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2148 return E_OUTOFMEMORY
;
2150 lstrcpyW(This
->sPath
, buffer
);
2152 This
->bDirty
= TRUE
;
2157 /**************************************************************************
2158 * IShellLinkW Implementation
2161 static const IShellLinkWVtbl slvtw
=
2163 IShellLinkW_fnQueryInterface
,
2164 IShellLinkW_fnAddRef
,
2165 IShellLinkW_fnRelease
,
2166 IShellLinkW_fnGetPath
,
2167 IShellLinkW_fnGetIDList
,
2168 IShellLinkW_fnSetIDList
,
2169 IShellLinkW_fnGetDescription
,
2170 IShellLinkW_fnSetDescription
,
2171 IShellLinkW_fnGetWorkingDirectory
,
2172 IShellLinkW_fnSetWorkingDirectory
,
2173 IShellLinkW_fnGetArguments
,
2174 IShellLinkW_fnSetArguments
,
2175 IShellLinkW_fnGetHotkey
,
2176 IShellLinkW_fnSetHotkey
,
2177 IShellLinkW_fnGetShowCmd
,
2178 IShellLinkW_fnSetShowCmd
,
2179 IShellLinkW_fnGetIconLocation
,
2180 IShellLinkW_fnSetIconLocation
,
2181 IShellLinkW_fnSetRelativePath
,
2182 IShellLinkW_fnResolve
,
2183 IShellLinkW_fnSetPath
2186 static HRESULT WINAPI
2187 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2189 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl
, iface
);
2190 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2194 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2196 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl
, iface
);
2197 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2201 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2203 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl
, iface
);
2204 return IShellLinkA_Release((IShellLinkA
*)This
);
2207 static HRESULT WINAPI
2208 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2214 static HRESULT WINAPI
2215 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2221 static HRESULT WINAPI
2222 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2228 static HRESULT WINAPI
2229 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2235 static HRESULT WINAPI
2236 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2242 static const IShellLinkDataListVtbl dlvt
=
2244 ShellLink_DataList_QueryInterface
,
2245 ShellLink_DataList_AddRef
,
2246 ShellLink_DataList_Release
,
2247 ShellLink_AddDataBlock
,
2248 ShellLink_CopyDataBlock
,
2249 ShellLink_RemoveDataBlock
,
2254 static HRESULT WINAPI
2255 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2257 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl
, iface
);
2258 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2262 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2264 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl
, iface
);
2265 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2269 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2271 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl
, iface
);
2272 return IShellLinkA_Release((IShellLinkA
*)This
);
2275 /**************************************************************************
2276 * ShellLink implementation of IShellExtInit::Initialize()
2278 * Loads the shelllink from the dataobject the shell is pointing to.
2280 static HRESULT WINAPI
2281 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2282 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2284 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl
, iface
);
2290 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2295 format
.cfFormat
= CF_HDROP
;
2297 format
.dwAspect
= DVASPECT_CONTENT
;
2299 format
.tymed
= TYMED_HGLOBAL
;
2301 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2304 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2309 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2311 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2314 IPersistFile
*pf
= (IPersistFile
*) &This
->lpvtblPersistFile
;
2316 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2317 r
= IPersistFile_Load( pf
, path
, 0 );
2318 HeapFree( GetProcessHeap(), 0, path
);
2321 ReleaseStgMedium( &stgm
);
2326 static const IShellExtInitVtbl eivt
=
2328 ShellLink_ExtInit_QueryInterface
,
2329 ShellLink_ExtInit_AddRef
,
2330 ShellLink_ExtInit_Release
,
2331 ShellLink_ExtInit_Initialize
2334 static HRESULT WINAPI
2335 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2337 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2338 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2342 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2344 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2345 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2349 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2351 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2352 return IShellLinkA_Release((IShellLinkA
*)This
);
2355 static HRESULT WINAPI
2356 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2357 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2359 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2361 FIXME("%p %p %u %u %u %u\n", This
,
2362 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2367 static HRESULT WINAPI
2368 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2370 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2372 FIXME("%p %p\n", This
, lpici
);
2377 static HRESULT WINAPI
2378 ShellLink_GetCommandString( IContextMenu
* iface
, UINT idCmd
, UINT uType
,
2379 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2381 _ICOM_THIS_From_IContextMenu(IShellLinkImpl
, iface
);
2383 FIXME("%p %u %u %p %p %u\n", This
,
2384 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2389 static const IContextMenuVtbl cmvt
=
2391 ShellLink_ContextMenu_QueryInterface
,
2392 ShellLink_ContextMenu_AddRef
,
2393 ShellLink_ContextMenu_Release
,
2394 ShellLink_QueryContextMenu
,
2395 ShellLink_InvokeCommand
,
2396 ShellLink_GetCommandString