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 static inline LPWSTR
strdupW( LPCWSTR src
)
221 if (!src
) return NULL
;
222 dest
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(src
)+1)*sizeof(WCHAR
) );
228 /**************************************************************************
229 * IPersistFile_QueryInterface
231 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
236 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
237 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
240 /******************************************************************************
241 * IPersistFile_AddRef
243 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
245 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
246 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
249 /******************************************************************************
250 * IPersistFile_Release
252 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
254 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
255 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
258 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
260 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
262 TRACE("(%p)->(%p)\n", This
, pClassID
);
264 *pClassID
= CLSID_ShellLink
;
269 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
271 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
273 TRACE("(%p)\n",This
);
281 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
283 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
284 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
288 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
291 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
292 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
295 r
= IPersistStream_Load(StreamThis
, stm
);
296 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
297 IStream_Release( stm
);
299 /* update file path */
300 HeapFree(GetProcessHeap(), 0, This
->filepath
);
301 This
->filepath
= strdupW(pszFileName
);
303 This
->bDirty
= FALSE
;
305 TRACE("-- returning hr %08x\n", r
);
309 BOOL
run_winemenubuilder( const WCHAR
*args
)
311 static const WCHAR menubuilder
[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
315 PROCESS_INFORMATION pi
;
320 GetSystemDirectoryW( app
, MAX_PATH
- sizeof(menubuilder
)/sizeof(WCHAR
) );
321 strcatW( app
, menubuilder
);
323 len
= (strlenW( app
) + strlenW( args
) + 1) * sizeof(WCHAR
);
324 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
328 strcpyW( buffer
, app
);
329 strcatW( buffer
, args
);
331 TRACE("starting %s\n",debugstr_w(buffer
));
333 memset(&si
, 0, sizeof(si
));
336 Wow64DisableWow64FsRedirection( &redir
);
337 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
338 Wow64RevertWow64FsRedirection( redir
);
340 HeapFree( GetProcessHeap(), 0, buffer
);
344 CloseHandle( pi
.hProcess
);
345 CloseHandle( pi
.hThread
);
351 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
353 static const WCHAR szFormat
[] = {' ','-','w',' ','"','%','s','"',0 };
358 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
359 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
363 wsprintfW( buffer
, szFormat
, szLink
);
364 ret
= run_winemenubuilder( buffer
);
365 HeapFree( GetProcessHeap(), 0, buffer
);
369 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
371 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
372 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
376 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
381 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
384 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
385 IStream_Release( stm
);
389 StartLinkProcessor( pszFileName
);
391 /* update file path */
392 HeapFree(GetProcessHeap(), 0, This
->filepath
);
393 This
->filepath
= strdupW(pszFileName
);
395 This
->bDirty
= FALSE
;
399 DeleteFileW( pszFileName
);
400 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
407 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
409 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
410 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
414 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
416 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
419 TRACE("(%p)->(%p)\n", This
, filename
);
427 SHGetMalloc(&pMalloc
);
428 *filename
= IMalloc_Alloc(pMalloc
, (strlenW(This
->filepath
)+1)*sizeof(WCHAR
));
429 if (!*filename
) return E_OUTOFMEMORY
;
431 strcpyW(*filename
, This
->filepath
);
436 static const IPersistFileVtbl pfvt
=
438 IPersistFile_fnQueryInterface
,
439 IPersistFile_fnAddRef
,
440 IPersistFile_fnRelease
,
441 IPersistFile_fnGetClassID
,
442 IPersistFile_fnIsDirty
,
445 IPersistFile_fnSaveCompleted
,
446 IPersistFile_fnGetCurFile
449 /************************************************************************
450 * IPersistStream_QueryInterface
452 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
453 IPersistStream
* iface
,
457 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
458 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
461 /************************************************************************
462 * IPersistStream_Release
464 static ULONG WINAPI
IPersistStream_fnRelease(
465 IPersistStream
* iface
)
467 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
468 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
471 /************************************************************************
472 * IPersistStream_AddRef
474 static ULONG WINAPI
IPersistStream_fnAddRef(
475 IPersistStream
* iface
)
477 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
478 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
481 /************************************************************************
482 * IPersistStream_GetClassID
485 static HRESULT WINAPI
IPersistStream_fnGetClassID(
486 IPersistStream
* iface
,
489 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
490 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
493 /************************************************************************
494 * IPersistStream_IsDirty (IPersistStream)
496 static HRESULT WINAPI
IPersistStream_fnIsDirty(
497 IPersistStream
* iface
)
499 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
501 TRACE("(%p)\n", This
);
507 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
518 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
519 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
523 len
*= sizeof (WCHAR
);
525 TRACE("reading %d\n", len
);
526 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
528 return E_OUTOFMEMORY
;
530 r
= IStream_Read(stm
, temp
, len
, &count
);
531 if( FAILED (r
) || ( count
!= len
) )
533 HeapFree( GetProcessHeap(), 0, temp
);
537 TRACE("read %s\n", debugstr_an(temp
,len
));
539 /* convert to unicode if necessary */
542 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
543 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
546 HeapFree( GetProcessHeap(), 0, temp
);
547 return E_OUTOFMEMORY
;
549 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
550 HeapFree( GetProcessHeap(), 0, temp
);
564 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
571 unsigned char data
[1];
576 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
577 if( FAILED( r
) || count
!= sizeof(size
) )
580 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
582 return E_OUTOFMEMORY
;
585 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
586 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
588 HeapFree( GetProcessHeap(), 0, chunk
);
592 TRACE("Read %d bytes\n",chunk
->size
);
599 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
601 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
605 volume
->serial
= vol
->dwVolSerial
;
606 volume
->type
= vol
->dwType
;
608 if( !vol
->dwVolLabelOfs
)
610 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
612 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
615 label
+= vol
->dwVolLabelOfs
;
616 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
621 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
626 while( p
[len
] && (len
< maxlen
) )
629 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
630 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
631 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
637 static HRESULT
Stream_LoadLocation( IStream
*stm
,
638 volume_info
*volume
, LPWSTR
*path
)
645 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
649 loc
= (LOCATION_INFO
*) p
;
650 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
652 HeapFree( GetProcessHeap(), 0, p
);
656 /* if there's valid local volume information, load it */
657 if( loc
->dwVolTableOfs
&&
658 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
660 LOCAL_VOLUME_INFO
*volume_info
;
662 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
663 Stream_LoadVolume( volume_info
, volume
);
666 /* if there's a local path, load it */
667 n
= loc
->dwLocalPathOfs
;
668 if( n
&& (n
< loc
->dwTotalSize
) )
669 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
671 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
672 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
674 HeapFree( GetProcessHeap(), 0, p
);
679 * The format of the advertised shortcut info seems to be:
684 * 0 Length of the block (4 bytes, usually 0x314)
686 * 8 string data in ASCII
687 * 8+0x104 string data in UNICODE
689 * In the original Win32 implementation the buffers are not initialized
690 * to zero, so data trailing the string is random garbage.
692 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
697 EXP_DARWIN_LINK buffer
;
701 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
705 /* make sure that we read the size of the structure even on error */
706 size
= sizeof buffer
- sizeof (DWORD
);
707 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
709 ERR("Ooops. This structure is not as expected...\n");
713 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
720 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
722 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
724 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
728 *str
= HeapAlloc( GetProcessHeap(), 0,
729 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
730 lstrcpyW( *str
, buffer
.szwDarwinID
);
735 /************************************************************************
736 * IPersistStream_Load (IPersistStream)
738 static HRESULT WINAPI
IPersistStream_fnLoad(
739 IPersistStream
* iface
,
748 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
750 TRACE("%p %p\n", This
, stm
);
753 return STG_E_INVALIDPOINTER
;
756 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
760 if( dwBytesRead
!= sizeof(hdr
))
762 if( hdr
.dwSize
!= sizeof(hdr
))
764 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
767 /* free all the old stuff */
770 memset( &This
->volume
, 0, sizeof This
->volume
);
771 HeapFree(GetProcessHeap(), 0, This
->sPath
);
773 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
774 This
->sDescription
= NULL
;
775 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
776 This
->sPathRel
= NULL
;
777 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
778 This
->sWorkDir
= NULL
;
779 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
781 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
782 This
->sIcoPath
= NULL
;
783 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
784 This
->sProduct
= NULL
;
785 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
786 This
->sComponent
= NULL
;
788 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
789 This
->iIcoNdx
= hdr
.nIcon
;
790 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
791 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
792 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
795 WCHAR sTemp
[MAX_PATH
];
796 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
797 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
798 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
799 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
800 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
801 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
802 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
803 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
804 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
807 /* load all the new stuff */
808 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
810 r
= ILLoadFromStream( stm
, &This
->pPidl
);
816 /* load the location information */
817 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
818 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
822 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
823 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
825 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
826 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
831 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
833 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
834 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
839 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
841 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
842 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
847 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
849 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
850 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
855 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
857 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
858 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
863 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
865 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
866 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
871 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
873 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
874 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
879 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
880 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
882 /* Some lnk files have extra data blocks starting with a
883 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
884 * one with a 0xa0000003 signature. However these don't seem to matter
887 WARN("Last word was not zero\n");
899 /************************************************************************
902 * Helper function for IPersistStream_Save. Writes a unicode string
903 * with terminating nul byte to a stream, preceded by the its length.
905 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
907 USHORT len
= lstrlenW( str
) + 1;
911 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
915 len
*= sizeof(WCHAR
);
917 r
= IStream_Write( stm
, str
, len
, &count
);
924 /************************************************************************
925 * Stream_WriteLocationInfo
927 * Writes the location info to a stream
929 * FIXME: One day we might want to write the network volume information
930 * and the final path.
931 * Figure out how Windows deals with unicode paths here.
933 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
934 volume_info
*volume
)
936 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
937 LOCAL_VOLUME_INFO
*vol
;
939 LPSTR szLabel
, szPath
, szFinalPath
;
943 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
945 /* figure out the size of everything */
946 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
947 NULL
, 0, NULL
, NULL
);
948 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
949 NULL
, 0, NULL
, NULL
);
950 volume_info_size
= sizeof *vol
+ label_size
;
952 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
954 /* create pointers to everything */
955 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
956 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
957 szLabel
= (LPSTR
) &vol
[1];
958 szPath
= &szLabel
[label_size
];
959 szFinalPath
= &szPath
[path_size
];
961 /* fill in the location information header */
962 loc
->dwTotalSize
= total_size
;
963 loc
->dwHeaderSize
= sizeof (*loc
);
965 loc
->dwVolTableOfs
= sizeof (*loc
);
966 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
967 loc
->dwNetworkVolTableOfs
= 0;
968 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
970 /* fill in the volume information */
971 vol
->dwSize
= volume_info_size
;
972 vol
->dwType
= volume
->type
;
973 vol
->dwVolSerial
= volume
->serial
;
974 vol
->dwVolLabelOfs
= sizeof (*vol
);
976 /* copy in the strings */
977 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
978 szLabel
, label_size
, NULL
, NULL
);
979 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
980 szPath
, path_size
, NULL
, NULL
);
983 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
984 HeapFree(GetProcessHeap(), 0, loc
);
989 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
991 EXP_DARWIN_LINK
*buffer
;
993 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
994 buffer
->dbh
.cbSize
= sizeof *buffer
;
995 buffer
->dbh
.dwSignature
= magic
;
996 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
997 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
1002 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
1004 EXP_DARWIN_LINK
*buffer
;
1009 buffer
= shelllink_build_darwinid( string
, magic
);
1011 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1014 /************************************************************************
1015 * IPersistStream_Save (IPersistStream)
1017 * FIXME: makes assumptions about byte order
1019 static HRESULT WINAPI
IPersistStream_fnSave(
1020 IPersistStream
* iface
,
1029 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1031 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1033 memset(&header
, 0, sizeof(header
));
1034 header
.dwSize
= sizeof(header
);
1035 header
.fStartup
= This
->iShowCmd
;
1036 header
.MagicGuid
= CLSID_ShellLink
;
1038 header
.wHotKey
= This
->wHotKey
;
1039 header
.nIcon
= This
->iIcoNdx
;
1040 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1042 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1044 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1045 if( This
->sDescription
)
1046 header
.dwFlags
|= SLDF_HAS_NAME
;
1047 if( This
->sWorkDir
)
1048 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1050 header
.dwFlags
|= SLDF_HAS_ARGS
;
1051 if( This
->sIcoPath
)
1052 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1053 if( This
->sProduct
)
1054 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1055 if( This
->sComponent
)
1056 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1058 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1059 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1060 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1062 /* write the Shortcut header */
1063 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1066 ERR("Write failed at %d\n",__LINE__
);
1070 TRACE("Writing pidl\n");
1072 /* write the PIDL to the shortcut */
1075 r
= ILSaveToStream( stm
, This
->pPidl
);
1078 ERR("Failed to write PIDL at %d\n",__LINE__
);
1084 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1086 if( This
->sDescription
)
1087 r
= Stream_WriteString( stm
, This
->sDescription
);
1089 if( This
->sPathRel
)
1090 r
= Stream_WriteString( stm
, This
->sPathRel
);
1092 if( This
->sWorkDir
)
1093 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1096 r
= Stream_WriteString( stm
, This
->sArgs
);
1098 if( This
->sIcoPath
)
1099 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1101 if( This
->sProduct
)
1102 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1104 if( This
->sComponent
)
1105 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1107 /* the last field is a single zero dword */
1109 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1114 /************************************************************************
1115 * IPersistStream_GetSizeMax (IPersistStream)
1117 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1118 IPersistStream
* iface
,
1119 ULARGE_INTEGER
* pcbSize
)
1121 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1123 TRACE("(%p)\n", This
);
1128 static const IPersistStreamVtbl psvt
=
1130 IPersistStream_fnQueryInterface
,
1131 IPersistStream_fnAddRef
,
1132 IPersistStream_fnRelease
,
1133 IPersistStream_fnGetClassID
,
1134 IPersistStream_fnIsDirty
,
1135 IPersistStream_fnLoad
,
1136 IPersistStream_fnSave
,
1137 IPersistStream_fnGetSizeMax
1140 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1142 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1147 /**************************************************************************
1148 * ShellLink_UpdatePath
1149 * update absolute path in sPath using relative path in sPathRel
1151 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1153 if (!path
|| !psPath
)
1154 return E_INVALIDARG
;
1156 if (!*psPath
&& sPathRel
) {
1157 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1158 LPWSTR final
= NULL
;
1160 /* first try if [directory of link file] + [relative path] finds an existing file */
1162 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1165 lstrcpyW(final
, sPathRel
);
1169 if (SHELL_ExistsFileW(buffer
)) {
1170 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1171 lstrcpyW(abs_path
, buffer
);
1173 /* try if [working directory] + [relative path] finds an existing file */
1175 lstrcpyW(buffer
, sWorkDir
);
1176 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1178 if (SHELL_ExistsFileW(buffer
))
1179 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1180 lstrcpyW(abs_path
, buffer
);
1184 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1186 lstrcpyW(abs_path
, sPathRel
);
1188 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1190 return E_OUTOFMEMORY
;
1192 lstrcpyW(*psPath
, abs_path
);
1198 /**************************************************************************
1199 * IShellLink_ConstructFromFile
1201 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1202 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1206 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1208 if (SUCCEEDED(hr
)) {
1213 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1215 if (SUCCEEDED(hr
)) {
1216 WCHAR path
[MAX_PATH
];
1218 if (SHGetPathFromIDListW(pidl
, path
))
1219 hr
= IPersistFile_Load(ppf
, path
, 0);
1224 *ppv
= (IUnknown
*)psl
;
1226 IPersistFile_Release(ppf
);
1230 IShellLinkW_Release(psl
);
1236 /**************************************************************************
1237 * IShellLinkA_QueryInterface
1239 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1241 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1242 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObj
);
1245 /******************************************************************************
1246 * IShellLinkA_AddRef
1248 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1250 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1251 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1254 /******************************************************************************
1255 * IShellLinkA_Release
1257 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1259 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1260 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1263 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1264 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1266 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1268 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1269 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1271 if (This
->sComponent
|| This
->sProduct
)
1277 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1278 pszFile
, cchMaxPath
, NULL
, NULL
);
1280 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1285 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1287 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1288 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1291 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1293 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1294 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1297 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1300 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1302 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1306 if( This
->sDescription
)
1307 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1308 pszName
, cchMaxName
, NULL
, NULL
);
1313 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1315 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1319 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1323 descrW
= heap_strdupAtoW(pszName
);
1324 if (!descrW
) return E_OUTOFMEMORY
;
1329 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1330 HeapFree(GetProcessHeap(), 0, descrW
);
1335 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1338 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1340 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1344 if( This
->sWorkDir
)
1345 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1346 pszDir
, cchMaxPath
, NULL
, NULL
);
1351 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1353 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1357 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1359 dirW
= heap_strdupAtoW(pszDir
);
1360 if (!dirW
) return E_OUTOFMEMORY
;
1362 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1363 HeapFree(GetProcessHeap(), 0, dirW
);
1368 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1370 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1372 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1377 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1378 pszArgs
, cchMaxPath
, NULL
, NULL
);
1383 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1385 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1389 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1393 argsW
= heap_strdupAtoW(pszArgs
);
1394 if (!argsW
) return E_OUTOFMEMORY
;
1399 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1400 HeapFree(GetProcessHeap(), 0, argsW
);
1405 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1407 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1408 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1411 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1413 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1414 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1417 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1419 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1420 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1423 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1425 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1426 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1429 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1430 INT cchIconPath
, INT
*piIcon
)
1432 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1434 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1436 *piIcon
= This
->iIcoNdx
;
1439 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1446 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR pszIconPath
,
1449 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1453 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1455 pathW
= heap_strdupAtoW(pszIconPath
);
1456 if (!pathW
) return E_OUTOFMEMORY
;
1458 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, pathW
, iIcon
);
1459 HeapFree(GetProcessHeap(), 0, pathW
);
1464 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1467 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1471 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1473 pathW
= heap_strdupAtoW(pszPathRel
);
1474 if (!pathW
) return E_OUTOFMEMORY
;
1476 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1477 HeapFree(GetProcessHeap(), 0, pathW
);
1482 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1484 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1486 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1488 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1491 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1493 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1497 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1499 if (!pszFile
) return E_INVALIDARG
;
1501 str
= heap_strdupAtoW(pszFile
);
1503 return E_OUTOFMEMORY
;
1505 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1506 HeapFree( GetProcessHeap(), 0, str
);
1511 /**************************************************************************
1512 * IShellLink Implementation
1515 static const IShellLinkAVtbl slvt
=
1517 IShellLinkA_fnQueryInterface
,
1518 IShellLinkA_fnAddRef
,
1519 IShellLinkA_fnRelease
,
1520 IShellLinkA_fnGetPath
,
1521 IShellLinkA_fnGetIDList
,
1522 IShellLinkA_fnSetIDList
,
1523 IShellLinkA_fnGetDescription
,
1524 IShellLinkA_fnSetDescription
,
1525 IShellLinkA_fnGetWorkingDirectory
,
1526 IShellLinkA_fnSetWorkingDirectory
,
1527 IShellLinkA_fnGetArguments
,
1528 IShellLinkA_fnSetArguments
,
1529 IShellLinkA_fnGetHotkey
,
1530 IShellLinkA_fnSetHotkey
,
1531 IShellLinkA_fnGetShowCmd
,
1532 IShellLinkA_fnSetShowCmd
,
1533 IShellLinkA_fnGetIconLocation
,
1534 IShellLinkA_fnSetIconLocation
,
1535 IShellLinkA_fnSetRelativePath
,
1536 IShellLinkA_fnResolve
,
1537 IShellLinkA_fnSetPath
1541 /**************************************************************************
1542 * IShellLinkW_fnQueryInterface
1544 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1545 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1547 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1549 TRACE("(%p)->(%s)\n", This
, debugstr_guid(riid
));
1553 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
1555 *ppvObj
= &This
->IShellLinkA_iface
;
1557 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
1559 *ppvObj
= &This
->IShellLinkW_iface
;
1561 else if(IsEqualIID(riid
, &IID_IPersistFile
))
1563 *ppvObj
= &This
->IPersistFile_iface
;
1565 else if(IsEqualIID(riid
, &IID_IPersistStream
))
1567 *ppvObj
= &This
->IPersistStream_iface
;
1569 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
1571 *ppvObj
= &This
->IShellLinkDataList_iface
;
1573 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
1575 *ppvObj
= &This
->IShellExtInit_iface
;
1577 else if(IsEqualIID(riid
, &IID_IContextMenu
))
1579 *ppvObj
= &This
->IContextMenu_iface
;
1581 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
1583 *ppvObj
= &This
->IObjectWithSite_iface
;
1585 else if(IsEqualIID(riid
, &IID_IPropertyStore
))
1587 *ppvObj
= &This
->IPropertyStore_iface
;
1592 IUnknown_AddRef((IUnknown
*)*ppvObj
);
1593 TRACE("-- Interface: (%p)->(%p)\n", ppvObj
, *ppvObj
);
1596 ERR("-- Interface: E_NOINTERFACE\n");
1597 return E_NOINTERFACE
;
1600 /******************************************************************************
1601 * IShellLinkW_fnAddRef
1603 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1605 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1606 ULONG ref
= InterlockedIncrement(&This
->ref
);
1608 TRACE("(%p)->(count=%u)\n", This
, ref
- 1);
1613 /******************************************************************************
1614 * IShellLinkW_fnRelease
1616 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1618 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1619 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1621 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
1626 TRACE("-- destroying IShellLink(%p)\n",This
);
1628 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1629 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1630 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1631 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1632 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1633 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1634 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
1635 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
1636 HeapFree(GetProcessHeap(), 0, This
->filepath
);
1639 IUnknown_Release( This
->site
);
1642 ILFree(This
->pPidl
);
1649 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1651 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1653 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1654 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1656 if (This
->sComponent
|| This
->sProduct
)
1662 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1664 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1669 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1671 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1673 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1680 *ppidl
= ILClone(This
->pPidl
);
1684 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1686 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1688 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1691 ILFree( This
->pPidl
);
1692 This
->pPidl
= ILClone( pidl
);
1696 This
->bDirty
= TRUE
;
1701 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1703 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1705 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1708 if( This
->sDescription
)
1709 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1714 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1716 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1718 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1720 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1723 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1724 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1725 if ( !This
->sDescription
)
1726 return E_OUTOFMEMORY
;
1728 lstrcpyW( This
->sDescription
, pszName
);
1731 This
->sDescription
= NULL
;
1732 This
->bDirty
= TRUE
;
1737 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1739 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1741 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1745 if( This
->sWorkDir
)
1746 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1751 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1753 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1755 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1757 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1758 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1759 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1760 if ( !This
->sWorkDir
)
1761 return E_OUTOFMEMORY
;
1762 lstrcpyW( This
->sWorkDir
, pszDir
);
1763 This
->bDirty
= TRUE
;
1768 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1770 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1772 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1777 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1782 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1784 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1786 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1788 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1791 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1792 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1794 return E_OUTOFMEMORY
;
1795 lstrcpyW( This
->sArgs
, pszArgs
);
1797 else This
->sArgs
= NULL
;
1799 This
->bDirty
= TRUE
;
1804 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1806 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1808 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1810 *pwHotkey
=This
->wHotKey
;
1815 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1817 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1819 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1821 This
->wHotKey
= wHotkey
;
1822 This
->bDirty
= TRUE
;
1827 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1829 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1831 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1833 *piShowCmd
= This
->iShowCmd
;
1838 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1840 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1842 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1844 This
->iShowCmd
= iShowCmd
;
1845 This
->bDirty
= TRUE
;
1850 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1852 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1854 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1856 *piIcon
= This
->iIcoNdx
;
1859 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1866 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1868 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1870 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1872 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1873 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1874 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1875 if ( !This
->sIcoPath
)
1876 return E_OUTOFMEMORY
;
1877 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1879 This
->iIcoNdx
= iIcon
;
1880 This
->bDirty
= TRUE
;
1885 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1887 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1889 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1891 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1892 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1893 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1894 if ( !This
->sPathRel
)
1895 return E_OUTOFMEMORY
;
1896 lstrcpyW( This
->sPathRel
, pszPathRel
);
1897 This
->bDirty
= TRUE
;
1899 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1902 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1907 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1909 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1911 /*FIXME: use IResolveShellLink interface */
1913 if (!This
->sPath
&& This
->pPidl
) {
1914 WCHAR buffer
[MAX_PATH
];
1916 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1918 if (bSuccess
&& *buffer
) {
1919 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1921 return E_OUTOFMEMORY
;
1923 lstrcpyW(This
->sPath
, buffer
);
1925 This
->bDirty
= TRUE
;
1927 hr
= S_OK
; /* don't report an error occurred while just caching information */
1930 if (!This
->sIcoPath
&& This
->sPath
) {
1931 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1932 if (!This
->sIcoPath
)
1933 return E_OUTOFMEMORY
;
1935 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1938 This
->bDirty
= TRUE
;
1944 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
1953 p
= strchrW( str
, ':' );
1957 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
1960 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
1965 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
1967 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
1975 /* each segment must start with two colons */
1976 if( str
[0] != ':' || str
[1] != ':' )
1979 /* the last segment is just two colons */
1984 /* there must be a colon straight after a guid */
1985 p
= strchrW( str
, ':' );
1992 /* get the guid, and check it's validly formatted */
1993 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
1995 r
= CLSIDFromString( szGuid
, &guid
);
2000 /* match it up to a guid that we care about */
2001 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2003 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2008 /* skip to the next field */
2009 str
= strchrW( str
, ':' );
2014 /* we have to have a component for an advertised shortcut */
2018 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2019 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2021 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2022 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2027 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2029 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2030 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2033 volume
->type
= GetDriveTypeW(drive
);
2034 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2035 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2036 TRACE("r = %d type %d serial %08x name %s\n", r
,
2037 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2041 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2043 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2044 WCHAR buffer
[MAX_PATH
];
2045 LPWSTR fname
, unquoted
= NULL
;
2049 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2051 if (!pszFile
) return E_INVALIDARG
;
2053 /* quotes at the ends of the string are stripped */
2054 len
= lstrlenW(pszFile
);
2055 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2057 unquoted
= strdupW(pszFile
);
2058 PathUnquoteSpacesW(unquoted
);
2062 /* any other quote marks are invalid */
2063 if (strchrW(pszFile
, '"'))
2065 HeapFree(GetProcessHeap(), 0, unquoted
);
2069 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2072 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2073 This
->sComponent
= NULL
;
2076 ILFree(This
->pPidl
);
2079 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2081 if (*pszFile
== '\0')
2083 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2085 else if(!PathFileExistsW(buffer
) &&
2086 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2089 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2090 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2092 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2093 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2096 HeapFree(GetProcessHeap(), 0, unquoted
);
2097 return E_OUTOFMEMORY
;
2100 lstrcpyW(This
->sPath
, buffer
);
2102 This
->bDirty
= TRUE
;
2103 HeapFree(GetProcessHeap(), 0, unquoted
);
2108 /**************************************************************************
2109 * IShellLinkW Implementation
2112 static const IShellLinkWVtbl slvtw
=
2114 IShellLinkW_fnQueryInterface
,
2115 IShellLinkW_fnAddRef
,
2116 IShellLinkW_fnRelease
,
2117 IShellLinkW_fnGetPath
,
2118 IShellLinkW_fnGetIDList
,
2119 IShellLinkW_fnSetIDList
,
2120 IShellLinkW_fnGetDescription
,
2121 IShellLinkW_fnSetDescription
,
2122 IShellLinkW_fnGetWorkingDirectory
,
2123 IShellLinkW_fnSetWorkingDirectory
,
2124 IShellLinkW_fnGetArguments
,
2125 IShellLinkW_fnSetArguments
,
2126 IShellLinkW_fnGetHotkey
,
2127 IShellLinkW_fnSetHotkey
,
2128 IShellLinkW_fnGetShowCmd
,
2129 IShellLinkW_fnSetShowCmd
,
2130 IShellLinkW_fnGetIconLocation
,
2131 IShellLinkW_fnSetIconLocation
,
2132 IShellLinkW_fnSetRelativePath
,
2133 IShellLinkW_fnResolve
,
2134 IShellLinkW_fnSetPath
2137 static HRESULT WINAPI
2138 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2140 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2141 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2145 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2147 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2148 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2152 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2154 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2155 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2158 static HRESULT WINAPI
2159 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2161 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2165 static HRESULT WINAPI
2166 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2168 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2169 LPVOID block
= NULL
;
2172 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2176 case EXP_DARWIN_ID_SIG
:
2177 if (!This
->sComponent
)
2179 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2182 case EXP_SZ_LINK_SIG
:
2183 case NT_CONSOLE_PROPS_SIG
:
2184 case NT_FE_CONSOLE_PROPS_SIG
:
2185 case EXP_SPECIAL_FOLDER_SIG
:
2186 case EXP_SZ_ICON_SIG
:
2187 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2190 ERR("unknown datablock %08x\n", dwSig
);
2192 *ppDataBlock
= block
;
2196 static HRESULT WINAPI
2197 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2199 FIXME("(%p)->(%u): stub\n", iface
, dwSig
);
2203 static HRESULT WINAPI
2204 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2206 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2209 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2211 /* FIXME: add more */
2213 flags
|= SLDF_HAS_ARGS
;
2214 if (This
->sComponent
)
2215 flags
|= SLDF_HAS_DARWINID
;
2217 flags
|= SLDF_HAS_ICONLOCATION
;
2219 flags
|= SLDF_HAS_LOGO3ID
;
2221 flags
|= SLDF_HAS_ID_LIST
;
2228 static HRESULT WINAPI
2229 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2231 FIXME("(%p)->(%u): stub\n", iface
, dwFlags
);
2235 static const IShellLinkDataListVtbl dlvt
=
2237 ShellLink_DataList_QueryInterface
,
2238 ShellLink_DataList_AddRef
,
2239 ShellLink_DataList_Release
,
2240 ShellLink_AddDataBlock
,
2241 ShellLink_CopyDataBlock
,
2242 ShellLink_RemoveDataBlock
,
2247 static HRESULT WINAPI
2248 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2250 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2251 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2255 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2257 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2258 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2262 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2264 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2265 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2268 /**************************************************************************
2269 * ShellLink implementation of IShellExtInit::Initialize()
2271 * Loads the shelllink from the dataobject the shell is pointing to.
2273 static HRESULT WINAPI
2274 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2275 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2277 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2283 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2288 format
.cfFormat
= CF_HDROP
;
2290 format
.dwAspect
= DVASPECT_CONTENT
;
2292 format
.tymed
= TYMED_HGLOBAL
;
2294 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2297 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2302 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2304 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2307 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2309 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2310 r
= IPersistFile_Load( pf
, path
, 0 );
2311 HeapFree( GetProcessHeap(), 0, path
);
2314 ReleaseStgMedium( &stgm
);
2319 static const IShellExtInitVtbl eivt
=
2321 ShellLink_ExtInit_QueryInterface
,
2322 ShellLink_ExtInit_AddRef
,
2323 ShellLink_ExtInit_Release
,
2324 ShellLink_ExtInit_Initialize
2327 static HRESULT WINAPI
2328 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2330 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2331 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2335 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2337 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2338 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2342 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2344 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2345 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2348 static HRESULT WINAPI
2349 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2350 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2352 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2353 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2357 TRACE("%p %p %u %u %u %u\n", This
,
2358 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2361 return E_INVALIDARG
;
2363 memset( &mii
, 0, sizeof mii
);
2364 mii
.cbSize
= sizeof mii
;
2365 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2366 mii
.dwTypeData
= szOpen
;
2367 mii
.cch
= strlenW( mii
.dwTypeData
);
2368 mii
.wID
= idCmdFirst
+ id
++;
2369 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2370 mii
.fType
= MFT_STRING
;
2371 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2375 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2379 shelllink_get_msi_component_path( LPWSTR component
)
2384 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2385 if (r
!= ERROR_SUCCESS
)
2389 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2390 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2391 if (r
!= ERROR_SUCCESS
)
2393 HeapFree( GetProcessHeap(), 0, path
);
2397 TRACE("returning %s\n", debugstr_w( path
) );
2402 static HRESULT WINAPI
2403 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2405 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2406 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2407 SHELLEXECUTEINFOW sei
;
2408 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2413 TRACE("%p %p\n", This
, lpici
);
2415 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2416 return E_INVALIDARG
;
2418 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2420 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2421 return E_INVALIDARG
;
2424 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2428 if ( This
->sComponent
)
2430 path
= shelllink_get_msi_component_path( This
->sComponent
);
2435 path
= strdupW( This
->sPath
);
2437 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2438 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2440 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2444 len
+= lstrlenW( This
->sArgs
);
2445 if ( iciex
->lpParametersW
)
2446 len
+= lstrlenW( iciex
->lpParametersW
);
2448 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2451 lstrcatW( args
, This
->sArgs
);
2452 if ( iciex
->lpParametersW
&& iciex
->lpParametersW
[0] )
2454 static const WCHAR space
[] = { ' ', 0 };
2455 lstrcatW( args
, space
);
2456 lstrcatW( args
, iciex
->lpParametersW
);
2460 memset( &sei
, 0, sizeof sei
);
2461 sei
.cbSize
= sizeof sei
;
2462 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_NO_CONSOLE
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2464 sei
.nShow
= This
->iShowCmd
;
2465 sei
.lpIDList
= This
->pPidl
;
2466 sei
.lpDirectory
= This
->sWorkDir
;
2467 sei
.lpParameters
= args
;
2468 sei
.lpVerb
= szOpen
;
2470 if( ShellExecuteExW( &sei
) )
2475 HeapFree( GetProcessHeap(), 0, args
);
2476 HeapFree( GetProcessHeap(), 0, path
);
2481 static HRESULT WINAPI
2482 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2483 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2485 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2487 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This
,
2488 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2493 static const IContextMenuVtbl cmvt
=
2495 ShellLink_ContextMenu_QueryInterface
,
2496 ShellLink_ContextMenu_AddRef
,
2497 ShellLink_ContextMenu_Release
,
2498 ShellLink_QueryContextMenu
,
2499 ShellLink_InvokeCommand
,
2500 ShellLink_GetCommandString
2503 static HRESULT WINAPI
2504 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2506 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2507 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, ppvObject
);
2511 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2513 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2514 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2518 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2520 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2521 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2524 static HRESULT WINAPI
2525 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2527 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2529 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2533 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2536 static HRESULT WINAPI
2537 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2539 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2541 TRACE("%p %p\n", iface
, punk
);
2544 IUnknown_AddRef( punk
);
2547 IUnknown_Release( This
->site
);
2554 static const IObjectWithSiteVtbl owsvt
=
2556 ShellLink_ObjectWithSite_QueryInterface
,
2557 ShellLink_ObjectWithSite_AddRef
,
2558 ShellLink_ObjectWithSite_Release
,
2563 static HRESULT WINAPI
propertystore_QueryInterface(IPropertyStore
*iface
, REFIID riid
, void **obj
)
2565 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2566 return IShellLinkW_QueryInterface(&This
->IShellLinkW_iface
, riid
, obj
);
2569 static ULONG WINAPI
propertystore_AddRef(IPropertyStore
*iface
)
2571 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2572 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2575 static ULONG WINAPI
propertystore_Release(IPropertyStore
*iface
)
2577 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2578 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2581 static HRESULT WINAPI
propertystore_GetCount(IPropertyStore
*iface
, DWORD
*props
)
2583 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2584 FIXME("(%p)->(%p): stub\n", This
, props
);
2588 static HRESULT WINAPI
propertystore_GetAt(IPropertyStore
*iface
, DWORD propid
, PROPERTYKEY
*key
)
2590 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2591 FIXME("(%p)->(%d %p): stub\n", This
, propid
, key
);
2595 static HRESULT WINAPI
propertystore_GetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, PROPVARIANT
*value
)
2597 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2598 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2602 static HRESULT WINAPI
propertystore_SetValue(IPropertyStore
*iface
, REFPROPERTYKEY key
, REFPROPVARIANT value
)
2604 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2605 FIXME("(%p)->(%p %p): stub\n", This
, key
, value
);
2609 static HRESULT WINAPI
propertystore_Commit(IPropertyStore
*iface
)
2611 IShellLinkImpl
*This
= impl_from_IPropertyStore(iface
);
2612 FIXME("(%p): stub\n", This
);
2616 static const IPropertyStoreVtbl propertystorevtbl
= {
2617 propertystore_QueryInterface
,
2618 propertystore_AddRef
,
2619 propertystore_Release
,
2620 propertystore_GetCount
,
2621 propertystore_GetAt
,
2622 propertystore_GetValue
,
2623 propertystore_SetValue
,
2624 propertystore_Commit
2627 HRESULT WINAPI
IShellLink_Constructor(IUnknown
*outer
, REFIID riid
, void **obj
)
2629 IShellLinkImpl
* sl
;
2632 TRACE("outer=%p riid=%s\n", outer
, debugstr_guid(riid
));
2637 return CLASS_E_NOAGGREGATION
;
2639 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
2641 return E_OUTOFMEMORY
;
2644 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
2645 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
2646 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
2647 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
2648 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
2649 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
2650 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
2651 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
2652 sl
->IPropertyStore_iface
.lpVtbl
= &propertystorevtbl
;
2653 sl
->iShowCmd
= SW_SHOWNORMAL
;
2657 sl
->filepath
= NULL
;
2659 TRACE("(%p)\n", sl
);
2661 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, obj
);
2662 IShellLinkW_Release( &sl
->IShellLinkW_iface
);