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 /* IShellLink Implementation */
122 IShellLinkA IShellLinkA_iface
;
123 IShellLinkW IShellLinkW_iface
;
124 IPersistFile IPersistFile_iface
;
125 IPersistStream IPersistStream_iface
;
126 IShellLinkDataList IShellLinkDataList_iface
;
127 IShellExtInit IShellExtInit_iface
;
128 IContextMenu IContextMenu_iface
;
129 IObjectWithSite IObjectWithSite_iface
;
130 IPropertyStore IPropertyStore_iface
;
134 /* data structures according to the information in the link */
154 INT iIdOpen
; /* id of the "Open" entry in the context menu */
157 LPOLESTR filepath
; /* file path returned by IPersistFile::GetCurFile */
160 static inline IShellLinkImpl
*impl_from_IShellLinkA(IShellLinkA
*iface
)
162 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkA_iface
);
165 static inline IShellLinkImpl
*impl_from_IShellLinkW(IShellLinkW
*iface
)
167 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkW_iface
);
170 static inline IShellLinkImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
172 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistFile_iface
);
175 static inline IShellLinkImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
177 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistStream_iface
);
180 static inline IShellLinkImpl
*impl_from_IShellLinkDataList(IShellLinkDataList
*iface
)
182 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkDataList_iface
);
185 static inline IShellLinkImpl
*impl_from_IShellExtInit(IShellExtInit
*iface
)
187 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellExtInit_iface
);
190 static inline IShellLinkImpl
*impl_from_IContextMenu(IContextMenu
*iface
)
192 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IContextMenu_iface
);
195 static inline IShellLinkImpl
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
197 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IObjectWithSite_iface
);
200 static inline IShellLinkImpl
*impl_from_IPropertyStore(IPropertyStore
*iface
)
202 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPropertyStore_iface
);
205 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
207 /* strdup on the process heap */
208 static inline LPWSTR
heap_strdupAtoW( LPCSTR str
)
210 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
211 LPWSTR p
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof (WCHAR
) );
214 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
218 /**************************************************************************
219 * IPersistFile_QueryInterface
221 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
226 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
227 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
230 /******************************************************************************
231 * IPersistFile_AddRef
233 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
235 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
236 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
239 /******************************************************************************
240 * IPersistFile_Release
242 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
244 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
245 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
248 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
250 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
252 TRACE("(%p)->(%p)\n", This
, pClassID
);
254 *pClassID
= CLSID_ShellLink
;
259 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
261 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
263 TRACE("(%p)\n",This
);
271 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
273 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
274 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
278 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
281 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
282 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
285 r
= IPersistStream_Load(StreamThis
, stm
);
286 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
287 IStream_Release( stm
);
289 /* update file path */
290 HeapFree(GetProcessHeap(), 0, This
->filepath
);
291 This
->filepath
= strdupW(pszFileName
);
293 This
->bDirty
= FALSE
;
295 TRACE("-- returning hr %08x\n", r
);
299 BOOL
run_winemenubuilder( const WCHAR
*args
)
301 static const WCHAR menubuilder
[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
305 PROCESS_INFORMATION pi
;
310 GetSystemDirectoryW( app
, MAX_PATH
- sizeof(menubuilder
)/sizeof(WCHAR
) );
311 strcatW( app
, menubuilder
);
313 len
= (strlenW( app
) + strlenW( args
) + 1) * sizeof(WCHAR
);
314 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
318 strcpyW( buffer
, app
);
319 strcatW( buffer
, args
);
321 TRACE("starting %s\n",debugstr_w(buffer
));
323 memset(&si
, 0, sizeof(si
));
326 Wow64DisableWow64FsRedirection( &redir
);
327 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
328 Wow64RevertWow64FsRedirection( redir
);
330 HeapFree( GetProcessHeap(), 0, buffer
);
334 CloseHandle( pi
.hProcess
);
335 CloseHandle( pi
.hThread
);
341 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
343 static const WCHAR szFormat
[] = {' ','-','w',' ','"','%','s','"',0 };
348 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
349 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
353 wsprintfW( buffer
, szFormat
, szLink
);
354 ret
= run_winemenubuilder( buffer
);
355 HeapFree( GetProcessHeap(), 0, buffer
);
359 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
361 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
362 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
366 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
371 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
374 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
375 IStream_Release( stm
);
379 StartLinkProcessor( pszFileName
);
381 /* update file path */
382 HeapFree(GetProcessHeap(), 0, This
->filepath
);
383 This
->filepath
= strdupW(pszFileName
);
385 This
->bDirty
= FALSE
;
389 DeleteFileW( pszFileName
);
390 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
397 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
399 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
400 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
404 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
406 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
409 TRACE("(%p)->(%p)\n", This
, filename
);
417 SHGetMalloc(&pMalloc
);
418 *filename
= IMalloc_Alloc(pMalloc
, (strlenW(This
->filepath
)+1)*sizeof(WCHAR
));
419 if (!*filename
) return E_OUTOFMEMORY
;
421 strcpyW(*filename
, This
->filepath
);
426 static const IPersistFileVtbl pfvt
=
428 IPersistFile_fnQueryInterface
,
429 IPersistFile_fnAddRef
,
430 IPersistFile_fnRelease
,
431 IPersistFile_fnGetClassID
,
432 IPersistFile_fnIsDirty
,
435 IPersistFile_fnSaveCompleted
,
436 IPersistFile_fnGetCurFile
439 /************************************************************************
440 * IPersistStream_QueryInterface
442 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
443 IPersistStream
* iface
,
447 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
448 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
451 /************************************************************************
452 * IPersistStream_Release
454 static ULONG WINAPI
IPersistStream_fnRelease(
455 IPersistStream
* iface
)
457 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
458 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
461 /************************************************************************
462 * IPersistStream_AddRef
464 static ULONG WINAPI
IPersistStream_fnAddRef(
465 IPersistStream
* iface
)
467 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
468 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
471 /************************************************************************
472 * IPersistStream_GetClassID
475 static HRESULT WINAPI
IPersistStream_fnGetClassID(
476 IPersistStream
* iface
,
479 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
480 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
483 /************************************************************************
484 * IPersistStream_IsDirty (IPersistStream)
486 static HRESULT WINAPI
IPersistStream_fnIsDirty(
487 IPersistStream
* iface
)
489 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
491 TRACE("(%p)\n", This
);
497 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
508 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
509 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
513 len
*= sizeof (WCHAR
);
515 TRACE("reading %d\n", len
);
516 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
518 return E_OUTOFMEMORY
;
520 r
= IStream_Read(stm
, temp
, len
, &count
);
521 if( FAILED (r
) || ( count
!= len
) )
523 HeapFree( GetProcessHeap(), 0, temp
);
527 TRACE("read %s\n", debugstr_an(temp
,len
));
529 /* convert to unicode if necessary */
532 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
533 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
536 HeapFree( GetProcessHeap(), 0, temp
);
537 return E_OUTOFMEMORY
;
539 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
540 HeapFree( GetProcessHeap(), 0, temp
);
554 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
561 unsigned char data
[1];
566 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
567 if( FAILED( r
) || count
!= sizeof(size
) )
570 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
572 return E_OUTOFMEMORY
;
575 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
576 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
578 HeapFree( GetProcessHeap(), 0, chunk
);
582 TRACE("Read %d bytes\n",chunk
->size
);
589 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
591 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
595 volume
->serial
= vol
->dwVolSerial
;
596 volume
->type
= vol
->dwType
;
598 if( !vol
->dwVolLabelOfs
)
600 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
602 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
605 label
+= vol
->dwVolLabelOfs
;
606 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
611 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
616 while( p
[len
] && (len
< maxlen
) )
619 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
620 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
621 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
627 static HRESULT
Stream_LoadLocation( IStream
*stm
,
628 volume_info
*volume
, LPWSTR
*path
)
635 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
639 loc
= (LOCATION_INFO
*) p
;
640 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
642 HeapFree( GetProcessHeap(), 0, p
);
646 /* if there's valid local volume information, load it */
647 if( loc
->dwVolTableOfs
&&
648 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
650 LOCAL_VOLUME_INFO
*volume_info
;
652 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
653 Stream_LoadVolume( volume_info
, volume
);
656 /* if there's a local path, load it */
657 n
= loc
->dwLocalPathOfs
;
658 if( n
&& (n
< loc
->dwTotalSize
) )
659 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
661 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
662 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
664 HeapFree( GetProcessHeap(), 0, p
);
669 * The format of the advertised shortcut info seems to be:
674 * 0 Length of the block (4 bytes, usually 0x314)
676 * 8 string data in ASCII
677 * 8+0x104 string data in UNICODE
679 * In the original Win32 implementation the buffers are not initialized
680 * to zero, so data trailing the string is random garbage.
682 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
687 EXP_DARWIN_LINK buffer
;
691 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
695 /* make sure that we read the size of the structure even on error */
696 size
= sizeof buffer
- sizeof (DWORD
);
697 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
699 ERR("Ooops. This structure is not as expected...\n");
703 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
710 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
712 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
714 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
718 *str
= HeapAlloc( GetProcessHeap(), 0,
719 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
720 lstrcpyW( *str
, buffer
.szwDarwinID
);
725 /************************************************************************
726 * IPersistStream_Load (IPersistStream)
728 static HRESULT WINAPI
IPersistStream_fnLoad(
729 IPersistStream
* iface
,
738 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
740 TRACE("%p %p\n", This
, stm
);
743 return STG_E_INVALIDPOINTER
;
746 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
750 if( dwBytesRead
!= sizeof(hdr
))
752 if( hdr
.dwSize
!= sizeof(hdr
))
754 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
757 /* free all the old stuff */
760 memset( &This
->volume
, 0, sizeof This
->volume
);
761 HeapFree(GetProcessHeap(), 0, This
->sPath
);
763 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
764 This
->sDescription
= NULL
;
765 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
766 This
->sPathRel
= NULL
;
767 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
768 This
->sWorkDir
= NULL
;
769 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
771 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
772 This
->sIcoPath
= NULL
;
773 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
774 This
->sProduct
= NULL
;
775 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
776 This
->sComponent
= NULL
;
778 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
779 This
->iIcoNdx
= hdr
.nIcon
;
780 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
781 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
782 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
785 WCHAR sTemp
[MAX_PATH
];
786 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
787 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
788 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
789 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
790 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
791 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
792 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
793 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
794 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
797 /* load all the new stuff */
798 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
800 r
= ILLoadFromStream( stm
, &This
->pPidl
);
806 /* load the location information */
807 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
808 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
812 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
813 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
815 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
816 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
821 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
823 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
824 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
829 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
831 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
832 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
837 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
839 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
840 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
845 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
847 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
848 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
853 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
855 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
856 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
861 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
863 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
864 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
869 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
870 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
872 /* Some lnk files have extra data blocks starting with a
873 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
874 * one with a 0xa0000003 signature. However these don't seem to matter
877 WARN("Last word was not zero\n");
889 /************************************************************************
892 * Helper function for IPersistStream_Save. Writes a unicode string
893 * with terminating nul byte to a stream, preceded by the its length.
895 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
897 USHORT len
= lstrlenW( str
) + 1;
901 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
905 len
*= sizeof(WCHAR
);
907 r
= IStream_Write( stm
, str
, len
, &count
);
914 /************************************************************************
915 * Stream_WriteLocationInfo
917 * Writes the location info to a stream
919 * FIXME: One day we might want to write the network volume information
920 * and the final path.
921 * Figure out how Windows deals with unicode paths here.
923 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
924 volume_info
*volume
)
926 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
927 LOCAL_VOLUME_INFO
*vol
;
929 LPSTR szLabel
, szPath
, szFinalPath
;
933 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
935 /* figure out the size of everything */
936 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
937 NULL
, 0, NULL
, NULL
);
938 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
939 NULL
, 0, NULL
, NULL
);
940 volume_info_size
= sizeof *vol
+ label_size
;
942 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
944 /* create pointers to everything */
945 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
946 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
947 szLabel
= (LPSTR
) &vol
[1];
948 szPath
= &szLabel
[label_size
];
949 szFinalPath
= &szPath
[path_size
];
951 /* fill in the location information header */
952 loc
->dwTotalSize
= total_size
;
953 loc
->dwHeaderSize
= sizeof (*loc
);
955 loc
->dwVolTableOfs
= sizeof (*loc
);
956 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
957 loc
->dwNetworkVolTableOfs
= 0;
958 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
960 /* fill in the volume information */
961 vol
->dwSize
= volume_info_size
;
962 vol
->dwType
= volume
->type
;
963 vol
->dwVolSerial
= volume
->serial
;
964 vol
->dwVolLabelOfs
= sizeof (*vol
);
966 /* copy in the strings */
967 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
968 szLabel
, label_size
, NULL
, NULL
);
969 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
970 szPath
, path_size
, NULL
, NULL
);
973 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
974 HeapFree(GetProcessHeap(), 0, loc
);
979 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
981 EXP_DARWIN_LINK
*buffer
;
983 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
984 buffer
->dbh
.cbSize
= sizeof *buffer
;
985 buffer
->dbh
.dwSignature
= magic
;
986 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
987 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
992 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
994 EXP_DARWIN_LINK
*buffer
;
999 buffer
= shelllink_build_darwinid( string
, magic
);
1001 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1004 /************************************************************************
1005 * IPersistStream_Save (IPersistStream)
1007 * FIXME: makes assumptions about byte order
1009 static HRESULT WINAPI
IPersistStream_fnSave(
1010 IPersistStream
* iface
,
1019 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1021 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1023 memset(&header
, 0, sizeof(header
));
1024 header
.dwSize
= sizeof(header
);
1025 header
.fStartup
= This
->iShowCmd
;
1026 header
.MagicGuid
= CLSID_ShellLink
;
1028 header
.wHotKey
= This
->wHotKey
;
1029 header
.nIcon
= This
->iIcoNdx
;
1030 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1032 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1034 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1035 if( This
->sDescription
)
1036 header
.dwFlags
|= SLDF_HAS_NAME
;
1037 if( This
->sWorkDir
)
1038 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1040 header
.dwFlags
|= SLDF_HAS_ARGS
;
1041 if( This
->sIcoPath
)
1042 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1043 if( This
->sProduct
)
1044 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1045 if( This
->sComponent
)
1046 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1048 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1049 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1050 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1052 /* write the Shortcut header */
1053 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1056 ERR("Write failed at %d\n",__LINE__
);
1060 TRACE("Writing pidl\n");
1062 /* write the PIDL to the shortcut */
1065 r
= ILSaveToStream( stm
, This
->pPidl
);
1068 ERR("Failed to write PIDL at %d\n",__LINE__
);
1074 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1076 if( This
->sDescription
)
1077 r
= Stream_WriteString( stm
, This
->sDescription
);
1079 if( This
->sPathRel
)
1080 r
= Stream_WriteString( stm
, This
->sPathRel
);
1082 if( This
->sWorkDir
)
1083 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1086 r
= Stream_WriteString( stm
, This
->sArgs
);
1088 if( This
->sIcoPath
)
1089 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1091 if( This
->sProduct
)
1092 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1094 if( This
->sComponent
)
1095 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1097 /* the last field is a single zero dword */
1099 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1104 /************************************************************************
1105 * IPersistStream_GetSizeMax (IPersistStream)
1107 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1108 IPersistStream
* iface
,
1109 ULARGE_INTEGER
* pcbSize
)
1111 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1113 TRACE("(%p)\n", This
);
1118 static const IPersistStreamVtbl psvt
=
1120 IPersistStream_fnQueryInterface
,
1121 IPersistStream_fnAddRef
,
1122 IPersistStream_fnRelease
,
1123 IPersistStream_fnGetClassID
,
1124 IPersistStream_fnIsDirty
,
1125 IPersistStream_fnLoad
,
1126 IPersistStream_fnSave
,
1127 IPersistStream_fnGetSizeMax
1130 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1132 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1137 /**************************************************************************
1138 * ShellLink_UpdatePath
1139 * update absolute path in sPath using relative path in sPathRel
1141 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1143 if (!path
|| !psPath
)
1144 return E_INVALIDARG
;
1146 if (!*psPath
&& sPathRel
) {
1147 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1148 LPWSTR final
= NULL
;
1150 /* first try if [directory of link file] + [relative path] finds an existing file */
1152 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1155 lstrcpyW(final
, sPathRel
);
1159 if (SHELL_ExistsFileW(buffer
)) {
1160 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1161 lstrcpyW(abs_path
, buffer
);
1163 /* try if [working directory] + [relative path] finds an existing file */
1165 lstrcpyW(buffer
, sWorkDir
);
1166 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1168 if (SHELL_ExistsFileW(buffer
))
1169 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1170 lstrcpyW(abs_path
, buffer
);
1174 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1176 lstrcpyW(abs_path
, sPathRel
);
1178 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1180 return E_OUTOFMEMORY
;
1182 lstrcpyW(*psPath
, abs_path
);
1188 /**************************************************************************
1189 * IShellLink_ConstructFromFile
1191 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1192 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1196 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1198 if (SUCCEEDED(hr
)) {
1203 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1205 if (SUCCEEDED(hr
)) {
1206 WCHAR path
[MAX_PATH
];
1208 if (SHGetPathFromIDListW(pidl
, path
))
1209 hr
= IPersistFile_Load(ppf
, path
, 0);
1214 *ppv
= (IUnknown
*)psl
;
1216 IPersistFile_Release(ppf
);
1220 IShellLinkW_Release(psl
);
1226 /**************************************************************************
1227 * IShellLinkA_QueryInterface
1229 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1231 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1232 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1235 /******************************************************************************
1236 * IShellLinkA_AddRef
1238 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1240 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1241 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1244 /******************************************************************************
1245 * IShellLinkA_Release
1247 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1249 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1250 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1253 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1254 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1256 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1258 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1259 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1261 if (This
->sComponent
|| This
->sProduct
)
1267 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1268 pszFile
, cchMaxPath
, NULL
, NULL
);
1270 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1275 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1277 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1278 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1281 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1283 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1284 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1287 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1290 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1292 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1296 if( This
->sDescription
)
1297 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1298 pszName
, cchMaxName
, NULL
, NULL
);
1303 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1305 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1309 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1313 descrW
= heap_strdupAtoW(pszName
);
1314 if (!descrW
) return E_OUTOFMEMORY
;
1319 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1320 HeapFree(GetProcessHeap(), 0, descrW
);
1325 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1328 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1330 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1334 if( This
->sWorkDir
)
1335 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1336 pszDir
, cchMaxPath
, NULL
, NULL
);
1341 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1343 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1347 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1349 dirW
= heap_strdupAtoW(pszDir
);
1350 if (!dirW
) return E_OUTOFMEMORY
;
1352 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1353 HeapFree(GetProcessHeap(), 0, dirW
);
1358 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1360 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1362 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1367 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1368 pszArgs
, cchMaxPath
, NULL
, NULL
);
1373 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1375 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1379 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1383 argsW
= heap_strdupAtoW(pszArgs
);
1384 if (!argsW
) return E_OUTOFMEMORY
;
1389 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1390 HeapFree(GetProcessHeap(), 0, argsW
);
1395 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1397 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1398 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1401 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1403 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1404 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1407 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1409 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1410 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1413 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1415 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1416 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1419 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1420 INT cchIconPath
, INT
*piIcon
)
1422 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1424 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1426 *piIcon
= This
->iIcoNdx
;
1429 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1436 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR pszIconPath
,
1439 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1443 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1445 pathW
= heap_strdupAtoW(pszIconPath
);
1446 if (!pathW
) return E_OUTOFMEMORY
;
1448 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, pathW
, iIcon
);
1449 HeapFree(GetProcessHeap(), 0, pathW
);
1454 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1457 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1461 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1463 pathW
= heap_strdupAtoW(pszPathRel
);
1464 if (!pathW
) return E_OUTOFMEMORY
;
1466 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1467 HeapFree(GetProcessHeap(), 0, pathW
);
1472 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1474 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1476 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1478 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1481 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1483 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1487 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1489 if (!pszFile
) return E_INVALIDARG
;
1491 str
= heap_strdupAtoW(pszFile
);
1493 return E_OUTOFMEMORY
;
1495 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1496 HeapFree( GetProcessHeap(), 0, str
);
1501 /**************************************************************************
1502 * IShellLink Implementation
1505 static const IShellLinkAVtbl slvt
=
1507 IShellLinkA_fnQueryInterface
,
1508 IShellLinkA_fnAddRef
,
1509 IShellLinkA_fnRelease
,
1510 IShellLinkA_fnGetPath
,
1511 IShellLinkA_fnGetIDList
,
1512 IShellLinkA_fnSetIDList
,
1513 IShellLinkA_fnGetDescription
,
1514 IShellLinkA_fnSetDescription
,
1515 IShellLinkA_fnGetWorkingDirectory
,
1516 IShellLinkA_fnSetWorkingDirectory
,
1517 IShellLinkA_fnGetArguments
,
1518 IShellLinkA_fnSetArguments
,
1519 IShellLinkA_fnGetHotkey
,
1520 IShellLinkA_fnSetHotkey
,
1521 IShellLinkA_fnGetShowCmd
,
1522 IShellLinkA_fnSetShowCmd
,
1523 IShellLinkA_fnGetIconLocation
,
1524 IShellLinkA_fnSetIconLocation
,
1525 IShellLinkA_fnSetRelativePath
,
1526 IShellLinkA_fnResolve
,
1527 IShellLinkA_fnSetPath
1531 /**************************************************************************
1532 * IShellLinkW_fnQueryInterface
1534 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1535 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1537 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1539 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1543 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1545 *ppvObj
= &This
->IShellLinkA_iface
;
1547 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1549 *ppvObj
= &This
->IShellLinkW_iface
;
1551 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1553 *ppvObj
= &This
->IPersistFile_iface
;
1555 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1557 *ppvObj
= &This
->IPersistStream_iface
;
1559 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1561 *ppvObj
= &This
->IShellLinkDataList_iface
;
1563 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1565 *ppvObj
= &This
->IShellExtInit_iface
;
1567 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1569 *ppvObj
= &This
->IContextMenu_iface
;
1571 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1573 *ppvObj
= &This
->IObjectWithSite_iface
;
1575 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1577 *ppvObj
= &This
->IPropertyStore_iface
;
1582 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1583 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1586 ERR("-- Interface: E_NOINTERFACE\n");
1587 return E_NOINTERFACE
;
1590 /******************************************************************************
1591 * IShellLinkW_fnAddRef
1593 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1595 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1596 ULONG ref
= InterlockedIncrement(&This
->ref
);
1598 TRACE("(%p)->(count=%u)\n", This
, ref
- 1);
1603 /******************************************************************************
1604 * IShellLinkW_fnRelease
1606 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1608 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1609 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1611 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
1616 TRACE("-- destroying IShellLink(%p)\n",This
);
1618 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1619 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1620 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1621 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1622 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1623 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1624 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
1625 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
1626 HeapFree(GetProcessHeap(), 0, This
->filepath
);
1629 IUnknown_Release( This
->site
);
1632 ILFree(This
->pPidl
);
1639 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1641 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1643 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1644 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1646 if (This
->sComponent
|| This
->sProduct
)
1652 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1654 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1659 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1661 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1663 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1670 *ppidl
= ILClone(This
->pPidl
);
1674 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1676 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1678 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1681 ILFree( This
->pPidl
);
1682 This
->pPidl
= ILClone( pidl
);
1686 This
->bDirty
= TRUE
;
1691 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1693 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1695 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1698 if( This
->sDescription
)
1699 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1704 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1706 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1708 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1710 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1713 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1714 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1715 if ( !This
->sDescription
)
1716 return E_OUTOFMEMORY
;
1718 lstrcpyW( This
->sDescription
, pszName
);
1721 This
->sDescription
= NULL
;
1722 This
->bDirty
= TRUE
;
1727 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1729 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1731 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1735 if( This
->sWorkDir
)
1736 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1741 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1743 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1745 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1747 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1748 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1749 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1750 if ( !This
->sWorkDir
)
1751 return E_OUTOFMEMORY
;
1752 lstrcpyW( This
->sWorkDir
, pszDir
);
1753 This
->bDirty
= TRUE
;
1758 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1760 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1762 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1767 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1772 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1774 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1776 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1778 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1781 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1782 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1784 return E_OUTOFMEMORY
;
1785 lstrcpyW( This
->sArgs
, pszArgs
);
1787 else This
->sArgs
= NULL
;
1789 This
->bDirty
= TRUE
;
1794 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1796 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1798 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1800 *pwHotkey
=This
->wHotKey
;
1805 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1807 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1809 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1811 This
->wHotKey
= wHotkey
;
1812 This
->bDirty
= TRUE
;
1817 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1819 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1821 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1823 *piShowCmd
= This
->iShowCmd
;
1828 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1830 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1832 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1834 This
->iShowCmd
= iShowCmd
;
1835 This
->bDirty
= TRUE
;
1840 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1842 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1844 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1846 *piIcon
= This
->iIcoNdx
;
1849 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1856 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1858 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1860 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1862 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1863 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1864 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1865 if ( !This
->sIcoPath
)
1866 return E_OUTOFMEMORY
;
1867 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1869 This
->iIcoNdx
= iIcon
;
1870 This
->bDirty
= TRUE
;
1875 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1877 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1879 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1881 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1882 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1883 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1884 if ( !This
->sPathRel
)
1885 return E_OUTOFMEMORY
;
1886 lstrcpyW( This
->sPathRel
, pszPathRel
);
1887 This
->bDirty
= TRUE
;
1889 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1892 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1897 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1899 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1901 /*FIXME: use IResolveShellLink interface */
1903 if (!This
->sPath
&& This
->pPidl
) {
1904 WCHAR buffer
[MAX_PATH
];
1906 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1908 if (bSuccess
&& *buffer
) {
1909 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1911 return E_OUTOFMEMORY
;
1913 lstrcpyW(This
->sPath
, buffer
);
1915 This
->bDirty
= TRUE
;
1917 hr
= S_OK
; /* don't report an error occurred while just caching information */
1920 if (!This
->sIcoPath
&& This
->sPath
) {
1921 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1922 if (!This
->sIcoPath
)
1923 return E_OUTOFMEMORY
;
1925 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1928 This
->bDirty
= TRUE
;
1934 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
1943 p
= strchrW( str
, ':' );
1947 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
1950 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
1955 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
1957 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
1965 /* each segment must start with two colons */
1966 if( str
[0] != ':' || str
[1] != ':' )
1969 /* the last segment is just two colons */
1974 /* there must be a colon straight after a guid */
1975 p
= strchrW( str
, ':' );
1982 /* get the guid, and check it's validly formatted */
1983 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
1985 r
= CLSIDFromString( szGuid
, &guid
);
1990 /* match it up to a guid that we care about */
1991 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
1993 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
1998 /* skip to the next field */
1999 str
= strchrW( str
, ':' );
2004 /* we have to have a component for an advertised shortcut */
2008 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2009 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2011 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2012 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2017 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2019 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2020 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2023 volume
->type
= GetDriveTypeW(drive
);
2024 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2025 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2026 TRACE("r = %d type %d serial %08x name %s\n", r
,
2027 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2031 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2033 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2034 WCHAR buffer
[MAX_PATH
];
2035 LPWSTR fname
, unquoted
= NULL
;
2039 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2041 if (!pszFile
) return E_INVALIDARG
;
2043 /* quotes at the ends of the string are stripped */
2044 len
= lstrlenW(pszFile
);
2045 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2047 unquoted
= strdupW(pszFile
);
2048 PathUnquoteSpacesW(unquoted
);
2052 /* any other quote marks are invalid */
2053 if (strchrW(pszFile
, '"'))
2055 HeapFree(GetProcessHeap(), 0, unquoted
);
2059 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2062 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2063 This
->sComponent
= NULL
;
2066 ILFree(This
->pPidl
);
2069 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2071 if (*pszFile
== '\0')
2073 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2075 else if(!PathFileExistsW(buffer
) &&
2076 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2079 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2080 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2082 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2083 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2086 HeapFree(GetProcessHeap(), 0, unquoted
);
2087 return E_OUTOFMEMORY
;
2090 lstrcpyW(This
->sPath
, buffer
);
2092 This
->bDirty
= TRUE
;
2093 HeapFree(GetProcessHeap(), 0, unquoted
);
2098 /**************************************************************************
2099 * IShellLinkW Implementation
2102 static const IShellLinkWVtbl slvtw
=
2104 IShellLinkW_fnQueryInterface
,
2105 IShellLinkW_fnAddRef
,
2106 IShellLinkW_fnRelease
,
2107 IShellLinkW_fnGetPath
,
2108 IShellLinkW_fnGetIDList
,
2109 IShellLinkW_fnSetIDList
,
2110 IShellLinkW_fnGetDescription
,
2111 IShellLinkW_fnSetDescription
,
2112 IShellLinkW_fnGetWorkingDirectory
,
2113 IShellLinkW_fnSetWorkingDirectory
,
2114 IShellLinkW_fnGetArguments
,
2115 IShellLinkW_fnSetArguments
,
2116 IShellLinkW_fnGetHotkey
,
2117 IShellLinkW_fnSetHotkey
,
2118 IShellLinkW_fnGetShowCmd
,
2119 IShellLinkW_fnSetShowCmd
,
2120 IShellLinkW_fnGetIconLocation
,
2121 IShellLinkW_fnSetIconLocation
,
2122 IShellLinkW_fnSetRelativePath
,
2123 IShellLinkW_fnResolve
,
2124 IShellLinkW_fnSetPath
2127 static HRESULT WINAPI
2128 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2130 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2131 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2135 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2137 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2138 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2142 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2144 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2145 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2148 static HRESULT WINAPI
2149 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2151 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2155 static HRESULT WINAPI
2156 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2158 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2159 LPVOID block
= NULL
;
2162 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2166 case EXP_DARWIN_ID_SIG
:
2167 if (!This
->sComponent
)
2169 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2172 case EXP_SZ_LINK_SIG
:
2173 case NT_CONSOLE_PROPS_SIG
:
2174 case NT_FE_CONSOLE_PROPS_SIG
:
2175 case EXP_SPECIAL_FOLDER_SIG
:
2176 case EXP_SZ_ICON_SIG
:
2177 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2180 ERR("unknown datablock %08x\n", dwSig
);
2182 *ppDataBlock
= block
;
2186 static HRESULT WINAPI
2187 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2189 FIXME("(%p)->(%u): stub\n", iface
, dwSig
);
2193 static HRESULT WINAPI
2194 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2196 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2199 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2201 /* FIXME: add more */
2203 flags
|= SLDF_HAS_ARGS
;
2204 if (This
->sComponent
)
2205 flags
|= SLDF_HAS_DARWINID
;
2207 flags
|= SLDF_HAS_ICONLOCATION
;
2209 flags
|= SLDF_HAS_LOGO3ID
;
2211 flags
|= SLDF_HAS_ID_LIST
;
2218 static HRESULT WINAPI
2219 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2221 FIXME("(%p)->(%u): stub\n", iface
, dwFlags
);
2225 static const IShellLinkDataListVtbl dlvt
=
2227 ShellLink_DataList_QueryInterface
,
2228 ShellLink_DataList_AddRef
,
2229 ShellLink_DataList_Release
,
2230 ShellLink_AddDataBlock
,
2231 ShellLink_CopyDataBlock
,
2232 ShellLink_RemoveDataBlock
,
2237 static HRESULT WINAPI
2238 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2240 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2241 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2245 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2247 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2248 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2252 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2254 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2255 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2258 /**************************************************************************
2259 * ShellLink implementation of IShellExtInit::Initialize()
2261 * Loads the shelllink from the dataobject the shell is pointing to.
2263 static HRESULT WINAPI
2264 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2265 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2267 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2273 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2278 format
.cfFormat
= CF_HDROP
;
2280 format
.dwAspect
= DVASPECT_CONTENT
;
2282 format
.tymed
= TYMED_HGLOBAL
;
2284 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2287 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2292 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2294 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2297 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2299 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2300 r
= IPersistFile_Load( pf
, path
, 0 );
2301 HeapFree( GetProcessHeap(), 0, path
);
2304 ReleaseStgMedium( &stgm
);
2309 static const IShellExtInitVtbl eivt
=
2311 ShellLink_ExtInit_QueryInterface
,
2312 ShellLink_ExtInit_AddRef
,
2313 ShellLink_ExtInit_Release
,
2314 ShellLink_ExtInit_Initialize
2317 static HRESULT WINAPI
2318 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2320 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2321 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2325 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2327 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2328 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2332 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2334 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2335 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2338 static HRESULT WINAPI
2339 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2340 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2342 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2343 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2347 TRACE("%p %p %u %u %u %u\n", This
,
2348 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2351 return E_INVALIDARG
;
2353 memset( &mii
, 0, sizeof mii
);
2354 mii
.cbSize
= sizeof mii
;
2355 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2356 mii
.dwTypeData
= szOpen
;
2357 mii
.cch
= strlenW( mii
.dwTypeData
);
2358 mii
.wID
= idCmdFirst
+ id
++;
2359 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2360 mii
.fType
= MFT_STRING
;
2361 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2365 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2369 shelllink_get_msi_component_path( LPWSTR component
)
2374 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2375 if (r
!= ERROR_SUCCESS
)
2379 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2380 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2381 if (r
!= ERROR_SUCCESS
)
2383 HeapFree( GetProcessHeap(), 0, path
);
2387 TRACE("returning %s\n", debugstr_w( path
) );
2392 static HRESULT WINAPI
2393 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2395 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2396 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2397 SHELLEXECUTEINFOW sei
;
2398 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2403 TRACE("%p %p\n", This
, lpici
);
2405 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2406 return E_INVALIDARG
;
2408 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2410 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2411 return E_INVALIDARG
;
2414 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2418 if ( This
->sComponent
)
2420 path
= shelllink_get_msi_component_path( This
->sComponent
);
2425 path
= strdupW( This
->sPath
);
2427 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2428 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2430 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2434 len
+= lstrlenW( This
->sArgs
);
2435 if ( iciex
->lpParametersW
)
2436 len
+= lstrlenW( iciex
->lpParametersW
);
2438 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2441 lstrcatW( args
, This
->sArgs
);
2442 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2444 static const WCHAR space
[] = { ' ', 0 };
2445 lstrcatW( args
, space
);
2446 lstrcatW( args
, iciex
->lpParametersW
);
2450 memset( &sei
, 0, sizeof sei
);
2451 sei
.cbSize
= sizeof sei
;
2452 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2454 sei
.nShow
= This
->iShowCmd
;
2455 sei
.lpIDList
= This
->pPidl
;
2456 sei
.lpDirectory
= This
->sWorkDir
;
2457 sei
.lpParameters
= args
;
2458 sei
.lpVerb
= szOpen
;
2460 if( ShellExecuteExW( &sei
) )
2465 HeapFree( GetProcessHeap(), 0, args
);
2466 HeapFree( GetProcessHeap(), 0, path
);
2471 static HRESULT WINAPI
2472 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2473 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2475 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2477 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This
,
2478 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2483 static const IContextMenuVtbl cmvt
=
2485 ShellLink_ContextMenu_QueryInterface
,
2486 ShellLink_ContextMenu_AddRef
,
2487 ShellLink_ContextMenu_Release
,
2488 ShellLink_QueryContextMenu
,
2489 ShellLink_InvokeCommand
,
2490 ShellLink_GetCommandString
2493 static HRESULT WINAPI
2494 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2496 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2497 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2501 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2503 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2504 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2508 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2510 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2511 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2514 static HRESULT WINAPI
2515 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2517 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2519 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2523 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2526 static HRESULT WINAPI
2527 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2529 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2531 TRACE("%p %p\n", iface
, punk
);
2534 IUnknown_AddRef( punk
);
2537 IUnknown_Release( This
->site
);
2544 static const IObjectWithSiteVtbl owsvt
=
2546 ShellLink_ObjectWithSite_QueryInterface
,
2547 ShellLink_ObjectWithSite_AddRef
,
2548 ShellLink_ObjectWithSite_Release
,
2553 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2555 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2556 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2559 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2561 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2562 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2565 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2567 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2568 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2571 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2573 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2574 FIXME("(%p)->(%p): stub\n", This
, props
);
2578 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2580 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2581 FIXME("(%p)->(%d %p): stub\n", This
, propid
, key
);
2585 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2587 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2588 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2592 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2594 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2595 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2599 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2601 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2602 FIXME("(%p): stub\n", This
);
2606 static const IPropertyStoreVtbl propertystorevtbl
= {
2607 propertystore_QueryInterface
,
2608 propertystore_AddRef
,
2609 propertystore_Release
,
2610 propertystore_GetCount
,
2611 propertystore_GetAt
,
2612 propertystore_GetValue
,
2613 propertystore_SetValue
,
2614 propertystore_Commit
2617 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2619 IShellLinkImpl
* sl
;
2622 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2627 return CLASS_E_NOAGGREGATION
;
2629 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2631 return E_OUTOFMEMORY
;
2634 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2635 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2636 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2637 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2638 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2639 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2640 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2641 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2642 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2643 sl
->iShowCmd
= SW_SHOWNORMAL
;
2647 sl
->filepath
= NULL
;
2649 TRACE("(%p)\n", sl
);
2651 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2652 IShellLinkW_Release( &sl
->IShellLinkW_iface
);