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;
124 /* IShellLink Implementation */
128 const IShellLinkAVtbl *lpVtbl;
129 const IShellLinkWVtbl *lpvtblw;
130 const IPersistFileVtbl *lpvtblPersistFile;
131 const IPersistStreamVtbl *lpvtblPersistStream;
132 const IShellLinkDataListVtbl *lpvtblShellLinkDataList;
133 const IShellExtInitVtbl *lpvtblShellExtInit;
134 const IContextMenuVtbl *lpvtblContextMenu;
138 /* data structures according to the informations in the link */
160 static inline IShellLinkImpl *impl_from_IShellLinkW( IShellLinkW *iface )
162 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblw));
164 #define _ICOM_THIS_From_IShellLinkW(class, iface) \
165 class* This = impl_from_IShellLinkW( iface )
167 static inline IShellLinkImpl *impl_from_IPersistFile( IPersistFile *iface )
169 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblPersistFile));
171 #define _ICOM_THIS_From_IPersistFile(class, iface) \
172 class* This = impl_from_IPersistFile( iface )
174 static inline IShellLinkImpl *impl_from_IPersistStream( IPersistStream *iface )
176 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblPersistStream));
178 #define _ICOM_THIS_From_IPersistStream(class, iface) \
179 class* This = impl_from_IPersistStream( iface )
181 static inline IShellLinkImpl *impl_from_IShellLinkDataList( IShellLinkDataList *iface )
183 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblShellLinkDataList));
185 #define _ICOM_THIS_From_IShellLinkDataList(class, iface) \
186 class* This = impl_from_IShellLinkDataList( iface )
188 static inline IShellLinkImpl *impl_from_IShellExtInit( IShellExtInit *iface )
190 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblShellExtInit));
192 #define _ICOM_THIS_From_IShellExtInit(class, iface) \
193 class* This = impl_from_IShellExtInit( iface )
195 static inline IShellLinkImpl *impl_from_IContextMenu( IContextMenu *iface )
197 return (IShellLinkImpl *)((char*)iface - FIELD_OFFSET(IShellLinkImpl, lpvtblContextMenu));
199 #define _ICOM_THIS_From_IContextMenu(class, iface) \
200 class* This = impl_from_IContextMenu( iface )
202 static HRESULT ShellLink_UpdatePath(LPWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath);
204 /* strdup on the process heap */
205 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str)
207 INT len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
208 LPWSTR p = HeapAlloc( heap, flags, len*sizeof (WCHAR) );
211 MultiByteToWideChar( CP_ACP, 0, str, -1, p, len );
215 /**************************************************************************
216 * IPersistFile_QueryInterface
218 static HRESULT WINAPI IPersistFile_fnQueryInterface(
223 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
224 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
227 /******************************************************************************
228 * IPersistFile_AddRef
230 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
232 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
233 return IShellLinkA_AddRef((IShellLinkA*)This);
236 /******************************************************************************
237 * IPersistFile_Release
239 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
241 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
242 return IShellLinkA_Release((IShellLinkA*)This);
245 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
247 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
248 FIXME("(%p)\n",This);
252 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
254 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
256 TRACE("(%p)\n",This);
264 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
266 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
267 IPersistStream *StreamThis = (IPersistStream *)&This->lpvtblPersistStream;
271 TRACE("(%p, %s, %lx)\n",This, debugstr_w(pszFileName), dwMode);
273 r = CreateStreamOnFile(pszFileName, dwMode, &stm);
276 r = IPersistStream_Load(StreamThis, stm);
277 ShellLink_UpdatePath(This->sPathRel, pszFileName, This->sWorkDir, &This->sPath);
278 IStream_Release( stm );
279 This->bDirty = FALSE;
281 TRACE("-- returning hr %08lx\n", r);
285 static BOOL StartLinkProcessor( LPCOLESTR szLink )
287 static const WCHAR szFormat[] = {
288 'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
289 ' ','-','r',' ','"','%','s','"',0 };
293 PROCESS_INFORMATION pi;
295 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
296 buffer = HeapAlloc( GetProcessHeap(), 0, len );
300 wsprintfW( buffer, szFormat, szLink );
302 TRACE("starting %s\n",debugstr_w(buffer));
304 memset(&si, 0, sizeof(si));
306 if (!CreateProcessW( NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return FALSE;
308 /* wait for a while to throttle the creation of linker processes */
309 if( WAIT_OBJECT_0 != WaitForSingleObject( pi.hProcess, 10000 ) )
310 WARN("Timed out waiting for shell linker\n");
312 CloseHandle( pi.hProcess );
313 CloseHandle( pi.hThread );
318 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
320 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
321 IPersistStream *StreamThis = (IPersistStream *)&This->lpvtblPersistStream;
325 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
330 r = CreateStreamOnFile(pszFileName, STGM_READWRITE | STGM_CREATE, &stm);
333 r = IPersistStream_Save(StreamThis, stm, FALSE);
334 IStream_Release( stm );
338 StartLinkProcessor( pszFileName );
340 This->bDirty = FALSE;
344 DeleteFileW( pszFileName );
345 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName) );
352 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
354 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
355 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
359 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
361 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
362 FIXME("(%p)\n",This);
366 static const IPersistFileVtbl pfvt =
368 IPersistFile_fnQueryInterface,
369 IPersistFile_fnAddRef,
370 IPersistFile_fnRelease,
371 IPersistFile_fnGetClassID,
372 IPersistFile_fnIsDirty,
375 IPersistFile_fnSaveCompleted,
376 IPersistFile_fnGetCurFile
379 /************************************************************************
380 * IPersistStream_QueryInterface
382 static HRESULT WINAPI IPersistStream_fnQueryInterface(
383 IPersistStream* iface,
387 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
388 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
391 /************************************************************************
392 * IPersistStream_Release
394 static ULONG WINAPI IPersistStream_fnRelease(
395 IPersistStream* iface)
397 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
398 return IShellLinkA_Release((IShellLinkA*)This);
401 /************************************************************************
402 * IPersistStream_AddRef
404 static ULONG WINAPI IPersistStream_fnAddRef(
405 IPersistStream* iface)
407 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
408 return IShellLinkA_AddRef((IShellLinkA*)This);
411 /************************************************************************
412 * IPersistStream_GetClassID
415 static HRESULT WINAPI IPersistStream_fnGetClassID(
416 IPersistStream* iface,
419 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
421 TRACE("(%p)\n", This);
426 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
431 /************************************************************************
432 * IPersistStream_IsDirty (IPersistStream)
434 static HRESULT WINAPI IPersistStream_fnIsDirty(
435 IPersistStream* iface)
437 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
439 TRACE("(%p)\n", This);
445 static HRESULT Stream_LoadString( IStream* stm, BOOL unicode, LPWSTR *pstr )
456 r = IStream_Read(stm, &len, sizeof(len), &count);
457 if ( FAILED (r) || ( count != sizeof(len) ) )
461 len *= sizeof (WCHAR);
463 TRACE("reading %d\n", len);
464 temp = HeapAlloc(GetProcessHeap(), 0, len+sizeof(WCHAR));
466 return E_OUTOFMEMORY;
468 r = IStream_Read(stm, temp, len, &count);
469 if( FAILED (r) || ( count != len ) )
471 HeapFree( GetProcessHeap(), 0, temp );
475 TRACE("read %s\n", debugstr_an(temp,len));
477 /* convert to unicode if necessary */
480 count = MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, NULL, 0 );
481 str = HeapAlloc( GetProcessHeap(), 0, (count+1)*sizeof (WCHAR) );
483 MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, str, count );
484 HeapFree( GetProcessHeap(), 0, temp );
498 static HRESULT Stream_ReadChunk( IStream* stm, LPVOID *data )
505 unsigned char data[1];
510 r = IStream_Read( stm, &size, sizeof(size), &count );
511 if( FAILED( r ) || count != sizeof(size) )
514 chunk = HeapAlloc( GetProcessHeap(), 0, size );
516 return E_OUTOFMEMORY;
519 r = IStream_Read( stm, chunk->data, size - sizeof(size), &count );
520 if( FAILED( r ) || count != (size - sizeof(size)) )
522 HeapFree( GetProcessHeap(), 0, chunk );
526 TRACE("Read %ld bytes\n",chunk->size);
528 *data = (LPVOID) chunk;
533 static BOOL Stream_LoadVolume( LOCAL_VOLUME_INFO *vol, volume_info *volume )
535 const int label_sz = sizeof volume->label/sizeof volume->label[0];
539 volume->serial = vol->dwVolSerial;
540 volume->type = vol->dwType;
542 if( !vol->dwVolLabelOfs )
544 if( vol->dwSize <= vol->dwVolLabelOfs )
546 len = vol->dwSize - vol->dwVolLabelOfs;
549 label += vol->dwVolLabelOfs;
550 MultiByteToWideChar( CP_ACP, 0, label, len, volume->label, label_sz-1);
555 static LPWSTR Stream_LoadPath( LPSTR p, DWORD maxlen )
560 while( p[len] && (len < maxlen) )
563 wlen = MultiByteToWideChar(CP_ACP, 0, p, len, NULL, 0);
564 path = HeapAlloc(GetProcessHeap(), 0, (wlen+1)*sizeof(WCHAR));
565 MultiByteToWideChar(CP_ACP, 0, p, len, path, wlen);
571 static HRESULT Stream_LoadLocation( IStream *stm,
572 volume_info *volume, LPWSTR *path )
574 unsigned char *p = NULL;
579 r = Stream_ReadChunk( stm, (LPVOID*) &p );
583 loc = (LOCATION_INFO*) p;
584 if (loc->dwTotalSize < sizeof(LOCATION_INFO))
586 HeapFree( GetProcessHeap(), 0, p );
590 /* if there's valid local volume information, load it */
591 if( loc->dwVolTableOfs &&
592 ((loc->dwVolTableOfs + sizeof(LOCAL_VOLUME_INFO)) <= loc->dwTotalSize) )
594 LOCAL_VOLUME_INFO *volume_info;
596 volume_info = (LOCAL_VOLUME_INFO*) &p[loc->dwVolTableOfs];
597 Stream_LoadVolume( volume_info, volume );
600 /* if there's a local path, load it */
601 n = loc->dwLocalPathOfs;
602 if( n && (n < loc->dwTotalSize) )
603 *path = Stream_LoadPath( &p[n], loc->dwTotalSize - n );
605 TRACE("type %ld serial %08lx name %s path %s\n", volume->type,
606 volume->serial, debugstr_w(volume->label), debugstr_w(*path));
608 HeapFree( GetProcessHeap(), 0, p );
613 * The format of the advertised shortcut info seems to be:
618 * 0 Length of the block (4 bytes, usually 0x314)
620 * 8 string data in ASCII
621 * 8+0x104 string data in UNICODE
623 * In the original Win32 implementation the buffers are not initialized
624 * to zero, so data trailing the string is random garbage.
626 static HRESULT Stream_LoadAdvertiseInfo( IStream* stm, LPWSTR *str )
631 EXP_DARWIN_LINK buffer;
635 r = IStream_Read( stm, &buffer.dbh.cbSize, sizeof (DWORD), &count );
639 /* make sure that we read the size of the structure even on error */
640 size = sizeof buffer - sizeof (DWORD);
641 if( buffer.dbh.cbSize != sizeof buffer )
643 ERR("Ooops. This structure is not as expected...\n");
647 r = IStream_Read( stm, &buffer.dbh.dwSignature, size, &count );
654 TRACE("magic %08lx string = %s\n", buffer.dbh.dwSignature, debugstr_w(buffer.szwDarwinID));
656 if( (buffer.dbh.dwSignature&0xffff0000) != 0xa0000000 )
658 ERR("Unknown magic number %08lx in advertised shortcut\n", buffer.dbh.dwSignature);
662 *str = HeapAlloc( GetProcessHeap(), 0,
663 (strlenW(buffer.szwDarwinID)+1) * sizeof(WCHAR) );
664 strcpyW( *str, buffer.szwDarwinID );
669 /************************************************************************
670 * IPersistStream_Load (IPersistStream)
672 static HRESULT WINAPI IPersistStream_fnLoad(
673 IPersistStream* iface,
682 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
684 TRACE("%p %p\n", This, stm);
687 return STG_E_INVALIDPOINTER;
690 r = IStream_Read(stm, &hdr, sizeof(hdr), &dwBytesRead);
694 if( dwBytesRead != sizeof(hdr))
696 if( hdr.dwSize != sizeof(hdr))
698 if( !IsEqualIID(&hdr.MagicGuid, &CLSID_ShellLink) )
701 /* free all the old stuff */
704 memset( &This->volume, 0, sizeof This->volume );
705 HeapFree(GetProcessHeap(), 0, This->sPath);
707 HeapFree(GetProcessHeap(), 0, This->sDescription);
708 This->sDescription = NULL;
709 HeapFree(GetProcessHeap(), 0, This->sPathRel);
710 This->sPathRel = NULL;
711 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
712 This->sWorkDir = NULL;
713 HeapFree(GetProcessHeap(), 0, This->sArgs);
715 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
716 This->sIcoPath = NULL;
717 HeapFree(GetProcessHeap(), 0, This->sProduct);
718 This->sProduct = NULL;
719 HeapFree(GetProcessHeap(), 0, This->sComponent);
720 This->sComponent = NULL;
722 This->wHotKey = (WORD)hdr.wHotKey;
723 This->iIcoNdx = hdr.nIcon;
724 FileTimeToSystemTime (&hdr.Time1, &This->time1);
725 FileTimeToSystemTime (&hdr.Time2, &This->time2);
726 FileTimeToSystemTime (&hdr.Time3, &This->time3);
729 WCHAR sTemp[MAX_PATH];
730 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time1,
731 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
732 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
733 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time2,
734 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
735 TRACE("-- time2: %s\n", debugstr_w(sTemp) );
736 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &This->time3,
737 NULL, sTemp, sizeof(sTemp)/sizeof(*sTemp));
738 TRACE("-- time3: %s\n", debugstr_w(sTemp) );
741 /* load all the new stuff */
742 if( hdr.dwFlags & SLDF_HAS_ID_LIST )
744 r = ILLoadFromStream( stm, &This->pPidl );
750 /* load the location information */
751 if( hdr.dwFlags & SLDF_HAS_LINK_INFO )
752 r = Stream_LoadLocation( stm, &This->volume, &This->sPath );
756 unicode = hdr.dwFlags & SLDF_UNICODE;
757 if( hdr.dwFlags & SLDF_HAS_NAME )
759 r = Stream_LoadString( stm, unicode, &This->sDescription );
760 TRACE("Description -> %s\n",debugstr_w(This->sDescription));
765 if( hdr.dwFlags & SLDF_HAS_RELPATH )
767 r = Stream_LoadString( stm, unicode, &This->sPathRel );
768 TRACE("Relative Path-> %s\n",debugstr_w(This->sPathRel));
773 if( hdr.dwFlags & SLDF_HAS_WORKINGDIR )
775 r = Stream_LoadString( stm, unicode, &This->sWorkDir );
776 TRACE("Working Dir -> %s\n",debugstr_w(This->sWorkDir));
781 if( hdr.dwFlags & SLDF_HAS_ARGS )
783 r = Stream_LoadString( stm, unicode, &This->sArgs );
784 TRACE("Working Dir -> %s\n",debugstr_w(This->sArgs));
789 if( hdr.dwFlags & SLDF_HAS_ICONLOCATION )
791 r = Stream_LoadString( stm, unicode, &This->sIcoPath );
792 TRACE("Icon file -> %s\n",debugstr_w(This->sIcoPath));
797 if( hdr.dwFlags & SLDF_HAS_LOGO3ID )
799 r = Stream_LoadAdvertiseInfo( stm, &This->sProduct );
800 TRACE("Product -> %s\n",debugstr_w(This->sProduct));
805 if( hdr.dwFlags & SLDF_HAS_DARWINID )
807 r = Stream_LoadAdvertiseInfo( stm, &This->sComponent );
808 TRACE("Component -> %s\n",debugstr_w(This->sComponent));
813 r = IStream_Read(stm, &zero, sizeof zero, &dwBytesRead);
814 if( FAILED( r ) || zero || dwBytesRead != sizeof zero )
815 ERR("Last word was not zero\n");
826 /************************************************************************
829 * Helper function for IPersistStream_Save. Writes a unicode string
830 * with terminating nul byte to a stream, preceded by the its length.
832 static HRESULT Stream_WriteString( IStream* stm, LPCWSTR str )
834 USHORT len = lstrlenW( str ) + 1;
838 r = IStream_Write( stm, &len, sizeof(len), &count );
842 len *= sizeof(WCHAR);
844 r = IStream_Write( stm, str, len, &count );
851 /************************************************************************
852 * Stream_WriteLocationInfo
854 * Writes the location info to a stream
856 * FIXME: One day we might want to write the network volume information
857 * and the final path.
858 * Figure out how Windows deals with unicode paths here.
860 static HRESULT Stream_WriteLocationInfo( IStream* stm, LPCWSTR path,
861 volume_info *volume )
863 DWORD total_size, path_size, volume_info_size, label_size, final_path_size;
864 LOCAL_VOLUME_INFO *vol;
866 LPSTR szLabel, szPath, szFinalPath;
869 TRACE("%p %s %p\n", stm, debugstr_w(path), volume);
871 /* figure out the size of everything */
872 label_size = WideCharToMultiByte( CP_ACP, 0, volume->label, -1,
873 NULL, 0, NULL, NULL );
874 path_size = WideCharToMultiByte( CP_ACP, 0, path, -1,
875 NULL, 0, NULL, NULL );
876 volume_info_size = sizeof *vol + label_size;
878 total_size = sizeof *loc + volume_info_size + path_size + final_path_size;
880 /* create pointers to everything */
881 loc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, total_size);
882 vol = (LOCAL_VOLUME_INFO*) &loc[1];
883 szLabel = (LPSTR) &vol[1];
884 szPath = &szLabel[label_size];
885 szFinalPath = &szPath[path_size];
887 /* fill in the location information header */
888 loc->dwTotalSize = total_size;
889 loc->dwHeaderSize = sizeof (*loc);
891 loc->dwVolTableOfs = sizeof (*loc);
892 loc->dwLocalPathOfs = sizeof (*loc) + volume_info_size;
893 loc->dwNetworkVolTableOfs = 0;
894 loc->dwFinalPathOfs = sizeof (*loc) + volume_info_size + path_size;
896 /* fill in the volume information */
897 vol->dwSize = volume_info_size;
898 vol->dwType = volume->type;
899 vol->dwVolSerial = volume->serial;
900 vol->dwVolLabelOfs = sizeof (*vol);
902 /* copy in the strings */
903 WideCharToMultiByte( CP_ACP, 0, volume->label, -1,
904 szLabel, label_size, NULL, NULL );
905 WideCharToMultiByte( CP_ACP, 0, path, -1,
906 szPath, path_size, NULL, NULL );
909 return IStream_Write( stm, loc, total_size, &count );
912 static HRESULT Stream_WriteAdvertiseInfo( IStream* stm, LPCWSTR string, DWORD magic )
915 EXP_DARWIN_LINK buffer;
919 memset( &buffer, 0, sizeof buffer );
920 buffer.dbh.cbSize = sizeof buffer;
921 buffer.dbh.dwSignature = magic;
922 lstrcpynW( buffer.szwDarwinID, string, MAX_PATH );
923 WideCharToMultiByte(CP_ACP, 0, string, -1, buffer.szDarwinID, MAX_PATH, NULL, NULL );
925 return IStream_Write( stm, &buffer, buffer.dbh.cbSize, &count );
928 /************************************************************************
929 * IPersistStream_Save (IPersistStream)
931 * FIXME: makes assumptions about byte order
933 static HRESULT WINAPI IPersistStream_fnSave(
934 IPersistStream* iface,
938 static const WCHAR wOpen[] = {'o','p','e','n',0};
941 WCHAR exePath[MAX_PATH];
946 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
948 TRACE("%p %p %x\n", This, stm, fClearDirty);
954 SHELL_FindExecutable(NULL, This->sPath, wOpen, exePath, MAX_PATH,
955 NULL, NULL, NULL, NULL);
957 * windows can create lnk files to executables that do not exist yet
958 * so if the executable does not exist the just trust the path they
961 if (!*exePath) strcpyW(exePath,This->sPath);
964 memset(&header, 0, sizeof(header));
965 header.dwSize = sizeof(header);
966 header.fStartup = This->iShowCmd;
967 memcpy(&header.MagicGuid, &CLSID_ShellLink, sizeof(header.MagicGuid) );
969 header.wHotKey = This->wHotKey;
970 header.nIcon = This->iIcoNdx;
971 header.dwFlags = SLDF_UNICODE; /* strings are in unicode */
973 header.dwFlags |= SLDF_HAS_ID_LIST;
975 header.dwFlags |= SLDF_HAS_LINK_INFO;
976 if( This->sDescription )
977 header.dwFlags |= SLDF_HAS_NAME;
979 header.dwFlags |= SLDF_HAS_WORKINGDIR;
981 header.dwFlags |= SLDF_HAS_ARGS;
983 header.dwFlags |= SLDF_HAS_ICONLOCATION;
985 header.dwFlags |= SLDF_HAS_LOGO3ID;
986 if( This->sComponent )
987 header.dwFlags |= SLDF_HAS_DARWINID;
989 SystemTimeToFileTime ( &This->time1, &header.Time1 );
990 SystemTimeToFileTime ( &This->time2, &header.Time2 );
991 SystemTimeToFileTime ( &This->time3, &header.Time3 );
993 /* write the Shortcut header */
994 r = IStream_Write( stm, &header, sizeof(header), &count );
997 ERR("Write failed at %d\n",__LINE__);
1001 TRACE("Writing pidl \n");
1003 /* write the PIDL to the shortcut */
1006 r = ILSaveToStream( stm, This->pPidl );
1009 ERR("Failed to write PIDL at %d\n",__LINE__);
1015 Stream_WriteLocationInfo( stm, exePath, &This->volume );
1017 if( This->sDescription )
1018 r = Stream_WriteString( stm, This->sDescription );
1020 if( This->sPathRel )
1021 r = Stream_WriteString( stm, This->sPathRel );
1023 if( This->sWorkDir )
1024 r = Stream_WriteString( stm, This->sWorkDir );
1027 r = Stream_WriteString( stm, This->sArgs );
1029 if( This->sIcoPath )
1030 r = Stream_WriteString( stm, This->sIcoPath );
1032 if( This->sProduct )
1033 r = Stream_WriteAdvertiseInfo( stm, This->sProduct, EXP_SZ_ICON_SIG );
1035 if( This->sComponent )
1036 r = Stream_WriteAdvertiseInfo( stm, This->sComponent, EXP_DARWIN_ID_SIG );
1038 /* the last field is a single zero dword */
1040 r = IStream_Write( stm, &zero, sizeof zero, &count );
1045 /************************************************************************
1046 * IPersistStream_GetSizeMax (IPersistStream)
1048 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
1049 IPersistStream* iface,
1050 ULARGE_INTEGER* pcbSize)
1052 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
1054 TRACE("(%p)\n", This);
1059 static const IPersistStreamVtbl psvt =
1061 IPersistStream_fnQueryInterface,
1062 IPersistStream_fnAddRef,
1063 IPersistStream_fnRelease,
1064 IPersistStream_fnGetClassID,
1065 IPersistStream_fnIsDirty,
1066 IPersistStream_fnLoad,
1067 IPersistStream_fnSave,
1068 IPersistStream_fnGetSizeMax
1071 /**************************************************************************
1072 * IShellLink_Constructor
1074 HRESULT WINAPI IShellLink_Constructor( IUnknown *pUnkOuter,
1075 REFIID riid, LPVOID *ppv )
1077 IShellLinkImpl * sl;
1079 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
1084 return CLASS_E_NOAGGREGATION;
1085 sl = LocalAlloc(LMEM_ZEROINIT,sizeof(IShellLinkImpl));
1087 return E_OUTOFMEMORY;
1091 sl->lpvtblw = &slvtw;
1092 sl->lpvtblPersistFile = &pfvt;
1093 sl->lpvtblPersistStream = &psvt;
1094 sl->lpvtblShellLinkDataList = &dlvt;
1095 sl->lpvtblShellExtInit = &eivt;
1096 sl->lpvtblContextMenu = &cmvt;
1097 sl->iShowCmd = SW_SHOWNORMAL;
1100 TRACE("(%p)->()\n",sl);
1102 if (IsEqualIID(riid, &IID_IUnknown) ||
1103 IsEqualIID(riid, &IID_IShellLinkA))
1105 else if (IsEqualIID(riid, &IID_IShellLinkW))
1106 *ppv = &(sl->lpvtblw);
1108 LocalFree((HLOCAL)sl);
1109 ERR("E_NOINTERFACE\n");
1110 return E_NOINTERFACE;
1117 static BOOL SHELL_ExistsFileW(LPCWSTR path)
1119 if (INVALID_FILE_ATTRIBUTES == GetFileAttributesW(path))
1124 /**************************************************************************
1125 * ShellLink_UpdatePath
1126 * update absolute path in sPath using relative path in sPathRel
1128 static HRESULT ShellLink_UpdatePath(LPWSTR sPathRel, LPCWSTR path, LPCWSTR sWorkDir, LPWSTR* psPath)
1130 if (!path || !psPath)
1131 return E_INVALIDARG;
1133 if (!*psPath && sPathRel) {
1134 WCHAR buffer[2*MAX_PATH], abs_path[2*MAX_PATH];
1135 LPWSTR final = NULL;
1137 /* first try if [directory of link file] + [relative path] finds an existing file */
1139 GetFullPathNameW( path, MAX_PATH*2, buffer, &final );
1142 lstrcpyW(final, sPathRel);
1146 if (SHELL_ExistsFileW(buffer)) {
1147 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1148 lstrcpyW(abs_path, buffer);
1150 /* try if [working directory] + [relative path] finds an existing file */
1152 lstrcpyW(buffer, sWorkDir);
1153 lstrcpyW(PathAddBackslashW(buffer), sPathRel);
1155 if (SHELL_ExistsFileW(buffer))
1156 if (!GetFullPathNameW(buffer, MAX_PATH, abs_path, &final))
1157 lstrcpyW(abs_path, buffer);
1161 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
1163 lstrcpyW(abs_path, sPathRel);
1165 *psPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path)+1)*sizeof(WCHAR));
1167 return E_OUTOFMEMORY;
1169 lstrcpyW(*psPath, abs_path);
1175 /**************************************************************************
1176 * IShellLink_ConstructFromFile
1178 HRESULT WINAPI IShellLink_ConstructFromFile( IUnknown* pUnkOuter, REFIID riid,
1179 LPCITEMIDLIST pidl, LPVOID* ppv)
1183 HRESULT hr = IShellLink_Constructor(NULL, riid, (LPVOID*)&psl);
1185 if (SUCCEEDED(hr)) {
1190 hr = IShellLinkW_QueryInterface(psl, &IID_IPersistFile, (LPVOID*)&ppf);
1192 if (SUCCEEDED(hr)) {
1193 WCHAR path[MAX_PATH];
1195 if (SHGetPathFromIDListW(pidl, path))
1196 hr = IPersistFile_Load(ppf, path, 0);
1201 *ppv = (IUnknown*) psl;
1203 IPersistFile_Release(ppf);
1207 IShellLinkW_Release(psl);
1213 /**************************************************************************
1214 * IShellLinkA_QueryInterface
1216 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
1218 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1220 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
1224 if(IsEqualIID(riid, &IID_IUnknown) ||
1225 IsEqualIID(riid, &IID_IShellLinkA))
1229 else if(IsEqualIID(riid, &IID_IShellLinkW))
1231 *ppvObj = &(This->lpvtblw);
1233 else if(IsEqualIID(riid, &IID_IPersistFile))
1235 *ppvObj = &(This->lpvtblPersistFile);
1237 else if(IsEqualIID(riid, &IID_IPersistStream))
1239 *ppvObj = &(This->lpvtblPersistStream);
1241 else if(IsEqualIID(riid, &IID_IShellLinkDataList))
1243 *ppvObj = &(This->lpvtblShellLinkDataList);
1245 else if(IsEqualIID(riid, &IID_IShellExtInit))
1247 *ppvObj = &(This->lpvtblShellExtInit);
1249 else if(IsEqualIID(riid, &IID_IContextMenu))
1251 *ppvObj = &(This->lpvtblContextMenu);
1256 IUnknown_AddRef((IUnknown*)(*ppvObj));
1257 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
1260 ERR("-- Interface: E_NOINTERFACE\n");
1261 return E_NOINTERFACE;
1264 /******************************************************************************
1265 * IShellLinkA_AddRef
1267 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
1269 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1270 ULONG refCount = InterlockedIncrement(&This->ref);
1272 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
1277 /******************************************************************************
1278 * IShellLinkA_Release
1280 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
1282 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1283 ULONG refCount = InterlockedDecrement(&This->ref);
1285 TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
1290 TRACE("-- destroying IShellLink(%p)\n",This);
1292 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1293 HeapFree(GetProcessHeap(), 0, This->sArgs);
1294 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1295 HeapFree(GetProcessHeap(), 0, This->sDescription);
1296 HeapFree(GetProcessHeap(),0,This->sPath);
1299 ILFree(This->pPidl);
1301 LocalFree((HANDLE)This);
1306 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,
1307 INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1309 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1311 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1312 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
1314 if (This->sComponent || This->sProduct)
1320 WideCharToMultiByte( CP_ACP, 0, This->sPath, -1,
1321 pszFile, cchMaxPath, NULL, NULL);
1323 if (pfd) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This);
1328 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1330 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1332 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1334 return IShellLinkW_GetIDList((IShellLinkW*)&(This->lpvtblw), ppidl);
1337 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1339 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1341 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1344 ILFree(This->pPidl);
1345 This->pPidl = ILClone (pidl);
1346 This->bDirty = TRUE;
1351 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1353 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1355 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1359 if( This->sDescription )
1360 WideCharToMultiByte( CP_ACP, 0, This->sDescription, -1,
1361 pszName, cchMaxName, NULL, NULL);
1366 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1368 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1370 TRACE("(%p)->(pName=%s)\n", This, pszName);
1372 HeapFree(GetProcessHeap(), 0, This->sDescription);
1373 This->sDescription = HEAP_strdupAtoW( GetProcessHeap(), 0, pszName);
1374 if ( !This->sDescription )
1375 return E_OUTOFMEMORY;
1377 This->bDirty = TRUE;
1382 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1384 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1386 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1390 if( This->sWorkDir )
1391 WideCharToMultiByte( CP_ACP, 0, This->sWorkDir, -1,
1392 pszDir, cchMaxPath, NULL, NULL);
1397 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1399 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1401 TRACE("(%p)->(dir=%s)\n",This, pszDir);
1403 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1404 This->sWorkDir = HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir);
1405 if ( !This->sWorkDir )
1406 return E_OUTOFMEMORY;
1408 This->bDirty = TRUE;
1413 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1415 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1417 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1422 WideCharToMultiByte( CP_ACP, 0, This->sArgs, -1,
1423 pszArgs, cchMaxPath, NULL, NULL);
1428 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1430 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1432 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1434 HeapFree(GetProcessHeap(), 0, This->sArgs);
1435 This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs);
1437 return E_OUTOFMEMORY;
1439 This->bDirty = TRUE;
1444 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1446 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1448 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1450 *pwHotkey = This->wHotKey;
1455 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1457 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1459 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1461 This->wHotKey = wHotkey;
1462 This->bDirty = TRUE;
1467 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1469 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1471 TRACE("(%p)->(%p)\n",This, piShowCmd);
1472 *piShowCmd = This->iShowCmd;
1476 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1478 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1480 TRACE("(%p) %d\n",This, iShowCmd);
1482 This->iShowCmd = iShowCmd;
1483 This->bDirty = TRUE;
1488 static HRESULT SHELL_PidlGeticonLocationA(IShellFolder* psf, LPITEMIDLIST pidl, LPSTR pszIconPath, int cchIconPath, int* piIcon)
1490 LPCITEMIDLIST pidlLast;
1492 HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
1494 if (SUCCEEDED(hr)) {
1497 hr = IShellFolder_GetUIObjectOf(psf, 0, 1, (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconA, NULL, (LPVOID*)&pei);
1499 if (SUCCEEDED(hr)) {
1500 hr = IExtractIconA_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
1502 IExtractIconA_Release(pei);
1505 IShellFolder_Release(psf);
1511 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1513 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1515 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1518 *piIcon = This->iIcoNdx;
1522 WideCharToMultiByte(CP_ACP, 0, This->sIcoPath, -1, pszIconPath, cchIconPath, NULL, NULL);
1526 if (This->pPidl || This->sPath)
1530 HRESULT hr = SHGetDesktopFolder(&pdsk);
1534 /* first look for an icon using the PIDL (if present) */
1536 hr = SHELL_PidlGeticonLocationA(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
1540 /* if we couldn't find an icon yet, look for it using the file system path */
1541 if (FAILED(hr) && This->sPath)
1545 hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
1547 if (SUCCEEDED(hr)) {
1548 hr = SHELL_PidlGeticonLocationA(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
1554 IShellFolder_Release(pdsk);
1562 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1564 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1566 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1568 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1569 This->sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1570 if ( !This->sIcoPath )
1571 return E_OUTOFMEMORY;
1573 This->iIcoNdx = iIcon;
1574 This->bDirty = TRUE;
1579 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1581 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1583 TRACE("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1585 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1586 This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1587 This->bDirty = TRUE;
1589 return ShellLink_UpdatePath(This->sPathRel, This->sPath, This->sWorkDir, &This->sPath);
1592 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1594 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1596 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1598 return IShellLinkW_Resolve( (IShellLinkW*)&(This->lpvtblw), hwnd, fFlags );
1601 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1605 IShellLinkImpl *This = (IShellLinkImpl *)iface;
1607 TRACE("(%p)->(path=%s)\n",This, pszFile);
1609 str = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1611 return E_OUTOFMEMORY;
1613 r = IShellLinkW_SetPath((IShellLinkW*)&(This->lpvtblw), str);
1614 HeapFree( GetProcessHeap(), 0, str );
1619 /**************************************************************************
1620 * IShellLink Implementation
1623 static const IShellLinkAVtbl slvt =
1625 IShellLinkA_fnQueryInterface,
1626 IShellLinkA_fnAddRef,
1627 IShellLinkA_fnRelease,
1628 IShellLinkA_fnGetPath,
1629 IShellLinkA_fnGetIDList,
1630 IShellLinkA_fnSetIDList,
1631 IShellLinkA_fnGetDescription,
1632 IShellLinkA_fnSetDescription,
1633 IShellLinkA_fnGetWorkingDirectory,
1634 IShellLinkA_fnSetWorkingDirectory,
1635 IShellLinkA_fnGetArguments,
1636 IShellLinkA_fnSetArguments,
1637 IShellLinkA_fnGetHotkey,
1638 IShellLinkA_fnSetHotkey,
1639 IShellLinkA_fnGetShowCmd,
1640 IShellLinkA_fnSetShowCmd,
1641 IShellLinkA_fnGetIconLocation,
1642 IShellLinkA_fnSetIconLocation,
1643 IShellLinkA_fnSetRelativePath,
1644 IShellLinkA_fnResolve,
1645 IShellLinkA_fnSetPath
1649 /**************************************************************************
1650 * IShellLinkW_fnQueryInterface
1652 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1653 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1655 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1656 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1659 /******************************************************************************
1660 * IShellLinkW_fnAddRef
1662 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1664 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1665 return IShellLinkA_AddRef((IShellLinkA*)This);
1667 /******************************************************************************
1668 * IShellLinkW_fnRelease
1671 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1673 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1674 return IShellLinkA_Release((IShellLinkA*)This);
1677 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags)
1679 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1681 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1682 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
1684 if (This->sComponent || This->sProduct)
1690 lstrcpynW( pszFile, This->sPath, cchMaxPath );
1692 if (pfd) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This);
1697 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1699 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1701 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1705 *ppidl = ILClone(This->pPidl);
1709 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1711 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1713 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1716 ILFree( This->pPidl );
1717 This->pPidl = ILClone( pidl );
1721 This->bDirty = TRUE;
1726 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1728 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1730 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1733 if( This->sDescription )
1734 lstrcpynW( pszName, This->sDescription, cchMaxName );
1739 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1741 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1743 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1745 HeapFree(GetProcessHeap(), 0, This->sDescription);
1746 This->sDescription = HeapAlloc( GetProcessHeap(), 0,
1747 (lstrlenW( pszName )+1)*sizeof(WCHAR) );
1748 if ( !This->sDescription )
1749 return E_OUTOFMEMORY;
1751 lstrcpyW( This->sDescription, pszName );
1752 This->bDirty = TRUE;
1757 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1759 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1761 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1765 if( This->sWorkDir )
1766 lstrcpynW( pszDir, This->sWorkDir, cchMaxPath );
1771 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1773 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1775 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1777 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1778 This->sWorkDir = HeapAlloc( GetProcessHeap(), 0,
1779 (lstrlenW( pszDir )+1)*sizeof (WCHAR) );
1780 if ( !This->sWorkDir )
1781 return E_OUTOFMEMORY;
1782 lstrcpyW( This->sWorkDir, pszDir );
1783 This->bDirty = TRUE;
1788 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1790 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1792 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1797 lstrcpynW( pszArgs, This->sArgs, cchMaxPath );
1802 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1804 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1806 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1808 HeapFree(GetProcessHeap(), 0, This->sArgs);
1809 This->sArgs = HeapAlloc( GetProcessHeap(), 0,
1810 (lstrlenW( pszArgs )+1)*sizeof (WCHAR) );
1812 return E_OUTOFMEMORY;
1813 lstrcpyW( This->sArgs, pszArgs );
1814 This->bDirty = TRUE;
1819 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1821 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1823 TRACE("(%p)->(%p)\n",This, pwHotkey);
1825 *pwHotkey=This->wHotKey;
1830 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1832 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1834 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1836 This->wHotKey = wHotkey;
1837 This->bDirty = TRUE;
1842 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1844 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1846 TRACE("(%p)->(%p)\n",This, piShowCmd);
1848 *piShowCmd = This->iShowCmd;
1853 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1855 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1857 This->iShowCmd = iShowCmd;
1858 This->bDirty = TRUE;
1863 static HRESULT SHELL_PidlGeticonLocationW(IShellFolder* psf, LPITEMIDLIST pidl, LPWSTR pszIconPath, int cchIconPath, int* piIcon)
1865 LPCITEMIDLIST pidlLast;
1867 HRESULT hr = SHBindToParent(pidl, &IID_IShellFolder, (LPVOID*)&psf, &pidlLast);
1869 if (SUCCEEDED(hr)) {
1872 hr = IShellFolder_GetUIObjectOf(psf, 0, 1, (LPCITEMIDLIST*)&pidlLast, &IID_IExtractIconW, NULL, (LPVOID*)&pei);
1874 if (SUCCEEDED(hr)) {
1875 hr = IExtractIconW_GetIconLocation(pei, 0, pszIconPath, MAX_PATH, piIcon, NULL);
1877 IExtractIconW_Release(pei);
1880 IShellFolder_Release(psf);
1886 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1888 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1890 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1893 *piIcon = This->iIcoNdx;
1897 lstrcpynW(pszIconPath, This->sIcoPath, cchIconPath);
1901 if (This->pPidl || This->sPath)
1905 HRESULT hr = SHGetDesktopFolder(&pdsk);
1909 /* first look for an icon using the PIDL (if present) */
1911 hr = SHELL_PidlGeticonLocationW(pdsk, This->pPidl, pszIconPath, cchIconPath, piIcon);
1915 /* if we couldn't find an icon yet, look for it using the file system path */
1916 if (FAILED(hr) && This->sPath)
1920 hr = IShellFolder_ParseDisplayName(pdsk, 0, NULL, This->sPath, NULL, &pidl, NULL);
1924 hr = SHELL_PidlGeticonLocationW(pdsk, pidl, pszIconPath, cchIconPath, piIcon);
1930 IShellFolder_Release(pdsk);
1937 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1939 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1941 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1943 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1944 This->sIcoPath = HeapAlloc( GetProcessHeap(), 0,
1945 (lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
1946 if ( !This->sIcoPath )
1947 return E_OUTOFMEMORY;
1948 lstrcpyW( This->sIcoPath, pszIconPath );
1950 This->iIcoNdx = iIcon;
1951 This->bDirty = TRUE;
1956 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1958 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1960 TRACE("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1962 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1963 This->sPathRel = HeapAlloc( GetProcessHeap(), 0,
1964 (lstrlenW( pszPathRel )+1) * sizeof (WCHAR) );
1965 if ( !This->sPathRel )
1966 return E_OUTOFMEMORY;
1967 lstrcpyW( This->sPathRel, pszPathRel );
1968 This->bDirty = TRUE;
1970 return ShellLink_UpdatePath(This->sPathRel, This->sPath, This->sWorkDir, &This->sPath);
1973 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1978 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1980 TRACE("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1982 /*FIXME: use IResolveShellLink interface */
1984 if (!This->sPath && This->pPidl) {
1985 WCHAR buffer[MAX_PATH];
1987 bSuccess = SHGetPathFromIDListW(This->pPidl, buffer);
1989 if (bSuccess && *buffer) {
1990 This->sPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer)+1)*sizeof(WCHAR));
1992 return E_OUTOFMEMORY;
1994 lstrcpyW(This->sPath, buffer);
1996 This->bDirty = TRUE;
1998 hr = S_OK; /* don't report an error occurred while just caching information */
2001 if (!This->sIcoPath && This->sPath) {
2002 This->sIcoPath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This->sPath)+1)*sizeof(WCHAR));
2003 if (!This->sIcoPath)
2004 return E_OUTOFMEMORY;
2006 lstrcpyW(This->sIcoPath, This->sPath);
2009 This->bDirty = TRUE;
2015 static LPWSTR ShellLink_GetAdvertisedArg(LPCWSTR str)
2024 p = strchrW( str, ':' );
2028 ret = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*(len+1));
2031 memcpy( ret, str, sizeof(WCHAR)*len );
2036 static HRESULT ShellLink_SetAdvertiseInfo(IShellLinkImpl *This, LPCWSTR str)
2038 LPCWSTR szComponent = NULL, szProduct = NULL, p;
2046 /* each segment must start with two colons */
2047 if( str[0] != ':' || str[1] != ':' )
2050 /* the last segment is just two colons */
2055 /* there must be a colon straight after a guid */
2056 p = strchrW( str, ':' );
2063 /* get the guid, and check it's validly formatted */
2064 memcpy( szGuid, str, sizeof(WCHAR)*len );
2066 r = CLSIDFromString( szGuid, &guid );
2071 /* match it up to a guid that we care about */
2072 if( IsEqualGUID( &guid, &SHELL32_AdvtShortcutComponent ) && !szComponent )
2074 else if( IsEqualGUID( &guid, &SHELL32_AdvtShortcutProduct ) && !szProduct )
2079 /* skip to the next field */
2080 str = strchrW( str, ':' );
2085 /* we have to have a component for an advertised shortcut */
2089 This->sComponent = ShellLink_GetAdvertisedArg( szComponent );
2090 This->sProduct = ShellLink_GetAdvertisedArg( szProduct );
2092 TRACE("Component = %s\n", debugstr_w(This->sComponent));
2093 TRACE("Product = %s\n", debugstr_w(This->sProduct));
2098 static BOOL ShellLink_GetVolumeInfo(LPWSTR path, volume_info *volume)
2100 const int label_sz = sizeof volume->label/sizeof volume->label[0];
2101 WCHAR drive[4] = { path[0], ':', '\\', 0 };
2104 volume->type = GetDriveTypeW(drive);
2105 r = GetVolumeInformationW(drive, volume->label, label_sz,
2106 &volume->serial, NULL, NULL, NULL, 0);
2107 TRACE("r = %d type %ld serial %08lx name %s\n", r,
2108 volume->type, volume->serial, debugstr_w(volume->label));
2112 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
2114 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
2115 WCHAR buffer[MAX_PATH];
2119 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
2121 HeapFree(GetProcessHeap(), 0, This->sPath);
2124 HeapFree(GetProcessHeap(), 0, This->sComponent);
2125 This->sComponent = NULL;
2128 ILFree(This->pPidl);
2131 if (S_OK != ShellLink_SetAdvertiseInfo( This, pszFile ))
2133 if (*pszFile == '\0')
2135 else if (!GetFullPathNameW(pszFile, MAX_PATH, buffer, &fname))
2137 else if(!PathFileExistsW(buffer))
2140 This->pPidl = SHSimpleIDListFromPathW(pszFile);
2141 ShellLink_GetVolumeInfo(buffer, &This->volume);
2143 This->sPath = HeapAlloc( GetProcessHeap(), 0,
2144 (lstrlenW( buffer )+1) * sizeof (WCHAR) );
2146 return E_OUTOFMEMORY;
2148 lstrcpyW(This->sPath, buffer);
2150 This->bDirty = TRUE;
2155 /**************************************************************************
2156 * IShellLinkW Implementation
2159 static const IShellLinkWVtbl slvtw =
2161 IShellLinkW_fnQueryInterface,
2162 IShellLinkW_fnAddRef,
2163 IShellLinkW_fnRelease,
2164 IShellLinkW_fnGetPath,
2165 IShellLinkW_fnGetIDList,
2166 IShellLinkW_fnSetIDList,
2167 IShellLinkW_fnGetDescription,
2168 IShellLinkW_fnSetDescription,
2169 IShellLinkW_fnGetWorkingDirectory,
2170 IShellLinkW_fnSetWorkingDirectory,
2171 IShellLinkW_fnGetArguments,
2172 IShellLinkW_fnSetArguments,
2173 IShellLinkW_fnGetHotkey,
2174 IShellLinkW_fnSetHotkey,
2175 IShellLinkW_fnGetShowCmd,
2176 IShellLinkW_fnSetShowCmd,
2177 IShellLinkW_fnGetIconLocation,
2178 IShellLinkW_fnSetIconLocation,
2179 IShellLinkW_fnSetRelativePath,
2180 IShellLinkW_fnResolve,
2181 IShellLinkW_fnSetPath
2184 static HRESULT WINAPI
2185 ShellLink_DataList_QueryInterface( IShellLinkDataList* iface, REFIID riid, void** ppvObject)
2187 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl, iface);
2188 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2192 ShellLink_DataList_AddRef( IShellLinkDataList* iface )
2194 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl, iface);
2195 return IShellLinkA_AddRef((IShellLinkA*)This);
2199 ShellLink_DataList_Release( IShellLinkDataList* iface )
2201 _ICOM_THIS_From_IShellLinkDataList(IShellLinkImpl, iface);
2202 return IShellLinkA_Release((IShellLinkA*)This);
2205 static HRESULT WINAPI
2206 ShellLink_AddDataBlock( IShellLinkDataList* iface, void* pDataBlock )
2212 static HRESULT WINAPI
2213 ShellLink_CopyDataBlock( IShellLinkDataList* iface, DWORD dwSig, void** ppDataBlock )
2219 static HRESULT WINAPI
2220 ShellLink_RemoveDataBlock( IShellLinkDataList* iface, DWORD dwSig )
2226 static HRESULT WINAPI
2227 ShellLink_GetFlags( IShellLinkDataList* iface, DWORD* pdwFlags )
2233 static HRESULT WINAPI
2234 ShellLink_SetFlags( IShellLinkDataList* iface, DWORD dwFlags )
2240 static const IShellLinkDataListVtbl dlvt =
2242 ShellLink_DataList_QueryInterface,
2243 ShellLink_DataList_AddRef,
2244 ShellLink_DataList_Release,
2245 ShellLink_AddDataBlock,
2246 ShellLink_CopyDataBlock,
2247 ShellLink_RemoveDataBlock,
2252 static HRESULT WINAPI
2253 ShellLink_ExtInit_QueryInterface( IShellExtInit* iface, REFIID riid, void** ppvObject )
2255 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl, iface);
2256 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2260 ShellLink_ExtInit_AddRef( IShellExtInit* iface )
2262 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl, iface);
2263 return IShellLinkA_AddRef((IShellLinkA*)This);
2267 ShellLink_ExtInit_Release( IShellExtInit* iface )
2269 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl, iface);
2270 return IShellLinkA_Release((IShellLinkA*)This);
2273 /**************************************************************************
2274 * ShellLink implementation of IShellExtInit::Initialize()
2276 * Loads the shelllink from the dataobject the shell is pointing to.
2278 static HRESULT WINAPI
2279 ShellLink_ExtInit_Initialize( IShellExtInit* iface, LPCITEMIDLIST pidlFolder,
2280 IDataObject *pdtobj, HKEY hkeyProgID )
2282 _ICOM_THIS_From_IShellExtInit(IShellLinkImpl, iface);
2288 TRACE("%p %p %p %p\n", This, pidlFolder, pdtobj, hkeyProgID );
2293 format.cfFormat = CF_HDROP;
2295 format.dwAspect = DVASPECT_CONTENT;
2297 format.tymed = TYMED_HGLOBAL;
2299 if( FAILED( IDataObject_GetData( pdtobj, &format, &stgm ) ) )
2302 count = DragQueryFileW( stgm.u.hGlobal, -1, NULL, 0 );
2307 count = DragQueryFileW( stgm.u.hGlobal, 0, NULL, 0 );
2309 path = HeapAlloc( GetProcessHeap(), 0, count*sizeof(WCHAR) );
2312 IPersistFile *pf = (IPersistFile*) &This->lpvtblPersistFile;
2314 count = DragQueryFileW( stgm.u.hGlobal, 0, path, count );
2315 r = IPersistFile_Load( pf, path, 0 );
2316 HeapFree( GetProcessHeap(), 0, path );
2319 ReleaseStgMedium( &stgm );
2324 static const IShellExtInitVtbl eivt =
2326 ShellLink_ExtInit_QueryInterface,
2327 ShellLink_ExtInit_AddRef,
2328 ShellLink_ExtInit_Release,
2329 ShellLink_ExtInit_Initialize
2332 static HRESULT WINAPI
2333 ShellLink_ContextMenu_QueryInterface( IContextMenu* iface, REFIID riid, void** ppvObject )
2335 _ICOM_THIS_From_IContextMenu(IShellLinkImpl, iface);
2336 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObject);
2340 ShellLink_ContextMenu_AddRef( IContextMenu* iface )
2342 _ICOM_THIS_From_IContextMenu(IShellLinkImpl, iface);
2343 return IShellLinkA_AddRef((IShellLinkA*)This);
2347 ShellLink_ContextMenu_Release( IContextMenu* iface )
2349 _ICOM_THIS_From_IContextMenu(IShellLinkImpl, iface);
2350 return IShellLinkA_Release((IShellLinkA*)This);
2353 static HRESULT WINAPI
2354 ShellLink_QueryContextMenu( IContextMenu* iface, HMENU hmenu, UINT indexMenu,
2355 UINT idCmdFirst, UINT idCmdLast, UINT uFlags )
2357 _ICOM_THIS_From_IContextMenu(IShellLinkImpl, iface);
2359 FIXME("%p %p %u %u %u %u\n", This,
2360 hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags );
2365 static HRESULT WINAPI
2366 ShellLink_InvokeCommand( IContextMenu* iface, LPCMINVOKECOMMANDINFO lpici )
2368 _ICOM_THIS_From_IContextMenu(IShellLinkImpl, iface);
2370 FIXME("%p %p\n", This, lpici );
2375 static HRESULT WINAPI
2376 ShellLink_GetCommandString( IContextMenu* iface, UINT idCmd, UINT uType,
2377 UINT* pwReserved, LPSTR pszName, UINT cchMax )
2379 _ICOM_THIS_From_IContextMenu(IShellLinkImpl, iface);
2381 FIXME("%p %u %u %p %p %u\n", This,
2382 idCmd, uType, pwReserved, pszName, cchMax );
2387 static const IContextMenuVtbl cmvt =
2389 ShellLink_ContextMenu_QueryInterface,
2390 ShellLink_ContextMenu_AddRef,
2391 ShellLink_ContextMenu_Release,
2392 ShellLink_QueryContextMenu,
2393 ShellLink_InvokeCommand,
2394 ShellLink_GetCommandString