3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Nearly complete informations about the binary formats
22 * of .lnk files avaiable at http://www.wotsit.org
37 #ifdef HAVE_SYS_WAIT_H
38 # include <sys/wait.h>
40 #include "wine/debug.h"
41 #include "wine/port.h"
51 #include "undocshell.h"
55 #include "shell32_main.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(shell);
60 /* link file formats */
62 /* flag1: lnk elements: simple link has 0x0B */
65 #define SCF_DESCRIPTION 4
66 #define SCF_RELATIVE 8
67 #define SCF_WORKDIR 0x10
69 #define SCF_CUSTOMICON 0x40
71 #define SCF_UNICODE 0x1000
75 typedef struct _LINK_HEADER
77 DWORD dwSize; /* 0x00 size of the header - 0x4c */
78 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
79 DWORD dwFlags; /* 0x14 describes elements following */
80 DWORD dwFileAttr; /* 0x18 attributes of the target file */
81 FILETIME Time1; /* 0x1c */
82 FILETIME Time2; /* 0x24 */
83 FILETIME Time3; /* 0x2c */
84 DWORD dwFileLength; /* 0x34 File length */
85 DWORD nIcon; /* 0x38 icon number */
86 DWORD fStartup; /* 0x3c startup type */
87 DWORD wHotKey; /* 0x40 hotkey */
88 DWORD Unknown5; /* 0x44 */
89 DWORD Unknown6; /* 0x48 */
90 } LINK_HEADER, * PLINK_HEADER;
92 #define SHLINK_LOCAL 0
93 #define SHLINK_REMOTE 1
95 typedef struct _LOCATION_INFO
101 DWORD dwLocalPathOfs;
102 DWORD dwNetworkVolTableOfs;
103 DWORD dwFinalPathOfs;
106 typedef struct _LOCAL_VOLUME_INFO
116 static ICOM_VTABLE(IShellLinkA) slvt;
117 static ICOM_VTABLE(IShellLinkW) slvtw;
118 static ICOM_VTABLE(IPersistFile) pfvt;
119 static ICOM_VTABLE(IPersistStream) psvt;
121 /* IShellLink Implementation */
125 ICOM_VFIELD(IShellLinkA);
128 ICOM_VTABLE(IShellLinkW)* lpvtblw;
129 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
130 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
132 /* data structures according to the informations in the lnk */
149 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
150 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
152 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
153 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
155 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
156 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
157 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset)
160 /* strdup on the process heap */
161 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str)
163 INT len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
164 LPWSTR p = HeapAlloc( heap, flags, len*sizeof (WCHAR) );
167 MultiByteToWideChar( CP_ACP, 0, str, -1, p, len );
172 /**************************************************************************
173 * IPersistFile_QueryInterface
175 static HRESULT WINAPI IPersistFile_fnQueryInterface(
180 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
182 TRACE("(%p)\n",This);
184 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
187 /******************************************************************************
188 * IPersistFile_AddRef
190 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
192 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
194 TRACE("(%p)->(count=%lu)\n",This,This->ref);
196 return IShellLinkA_AddRef((IShellLinkA*)This);
198 /******************************************************************************
199 * IPersistFile_Release
201 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
203 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
205 TRACE("(%p)->(count=%lu)\n",This,This->ref);
207 return IShellLinkA_Release((IShellLinkA*)This);
210 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
212 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
213 FIXME("(%p)\n",This);
216 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
218 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
219 FIXME("(%p)\n",This);
222 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
224 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
225 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
229 TRACE("(%p, %s)\n",This, debugstr_w(pszFileName));
231 r = CreateStreamOnFile(pszFileName, dwMode, &stm);
234 r = IPersistStream_Load(StreamThis, stm);
235 IStream_Release( stm );
241 static BOOL StartLinkProcessor( LPCOLESTR szLink )
243 const WCHAR szFormat[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
244 ' ','-','r',' ','"','%','s','"',0 };
248 PROCESS_INFORMATION pi;
250 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
251 buffer = HeapAlloc( GetProcessHeap(), 0, len );
255 wsprintfW( buffer, szFormat, szLink );
257 TRACE("starting %s\n",debugstr_w(buffer));
259 memset(&si, 0, sizeof(si));
261 if (!CreateProcessW( NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return FALSE;
263 /* wait for a while to throttle the creation of linker processes */
264 if( WAIT_OBJECT_0 != WaitForSingleObject( pi.hProcess, 10000 ) )
265 WARN("Timed out waiting for shell linker\n");
267 CloseHandle( pi.hProcess );
268 CloseHandle( pi.hThread );
273 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
275 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
276 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
280 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
282 if (!pszFileName || !This->sPath)
283 return ERROR_UNKNOWN;
285 r = CreateStreamOnFile(pszFileName, STGM_READWRITE | STGM_CREATE, &stm);
288 r = IPersistStream_Save(StreamThis, stm, FALSE);
289 IStream_Release( stm );
292 StartLinkProcessor( pszFileName );
295 DeleteFileW( pszFileName );
296 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName) );
303 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
305 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
306 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
309 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
311 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
312 FIXME("(%p)\n",This);
316 static ICOM_VTABLE(IPersistFile) pfvt =
318 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
319 IPersistFile_fnQueryInterface,
320 IPersistFile_fnAddRef,
321 IPersistFile_fnRelease,
322 IPersistFile_fnGetClassID,
323 IPersistFile_fnIsDirty,
326 IPersistFile_fnSaveCompleted,
327 IPersistFile_fnGetCurFile
330 /************************************************************************
331 * IPersistStream_QueryInterface
333 static HRESULT WINAPI IPersistStream_fnQueryInterface(
334 IPersistStream* iface,
338 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
340 TRACE("(%p)\n",This);
342 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
345 /************************************************************************
346 * IPersistStream_Release
348 static ULONG WINAPI IPersistStream_fnRelease(
349 IPersistStream* iface)
351 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
353 TRACE("(%p)\n",This);
355 return IShellLinkA_Release((IShellLinkA*)This);
358 /************************************************************************
359 * IPersistStream_AddRef
361 static ULONG WINAPI IPersistStream_fnAddRef(
362 IPersistStream* iface)
364 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
366 TRACE("(%p)\n",This);
368 return IShellLinkA_AddRef((IShellLinkA*)This);
371 /************************************************************************
372 * IPersistStream_GetClassID
375 static HRESULT WINAPI IPersistStream_fnGetClassID(
376 IPersistStream* iface,
379 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
381 TRACE("(%p)\n", This);
386 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
391 /************************************************************************
392 * IPersistStream_IsDirty (IPersistStream)
394 static HRESULT WINAPI IPersistStream_fnIsDirty(
395 IPersistStream* iface)
397 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
399 TRACE("(%p)\n", This);
405 static HRESULT Stream_LoadString( IStream* stm, BOOL unicode, LPWSTR *pstr )
416 r = IStream_Read(stm, &len, sizeof(len), &count);
417 if ( FAILED (r) || ( count != sizeof(len) ) )
421 len *= sizeof (WCHAR);
423 TRACE("reading %d\n", len);
424 temp = HeapAlloc(GetProcessHeap(), 0, len+sizeof(WCHAR));
426 return E_OUTOFMEMORY;
428 r = IStream_Read(stm, temp, len, &count);
429 if( FAILED (r) || ( count != len ) )
431 HeapFree( GetProcessHeap(), 0, temp );
435 TRACE("read %s\n", debugstr_an(temp,len));
437 /* convert to unicode if necessary */
440 count = MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, NULL, 0 );
441 str = HeapAlloc( GetProcessHeap(), 0, (count+1)*sizeof (WCHAR) );
443 MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, str, count );
444 HeapFree( GetProcessHeap(), 0, temp );
458 static HRESULT Stream_LoadLocation( IStream* stm )
467 r = IStream_Read( stm, &size, sizeof(size), &count );
470 if( count != sizeof(loc->dwTotalSize) )
473 loc = HeapAlloc( GetProcessHeap(), 0, size );
475 return E_OUTOFMEMORY;
477 r = IStream_Read( stm, &loc->dwHeaderSize, size-sizeof(size), &count );
480 if( count != (size - sizeof(size)) )
485 loc->dwTotalSize = size;
487 TRACE("Read %ld bytes\n",count);
489 /* FIXME: do something useful with it */
490 HeapFree( GetProcessHeap(), 0, loc );
494 HeapFree( GetProcessHeap(), 0, loc );
498 /************************************************************************
499 * IPersistStream_Load (IPersistStream)
501 static HRESULT WINAPI IPersistStream_fnLoad(
502 IPersistStream* iface,
508 WCHAR sTemp[MAX_PATH];
511 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
513 TRACE("(%p)(%p)\n", This, stm);
516 return STG_E_INVALIDPOINTER;
519 r = IStream_Read(stm, &hdr, sizeof(hdr), &dwBytesRead);
523 if( dwBytesRead != sizeof(hdr))
525 if( hdr.dwSize != sizeof(hdr))
527 if( !IsEqualIID(&hdr.MagicGuid, &CLSID_ShellLink) )
530 /* if( hdr.dwFlags & SCF_PIDL ) */ /* FIXME: seems to always have a PIDL */
532 r = ILLoadFromStream( stm, &This->pPidl );
536 This->wHotKey = hdr.wHotKey;
537 This->iIcoNdx = hdr.nIcon;
538 FileTimeToSystemTime (&hdr.Time1, &This->time1);
539 FileTimeToSystemTime (&hdr.Time2, &This->time2);
540 FileTimeToSystemTime (&hdr.Time3, &This->time3);
542 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
543 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
544 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
545 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
546 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
547 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
550 if( hdr.dwFlags & SCF_NORMAL )
551 r = Stream_LoadLocation( stm );
554 unicode = hdr.dwFlags & SCF_UNICODE;
555 if( hdr.dwFlags & SCF_DESCRIPTION )
557 r = Stream_LoadString( stm, unicode, &This->sDescription );
558 TRACE("Description -> %s\n",debugstr_w(This->sDescription));
563 if( hdr.dwFlags & SCF_RELATIVE )
565 r = Stream_LoadString( stm, unicode, &This->sPathRel );
566 TRACE("Relative Path-> %s\n",debugstr_w(This->sPathRel));
571 if( hdr.dwFlags & SCF_WORKDIR )
573 r = Stream_LoadString( stm, unicode, &This->sWorkDir );
574 TRACE("Working Dir -> %s\n",debugstr_w(This->sWorkDir));
579 if( hdr.dwFlags & SCF_ARGS )
581 r = Stream_LoadString( stm, unicode, &This->sArgs );
582 TRACE("Working Dir -> %s\n",debugstr_w(This->sArgs));
587 if( hdr.dwFlags & SCF_CUSTOMICON )
589 r = Stream_LoadString( stm, unicode, &This->sIcoPath );
590 TRACE("Icon file -> %s\n",debugstr_w(This->sIcoPath));
604 /************************************************************************
607 * Helper function for IPersistStream_Save. Writes a unicode string
608 * with terminating nul byte to a stream, preceded by the its length.
610 static HRESULT Stream_WriteString( IStream* stm, LPCWSTR str )
612 USHORT len = lstrlenW( str ) + 1;
616 r = IStream_Write( stm, &len, sizeof(len), &count );
620 len *= sizeof(WCHAR);
622 r = IStream_Write( stm, str, len, &count );
629 static HRESULT Stream_WriteLocationInfo( IStream* stm, LPCWSTR filename )
634 FIXME("writing empty location info\n");
636 memset( &loc, 0, sizeof(loc) );
637 loc.dwTotalSize = sizeof(loc) - sizeof(loc.dwTotalSize);
639 /* FIXME: fill this in */
641 return IStream_Write( stm, &loc, loc.dwTotalSize, &count );
644 /************************************************************************
645 * IPersistStream_Save (IPersistStream)
647 * FIXME: makes assumptions about byte order
649 static HRESULT WINAPI IPersistStream_fnSave(
650 IPersistStream* iface,
658 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
660 TRACE("(%p) %p %x\n", This, stm, fClearDirty);
662 /* if there's no PIDL, generate one */
667 This->pPidl = ILCreateFromPathW( This->sPath );
670 memset(&header, 0, sizeof(header));
671 header.dwSize = sizeof(header);
672 memcpy(&header.MagicGuid, &CLSID_ShellLink, sizeof(header.MagicGuid) );
674 header.wHotKey = This->wHotKey;
675 header.nIcon = This->iIcoNdx;
676 header.dwFlags = SCF_UNICODE; /* strings are in unicode */
677 header.dwFlags |= SCF_NORMAL; /* how do we determine this ? */
679 header.dwFlags |= SCF_PIDL;
680 if( This->sDescription )
681 header.dwFlags |= SCF_DESCRIPTION;
683 header.dwFlags |= SCF_WORKDIR;
685 header.dwFlags |= SCF_ARGS;
687 header.dwFlags |= SCF_CUSTOMICON;
689 SystemTimeToFileTime ( &This->time1, &header.Time1 );
690 SystemTimeToFileTime ( &This->time2, &header.Time2 );
691 SystemTimeToFileTime ( &This->time3, &header.Time3 );
693 /* write the Shortcut header */
694 r = IStream_Write( stm, &header, sizeof(header), &count );
697 ERR("Write failed at %d\n",__LINE__);
701 TRACE("Writing pidl \n");
703 /* write the PIDL to the shortcut */
706 r = ILSaveToStream( stm, This->pPidl );
709 ERR("Failed to write PIDL at %d\n",__LINE__);
714 TRACE("Path = %s\n", debugstr_w(This->sPath));
717 Stream_WriteLocationInfo( stm, This->sPath );
719 TRACE("Description = %s\n", debugstr_w(This->sDescription));
720 if( This->sDescription )
721 r = Stream_WriteString( stm, This->sDescription );
724 r = Stream_WriteString( stm, This->sPathRel );
727 r = Stream_WriteString( stm, This->sWorkDir );
730 r = Stream_WriteString( stm, This->sArgs );
733 r = Stream_WriteString( stm, This->sIcoPath );
738 /************************************************************************
739 * IPersistStream_GetSizeMax (IPersistStream)
741 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
742 IPersistStream* iface,
743 ULARGE_INTEGER* pcbSize)
745 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
747 TRACE("(%p)\n", This);
752 static ICOM_VTABLE(IPersistStream) psvt =
754 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
755 IPersistStream_fnQueryInterface,
756 IPersistStream_fnAddRef,
757 IPersistStream_fnRelease,
758 IPersistStream_fnGetClassID,
759 IPersistStream_fnIsDirty,
760 IPersistStream_fnLoad,
761 IPersistStream_fnSave,
762 IPersistStream_fnGetSizeMax
765 /**************************************************************************
766 * IShellLink_Constructor
768 HRESULT WINAPI IShellLink_Constructor (
769 IUnknown * pUnkOuter,
775 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
779 if(pUnkOuter) return CLASS_E_NOAGGREGATION;
780 sl = (IShellLinkImpl *) LocalAlloc(GMEM_ZEROINIT,sizeof(IShellLinkImpl));
781 if (!sl) return E_OUTOFMEMORY;
785 sl->lpvtblw = &slvtw;
786 sl->lpvtblPersistFile = &pfvt;
787 sl->lpvtblPersistStream = &psvt;
788 sl->iShowCmd = SW_SHOWNORMAL;
790 TRACE("(%p)->()\n",sl);
792 if (IsEqualIID(riid, &IID_IUnknown) ||
793 IsEqualIID(riid, &IID_IShellLinkA))
795 else if (IsEqualIID(riid, &IID_IShellLinkW))
796 *ppv = &(sl->lpvtblw);
798 LocalFree((HLOCAL)sl);
799 ERR("E_NOINTERFACE\n");
800 return E_NOINTERFACE;
806 /**************************************************************************
807 * IShellLinkA_QueryInterface
809 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
811 ICOM_THIS(IShellLinkImpl, iface);
813 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
817 if(IsEqualIID(riid, &IID_IUnknown) ||
818 IsEqualIID(riid, &IID_IShellLinkA))
822 else if(IsEqualIID(riid, &IID_IShellLinkW))
824 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
826 else if(IsEqualIID(riid, &IID_IPersistFile))
828 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
830 else if(IsEqualIID(riid, &IID_IPersistStream))
832 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
837 IUnknown_AddRef((IUnknown*)(*ppvObj));
838 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
841 TRACE("-- Interface: E_NOINTERFACE\n");
842 return E_NOINTERFACE;
844 /******************************************************************************
847 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
849 ICOM_THIS(IShellLinkImpl, iface);
851 TRACE("(%p)->(count=%lu)\n",This,This->ref);
853 return ++(This->ref);
855 /******************************************************************************
856 * IShellLinkA_Release
858 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
860 ICOM_THIS(IShellLinkImpl, iface);
862 TRACE("(%p)->(count=%lu)\n",This,This->ref);
867 TRACE("-- destroying IShellLink(%p)\n",This);
870 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
873 HeapFree(GetProcessHeap(), 0, This->sArgs);
876 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
878 if (This->sDescription)
879 HeapFree(GetProcessHeap(), 0, This->sDescription);
882 HeapFree(GetProcessHeap(),0,This->sPath);
887 LocalFree((HANDLE)This);
892 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,
893 INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
895 ICOM_THIS(IShellLinkImpl, iface);
897 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
898 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
903 WideCharToMultiByte( CP_ACP, 0, This->sPath, -1,
904 pszFile, cchMaxPath, NULL, NULL);
909 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
911 ICOM_THIS(IShellLinkImpl, iface);
913 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
915 *ppidl = ILClone(This->pPidl);
920 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
922 ICOM_THIS(IShellLinkImpl, iface);
924 TRACE("(%p)->(pidl=%p)\n",This, pidl);
928 This->pPidl = ILClone (pidl);
933 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
935 ICOM_THIS(IShellLinkImpl, iface);
937 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
941 if( This->sDescription )
942 WideCharToMultiByte( CP_ACP, 0, This->sDescription, -1,
943 pszName, cchMaxName, NULL, NULL);
947 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
949 ICOM_THIS(IShellLinkImpl, iface);
951 TRACE("(%p)->(pName=%s)\n", This, pszName);
953 if (This->sDescription)
954 HeapFree(GetProcessHeap(), 0, This->sDescription);
955 This->sDescription = HEAP_strdupAtoW( GetProcessHeap(), 0, pszName);
956 if ( !This->sDescription )
957 return E_OUTOFMEMORY;
962 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
964 ICOM_THIS(IShellLinkImpl, iface);
966 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
971 WideCharToMultiByte( CP_ACP, 0, This->sWorkDir, -1,
972 pszDir, cchMaxPath, NULL, NULL);
977 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
979 ICOM_THIS(IShellLinkImpl, iface);
981 TRACE("(%p)->(dir=%s)\n",This, pszDir);
984 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
985 This->sWorkDir = HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir);
986 if ( !This->sWorkDir )
987 return E_OUTOFMEMORY;
992 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
994 ICOM_THIS(IShellLinkImpl, iface);
996 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1001 WideCharToMultiByte( CP_ACP, 0, This->sArgs, -1,
1002 pszArgs, cchMaxPath, NULL, NULL);
1007 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1009 ICOM_THIS(IShellLinkImpl, iface);
1011 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1014 HeapFree(GetProcessHeap(), 0, This->sArgs);
1015 This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs);
1017 return E_OUTOFMEMORY;
1022 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1024 ICOM_THIS(IShellLinkImpl, iface);
1026 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1028 *pwHotkey = This->wHotKey;
1033 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1035 ICOM_THIS(IShellLinkImpl, iface);
1037 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1039 This->wHotKey = wHotkey;
1044 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1046 ICOM_THIS(IShellLinkImpl, iface);
1048 TRACE("(%p)->(%p)\n",This, piShowCmd);
1049 *piShowCmd = This->iShowCmd;
1053 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1055 ICOM_THIS(IShellLinkImpl, iface);
1057 TRACE("(%p) %d\n",This, iShowCmd);
1059 This->iShowCmd = iShowCmd;
1064 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1066 ICOM_THIS(IShellLinkImpl, iface);
1068 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1072 if( This->sIcoPath )
1073 WideCharToMultiByte( CP_ACP, 0, This->sIcoPath, -1,
1074 pszIconPath, cchIconPath, NULL, NULL);
1075 *piIcon = This->iIcoNdx;
1080 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1082 ICOM_THIS(IShellLinkImpl, iface);
1084 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1087 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1088 This->sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1089 if ( !This->sIcoPath )
1090 return E_OUTOFMEMORY;
1091 This->iIcoNdx = iIcon;
1096 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1098 ICOM_THIS(IShellLinkImpl, iface);
1100 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1103 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1104 This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1109 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1111 ICOM_THIS(IShellLinkImpl, iface);
1113 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1117 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1119 ICOM_THIS(IShellLinkImpl, iface);
1121 TRACE("(%p)->(path=%s)\n",This, pszFile);
1124 HeapFree(GetProcessHeap(), 0, This->sPath);
1125 This->sPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1127 return E_OUTOFMEMORY;
1132 /**************************************************************************
1133 * IShellLink Implementation
1136 static ICOM_VTABLE(IShellLinkA) slvt =
1138 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1139 IShellLinkA_fnQueryInterface,
1140 IShellLinkA_fnAddRef,
1141 IShellLinkA_fnRelease,
1142 IShellLinkA_fnGetPath,
1143 IShellLinkA_fnGetIDList,
1144 IShellLinkA_fnSetIDList,
1145 IShellLinkA_fnGetDescription,
1146 IShellLinkA_fnSetDescription,
1147 IShellLinkA_fnGetWorkingDirectory,
1148 IShellLinkA_fnSetWorkingDirectory,
1149 IShellLinkA_fnGetArguments,
1150 IShellLinkA_fnSetArguments,
1151 IShellLinkA_fnGetHotkey,
1152 IShellLinkA_fnSetHotkey,
1153 IShellLinkA_fnGetShowCmd,
1154 IShellLinkA_fnSetShowCmd,
1155 IShellLinkA_fnGetIconLocation,
1156 IShellLinkA_fnSetIconLocation,
1157 IShellLinkA_fnSetRelativePath,
1158 IShellLinkA_fnResolve,
1159 IShellLinkA_fnSetPath
1163 /**************************************************************************
1164 * IShellLinkW_fnQueryInterface
1166 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1167 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1169 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1171 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1174 /******************************************************************************
1175 * IShellLinkW_fnAddRef
1177 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1179 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1181 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1183 return IShellLinkA_AddRef((IShellLinkA*)This);
1185 /******************************************************************************
1186 * IShellLinkW_fnRelease
1189 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1191 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1193 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1195 return IShellLinkA_Release((IShellLinkA*)This);
1198 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags)
1200 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1202 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1206 lstrcpynW( pszFile, This->sPath, cchMaxPath );
1211 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1213 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1215 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1218 *ppidl = ILClone( This->pPidl );
1225 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1227 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1229 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1232 ILFree( This->pPidl );
1233 This->pPidl = ILClone( pidl );
1240 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1242 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1244 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1248 if( This->sDescription )
1249 lstrcpynW( pszName, This->sDescription, cchMaxName );
1254 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1256 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1258 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1260 if (This->sDescription)
1261 HeapFree(GetProcessHeap(), 0, This->sDescription);
1262 This->sDescription = HeapAlloc( GetProcessHeap(), 0,
1263 (lstrlenW( pszName )+1)*sizeof(WCHAR) );
1264 if ( !This->sDescription )
1265 return E_OUTOFMEMORY;
1266 lstrcpyW( This->sDescription, pszName );
1271 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1273 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1275 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1279 if( This->sWorkDir )
1280 lstrcpynW( pszDir, This->sWorkDir, cchMaxPath );
1285 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1287 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1289 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1292 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1293 This->sWorkDir = HeapAlloc( GetProcessHeap(), 0,
1294 (lstrlenW( pszDir )+1)*sizeof (WCHAR) );
1295 if ( !This->sWorkDir )
1296 return E_OUTOFMEMORY;
1297 lstrcpyW( This->sWorkDir, pszDir );
1302 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1304 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1306 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1311 lstrcpynW( pszArgs, This->sArgs, cchMaxPath );
1316 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1318 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1320 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1323 HeapFree(GetProcessHeap(), 0, This->sArgs);
1324 This->sArgs = HeapAlloc( GetProcessHeap(), 0,
1325 (lstrlenW( pszArgs )+1)*sizeof (WCHAR) );
1327 return E_OUTOFMEMORY;
1328 lstrcpyW( This->sArgs, pszArgs );
1333 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1335 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1337 TRACE("(%p)->(%p)\n",This, pwHotkey);
1339 *pwHotkey=This->wHotKey;
1344 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1346 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1348 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1350 This->wHotKey = wHotkey;
1355 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1357 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1359 TRACE("(%p)->(%p)\n",This, piShowCmd);
1361 *piShowCmd = This->iShowCmd;
1366 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1368 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1370 This->iShowCmd = iShowCmd;
1375 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1377 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1379 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1383 if( This->sIcoPath )
1384 lstrcpynW( pszIconPath, This->sIcoPath, cchIconPath );
1385 *piIcon = This->iIcoNdx;
1390 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1392 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1394 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1397 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1398 This->sIcoPath = HeapAlloc( GetProcessHeap(), 0,
1399 (lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
1400 if ( !This->sIcoPath )
1401 return E_OUTOFMEMORY;
1402 lstrcpyW( This->sIcoPath, pszIconPath );
1404 This->iIcoNdx = iIcon;
1409 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1411 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1413 TRACE("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1416 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1417 This->sPathRel = HeapAlloc( GetProcessHeap(), 0,
1418 (lstrlenW( pszPathRel )+1) * sizeof (WCHAR) );
1419 if ( !This->sPathRel )
1420 return E_OUTOFMEMORY;
1421 lstrcpyW( This->sPathRel, pszPathRel );
1426 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1428 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1430 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1435 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1437 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1439 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1442 HeapFree(GetProcessHeap(), 0, This->sPath);
1443 This->sPath = HeapAlloc( GetProcessHeap(), 0,
1444 (lstrlenW( pszFile )+1) * sizeof (WCHAR) );
1446 return E_OUTOFMEMORY;
1447 lstrcpyW( This->sPath, pszFile );
1452 /**************************************************************************
1453 * IShellLinkW Implementation
1456 static ICOM_VTABLE(IShellLinkW) slvtw =
1458 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1459 IShellLinkW_fnQueryInterface,
1460 IShellLinkW_fnAddRef,
1461 IShellLinkW_fnRelease,
1462 IShellLinkW_fnGetPath,
1463 IShellLinkW_fnGetIDList,
1464 IShellLinkW_fnSetIDList,
1465 IShellLinkW_fnGetDescription,
1466 IShellLinkW_fnSetDescription,
1467 IShellLinkW_fnGetWorkingDirectory,
1468 IShellLinkW_fnSetWorkingDirectory,
1469 IShellLinkW_fnGetArguments,
1470 IShellLinkW_fnSetArguments,
1471 IShellLinkW_fnGetHotkey,
1472 IShellLinkW_fnSetHotkey,
1473 IShellLinkW_fnGetShowCmd,
1474 IShellLinkW_fnSetShowCmd,
1475 IShellLinkW_fnGetIconLocation,
1476 IShellLinkW_fnSetIconLocation,
1477 IShellLinkW_fnSetRelativePath,
1478 IShellLinkW_fnResolve,
1479 IShellLinkW_fnSetPath