3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Nearly complete information about the binary formats
23 * of .lnk files available at http://www.wotsit.org
25 * You can use winedump to examine the contents of a link file:
28 * MSI advertised shortcuts are totally undocumented. They provide an
29 * icon for a program that is not yet installed, and invoke MSI to
30 * install the program when the shortcut is clicked on. They are
31 * created by passing a special string to SetPath, and the information
32 * in that string is parsed an stored.
36 #define NONAMELESSUNION
38 #include "wine/debug.h"
48 #include "undocshell.h"
51 #include "shell32_main.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
61 DEFINE_GUID( SHELL32_AdvtShortcutProduct
,
62 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
63 DEFINE_GUID( SHELL32_AdvtShortcutComponent
,
64 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
66 /* link file formats */
70 typedef struct _LINK_HEADER
72 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
73 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
74 DWORD dwFlags
; /* 0x14 describes elements following */
75 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
76 FILETIME Time1
; /* 0x1c */
77 FILETIME Time2
; /* 0x24 */
78 FILETIME Time3
; /* 0x2c */
79 DWORD dwFileLength
; /* 0x34 File length */
80 DWORD nIcon
; /* 0x38 icon number */
81 DWORD fStartup
; /* 0x3c startup type */
82 DWORD wHotKey
; /* 0x40 hotkey */
83 DWORD Unknown5
; /* 0x44 */
84 DWORD Unknown6
; /* 0x48 */
85 } LINK_HEADER
, * PLINK_HEADER
;
87 #define SHLINK_LOCAL 0
88 #define SHLINK_REMOTE 1
90 typedef struct _LOCATION_INFO
97 DWORD dwNetworkVolTableOfs
;
101 typedef struct _LOCAL_VOLUME_INFO
109 typedef struct volume_info_t
113 WCHAR label
[12]; /* assume 8.3 */
118 static const IShellLinkAVtbl slvt
;
119 static const IShellLinkWVtbl slvtw
;
120 static const IPersistFileVtbl pfvt
;
121 static const IPersistStreamVtbl psvt
;
122 static const IShellLinkDataListVtbl dlvt
;
123 static const IShellExtInitVtbl eivt
;
124 static const IContextMenuVtbl cmvt
;
125 static const IObjectWithSiteVtbl owsvt
;
127 /* IShellLink Implementation */
131 IShellLinkA IShellLinkA_iface
;
132 IShellLinkW IShellLinkW_iface
;
133 IPersistFile IPersistFile_iface
;
134 IPersistStream IPersistStream_iface
;
135 IShellLinkDataList IShellLinkDataList_iface
;
136 IShellExtInit IShellExtInit_iface
;
137 IContextMenu IContextMenu_iface
;
138 IObjectWithSite IObjectWithSite_iface
;
142 /* data structures according to the information in the link */
162 INT iIdOpen
; /* id of the "Open" entry in the context menu */
165 LPOLESTR filepath
; /* file path returned by IPersistFile::GetCurFile */
168 static inline IShellLinkImpl
*impl_from_IShellLinkA(IShellLinkA
*iface
)
170 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkA_iface
);
173 static inline IShellLinkImpl
*impl_from_IShellLinkW(IShellLinkW
*iface
)
175 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkW_iface
);
178 static inline IShellLinkImpl
*impl_from_IPersistFile(IPersistFile
*iface
)
180 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistFile_iface
);
183 static inline IShellLinkImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
185 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IPersistStream_iface
);
188 static inline IShellLinkImpl
*impl_from_IShellLinkDataList(IShellLinkDataList
*iface
)
190 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellLinkDataList_iface
);
193 static inline IShellLinkImpl
*impl_from_IShellExtInit(IShellExtInit
*iface
)
195 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IShellExtInit_iface
);
198 static inline IShellLinkImpl
*impl_from_IContextMenu(IContextMenu
*iface
)
200 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IContextMenu_iface
);
203 static inline IShellLinkImpl
*impl_from_IObjectWithSite(IObjectWithSite
*iface
)
205 return CONTAINING_RECORD(iface
, IShellLinkImpl
, IObjectWithSite_iface
);
208 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
210 /* strdup on the process heap */
211 static inline LPWSTR
heap_strdupAtoW( LPCSTR str
)
213 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
214 LPWSTR p
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof (WCHAR
) );
217 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
221 static inline LPWSTR
strdupW( LPCWSTR src
)
224 if (!src
) return NULL
;
225 dest
= HeapAlloc( GetProcessHeap(), 0, (lstrlenW(src
)+1)*sizeof(WCHAR
) );
231 /**************************************************************************
232 * ShellLink::QueryInterface implementation
234 static HRESULT
ShellLink_QueryInterface( IShellLinkImpl
*This
, REFIID riid
, LPVOID
*ppvObj
)
236 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
240 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IShellLinkA
))
242 *ppvObj
= &This
->IShellLinkA_iface
;
244 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
246 *ppvObj
= &This
->IShellLinkW_iface
;
248 else if(IsEqualIID(riid
, &IID_IPersistFile
))
250 *ppvObj
= &This
->IPersistFile_iface
;
252 else if(IsEqualIID(riid
, &IID_IPersistStream
))
254 *ppvObj
= &This
->IPersistStream_iface
;
256 else if(IsEqualIID(riid
, &IID_IShellLinkDataList
))
258 *ppvObj
= &This
->IShellLinkDataList_iface
;
260 else if(IsEqualIID(riid
, &IID_IShellExtInit
))
262 *ppvObj
= &This
->IShellExtInit_iface
;
264 else if(IsEqualIID(riid
, &IID_IContextMenu
))
266 *ppvObj
= &This
->IContextMenu_iface
;
268 else if(IsEqualIID(riid
, &IID_IObjectWithSite
))
270 *ppvObj
= &This
->IObjectWithSite_iface
;
275 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
276 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
279 ERR("-- Interface: E_NOINTERFACE\n");
280 return E_NOINTERFACE
;
283 /**************************************************************************
284 * IPersistFile_QueryInterface
286 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
291 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
292 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
295 /******************************************************************************
296 * IPersistFile_AddRef
298 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
300 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
301 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
304 /******************************************************************************
305 * IPersistFile_Release
307 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
309 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
310 return IShellLinkA_Release(&This
->IShellLinkA_iface
);
313 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
315 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
317 TRACE("(%p)->(%p)\n", This
, pClassID
);
319 *pClassID
= CLSID_ShellLink
;
324 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
326 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
328 TRACE("(%p)\n",This
);
336 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
338 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
339 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
343 TRACE("(%p, %s, %x)\n",This
, debugstr_w(pszFileName
), dwMode
);
346 dwMode
= STGM_READ
| STGM_SHARE_DENY_WRITE
;
347 r
= SHCreateStreamOnFileW(pszFileName
, dwMode
, &stm
);
350 r
= IPersistStream_Load(StreamThis
, stm
);
351 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
352 IStream_Release( stm
);
354 /* update file path */
355 HeapFree(GetProcessHeap(), 0, This
->filepath
);
356 This
->filepath
= strdupW(pszFileName
);
358 This
->bDirty
= FALSE
;
360 TRACE("-- returning hr %08x\n", r
);
364 BOOL
run_winemenubuilder( const WCHAR
*args
)
366 static const WCHAR menubuilder
[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
370 PROCESS_INFORMATION pi
;
375 GetSystemDirectoryW( app
, MAX_PATH
- sizeof(menubuilder
)/sizeof(WCHAR
) );
376 strcatW( app
, menubuilder
);
378 len
= (strlenW( app
) + strlenW( args
) + 1) * sizeof(WCHAR
);
379 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
383 strcpyW( buffer
, app
);
384 strcatW( buffer
, args
);
386 TRACE("starting %s\n",debugstr_w(buffer
));
388 memset(&si
, 0, sizeof(si
));
391 Wow64DisableWow64FsRedirection( &redir
);
392 ret
= CreateProcessW( app
, buffer
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
, NULL
, NULL
, &si
, &pi
);
393 Wow64RevertWow64FsRedirection( redir
);
395 HeapFree( GetProcessHeap(), 0, buffer
);
399 CloseHandle( pi
.hProcess
);
400 CloseHandle( pi
.hThread
);
406 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
408 static const WCHAR szFormat
[] = {' ','-','w',' ','"','%','s','"',0 };
413 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
414 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
418 wsprintfW( buffer
, szFormat
, szLink
);
419 ret
= run_winemenubuilder( buffer
);
420 HeapFree( GetProcessHeap(), 0, buffer
);
424 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
426 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
427 IPersistStream
*StreamThis
= &This
->IPersistStream_iface
;
431 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
436 r
= SHCreateStreamOnFileW( pszFileName
, STGM_READWRITE
| STGM_CREATE
| STGM_SHARE_EXCLUSIVE
, &stm
);
439 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
440 IStream_Release( stm
);
444 StartLinkProcessor( pszFileName
);
446 /* update file path */
447 HeapFree(GetProcessHeap(), 0, This
->filepath
);
448 This
->filepath
= strdupW(pszFileName
);
450 This
->bDirty
= FALSE
;
454 DeleteFileW( pszFileName
);
455 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
462 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR filename
)
464 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
465 FIXME("(%p)->(%s): stub\n", This
, debugstr_w(filename
));
469 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*filename
)
471 IShellLinkImpl
*This
= impl_from_IPersistFile(iface
);
474 TRACE("(%p)->(%p)\n", This
, filename
);
482 SHGetMalloc(&pMalloc
);
483 *filename
= IMalloc_Alloc(pMalloc
, (strlenW(This
->filepath
)+1)*sizeof(WCHAR
));
484 if (!*filename
) return E_OUTOFMEMORY
;
486 strcpyW(*filename
, This
->filepath
);
491 static const IPersistFileVtbl pfvt
=
493 IPersistFile_fnQueryInterface
,
494 IPersistFile_fnAddRef
,
495 IPersistFile_fnRelease
,
496 IPersistFile_fnGetClassID
,
497 IPersistFile_fnIsDirty
,
500 IPersistFile_fnSaveCompleted
,
501 IPersistFile_fnGetCurFile
504 /************************************************************************
505 * IPersistStream_QueryInterface
507 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
508 IPersistStream
* iface
,
512 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
513 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
516 /************************************************************************
517 * IPersistStream_Release
519 static ULONG WINAPI
IPersistStream_fnRelease(
520 IPersistStream
* iface
)
522 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
523 return IShellLinkA_Release(&This
->IShellLinkA_iface
);
526 /************************************************************************
527 * IPersistStream_AddRef
529 static ULONG WINAPI
IPersistStream_fnAddRef(
530 IPersistStream
* iface
)
532 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
533 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
536 /************************************************************************
537 * IPersistStream_GetClassID
540 static HRESULT WINAPI
IPersistStream_fnGetClassID(
541 IPersistStream
* iface
,
544 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
545 return IPersistFile_GetClassID(&This
->IPersistFile_iface
, pClassID
);
548 /************************************************************************
549 * IPersistStream_IsDirty (IPersistStream)
551 static HRESULT WINAPI
IPersistStream_fnIsDirty(
552 IPersistStream
* iface
)
554 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
556 TRACE("(%p)\n", This
);
562 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
573 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
574 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
578 len
*= sizeof (WCHAR
);
580 TRACE("reading %d\n", len
);
581 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
583 return E_OUTOFMEMORY
;
585 r
= IStream_Read(stm
, temp
, len
, &count
);
586 if( FAILED (r
) || ( count
!= len
) )
588 HeapFree( GetProcessHeap(), 0, temp
);
592 TRACE("read %s\n", debugstr_an(temp
,len
));
594 /* convert to unicode if necessary */
597 count
= MultiByteToWideChar( CP_ACP
, 0, temp
, len
, NULL
, 0 );
598 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
601 HeapFree( GetProcessHeap(), 0, temp
);
602 return E_OUTOFMEMORY
;
604 MultiByteToWideChar( CP_ACP
, 0, temp
, len
, str
, count
);
605 HeapFree( GetProcessHeap(), 0, temp
);
619 static HRESULT
Stream_ReadChunk( IStream
* stm
, LPVOID
*data
)
626 unsigned char data
[1];
631 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
632 if( FAILED( r
) || count
!= sizeof(size
) )
635 chunk
= HeapAlloc( GetProcessHeap(), 0, size
);
637 return E_OUTOFMEMORY
;
640 r
= IStream_Read( stm
, chunk
->data
, size
- sizeof(size
), &count
);
641 if( FAILED( r
) || count
!= (size
- sizeof(size
)) )
643 HeapFree( GetProcessHeap(), 0, chunk
);
647 TRACE("Read %d bytes\n",chunk
->size
);
654 static BOOL
Stream_LoadVolume( LOCAL_VOLUME_INFO
*vol
, volume_info
*volume
)
656 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
660 volume
->serial
= vol
->dwVolSerial
;
661 volume
->type
= vol
->dwType
;
663 if( !vol
->dwVolLabelOfs
)
665 if( vol
->dwSize
<= vol
->dwVolLabelOfs
)
667 len
= vol
->dwSize
- vol
->dwVolLabelOfs
;
670 label
+= vol
->dwVolLabelOfs
;
671 MultiByteToWideChar( CP_ACP
, 0, label
, len
, volume
->label
, label_sz
-1);
676 static LPWSTR
Stream_LoadPath( LPCSTR p
, DWORD maxlen
)
681 while( p
[len
] && (len
< maxlen
) )
684 wlen
= MultiByteToWideChar(CP_ACP
, 0, p
, len
, NULL
, 0);
685 path
= HeapAlloc(GetProcessHeap(), 0, (wlen
+1)*sizeof(WCHAR
));
686 MultiByteToWideChar(CP_ACP
, 0, p
, len
, path
, wlen
);
692 static HRESULT
Stream_LoadLocation( IStream
*stm
,
693 volume_info
*volume
, LPWSTR
*path
)
700 r
= Stream_ReadChunk( stm
, (LPVOID
*) &p
);
704 loc
= (LOCATION_INFO
*) p
;
705 if (loc
->dwTotalSize
< sizeof(LOCATION_INFO
))
707 HeapFree( GetProcessHeap(), 0, p
);
711 /* if there's valid local volume information, load it */
712 if( loc
->dwVolTableOfs
&&
713 ((loc
->dwVolTableOfs
+ sizeof(LOCAL_VOLUME_INFO
)) <= loc
->dwTotalSize
) )
715 LOCAL_VOLUME_INFO
*volume_info
;
717 volume_info
= (LOCAL_VOLUME_INFO
*) &p
[loc
->dwVolTableOfs
];
718 Stream_LoadVolume( volume_info
, volume
);
721 /* if there's a local path, load it */
722 n
= loc
->dwLocalPathOfs
;
723 if( n
&& (n
< loc
->dwTotalSize
) )
724 *path
= Stream_LoadPath( &p
[n
], loc
->dwTotalSize
- n
);
726 TRACE("type %d serial %08x name %s path %s\n", volume
->type
,
727 volume
->serial
, debugstr_w(volume
->label
), debugstr_w(*path
));
729 HeapFree( GetProcessHeap(), 0, p
);
734 * The format of the advertised shortcut info seems to be:
739 * 0 Length of the block (4 bytes, usually 0x314)
741 * 8 string data in ASCII
742 * 8+0x104 string data in UNICODE
744 * In the original Win32 implementation the buffers are not initialized
745 * to zero, so data trailing the string is random garbage.
747 static HRESULT
Stream_LoadAdvertiseInfo( IStream
* stm
, LPWSTR
*str
)
752 EXP_DARWIN_LINK buffer
;
756 r
= IStream_Read( stm
, &buffer
.dbh
.cbSize
, sizeof (DWORD
), &count
);
760 /* make sure that we read the size of the structure even on error */
761 size
= sizeof buffer
- sizeof (DWORD
);
762 if( buffer
.dbh
.cbSize
!= sizeof buffer
)
764 ERR("Ooops. This structure is not as expected...\n");
768 r
= IStream_Read( stm
, &buffer
.dbh
.dwSignature
, size
, &count
);
775 TRACE("magic %08x string = %s\n", buffer
.dbh
.dwSignature
, debugstr_w(buffer
.szwDarwinID
));
777 if( (buffer
.dbh
.dwSignature
&0xffff0000) != 0xa0000000 )
779 ERR("Unknown magic number %08x in advertised shortcut\n", buffer
.dbh
.dwSignature
);
783 *str
= HeapAlloc( GetProcessHeap(), 0,
784 (lstrlenW(buffer
.szwDarwinID
)+1) * sizeof(WCHAR
) );
785 lstrcpyW( *str
, buffer
.szwDarwinID
);
790 /************************************************************************
791 * IPersistStream_Load (IPersistStream)
793 static HRESULT WINAPI
IPersistStream_fnLoad(
794 IPersistStream
* iface
,
803 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
805 TRACE("%p %p\n", This
, stm
);
808 return STG_E_INVALIDPOINTER
;
811 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
815 if( dwBytesRead
!= sizeof(hdr
))
817 if( hdr
.dwSize
!= sizeof(hdr
))
819 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
822 /* free all the old stuff */
825 memset( &This
->volume
, 0, sizeof This
->volume
);
826 HeapFree(GetProcessHeap(), 0, This
->sPath
);
828 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
829 This
->sDescription
= NULL
;
830 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
831 This
->sPathRel
= NULL
;
832 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
833 This
->sWorkDir
= NULL
;
834 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
836 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
837 This
->sIcoPath
= NULL
;
838 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
839 This
->sProduct
= NULL
;
840 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
841 This
->sComponent
= NULL
;
843 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
844 This
->iIcoNdx
= hdr
.nIcon
;
845 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
846 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
847 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
850 WCHAR sTemp
[MAX_PATH
];
851 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time1
,
852 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
853 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
854 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time2
,
855 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
856 TRACE("-- time2: %s\n", debugstr_w(sTemp
) );
857 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
, &This
->time3
,
858 NULL
, sTemp
, sizeof(sTemp
)/sizeof(*sTemp
));
859 TRACE("-- time3: %s\n", debugstr_w(sTemp
) );
862 /* load all the new stuff */
863 if( hdr
.dwFlags
& SLDF_HAS_ID_LIST
)
865 r
= ILLoadFromStream( stm
, &This
->pPidl
);
871 /* load the location information */
872 if( hdr
.dwFlags
& SLDF_HAS_LINK_INFO
)
873 r
= Stream_LoadLocation( stm
, &This
->volume
, &This
->sPath
);
877 unicode
= hdr
.dwFlags
& SLDF_UNICODE
;
878 if( hdr
.dwFlags
& SLDF_HAS_NAME
)
880 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
881 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
886 if( hdr
.dwFlags
& SLDF_HAS_RELPATH
)
888 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
889 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
894 if( hdr
.dwFlags
& SLDF_HAS_WORKINGDIR
)
896 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
897 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
902 if( hdr
.dwFlags
& SLDF_HAS_ARGS
)
904 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
905 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
910 if( hdr
.dwFlags
& SLDF_HAS_ICONLOCATION
)
912 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
913 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
918 if( hdr
.dwFlags
& SLDF_HAS_LOGO3ID
)
920 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sProduct
);
921 TRACE("Product -> %s\n",debugstr_w(This
->sProduct
));
926 if( hdr
.dwFlags
& SLDF_HAS_DARWINID
)
928 r
= Stream_LoadAdvertiseInfo( stm
, &This
->sComponent
);
929 TRACE("Component -> %s\n",debugstr_w(This
->sComponent
));
934 r
= IStream_Read(stm
, &zero
, sizeof zero
, &dwBytesRead
);
935 if( FAILED( r
) || zero
|| dwBytesRead
!= sizeof zero
)
937 /* Some lnk files have extra data blocks starting with a
938 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
939 * one with a 0xa0000003 signature. However these don't seem to matter
942 WARN("Last word was not zero\n");
954 /************************************************************************
957 * Helper function for IPersistStream_Save. Writes a unicode string
958 * with terminating nul byte to a stream, preceded by the its length.
960 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
962 USHORT len
= lstrlenW( str
) + 1;
966 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
970 len
*= sizeof(WCHAR
);
972 r
= IStream_Write( stm
, str
, len
, &count
);
979 /************************************************************************
980 * Stream_WriteLocationInfo
982 * Writes the location info to a stream
984 * FIXME: One day we might want to write the network volume information
985 * and the final path.
986 * Figure out how Windows deals with unicode paths here.
988 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR path
,
989 volume_info
*volume
)
991 DWORD total_size
, path_size
, volume_info_size
, label_size
, final_path_size
;
992 LOCAL_VOLUME_INFO
*vol
;
994 LPSTR szLabel
, szPath
, szFinalPath
;
998 TRACE("%p %s %p\n", stm
, debugstr_w(path
), volume
);
1000 /* figure out the size of everything */
1001 label_size
= WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
1002 NULL
, 0, NULL
, NULL
);
1003 path_size
= WideCharToMultiByte( CP_ACP
, 0, path
, -1,
1004 NULL
, 0, NULL
, NULL
);
1005 volume_info_size
= sizeof *vol
+ label_size
;
1006 final_path_size
= 1;
1007 total_size
= sizeof *loc
+ volume_info_size
+ path_size
+ final_path_size
;
1009 /* create pointers to everything */
1010 loc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, total_size
);
1011 vol
= (LOCAL_VOLUME_INFO
*) &loc
[1];
1012 szLabel
= (LPSTR
) &vol
[1];
1013 szPath
= &szLabel
[label_size
];
1014 szFinalPath
= &szPath
[path_size
];
1016 /* fill in the location information header */
1017 loc
->dwTotalSize
= total_size
;
1018 loc
->dwHeaderSize
= sizeof (*loc
);
1020 loc
->dwVolTableOfs
= sizeof (*loc
);
1021 loc
->dwLocalPathOfs
= sizeof (*loc
) + volume_info_size
;
1022 loc
->dwNetworkVolTableOfs
= 0;
1023 loc
->dwFinalPathOfs
= sizeof (*loc
) + volume_info_size
+ path_size
;
1025 /* fill in the volume information */
1026 vol
->dwSize
= volume_info_size
;
1027 vol
->dwType
= volume
->type
;
1028 vol
->dwVolSerial
= volume
->serial
;
1029 vol
->dwVolLabelOfs
= sizeof (*vol
);
1031 /* copy in the strings */
1032 WideCharToMultiByte( CP_ACP
, 0, volume
->label
, -1,
1033 szLabel
, label_size
, NULL
, NULL
);
1034 WideCharToMultiByte( CP_ACP
, 0, path
, -1,
1035 szPath
, path_size
, NULL
, NULL
);
1038 hr
= IStream_Write( stm
, loc
, total_size
, &count
);
1039 HeapFree(GetProcessHeap(), 0, loc
);
1044 static EXP_DARWIN_LINK
* shelllink_build_darwinid( LPCWSTR string
, DWORD magic
)
1046 EXP_DARWIN_LINK
*buffer
;
1048 buffer
= LocalAlloc( LMEM_ZEROINIT
, sizeof *buffer
);
1049 buffer
->dbh
.cbSize
= sizeof *buffer
;
1050 buffer
->dbh
.dwSignature
= magic
;
1051 lstrcpynW( buffer
->szwDarwinID
, string
, MAX_PATH
);
1052 WideCharToMultiByte(CP_ACP
, 0, string
, -1, buffer
->szDarwinID
, MAX_PATH
, NULL
, NULL
);
1057 static HRESULT
Stream_WriteAdvertiseInfo( IStream
* stm
, LPCWSTR string
, DWORD magic
)
1059 EXP_DARWIN_LINK
*buffer
;
1064 buffer
= shelllink_build_darwinid( string
, magic
);
1066 return IStream_Write( stm
, buffer
, buffer
->dbh
.cbSize
, &count
);
1069 /************************************************************************
1070 * IPersistStream_Save (IPersistStream)
1072 * FIXME: makes assumptions about byte order
1074 static HRESULT WINAPI
IPersistStream_fnSave(
1075 IPersistStream
* iface
,
1084 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1086 TRACE("%p %p %x\n", This
, stm
, fClearDirty
);
1088 memset(&header
, 0, sizeof(header
));
1089 header
.dwSize
= sizeof(header
);
1090 header
.fStartup
= This
->iShowCmd
;
1091 header
.MagicGuid
= CLSID_ShellLink
;
1093 header
.wHotKey
= This
->wHotKey
;
1094 header
.nIcon
= This
->iIcoNdx
;
1095 header
.dwFlags
= SLDF_UNICODE
; /* strings are in unicode */
1097 header
.dwFlags
|= SLDF_HAS_ID_LIST
;
1099 header
.dwFlags
|= SLDF_HAS_LINK_INFO
;
1100 if( This
->sDescription
)
1101 header
.dwFlags
|= SLDF_HAS_NAME
;
1102 if( This
->sWorkDir
)
1103 header
.dwFlags
|= SLDF_HAS_WORKINGDIR
;
1105 header
.dwFlags
|= SLDF_HAS_ARGS
;
1106 if( This
->sIcoPath
)
1107 header
.dwFlags
|= SLDF_HAS_ICONLOCATION
;
1108 if( This
->sProduct
)
1109 header
.dwFlags
|= SLDF_HAS_LOGO3ID
;
1110 if( This
->sComponent
)
1111 header
.dwFlags
|= SLDF_HAS_DARWINID
;
1113 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
1114 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
1115 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
1117 /* write the Shortcut header */
1118 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
1121 ERR("Write failed at %d\n",__LINE__
);
1125 TRACE("Writing pidl\n");
1127 /* write the PIDL to the shortcut */
1130 r
= ILSaveToStream( stm
, This
->pPidl
);
1133 ERR("Failed to write PIDL at %d\n",__LINE__
);
1139 Stream_WriteLocationInfo( stm
, This
->sPath
, &This
->volume
);
1141 if( This
->sDescription
)
1142 r
= Stream_WriteString( stm
, This
->sDescription
);
1144 if( This
->sPathRel
)
1145 r
= Stream_WriteString( stm
, This
->sPathRel
);
1147 if( This
->sWorkDir
)
1148 r
= Stream_WriteString( stm
, This
->sWorkDir
);
1151 r
= Stream_WriteString( stm
, This
->sArgs
);
1153 if( This
->sIcoPath
)
1154 r
= Stream_WriteString( stm
, This
->sIcoPath
);
1156 if( This
->sProduct
)
1157 r
= Stream_WriteAdvertiseInfo( stm
, This
->sProduct
, EXP_SZ_ICON_SIG
);
1159 if( This
->sComponent
)
1160 r
= Stream_WriteAdvertiseInfo( stm
, This
->sComponent
, EXP_DARWIN_ID_SIG
);
1162 /* the last field is a single zero dword */
1164 r
= IStream_Write( stm
, &zero
, sizeof zero
, &count
);
1169 /************************************************************************
1170 * IPersistStream_GetSizeMax (IPersistStream)
1172 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
1173 IPersistStream
* iface
,
1174 ULARGE_INTEGER
* pcbSize
)
1176 IShellLinkImpl
*This
= impl_from_IPersistStream(iface
);
1178 TRACE("(%p)\n", This
);
1183 static const IPersistStreamVtbl psvt
=
1185 IPersistStream_fnQueryInterface
,
1186 IPersistStream_fnAddRef
,
1187 IPersistStream_fnRelease
,
1188 IPersistStream_fnGetClassID
,
1189 IPersistStream_fnIsDirty
,
1190 IPersistStream_fnLoad
,
1191 IPersistStream_fnSave
,
1192 IPersistStream_fnGetSizeMax
1195 /**************************************************************************
1196 * IShellLink_Constructor
1198 HRESULT WINAPI
IShellLink_Constructor( IUnknown
*pUnkOuter
,
1199 REFIID riid
, LPVOID
*ppv
)
1201 IShellLinkImpl
* sl
;
1204 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
1209 return CLASS_E_NOAGGREGATION
;
1210 sl
= LocalAlloc(LMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
1212 return E_OUTOFMEMORY
;
1215 sl
->IShellLinkA_iface
.lpVtbl
= &slvt
;
1216 sl
->IShellLinkW_iface
.lpVtbl
= &slvtw
;
1217 sl
->IPersistFile_iface
.lpVtbl
= &pfvt
;
1218 sl
->IPersistStream_iface
.lpVtbl
= &psvt
;
1219 sl
->IShellLinkDataList_iface
.lpVtbl
= &dlvt
;
1220 sl
->IShellExtInit_iface
.lpVtbl
= &eivt
;
1221 sl
->IContextMenu_iface
.lpVtbl
= &cmvt
;
1222 sl
->IObjectWithSite_iface
.lpVtbl
= &owsvt
;
1223 sl
->iShowCmd
= SW_SHOWNORMAL
;
1227 sl
->filepath
= NULL
;
1229 TRACE("(%p)->()\n",sl
);
1231 r
= IShellLinkW_QueryInterface( &sl
->IShellLinkW_iface
, riid
, ppv
);
1232 IShellLinkW_Release( &sl
->IShellLinkW_iface
);
1237 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
1239 if (INVALID_FILE_ATTRIBUTES
== GetFileAttributesW(path
))
1244 /**************************************************************************
1245 * ShellLink_UpdatePath
1246 * update absolute path in sPath using relative path in sPathRel
1248 static HRESULT
ShellLink_UpdatePath(LPCWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
1250 if (!path
|| !psPath
)
1251 return E_INVALIDARG
;
1253 if (!*psPath
&& sPathRel
) {
1254 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
1255 LPWSTR final
= NULL
;
1257 /* first try if [directory of link file] + [relative path] finds an existing file */
1259 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
1262 lstrcpyW(final
, sPathRel
);
1266 if (SHELL_ExistsFileW(buffer
)) {
1267 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1268 lstrcpyW(abs_path
, buffer
);
1270 /* try if [working directory] + [relative path] finds an existing file */
1272 lstrcpyW(buffer
, sWorkDir
);
1273 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
1275 if (SHELL_ExistsFileW(buffer
))
1276 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
1277 lstrcpyW(abs_path
, buffer
);
1281 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1283 lstrcpyW(abs_path
, sPathRel
);
1285 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
1287 return E_OUTOFMEMORY
;
1289 lstrcpyW(*psPath
, abs_path
);
1295 /**************************************************************************
1296 * IShellLink_ConstructFromFile
1298 HRESULT
IShellLink_ConstructFromFile( IUnknown
* pUnkOuter
, REFIID riid
,
1299 LPCITEMIDLIST pidl
, IUnknown
**ppv
)
1303 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
1305 if (SUCCEEDED(hr
)) {
1310 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
1312 if (SUCCEEDED(hr
)) {
1313 WCHAR path
[MAX_PATH
];
1315 if (SHGetPathFromIDListW(pidl
, path
))
1316 hr
= IPersistFile_Load(ppf
, path
, 0);
1321 *ppv
= (IUnknown
*)psl
;
1323 IPersistFile_Release(ppf
);
1327 IShellLinkW_Release(psl
);
1333 /**************************************************************************
1334 * IShellLinkA_QueryInterface
1336 static HRESULT WINAPI
IShellLinkA_fnQueryInterface(IShellLinkA
*iface
, REFIID riid
, void **ppvObj
)
1338 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1339 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1342 /******************************************************************************
1343 * IShellLinkA_AddRef
1345 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
*iface
)
1347 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1348 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
1351 /******************************************************************************
1352 * IShellLinkA_Release
1354 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
*iface
)
1356 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1357 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
1360 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
*iface
, LPSTR pszFile
, INT cchMaxPath
,
1361 WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1363 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1365 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1366 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1368 if (This
->sComponent
|| This
->sProduct
)
1374 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1375 pszFile
, cchMaxPath
, NULL
, NULL
);
1377 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1382 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
*iface
, LPITEMIDLIST
*ppidl
)
1384 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1385 return IShellLinkW_GetIDList(&This
->IShellLinkW_iface
, ppidl
);
1388 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
*iface
, LPCITEMIDLIST pidl
)
1390 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1391 return IShellLinkW_SetIDList(&This
->IShellLinkW_iface
, pidl
);
1394 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
*iface
, LPSTR pszName
,
1397 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1399 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1403 if( This
->sDescription
)
1404 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1405 pszName
, cchMaxName
, NULL
, NULL
);
1410 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
*iface
, LPCSTR pszName
)
1412 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1416 TRACE("(%p)->(pName=%s)\n", This
, debugstr_a(pszName
));
1420 descrW
= heap_strdupAtoW(pszName
);
1421 if (!descrW
) return E_OUTOFMEMORY
;
1426 hr
= IShellLinkW_SetDescription(&This
->IShellLinkW_iface
, descrW
);
1427 HeapFree(GetProcessHeap(), 0, descrW
);
1432 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
*iface
, LPSTR pszDir
,
1435 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1437 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1441 if( This
->sWorkDir
)
1442 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1443 pszDir
, cchMaxPath
, NULL
, NULL
);
1448 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
*iface
, LPCSTR pszDir
)
1450 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1454 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1456 dirW
= heap_strdupAtoW(pszDir
);
1457 if (!dirW
) return E_OUTOFMEMORY
;
1459 hr
= IShellLinkW_SetWorkingDirectory(&This
->IShellLinkW_iface
, dirW
);
1460 HeapFree(GetProcessHeap(), 0, dirW
);
1465 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
*iface
, LPSTR pszArgs
, INT cchMaxPath
)
1467 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1469 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1474 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1475 pszArgs
, cchMaxPath
, NULL
, NULL
);
1480 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
*iface
, LPCSTR pszArgs
)
1482 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1486 TRACE("(%p)->(args=%s)\n",This
, debugstr_a(pszArgs
));
1490 argsW
= heap_strdupAtoW(pszArgs
);
1491 if (!argsW
) return E_OUTOFMEMORY
;
1496 hr
= IShellLinkW_SetArguments(&This
->IShellLinkW_iface
, argsW
);
1497 HeapFree(GetProcessHeap(), 0, argsW
);
1502 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
*iface
, WORD
*pwHotkey
)
1504 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1505 return IShellLinkW_GetHotkey(&This
->IShellLinkW_iface
, pwHotkey
);
1508 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
*iface
, WORD wHotkey
)
1510 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1511 return IShellLinkW_SetHotkey(&This
->IShellLinkW_iface
, wHotkey
);
1514 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
*iface
, INT
*piShowCmd
)
1516 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1517 return IShellLinkW_GetShowCmd(&This
->IShellLinkW_iface
, piShowCmd
);
1520 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
*iface
, INT iShowCmd
)
1522 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1523 return IShellLinkW_SetShowCmd(&This
->IShellLinkW_iface
, iShowCmd
);
1526 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
*iface
, LPSTR pszIconPath
,
1527 INT cchIconPath
, INT
*piIcon
)
1529 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1531 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1533 *piIcon
= This
->iIcoNdx
;
1536 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1543 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
*iface
, LPCSTR pszIconPath
,
1546 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1550 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1552 pathW
= heap_strdupAtoW(pszIconPath
);
1553 if (!pathW
) return E_OUTOFMEMORY
;
1555 hr
= IShellLinkW_SetIconLocation(&This
->IShellLinkW_iface
, pathW
, iIcon
);
1556 HeapFree(GetProcessHeap(), 0, pathW
);
1561 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
*iface
, LPCSTR pszPathRel
,
1564 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1568 TRACE("(%p)->(path=%s %x)\n",This
, pszPathRel
, dwReserved
);
1570 pathW
= heap_strdupAtoW(pszPathRel
);
1571 if (!pathW
) return E_OUTOFMEMORY
;
1573 hr
= IShellLinkW_SetRelativePath(&This
->IShellLinkW_iface
, pathW
, dwReserved
);
1574 HeapFree(GetProcessHeap(), 0, pathW
);
1579 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
*iface
, HWND hwnd
, DWORD fFlags
)
1581 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1583 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1585 return IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, fFlags
);
1588 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
*iface
, LPCSTR pszFile
)
1590 IShellLinkImpl
*This
= impl_from_IShellLinkA(iface
);
1594 TRACE("(%p)->(path=%s)\n",This
, debugstr_a(pszFile
));
1596 if (!pszFile
) return E_INVALIDARG
;
1598 str
= heap_strdupAtoW(pszFile
);
1600 return E_OUTOFMEMORY
;
1602 r
= IShellLinkW_SetPath(&This
->IShellLinkW_iface
, str
);
1603 HeapFree( GetProcessHeap(), 0, str
);
1608 /**************************************************************************
1609 * IShellLink Implementation
1612 static const IShellLinkAVtbl slvt
=
1614 IShellLinkA_fnQueryInterface
,
1615 IShellLinkA_fnAddRef
,
1616 IShellLinkA_fnRelease
,
1617 IShellLinkA_fnGetPath
,
1618 IShellLinkA_fnGetIDList
,
1619 IShellLinkA_fnSetIDList
,
1620 IShellLinkA_fnGetDescription
,
1621 IShellLinkA_fnSetDescription
,
1622 IShellLinkA_fnGetWorkingDirectory
,
1623 IShellLinkA_fnSetWorkingDirectory
,
1624 IShellLinkA_fnGetArguments
,
1625 IShellLinkA_fnSetArguments
,
1626 IShellLinkA_fnGetHotkey
,
1627 IShellLinkA_fnSetHotkey
,
1628 IShellLinkA_fnGetShowCmd
,
1629 IShellLinkA_fnSetShowCmd
,
1630 IShellLinkA_fnGetIconLocation
,
1631 IShellLinkA_fnSetIconLocation
,
1632 IShellLinkA_fnSetRelativePath
,
1633 IShellLinkA_fnResolve
,
1634 IShellLinkA_fnSetPath
1638 /**************************************************************************
1639 * IShellLinkW_fnQueryInterface
1641 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1642 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1644 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1645 return ShellLink_QueryInterface( This
, riid
, ppvObj
);
1648 /******************************************************************************
1649 * IShellLinkW_fnAddRef
1651 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1653 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1654 ULONG ref
= InterlockedIncrement(&This
->ref
);
1656 TRACE("(%p)->(count=%u)\n", This
, ref
- 1);
1661 /******************************************************************************
1662 * IShellLinkW_fnRelease
1664 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1666 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1667 ULONG refCount
= InterlockedDecrement(&This
->ref
);
1669 TRACE("(%p)->(count=%u)\n", This
, refCount
+ 1);
1674 TRACE("-- destroying IShellLink(%p)\n",This
);
1676 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1677 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1678 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1679 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1680 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1681 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1682 HeapFree(GetProcessHeap(), 0, This
->sProduct
);
1683 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
1684 HeapFree(GetProcessHeap(), 0, This
->filepath
);
1687 IUnknown_Release( This
->site
);
1690 ILFree(This
->pPidl
);
1697 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1699 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1701 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1702 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1704 if (This
->sComponent
|| This
->sProduct
)
1710 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1712 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1717 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1719 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1721 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1728 *ppidl
= ILClone(This
->pPidl
);
1732 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1734 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1736 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1739 ILFree( This
->pPidl
);
1740 This
->pPidl
= ILClone( pidl
);
1744 This
->bDirty
= TRUE
;
1749 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1751 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1753 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1756 if( This
->sDescription
)
1757 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1762 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1764 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1766 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1768 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1771 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1772 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1773 if ( !This
->sDescription
)
1774 return E_OUTOFMEMORY
;
1776 lstrcpyW( This
->sDescription
, pszName
);
1779 This
->sDescription
= NULL
;
1780 This
->bDirty
= TRUE
;
1785 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1787 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1789 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1793 if( This
->sWorkDir
)
1794 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1799 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1801 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1803 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1805 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1806 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1807 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1808 if ( !This
->sWorkDir
)
1809 return E_OUTOFMEMORY
;
1810 lstrcpyW( This
->sWorkDir
, pszDir
);
1811 This
->bDirty
= TRUE
;
1816 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1818 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1820 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1825 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1830 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1832 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1834 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1836 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1839 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1840 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1842 return E_OUTOFMEMORY
;
1843 lstrcpyW( This
->sArgs
, pszArgs
);
1845 else This
->sArgs
= NULL
;
1847 This
->bDirty
= TRUE
;
1852 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1854 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1856 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1858 *pwHotkey
=This
->wHotKey
;
1863 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1865 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1867 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1869 This
->wHotKey
= wHotkey
;
1870 This
->bDirty
= TRUE
;
1875 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1877 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1879 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1881 *piShowCmd
= This
->iShowCmd
;
1886 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1888 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1890 TRACE("(%p)->(%d)\n", This
, iShowCmd
);
1892 This
->iShowCmd
= iShowCmd
;
1893 This
->bDirty
= TRUE
;
1898 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1900 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1902 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1904 *piIcon
= This
->iIcoNdx
;
1907 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1914 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1916 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1918 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1920 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1921 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1922 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1923 if ( !This
->sIcoPath
)
1924 return E_OUTOFMEMORY
;
1925 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1927 This
->iIcoNdx
= iIcon
;
1928 This
->bDirty
= TRUE
;
1933 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1935 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1937 TRACE("(%p)->(path=%s %x)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1939 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1940 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1941 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1942 if ( !This
->sPathRel
)
1943 return E_OUTOFMEMORY
;
1944 lstrcpyW( This
->sPathRel
, pszPathRel
);
1945 This
->bDirty
= TRUE
;
1947 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1950 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1955 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
1957 TRACE("(%p)->(hwnd=%p flags=%x)\n",This
, hwnd
, fFlags
);
1959 /*FIXME: use IResolveShellLink interface */
1961 if (!This
->sPath
&& This
->pPidl
) {
1962 WCHAR buffer
[MAX_PATH
];
1964 bSuccess
= SHGetPathFromIDListW(This
->pPidl
, buffer
);
1966 if (bSuccess
&& *buffer
) {
1967 This
->sPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1969 return E_OUTOFMEMORY
;
1971 lstrcpyW(This
->sPath
, buffer
);
1973 This
->bDirty
= TRUE
;
1975 hr
= S_OK
; /* don't report an error occurred while just caching information */
1978 if (!This
->sIcoPath
&& This
->sPath
) {
1979 This
->sIcoPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1980 if (!This
->sIcoPath
)
1981 return E_OUTOFMEMORY
;
1983 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1986 This
->bDirty
= TRUE
;
1992 static LPWSTR
ShellLink_GetAdvertisedArg(LPCWSTR str
)
2001 p
= strchrW( str
, ':' );
2005 ret
= HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR
)*(len
+1));
2008 memcpy( ret
, str
, sizeof(WCHAR
)*len
);
2013 static HRESULT
ShellLink_SetAdvertiseInfo(IShellLinkImpl
*This
, LPCWSTR str
)
2015 LPCWSTR szComponent
= NULL
, szProduct
= NULL
, p
;
2023 /* each segment must start with two colons */
2024 if( str
[0] != ':' || str
[1] != ':' )
2027 /* the last segment is just two colons */
2032 /* there must be a colon straight after a guid */
2033 p
= strchrW( str
, ':' );
2040 /* get the guid, and check it's validly formatted */
2041 memcpy( szGuid
, str
, sizeof(WCHAR
)*len
);
2043 r
= CLSIDFromString( szGuid
, &guid
);
2048 /* match it up to a guid that we care about */
2049 if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutComponent
) && !szComponent
)
2051 else if( IsEqualGUID( &guid
, &SHELL32_AdvtShortcutProduct
) && !szProduct
)
2056 /* skip to the next field */
2057 str
= strchrW( str
, ':' );
2062 /* we have to have a component for an advertised shortcut */
2066 This
->sComponent
= ShellLink_GetAdvertisedArg( szComponent
);
2067 This
->sProduct
= ShellLink_GetAdvertisedArg( szProduct
);
2069 TRACE("Component = %s\n", debugstr_w(This
->sComponent
));
2070 TRACE("Product = %s\n", debugstr_w(This
->sProduct
));
2075 static BOOL
ShellLink_GetVolumeInfo(LPCWSTR path
, volume_info
*volume
)
2077 const int label_sz
= sizeof volume
->label
/sizeof volume
->label
[0];
2078 WCHAR drive
[] = { path
[0], ':', '\\', 0 };
2081 volume
->type
= GetDriveTypeW(drive
);
2082 r
= GetVolumeInformationW(drive
, volume
->label
, label_sz
,
2083 &volume
->serial
, NULL
, NULL
, NULL
, 0);
2084 TRACE("r = %d type %d serial %08x name %s\n", r
,
2085 volume
->type
, volume
->serial
, debugstr_w(volume
->label
));
2089 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
2091 IShellLinkImpl
*This
= impl_from_IShellLinkW(iface
);
2092 WCHAR buffer
[MAX_PATH
];
2093 LPWSTR fname
, unquoted
= NULL
;
2097 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
2099 if (!pszFile
) return E_INVALIDARG
;
2101 /* quotes at the ends of the string are stripped */
2102 len
= lstrlenW(pszFile
);
2103 if (pszFile
[0] == '"' && pszFile
[len
-1] == '"')
2105 unquoted
= strdupW(pszFile
);
2106 PathUnquoteSpacesW(unquoted
);
2110 /* any other quote marks are invalid */
2111 if (strchrW(pszFile
, '"'))
2113 HeapFree(GetProcessHeap(), 0, unquoted
);
2117 HeapFree(GetProcessHeap(), 0, This
->sPath
);
2120 HeapFree(GetProcessHeap(), 0, This
->sComponent
);
2121 This
->sComponent
= NULL
;
2124 ILFree(This
->pPidl
);
2127 if (S_OK
!= ShellLink_SetAdvertiseInfo( This
, pszFile
))
2129 if (*pszFile
== '\0')
2131 else if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
2133 else if(!PathFileExistsW(buffer
) &&
2134 !SearchPathW(NULL
, pszFile
, NULL
, MAX_PATH
, buffer
, NULL
))
2137 This
->pPidl
= SHSimpleIDListFromPathW(pszFile
);
2138 ShellLink_GetVolumeInfo(buffer
, &This
->volume
);
2140 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
2141 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
2144 HeapFree(GetProcessHeap(), 0, unquoted
);
2145 return E_OUTOFMEMORY
;
2148 lstrcpyW(This
->sPath
, buffer
);
2150 This
->bDirty
= TRUE
;
2151 HeapFree(GetProcessHeap(), 0, unquoted
);
2156 /**************************************************************************
2157 * IShellLinkW Implementation
2160 static const IShellLinkWVtbl slvtw
=
2162 IShellLinkW_fnQueryInterface
,
2163 IShellLinkW_fnAddRef
,
2164 IShellLinkW_fnRelease
,
2165 IShellLinkW_fnGetPath
,
2166 IShellLinkW_fnGetIDList
,
2167 IShellLinkW_fnSetIDList
,
2168 IShellLinkW_fnGetDescription
,
2169 IShellLinkW_fnSetDescription
,
2170 IShellLinkW_fnGetWorkingDirectory
,
2171 IShellLinkW_fnSetWorkingDirectory
,
2172 IShellLinkW_fnGetArguments
,
2173 IShellLinkW_fnSetArguments
,
2174 IShellLinkW_fnGetHotkey
,
2175 IShellLinkW_fnSetHotkey
,
2176 IShellLinkW_fnGetShowCmd
,
2177 IShellLinkW_fnSetShowCmd
,
2178 IShellLinkW_fnGetIconLocation
,
2179 IShellLinkW_fnSetIconLocation
,
2180 IShellLinkW_fnSetRelativePath
,
2181 IShellLinkW_fnResolve
,
2182 IShellLinkW_fnSetPath
2185 static HRESULT WINAPI
2186 ShellLink_DataList_QueryInterface( IShellLinkDataList
* iface
, REFIID riid
, void** ppvObject
)
2188 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2189 return IShellLinkA_QueryInterface(&This
->IShellLinkA_iface
, riid
, ppvObject
);
2193 ShellLink_DataList_AddRef( IShellLinkDataList
* iface
)
2195 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2196 return IShellLinkA_AddRef(&This
->IShellLinkA_iface
);
2200 ShellLink_DataList_Release( IShellLinkDataList
* iface
)
2202 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2203 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2206 static HRESULT WINAPI
2207 ShellLink_AddDataBlock( IShellLinkDataList
* iface
, void* pDataBlock
)
2209 FIXME("(%p)->(%p): stub\n", iface
, pDataBlock
);
2213 static HRESULT WINAPI
2214 ShellLink_CopyDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
, void** ppDataBlock
)
2216 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2217 LPVOID block
= NULL
;
2220 TRACE("%p %08x %p\n", iface
, dwSig
, ppDataBlock
);
2224 case EXP_DARWIN_ID_SIG
:
2225 if (!This
->sComponent
)
2227 block
= shelllink_build_darwinid( This
->sComponent
, dwSig
);
2230 case EXP_SZ_LINK_SIG
:
2231 case NT_CONSOLE_PROPS_SIG
:
2232 case NT_FE_CONSOLE_PROPS_SIG
:
2233 case EXP_SPECIAL_FOLDER_SIG
:
2234 case EXP_SZ_ICON_SIG
:
2235 FIXME("valid but unhandled datablock %08x\n", dwSig
);
2238 ERR("unknown datablock %08x\n", dwSig
);
2240 *ppDataBlock
= block
;
2244 static HRESULT WINAPI
2245 ShellLink_RemoveDataBlock( IShellLinkDataList
* iface
, DWORD dwSig
)
2247 FIXME("(%p)->(%u): stub\n", iface
, dwSig
);
2251 static HRESULT WINAPI
2252 ShellLink_GetFlags( IShellLinkDataList
* iface
, DWORD
* pdwFlags
)
2254 IShellLinkImpl
*This
= impl_from_IShellLinkDataList(iface
);
2257 FIXME("(%p)->(%p): partially implemented\n", This
, pdwFlags
);
2259 /* FIXME: add more */
2261 flags
|= SLDF_HAS_ARGS
;
2262 if (This
->sComponent
)
2263 flags
|= SLDF_HAS_DARWINID
;
2265 flags
|= SLDF_HAS_ICONLOCATION
;
2267 flags
|= SLDF_HAS_LOGO3ID
;
2269 flags
|= SLDF_HAS_ID_LIST
;
2276 static HRESULT WINAPI
2277 ShellLink_SetFlags( IShellLinkDataList
* iface
, DWORD dwFlags
)
2279 FIXME("(%p)->(%u): stub\n", iface
, dwFlags
);
2283 static const IShellLinkDataListVtbl dlvt
=
2285 ShellLink_DataList_QueryInterface
,
2286 ShellLink_DataList_AddRef
,
2287 ShellLink_DataList_Release
,
2288 ShellLink_AddDataBlock
,
2289 ShellLink_CopyDataBlock
,
2290 ShellLink_RemoveDataBlock
,
2295 static HRESULT WINAPI
2296 ShellLink_ExtInit_QueryInterface( IShellExtInit
* iface
, REFIID riid
, void** ppvObject
)
2298 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2299 return IShellLinkA_QueryInterface(&This
->IShellLinkA_iface
, riid
, ppvObject
);
2303 ShellLink_ExtInit_AddRef( IShellExtInit
* iface
)
2305 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2306 return IShellLinkA_AddRef(&This
->IShellLinkA_iface
);
2310 ShellLink_ExtInit_Release( IShellExtInit
* iface
)
2312 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2313 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2316 /**************************************************************************
2317 * ShellLink implementation of IShellExtInit::Initialize()
2319 * Loads the shelllink from the dataobject the shell is pointing to.
2321 static HRESULT WINAPI
2322 ShellLink_ExtInit_Initialize( IShellExtInit
* iface
, LPCITEMIDLIST pidlFolder
,
2323 IDataObject
*pdtobj
, HKEY hkeyProgID
)
2325 IShellLinkImpl
*This
= impl_from_IShellExtInit(iface
);
2331 TRACE("%p %p %p %p\n", This
, pidlFolder
, pdtobj
, hkeyProgID
);
2336 format
.cfFormat
= CF_HDROP
;
2338 format
.dwAspect
= DVASPECT_CONTENT
;
2340 format
.tymed
= TYMED_HGLOBAL
;
2342 if( FAILED( IDataObject_GetData( pdtobj
, &format
, &stgm
) ) )
2345 count
= DragQueryFileW( stgm
.u
.hGlobal
, -1, NULL
, 0 );
2350 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, NULL
, 0 );
2352 path
= HeapAlloc( GetProcessHeap(), 0, count
*sizeof(WCHAR
) );
2355 IPersistFile
*pf
= &This
->IPersistFile_iface
;
2357 count
= DragQueryFileW( stgm
.u
.hGlobal
, 0, path
, count
);
2358 r
= IPersistFile_Load( pf
, path
, 0 );
2359 HeapFree( GetProcessHeap(), 0, path
);
2362 ReleaseStgMedium( &stgm
);
2367 static const IShellExtInitVtbl eivt
=
2369 ShellLink_ExtInit_QueryInterface
,
2370 ShellLink_ExtInit_AddRef
,
2371 ShellLink_ExtInit_Release
,
2372 ShellLink_ExtInit_Initialize
2375 static HRESULT WINAPI
2376 ShellLink_ContextMenu_QueryInterface( IContextMenu
* iface
, REFIID riid
, void** ppvObject
)
2378 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2379 return IShellLinkA_QueryInterface(&This
->IShellLinkA_iface
, riid
, ppvObject
);
2383 ShellLink_ContextMenu_AddRef( IContextMenu
* iface
)
2385 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2386 return IShellLinkA_AddRef(&This
->IShellLinkA_iface
);
2390 ShellLink_ContextMenu_Release( IContextMenu
* iface
)
2392 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2393 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2396 static HRESULT WINAPI
2397 ShellLink_QueryContextMenu( IContextMenu
* iface
, HMENU hmenu
, UINT indexMenu
,
2398 UINT idCmdFirst
, UINT idCmdLast
, UINT uFlags
)
2400 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2401 static WCHAR szOpen
[] = { 'O','p','e','n',0 };
2405 TRACE("%p %p %u %u %u %u\n", This
,
2406 hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
2409 return E_INVALIDARG
;
2411 memset( &mii
, 0, sizeof mii
);
2412 mii
.cbSize
= sizeof mii
;
2413 mii
.fMask
= MIIM_TYPE
| MIIM_ID
| MIIM_STATE
;
2414 mii
.dwTypeData
= szOpen
;
2415 mii
.cch
= strlenW( mii
.dwTypeData
);
2416 mii
.wID
= idCmdFirst
+ id
++;
2417 mii
.fState
= MFS_DEFAULT
| MFS_ENABLED
;
2418 mii
.fType
= MFT_STRING
;
2419 if (!InsertMenuItemW( hmenu
, indexMenu
, TRUE
, &mii
))
2423 return MAKE_HRESULT( SEVERITY_SUCCESS
, 0, id
);
2427 shelllink_get_msi_component_path( LPWSTR component
)
2432 r
= CommandLineFromMsiDescriptor( component
, NULL
, &sz
);
2433 if (r
!= ERROR_SUCCESS
)
2437 path
= HeapAlloc( GetProcessHeap(), 0, sz
*sizeof(WCHAR
) );
2438 r
= CommandLineFromMsiDescriptor( component
, path
, &sz
);
2439 if (r
!= ERROR_SUCCESS
)
2441 HeapFree( GetProcessHeap(), 0, path
);
2445 TRACE("returning %s\n", debugstr_w( path
) );
2450 static HRESULT WINAPI
2451 ShellLink_InvokeCommand( IContextMenu
* iface
, LPCMINVOKECOMMANDINFO lpici
)
2453 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2454 static const WCHAR szOpen
[] = { 'O','p','e','n',0 };
2455 SHELLEXECUTEINFOW sei
;
2456 HWND hwnd
= NULL
; /* FIXME: get using interface set from IObjectWithSite */
2461 TRACE("%p %p\n", This
, lpici
);
2463 if ( lpici
->cbSize
< sizeof (CMINVOKECOMMANDINFO
) )
2464 return E_INVALIDARG
;
2466 if ( lpici
->lpVerb
!= MAKEINTRESOURCEA(This
->iIdOpen
) )
2468 ERR("Unknown id %p != %d\n", lpici
->lpVerb
, This
->iIdOpen
);
2469 return E_INVALIDARG
;
2472 r
= IShellLinkW_Resolve(&This
->IShellLinkW_iface
, hwnd
, 0);
2476 if ( This
->sComponent
)
2478 path
= shelllink_get_msi_component_path( This
->sComponent
);
2483 path
= strdupW( This
->sPath
);
2485 if ( lpici
->cbSize
== sizeof (CMINVOKECOMMANDINFOEX
) &&
2486 ( lpici
->fMask
& CMIC_MASK_UNICODE
) )
2488 LPCMINVOKECOMMANDINFOEX iciex
= (LPCMINVOKECOMMANDINFOEX
) lpici
;
2492 len
+= lstrlenW( This
->sArgs
);
2493 if ( iciex
->lpParametersW
)
2494 len
+= lstrlenW( iciex
->lpParametersW
);
2496 args
= HeapAlloc( GetProcessHeap(), 0, len
*sizeof(WCHAR
) );
2499 lstrcatW( args
, This
->sArgs
);
2500 if ( iciex
->lpParametersW
)
2502 static const WCHAR space
[] = { ' ', 0 };
2503 lstrcatW( args
, space
);
2504 lstrcatW( args
, iciex
->lpParametersW
);
2508 memset( &sei
, 0, sizeof sei
);
2509 sei
.cbSize
= sizeof sei
;
2510 sei
.fMask
= SEE_MASK_UNICODE
| (lpici
->fMask
& (SEE_MASK_NOASYNC
|SEE_MASK_ASYNCOK
|SEE_MASK_FLAG_NO_UI
));
2512 sei
.nShow
= This
->iShowCmd
;
2513 sei
.lpIDList
= This
->pPidl
;
2514 sei
.lpDirectory
= This
->sWorkDir
;
2515 sei
.lpParameters
= args
;
2516 sei
.lpVerb
= szOpen
;
2518 if( ShellExecuteExW( &sei
) )
2523 HeapFree( GetProcessHeap(), 0, args
);
2524 HeapFree( GetProcessHeap(), 0, path
);
2529 static HRESULT WINAPI
2530 ShellLink_GetCommandString( IContextMenu
* iface
, UINT_PTR idCmd
, UINT uType
,
2531 UINT
* pwReserved
, LPSTR pszName
, UINT cchMax
)
2533 IShellLinkImpl
*This
= impl_from_IContextMenu(iface
);
2535 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This
,
2536 idCmd
, uType
, pwReserved
, pszName
, cchMax
);
2541 static const IContextMenuVtbl cmvt
=
2543 ShellLink_ContextMenu_QueryInterface
,
2544 ShellLink_ContextMenu_AddRef
,
2545 ShellLink_ContextMenu_Release
,
2546 ShellLink_QueryContextMenu
,
2547 ShellLink_InvokeCommand
,
2548 ShellLink_GetCommandString
2551 static HRESULT WINAPI
2552 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite
* iface
, REFIID riid
, void** ppvObject
)
2554 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2555 return ShellLink_QueryInterface( This
, riid
, ppvObject
);
2559 ShellLink_ObjectWithSite_AddRef( IObjectWithSite
* iface
)
2561 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2562 return IShellLinkW_AddRef(&This
->IShellLinkW_iface
);
2566 ShellLink_ObjectWithSite_Release( IObjectWithSite
* iface
)
2568 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2569 return IShellLinkW_Release(&This
->IShellLinkW_iface
);
2572 static HRESULT WINAPI
2573 ShellLink_GetSite( IObjectWithSite
*iface
, REFIID iid
, void ** ppvSite
)
2575 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2577 TRACE("%p %s %p\n", This
, debugstr_guid( iid
), ppvSite
);
2581 return IUnknown_QueryInterface( This
->site
, iid
, ppvSite
);
2584 static HRESULT WINAPI
2585 ShellLink_SetSite( IObjectWithSite
*iface
, IUnknown
*punk
)
2587 IShellLinkImpl
*This
= impl_from_IObjectWithSite(iface
);
2589 TRACE("%p %p\n", iface
, punk
);
2592 IUnknown_AddRef( punk
);
2595 IUnknown_Release( This
->site
);
2602 static const IObjectWithSiteVtbl owsvt
=
2604 ShellLink_ObjectWithSite_QueryInterface
,
2605 ShellLink_ObjectWithSite_AddRef
,
2606 ShellLink_ObjectWithSite_Release
,