3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Nearly complete information about the binary formats
23 * of .lnk files available at http://www.wotsit.org
25 * You can use winedump to examine the contents of a link file:
28 * MSI advertised shortcuts are totally undocumented. They provide an
29 * icon for a program that is not yet installed, and invoke MSI to
30 * install the program when the shortcut is clicked on. They are
31 * created by passing a special string to SetPath, and the information
32 * in that string is parsed an stored.
36 #define NONAMELESSUNION
38 #include "wine/debug.h"
48 #include "undocshell.h"
51 #include "shell32_main.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
61 DEFINE_GUID( SHELL32_AdvtShortcutProduct
,
62 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
63 DEFINE_GUID( SHELL32_AdvtShortcutComponent
,
64 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
66 /* link file formats */
70 typedef struct _LINK_HEADER
72 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
73 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
74 DWORD dwFlags
; /* 0x14 describes elements following */
75 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
76 FILETIME Time1
; /* 0x1c */
77 FILETIME Time2
; /* 0x24 */
78 FILETIME Time3
; /* 0x2c */
79 DWORD dwFileLength
; /* 0x34 File length */
80 DWORD nIcon
; /* 0x38 icon number */
81 DWORD fStartup
; /* 0x3c startup type */
82 DWORD wHotKey
; /* 0x40 hotkey */
83 DWORD Unknown5
; /* 0x44 */
84 DWORD Unknown6
; /* 0x48 */
85 } LINK_HEADER
, * PLINK_HEADER
;
87 #define SHLINK_LOCAL 0
88 #define SHLINK_REMOTE 1
90 typedef struct _LOCATION_INFO
97 DWORD dwNetworkVolTableOfs
;
101 typedef struct _LOCAL_VOLUME_INFO
109 typedef struct volume_info_t
113 WCHAR label
[12]; /* assume 8.3 */
118 static const IShellLinkAVtbl slvt
;
119 static const IShellLinkWVtbl slvtw
;
120 static const IPersistFileVtbl pfvt
;
121 static const IPersistStreamVtbl psvt
;
122 static const IShellLinkDataListVtbl dlvt
;
123 static const IShellExtInitVtbl eivt
;
124 static const IContextMenuVtbl cmvt
;
125 static const IObjectWithSiteVtbl owsvt
;
127 /* IShellLink Implementation */
131 const IShellLinkAVtbl
*lpVtbl
;
132 const IShellLinkWVtbl
*lpvtblw
;
133 const IPersistFileVtbl
*lpvtblPersistFile
;
134 const IPersistStreamVtbl
*lpvtblPersistStream
;
135 const IShellLinkDataListVtbl
*lpvtblShellLinkDataList
;
136 const IShellExtInitVtbl
*lpvtblShellExtInit
;
137 const IContextMenuVtbl
*lpvtblContextMenu
;
138 const IObjectWithSiteVtbl
*lpvtblObjectWithSite
;
142 /* data structures according to the information in the link */
162 INT iIdOpen
; /* id of the "Open" entry in the context menu */
166 static inline IShellLinkImpl
*impl_from_IShellLinkW( IShellLinkW
*iface
)
168 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblw
));
171 static inline IShellLinkImpl
*impl_from_IPersistFile( IPersistFile
*iface
)
173 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistFile
));
176 static inline IShellLinkImpl
*impl_from_IPersistStream( IPersistStream
*iface
)
178 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblPersistStream
));
181 static inline IShellLinkImpl
*impl_from_IShellLinkDataList( IShellLinkDataList
*iface
)
183 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellLinkDataList
));
186 static inline IShellLinkImpl
*impl_from_IShellExtInit( IShellExtInit
*iface
)
188 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblShellExtInit
));
191 static inline IShellLinkImpl
*impl_from_IContextMenu( IContextMenu
*iface
)
193 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblContextMenu
));
196 static inline IShellLinkImpl
*impl_from_IObjectWithSite( IObjectWithSite
*iface
)
198 return (IShellLinkImpl
*)((char*)iface
- FIELD_OFFSET(IShellLinkImpl
, lpvtblObjectWithSite
));
201 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
203 /* strdup on the process heap */
204 static inline LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
206 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
207 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
210 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
214 static inline LPWSTR
strdupW( LPCWSTR src
)
217 if (!src
) return NULL
;
218 dest
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(src
)+1)*sizeof(WCHAR
) );
224 /**************************************************************************
225 * ShellLink::QueryInterface implementation
227 static HRESULT
ShellLink_QueryInterface( IShellLinkImpl
*This
, REFIID riid
, LPVOID
*ppvObj
)
229 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
233 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
237 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
239 *ppvObj
= &(This
->lpvtblw
);
241 else if(IsEqualIID(riid
, &IID_IPersistFile
))
243 *ppvObj
= &(This
->lpvtblPersistFile
);
245 else if(IsEqualIID(riid
, &IID_IPersistStream
))
247 *ppvObj
= &(This
->lpvtblPersistStream
);
249 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
251 *ppvObj
= &(This
->lpvtblShellLinkDataList
);
253 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
255 *ppvObj
= &(This
->lpvtblShellExtInit
);
257 else if(IsEqualIID(riid
, &IID_IContextMenu
))
259 *ppvObj
= &(This
->lpvtblContextMenu
);
261 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
263 *ppvObj
= &(This
->lpvtblObjectWithSite
);
268 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
269 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
272 ERR("-- Interface: E_NOINTERFACE\n");
273 return E_NOINTERFACE
;
276 /**************************************************************************
277 * ShellLink::AddRef implementation
279 static ULONG
ShellLink_AddRef( IShellLinkImpl
*This
)
281 ULONG refCount
= InterlockedIncrement(&This
->ref
);
283 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
288 /**************************************************************************
289 * ShellLink::Release implementation
291 static ULONG
ShellLink_Release( IShellLinkImpl
*This
)
293 ULONG refCount
= InterlockedDecrement(&This
->ref
);
295 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
300 TRACE("-- destroying IShellLink(%p)\n",This
);
302 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
303 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
304 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
305 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
306 HeapFree(GetProcessHeap(),0,This
->sPath
);
309 IUnknown_Release( This
->site
);
314 LocalFree((HANDLE
)This
);
319 static HRESULT
ShellLink_GetClassID( IShellLinkImpl
*This
, CLSID
*pclsid
)
321 TRACE("%p %p\n", This
, pclsid
);
323 memcpy( pclsid
, &CLSID_ShellLink
, sizeof (CLSID
) );
327 /**************************************************************************
328 * IPersistFile_QueryInterface
330 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
335 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
336 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
339 /******************************************************************************
340 * IPersistFile_AddRef
342 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
344 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
345 return ShellLink_AddRef( This
);
348 /******************************************************************************
349 * IPersistFile_Release
351 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
353 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
354 return IShellLinkA_Release((IShellLinkA
*)This
);
357 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
359 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
360 return ShellLink_GetClassID( This
, pClassID
);
363 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
365 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
367 TRACE("(%p)\n",This
);
375 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
377 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
378 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
382 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
384 r
= CreateStreamOnFile(pszFileName
, dwMode
, &stm
);
387 r
= IPersistStream_Load(StreamThis
, stm
);
388 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
389 IStream_Release( stm
);
390 This
->bDirty
= FALSE
;
392 TRACE("-- returning hr %08x\n", r
);
396 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
398 static const WCHAR szFormat
[] = {
399 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
400 ' ','-','r',' ','"','%','s','"',0 };
404 PROCESS_INFORMATION pi
;
406 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
407 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
411 wsprintfW( buffer
, szFormat
, szLink
);
413 TRACE("starting %s\n",debugstr_w(buffer
));
415 memset(&si
, 0, sizeof(si
));
417 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
419 /* wait for a while to throttle the creation of linker processes */
420 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
421 WARN("Timed out waiting for shell linker\n");
423 CloseHandle( pi
.hProcess
);
424 CloseHandle( pi
.hThread
);
429 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
431 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
432 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
435 static const WCHAR wszIEStartMenuHardCoded
[] = {'C',':','\\','W','i','n','d','o','w','s','\\','S','t','a','r','t',' ','M','e','n','u','\\','P','r','o','g','r','a','m','s','\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','.','l','n','k',0};
436 static const WCHAR wszIEDesktopHardCoded
[] = {'C',':','\\','W','i','n','d','o','w','s','\\','D','e','s','k','t','o','p','\\','I','n','t','e','r','n','e','t',' ','E','x','p','l','o','r','e','r','.','l','n','k',0};
437 WCHAR buffer
[MAX_PATH
];
439 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
444 /* CrossOver HACK! The IE 6 installer hardcodes these paths (which work on
445 * Win9x), but don't in Windows 2000+ and Wine. So fix them up to use the
446 * proper functions to get the directory to save the link into */
447 if (!strcmpW(pszFileName
, wszIEStartMenuHardCoded
))
449 r
= SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, SHGFP_TYPE_CURRENT
, buffer
);
450 strcatW(buffer
, strchrW(strchrW(strchrW(wszIEStartMenuHardCoded
, '\\') + 1, '\\') + 1, '\\'));
451 TRACE("changing %s to %s\n", debugstr_w(pszFileName
), debugstr_w(buffer
));
452 pszFileName
= buffer
;
454 else if (!strcmpW(pszFileName
, wszIEDesktopHardCoded
))
456 r
= SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, SHGFP_TYPE_CURRENT
, buffer
);
457 strcatW(buffer
, strchrW(strchrW(strchrW(wszIEDesktopHardCoded
, '\\') + 1, '\\') + 1, '\\'));
458 TRACE("changing %s to %s\n", debugstr_w(pszFileName
), debugstr_w(buffer
));
459 pszFileName
= buffer
;
462 r
= CreateStreamOnFile(pszFileName
, STGM_READWRITE
| STGM_CREATE
, &stm
);
465 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
466 IStream_Release( stm
);
470 StartLinkProcessor( pszFileName
);
472 This
->bDirty
= FALSE
;
476 DeleteFileW( pszFileName
);
477 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
484 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
486 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
487 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
491 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
493 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
494 FIXME("(%p)\n",This
);
498 static const IPersistFileVtbl pfvt
=
500 IPersistFile_fnQueryInterface
,
501 IPersistFile_fnAddRef
,
502 IPersistFile_fnRelease
,
503 IPersistFile_fnGetClassID
,
504 IPersistFile_fnIsDirty
,
507 IPersistFile_fnSaveCompleted
,
508 IPersistFile_fnGetCurFile
511 /************************************************************************
512 * IPersistStream_QueryInterface
514 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
515 IPersistStream
* iface
,
519 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
520 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
523 /************************************************************************
524 * IPersistStream_Release
526 static ULONG WINAPI
IPersistStream_fnRelease(
527 IPersistStream
* iface
)
529 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
530 return IShellLinkA_Release((IShellLinkA
*)This
);
533 /************************************************************************
534 * IPersistStream_AddRef
536 static ULONG WINAPI
IPersistStream_fnAddRef(
537 IPersistStream
* iface
)
539 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
540 return ShellLink_AddRef( This
);
543 /************************************************************************
544 * IPersistStream_GetClassID
547 static HRESULT WINAPI
IPersistStream_fnGetClassID(
548 IPersistStream
* iface
,
551 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
552 return ShellLink_GetClassID( This
, pClassID
);
555 /************************************************************************
556 * IPersistStream_IsDirty (IPersistStream)
558 static HRESULT WINAPI
IPersistStream_fnIsDirty(
559 IPersistStream
* iface
)
561 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
563 TRACE("(%p)\n", This
);
569 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
580 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
581 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
585 len
*= sizeof (WCHAR
);
587 TRACE("reading %d\n", len
);
588 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
590 return E_OUTOFMEMORY
;
592 r
= IStream_Read(stm
, temp
, len
, &count
);
593 if( FAILED (r
) || ( count
!= len
) )
595 HeapFree( GetProcessHeap(), 0, temp
);
599 TRACE("read %s\n", debugstr_an(temp
,len
));
601 /* convert to unicode if necessary */
604 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
605 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
607 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
608 HeapFree( GetProcessHeap(), 0, temp
);
622 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
629 unsigned char data
[1];
634 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
635 if( FAILED( r
) || count
!= sizeof(size
) )
638 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
640 return E_OUTOFMEMORY
;
643 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
644 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
646 HeapFree( GetProcessHeap(), 0, chunk
);
650 TRACE("Read %d bytes\n",chunk
->size
);
652 *data
= (LPVOID
) chunk
;
657 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
659 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
663 volume
->serial
= vol
->dwVolSerial
;
664 volume
->type
= vol
->dwType
;
666 if( !vol
->dwVolLabelOfs
)
668 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
670 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
673 label
+= vol
->dwVolLabelOfs
;
674 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
679 static LPWSTR
Stream_LoadPath( LPSTR p
, DWORD maxlen
)
684 while( p
[len
] && (len
< maxlen
) )
687 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
688 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
689 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
695 static HRESULT
Stream_LoadLocation( IStream
*stm
,
696 volume_info
*volume
, LPWSTR
*path
)
703 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
707 loc
= (LOCATION_INFO
*) p
;
709 /* hack around .lnk files generated by older broken shelllink code */
710 if( loc
->dwTotalSize
== 0x18 )
712 ERR("link was generated by an older shelllink version\n");
713 memset( volume
, 0, sizeof *volume
);
718 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
720 HeapFree( GetProcessHeap(), 0, p
);
724 /* if there's valid local volume information, load it */
725 if( loc
->dwVolTableOfs
&&
726 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
728 LOCAL_VOLUME_INFO
*volume_info
;
730 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
731 Stream_LoadVolume( volume_info
, volume
);
734 /* if there's a local path, load it */
735 n
= loc
->dwLocalPathOfs
;
736 if( n
&& (n
< loc
->dwTotalSize
) )
737 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
739 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
740 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
742 HeapFree( GetProcessHeap(), 0, p
);
747 * The format of the advertised shortcut info seems to be:
752 * 0 Length of the block (4 bytes, usually 0x314)
754 * 8 string data in ASCII
755 * 8+0x104 string data in UNICODE
757 * In the original Win32 implementation the buffers are not initialized
758 * to zero, so data trailing the string is random garbage.
760 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
765 EXP_DARWIN_LINK buffer
;
769 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
773 /* make sure that we read the size of the structure even on error */
774 size
= sizeof buffer
- sizeof (DWORD
);
775 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
777 ERR("Ooops. This structure is not as expected...\n");
781 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
788 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
790 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
792 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
796 *str
= HeapAlloc( GetProcessHeap(), 0,
797 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
798 lstrcpyW( *str
, buffer
.szwDarwinID
);
803 /************************************************************************
804 * IPersistStream_Load (IPersistStream)
806 static HRESULT WINAPI
IPersistStream_fnLoad(
807 IPersistStream
* iface
,
816 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
818 TRACE("%p %p\n", This
, stm
);
821 return STG_E_INVALIDPOINTER
;
824 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
828 if( dwBytesRead
!= sizeof(hdr
))
830 if( hdr
.dwSize
!= sizeof(hdr
))
832 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
835 /* free all the old stuff */
838 memset( &This
->volume
, 0, sizeof This
->volume
);
839 HeapFree(GetProcessHeap(), 0, This
->sPath
);
841 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
842 This
->sDescription
= NULL
;
843 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
844 This
->sPathRel
= NULL
;
845 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
846 This
->sWorkDir
= NULL
;
847 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
849 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
850 This
->sIcoPath
= NULL
;
851 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
852 This
->sProduct
= NULL
;
853 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
854 This
->sComponent
= NULL
;
856 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
857 This
->iIcoNdx
= hdr
.nIcon
;
858 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
859 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
860 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
863 WCHAR sTemp
[MAX_PATH
];
864 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
865 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
866 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
867 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
868 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
869 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
870 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
871 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
872 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
875 /* load all the new stuff */
876 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
878 r
= ILLoadFromStream( stm
, &This
->pPidl
);
884 /* load the location information */
885 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
886 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
890 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
891 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
893 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
894 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
899 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
901 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
902 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
907 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
909 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
910 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
915 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
917 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
918 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
923 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
925 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
926 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
931 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
933 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
934 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
939 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
941 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
942 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
947 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
948 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
949 ERR("Last word was not zero\n");
960 /************************************************************************
963 * Helper function for IPersistStream_Save. Writes a unicode string
964 * with terminating nul byte to a stream, preceded by the its length.
966 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
968 USHORT len
= lstrlenW( str
) + 1;
972 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
976 len
*= sizeof(WCHAR
);
978 r
= IStream_Write( stm
, str
, len
, &count
);
985 /************************************************************************
986 * Stream_WriteLocationInfo
988 * Writes the location info to a stream
990 * FIXME: One day we might want to write the network volume information
991 * and the final path.
992 * Figure out how Windows deals with unicode paths here.
994 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
995 volume_info
*volume
)
997 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
998 LOCAL_VOLUME_INFO
*vol
;
1000 LPSTR szLabel
, szPath
, szFinalPath
;
1003 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
1005 /* figure out the size of everything */
1006 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
1007 NULL
, 0, NULL
, NULL
);
1008 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
1009 NULL
, 0, NULL
, NULL
);
1010 volume_info_size
= sizeof *vol
+ label_size
;
1011 final_path_size
= 1;
1012 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
1014 /* create pointers to everything */
1015 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
1016 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
1017 szLabel
= (LPSTR
) &vol
[1];
1018 szPath
= &szLabel
[label_size
];
1019 szFinalPath
= &szPath
[path_size
];
1021 /* fill in the location information header */
1022 loc
->dwTotalSize
= total_size
;
1023 loc
->dwHeaderSize
= sizeof (*loc
);
1025 loc
->dwVolTableOfs
= sizeof (*loc
);
1026 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
1027 loc
->dwNetworkVolTableOfs
= 0;
1028 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
1030 /* fill in the volume information */
1031 vol
->dwSize
= volume_info_size
;
1032 vol
->dwType
= volume
->type
;
1033 vol
->dwVolSerial
= volume
->serial
;
1034 vol
->dwVolLabelOfs
= sizeof (*vol
);
1036 /* copy in the strings */
1037 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
1038 szLabel
, label_size
, NULL
, NULL
);
1039 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
1040 szPath
, path_size
, NULL
, NULL
);
1043 return IStream_Write( stm
, loc
, total_size
, &count
);
1046 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
1048 EXP_DARWIN_LINK
*buffer
;
1050 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
1051 buffer
->dbh
.cbSize
= sizeof *buffer
;
1052 buffer
->dbh
.dwSignature
= magic
;
1053 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
1054 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
1059 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
1061 EXP_DARWIN_LINK
*buffer
;
1066 buffer
= shelllink_build_darwinid( string
, magic
);
1068 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1071 /************************************************************************
1072 * IPersistStream_Save (IPersistStream)
1074 * FIXME: makes assumptions about byte order
1076 static HRESULT WINAPI
IPersistStream_fnSave(
1077 IPersistStream
* iface
,
1081 static const WCHAR wOpen
[] = {'o','p','e','n',0};
1084 WCHAR exePath
[MAX_PATH
];
1089 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1091 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1097 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, MAX_PATH
,
1098 NULL
, NULL
, NULL
, NULL
);
1100 * windows can create lnk files to executables that do not exist yet
1101 * so if the executable does not exist the just trust the path they
1104 if (!*exePath
) lstrcpyW(exePath
,This
->sPath
);
1107 memset(&header
, 0, sizeof(header
));
1108 header
.dwSize
= sizeof(header
);
1109 header
.fStartup
= This
->iShowCmd
;
1110 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
1112 header
.wHotKey
= This
->wHotKey
;
1113 header
.nIcon
= This
->iIcoNdx
;
1114 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1116 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1118 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1119 if( This
->sDescription
)
1120 header
.dwFlags
|= SLDF_HAS_NAME
;
1121 if( This
->sWorkDir
)
1122 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1124 header
.dwFlags
|= SLDF_HAS_ARGS
;
1125 if( This
->sIcoPath
)
1126 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1127 if( This
->sProduct
)
1128 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1129 if( This
->sComponent
)
1130 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1132 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1133 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1134 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1136 /* write the Shortcut header */
1137 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1140 ERR("Write failed at %d\n",__LINE__
);
1144 TRACE("Writing pidl\n");
1146 /* write the PIDL to the shortcut */
1149 r
= ILSaveToStream( stm
, This
->pPidl
);
1152 ERR("Failed to write PIDL at %d\n",__LINE__
);
1158 Stream_WriteLocationInfo( stm
, exePath
, &This
->volume
);
1160 if( This
->sDescription
)
1161 r
= Stream_WriteString( stm
, This
->sDescription
);
1163 if( This
->sPathRel
)
1164 r
= Stream_WriteString( stm
, This
->sPathRel
);
1166 if( This
->sWorkDir
)
1167 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1170 r
= Stream_WriteString( stm
, This
->sArgs
);
1172 if( This
->sIcoPath
)
1173 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1175 if( This
->sProduct
)
1176 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1178 if( This
->sComponent
)
1179 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1181 /* the last field is a single zero dword */
1183 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1188 /************************************************************************
1189 * IPersistStream_GetSizeMax (IPersistStream)
1191 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1192 IPersistStream
* iface
,
1193 ULARGE_INTEGER
* pcbSize
)
1195 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1197 TRACE("(%p)\n", This
);
1202 static const IPersistStreamVtbl psvt
=
1204 IPersistStream_fnQueryInterface
,
1205 IPersistStream_fnAddRef
,
1206 IPersistStream_fnRelease
,
1207 IPersistStream_fnGetClassID
,
1208 IPersistStream_fnIsDirty
,
1209 IPersistStream_fnLoad
,
1210 IPersistStream_fnSave
,
1211 IPersistStream_fnGetSizeMax
1214 /**************************************************************************
1215 * IShellLink_Constructor
1217 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1218 REFIID riid
, LPVOID
*ppv
)
1220 IShellLinkImpl
* sl
;
1223 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1228 return CLASS_E_NOAGGREGATION
;
1229 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1231 return E_OUTOFMEMORY
;
1235 sl
->lpvtblw
= &slvtw
;
1236 sl
->lpvtblPersistFile
= &pfvt
;
1237 sl
->lpvtblPersistStream
= &psvt
;
1238 sl
->lpvtblShellLinkDataList
= &dlvt
;
1239 sl
->lpvtblShellExtInit
= &eivt
;
1240 sl
->lpvtblContextMenu
= &cmvt
;
1241 sl
->lpvtblObjectWithSite
= &owsvt
;
1242 sl
->iShowCmd
= SW_SHOWNORMAL
;
1247 TRACE("(%p)->()\n",sl
);
1249 r
= ShellLink_QueryInterface( sl
, riid
, ppv
);
1250 ShellLink_Release( sl
);
1255 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1257 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1262 /**************************************************************************
1263 * ShellLink_UpdatePath
1264 * update absolute path in sPath using relative path in sPathRel
1266 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1268 if (!path
|| !psPath
)
1269 return E_INVALIDARG
;
1271 if (!*psPath
&& sPathRel
) {
1272 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1273 LPWSTR final
= NULL
;
1275 /* first try if [directory of link file] + [relative path] finds an existing file */
1277 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1280 lstrcpyW(final
, sPathRel
);
1284 if (SHELL_ExistsFileW(buffer
)) {
1285 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1286 lstrcpyW(abs_path
, buffer
);
1288 /* try if [working directory] + [relative path] finds an existing file */
1290 lstrcpyW(buffer
, sWorkDir
);
1291 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1293 if (SHELL_ExistsFileW(buffer
))
1294 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1295 lstrcpyW(abs_path
, buffer
);
1299 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1301 lstrcpyW(abs_path
, sPathRel
);
1303 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1305 return E_OUTOFMEMORY
;
1307 lstrcpyW(*psPath
, abs_path
);
1313 /**************************************************************************
1314 * IShellLink_ConstructFromFile
1316 HRESULT WINAPI
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1317 LPCITEMIDLIST pidl
, LPVOID
* ppv
)
1321 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1323 if (SUCCEEDED(hr
)) {
1328 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1330 if (SUCCEEDED(hr
)) {
1331 WCHAR path
[MAX_PATH
];
1333 if (SHGetPathFromIDListW(pidl
, path
))
1334 hr
= IPersistFile_Load(ppf
, path
, 0);
1339 *ppv
= (IUnknown
*) psl
;
1341 IPersistFile_Release(ppf
);
1345 IShellLinkW_Release(psl
);
1351 /**************************************************************************
1352 * IShellLinkA_QueryInterface
1354 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1356 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1357 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1360 /******************************************************************************
1361 * IShellLinkA_AddRef
1363 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
1365 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1366 return ShellLink_AddRef( This
);
1369 /******************************************************************************
1370 * IShellLinkA_Release
1372 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1374 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1375 return ShellLink_Release( This
);
1378 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1379 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1381 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1383 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1384 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1386 if (This
->sComponent
|| This
->sProduct
)
1392 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1393 pszFile
, cchMaxPath
, NULL
, NULL
);
1395 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1400 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1402 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1404 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1406 return IShellLinkW_GetIDList((IShellLinkW
*)&(This
->lpvtblw
), ppidl
);
1409 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1411 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1413 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1416 ILFree(This
->pPidl
);
1417 This
->pPidl
= ILClone (pidl
);
1418 This
->bDirty
= TRUE
;
1423 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1425 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1427 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1431 if( This
->sDescription
)
1432 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1433 pszName
, cchMaxName
, NULL
, NULL
);
1438 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1440 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1442 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1444 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1445 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1446 if ( !This
->sDescription
)
1447 return E_OUTOFMEMORY
;
1449 This
->bDirty
= TRUE
;
1454 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1456 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1458 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1462 if( This
->sWorkDir
)
1463 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1464 pszDir
, cchMaxPath
, NULL
, NULL
);
1469 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1471 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1473 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1475 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1476 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1477 if ( !This
->sWorkDir
)
1478 return E_OUTOFMEMORY
;
1480 This
->bDirty
= TRUE
;
1485 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1487 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1489 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1494 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1495 pszArgs
, cchMaxPath
, NULL
, NULL
);
1500 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1502 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1504 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1506 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1507 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1509 return E_OUTOFMEMORY
;
1511 This
->bDirty
= TRUE
;
1516 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1518 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1520 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1522 *pwHotkey
= This
->wHotKey
;
1527 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1529 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1531 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1533 This
->wHotKey
= wHotkey
;
1534 This
->bDirty
= TRUE
;
1539 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1541 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1543 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1544 *piShowCmd
= This
->iShowCmd
;
1548 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1550 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1552 TRACE("(%p) %d\n",This
, iShowCmd
);
1554 This
->iShowCmd
= iShowCmd
;
1555 This
->bDirty
= TRUE
;
1560 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1562 LPCITEMIDLIST pidlLast
;
1564 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1566 if (SUCCEEDED(hr
)) {
1569 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1571 if (SUCCEEDED(hr
)) {
1572 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1574 IExtractIconA_Release(pei
);
1577 IShellFolder_Release(psf
);
1583 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1585 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1587 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1590 *piIcon
= This
->iIcoNdx
;
1594 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1598 if (This
->pPidl
|| This
->sPath
)
1602 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1606 /* first look for an icon using the PIDL (if present) */
1608 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1612 /* if we couldn't find an icon yet, look for it using the file system path */
1613 if (FAILED(hr
) && This
->sPath
)
1617 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1619 if (SUCCEEDED(hr
)) {
1620 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1626 IShellFolder_Release(pdsk
);
1634 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1636 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1638 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1640 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1641 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1642 if ( !This
->sIcoPath
)
1643 return E_OUTOFMEMORY
;
1645 This
->iIcoNdx
= iIcon
;
1646 This
->bDirty
= TRUE
;
1651 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1653 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1655 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1657 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1658 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1659 This
->bDirty
= TRUE
;
1661 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1664 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1666 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1668 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1670 return IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, fFlags
);
1673 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1677 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1679 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1681 str
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1683 return E_OUTOFMEMORY
;
1685 r
= IShellLinkW_SetPath((IShellLinkW
*)&(This
->lpvtblw
), str
);
1686 HeapFree( GetProcessHeap(), 0, str
);
1691 /**************************************************************************
1692 * IShellLink Implementation
1695 static const IShellLinkAVtbl slvt
=
1697 IShellLinkA_fnQueryInterface
,
1698 IShellLinkA_fnAddRef
,
1699 IShellLinkA_fnRelease
,
1700 IShellLinkA_fnGetPath
,
1701 IShellLinkA_fnGetIDList
,
1702 IShellLinkA_fnSetIDList
,
1703 IShellLinkA_fnGetDescription
,
1704 IShellLinkA_fnSetDescription
,
1705 IShellLinkA_fnGetWorkingDirectory
,
1706 IShellLinkA_fnSetWorkingDirectory
,
1707 IShellLinkA_fnGetArguments
,
1708 IShellLinkA_fnSetArguments
,
1709 IShellLinkA_fnGetHotkey
,
1710 IShellLinkA_fnSetHotkey
,
1711 IShellLinkA_fnGetShowCmd
,
1712 IShellLinkA_fnSetShowCmd
,
1713 IShellLinkA_fnGetIconLocation
,
1714 IShellLinkA_fnSetIconLocation
,
1715 IShellLinkA_fnSetRelativePath
,
1716 IShellLinkA_fnResolve
,
1717 IShellLinkA_fnSetPath
1721 /**************************************************************************
1722 * IShellLinkW_fnQueryInterface
1724 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1725 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1727 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1728 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1731 /******************************************************************************
1732 * IShellLinkW_fnAddRef
1734 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1736 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1737 return ShellLink_AddRef( This
);
1740 /******************************************************************************
1741 * IShellLinkW_fnRelease
1743 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1745 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1746 return ShellLink_Release( This
);
1749 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1751 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1753 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1754 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1756 if (This
->sComponent
|| This
->sProduct
)
1762 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1764 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1769 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1771 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1773 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1780 *ppidl
= ILClone(This
->pPidl
);
1784 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1786 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1788 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1791 ILFree( This
->pPidl
);
1792 This
->pPidl
= ILClone( pidl
);
1796 This
->bDirty
= TRUE
;
1801 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1803 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1805 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1808 if( This
->sDescription
)
1809 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1814 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1816 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1818 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1820 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1821 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1822 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1823 if ( !This
->sDescription
)
1824 return E_OUTOFMEMORY
;
1826 lstrcpyW( This
->sDescription
, pszName
);
1827 This
->bDirty
= TRUE
;
1832 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1834 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1836 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1840 if( This
->sWorkDir
)
1841 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1846 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1848 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1850 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1852 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1853 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1854 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1855 if ( !This
->sWorkDir
)
1856 return E_OUTOFMEMORY
;
1857 lstrcpyW( This
->sWorkDir
, pszDir
);
1858 This
->bDirty
= TRUE
;
1863 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1865 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1867 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1872 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1877 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1879 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1881 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1883 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1884 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1885 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1887 return E_OUTOFMEMORY
;
1888 lstrcpyW( This
->sArgs
, pszArgs
);
1889 This
->bDirty
= TRUE
;
1894 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1896 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1898 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1900 *pwHotkey
=This
->wHotKey
;
1905 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1907 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1909 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1911 This
->wHotKey
= wHotkey
;
1912 This
->bDirty
= TRUE
;
1917 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1919 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1921 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1923 *piShowCmd
= This
->iShowCmd
;
1928 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1930 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1932 This
->iShowCmd
= iShowCmd
;
1933 This
->bDirty
= TRUE
;
1938 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1940 LPCITEMIDLIST pidlLast
;
1942 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1944 if (SUCCEEDED(hr
)) {
1947 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1949 if (SUCCEEDED(hr
)) {
1950 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1952 IExtractIconW_Release(pei
);
1955 IShellFolder_Release(psf
);
1961 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1963 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1965 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1968 *piIcon
= This
->iIcoNdx
;
1972 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1976 if (This
->pPidl
|| This
->sPath
)
1980 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1984 /* first look for an icon using the PIDL (if present) */
1986 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1990 /* if we couldn't find an icon yet, look for it using the file system path */
1991 if (FAILED(hr
) && This
->sPath
)
1995 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1999 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
2005 IShellFolder_Release(pdsk
);
2012 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
2014 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2016 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
2018 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
2019 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
2020 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
2021 if ( !This
->sIcoPath
)
2022 return E_OUTOFMEMORY
;
2023 lstrcpyW( This
->sIcoPath
, pszIconPath
);
2025 This
->iIcoNdx
= iIcon
;
2026 This
->bDirty
= TRUE
;
2031 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
2033 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2035 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
2037 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
2038 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
2039 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
2040 if ( !This
->sPathRel
)
2041 return E_OUTOFMEMORY
;
2042 lstrcpyW( This
->sPathRel
, pszPathRel
);
2043 This
->bDirty
= TRUE
;
2045 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
2048 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
2053 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2055 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
2057 /*FIXME: use IResolveShellLink interface */
2059 if (!This
->sPath
&& This
->pPidl
) {
2060 WCHAR buffer
[MAX_PATH
];
2062 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
2064 if (bSuccess
&& *buffer
) {
2065 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
2067 return E_OUTOFMEMORY
;
2069 lstrcpyW(This
->sPath
, buffer
);
2071 This
->bDirty
= TRUE
;
2073 hr
= S_OK
; /* don't report an error occurred while just caching information */
2076 if (!This
->sIcoPath
&& This
->sPath
) {
2077 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
2078 if (!This
->sIcoPath
)
2079 return E_OUTOFMEMORY
;
2081 lstrcpyW(This
->sIcoPath
, This
->sPath
);
2084 This
->bDirty
= TRUE
;
2090 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2099 p
= strchrW( str
, ':' );
2103 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2106 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2111 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2113 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2121 /* each segment must start with two colons */
2122 if( str
[0] != ':' || str
[1] != ':' )
2125 /* the last segment is just two colons */
2130 /* there must be a colon straight after a guid */
2131 p
= strchrW( str
, ':' );
2138 /* get the guid, and check it's validly formatted */
2139 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2141 r
= CLSIDFromString( szGuid
, &guid
);
2146 /* match it up to a guid that we care about */
2147 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2149 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2154 /* skip to the next field */
2155 str
= strchrW( str
, ':' );
2160 /* we have to have a component for an advertised shortcut */
2164 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2165 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2167 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2168 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2173 static BOOL
ShellLink_GetVolumeInfo(LPWSTR path
, volume_info
*volume
)
2175 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2176 WCHAR drive
[4] = { path
[0], ':', '\\', 0 };
2179 volume
->type
= GetDriveTypeW(drive
);
2180 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2181 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2182 TRACE("r = %d type %d serial %08x name %s\n", r
,
2183 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2187 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2189 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2190 WCHAR buffer
[MAX_PATH
];
2191 LPWSTR fname
, unquoted
= NULL
;
2195 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2197 /* quotes at the ends of the string are stripped */
2198 len
= lstrlenW(pszFile
);
2199 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2201 unquoted
= strdupW(pszFile
);
2202 PathUnquoteSpacesW(unquoted
);
2206 /* any other quote marks are invalid */
2207 if (strchrW(pszFile
, '"'))
2210 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2213 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2214 This
->sComponent
= NULL
;
2217 ILFree(This
->pPidl
);
2220 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2222 if (*pszFile
== '\0')
2224 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2226 else if(!PathFileExistsW(buffer
) &&
2227 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2230 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2231 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2233 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2234 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2236 return E_OUTOFMEMORY
;
2238 lstrcpyW(This
->sPath
, buffer
);
2240 This
->bDirty
= TRUE
;
2241 HeapFree(GetProcessHeap(), 0, unquoted
);
2246 /**************************************************************************
2247 * IShellLinkW Implementation
2250 static const IShellLinkWVtbl slvtw
=
2252 IShellLinkW_fnQueryInterface
,
2253 IShellLinkW_fnAddRef
,
2254 IShellLinkW_fnRelease
,
2255 IShellLinkW_fnGetPath
,
2256 IShellLinkW_fnGetIDList
,
2257 IShellLinkW_fnSetIDList
,
2258 IShellLinkW_fnGetDescription
,
2259 IShellLinkW_fnSetDescription
,
2260 IShellLinkW_fnGetWorkingDirectory
,
2261 IShellLinkW_fnSetWorkingDirectory
,
2262 IShellLinkW_fnGetArguments
,
2263 IShellLinkW_fnSetArguments
,
2264 IShellLinkW_fnGetHotkey
,
2265 IShellLinkW_fnSetHotkey
,
2266 IShellLinkW_fnGetShowCmd
,
2267 IShellLinkW_fnSetShowCmd
,
2268 IShellLinkW_fnGetIconLocation
,
2269 IShellLinkW_fnSetIconLocation
,
2270 IShellLinkW_fnSetRelativePath
,
2271 IShellLinkW_fnResolve
,
2272 IShellLinkW_fnSetPath
2275 static HRESULT WINAPI
2276 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2278 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2279 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2283 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2285 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2286 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2290 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2292 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2293 return ShellLink_Release( This
);
2296 static HRESULT WINAPI
2297 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2303 static HRESULT WINAPI
2304 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2306 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2307 LPVOID block
= NULL
;
2310 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2314 case EXP_DARWIN_ID_SIG
:
2315 if (!This
->sComponent
)
2317 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2320 case EXP_SZ_LINK_SIG
:
2321 case NT_CONSOLE_PROPS_SIG
:
2322 case NT_FE_CONSOLE_PROPS_SIG
:
2323 case EXP_SPECIAL_FOLDER_SIG
:
2324 case EXP_SZ_ICON_SIG
:
2325 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2328 ERR("unknown datablock %08x\n", dwSig
);
2330 *ppDataBlock
= block
;
2334 static HRESULT WINAPI
2335 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2341 static HRESULT WINAPI
2342 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2344 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2347 FIXME("%p %p\n", This
, pdwFlags
);
2349 /* FIXME: add more */
2351 flags
|= SLDF_HAS_ARGS
;
2352 if (This
->sComponent
)
2353 flags
|= SLDF_HAS_DARWINID
;
2355 flags
|= SLDF_HAS_ICONLOCATION
;
2357 flags
|= SLDF_HAS_LOGO3ID
;
2359 flags
|= SLDF_HAS_ID_LIST
;
2366 static HRESULT WINAPI
2367 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2373 static const IShellLinkDataListVtbl dlvt
=
2375 ShellLink_DataList_QueryInterface
,
2376 ShellLink_DataList_AddRef
,
2377 ShellLink_DataList_Release
,
2378 ShellLink_AddDataBlock
,
2379 ShellLink_CopyDataBlock
,
2380 ShellLink_RemoveDataBlock
,
2385 static HRESULT WINAPI
2386 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2388 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2389 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2393 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2395 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2396 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2400 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2402 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2403 return ShellLink_Release( This
);
2406 /**************************************************************************
2407 * ShellLink implementation of IShellExtInit::Initialize()
2409 * Loads the shelllink from the dataobject the shell is pointing to.
2411 static HRESULT WINAPI
2412 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2413 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2415 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2421 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2426 format
.cfFormat
= CF_HDROP
;
2428 format
.dwAspect
= DVASPECT_CONTENT
;
2430 format
.tymed
= TYMED_HGLOBAL
;
2432 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2435 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2440 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2442 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2445 IPersistFile
*pf
= (IPersistFile
*) &This
->lpvtblPersistFile
;
2447 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2448 r
= IPersistFile_Load( pf
, path
, 0 );
2449 HeapFree( GetProcessHeap(), 0, path
);
2452 ReleaseStgMedium( &stgm
);
2457 static const IShellExtInitVtbl eivt
=
2459 ShellLink_ExtInit_QueryInterface
,
2460 ShellLink_ExtInit_AddRef
,
2461 ShellLink_ExtInit_Release
,
2462 ShellLink_ExtInit_Initialize
2465 static HRESULT WINAPI
2466 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2468 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2469 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObject
);
2473 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2475 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2476 return IShellLinkA_AddRef((IShellLinkA
*)This
);
2480 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2482 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2483 return ShellLink_Release( This
);
2486 static HRESULT WINAPI
2487 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2488 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2490 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2491 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2495 TRACE("%p %p %u %u %u %u\n", This
,
2496 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2499 return E_INVALIDARG
;
2501 memset( &mii
, 0, sizeof mii
);
2502 mii
.cbSize
= sizeof mii
;
2503 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2504 mii
.dwTypeData
= szOpen
;
2505 mii
.cch
= strlenW( mii
.dwTypeData
);
2506 mii
.wID
= idCmdFirst
+ id
++;
2507 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2508 mii
.fType
= MFT_STRING
;
2509 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2513 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2517 shelllink_get_msi_component_path( LPWSTR component
)
2522 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2523 if (r
!= ERROR_SUCCESS
)
2527 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2528 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2529 if (r
!= ERROR_SUCCESS
)
2531 HeapFree( GetProcessHeap(), 0, path
);
2535 TRACE("returning %s\n", debugstr_w( path
) );
2540 static HRESULT WINAPI
2541 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2543 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2544 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2545 SHELLEXECUTEINFOW sei
;
2546 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2551 TRACE("%p %p\n", This
, lpici
);
2553 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2554 return E_INVALIDARG
;
2556 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2558 ERR("Unknown id %d != %d\n", (INT
)lpici
->lpVerb
, This
->iIdOpen
);
2559 return E_INVALIDARG
;
2562 r
= IShellLinkW_Resolve( (IShellLinkW
*)&(This
->lpvtblw
), hwnd
, 0 );
2566 if ( This
->sComponent
)
2568 path
= shelllink_get_msi_component_path( This
->sComponent
);
2573 path
= strdupW( This
->sPath
);
2575 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2576 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2578 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2582 len
+= lstrlenW( This
->sArgs
);
2583 if ( iciex
->lpParametersW
)
2584 len
+= lstrlenW( iciex
->lpParametersW
);
2586 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2589 lstrcatW( args
, This
->sArgs
);
2590 if ( iciex
->lpParametersW
)
2592 static const WCHAR space
[] = { ' ', 0 };
2593 lstrcatW( args
, space
);
2594 lstrcatW( args
, iciex
->lpParametersW
);
2598 memset( &sei
, 0, sizeof sei
);
2599 sei
.cbSize
= sizeof sei
;
2600 sei
.fMask
= SEE_MASK_UNICODE
| SEE_MASK_NOCLOSEPROCESS
;
2602 sei
.nShow
= This
->iShowCmd
;
2603 sei
.lpIDList
= This
->pPidl
;
2604 sei
.lpDirectory
= This
->sWorkDir
;
2605 sei
.lpParameters
= args
;
2606 sei
.lpVerb
= szOpen
;
2608 if( ShellExecuteExW( &sei
) )
2612 WaitForSingleObject( sei
.hProcess
, 10000 );
2613 CloseHandle( sei
.hProcess
);
2620 HeapFree( GetProcessHeap(), 0, args
);
2621 HeapFree( GetProcessHeap(), 0, path
);
2626 static HRESULT WINAPI
2627 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2628 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2630 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2632 FIXME("%p %u %u %p %p %u\n", This
,
2633 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2638 static const IContextMenuVtbl cmvt
=
2640 ShellLink_ContextMenu_QueryInterface
,
2641 ShellLink_ContextMenu_AddRef
,
2642 ShellLink_ContextMenu_Release
,
2643 ShellLink_QueryContextMenu
,
2644 ShellLink_InvokeCommand
,
2645 ShellLink_GetCommandString
2648 static HRESULT WINAPI
2649 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2651 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2652 return ShellLink_QueryInterface( This
, riid
, ppvObject
);
2656 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2658 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2659 return ShellLink_AddRef( This
);
2663 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2665 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2666 return ShellLink_Release( This
);
2669 static HRESULT WINAPI
2670 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2672 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2674 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2678 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2681 static HRESULT WINAPI
2682 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2684 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2686 TRACE("%p %p\n", iface
, punk
);
2689 IUnknown_AddRef( punk
);
2695 static const IObjectWithSiteVtbl owsvt
=
2697 ShellLink_ObjectWithSite_QueryInterface
,
2698 ShellLink_ObjectWithSite_AddRef
,
2699 ShellLink_ObjectWithSite_Release
,