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
));
165 static inline IShellLinkImpl
*impl_from_IPersistFile( IPersistFile
*iface
)
167 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistFile
));
170 static inline IShellLinkImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
172 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistStream
));
175 static inline IShellLinkImpl
*impl_from_IShellLinkDataList( IShellLinkDataList
*iface
)
177 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellLinkDataList
));
180 static inline IShellLinkImpl
*impl_from_IShellExtInit( IShellExtInit
*iface
)
182 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellExtInit
));
185 static inline IShellLinkImpl
*impl_from_IContextMenu( IContextMenu
*iface
)
187 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblContextMenu
));
190 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
192 /* strdup on the process heap */
193 inline static LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
195 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
196 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
199 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
203 /**************************************************************************
204 * ShellLink::QueryInterface implementation
206 static HRESULT
ShellLink_QueryInterface( IShellLinkImpl
*This
, REFIID riid
, LPVOID
*ppvObj
)
208 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
212 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
216 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
218 *ppvObj
= &(This
->lpvtblw
);
220 else if(IsEqualIID(riid
, &IID_IPersistFile
))
222 *ppvObj
= &(This
->lpvtblPersistFile
);
224 else if(IsEqualIID(riid
, &IID_IPersistStream
))
226 *ppvObj
= &(This
->lpvtblPersistStream
);
228 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
230 *ppvObj
= &(This
->lpvtblShellLinkDataList
);
232 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
234 *ppvObj
= &(This
->lpvtblShellExtInit
);
236 else if(IsEqualIID(riid
, &IID_IContextMenu
))
238 *ppvObj
= &(This
->lpvtblContextMenu
);
243 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
244 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
247 ERR("-- Interface: E_NOINTERFACE\n");
248 return E_NOINTERFACE
;
251 /**************************************************************************
252 * ShellLink::AddRef implementation
254 static ULONG
ShellLink_AddRef( IShellLinkImpl
*This
)
256 ULONG refCount
= InterlockedIncrement(&This
->ref
);
258 TRACE("(%p)->(count=%lu)\n", This
, refCount
- 1);
263 /**************************************************************************
264 * ShellLink::Release implementation
266 static ULONG
ShellLink_Release( IShellLinkImpl
*This
)
268 ULONG refCount
= InterlockedDecrement(&This
->ref
);
270 TRACE("(%p)->(count=%lu)\n", This
, refCount
+ 1);
275 TRACE("-- destroying IShellLink(%p)\n",This
);
277 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
278 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
279 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
280 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
281 HeapFree(GetProcessHeap(),0,This
->sPath
);
286 LocalFree((HANDLE
)This
);
291 static HRESULT
ShellLink_GetClassID( IShellLinkImpl
*This
, CLSID
*pclsid
)
293 TRACE("%p %p\n", This
, pclsid
);
295 memcpy( pclsid
, &CLSID_ShellLink
, sizeof (CLSID
) );
299 /**************************************************************************
300 * IPersistFile_QueryInterface
302 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
307 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
308 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
311 /******************************************************************************
312 * IPersistFile_AddRef
314 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
316 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
317 return ShellLink_AddRef( This
);
320 /******************************************************************************
321 * IPersistFile_Release
323 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
325 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
326 return IShellLinkA_Release((IShellLinkA
*)This
);
329 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
331 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
332 return ShellLink_GetClassID( This
, pClassID
);
335 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
337 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
339 TRACE("(%p)\n",This
);
347 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
349 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
350 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
354 TRACE("(%p, %s, %lx)\n",This
, debugstr_w(pszFileName
), dwMode
);
357 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
358 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
361 r
= IPersistStream_Load(StreamThis
, stm
);
362 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
363 IStream_Release( stm
);
364 This
->bDirty
= FALSE
;
366 TRACE("-- returning hr %08lx\n", r
);
370 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
372 static const WCHAR szFormat
[] = {
373 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
374 ' ','-','r',' ','"','%','s','"',0 };
378 PROCESS_INFORMATION pi
;
380 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
381 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
385 wsprintfW( buffer
, szFormat
, szLink
);
387 TRACE("starting %s\n",debugstr_w(buffer
));
389 memset(&si
, 0, sizeof(si
));
391 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
393 /* wait for a while to throttle the creation of linker processes */
394 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
395 WARN("Timed out waiting for shell linker\n");
397 CloseHandle( pi
.hProcess
);
398 CloseHandle( pi
.hThread
);
403 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
405 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
406 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
410 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
415 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
418 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
419 IStream_Release( stm
);
423 StartLinkProcessor( pszFileName
);
425 This
->bDirty
= FALSE
;
429 DeleteFileW( pszFileName
);
430 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
437 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
439 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
440 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
444 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
446 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
447 FIXME("(%p)\n",This
);
451 static const IPersistFileVtbl pfvt
=
453 IPersistFile_fnQueryInterface
,
454 IPersistFile_fnAddRef
,
455 IPersistFile_fnRelease
,
456 IPersistFile_fnGetClassID
,
457 IPersistFile_fnIsDirty
,
460 IPersistFile_fnSaveCompleted
,
461 IPersistFile_fnGetCurFile
464 /************************************************************************
465 * IPersistStream_QueryInterface
467 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
468 IPersistStream
* iface
,
472 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
473 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
476 /************************************************************************
477 * IPersistStream_Release
479 static ULONG WINAPI
IPersistStream_fnRelease(
480 IPersistStream
* iface
)
482 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
483 return IShellLinkA_Release((IShellLinkA
*)This
);
486 /************************************************************************
487 * IPersistStream_AddRef
489 static ULONG WINAPI
IPersistStream_fnAddRef(
490 IPersistStream
* iface
)
492 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
493 return ShellLink_AddRef( This
);
496 /************************************************************************
497 * IPersistStream_GetClassID
500 static HRESULT WINAPI
IPersistStream_fnGetClassID(
501 IPersistStream
* iface
,
504 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
505 return ShellLink_GetClassID( This
, pClassID
);
508 /************************************************************************
509 * IPersistStream_IsDirty (IPersistStream)
511 static HRESULT WINAPI
IPersistStream_fnIsDirty(
512 IPersistStream
* iface
)
514 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
516 TRACE("(%p)\n", This
);
522 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
533 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
534 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
538 len
*= sizeof (WCHAR
);
540 TRACE("reading %d\n", len
);
541 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
543 return E_OUTOFMEMORY
;
545 r
= IStream_Read(stm
, temp
, len
, &count
);
546 if( FAILED (r
) || ( count
!= len
) )
548 HeapFree( GetProcessHeap(), 0, temp
);
552 TRACE("read %s\n", debugstr_an(temp
,len
));
554 /* convert to unicode if necessary */
557 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
558 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
560 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
561 HeapFree( GetProcessHeap(), 0, temp
);
575 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
582 unsigned char data
[1];
587 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
588 if( FAILED( r
) || count
!= sizeof(size
) )
591 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
593 return E_OUTOFMEMORY
;
596 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
597 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
599 HeapFree( GetProcessHeap(), 0, chunk
);
603 TRACE("Read %ld bytes\n",chunk
->size
);
605 *data
= (LPVOID
) chunk
;
610 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
612 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
616 volume
->serial
= vol
->dwVolSerial
;
617 volume
->type
= vol
->dwType
;
619 if( !vol
->dwVolLabelOfs
)
621 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
623 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
626 label
+= vol
->dwVolLabelOfs
;
627 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
632 static LPWSTR
Stream_LoadPath( LPSTR p
, DWORD maxlen
)
637 while( p
[len
] && (len
< maxlen
) )
640 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
641 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
642 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
648 static HRESULT
Stream_LoadLocation( IStream
*stm
,
649 volume_info
*volume
, LPWSTR
*path
)
656 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
660 loc
= (LOCATION_INFO
*) p
;
661 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
663 HeapFree( GetProcessHeap(), 0, p
);
667 /* if there's valid local volume information, load it */
668 if( loc
->dwVolTableOfs
&&
669 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
671 LOCAL_VOLUME_INFO
*volume_info
;
673 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
674 Stream_LoadVolume( volume_info
, volume
);
677 /* if there's a local path, load it */
678 n
= loc
->dwLocalPathOfs
;
679 if( n
&& (n
< loc
->dwTotalSize
) )
680 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
682 TRACE("type %ld serial %08lx name %s path %s\n", volume
->type
,
683 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
685 HeapFree( GetProcessHeap(), 0, p
);
690 * The format of the advertised shortcut info seems to be:
695 * 0 Length of the block (4 bytes, usually 0x314)
697 * 8 string data in ASCII
698 * 8+0x104 string data in UNICODE
700 * In the original Win32 implementation the buffers are not initialized
701 * to zero, so data trailing the string is random garbage.
703 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
708 EXP_DARWIN_LINK buffer
;
712 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
716 /* make sure that we read the size of the structure even on error */
717 size
= sizeof buffer
- sizeof (DWORD
);
718 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
720 ERR("Ooops. This structure is not as expected...\n");
724 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
731 TRACE("magic %08lx string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
733 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
735 ERR("Unknown magic number %08lx in advertised shortcut\n", buffer
.dbh
.dwSignature
);
739 *str
= HeapAlloc( GetProcessHeap(), 0,
740 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
741 lstrcpyW( *str
, buffer
.szwDarwinID
);
746 /************************************************************************
747 * IPersistStream_Load (IPersistStream)
749 static HRESULT WINAPI
IPersistStream_fnLoad(
750 IPersistStream
* iface
,
759 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
761 TRACE("%p %p\n", This
, stm
);
764 return STG_E_INVALIDPOINTER
;
767 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
771 if( dwBytesRead
!= sizeof(hdr
))
773 if( hdr
.dwSize
!= sizeof(hdr
))
775 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
778 /* free all the old stuff */
781 memset( &This
->volume
, 0, sizeof This
->volume
);
782 HeapFree(GetProcessHeap(), 0, This
->sPath
);
784 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
785 This
->sDescription
= NULL
;
786 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
787 This
->sPathRel
= NULL
;
788 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
789 This
->sWorkDir
= NULL
;
790 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
792 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
793 This
->sIcoPath
= NULL
;
794 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
795 This
->sProduct
= NULL
;
796 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
797 This
->sComponent
= NULL
;
799 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
800 This
->iIcoNdx
= hdr
.nIcon
;
801 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
802 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
803 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
806 WCHAR sTemp
[MAX_PATH
];
807 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
808 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
809 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
810 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
811 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
812 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
813 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
814 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
815 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
818 /* load all the new stuff */
819 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
821 r
= ILLoadFromStream( stm
, &This
->pPidl
);
827 /* load the location information */
828 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
829 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
833 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
834 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
836 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
837 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
842 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
844 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
845 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
850 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
852 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
853 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
858 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
860 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
861 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
866 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
868 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
869 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
874 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
876 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
877 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
882 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
884 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
885 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
890 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
891 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
892 ERR("Last word was not zero\n");
903 /************************************************************************
906 * Helper function for IPersistStream_Save. Writes a unicode string
907 * with terminating nul byte to a stream, preceded by the its length.
909 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
911 USHORT len
= lstrlenW( str
) + 1;
915 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
919 len
*= sizeof(WCHAR
);
921 r
= IStream_Write( stm
, str
, len
, &count
);
928 /************************************************************************
929 * Stream_WriteLocationInfo
931 * Writes the location info to a stream
933 * FIXME: One day we might want to write the network volume information
934 * and the final path.
935 * Figure out how Windows deals with unicode paths here.
937 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
938 volume_info
*volume
)
940 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
941 LOCAL_VOLUME_INFO
*vol
;
943 LPSTR szLabel
, szPath
, szFinalPath
;
946 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
948 /* figure out the size of everything */
949 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
950 NULL
, 0, NULL
, NULL
);
951 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
952 NULL
, 0, NULL
, NULL
);
953 volume_info_size
= sizeof *vol
+ label_size
;
955 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
957 /* create pointers to everything */
958 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
959 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
960 szLabel
= (LPSTR
) &vol
[1];
961 szPath
= &szLabel
[label_size
];
962 szFinalPath
= &szPath
[path_size
];
964 /* fill in the location information header */
965 loc
->dwTotalSize
= total_size
;
966 loc
->dwHeaderSize
= sizeof (*loc
);
968 loc
->dwVolTableOfs
= sizeof (*loc
);
969 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
970 loc
->dwNetworkVolTableOfs
= 0;
971 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
973 /* fill in the volume information */
974 vol
->dwSize
= volume_info_size
;
975 vol
->dwType
= volume
->type
;
976 vol
->dwVolSerial
= volume
->serial
;
977 vol
->dwVolLabelOfs
= sizeof (*vol
);
979 /* copy in the strings */
980 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
981 szLabel
, label_size
, NULL
, NULL
);
982 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
983 szPath
, path_size
, NULL
, NULL
);
986 return IStream_Write( stm
, loc
, total_size
, &count
);
989 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
992 EXP_DARWIN_LINK buffer
;
996 memset( &buffer
, 0, sizeof buffer
);
997 buffer
.dbh
.cbSize
= sizeof buffer
;
998 buffer
.dbh
.dwSignature
= magic
;
999 lstrcpynW( buffer
.szwDarwinID
, string
, MAX_PATH
);
1000 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
.szDarwinID
, MAX_PATH
, NULL
, NULL
);
1002 return IStream_Write( stm
, &buffer
, buffer
.dbh
.cbSize
, &count
);
1005 /************************************************************************
1006 * IPersistStream_Save (IPersistStream)
1008 * FIXME: makes assumptions about byte order
1010 static HRESULT WINAPI
IPersistStream_fnSave(
1011 IPersistStream
* iface
,
1015 static const WCHAR wOpen
[] = {'o','p','e','n',0};
1018 WCHAR exePath
[MAX_PATH
];
1023 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1025 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1031 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, MAX_PATH
,
1032 NULL
, NULL
, NULL
, NULL
);
1034 * windows can create lnk files to executables that do not exist yet
1035 * so if the executable does not exist the just trust the path they
1038 if (!*exePath
) lstrcpyW(exePath
,This
->sPath
);
1041 memset(&header
, 0, sizeof(header
));
1042 header
.dwSize
= sizeof(header
);
1043 header
.fStartup
= This
->iShowCmd
;
1044 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
1046 header
.wHotKey
= This
->wHotKey
;
1047 header
.nIcon
= This
->iIcoNdx
;
1048 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1050 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1052 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1053 if( This
->sDescription
)
1054 header
.dwFlags
|= SLDF_HAS_NAME
;
1055 if( This
->sWorkDir
)
1056 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1058 header
.dwFlags
|= SLDF_HAS_ARGS
;
1059 if( This
->sIcoPath
)
1060 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1061 if( This
->sProduct
)
1062 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1063 if( This
->sComponent
)
1064 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1066 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1067 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1068 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1070 /* write the Shortcut header */
1071 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1074 ERR("Write failed at %d\n",__LINE__
);
1078 TRACE("Writing pidl \n");
1080 /* write the PIDL to the shortcut */
1083 r
= ILSaveToStream( stm
, This
->pPidl
);
1086 ERR("Failed to write PIDL at %d\n",__LINE__
);
1092 Stream_WriteLocationInfo( stm
, exePath
, &This
->volume
);
1094 if( This
->sDescription
)
1095 r
= Stream_WriteString( stm
, This
->sDescription
);
1097 if( This
->sPathRel
)
1098 r
= Stream_WriteString( stm
, This
->sPathRel
);
1100 if( This
->sWorkDir
)
1101 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1104 r
= Stream_WriteString( stm
, This
->sArgs
);
1106 if( This
->sIcoPath
)
1107 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1109 if( This
->sProduct
)
1110 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1112 if( This
->sComponent
)
1113 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1115 /* the last field is a single zero dword */
1117 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1122 /************************************************************************
1123 * IPersistStream_GetSizeMax (IPersistStream)
1125 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1126 IPersistStream
* iface
,
1127 ULARGE_INTEGER
* pcbSize
)
1129 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1131 TRACE("(%p)\n", This
);
1136 static const IPersistStreamVtbl psvt
=
1138 IPersistStream_fnQueryInterface
,
1139 IPersistStream_fnAddRef
,
1140 IPersistStream_fnRelease
,
1141 IPersistStream_fnGetClassID
,
1142 IPersistStream_fnIsDirty
,
1143 IPersistStream_fnLoad
,
1144 IPersistStream_fnSave
,
1145 IPersistStream_fnGetSizeMax
1148 /**************************************************************************
1149 * IShellLink_Constructor
1151 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1152 REFIID riid
, LPVOID
*ppv
)
1154 IShellLinkImpl
* sl
;
1156 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1161 return CLASS_E_NOAGGREGATION
;
1162 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1164 return E_OUTOFMEMORY
;
1168 sl
->lpvtblw
= &slvtw
;
1169 sl
->lpvtblPersistFile
= &pfvt
;
1170 sl
->lpvtblPersistStream
= &psvt
;
1171 sl
->lpvtblShellLinkDataList
= &dlvt
;
1172 sl
->lpvtblShellExtInit
= &eivt
;
1173 sl
->lpvtblContextMenu
= &cmvt
;
1174 sl
->iShowCmd
= SW_SHOWNORMAL
;
1177 TRACE("(%p)->()\n",sl
);
1179 if (IsEqualIID(riid
, &IID_IUnknown
) ||
1180 IsEqualIID(riid
, &IID_IShellLinkA
))
1182 else if (IsEqualIID(riid
, &IID_IShellLinkW
))
1183 *ppv
= &(sl
->lpvtblw
);
1185 LocalFree((HLOCAL
)sl
);
1186 ERR("E_NOINTERFACE\n");
1187 return E_NOINTERFACE
;
1194 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1196 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1201 /**************************************************************************
1202 * ShellLink_UpdatePath
1203 * update absolute path in sPath using relative path in sPathRel
1205 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1207 if (!path
|| !psPath
)
1208 return E_INVALIDARG
;
1210 if (!*psPath
&& sPathRel
) {
1211 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1212 LPWSTR final
= NULL
;
1214 /* first try if [directory of link file] + [relative path] finds an existing file */
1216 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1219 lstrcpyW(final
, sPathRel
);
1223 if (SHELL_ExistsFileW(buffer
)) {
1224 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1225 lstrcpyW(abs_path
, buffer
);
1227 /* try if [working directory] + [relative path] finds an existing file */
1229 lstrcpyW(buffer
, sWorkDir
);
1230 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1232 if (SHELL_ExistsFileW(buffer
))
1233 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1234 lstrcpyW(abs_path
, buffer
);
1238 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1240 lstrcpyW(abs_path
, sPathRel
);
1242 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1244 return E_OUTOFMEMORY
;
1246 lstrcpyW(*psPath
, abs_path
);
1252 /**************************************************************************
1253 * IShellLink_ConstructFromFile
1255 HRESULT WINAPI
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1256 LPCITEMIDLIST pidl
, LPVOID
* ppv
)
1260 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1262 if (SUCCEEDED(hr
)) {
1267 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1269 if (SUCCEEDED(hr
)) {
1270 WCHAR path
[MAX_PATH
];
1272 if (SHGetPathFromIDListW(pidl
, path
))
1273 hr
= IPersistFile_Load(ppf
, path
, 0);
1278 *ppv
= (IUnknown
*) psl
;
1280 IPersistFile_Release(ppf
);
1284 IShellLinkW_Release(psl
);
1290 /**************************************************************************
1291 * IShellLinkA_QueryInterface
1293 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1295 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1296 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1299 /******************************************************************************
1300 * IShellLinkA_AddRef
1302 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
1304 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1305 return ShellLink_AddRef( This
);
1308 /******************************************************************************
1309 * IShellLinkA_Release
1311 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1313 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1314 return ShellLink_Release( This
);
1317 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1318 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1320 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1322 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1323 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1325 if (This
->sComponent
|| This
->sProduct
)
1331 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1332 pszFile
, cchMaxPath
, NULL
, NULL
);
1334 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1339 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1341 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1343 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1345 return IShellLinkW_GetIDList((IShellLinkW
*)&(This
->lpvtblw
), ppidl
);
1348 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1350 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1352 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1355 ILFree(This
->pPidl
);
1356 This
->pPidl
= ILClone (pidl
);
1357 This
->bDirty
= TRUE
;
1362 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1364 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1366 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1370 if( This
->sDescription
)
1371 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1372 pszName
, cchMaxName
, NULL
, NULL
);
1377 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1379 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1381 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1383 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1384 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1385 if ( !This
->sDescription
)
1386 return E_OUTOFMEMORY
;
1388 This
->bDirty
= TRUE
;
1393 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1395 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1397 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1401 if( This
->sWorkDir
)
1402 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1403 pszDir
, cchMaxPath
, NULL
, NULL
);
1408 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1410 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1412 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1414 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1415 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1416 if ( !This
->sWorkDir
)
1417 return E_OUTOFMEMORY
;
1419 This
->bDirty
= TRUE
;
1424 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1426 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1428 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1433 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1434 pszArgs
, cchMaxPath
, NULL
, NULL
);
1439 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1441 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1443 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1445 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1446 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1448 return E_OUTOFMEMORY
;
1450 This
->bDirty
= TRUE
;
1455 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1457 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1459 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1461 *pwHotkey
= This
->wHotKey
;
1466 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1468 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1470 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1472 This
->wHotKey
= wHotkey
;
1473 This
->bDirty
= TRUE
;
1478 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1480 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1482 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1483 *piShowCmd
= This
->iShowCmd
;
1487 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1489 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1491 TRACE("(%p) %d\n",This
, iShowCmd
);
1493 This
->iShowCmd
= iShowCmd
;
1494 This
->bDirty
= TRUE
;
1499 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1501 LPCITEMIDLIST pidlLast
;
1503 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1505 if (SUCCEEDED(hr
)) {
1508 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1510 if (SUCCEEDED(hr
)) {
1511 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1513 IExtractIconA_Release(pei
);
1516 IShellFolder_Release(psf
);
1522 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1524 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1526 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1529 *piIcon
= This
->iIcoNdx
;
1533 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1537 if (This
->pPidl
|| This
->sPath
)
1541 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1545 /* first look for an icon using the PIDL (if present) */
1547 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1551 /* if we couldn't find an icon yet, look for it using the file system path */
1552 if (FAILED(hr
) && This
->sPath
)
1556 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1558 if (SUCCEEDED(hr
)) {
1559 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1565 IShellFolder_Release(pdsk
);
1573 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1575 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1577 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1579 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1580 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1581 if ( !This
->sIcoPath
)
1582 return E_OUTOFMEMORY
;
1584 This
->iIcoNdx
= iIcon
;
1585 This
->bDirty
= TRUE
;
1590 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1592 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1594 TRACE("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1596 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1597 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1598 This
->bDirty
= TRUE
;
1600 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1603 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1605 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1607 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1609 return IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, fFlags
);
1612 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1616 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1618 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1620 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1622 return E_OUTOFMEMORY
;
1624 r
= IShellLinkW_SetPath((IShellLinkW
*)&(This
->lpvtblw
), str
);
1625 HeapFree( GetProcessHeap(), 0, str
);
1630 /**************************************************************************
1631 * IShellLink Implementation
1634 static const IShellLinkAVtbl slvt
=
1636 IShellLinkA_fnQueryInterface
,
1637 IShellLinkA_fnAddRef
,
1638 IShellLinkA_fnRelease
,
1639 IShellLinkA_fnGetPath
,
1640 IShellLinkA_fnGetIDList
,
1641 IShellLinkA_fnSetIDList
,
1642 IShellLinkA_fnGetDescription
,
1643 IShellLinkA_fnSetDescription
,
1644 IShellLinkA_fnGetWorkingDirectory
,
1645 IShellLinkA_fnSetWorkingDirectory
,
1646 IShellLinkA_fnGetArguments
,
1647 IShellLinkA_fnSetArguments
,
1648 IShellLinkA_fnGetHotkey
,
1649 IShellLinkA_fnSetHotkey
,
1650 IShellLinkA_fnGetShowCmd
,
1651 IShellLinkA_fnSetShowCmd
,
1652 IShellLinkA_fnGetIconLocation
,
1653 IShellLinkA_fnSetIconLocation
,
1654 IShellLinkA_fnSetRelativePath
,
1655 IShellLinkA_fnResolve
,
1656 IShellLinkA_fnSetPath
1660 /**************************************************************************
1661 * IShellLinkW_fnQueryInterface
1663 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1664 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1666 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1667 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1670 /******************************************************************************
1671 * IShellLinkW_fnAddRef
1673 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1675 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1676 return ShellLink_AddRef( This
);
1679 /******************************************************************************
1680 * IShellLinkW_fnRelease
1682 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1684 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1685 return ShellLink_Release( This
);
1688 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1690 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1692 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1693 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1695 if (This
->sComponent
|| This
->sProduct
)
1701 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1703 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1708 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1710 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1712 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1716 *ppidl
= ILClone(This
->pPidl
);
1720 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1722 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1724 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1727 ILFree( This
->pPidl
);
1728 This
->pPidl
= ILClone( pidl
);
1732 This
->bDirty
= TRUE
;
1737 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1739 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1741 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1744 if( This
->sDescription
)
1745 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1750 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1752 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1754 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1756 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1757 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1758 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1759 if ( !This
->sDescription
)
1760 return E_OUTOFMEMORY
;
1762 lstrcpyW( This
->sDescription
, pszName
);
1763 This
->bDirty
= TRUE
;
1768 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1770 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1772 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1776 if( This
->sWorkDir
)
1777 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1782 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1784 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1786 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1788 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1789 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1790 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1791 if ( !This
->sWorkDir
)
1792 return E_OUTOFMEMORY
;
1793 lstrcpyW( This
->sWorkDir
, pszDir
);
1794 This
->bDirty
= TRUE
;
1799 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1801 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1803 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1808 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1813 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1815 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1817 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1819 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1820 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1821 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1823 return E_OUTOFMEMORY
;
1824 lstrcpyW( This
->sArgs
, pszArgs
);
1825 This
->bDirty
= TRUE
;
1830 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1832 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1834 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1836 *pwHotkey
=This
->wHotKey
;
1841 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1843 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1845 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1847 This
->wHotKey
= wHotkey
;
1848 This
->bDirty
= TRUE
;
1853 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1855 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1857 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1859 *piShowCmd
= This
->iShowCmd
;
1864 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1866 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1868 This
->iShowCmd
= iShowCmd
;
1869 This
->bDirty
= TRUE
;
1874 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1876 LPCITEMIDLIST pidlLast
;
1878 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1880 if (SUCCEEDED(hr
)) {
1883 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1885 if (SUCCEEDED(hr
)) {
1886 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1888 IExtractIconW_Release(pei
);
1891 IShellFolder_Release(psf
);
1897 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1899 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1901 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1904 *piIcon
= This
->iIcoNdx
;
1908 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1912 if (This
->pPidl
|| This
->sPath
)
1916 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1920 /* first look for an icon using the PIDL (if present) */
1922 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1926 /* if we couldn't find an icon yet, look for it using the file system path */
1927 if (FAILED(hr
) && This
->sPath
)
1931 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1935 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1941 IShellFolder_Release(pdsk
);
1948 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1950 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1952 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1954 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1955 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1956 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1957 if ( !This
->sIcoPath
)
1958 return E_OUTOFMEMORY
;
1959 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1961 This
->iIcoNdx
= iIcon
;
1962 This
->bDirty
= TRUE
;
1967 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1969 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1971 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1973 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1974 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1975 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1976 if ( !This
->sPathRel
)
1977 return E_OUTOFMEMORY
;
1978 lstrcpyW( This
->sPathRel
, pszPathRel
);
1979 This
->bDirty
= TRUE
;
1981 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1984 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1989 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1991 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1993 /*FIXME: use IResolveShellLink interface */
1995 if (!This
->sPath
&& This
->pPidl
) {
1996 WCHAR buffer
[MAX_PATH
];
1998 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
2000 if (bSuccess
&& *buffer
) {
2001 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
2003 return E_OUTOFMEMORY
;
2005 lstrcpyW(This
->sPath
, buffer
);
2007 This
->bDirty
= TRUE
;
2009 hr
= S_OK
; /* don't report an error occurred while just caching information */
2012 if (!This
->sIcoPath
&& This
->sPath
) {
2013 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2014 if (!This
->sIcoPath
)
2015 return E_OUTOFMEMORY
;
2017 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2020 This
->bDirty
= TRUE
;
2026 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2035 p
= strchrW( str
, ':' );
2039 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2042 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2047 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2049 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2057 /* each segment must start with two colons */
2058 if( str
[0] != ':' || str
[1] != ':' )
2061 /* the last segment is just two colons */
2066 /* there must be a colon straight after a guid */
2067 p
= strchrW( str
, ':' );
2074 /* get the guid, and check it's validly formatted */
2075 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2077 r
= CLSIDFromString( szGuid
, &guid
);
2082 /* match it up to a guid that we care about */
2083 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2085 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2090 /* skip to the next field */
2091 str
= strchrW( str
, ':' );
2096 /* we have to have a component for an advertised shortcut */
2100 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2101 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2103 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2104 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2109 static BOOL
ShellLink_GetVolumeInfo(LPWSTR path
, volume_info
*volume
)
2111 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2112 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
2115 volume
->type
= GetDriveTypeW(drive
);
2116 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2117 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2118 TRACE("r = %d type %ld serial %08lx name %s\n", r
,
2119 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2123 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2125 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2126 WCHAR buffer
[MAX_PATH
];
2130 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2132 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2135 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2136 This
->sComponent
= NULL
;
2139 ILFree(This
->pPidl
);
2142 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2144 if (*pszFile
== '\0')
2146 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2148 else if(!PathFileExistsW(buffer
))
2151 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2152 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2154 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2155 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2157 return E_OUTOFMEMORY
;
2159 lstrcpyW(This
->sPath
, buffer
);
2161 This
->bDirty
= TRUE
;
2166 /**************************************************************************
2167 * IShellLinkW Implementation
2170 static const IShellLinkWVtbl slvtw
=
2172 IShellLinkW_fnQueryInterface
,
2173 IShellLinkW_fnAddRef
,
2174 IShellLinkW_fnRelease
,
2175 IShellLinkW_fnGetPath
,
2176 IShellLinkW_fnGetIDList
,
2177 IShellLinkW_fnSetIDList
,
2178 IShellLinkW_fnGetDescription
,
2179 IShellLinkW_fnSetDescription
,
2180 IShellLinkW_fnGetWorkingDirectory
,
2181 IShellLinkW_fnSetWorkingDirectory
,
2182 IShellLinkW_fnGetArguments
,
2183 IShellLinkW_fnSetArguments
,
2184 IShellLinkW_fnGetHotkey
,
2185 IShellLinkW_fnSetHotkey
,
2186 IShellLinkW_fnGetShowCmd
,
2187 IShellLinkW_fnSetShowCmd
,
2188 IShellLinkW_fnGetIconLocation
,
2189 IShellLinkW_fnSetIconLocation
,
2190 IShellLinkW_fnSetRelativePath
,
2191 IShellLinkW_fnResolve
,
2192 IShellLinkW_fnSetPath
2195 static HRESULT WINAPI
2196 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2198 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2199 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2203 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2205 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2206 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2210 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2212 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2213 return ShellLink_Release( This
);
2216 static HRESULT WINAPI
2217 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2223 static HRESULT WINAPI
2224 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2230 static HRESULT WINAPI
2231 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2237 static HRESULT WINAPI
2238 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2244 static HRESULT WINAPI
2245 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2251 static const IShellLinkDataListVtbl dlvt
=
2253 ShellLink_DataList_QueryInterface
,
2254 ShellLink_DataList_AddRef
,
2255 ShellLink_DataList_Release
,
2256 ShellLink_AddDataBlock
,
2257 ShellLink_CopyDataBlock
,
2258 ShellLink_RemoveDataBlock
,
2263 static HRESULT WINAPI
2264 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2266 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2267 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2271 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2273 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2274 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2278 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2280 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2281 return ShellLink_Release( This
);
2284 /**************************************************************************
2285 * ShellLink implementation of IShellExtInit::Initialize()
2287 * Loads the shelllink from the dataobject the shell is pointing to.
2289 static HRESULT WINAPI
2290 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2291 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2293 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2299 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2304 format
.cfFormat
= CF_HDROP
;
2306 format
.dwAspect
= DVASPECT_CONTENT
;
2308 format
.tymed
= TYMED_HGLOBAL
;
2310 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2313 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2318 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2320 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2323 IPersistFile
*pf
= (IPersistFile
*) &This
->lpvtblPersistFile
;
2325 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2326 r
= IPersistFile_Load( pf
, path
, 0 );
2327 HeapFree( GetProcessHeap(), 0, path
);
2330 ReleaseStgMedium( &stgm
);
2335 static const IShellExtInitVtbl eivt
=
2337 ShellLink_ExtInit_QueryInterface
,
2338 ShellLink_ExtInit_AddRef
,
2339 ShellLink_ExtInit_Release
,
2340 ShellLink_ExtInit_Initialize
2343 static HRESULT WINAPI
2344 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2346 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2347 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2351 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2353 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2354 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2358 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2360 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2361 return ShellLink_Release( This
);
2364 static HRESULT WINAPI
2365 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2366 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2368 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2370 FIXME("%p %p %u %u %u %u\n", This
,
2371 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2376 static HRESULT WINAPI
2377 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2379 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2381 FIXME("%p %p\n", This
, lpici
);
2386 static HRESULT WINAPI
2387 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2388 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2390 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2392 FIXME("%p %u %u %p %p %u\n", This
,
2393 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2398 static const IContextMenuVtbl cmvt
=
2400 ShellLink_ContextMenu_QueryInterface
,
2401 ShellLink_ContextMenu_AddRef
,
2402 ShellLink_ContextMenu_Release
,
2403 ShellLink_QueryContextMenu
,
2404 ShellLink_InvokeCommand
,
2405 ShellLink_GetCommandString