3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 * Nearly complete information about the binary formats
23 * of .lnk files available at http://www.wotsit.org
25 * You can use winedump to examine the contents of a link file:
28 * MSI advertised shortcuts are totally undocumented. They provide an
29 * icon for a program that is not yet installed, and invoke MSI to
30 * install the program when the shortcut is clicked on. They are
31 * created by passing a special string to SetPath, and the information
32 * in that string is parsed an stored.
36 #define NONAMELESSUNION
38 #include "wine/debug.h"
48 #include "undocshell.h"
51 #include "shell32_main.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(shell);
61 DEFINE_GUID( SHELL32_AdvtShortcutProduct,
62 0x9db1186f,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
63 DEFINE_GUID( SHELL32_AdvtShortcutComponent,
64 0x9db1186e,0x40df,0x11d1,0xaa,0x8c,0x00,0xc0,0x4f,0xb6,0x78,0x63);
66 /* link file formats */
70 typedef struct _LINK_HEADER
72 DWORD dwSize; /* 0x00 size of the header - 0x4c */
73 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
74 DWORD dwFlags; /* 0x14 describes elements following */
75 DWORD dwFileAttr; /* 0x18 attributes of the target file */
76 FILETIME Time1; /* 0x1c */
77 FILETIME Time2; /* 0x24 */
78 FILETIME Time3; /* 0x2c */
79 DWORD dwFileLength; /* 0x34 File length */
80 DWORD nIcon; /* 0x38 icon number */
81 DWORD fStartup; /* 0x3c startup type */
82 DWORD wHotKey; /* 0x40 hotkey */
83 DWORD Unknown5; /* 0x44 */
84 DWORD Unknown6; /* 0x48 */
85 } LINK_HEADER, * PLINK_HEADER;
87 #define SHLINK_LOCAL 0
88 #define SHLINK_REMOTE 1
90 typedef struct _LOCATION_INFO
97 DWORD dwNetworkVolTableOfs;
101 typedef struct _LOCAL_VOLUME_INFO
109 typedef struct volume_info_t
113 WCHAR label[12]; /* assume 8.3 */
118 static const IShellLinkAVtbl slvt;
119 static const IShellLinkWVtbl slvtw;
120 static const IPersistFileVtbl pfvt;
121 static const IPersistStreamVtbl psvt;
122 static const IShellLinkDataListVtbl dlvt;
123 static const IShellExtInitVtbl eivt;
124 static const IContextMenuVtbl cmvt;
125 static const IObjectWithSiteVtbl owsvt;
127 /* IShellLink Implementation */
131 const IShellLinkAVtbl *lpVtbl;
132 const IShellLinkWVtbl *lpvtblw;
133 const IPersistFileVtbl *lpvtblPersistFile;
134 const IPersistStreamVtbl *lpvtblPersistStream;
135 const IShellLinkDataListVtbl *lpvtblShellLinkDataList;
136 const IShellExtInitVtbl *lpvtblShellExtInit;
137 const IContextMenuVtbl *lpvtblContextMenu;
138 const IObjectWithSiteVtbl *lpvtblObjectWithSite;
142 /* data structures according to the information in the link */
162 INT iIdOpen; /* id of the "Open" entry in the context menu */
166 static inline IShellLinkImpl *impl_from_IShellLinkW( IShellLinkW *iface )
168 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblw));
171 static inline IShellLinkImpl *impl_from_IPersistFile( IPersistFile *iface )
173 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblPersistFile));
176 static inline IShellLinkImpl *impl_from_IPersistStream( IPersistStream *iface )
178 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblPersistStream));
181 static inline IShellLinkImpl *impl_from_IShellLinkDataList( IShellLinkDataList *iface )
183 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblShellLinkDataList));
186 static inline IShellLinkImpl *impl_from_IShellExtInit( IShellExtInit *iface )
188 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblShellExtInit));
191 static inline IShellLinkImpl *impl_from_IContextMenu( IContextMenu *iface )
193 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblContextMenu));
196 static inline IShellLinkImpl *impl_from_IObjectWithSite( IObjectWithSite *iface )
198 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblObjectWithSite));
201 static HRESULT ShellLink_UpdatePath(LPCWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath);
203 /* strdup on the process heap */
204 static inline LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str)
206 INT len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
207 LPWSTR p = HeapAlloc( heap, flags, len*sizeof (WCHAR) );
210 MultiByteToWideChar( CP_ACP, 0, str, -1, p, len );
214 static inline LPWSTR strdupW( LPCWSTR src )
217 if (!src) return NULL;
218 dest = HeapAlloc( GetProcessHeap(), 0, (lstrlenW(src)+1)*sizeof(WCHAR) );
224 /**************************************************************************
225 * ShellLink::QueryInterface implementation
227 static HRESULT ShellLink_QueryInterface( IShellLinkImpl *This, REFIID riid, LPVOID *ppvObj)
229 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
233 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IShellLinkA))
237 else if(IsEqualIID(riid, &IID_IShellLinkW))
239 *ppvObj = &(This->lpvtblw);
241 else if(IsEqualIID(riid, &IID_IPersistFile))
243 *ppvObj = &(This->lpvtblPersistFile);
245 else if(IsEqualIID(riid, &IID_IPersistStream))
247 *ppvObj = &(This->lpvtblPersistStream);
249 else if(IsEqualIID(riid, &IID_IShellLinkDataList))
251 *ppvObj = &(This->lpvtblShellLinkDataList);
253 else if(IsEqualIID(riid, &IID_IShellExtInit))
255 *ppvObj = &(This->lpvtblShellExtInit);
257 else if(IsEqualIID(riid, &IID_IContextMenu))
259 *ppvObj = &(This->lpvtblContextMenu);
261 else if(IsEqualIID(riid, &IID_IObjectWithSite))
263 *ppvObj = &(This->lpvtblObjectWithSite);
268 IUnknown_AddRef((IUnknown*)(*ppvObj));
269 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
272 ERR("-- Interface: E_NOINTERFACE\n");
273 return E_NOINTERFACE;
276 /**************************************************************************
277 * ShellLink::AddRef implementation
279 static ULONG ShellLink_AddRef( IShellLinkImpl *This )
281 ULONG refCount = InterlockedIncrement(&This->ref);
283 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
288 /**************************************************************************
289 * ShellLink::Release implementation
291 static ULONG ShellLink_Release( IShellLinkImpl *This )
293 ULONG refCount = InterlockedDecrement(&This->ref);
295 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
300 TRACE("-- destroying IShellLink(%p)\n",This);
302 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
303 HeapFree(GetProcessHeap(), 0, This->sArgs);
304 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
305 HeapFree(GetProcessHeap(), 0, This->sDescription);
306 HeapFree(GetProcessHeap(), 0, This->sPath);
307 HeapFree(GetProcessHeap(), 0, This->sPathRel);
308 HeapFree(GetProcessHeap(), 0, This->sProduct);
309 HeapFree(GetProcessHeap(), 0, This->sComponent);
312 IUnknown_Release( This->site );
322 static HRESULT ShellLink_GetClassID( IShellLinkImpl *This, CLSID *pclsid )
324 TRACE("%p %p\n", This, pclsid);
326 *pclsid = CLSID_ShellLink;
330 /**************************************************************************
331 * IPersistFile_QueryInterface
333 static HRESULT WINAPI IPersistFile_fnQueryInterface(
338 IShellLinkImpl *This = impl_from_IPersistFile(iface);
339 return ShellLink_QueryInterface( This, riid, ppvObj );
342 /******************************************************************************
343 * IPersistFile_AddRef
345 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
347 IShellLinkImpl *This = impl_from_IPersistFile(iface);
348 return ShellLink_AddRef( This );
351 /******************************************************************************
352 * IPersistFile_Release
354 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
356 IShellLinkImpl *This = impl_from_IPersistFile(iface);
357 return IShellLinkA_Release((IShellLinkA*)This);
360 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
362 IShellLinkImpl *This = impl_from_IPersistFile(iface);
363 return ShellLink_GetClassID( This, pClassID );
366 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
368 IShellLinkImpl *This = impl_from_IPersistFile(iface);
370 TRACE("(%p)\n",This);
378 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
380 IShellLinkImpl *This = impl_from_IPersistFile(iface);
381 IPersistStream *StreamThis = (IPersistStream *)&This->lpvtblPersistStream;
385 TRACE("(%p, %s, %x)\n",This, debugstr_w(pszFileName), dwMode);
388 dwMode = STGM_READ | STGM_SHARE_DENY_WRITE;
389 r = SHCreateStreamOnFileW(pszFileName, dwMode, &stm);
392 r = IPersistStream_Load(StreamThis, stm);
393 ShellLink_UpdatePath(This->sPathRel, pszFileName, This->sWorkDir, &This->sPath);
394 IStream_Release( stm );
395 This->bDirty = FALSE;
397 TRACE("-- returning hr %08x\n", r);
401 BOOL run_winemenubuilder( const WCHAR *args )
403 static const WCHAR menubuilder[] = {'\\','w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',0};
407 PROCESS_INFORMATION pi;
411 GetSystemDirectoryW( app, MAX_PATH - sizeof(menubuilder)/sizeof(WCHAR) );
412 strcatW( app, menubuilder );
414 len = (strlenW( app ) + strlenW( args ) + 1) * sizeof(WCHAR);
415 buffer = HeapAlloc( GetProcessHeap(), 0, len );
419 strcpyW( buffer, app );
420 strcatW( buffer, args );
422 TRACE("starting %s\n",debugstr_w(buffer));
424 memset(&si, 0, sizeof(si));
427 ret = CreateProcessW( app, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
429 HeapFree( GetProcessHeap(), 0, buffer );
433 CloseHandle( pi.hProcess );
434 CloseHandle( pi.hThread );
440 static BOOL StartLinkProcessor( LPCOLESTR szLink )
442 static const WCHAR szFormat[] = {' ','-','w',' ','"','%','s','"',0 };
447 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
448 buffer = HeapAlloc( GetProcessHeap(), 0, len );
452 wsprintfW( buffer, szFormat, szLink );
453 ret = run_winemenubuilder( buffer );
454 HeapFree( GetProcessHeap(), 0, buffer );
458 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
460 IShellLinkImpl *This = impl_from_IPersistFile(iface);
461 IPersistStream *StreamThis = (IPersistStream *)&This->lpvtblPersistStream;
465 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
470 r = SHCreateStreamOnFileW( pszFileName, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, &stm );
473 r = IPersistStream_Save(StreamThis, stm, FALSE);
474 IStream_Release( stm );
478 StartLinkProcessor( pszFileName );
480 This->bDirty = FALSE;
484 DeleteFileW( pszFileName );
485 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName) );
492 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
494 IShellLinkImpl *This = impl_from_IPersistFile(iface);
495 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
499 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
501 IShellLinkImpl *This = impl_from_IPersistFile(iface);
502 FIXME("(%p)->(%p): stub\n", This, ppszFileName);
506 static const IPersistFileVtbl pfvt =
508 IPersistFile_fnQueryInterface,
509 IPersistFile_fnAddRef,
510 IPersistFile_fnRelease,
511 IPersistFile_fnGetClassID,
512 IPersistFile_fnIsDirty,
515 IPersistFile_fnSaveCompleted,
516 IPersistFile_fnGetCurFile
519 /************************************************************************
520 * IPersistStream_QueryInterface
522 static HRESULT WINAPI IPersistStream_fnQueryInterface(
523 IPersistStream* iface,
527 IShellLinkImpl *This = impl_from_IPersistStream(iface);
528 return ShellLink_QueryInterface( This, riid, ppvObj );
531 /************************************************************************
532 * IPersistStream_Release
534 static ULONG WINAPI IPersistStream_fnRelease(
535 IPersistStream* iface)
537 IShellLinkImpl *This = impl_from_IPersistStream(iface);
538 return IShellLinkA_Release((IShellLinkA*)This);
541 /************************************************************************
542 * IPersistStream_AddRef
544 static ULONG WINAPI IPersistStream_fnAddRef(
545 IPersistStream* iface)
547 IShellLinkImpl *This = impl_from_IPersistStream(iface);
548 return ShellLink_AddRef( This );
551 /************************************************************************
552 * IPersistStream_GetClassID
555 static HRESULT WINAPI IPersistStream_fnGetClassID(
556 IPersistStream* iface,
559 IShellLinkImpl *This = impl_from_IPersistStream(iface);
560 return ShellLink_GetClassID( This, pClassID );
563 /************************************************************************
564 * IPersistStream_IsDirty (IPersistStream)
566 static HRESULT WINAPI IPersistStream_fnIsDirty(
567 IPersistStream* iface)
569 IShellLinkImpl *This = impl_from_IPersistStream(iface);
571 TRACE("(%p)\n", This);
577 static HRESULT Stream_LoadString( IStream* stm, BOOL unicode, LPWSTR *pstr )
588 r = IStream_Read(stm, &len, sizeof(len), &count);
589 if ( FAILED (r) || ( count != sizeof(len) ) )
593 len *= sizeof (WCHAR);
595 TRACE("reading %d\n", len);
596 temp = HeapAlloc(GetProcessHeap(), 0, len+sizeof(WCHAR));
598 return E_OUTOFMEMORY;
600 r = IStream_Read(stm, temp, len, &count);
601 if( FAILED (r) || ( count != len ) )
603 HeapFree( GetProcessHeap(), 0, temp );
607 TRACE("read %s\n", debugstr_an(temp,len));
609 /* convert to unicode if necessary */
612 count = MultiByteToWideChar( CP_ACP, 0, temp, len, NULL, 0 );
613 str = HeapAlloc( GetProcessHeap(), 0, (count+1)*sizeof (WCHAR) );
616 HeapFree( GetProcessHeap(), 0, temp );
617 return E_OUTOFMEMORY;
619 MultiByteToWideChar( CP_ACP, 0, temp, len, str, count );
620 HeapFree( GetProcessHeap(), 0, temp );
634 static HRESULT Stream_ReadChunk( IStream* stm, LPVOID *data )
641 unsigned char data[1];
646 r = IStream_Read( stm, &size, sizeof(size), &count );
647 if( FAILED( r ) || count != sizeof(size) )
650 chunk = HeapAlloc( GetProcessHeap(), 0, size );
652 return E_OUTOFMEMORY;
655 r = IStream_Read( stm, chunk->data, size - sizeof(size), &count );
656 if( FAILED( r ) || count != (size - sizeof(size)) )
658 HeapFree( GetProcessHeap(), 0, chunk );
662 TRACE("Read %d bytes\n",chunk->size);
669 static BOOL Stream_LoadVolume( LOCAL_VOLUME_INFO *vol, volume_info *volume )
671 const int label_sz = sizeof volume->label/sizeof volume->label[0];
675 volume->serial = vol->dwVolSerial;
676 volume->type = vol->dwType;
678 if( !vol->dwVolLabelOfs )
680 if( vol->dwSize <= vol->dwVolLabelOfs )
682 len = vol->dwSize - vol->dwVolLabelOfs;
685 label += vol->dwVolLabelOfs;
686 MultiByteToWideChar( CP_ACP, 0, label, len, volume->label, label_sz-1);
691 static LPWSTR Stream_LoadPath( LPCSTR p, DWORD maxlen )
696 while( p[len] && (len < maxlen) )
699 wlen = MultiByteToWideChar(CP_ACP, 0, p, len, NULL, 0);
700 path = HeapAlloc(GetProcessHeap(), 0, (wlen+1)*sizeof(WCHAR));
701 MultiByteToWideChar(CP_ACP, 0, p, len, path, wlen);
707 static HRESULT Stream_LoadLocation( IStream *stm,
708 volume_info *volume, LPWSTR *path )
715 r = Stream_ReadChunk( stm, (LPVOID*) &p );
719 loc = (LOCATION_INFO*) p;
720 if (loc->dwTotalSize < sizeof(LOCATION_INFO))
722 HeapFree( GetProcessHeap(), 0, p );
726 /* if there's valid local volume information, load it */
727 if( loc->dwVolTableOfs &&
728 ((loc->dwVolTableOfs + sizeof(LOCAL_VOLUME_INFO)) <= loc->dwTotalSize) )
730 LOCAL_VOLUME_INFO *volume_info;
732 volume_info = (LOCAL_VOLUME_INFO*) &p[loc->dwVolTableOfs];
733 Stream_LoadVolume( volume_info, volume );
736 /* if there's a local path, load it */
737 n = loc->dwLocalPathOfs;
738 if( n && (n < loc->dwTotalSize) )
739 *path = Stream_LoadPath( &p[n], loc->dwTotalSize - n );
741 TRACE("type %d serial %08x name %s path %s\n", volume->type,
742 volume->serial, debugstr_w(volume->label), debugstr_w(*path));
744 HeapFree( GetProcessHeap(), 0, p );
749 * The format of the advertised shortcut info seems to be:
754 * 0 Length of the block (4 bytes, usually 0x314)
756 * 8 string data in ASCII
757 * 8+0x104 string data in UNICODE
759 * In the original Win32 implementation the buffers are not initialized
760 * to zero, so data trailing the string is random garbage.
762 static HRESULT Stream_LoadAdvertiseInfo( IStream* stm, LPWSTR *str )
767 EXP_DARWIN_LINK buffer;
771 r = IStream_Read( stm, &buffer.dbh.cbSize, sizeof (DWORD), &count );
775 /* make sure that we read the size of the structure even on error */
776 size = sizeof buffer - sizeof (DWORD);
777 if( buffer.dbh.cbSize != sizeof buffer )
779 ERR("Ooops. This structure is not as expected...\n");
783 r = IStream_Read( stm, &buffer.dbh.dwSignature, size, &count );
790 TRACE("magic %08x string = %s\n", buffer.dbh.dwSignature, debugstr_w(buffer.szwDarwinID));
792 if( (buffer.dbh.dwSignature&0xffff0000) != 0xa0000000 )
794 ERR("Unknown magic number %08x in advertised shortcut\n", buffer.dbh.dwSignature);
798 *str = HeapAlloc( GetProcessHeap(), 0,
799 (lstrlenW(buffer.szwDarwinID)+1) * sizeof(WCHAR) );
800 lstrcpyW( *str, buffer.szwDarwinID );
805 /************************************************************************
806 * IPersistStream_Load (IPersistStream)
808 static HRESULT WINAPI IPersistStream_fnLoad(
809 IPersistStream* iface,
818 IShellLinkImpl *This = impl_from_IPersistStream(iface);
820 TRACE("%p %p\n", This, stm);
823 return STG_E_INVALIDPOINTER;
826 r = IStream_Read(stm, &hdr, sizeof(hdr), &dwBytesRead);
830 if( dwBytesRead != sizeof(hdr))
832 if( hdr.dwSize != sizeof(hdr))
834 if( !IsEqualIID(&hdr.MagicGuid, &CLSID_ShellLink) )
837 /* free all the old stuff */
840 memset( &This->volume, 0, sizeof This->volume );
841 HeapFree(GetProcessHeap(), 0, This->sPath);
843 HeapFree(GetProcessHeap(), 0, This->sDescription);
844 This->sDescription = NULL;
845 HeapFree(GetProcessHeap(), 0, This->sPathRel);
846 This->sPathRel = NULL;
847 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
848 This->sWorkDir = NULL;
849 HeapFree(GetProcessHeap(), 0, This->sArgs);
851 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
852 This->sIcoPath = NULL;
853 HeapFree(GetProcessHeap(), 0, This->sProduct);
854 This->sProduct = NULL;
855 HeapFree(GetProcessHeap(), 0, This->sComponent);
856 This->sComponent = NULL;
858 This->wHotKey = (WORD)hdr.wHotKey;
859 This->iIcoNdx = hdr.nIcon;
860 FileTimeToSystemTime (&hdr.Time1, &This->time1);
861 FileTimeToSystemTime (&hdr.Time2, &This->time2);
862 FileTimeToSystemTime (&hdr.Time3, &This->time3);
865 WCHAR sTemp[MAX_PATH];
866 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time1,
867 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
868 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
869 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time2,
870 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
871 TRACE("-- time2: %s\n", debugstr_w(sTemp) );
872 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time3,
873 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
874 TRACE("-- time3: %s\n", debugstr_w(sTemp) );
877 /* load all the new stuff */
878 if( hdr.dwFlags & SLDF_HAS_ID_LIST )
880 r = ILLoadFromStream( stm, &This->pPidl );
886 /* load the location information */
887 if( hdr.dwFlags & SLDF_HAS_LINK_INFO )
888 r = Stream_LoadLocation( stm, &This->volume, &This->sPath );
892 unicode = hdr.dwFlags & SLDF_UNICODE;
893 if( hdr.dwFlags & SLDF_HAS_NAME )
895 r = Stream_LoadString( stm, unicode, &This->sDescription );
896 TRACE("Description -> %s\n",debugstr_w(This->sDescription));
901 if( hdr.dwFlags & SLDF_HAS_RELPATH )
903 r = Stream_LoadString( stm, unicode, &This->sPathRel );
904 TRACE("Relative Path-> %s\n",debugstr_w(This->sPathRel));
909 if( hdr.dwFlags & SLDF_HAS_WORKINGDIR )
911 r = Stream_LoadString( stm, unicode, &This->sWorkDir );
912 TRACE("Working Dir -> %s\n",debugstr_w(This->sWorkDir));
917 if( hdr.dwFlags & SLDF_HAS_ARGS )
919 r = Stream_LoadString( stm, unicode, &This->sArgs );
920 TRACE("Working Dir -> %s\n",debugstr_w(This->sArgs));
925 if( hdr.dwFlags & SLDF_HAS_ICONLOCATION )
927 r = Stream_LoadString( stm, unicode, &This->sIcoPath );
928 TRACE("Icon file -> %s\n",debugstr_w(This->sIcoPath));
933 if( hdr.dwFlags & SLDF_HAS_LOGO3ID )
935 r = Stream_LoadAdvertiseInfo( stm, &This->sProduct );
936 TRACE("Product -> %s\n",debugstr_w(This->sProduct));
941 if( hdr.dwFlags & SLDF_HAS_DARWINID )
943 r = Stream_LoadAdvertiseInfo( stm, &This->sComponent );
944 TRACE("Component -> %s\n",debugstr_w(This->sComponent));
949 r = IStream_Read(stm, &zero, sizeof zero, &dwBytesRead);
950 if( FAILED( r ) || zero || dwBytesRead != sizeof zero )
952 /* Some lnk files have extra data blocks starting with a
953 * DATABLOCK_HEADER. For instance EXP_SPECIAL_FOLDER and an unknown
954 * one with a 0xa0000003 signature. However these don't seem to matter
957 WARN("Last word was not zero\n");
969 /************************************************************************
972 * Helper function for IPersistStream_Save. Writes a unicode string
973 * with terminating nul byte to a stream, preceded by the its length.
975 static HRESULT Stream_WriteString( IStream* stm, LPCWSTR str )
977 USHORT len = lstrlenW( str ) + 1;
981 r = IStream_Write( stm, &len, sizeof(len), &count );
985 len *= sizeof(WCHAR);
987 r = IStream_Write( stm, str, len, &count );
994 /************************************************************************
995 * Stream_WriteLocationInfo
997 * Writes the location info to a stream
999 * FIXME: One day we might want to write the network volume information
1000 * and the final path.
1001 * Figure out how Windows deals with unicode paths here.
1003 static HRESULT Stream_WriteLocationInfo( IStream* stm, LPCWSTR path,
1004 volume_info *volume )
1006 DWORD total_size, path_size, volume_info_size, label_size, final_path_size;
1007 LOCAL_VOLUME_INFO *vol;
1009 LPSTR szLabel, szPath, szFinalPath;
1013 TRACE("%p %s %p\n", stm, debugstr_w(path), volume);
1015 /* figure out the size of everything */
1016 label_size = WideCharToMultiByte( CP_ACP, 0, volume->label, -1,
1017 NULL, 0, NULL, NULL );
1018 path_size = WideCharToMultiByte( CP_ACP, 0, path, -1,
1019 NULL, 0, NULL, NULL );
1020 volume_info_size = sizeof *vol + label_size;
1021 final_path_size = 1;
1022 total_size = sizeof *loc + volume_info_size + path_size + final_path_size;
1024 /* create pointers to everything */
1025 loc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, total_size);
1026 vol = (LOCAL_VOLUME_INFO*) &loc[1];
1027 szLabel = (LPSTR) &vol[1];
1028 szPath = &szLabel[label_size];
1029 szFinalPath = &szPath[path_size];
1031 /* fill in the location information header */
1032 loc->dwTotalSize = total_size;
1033 loc->dwHeaderSize = sizeof (*loc);
1035 loc->dwVolTableOfs = sizeof (*loc);
1036 loc->dwLocalPathOfs = sizeof (*loc) + volume_info_size;
1037 loc->dwNetworkVolTableOfs = 0;
1038 loc->dwFinalPathOfs = sizeof (*loc) + volume_info_size + path_size;
1040 /* fill in the volume information */
1041 vol->dwSize = volume_info_size;
1042 vol->dwType = volume->type;
1043 vol->dwVolSerial = volume->serial;
1044 vol->dwVolLabelOfs = sizeof (*vol);
1046 /* copy in the strings */
1047 WideCharToMultiByte( CP_ACP, 0, volume->label, -1,
1048 szLabel, label_size, NULL, NULL );
1049 WideCharToMultiByte( CP_ACP, 0, path, -1,
1050 szPath, path_size, NULL, NULL );
1053 hr = IStream_Write( stm, loc, total_size, &count );
1054 HeapFree(GetProcessHeap(), 0, loc);
1059 static EXP_DARWIN_LINK* shelllink_build_darwinid( LPCWSTR string, DWORD magic )
1061 EXP_DARWIN_LINK *buffer;
1063 buffer = LocalAlloc( LMEM_ZEROINIT, sizeof *buffer );
1064 buffer->dbh.cbSize = sizeof *buffer;
1065 buffer->dbh.dwSignature = magic;
1066 lstrcpynW( buffer->szwDarwinID, string, MAX_PATH );
1067 WideCharToMultiByte(CP_ACP, 0, string, -1, buffer->szDarwinID, MAX_PATH, NULL, NULL );
1072 static HRESULT Stream_WriteAdvertiseInfo( IStream* stm, LPCWSTR string, DWORD magic )
1074 EXP_DARWIN_LINK *buffer;
1079 buffer = shelllink_build_darwinid( string, magic );
1081 return IStream_Write( stm, buffer, buffer->dbh.cbSize, &count );
1084 /************************************************************************
1085 * IPersistStream_Save (IPersistStream)
1087 * FIXME: makes assumptions about byte order
1089 static HRESULT WINAPI IPersistStream_fnSave(
1090 IPersistStream* iface,
1099 IShellLinkImpl *This = impl_from_IPersistStream(iface);
1101 TRACE("%p %p %x\n", This, stm, fClearDirty);
1103 memset(&header, 0, sizeof(header));
1104 header.dwSize = sizeof(header);
1105 header.fStartup = This->iShowCmd;
1106 header.MagicGuid = CLSID_ShellLink;
1108 header.wHotKey = This->wHotKey;
1109 header.nIcon = This->iIcoNdx;
1110 header.dwFlags = SLDF_UNICODE; /* strings are in unicode */
1112 header.dwFlags |= SLDF_HAS_ID_LIST;
1114 header.dwFlags |= SLDF_HAS_LINK_INFO;
1115 if( This->sDescription )
1116 header.dwFlags |= SLDF_HAS_NAME;
1117 if( This->sWorkDir )
1118 header.dwFlags |= SLDF_HAS_WORKINGDIR;
1120 header.dwFlags |= SLDF_HAS_ARGS;
1121 if( This->sIcoPath )
1122 header.dwFlags |= SLDF_HAS_ICONLOCATION;
1123 if( This->sProduct )
1124 header.dwFlags |= SLDF_HAS_LOGO3ID;
1125 if( This->sComponent )
1126 header.dwFlags |= SLDF_HAS_DARWINID;
1128 SystemTimeToFileTime ( &This->time1, &header.Time1 );
1129 SystemTimeToFileTime ( &This->time2, &header.Time2 );
1130 SystemTimeToFileTime ( &This->time3, &header.Time3 );
1132 /* write the Shortcut header */
1133 r = IStream_Write( stm, &header, sizeof(header), &count );
1136 ERR("Write failed at %d\n",__LINE__);
1140 TRACE("Writing pidl\n");
1142 /* write the PIDL to the shortcut */
1145 r = ILSaveToStream( stm, This->pPidl );
1148 ERR("Failed to write PIDL at %d\n",__LINE__);
1154 Stream_WriteLocationInfo( stm, This->sPath, &This->volume );
1156 if( This->sDescription )
1157 r = Stream_WriteString( stm, This->sDescription );
1159 if( This->sPathRel )
1160 r = Stream_WriteString( stm, This->sPathRel );
1162 if( This->sWorkDir )
1163 r = Stream_WriteString( stm, This->sWorkDir );
1166 r = Stream_WriteString( stm, This->sArgs );
1168 if( This->sIcoPath )
1169 r = Stream_WriteString( stm, This->sIcoPath );
1171 if( This->sProduct )
1172 r = Stream_WriteAdvertiseInfo( stm, This->sProduct, EXP_SZ_ICON_SIG );
1174 if( This->sComponent )
1175 r = Stream_WriteAdvertiseInfo( stm, This->sComponent, EXP_DARWIN_ID_SIG );
1177 /* the last field is a single zero dword */
1179 r = IStream_Write( stm, &zero, sizeof zero, &count );
1184 /************************************************************************
1185 * IPersistStream_GetSizeMax (IPersistStream)
1187 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
1188 IPersistStream* iface,
1189 ULARGE_INTEGER* pcbSize)
1191 IShellLinkImpl *This = impl_from_IPersistStream(iface);
1193 TRACE("(%p)\n", This);
1198 static const IPersistStreamVtbl psvt =
1200 IPersistStream_fnQueryInterface,
1201 IPersistStream_fnAddRef,
1202 IPersistStream_fnRelease,
1203 IPersistStream_fnGetClassID,
1204 IPersistStream_fnIsDirty,
1205 IPersistStream_fnLoad,
1206 IPersistStream_fnSave,
1207 IPersistStream_fnGetSizeMax
1210 /**************************************************************************
1211 * IShellLink_Constructor
1213 HRESULT WINAPI IShellLink_Constructor( IUnknown *pUnkOuter,
1214 REFIID riid, LPVOID *ppv )
1216 IShellLinkImpl * sl;
1219 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
1224 return CLASS_E_NOAGGREGATION;
1225 sl = LocalAlloc(LMEM_ZEROINIT,sizeof(IShellLinkImpl));
1227 return E_OUTOFMEMORY;
1231 sl->lpvtblw = &slvtw;
1232 sl->lpvtblPersistFile = &pfvt;
1233 sl->lpvtblPersistStream = &psvt;
1234 sl->lpvtblShellLinkDataList = &dlvt;
1235 sl->lpvtblShellExtInit = &eivt;
1236 sl->lpvtblContextMenu = &cmvt;
1237 sl->lpvtblObjectWithSite = &owsvt;
1238 sl->iShowCmd = SW_SHOWNORMAL;
1243 TRACE("(%p)->()\n",sl);
1245 r = ShellLink_QueryInterface( sl, riid, ppv );
1246 ShellLink_Release( sl );
1251 static BOOL SHELL_ExistsFileW(LPCWSTR path)
1253 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(path))
1258 /**************************************************************************
1259 * ShellLink_UpdatePath
1260 * update absolute path in sPath using relative path in sPathRel
1262 static HRESULT ShellLink_UpdatePath(LPCWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath)
1264 if (!path || !psPath)
1265 return E_INVALIDARG;
1267 if (!*psPath && sPathRel) {
1268 WCHAR buffer[2*MAX_PATH], abs_path[2*MAX_PATH];
1269 LPWSTR final = NULL;
1271 /* first try if [directory of link file] + [relative path] finds an existing file */
1273 GetFullPathNameW( path, MAX_PATH*2, buffer, &final );
1276 lstrcpyW(final, sPathRel);
1280 if (SHELL_ExistsFileW(buffer)) {
1281 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1282 lstrcpyW(abs_path, buffer);
1284 /* try if [working directory] + [relative path] finds an existing file */
1286 lstrcpyW(buffer, sWorkDir);
1287 lstrcpyW(PathAddBackslashW(buffer), sPathRel);
1289 if (SHELL_ExistsFileW(buffer))
1290 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1291 lstrcpyW(abs_path, buffer);
1295 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1297 lstrcpyW(abs_path, sPathRel);
1299 *psPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path)+1)*sizeof(WCHAR));
1301 return E_OUTOFMEMORY;
1303 lstrcpyW(*psPath, abs_path);
1309 /**************************************************************************
1310 * IShellLink_ConstructFromFile
1312 HRESULT WINAPI IShellLink_ConstructFromFile( IUnknown* pUnkOuter, REFIID riid,
1313 LPCITEMIDLIST pidl, LPVOID* ppv)
1317 HRESULT hr = IShellLink_Constructor(NULL, riid, (LPVOID*)&psl);
1319 if (SUCCEEDED(hr)) {
1324 hr = IShellLinkW_QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf);
1326 if (SUCCEEDED(hr)) {
1327 WCHAR path[MAX_PATH];
1329 if (SHGetPathFromIDListW(pidl, path))
1330 hr = IPersistFile_Load(ppf, path, 0);
1337 IPersistFile_Release(ppf);
1341 IShellLinkW_Release(psl);
1347 /**************************************************************************
1348 * IShellLinkA_QueryInterface
1350 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
1352 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1353 return ShellLink_QueryInterface( This, riid, ppvObj );
1356 /******************************************************************************
1357 * IShellLinkA_AddRef
1359 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
1361 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1362 return ShellLink_AddRef( This );
1365 /******************************************************************************
1366 * IShellLinkA_Release
1368 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
1370 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1371 return ShellLink_Release( This );
1374 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,
1375 INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1377 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1379 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1380 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
1382 if (This->sComponent || This->sProduct)
1388 WideCharToMultiByte( CP_ACP, 0, This->sPath, -1,
1389 pszFile, cchMaxPath, NULL, NULL);
1391 if (pfd) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This);
1396 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1398 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1400 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1402 return IShellLinkW_GetIDList((IShellLinkW*)&(This->lpvtblw), ppidl);
1405 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1407 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1409 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1412 ILFree(This->pPidl);
1413 This->pPidl = ILClone (pidl);
1414 This->bDirty = TRUE;
1419 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1421 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1423 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1427 if( This->sDescription )
1428 WideCharToMultiByte( CP_ACP, 0, This->sDescription, -1,
1429 pszName, cchMaxName, NULL, NULL);
1434 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1436 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1438 TRACE("(%p)->(pName=%s)\n", This, pszName);
1440 HeapFree(GetProcessHeap(), 0, This->sDescription);
1441 This->sDescription = HEAP_strdupAtoW( GetProcessHeap(), 0, pszName);
1442 if ( !This->sDescription )
1443 return E_OUTOFMEMORY;
1445 This->bDirty = TRUE;
1450 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1452 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1454 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1458 if( This->sWorkDir )
1459 WideCharToMultiByte( CP_ACP, 0, This->sWorkDir, -1,
1460 pszDir, cchMaxPath, NULL, NULL);
1465 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1467 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1469 TRACE("(%p)->(dir=%s)\n",This, pszDir);
1471 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1472 This->sWorkDir = HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir);
1473 if ( !This->sWorkDir )
1474 return E_OUTOFMEMORY;
1476 This->bDirty = TRUE;
1481 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1483 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1485 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1490 WideCharToMultiByte( CP_ACP, 0, This->sArgs, -1,
1491 pszArgs, cchMaxPath, NULL, NULL);
1496 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1498 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1500 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1502 HeapFree(GetProcessHeap(), 0, This->sArgs);
1505 This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs);
1507 return E_OUTOFMEMORY;
1509 else This->sArgs = NULL;
1511 This->bDirty = TRUE;
1516 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1518 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1520 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1522 *pwHotkey = This->wHotKey;
1527 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1529 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1531 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1533 This->wHotKey = wHotkey;
1534 This->bDirty = TRUE;
1539 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1541 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1543 TRACE("(%p)->(%p)\n",This, piShowCmd);
1544 *piShowCmd = This->iShowCmd;
1548 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1550 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1552 TRACE("(%p) %d\n",This, iShowCmd);
1554 This->iShowCmd = iShowCmd;
1555 This->bDirty = TRUE;
1560 static HRESULT SHELL_PidlGeticonLocationA(IShellFolder* psf, LPCITEMIDLIST pidl,
1561 LPSTR pszIconPath, int cchIconPath, int* piIcon)
1563 LPCITEMIDLIST pidlLast;
1565 HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
1567 if (SUCCEEDED(hr)) {
1570 hr = IShellFolder_GetUIObjectOf(psf, 0, 1, &pidlLast, &IID_IExtractIconA, NULL, (LPVOID*)&pei);
1572 if (SUCCEEDED(hr)) {
1573 hr = IExtractIconA_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
1575 IExtractIconA_Release(pei);
1578 IShellFolder_Release(psf);
1584 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1586 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1588 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1591 *piIcon = This->iIcoNdx;
1595 WideCharToMultiByte(CP_ACP, 0, This->sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL);
1599 if (This->pPidl || This->sPath)
1603 HRESULT hr = SHGetDesktopFolder(&pdsk);
1607 /* first look for an icon using the PIDL (if present) */
1609 hr = SHELL_PidlGeticonLocationA(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
1613 /* if we couldn't find an icon yet, look for it using the file system path */
1614 if (FAILED(hr) && This->sPath)
1618 hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
1620 if (SUCCEEDED(hr)) {
1621 hr = SHELL_PidlGeticonLocationA(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
1627 IShellFolder_Release(pdsk);
1635 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1637 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1639 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1641 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1642 This->sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1643 if ( !This->sIcoPath )
1644 return E_OUTOFMEMORY;
1646 This->iIcoNdx = iIcon;
1647 This->bDirty = TRUE;
1652 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1654 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1656 TRACE("(%p)->(path=%s %x)\n",This, pszPathRel, dwReserved);
1658 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1659 This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1660 This->bDirty = TRUE;
1662 return ShellLink_UpdatePath(This->sPathRel, This->sPath, This->sWorkDir, &This->sPath);
1665 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1667 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1669 TRACE("(%p)->(hwnd=%p flags=%x)\n",This, hwnd, fFlags);
1671 return IShellLinkW_Resolve( (IShellLinkW*)&(This->lpvtblw), hwnd, fFlags );
1674 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1678 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1680 TRACE("(%p)->(path=%s)\n",This, pszFile);
1682 if (!pszFile) return E_INVALIDARG;
1684 str = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1686 return E_OUTOFMEMORY;
1688 r = IShellLinkW_SetPath((IShellLinkW*)&(This->lpvtblw), str);
1689 HeapFree( GetProcessHeap(), 0, str );
1694 /**************************************************************************
1695 * IShellLink Implementation
1698 static const IShellLinkAVtbl slvt =
1700 IShellLinkA_fnQueryInterface,
1701 IShellLinkA_fnAddRef,
1702 IShellLinkA_fnRelease,
1703 IShellLinkA_fnGetPath,
1704 IShellLinkA_fnGetIDList,
1705 IShellLinkA_fnSetIDList,
1706 IShellLinkA_fnGetDescription,
1707 IShellLinkA_fnSetDescription,
1708 IShellLinkA_fnGetWorkingDirectory,
1709 IShellLinkA_fnSetWorkingDirectory,
1710 IShellLinkA_fnGetArguments,
1711 IShellLinkA_fnSetArguments,
1712 IShellLinkA_fnGetHotkey,
1713 IShellLinkA_fnSetHotkey,
1714 IShellLinkA_fnGetShowCmd,
1715 IShellLinkA_fnSetShowCmd,
1716 IShellLinkA_fnGetIconLocation,
1717 IShellLinkA_fnSetIconLocation,
1718 IShellLinkA_fnSetRelativePath,
1719 IShellLinkA_fnResolve,
1720 IShellLinkA_fnSetPath
1724 /**************************************************************************
1725 * IShellLinkW_fnQueryInterface
1727 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1728 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1730 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1731 return ShellLink_QueryInterface( This, riid, ppvObj );
1734 /******************************************************************************
1735 * IShellLinkW_fnAddRef
1737 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1739 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1740 return ShellLink_AddRef( This );
1743 /******************************************************************************
1744 * IShellLinkW_fnRelease
1746 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1748 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1749 return ShellLink_Release( This );
1752 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags)
1754 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1756 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%u)(%s)\n",
1757 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
1759 if (This->sComponent || This->sProduct)
1765 lstrcpynW( pszFile, This->sPath, cchMaxPath );
1767 if (pfd) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This);
1772 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1774 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1776 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1783 *ppidl = ILClone(This->pPidl);
1787 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1789 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1791 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1794 ILFree( This->pPidl );
1795 This->pPidl = ILClone( pidl );
1799 This->bDirty = TRUE;
1804 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1806 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1808 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1811 if( This->sDescription )
1812 lstrcpynW( pszName, This->sDescription, cchMaxName );
1817 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1819 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1821 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1823 HeapFree(GetProcessHeap(), 0, This->sDescription);
1824 This->sDescription = HeapAlloc( GetProcessHeap(), 0,
1825 (lstrlenW( pszName )+1)*sizeof(WCHAR) );
1826 if ( !This->sDescription )
1827 return E_OUTOFMEMORY;
1829 lstrcpyW( This->sDescription, pszName );
1830 This->bDirty = TRUE;
1835 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1837 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1839 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1843 if( This->sWorkDir )
1844 lstrcpynW( pszDir, This->sWorkDir, cchMaxPath );
1849 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1851 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1853 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1855 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1856 This->sWorkDir = HeapAlloc( GetProcessHeap(), 0,
1857 (lstrlenW( pszDir )+1)*sizeof (WCHAR) );
1858 if ( !This->sWorkDir )
1859 return E_OUTOFMEMORY;
1860 lstrcpyW( This->sWorkDir, pszDir );
1861 This->bDirty = TRUE;
1866 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1868 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1870 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1875 lstrcpynW( pszArgs, This->sArgs, cchMaxPath );
1880 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1882 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1884 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1886 HeapFree(GetProcessHeap(), 0, This->sArgs);
1889 This->sArgs = HeapAlloc( GetProcessHeap(), 0,
1890 (lstrlenW( pszArgs )+1)*sizeof (WCHAR) );
1892 return E_OUTOFMEMORY;
1893 lstrcpyW( This->sArgs, pszArgs );
1895 else This->sArgs = NULL;
1897 This->bDirty = TRUE;
1902 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1904 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1906 TRACE("(%p)->(%p)\n",This, pwHotkey);
1908 *pwHotkey=This->wHotKey;
1913 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1915 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1917 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1919 This->wHotKey = wHotkey;
1920 This->bDirty = TRUE;
1925 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1927 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1929 TRACE("(%p)->(%p)\n",This, piShowCmd);
1931 *piShowCmd = This->iShowCmd;
1936 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1938 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1940 This->iShowCmd = iShowCmd;
1941 This->bDirty = TRUE;
1946 static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPCITEMIDLIST pidl,
1947 LPWSTR pszIconPath, int cchIconPath, int* piIcon)
1949 LPCITEMIDLIST pidlLast;
1951 HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
1953 if (SUCCEEDED(hr)) {
1956 hr = IShellFolder_GetUIObjectOf(psf, 0, 1, &pidlLast, &IID_IExtractIconW, NULL, (LPVOID*)&pei);
1958 if (SUCCEEDED(hr)) {
1959 hr = IExtractIconW_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
1961 IExtractIconW_Release(pei);
1964 IShellFolder_Release(psf);
1970 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1972 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
1974 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1977 *piIcon = This->iIcoNdx;
1981 lstrcpynW(pszIconPath, This->sIcoPath, cchIconPath);
1985 if (This->pPidl || This->sPath)
1989 HRESULT hr = SHGetDesktopFolder(&pdsk);
1993 /* first look for an icon using the PIDL (if present) */
1995 hr = SHELL_PidlGeticonLocationW(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
1999 /* if we couldn't find an icon yet, look for it using the file system path */
2000 if (FAILED(hr) && This->sPath)
2004 hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
2008 hr = SHELL_PidlGeticonLocationW(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
2014 IShellFolder_Release(pdsk);
2021 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
2023 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
2025 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
2027 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
2028 This->sIcoPath = HeapAlloc( GetProcessHeap(), 0,
2029 (lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
2030 if ( !This->sIcoPath )
2031 return E_OUTOFMEMORY;
2032 lstrcpyW( This->sIcoPath, pszIconPath );
2034 This->iIcoNdx = iIcon;
2035 This->bDirty = TRUE;
2040 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
2042 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
2044 TRACE("(%p)->(path=%s %x)\n",This, debugstr_w(pszPathRel), dwReserved);
2046 HeapFree(GetProcessHeap(), 0, This->sPathRel);
2047 This->sPathRel = HeapAlloc( GetProcessHeap(), 0,
2048 (lstrlenW( pszPathRel )+1) * sizeof (WCHAR) );
2049 if ( !This->sPathRel )
2050 return E_OUTOFMEMORY;
2051 lstrcpyW( This->sPathRel, pszPathRel );
2052 This->bDirty = TRUE;
2054 return ShellLink_UpdatePath(This->sPathRel, This->sPath, This->sWorkDir, &This->sPath);
2057 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
2062 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
2064 TRACE("(%p)->(hwnd=%p flags=%x)\n",This, hwnd, fFlags);
2066 /*FIXME: use IResolveShellLink interface */
2068 if (!This->sPath && This->pPidl) {
2069 WCHAR buffer[MAX_PATH];
2071 bSuccess = SHGetPathFromIDListW(This->pPidl, buffer);
2073 if (bSuccess && *buffer) {
2074 This->sPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer)+1)*sizeof(WCHAR));
2076 return E_OUTOFMEMORY;
2078 lstrcpyW(This->sPath, buffer);
2080 This->bDirty = TRUE;
2082 hr = S_OK; /* don't report an error occurred while just caching information */
2085 if (!This->sIcoPath && This->sPath) {
2086 This->sIcoPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This->sPath)+1)*sizeof(WCHAR));
2087 if (!This->sIcoPath)
2088 return E_OUTOFMEMORY;
2090 lstrcpyW(This->sIcoPath, This->sPath);
2093 This->bDirty = TRUE;
2099 static LPWSTR ShellLink_GetAdvertisedArg(LPCWSTR str)
2108 p = strchrW( str, ':' );
2112 ret = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
2115 memcpy( ret, str, sizeof(WCHAR)*len );
2120 static HRESULT ShellLink_SetAdvertiseInfo(IShellLinkImpl *This, LPCWSTR str)
2122 LPCWSTR szComponent = NULL, szProduct = NULL, p;
2130 /* each segment must start with two colons */
2131 if( str[0] != ':' || str[1] != ':' )
2134 /* the last segment is just two colons */
2139 /* there must be a colon straight after a guid */
2140 p = strchrW( str, ':' );
2147 /* get the guid, and check it's validly formatted */
2148 memcpy( szGuid, str, sizeof(WCHAR)*len );
2150 r = CLSIDFromString( szGuid, &guid );
2155 /* match it up to a guid that we care about */
2156 if( IsEqualGUID( &guid, &SHELL32_AdvtShortcutComponent ) && !szComponent )
2158 else if( IsEqualGUID( &guid, &SHELL32_AdvtShortcutProduct ) && !szProduct )
2163 /* skip to the next field */
2164 str = strchrW( str, ':' );
2169 /* we have to have a component for an advertised shortcut */
2173 This->sComponent = ShellLink_GetAdvertisedArg( szComponent );
2174 This->sProduct = ShellLink_GetAdvertisedArg( szProduct );
2176 TRACE("Component = %s\n", debugstr_w(This->sComponent));
2177 TRACE("Product = %s\n", debugstr_w(This->sProduct));
2182 static BOOL ShellLink_GetVolumeInfo(LPCWSTR path, volume_info *volume)
2184 const int label_sz = sizeof volume->label/sizeof volume->label[0];
2185 WCHAR drive[4] = { path[0], ':', '\\', 0 };
2188 volume->type = GetDriveTypeW(drive);
2189 r = GetVolumeInformationW(drive, volume->label, label_sz,
2190 &volume->serial, NULL, NULL, NULL, 0);
2191 TRACE("r = %d type %d serial %08x name %s\n", r,
2192 volume->type, volume->serial, debugstr_w(volume->label));
2196 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
2198 IShellLinkImpl *This = impl_from_IShellLinkW(iface);
2199 WCHAR buffer[MAX_PATH];
2200 LPWSTR fname, unquoted = NULL;
2204 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
2206 if (!pszFile) return E_INVALIDARG;
2208 /* quotes at the ends of the string are stripped */
2209 len = lstrlenW(pszFile);
2210 if (pszFile[0] == '"' && pszFile[len-1] == '"')
2212 unquoted = strdupW(pszFile);
2213 PathUnquoteSpacesW(unquoted);
2217 /* any other quote marks are invalid */
2218 if (strchrW(pszFile, '"'))
2220 HeapFree(GetProcessHeap(), 0, unquoted);
2224 HeapFree(GetProcessHeap(), 0, This->sPath);
2227 HeapFree(GetProcessHeap(), 0, This->sComponent);
2228 This->sComponent = NULL;
2231 ILFree(This->pPidl);
2234 if (S_OK != ShellLink_SetAdvertiseInfo( This, pszFile ))
2236 if (*pszFile == '\0')
2238 else if (!GetFullPathNameW(pszFile, MAX_PATH, buffer, &fname))
2240 else if(!PathFileExistsW(buffer) &&
2241 !SearchPathW(NULL, pszFile, NULL, MAX_PATH, buffer, NULL))
2244 This->pPidl = SHSimpleIDListFromPathW(pszFile);
2245 ShellLink_GetVolumeInfo(buffer, &This->volume);
2247 This->sPath = HeapAlloc( GetProcessHeap(), 0,
2248 (lstrlenW( buffer )+1) * sizeof (WCHAR) );
2251 HeapFree(GetProcessHeap(), 0, unquoted);
2252 return E_OUTOFMEMORY;
2255 lstrcpyW(This->sPath, buffer);
2257 This->bDirty = TRUE;
2258 HeapFree(GetProcessHeap(), 0, unquoted);
2263 /**************************************************************************
2264 * IShellLinkW Implementation
2267 static const IShellLinkWVtbl slvtw =
2269 IShellLinkW_fnQueryInterface,
2270 IShellLinkW_fnAddRef,
2271 IShellLinkW_fnRelease,
2272 IShellLinkW_fnGetPath,
2273 IShellLinkW_fnGetIDList,
2274 IShellLinkW_fnSetIDList,
2275 IShellLinkW_fnGetDescription,
2276 IShellLinkW_fnSetDescription,
2277 IShellLinkW_fnGetWorkingDirectory,
2278 IShellLinkW_fnSetWorkingDirectory,
2279 IShellLinkW_fnGetArguments,
2280 IShellLinkW_fnSetArguments,
2281 IShellLinkW_fnGetHotkey,
2282 IShellLinkW_fnSetHotkey,
2283 IShellLinkW_fnGetShowCmd,
2284 IShellLinkW_fnSetShowCmd,
2285 IShellLinkW_fnGetIconLocation,
2286 IShellLinkW_fnSetIconLocation,
2287 IShellLinkW_fnSetRelativePath,
2288 IShellLinkW_fnResolve,
2289 IShellLinkW_fnSetPath
2292 static HRESULT WINAPI
2293 ShellLink_DataList_QueryInterface( IShellLinkDataList* iface, REFIID riid, void** ppvObject)
2295 IShellLinkImpl *This = impl_from_IShellLinkDataList(iface);
2296 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2300 ShellLink_DataList_AddRef( IShellLinkDataList* iface )
2302 IShellLinkImpl *This = impl_from_IShellLinkDataList(iface);
2303 return IShellLinkA_AddRef((IShellLinkA*)This);
2307 ShellLink_DataList_Release( IShellLinkDataList* iface )
2309 IShellLinkImpl *This = impl_from_IShellLinkDataList(iface);
2310 return ShellLink_Release( This );
2313 static HRESULT WINAPI
2314 ShellLink_AddDataBlock( IShellLinkDataList* iface, void* pDataBlock )
2316 FIXME("(%p)->(%p): stub\n", iface, pDataBlock);
2320 static HRESULT WINAPI
2321 ShellLink_CopyDataBlock( IShellLinkDataList* iface, DWORD dwSig, void** ppDataBlock )
2323 IShellLinkImpl *This = impl_from_IShellLinkDataList(iface);
2324 LPVOID block = NULL;
2327 TRACE("%p %08x %p\n", iface, dwSig, ppDataBlock );
2331 case EXP_DARWIN_ID_SIG:
2332 if (!This->sComponent)
2334 block = shelllink_build_darwinid( This->sComponent, dwSig );
2337 case EXP_SZ_LINK_SIG:
2338 case NT_CONSOLE_PROPS_SIG:
2339 case NT_FE_CONSOLE_PROPS_SIG:
2340 case EXP_SPECIAL_FOLDER_SIG:
2341 case EXP_SZ_ICON_SIG:
2342 FIXME("valid but unhandled datablock %08x\n", dwSig);
2345 ERR("unknown datablock %08x\n", dwSig);
2347 *ppDataBlock = block;
2351 static HRESULT WINAPI
2352 ShellLink_RemoveDataBlock( IShellLinkDataList* iface, DWORD dwSig )
2354 FIXME("(%p)->(%u): stub\n", iface, dwSig);
2358 static HRESULT WINAPI
2359 ShellLink_GetFlags( IShellLinkDataList* iface, DWORD* pdwFlags )
2361 IShellLinkImpl *This = impl_from_IShellLinkDataList(iface);
2364 FIXME("(%p)->(%p): partially implemented\n", This, pdwFlags);
2366 /* FIXME: add more */
2368 flags |= SLDF_HAS_ARGS;
2369 if (This->sComponent)
2370 flags |= SLDF_HAS_DARWINID;
2372 flags |= SLDF_HAS_ICONLOCATION;
2374 flags |= SLDF_HAS_LOGO3ID;
2376 flags |= SLDF_HAS_ID_LIST;
2383 static HRESULT WINAPI
2384 ShellLink_SetFlags( IShellLinkDataList* iface, DWORD dwFlags )
2386 FIXME("(%p)->(%u): stub\n", iface, dwFlags);
2390 static const IShellLinkDataListVtbl dlvt =
2392 ShellLink_DataList_QueryInterface,
2393 ShellLink_DataList_AddRef,
2394 ShellLink_DataList_Release,
2395 ShellLink_AddDataBlock,
2396 ShellLink_CopyDataBlock,
2397 ShellLink_RemoveDataBlock,
2402 static HRESULT WINAPI
2403 ShellLink_ExtInit_QueryInterface( IShellExtInit* iface, REFIID riid, void** ppvObject )
2405 IShellLinkImpl *This = impl_from_IShellExtInit(iface);
2406 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2410 ShellLink_ExtInit_AddRef( IShellExtInit* iface )
2412 IShellLinkImpl *This = impl_from_IShellExtInit(iface);
2413 return IShellLinkA_AddRef((IShellLinkA*)This);
2417 ShellLink_ExtInit_Release( IShellExtInit* iface )
2419 IShellLinkImpl *This = impl_from_IShellExtInit(iface);
2420 return ShellLink_Release( This );
2423 /**************************************************************************
2424 * ShellLink implementation of IShellExtInit::Initialize()
2426 * Loads the shelllink from the dataobject the shell is pointing to.
2428 static HRESULT WINAPI
2429 ShellLink_ExtInit_Initialize( IShellExtInit* iface, LPCITEMIDLIST pidlFolder,
2430 IDataObject *pdtobj, HKEY hkeyProgID )
2432 IShellLinkImpl *This = impl_from_IShellExtInit(iface);
2438 TRACE("%p %p %p %p\n", This, pidlFolder, pdtobj, hkeyProgID );
2443 format.cfFormat = CF_HDROP;
2445 format.dwAspect = DVASPECT_CONTENT;
2447 format.tymed = TYMED_HGLOBAL;
2449 if( FAILED( IDataObject_GetData( pdtobj, &format, &stgm ) ) )
2452 count = DragQueryFileW( stgm.u.hGlobal, -1, NULL, 0 );
2457 count = DragQueryFileW( stgm.u.hGlobal, 0, NULL, 0 );
2459 path = HeapAlloc( GetProcessHeap(), 0, count*sizeof(WCHAR) );
2462 IPersistFile *pf = (IPersistFile*) &This->lpvtblPersistFile;
2464 count = DragQueryFileW( stgm.u.hGlobal, 0, path, count );
2465 r = IPersistFile_Load( pf, path, 0 );
2466 HeapFree( GetProcessHeap(), 0, path );
2469 ReleaseStgMedium( &stgm );
2474 static const IShellExtInitVtbl eivt =
2476 ShellLink_ExtInit_QueryInterface,
2477 ShellLink_ExtInit_AddRef,
2478 ShellLink_ExtInit_Release,
2479 ShellLink_ExtInit_Initialize
2482 static HRESULT WINAPI
2483 ShellLink_ContextMenu_QueryInterface( IContextMenu* iface, REFIID riid, void** ppvObject )
2485 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2486 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2490 ShellLink_ContextMenu_AddRef( IContextMenu* iface )
2492 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2493 return IShellLinkA_AddRef((IShellLinkA*)This);
2497 ShellLink_ContextMenu_Release( IContextMenu* iface )
2499 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2500 return ShellLink_Release( This );
2503 static HRESULT WINAPI
2504 ShellLink_QueryContextMenu( IContextMenu* iface, HMENU hmenu, UINT indexMenu,
2505 UINT idCmdFirst, UINT idCmdLast, UINT uFlags )
2507 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2508 static WCHAR szOpen[] = { 'O','p','e','n',0 };
2512 TRACE("%p %p %u %u %u %u\n", This,
2513 hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags );
2516 return E_INVALIDARG;
2518 memset( &mii, 0, sizeof mii );
2519 mii.cbSize = sizeof mii;
2520 mii.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
2521 mii.dwTypeData = szOpen;
2522 mii.cch = strlenW( mii.dwTypeData );
2523 mii.wID = idCmdFirst + id++;
2524 mii.fState = MFS_DEFAULT | MFS_ENABLED;
2525 mii.fType = MFT_STRING;
2526 if (!InsertMenuItemW( hmenu, indexMenu, TRUE, &mii ))
2530 return MAKE_HRESULT( SEVERITY_SUCCESS, 0, id );
2534 shelllink_get_msi_component_path( LPWSTR component )
2539 r = CommandLineFromMsiDescriptor( component, NULL, &sz );
2540 if (r != ERROR_SUCCESS)
2544 path = HeapAlloc( GetProcessHeap(), 0, sz*sizeof(WCHAR) );
2545 r = CommandLineFromMsiDescriptor( component, path, &sz );
2546 if (r != ERROR_SUCCESS)
2548 HeapFree( GetProcessHeap(), 0, path );
2552 TRACE("returning %s\n", debugstr_w( path ) );
2557 static HRESULT WINAPI
2558 ShellLink_InvokeCommand( IContextMenu* iface, LPCMINVOKECOMMANDINFO lpici )
2560 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2561 static const WCHAR szOpen[] = { 'O','p','e','n',0 };
2562 SHELLEXECUTEINFOW sei;
2563 HWND hwnd = NULL; /* FIXME: get using interface set from IObjectWithSite */
2568 TRACE("%p %p\n", This, lpici );
2570 if ( lpici->cbSize < sizeof (CMINVOKECOMMANDINFO) )
2571 return E_INVALIDARG;
2573 if ( lpici->lpVerb != MAKEINTRESOURCEA(This->iIdOpen) )
2575 ERR("Unknown id %p != %d\n", lpici->lpVerb, This->iIdOpen );
2576 return E_INVALIDARG;
2579 r = IShellLinkW_Resolve( (IShellLinkW*)&(This->lpvtblw), hwnd, 0 );
2583 if ( This->sComponent )
2585 path = shelllink_get_msi_component_path( This->sComponent );
2590 path = strdupW( This->sPath );
2592 if ( lpici->cbSize == sizeof (CMINVOKECOMMANDINFOEX) &&
2593 ( lpici->fMask & CMIC_MASK_UNICODE ) )
2595 LPCMINVOKECOMMANDINFOEX iciex = (LPCMINVOKECOMMANDINFOEX) lpici;
2599 len += lstrlenW( This->sArgs );
2600 if ( iciex->lpParametersW )
2601 len += lstrlenW( iciex->lpParametersW );
2603 args = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
2606 lstrcatW( args, This->sArgs );
2607 if ( iciex->lpParametersW )
2609 static const WCHAR space[] = { ' ', 0 };
2610 lstrcatW( args, space );
2611 lstrcatW( args, iciex->lpParametersW );
2615 memset( &sei, 0, sizeof sei );
2616 sei.cbSize = sizeof sei;
2617 sei.fMask = SEE_MASK_UNICODE | (lpici->fMask & (SEE_MASK_NOASYNC|SEE_MASK_ASYNCOK|SEE_MASK_FLAG_NO_UI));
2619 sei.nShow = This->iShowCmd;
2620 sei.lpIDList = This->pPidl;
2621 sei.lpDirectory = This->sWorkDir;
2622 sei.lpParameters = args;
2623 sei.lpVerb = szOpen;
2625 if( ShellExecuteExW( &sei ) )
2630 HeapFree( GetProcessHeap(), 0, args );
2631 HeapFree( GetProcessHeap(), 0, path );
2636 static HRESULT WINAPI
2637 ShellLink_GetCommandString( IContextMenu* iface, UINT_PTR idCmd, UINT uType,
2638 UINT* pwReserved, LPSTR pszName, UINT cchMax )
2640 IShellLinkImpl *This = impl_from_IContextMenu(iface);
2642 FIXME("(%p)->(%lu %u %p %p %u): stub\n", This,
2643 idCmd, uType, pwReserved, pszName, cchMax );
2648 static const IContextMenuVtbl cmvt =
2650 ShellLink_ContextMenu_QueryInterface,
2651 ShellLink_ContextMenu_AddRef,
2652 ShellLink_ContextMenu_Release,
2653 ShellLink_QueryContextMenu,
2654 ShellLink_InvokeCommand,
2655 ShellLink_GetCommandString
2658 static HRESULT WINAPI
2659 ShellLink_ObjectWithSite_QueryInterface( IObjectWithSite* iface, REFIID riid, void** ppvObject )
2661 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2662 return ShellLink_QueryInterface( This, riid, ppvObject );
2666 ShellLink_ObjectWithSite_AddRef( IObjectWithSite* iface )
2668 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2669 return ShellLink_AddRef( This );
2673 ShellLink_ObjectWithSite_Release( IObjectWithSite* iface )
2675 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2676 return ShellLink_Release( This );
2679 static HRESULT WINAPI
2680 ShellLink_GetSite( IObjectWithSite *iface, REFIID iid, void ** ppvSite )
2682 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2684 TRACE("%p %s %p\n", This, debugstr_guid( iid ), ppvSite );
2688 return IUnknown_QueryInterface( This->site, iid, ppvSite );
2691 static HRESULT WINAPI
2692 ShellLink_SetSite( IObjectWithSite *iface, IUnknown *punk )
2694 IShellLinkImpl *This = impl_from_IObjectWithSite(iface);
2696 TRACE("%p %p\n", iface, punk);
2699 IUnknown_AddRef( punk );
2705 static const IObjectWithSiteVtbl owsvt =
2707 ShellLink_ObjectWithSite_QueryInterface,
2708 ShellLink_ObjectWithSite_AddRef,
2709 ShellLink_ObjectWithSite_Release,