3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Nearly complete informations about the binary formats
23 * of .lnk files available at http://www.wotsit.org
25 * You can use winedump to examine the contents of a link file:
28 * MSI advertised shortcuts are totally undocumented. They provide an
29 * icon for a program that is not yet installed, and invoke MSI to
30 * install the program when the shortcut is clicked on. They are
31 * created by passing a special string to SetPath, and the information
32 * in that string is parsed an stored.
36 #define NONAMELESSUNION
38 #include "wine/debug.h"
48 #include "undocshell.h"
51 #include "shell32_main.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(shell);
59 DEFINE_GUID( SHELL32_AdvtShortcutProduct,
60 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
61 DEFINE_GUID( SHELL32_AdvtShortcutComponent,
62 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
64 /* link file formats */
68 typedef struct _LINK_HEADER
70 DWORD dwSize; /* 0x00 size of the header - 0x4c */
71 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
72 DWORD dwFlags; /* 0x14 describes elements following */
73 DWORD dwFileAttr; /* 0x18 attributes of the target file */
74 FILETIME Time1; /* 0x1c */
75 FILETIME Time2; /* 0x24 */
76 FILETIME Time3; /* 0x2c */
77 DWORD dwFileLength; /* 0x34 File length */
78 DWORD nIcon; /* 0x38 icon number */
79 DWORD fStartup; /* 0x3c startup type */
80 DWORD wHotKey; /* 0x40 hotkey */
81 DWORD Unknown5; /* 0x44 */
82 DWORD Unknown6; /* 0x48 */
83 } LINK_HEADER, * PLINK_HEADER;
85 #define SHLINK_LOCAL 0
86 #define SHLINK_REMOTE 1
88 typedef struct _LOCATION_INFO
95 DWORD dwNetworkVolTableOfs;
99 typedef struct _LOCAL_VOLUME_INFO
107 typedef struct volume_info_t
111 WCHAR label[12]; /* assume 8.3 */
116 static const IShellLinkAVtbl slvt;
117 static const IShellLinkWVtbl slvtw;
118 static const IPersistFileVtbl pfvt;
119 static const IPersistStreamVtbl psvt;
120 static const IShellLinkDataListVtbl dlvt;
121 static const IShellExtInitVtbl eivt;
122 static const IContextMenuVtbl cmvt;
123 static const IObjectWithSiteVtbl owsvt;
125 /* IShellLink Implementation */
129 const IShellLinkAVtbl *lpVtbl;
130 const IShellLinkWVtbl *lpvtblw;
131 const IPersistFileVtbl *lpvtblPersistFile;
132 const IPersistStreamVtbl *lpvtblPersistStream;
133 const IShellLinkDataListVtbl *lpvtblShellLinkDataList;
134 const IShellExtInitVtbl *lpvtblShellExtInit;
135 const IContextMenuVtbl *lpvtblContextMenu;
136 const IObjectWithSiteVtbl *lpvtblObjectWithSite;
140 /* data structures according to the informations in the link */
163 static inline IShellLinkImpl *impl_from_IShellLinkW( IShellLinkW *iface )
165 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblw));
168 static inline IShellLinkImpl *impl_from_IPersistFile( IPersistFile *iface )
170 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblPersistFile));
173 static inline IShellLinkImpl *impl_from_IPersistStream( IPersistStream *iface )
175 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblPersistStream));
178 static inline IShellLinkImpl *impl_from_IShellLinkDataList( IShellLinkDataList *iface )
180 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblShellLinkDataList));
183 static inline IShellLinkImpl *impl_from_IShellExtInit( IShellExtInit *iface )
185 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblShellExtInit));
188 static inline IShellLinkImpl *impl_from_IContextMenu( IContextMenu *iface )
190 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblContextMenu));
193 static inline IShellLinkImpl *impl_from_IObjectWithSite( IObjectWithSite *iface )
195 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblObjectWithSite));
198 static HRESULT ShellLink_UpdatePath(LPWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath);
200 /* strdup on the process heap */
201 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str)
203 INT len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
204 LPWSTR p = HeapAlloc( heap, flags, len*sizeof (WCHAR) );
207 MultiByteToWideChar( CP_ACP, 0, str, -1, p, len );
211 /**************************************************************************
212 * ShellLink::QueryInterface implementation
214 static HRESULT ShellLink_QueryInterface( IShellLinkImpl *This, REFIID riid, LPVOID *ppvObj)
216 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
220 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IShellLinkA))
224 else if(IsEqualIID(riid, &IID_IShellLinkW))
226 *ppvObj = &(This->lpvtblw);
228 else if(IsEqualIID(riid, &IID_IPersistFile))
230 *ppvObj = &(This->lpvtblPersistFile);
232 else if(IsEqualIID(riid, &IID_IPersistStream))
234 *ppvObj = &(This->lpvtblPersistStream);
236 else if(IsEqualIID(riid, &IID_IShellLinkDataList))
238 *ppvObj = &(This->lpvtblShellLinkDataList);
240 else if(IsEqualIID(riid, &IID_IShellExtInit))
242 *ppvObj = &(This->lpvtblShellExtInit);
244 else if(IsEqualIID(riid, &IID_IContextMenu))
246 *ppvObj = &(This->lpvtblContextMenu);
248 else if(IsEqualIID(riid, &IID_IObjectWithSite))
250 *ppvObj = &(This->lpvtblObjectWithSite);
255 IUnknown_AddRef((IUnknown*)(*ppvObj));
256 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
259 ERR("-- Interface: E_NOINTERFACE\n");
260 return E_NOINTERFACE;
263 /**************************************************************************
264 * ShellLink::AddRef implementation
266 static ULONG ShellLink_AddRef( IShellLinkImpl *This )
268 ULONG refCount = InterlockedIncrement(&This->ref);
270 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
275 /**************************************************************************
276 * ShellLink::Release implementation
278 static ULONG ShellLink_Release( IShellLinkImpl *This )
280 ULONG refCount = InterlockedDecrement(&This->ref);
282 TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
287 TRACE("-- destroying IShellLink(%p)\n",This);
289 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
290 HeapFree(GetProcessHeap(), 0, This->sArgs);
291 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
292 HeapFree(GetProcessHeap(), 0, This->sDescription);
293 HeapFree(GetProcessHeap(),0,This->sPath);
296 IUnknown_Release( This->site );
301 LocalFree((HANDLE)This);
306 static HRESULT ShellLink_GetClassID( IShellLinkImpl *This, CLSID *pclsid )
308 TRACE("%p %p\n", This, pclsid);
310 memcpy( pclsid, &CLSID_ShellLink, sizeof (CLSID) );
314 /**************************************************************************
315 * IPersistFile_QueryInterface
317 static HRESULT WINAPI IPersistFile_fnQueryInterface(
322 IShellLinkImpl *This = impl_from_IPersistFile(iface);
323 return ShellLink_QueryInterface( This, riid, ppvObj );
326 /******************************************************************************
327 * IPersistFile_AddRef
329 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
331 IShellLinkImpl *This = impl_from_IPersistFile(iface);
332 return ShellLink_AddRef( This );
335 /******************************************************************************
336 * IPersistFile_Release
338 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
340 IShellLinkImpl *This = impl_from_IPersistFile(iface);
341 return IShellLinkA_Release((IShellLinkA*)This);
344 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
346 IShellLinkImpl *This = impl_from_IPersistFile(iface);
347 return ShellLink_GetClassID( This, pClassID );
350 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
352 IShellLinkImpl *This = impl_from_IPersistFile(iface);
354 TRACE("(%p)\n",This);
362 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
364 IShellLinkImpl *This = impl_from_IPersistFile(iface);
365 IPersistStream *StreamThis = (IPersistStream *)&This->lpvtblPersistStream;
369 TRACE("(%p, %s, %lx)\n",This, debugstr_w(pszFileName), dwMode);
372 dwMode = STGM_READ | STGM_SHARE_DENY_WRITE;
373 r = SHCreateStreamOnFileW(pszFileName, dwMode, &stm);
376 r = IPersistStream_Load(StreamThis, stm);
377 ShellLink_UpdatePath(This->sPathRel, pszFileName, This->sWorkDir, &This->sPath);
378 IStream_Release( stm );
379 This->bDirty = FALSE;
381 TRACE("-- returning hr %08lx\n", r);
385 static BOOL StartLinkProcessor( LPCOLESTR szLink )
387 static const WCHAR szFormat[] = {
388 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
389 ' ','-','r',' ','"','%','s','"',0 };
393 PROCESS_INFORMATION pi;
395 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
396 buffer = HeapAlloc( GetProcessHeap(), 0, len );
400 wsprintfW( buffer, szFormat, szLink );
402 TRACE("starting %s\n",debugstr_w(buffer));
404 memset(&si, 0, sizeof(si));
406 if (!CreateProcessW( NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return FALSE;
408 /* wait for a while to throttle the creation of linker processes */
409 if( WAIT_OBJECT_0 != WaitForSingleObject( pi.hProcess, 10000 ) )
410 WARN("Timed out waiting for shell linker\n");
412 CloseHandle( pi.hProcess );
413 CloseHandle( pi.hThread );
418 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
420 IShellLinkImpl *This = impl_from_IPersistFile(iface);
421 IPersistStream *StreamThis = (IPersistStream *)&This->lpvtblPersistStream;
425 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
430 r = SHCreateStreamOnFileW( pszFileName, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, &stm );
433 r = IPersistStream_Save(StreamThis, stm, FALSE);
434 IStream_Release( stm );
438 StartLinkProcessor( pszFileName );
440 This->bDirty = FALSE;
444 DeleteFileW( pszFileName );
445 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName) );
452 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
454 IShellLinkImpl *This = impl_from_IPersistFile(iface);
455 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
459 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
461 IShellLinkImpl *This = impl_from_IPersistFile(iface);
462 FIXME("(%p)\n",This);
466 static const IPersistFileVtbl pfvt =
468 IPersistFile_fnQueryInterface,
469 IPersistFile_fnAddRef,
470 IPersistFile_fnRelease,
471 IPersistFile_fnGetClassID,
472 IPersistFile_fnIsDirty,
475 IPersistFile_fnSaveCompleted,
476 IPersistFile_fnGetCurFile
479 /************************************************************************
480 * IPersistStream_QueryInterface
482 static HRESULT WINAPI IPersistStream_fnQueryInterface(
483 IPersistStream* iface,
487 IShellLinkImpl *This = impl_from_IPersistStream(iface);
488 return ShellLink_QueryInterface( This, riid, ppvObj );
491 /************************************************************************
492 * IPersistStream_Release
494 static ULONG WINAPI IPersistStream_fnRelease(
495 IPersistStream* iface)
497 IShellLinkImpl *This = impl_from_IPersistStream(iface);
498 return IShellLinkA_Release((IShellLinkA*)This);
501 /************************************************************************
502 * IPersistStream_AddRef
504 static ULONG WINAPI IPersistStream_fnAddRef(
505 IPersistStream* iface)
507 IShellLinkImpl *This = impl_from_IPersistStream(iface);
508 return ShellLink_AddRef( This );
511 /************************************************************************
512 * IPersistStream_GetClassID
515 static HRESULT WINAPI IPersistStream_fnGetClassID(
516 IPersistStream* iface,
519 IShellLinkImpl *This = impl_from_IPersistStream(iface);
520 return ShellLink_GetClassID( This, pClassID );
523 /************************************************************************
524 * IPersistStream_IsDirty (IPersistStream)
526 static HRESULT WINAPI IPersistStream_fnIsDirty(
527 IPersistStream* iface)
529 IShellLinkImpl *This = impl_from_IPersistStream(iface);
531 TRACE("(%p)\n", This);
537 static HRESULT Stream_LoadString( IStream* stm, BOOL unicode, LPWSTR *pstr )
548 r = IStream_Read(stm, &len, sizeof(len), &count);
549 if ( FAILED (r) || ( count != sizeof(len) ) )
553 len *= sizeof (WCHAR);
555 TRACE("reading %d\n", len);
556 temp = HeapAlloc(GetProcessHeap(), 0, len+sizeof(WCHAR));
558 return E_OUTOFMEMORY;
560 r = IStream_Read(stm, temp, len, &count);
561 if( FAILED (r) || ( count != len ) )
563 HeapFree( GetProcessHeap(), 0, temp );
567 TRACE("read %s\n", debugstr_an(temp,len));
569 /* convert to unicode if necessary */
572 count = MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, NULL, 0 );
573 str = HeapAlloc( GetProcessHeap(), 0, (count+1)*sizeof (WCHAR) );
575 MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, str, count );
576 HeapFree( GetProcessHeap(), 0, temp );
590 static HRESULT Stream_ReadChunk( IStream* stm, LPVOID *data )
597 unsigned char data[1];
602 r = IStream_Read( stm, &size, sizeof(size), &count );
603 if( FAILED( r ) || count != sizeof(size) )
606 chunk = HeapAlloc( GetProcessHeap(), 0, size );
608 return E_OUTOFMEMORY;
611 r = IStream_Read( stm, chunk->data, size - sizeof(size), &count );
612 if( FAILED( r ) || count != (size - sizeof(size)) )
614 HeapFree( GetProcessHeap(), 0, chunk );
618 TRACE("Read %ld bytes\n",chunk->size);
620 *data = (LPVOID) chunk;
625 static BOOL Stream_LoadVolume( LOCAL_VOLUME_INFO *vol, volume_info *volume )
627 const int label_sz = sizeof volume->label/sizeof volume->label[0];
631 volume->serial = vol->dwVolSerial;
632 volume->type = vol->dwType;
634 if( !vol->dwVolLabelOfs )
636 if( vol->dwSize <= vol->dwVolLabelOfs )
638 len = vol->dwSize - vol->dwVolLabelOfs;
641 label += vol->dwVolLabelOfs;
642 MultiByteToWideChar( CP_ACP, 0, label, len, volume->label, label_sz-1);
647 static LPWSTR Stream_LoadPath( LPSTR p, DWORD maxlen )
652 while( p[len] && (len < maxlen) )
655 wlen = MultiByteToWideChar(CP_ACP, 0, p, len, NULL, 0);
656 path = HeapAlloc(GetProcessHeap(), 0, (wlen+1)*sizeof(WCHAR));
657 MultiByteToWideChar(CP_ACP, 0, p, len, path, wlen);
663 static HRESULT Stream_LoadLocation( IStream *stm,
664 volume_info *volume, LPWSTR *path )
671 r = Stream_ReadChunk( stm, (LPVOID*) &p );
675 loc = (LOCATION_INFO*) p;
676 if (loc->dwTotalSize < sizeof(LOCATION_INFO))
678 HeapFree( GetProcessHeap(), 0, p );
682 /* if there's valid local volume information, load it */
683 if( loc->dwVolTableOfs &&
684 ((loc->dwVolTableOfs + sizeof(LOCAL_VOLUME_INFO)) <= loc->dwTotalSize) )
686 LOCAL_VOLUME_INFO *volume_info;
688 volume_info = (LOCAL_VOLUME_INFO*) &p[loc->dwVolTableOfs];
689 Stream_LoadVolume( volume_info, volume );
692 /* if there's a local path, load it */
693 n = loc->dwLocalPathOfs;
694 if( n && (n < loc->dwTotalSize) )
695 *path = Stream_LoadPath( &p[n], loc->dwTotalSize - n );
697 TRACE("type %ld serial %08lx name %s path %s\n", volume->type,
698 volume->serial, debugstr_w(volume->label), debugstr_w(*path));
700 HeapFree( GetProcessHeap(), 0, p );
705 * The format of the advertised shortcut info seems to be:
710 * 0 Length of the block (4 bytes, usually 0x314)
712 * 8 string data in ASCII
713 * 8+0x104 string data in UNICODE
715 * In the original Win32 implementation the buffers are not initialized
716 * to zero, so data trailing the string is random garbage.
718 static HRESULT Stream_LoadAdvertiseInfo( IStream* stm, LPWSTR *str )
723 EXP_DARWIN_LINK buffer;
727 r = IStream_Read( stm, &buffer.dbh.cbSize, sizeof (DWORD), &count );
731 /* make sure that we read the size of the structure even on error */
732 size = sizeof buffer - sizeof (DWORD);
733 if( buffer.dbh.cbSize != sizeof buffer )
735 ERR("Ooops. This structure is not as expected...\n");
739 r = IStream_Read( stm, &buffer.dbh.dwSignature, size, &count );
746 TRACE("magic %08lx string = %s\n", buffer.dbh.dwSignature, debugstr_w(buffer.szwDarwinID));
748 if( (buffer.dbh.dwSignature&0xffff0000) != 0xa0000000 )
750 ERR("Unknown magic number %08lx in advertised shortcut\n", buffer.dbh.dwSignature);
754 *str = HeapAlloc( GetProcessHeap(), 0,
755 (lstrlenW(buffer.szwDarwinID)+1) * sizeof(WCHAR) );
756 lstrcpyW( *str, buffer.szwDarwinID );
761 /************************************************************************
762 * IPersistStream_Load (IPersistStream)
764 static HRESULT WINAPI IPersistStream_fnLoad(
765 IPersistStream* iface,
774 IShellLinkImpl *This = impl_from_IPersistStream(iface);
776 TRACE("%p %p\n", This, stm);
779 return STG_E_INVALIDPOINTER;
782 r = IStream_Read(stm, &hdr, sizeof(hdr), &dwBytesRead);
786 if( dwBytesRead != sizeof(hdr))
788 if( hdr.dwSize != sizeof(hdr))
790 if( !IsEqualIID(&hdr.MagicGuid, &CLSID_ShellLink) )
793 /* free all the old stuff */
796 memset( &This->volume, 0, sizeof This->volume );
797 HeapFree(GetProcessHeap(), 0, This->sPath);
799 HeapFree(GetProcessHeap(), 0, This->sDescription);
800 This->sDescription = NULL;
801 HeapFree(GetProcessHeap(), 0, This->sPathRel);
802 This->sPathRel = NULL;
803 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
804 This->sWorkDir = NULL;
805 HeapFree(GetProcessHeap(), 0, This->sArgs);
807 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
808 This->sIcoPath = NULL;
809 HeapFree(GetProcessHeap(), 0, This->sProduct);
810 This->sProduct = NULL;
811 HeapFree(GetProcessHeap(), 0, This->sComponent);
812 This->sComponent = NULL;
814 This->wHotKey = (WORD)hdr.wHotKey;
815 This->iIcoNdx = hdr.nIcon;
816 FileTimeToSystemTime (&hdr.Time1, &This->time1);
817 FileTimeToSystemTime (&hdr.Time2, &This->time2);
818 FileTimeToSystemTime (&hdr.Time3, &This->time3);
821 WCHAR sTemp[MAX_PATH];
822 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time1,
823 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
824 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
825 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time2,
826 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
827 TRACE("-- time2: %s\n", debugstr_w(sTemp) );
828 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time3,
829 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
830 TRACE("-- time3: %s\n", debugstr_w(sTemp) );
833 /* load all the new stuff */
834 if( hdr.dwFlags & SLDF_HAS_ID_LIST )
836 r = ILLoadFromStream( stm, &This->pPidl );
842 /* load the location information */
843 if( hdr.dwFlags & SLDF_HAS_LINK_INFO )
844 r = Stream_LoadLocation( stm, &This->volume, &This->sPath );
848 unicode = hdr.dwFlags & SLDF_UNICODE;
849 if( hdr.dwFlags & SLDF_HAS_NAME )
851 r = Stream_LoadString( stm, unicode, &This->sDescription );
852 TRACE("Description -> %s\n",debugstr_w(This->sDescription));
857 if( hdr.dwFlags & SLDF_HAS_RELPATH )
859 r = Stream_LoadString( stm, unicode, &This->sPathRel );
860 TRACE("Relative Path-> %s\n",debugstr_w(This->sPathRel));
865 if( hdr.dwFlags & SLDF_HAS_WORKINGDIR )
867 r = Stream_LoadString( stm, unicode, &This->sWorkDir );
868 TRACE("Working Dir -> %s\n",debugstr_w(This->sWorkDir));
873 if( hdr.dwFlags & SLDF_HAS_ARGS )
875 r = Stream_LoadString( stm, unicode, &This->sArgs );
876 TRACE("Working Dir -> %s\n",debugstr_w(This->sArgs));
881 if( hdr.dwFlags & SLDF_HAS_ICONLOCATION )
883 r = Stream_LoadString( stm, unicode, &This->sIcoPath );
884 TRACE("Icon file -> %s\n",debugstr_w(This->sIcoPath));
889 if( hdr.dwFlags & SLDF_HAS_LOGO3ID )
891 r = Stream_LoadAdvertiseInfo( stm, &This->sProduct );
892 TRACE("Product -> %s\n",debugstr_w(This->sProduct));
897 if( hdr.dwFlags & SLDF_HAS_DARWINID )
899 r = Stream_LoadAdvertiseInfo( stm, &This->sComponent );
900 TRACE("Component -> %s\n",debugstr_w(This->sComponent));
905 r = IStream_Read(stm, &zero, sizeof zero, &dwBytesRead);
906 if( FAILED( r ) || zero || dwBytesRead != sizeof zero )
907 ERR("Last word was not zero\n");
918 /************************************************************************
921 * Helper function for IPersistStream_Save. Writes a unicode string
922 * with terminating nul byte to a stream, preceded by the its length.
924 static HRESULT Stream_WriteString( IStream* stm, LPCWSTR str )
926 USHORT len = lstrlenW( str ) + 1;
930 r = IStream_Write( stm, &len, sizeof(len), &count );
934 len *= sizeof(WCHAR);
936 r = IStream_Write( stm, str, len, &count );
943 /************************************************************************
944 * Stream_WriteLocationInfo
946 * Writes the location info to a stream
948 * FIXME: One day we might want to write the network volume information
949 * and the final path.
950 * Figure out how Windows deals with unicode paths here.
952 static HRESULT Stream_WriteLocationInfo( IStream* stm, LPCWSTR path,
953 volume_info *volume )
955 DWORD total_size, path_size, volume_info_size, label_size, final_path_size;
956 LOCAL_VOLUME_INFO *vol;
958 LPSTR szLabel, szPath, szFinalPath;
961 TRACE("%p %s %p\n", stm, debugstr_w(path), volume);
963 /* figure out the size of everything */
964 label_size = WideCharToMultiByte( CP_ACP, 0, volume->label, -1,
965 NULL, 0, NULL, NULL );
966 path_size = WideCharToMultiByte( CP_ACP, 0, path, -1,
967 NULL, 0, NULL, NULL );
968 volume_info_size = sizeof *vol + label_size;
970 total_size = sizeof *loc + volume_info_size + path_size + final_path_size;
972 /* create pointers to everything */
973 loc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, total_size);
974 vol = (LOCAL_VOLUME_INFO*) &loc[1];
975 szLabel = (LPSTR) &vol[1];
976 szPath = &szLabel[label_size];
977 szFinalPath = &szPath[path_size];
979 /* fill in the location information header */
980 loc->dwTotalSize = total_size;
981 loc->dwHeaderSize = sizeof (*loc);
983 loc->dwVolTableOfs = sizeof (*loc);
984 loc->dwLocalPathOfs = sizeof (*loc) + volume_info_size;
985 loc->dwNetworkVolTableOfs = 0;
986 loc->dwFinalPathOfs = sizeof (*loc) + volume_info_size + path_size;
988 /* fill in the volume information */
989 vol->dwSize = volume_info_size;
990 vol->dwType = volume->type;
991 vol->dwVolSerial = volume->serial;
992 vol->dwVolLabelOfs = sizeof (*vol);
994 /* copy in the strings */
995 WideCharToMultiByte( CP_ACP, 0, volume->label, -1,
996 szLabel, label_size, NULL, NULL );
997 WideCharToMultiByte( CP_ACP, 0, path, -1,
998 szPath, path_size, NULL, NULL );
1001 return IStream_Write( stm, loc, total_size, &count );
1004 static HRESULT Stream_WriteAdvertiseInfo( IStream* stm, LPCWSTR string, DWORD magic )
1007 EXP_DARWIN_LINK buffer;
1011 memset( &buffer, 0, sizeof buffer );
1012 buffer.dbh.cbSize = sizeof buffer;
1013 buffer.dbh.dwSignature = magic;
1014 lstrcpynW( buffer.szwDarwinID, string, MAX_PATH );
1015 WideCharToMultiByte(CP_ACP, 0, string, -1, buffer.szDarwinID, MAX_PATH, NULL, NULL );
1017 return IStream_Write( stm, &buffer, buffer.dbh.cbSize, &count );
1020 /************************************************************************
1021 * IPersistStream_Save (IPersistStream)
1023 * FIXME: makes assumptions about byte order
1025 static HRESULT WINAPI IPersistStream_fnSave(
1026 IPersistStream* iface,
1030 static const WCHAR wOpen[] = {'o','p','e','n',0};
1033 WCHAR exePath[MAX_PATH];
1038 IShellLinkImpl *This = impl_from_IPersistStream(iface);
1040 TRACE("%p %p %x\n", This, stm, fClearDirty);
1046 SHELL_FindExecutable(NULL, This->sPath, wOpen, exePath, MAX_PATH,
1047 NULL, NULL, NULL, NULL);
1049 * windows can create lnk files to executables that do not exist yet
1050 * so if the executable does not exist the just trust the path they
1053 if (!*exePath) lstrcpyW(exePath,This->sPath);
1056 memset(&header, 0, sizeof(header));
1057 header.dwSize = sizeof(header);
1058 header.fStartup = This->iShowCmd;
1059 memcpy(&header.MagicGuid, &CLSID_ShellLink, sizeof(header.MagicGuid) );
1061 header.wHotKey = This->wHotKey;
1062 header.nIcon = This->iIcoNdx;
1063 header.dwFlags = SLDF_UNICODE; /* strings are in unicode */
1065 header.dwFlags |= SLDF_HAS_ID_LIST;
1067 header.dwFlags |= SLDF_HAS_LINK_INFO;
1068 if( This->sDescription )
1069 header.dwFlags |= SLDF_HAS_NAME;
1070 if( This->sWorkDir )
1071 header.dwFlags |= SLDF_HAS_WORKINGDIR;
1073 header.dwFlags |= SLDF_HAS_ARGS;
1074 if( This->sIcoPath )
1075 header.dwFlags |= SLDF_HAS_ICONLOCATION;
1076 if( This->sProduct )
1077 header.dwFlags |= SLDF_HAS_LOGO3ID;
1078 if( This->sComponent )
1079 header.dwFlags |= SLDF_HAS_DARWINID;
1081 SystemTimeToFileTime ( &This->time1, &header.Time1 );
1082 SystemTimeToFileTime ( &This->time2, &header.Time2 );
1083 SystemTimeToFileTime ( &This->time3, &header.Time3 );
1085 /* write the Shortcut header */
1086 r = IStream_Write( stm, &header, sizeof(header), &count );
1089 ERR("Write failed at %d\n",__LINE__);
1093 TRACE("Writing pidl \n");
1095 /* write the PIDL to the shortcut */
1098 r = ILSaveToStream( stm, This->pPidl );
1101 ERR("Failed to write PIDL at %d\n",__LINE__);
1107 Stream_WriteLocationInfo( stm, exePath, &This->volume );
1109 if( This->sDescription )
1110 r = Stream_WriteString( stm, This->sDescription );
1112 if( This->sPathRel )
1113 r = Stream_WriteString( stm, This->sPathRel );
1115 if( This->sWorkDir )
1116 r = Stream_WriteString( stm, This->sWorkDir );
1119 r = Stream_WriteString( stm, This->sArgs );
1121 if( This->sIcoPath )
1122 r = Stream_WriteString( stm, This->sIcoPath );
1124 if( This->sProduct )
1125 r = Stream_WriteAdvertiseInfo( stm, This->sProduct, EXP_SZ_ICON_SIG );
1127 if( This->sComponent )
1128 r = Stream_WriteAdvertiseInfo( stm, This->sComponent, EXP_DARWIN_ID_SIG );
1130 /* the last field is a single zero dword */
1132 r = IStream_Write( stm, &zero, sizeof zero, &count );
1137 /************************************************************************
1138 * IPersistStream_GetSizeMax (IPersistStream)
1140 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
1141 IPersistStream* iface,
1142 ULARGE_INTEGER* pcbSize)
1144 IShellLinkImpl *This = impl_from_IPersistStream(iface);
1146 TRACE("(%p)\n", This);
1151 static const IPersistStreamVtbl psvt =
1153 IPersistStream_fnQueryInterface,
1154 IPersistStream_fnAddRef,
1155 IPersistStream_fnRelease,
1156 IPersistStream_fnGetClassID,
1157 IPersistStream_fnIsDirty,
1158 IPersistStream_fnLoad,
1159 IPersistStream_fnSave,
1160 IPersistStream_fnGetSizeMax
1163 /**************************************************************************
1164 * IShellLink_Constructor
1166 HRESULT WINAPI IShellLink_Constructor( IUnknown *pUnkOuter,
1167 REFIID riid, LPVOID *ppv )
1169 IShellLinkImpl * sl;
1172 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
1177 return CLASS_E_NOAGGREGATION;
1178 sl = LocalAlloc(LMEM_ZEROINIT,sizeof(IShellLinkImpl));
1180 return E_OUTOFMEMORY;
1184 sl->lpvtblw = &slvtw;
1185 sl->lpvtblPersistFile = &pfvt;
1186 sl->lpvtblPersistStream = &psvt;
1187 sl->lpvtblShellLinkDataList = &dlvt;
1188 sl->lpvtblShellExtInit = &eivt;
1189 sl->lpvtblContextMenu = &cmvt;
1190 sl->lpvtblObjectWithSite = &owsvt;
1191 sl->iShowCmd = SW_SHOWNORMAL;
1195 TRACE("(%p)->()\n",sl);
1197 r = ShellLink_QueryInterface( sl, riid, ppv );
1198 ShellLink_Release( sl );
1203 static BOOL SHELL_ExistsFileW(LPCWSTR path)
1205 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(path))
1210 /**************************************************************************
1211 * ShellLink_UpdatePath
1212 * update absolute path in sPath using relative path in sPathRel
1214 static HRESULT ShellLink_UpdatePath(LPWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath)
1216 if (!path || !psPath)
1217 return E_INVALIDARG;
1219 if (!*psPath && sPathRel) {
1220 WCHAR buffer[2*MAX_PATH], abs_path[2*MAX_PATH];
1221 LPWSTR final = NULL;
1223 /* first try if [directory of link file] + [relative path] finds an existing file */
1225 GetFullPathNameW( path, MAX_PATH*2, buffer, &final );
1228 lstrcpyW(final, sPathRel);
1232 if (SHELL_ExistsFileW(buffer)) {
1233 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1234 lstrcpyW(abs_path, buffer);
1236 /* try if [working directory] + [relative path] finds an existing file */
1238 lstrcpyW(buffer, sWorkDir);
1239 lstrcpyW(PathAddBackslashW(buffer), sPathRel);
1241 if (SHELL_ExistsFileW(buffer))
1242 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1243 lstrcpyW(abs_path, buffer);
1247 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1249 lstrcpyW(abs_path, sPathRel);
1251 *psPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path)+1)*sizeof(WCHAR));
1253 return E_OUTOFMEMORY;
1255 lstrcpyW(*psPath, abs_path);
1261 /**************************************************************************
1262 * IShellLink_ConstructFromFile
1264 HRESULT WINAPI IShellLink_ConstructFromFile( IUnknown* pUnkOuter, REFIID riid,
1265 LPCITEMIDLIST pidl, LPVOID* ppv)
1269 HRESULT hr = IShellLink_Constructor(NULL, riid, (LPVOID*)&psl);
1271 if (SUCCEEDED(hr)) {
1276 hr = IShellLinkW_QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf);
1278 if (SUCCEEDED(hr)) {
1279 WCHAR path[MAX_PATH];
1281 if (SHGetPathFromIDListW(pidl, path))
1282 hr = IPersistFile_Load(ppf, path, 0);
1287 *ppv = (IUnknown*) psl;
1289 IPersistFile_Release(ppf);
1293 IShellLinkW_Release(psl);
1299 /**************************************************************************
1300 * IShellLinkA_QueryInterface
1302 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
1304 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1305 return ShellLink_QueryInterface( This, riid, ppvObj );
1308 /******************************************************************************
1309 * IShellLinkA_AddRef
1311 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
1313 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1314 return ShellLink_AddRef( This );
1317 /******************************************************************************
1318 * IShellLinkA_Release
1320 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
1322 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1323 return ShellLink_Release( This );
1326 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,
1327 INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1329 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1331 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1332 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
1334 if (This->sComponent || This->sProduct)
1340 WideCharToMultiByte( CP_ACP, 0, This->sPath, -1,
1341 pszFile, cchMaxPath, NULL, NULL);
1343 if (pfd) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This);
1348 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1350 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1352 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1354 return IShellLinkW_GetIDList((IShellLinkW*)&(This->lpvtblw), ppidl);
1357 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1359 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1361 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1364 ILFree(This->pPidl);
1365 This->pPidl = ILClone (pidl);
1366 This->bDirty = TRUE;
1371 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1373 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1375 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1379 if( This->sDescription )
1380 WideCharToMultiByte( CP_ACP, 0, This->sDescription, -1,
1381 pszName, cchMaxName, NULL, NULL);
1386 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1388 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1390 TRACE("(%p)->(pName=%s)\n", This, pszName);
1392 HeapFree(GetProcessHeap(), 0, This->sDescription);
1393 This->sDescription = HEAP_strdupAtoW( GetProcessHeap(), 0, pszName);
1394 if ( !This->sDescription )
1395 return E_OUTOFMEMORY;
1397 This->bDirty = TRUE;
1402 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1404 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1406 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1410 if( This->sWorkDir )
1411 WideCharToMultiByte( CP_ACP, 0, This->sWorkDir, -1,
1412 pszDir, cchMaxPath, NULL, NULL);
1417 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1419 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1421 TRACE("(%p)->(dir=%s)\n",This, pszDir);
1423 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1424 This->sWorkDir = HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir);
1425 if ( !This->sWorkDir )
1426 return E_OUTOFMEMORY;
1428 This->bDirty = TRUE;
1433 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1435 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1437 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1442 WideCharToMultiByte( CP_ACP, 0, This->sArgs, -1,
1443 pszArgs, cchMaxPath, NULL, NULL);
1448 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1450 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1452 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1454 HeapFree(GetProcessHeap(), 0, This->sArgs);
1455 This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs);
1457 return E_OUTOFMEMORY;
1459 This->bDirty = TRUE;
1464 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1466 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1468 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1470 *pwHotkey = This->wHotKey;
1475 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1477 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1479 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1481 This->wHotKey = wHotkey;
1482 This->bDirty = TRUE;
1487 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1489 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1491 TRACE("(%p)->(%p)\n",This, piShowCmd);
1492 *piShowCmd = This->iShowCmd;
1496 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1498 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1500 TRACE("(%p) %d\n",This, iShowCmd);
1502 This->iShowCmd = iShowCmd;
1503 This->bDirty = TRUE;
1508 static HRESULT SHELL_PidlGeticonLocationA(IShellFolder* psf, LPITEMIDLIST pidl, LPSTR pszIconPath, int cchIconPath, int* piIcon)
1510 LPCITEMIDLIST pidlLast;
1512 HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
1514 if (SUCCEEDED(hr)) {
1517 hr = IShellFolder_GetUIObjectOf(psf, 0, 1, (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconA, NULL, (LPVOID*)&pei);
1519 if (SUCCEEDED(hr)) {
1520 hr = IExtractIconA_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
1522 IExtractIconA_Release(pei);
1525 IShellFolder_Release(psf);
1531 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1533 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1535 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1538 *piIcon = This->iIcoNdx;
1542 WideCharToMultiByte(CP_ACP, 0, This->sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL);
1546 if (This->pPidl || This->sPath)
1550 HRESULT hr = SHGetDesktopFolder(&pdsk);
1554 /* first look for an icon using the PIDL (if present) */
1556 hr = SHELL_PidlGeticonLocationA(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
1560 /* if we couldn't find an icon yet, look for it using the file system path */
1561 if (FAILED(hr) && This->sPath)
1565 hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
1567 if (SUCCEEDED(hr)) {
1568 hr = SHELL_PidlGeticonLocationA(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
1574 IShellFolder_Release(pdsk);
1582 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1584 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1586 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1588 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1589 This->sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1590 if ( !This->sIcoPath )
1591 return E_OUTOFMEMORY;
1593 This->iIcoNdx = iIcon;
1594 This->bDirty = TRUE;
1599 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1601 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1603 TRACE("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1605 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1606 This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1607 This->bDirty = TRUE;
1609 return ShellLink_UpdatePath(This->sPathRel, This->sPath, This->sWorkDir, &This->sPath);
1612 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1614 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1616 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1618 return IShellLinkW_Resolve( (IShellLinkW*)&(This->lpvtblw), hwnd, fFlags );
1621 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1625 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1627 TRACE("(%p)->(path=%s)\n",This, pszFile);
1629 str = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1631 return E_OUTOFMEMORY;
1633 r = IShellLinkW_SetPath((IShellLinkW*)&(This->lpvtblw), str);
1634 HeapFree( GetProcessHeap(), 0, str );
1639 /**************************************************************************
1640 * IShellLink Implementation
1643 static const IShellLinkAVtbl slvt =
1645 IShellLinkA_fnQueryInterface,
1646 IShellLinkA_fnAddRef,
1647 IShellLinkA_fnRelease,
1648 IShellLinkA_fnGetPath,
1649 IShellLinkA_fnGetIDList,
1650 IShellLinkA_fnSetIDList,
1651 IShellLinkA_fnGetDescription,
1652 IShellLinkA_fnSetDescription,
1653 IShellLinkA_fnGetWorkingDirectory,
1654 IShellLinkA_fnSetWorkingDirectory,
1655 IShellLinkA_fnGetArguments,
1656 IShellLinkA_fnSetArguments,
1657 IShellLinkA_fnGetHotkey,
1658 IShellLinkA_fnSetHotkey,
1659 IShellLinkA_fnGetShowCmd,
1660 IShellLinkA_fnSetShowCmd,
1661 IShellLinkA_fnGetIconLocation,
1662 IShellLinkA_fnSetIconLocation,
1663 IShellLinkA_fnSetRelativePath,
1664 IShellLinkA_fnResolve,
1665 IShellLinkA_fnSetPath
1669 /**************************************************************************
1670 * IShellLinkW_fnQueryInterface
1672 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1673 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1675 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1676 return ShellLink_QueryInterface( This, riid, ppvObj );
1679 /******************************************************************************
1680 * IShellLinkW_fnAddRef
1682 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1684 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1685 return ShellLink_AddRef( This );
1688 /******************************************************************************
1689 * IShellLinkW_fnRelease
1691 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1693 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1694 return ShellLink_Release( This );
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=%lu)(%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);
1725 *ppidl = ILClone(This->pPidl);
1729 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1731 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1733 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1736 ILFree( This->pPidl );
1737 This->pPidl = ILClone( pidl );
1741 This->bDirty = TRUE;
1746 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1748 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1750 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1753 if( This->sDescription )
1754 lstrcpynW( pszName, This->sDescription, cchMaxName );
1759 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1761 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1763 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1765 HeapFree(GetProcessHeap(), 0, This->sDescription);
1766 This->sDescription = HeapAlloc( GetProcessHeap(), 0,
1767 (lstrlenW( pszName )+1)*sizeof(WCHAR) );
1768 if ( !This->sDescription )
1769 return E_OUTOFMEMORY;
1771 lstrcpyW( This->sDescription, pszName );
1772 This->bDirty = TRUE;
1777 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1779 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1781 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1785 if( This->sWorkDir )
1786 lstrcpynW( pszDir, This->sWorkDir, cchMaxPath );
1791 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1793 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1795 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1797 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1798 This->sWorkDir = HeapAlloc( GetProcessHeap(), 0,
1799 (lstrlenW( pszDir )+1)*sizeof (WCHAR) );
1800 if ( !This->sWorkDir )
1801 return E_OUTOFMEMORY;
1802 lstrcpyW( This->sWorkDir, pszDir );
1803 This->bDirty = TRUE;
1808 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1810 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1812 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1817 lstrcpynW( pszArgs, This->sArgs, cchMaxPath );
1822 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1824 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1826 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1828 HeapFree(GetProcessHeap(), 0, This->sArgs);
1829 This->sArgs = HeapAlloc( GetProcessHeap(), 0,
1830 (lstrlenW( pszArgs )+1)*sizeof (WCHAR) );
1832 return E_OUTOFMEMORY;
1833 lstrcpyW( This->sArgs, pszArgs );
1834 This->bDirty = TRUE;
1839 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1841 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1843 TRACE("(%p)->(%p)\n",This, pwHotkey);
1845 *pwHotkey=This->wHotKey;
1850 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1852 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1854 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1856 This->wHotKey = wHotkey;
1857 This->bDirty = TRUE;
1862 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1864 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1866 TRACE("(%p)->(%p)\n",This, piShowCmd);
1868 *piShowCmd = This->iShowCmd;
1873 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1875 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1877 This->iShowCmd = iShowCmd;
1878 This->bDirty = TRUE;
1883 static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPITEMIDLIST pidl, LPWSTR pszIconPath, int cchIconPath, int* piIcon)
1885 LPCITEMIDLIST pidlLast;
1887 HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
1889 if (SUCCEEDED(hr)) {
1892 hr = IShellFolder_GetUIObjectOf(psf, 0, 1, (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW, NULL, (LPVOID*)&pei);
1894 if (SUCCEEDED(hr)) {
1895 hr = IExtractIconW_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
1897 IExtractIconW_Release(pei);
1900 IShellFolder_Release(psf);
1906 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1908 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1910 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1913 *piIcon = This->iIcoNdx;
1917 lstrcpynW(pszIconPath, This->sIcoPath, cchIconPath);
1921 if (This->pPidl || This->sPath)
1925 HRESULT hr = SHGetDesktopFolder(&pdsk);
1929 /* first look for an icon using the PIDL (if present) */
1931 hr = SHELL_PidlGeticonLocationW(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
1935 /* if we couldn't find an icon yet, look for it using the file system path */
1936 if (FAILED(hr) && This->sPath)
1940 hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
1944 hr = SHELL_PidlGeticonLocationW(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
1950 IShellFolder_Release(pdsk);
1957 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1959 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1961 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1963 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1964 This->sIcoPath = HeapAlloc( GetProcessHeap(), 0,
1965 (lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
1966 if ( !This->sIcoPath )
1967 return E_OUTOFMEMORY;
1968 lstrcpyW( This->sIcoPath, pszIconPath );
1970 This->iIcoNdx = iIcon;
1971 This->bDirty = TRUE;
1976 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1978 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1980 TRACE("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1982 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1983 This->sPathRel = HeapAlloc( GetProcessHeap(), 0,
1984 (lstrlenW( pszPathRel )+1) * sizeof (WCHAR) );
1985 if ( !This->sPathRel )
1986 return E_OUTOFMEMORY;
1987 lstrcpyW( This->sPathRel, pszPathRel );
1988 This->bDirty = TRUE;
1990 return ShellLink_UpdatePath(This->sPathRel, This->sPath, This->sWorkDir, &This->sPath);
1993 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1998 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
2000 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
2002 /*FIXME: use IResolveShellLink interface */
2004 if (!This->sPath && This->pPidl) {
2005 WCHAR buffer[MAX_PATH];
2007 bSuccess = SHGetPathFromIDListW(This->pPidl, buffer);
2009 if (bSuccess && *buffer) {
2010 This->sPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer)+1)*sizeof(WCHAR));
2012 return E_OUTOFMEMORY;
2014 lstrcpyW(This->sPath, buffer);
2016 This->bDirty = TRUE;
2018 hr = S_OK; /* don't report an error occurred while just caching information */
2021 if (!This->sIcoPath && This->sPath) {
2022 This->sIcoPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This->sPath)+1)*sizeof(WCHAR));
2023 if (!This->sIcoPath)
2024 return E_OUTOFMEMORY;
2026 lstrcpyW(This->sIcoPath, This->sPath);
2029 This->bDirty = TRUE;
2035 static LPWSTR ShellLink_GetAdvertisedArg(LPCWSTR str)
2044 p = strchrW( str, ':' );
2048 ret = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
2051 memcpy( ret, str, sizeof(WCHAR)*len );
2056 static HRESULT ShellLink_SetAdvertiseInfo(IShellLinkImpl *This, LPCWSTR str)
2058 LPCWSTR szComponent = NULL, szProduct = NULL, p;
2066 /* each segment must start with two colons */
2067 if( str[0] != ':' || str[1] != ':' )
2070 /* the last segment is just two colons */
2075 /* there must be a colon straight after a guid */
2076 p = strchrW( str, ':' );
2083 /* get the guid, and check it's validly formatted */
2084 memcpy( szGuid, str, sizeof(WCHAR)*len );
2086 r = CLSIDFromString( szGuid, &guid );
2091 /* match it up to a guid that we care about */
2092 if( IsEqualGUID( &guid, &SHELL32_AdvtShortcutComponent ) && !szComponent )
2094 else if( IsEqualGUID( &guid, &SHELL32_AdvtShortcutProduct ) && !szProduct )
2099 /* skip to the next field */
2100 str = strchrW( str, ':' );
2105 /* we have to have a component for an advertised shortcut */
2109 This->sComponent = ShellLink_GetAdvertisedArg( szComponent );
2110 This->sProduct = ShellLink_GetAdvertisedArg( szProduct );
2112 TRACE("Component = %s\n", debugstr_w(This->sComponent));
2113 TRACE("Product = %s\n", debugstr_w(This->sProduct));
2118 static BOOL ShellLink_GetVolumeInfo(LPWSTR path, volume_info *volume)
2120 const int label_sz = sizeof volume->label/sizeof volume->label[0];
2121 WCHAR drive[4] = { path[0], ':', '\\', 0 };
2124 volume->type = GetDriveTypeW(drive);
2125 r = GetVolumeInformationW(drive, volume->label, label_sz,
2126 &volume->serial, NULL, NULL, NULL, 0);
2127 TRACE("r = %d type %ld serial %08lx name %s\n", r,
2128 volume->type, volume->serial, debugstr_w(volume->label));
2132 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
2134 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
2135 WCHAR buffer[MAX_PATH];
2139 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
2141 HeapFree(GetProcessHeap(), 0, This->sPath);
2144 HeapFree(GetProcessHeap(), 0, This->sComponent);
2145 This->sComponent = NULL;
2148 ILFree(This->pPidl);
2151 if (S_OK != ShellLink_SetAdvertiseInfo( This, pszFile ))
2153 if (*pszFile == '\0')
2155 else if (!GetFullPathNameW(pszFile, MAX_PATH, buffer, &fname))
2157 else if(!PathFileExistsW(buffer))
2160 This->pPidl = SHSimpleIDListFromPathW(pszFile);
2161 ShellLink_GetVolumeInfo(buffer, &This->volume);
2163 This->sPath = HeapAlloc( GetProcessHeap(), 0,
2164 (lstrlenW( buffer )+1) * sizeof (WCHAR) );
2166 return E_OUTOFMEMORY;
2168 lstrcpyW(This->sPath, buffer);
2170 This->bDirty = TRUE;
2175 /**************************************************************************
2176 * IShellLinkW Implementation
2179 static const IShellLinkWVtbl slvtw =
2181 IShellLinkW_fnQueryInterface,
2182 IShellLinkW_fnAddRef,
2183 IShellLinkW_fnRelease,
2184 IShellLinkW_fnGetPath,
2185 IShellLinkW_fnGetIDList,
2186 IShellLinkW_fnSetIDList,
2187 IShellLinkW_fnGetDescription,
2188 IShellLinkW_fnSetDescription,
2189 IShellLinkW_fnGetWorkingDirectory,
2190 IShellLinkW_fnSetWorkingDirectory,
2191 IShellLinkW_fnGetArguments,
2192 IShellLinkW_fnSetArguments,
2193 IShellLinkW_fnGetHotkey,
2194 IShellLinkW_fnSetHotkey,
2195 IShellLinkW_fnGetShowCmd,
2196 IShellLinkW_fnSetShowCmd,
2197 IShellLinkW_fnGetIconLocation,
2198 IShellLinkW_fnSetIconLocation,
2199 IShellLinkW_fnSetRelativePath,
2200 IShellLinkW_fnResolve,
2201 IShellLinkW_fnSetPath
2204 static HRESULT WINAPI
2205 ShellLink_DataList_QueryInterface( IShellLinkDataList* iface, REFIID riid, void** ppvObject)
2207 IShellLinkImpl *This = impl_from_IShellLinkDataList(iface);
2208 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2212 ShellLink_DataList_AddRef( IShellLinkDataList* iface )
2214 IShellLinkImpl *This = impl_from_IShellLinkDataList(iface);
2215 return IShellLinkA_AddRef((IShellLinkA*)This);
2219 ShellLink_DataList_Release( IShellLinkDataList* iface )
2221 IShellLinkImpl *This = impl_from_IShellLinkDataList(iface);
2222 return ShellLink_Release( This );
2225 static HRESULT WINAPI
2226 ShellLink_AddDataBlock( IShellLinkDataList* iface, void* pDataBlock )
2232 static HRESULT WINAPI
2233 ShellLink_CopyDataBlock( IShellLinkDataList* iface, DWORD dwSig, void** ppDataBlock )
2239 static HRESULT WINAPI
2240 ShellLink_RemoveDataBlock( IShellLinkDataList* iface, DWORD dwSig )
2246 static HRESULT WINAPI
2247 ShellLink_GetFlags( IShellLinkDataList* iface, DWORD* pdwFlags )
2253 static HRESULT WINAPI
2254 ShellLink_SetFlags( IShellLinkDataList* iface, DWORD dwFlags )
2260 static const IShellLinkDataListVtbl dlvt =
2262 ShellLink_DataList_QueryInterface,
2263 ShellLink_DataList_AddRef,
2264 ShellLink_DataList_Release,
2265 ShellLink_AddDataBlock,
2266 ShellLink_CopyDataBlock,
2267 ShellLink_RemoveDataBlock,
2272 static HRESULT WINAPI
2273 ShellLink_ExtInit_QueryInterface( IShellExtInit* iface, REFIID riid, void** ppvObject )
2275 IShellLinkImpl *This = impl_from_IShellExtInit(iface);
2276 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2280 ShellLink_ExtInit_AddRef( IShellExtInit* iface )
2282 IShellLinkImpl *This = impl_from_IShellExtInit(iface);
2283 return IShellLinkA_AddRef((IShellLinkA*)This);
2287 ShellLink_ExtInit_Release( IShellExtInit* iface )
2289 IShellLinkImpl *This = impl_from_IShellExtInit(iface);
2290 return ShellLink_Release( This );
2293 /**************************************************************************
2294 * ShellLink implementation of IShellExtInit::Initialize()
2296 * Loads the shelllink from the dataobject the shell is pointing to.
2298 static HRESULT WINAPI
2299 ShellLink_ExtInit_Initialize( IShellExtInit* iface, LPCITEMIDLIST pidlFolder,
2300 IDataObject *pdtobj, HKEY hkeyProgID )
2302 IShellLinkImpl *This = impl_from_IShellExtInit(iface);
2308 TRACE("%p %p %p %p\n", This, pidlFolder, pdtobj, hkeyProgID );
2313 format.cfFormat = CF_HDROP;
2315 format.dwAspect = DVASPECT_CONTENT;
2317 format.tymed = TYMED_HGLOBAL;
2319 if( FAILED( IDataObject_GetData( pdtobj, &format, &stgm ) ) )
2322 count = DragQueryFileW( stgm.u.hGlobal, -1, NULL, 0 );
2327 count = DragQueryFileW( stgm.u.hGlobal, 0, NULL, 0 );
2329 path = HeapAlloc( GetProcessHeap(), 0, count*sizeof(WCHAR) );
2332 IPersistFile *pf = (IPersistFile*) &This->lpvtblPersistFile;
2334 count = DragQueryFileW( stgm.u.hGlobal, 0, path, count );
2335 r = IPersistFile_Load( pf, path, 0 );
2336 HeapFree( GetProcessHeap(), 0, path );
2339 ReleaseStgMedium( &stgm );
2344 static const IShellExtInitVtbl eivt =
2346 ShellLink_ExtInit_QueryInterface,
2347 ShellLink_ExtInit_AddRef,
2348 ShellLink_ExtInit_Release,
2349 ShellLink_ExtInit_Initialize
2352 static HRESULT WINAPI
2353 ShellLink_ContextMenu_QueryInterface( IContextMenu* iface, REFIID riid, void** ppvObject )
2355 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2356 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2360 ShellLink_ContextMenu_AddRef( IContextMenu* iface )
2362 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2363 return IShellLinkA_AddRef((IShellLinkA*)This);
2367 ShellLink_ContextMenu_Release( IContextMenu* iface )
2369 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2370 return ShellLink_Release( This );
2373 static HRESULT WINAPI
2374 ShellLink_QueryContextMenu( IContextMenu* iface, HMENU hmenu, UINT indexMenu,
2375 UINT idCmdFirst, UINT idCmdLast, UINT uFlags )
2377 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2379 FIXME("%p %p %u %u %u %u\n", This,
2380 hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags );
2385 static HRESULT WINAPI
2386 ShellLink_InvokeCommand( IContextMenu* iface, LPCMINVOKECOMMANDINFO lpici )
2388 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2390 FIXME("%p %p\n", This, lpici );
2395 static HRESULT WINAPI
2396 ShellLink_GetCommandString( IContextMenu* iface, UINT_PTR idCmd, UINT uType,
2397 UINT* pwReserved, LPSTR pszName, UINT cchMax )
2399 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2401 FIXME("%p %u %u %p %p %u\n", This,
2402 idCmd, uType, pwReserved, pszName, cchMax );
2407 static const IContextMenuVtbl cmvt =
2409 ShellLink_ContextMenu_QueryInterface,
2410 ShellLink_ContextMenu_AddRef,
2411 ShellLink_ContextMenu_Release,
2412 ShellLink_QueryContextMenu,
2413 ShellLink_InvokeCommand,
2414 ShellLink_GetCommandString
2417 static HRESULT WINAPI
2418 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite* iface, REFIID riid, void** ppvObject )
2420 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2421 return ShellLink_QueryInterface( This, riid, ppvObject );
2425 ShellLink_ObjectWithSite_AddRef( IObjectWithSite* iface )
2427 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2428 return ShellLink_AddRef( This );
2432 ShellLink_ObjectWithSite_Release( IObjectWithSite* iface )
2434 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2435 return ShellLink_Release( This );
2438 static HRESULT WINAPI
2439 ShellLink_GetSite( IObjectWithSite *iface, REFIID iid, void ** ppvSite )
2441 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2443 TRACE("%p %s %p\n", This, debugstr_guid( iid ), ppvSite );
2447 return IUnknown_QueryInterface( This->site, iid, ppvSite );
2450 static HRESULT WINAPI
2451 ShellLink_SetSite( IObjectWithSite *iface, IUnknown *punk )
2453 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2455 TRACE("%p %p\n", iface, punk);
2458 IUnknown_AddRef( punk );
2464 static const IObjectWithSiteVtbl owsvt =
2466 ShellLink_ObjectWithSite_QueryInterface,
2467 ShellLink_ObjectWithSite_AddRef,
2468 ShellLink_ObjectWithSite_Release,