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
31 #ifdef HAVE_SYS_WAIT_H
32 # include <sys/wait.h>
34 #include "wine/debug.h"
35 #include "wine/port.h"
42 #include "undocshell.h"
46 #include "shell32_main.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(shell);
51 /* link file formats */
53 /* flag1: lnk elements: simple link has 0x0B */
56 #define SCF_DESCRIPTION 4
57 #define SCF_RELATIVE 8
58 #define SCF_WORKDIR 0x10
60 #define SCF_CUSTOMICON 0x40
62 #define SCF_UNICODE 0x1000
66 typedef struct _LINK_HEADER
68 DWORD dwSize; /* 0x00 size of the header - 0x4c */
69 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
70 DWORD dwFlags; /* 0x14 describes elements following */
71 DWORD dwFileAttr; /* 0x18 attributes of the target file */
72 FILETIME Time1; /* 0x1c */
73 FILETIME Time2; /* 0x24 */
74 FILETIME Time3; /* 0x2c */
75 DWORD dwFileLength; /* 0x34 File length */
76 DWORD nIcon; /* 0x38 icon number */
77 DWORD fStartup; /* 0x3c startup type */
78 DWORD wHotKey; /* 0x40 hotkey */
79 DWORD Unknown5; /* 0x44 */
80 DWORD Unknown6; /* 0x48 */
81 } LINK_HEADER, * PLINK_HEADER;
83 #define SHLINK_LOCAL 0
84 #define SHLINK_REMOTE 1
86 typedef struct _LOCATION_INFO
93 DWORD dwNetworkVolTableOfs;
97 typedef struct _LOCAL_VOLUME_INFO
107 static ICOM_VTABLE(IShellLinkA) slvt;
108 static ICOM_VTABLE(IShellLinkW) slvtw;
109 static ICOM_VTABLE(IPersistFile) pfvt;
110 static ICOM_VTABLE(IPersistStream) psvt;
112 /* IShellLink Implementation */
116 ICOM_VFIELD(IShellLinkA);
119 ICOM_VTABLE(IShellLinkW)* lpvtblw;
120 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
121 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
123 /* data structures according to the informations in the lnk */
140 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
141 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
143 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
144 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
146 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
147 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
148 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset)
151 /* strdup on the process heap */
152 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str)
154 INT len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
155 LPWSTR p = HeapAlloc( heap, flags, len*sizeof (WCHAR) );
158 MultiByteToWideChar( CP_ACP, 0, str, -1, p, len );
163 /**************************************************************************
164 * IPersistFile_QueryInterface
166 static HRESULT WINAPI IPersistFile_fnQueryInterface(
171 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
173 TRACE("(%p)\n",This);
175 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
178 /******************************************************************************
179 * IPersistFile_AddRef
181 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
183 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
185 TRACE("(%p)->(count=%lu)\n",This,This->ref);
187 return IShellLinkA_AddRef((IShellLinkA*)This);
189 /******************************************************************************
190 * IPersistFile_Release
192 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
194 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
196 TRACE("(%p)->(count=%lu)\n",This,This->ref);
198 return IShellLinkA_Release((IShellLinkA*)This);
201 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
203 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
204 FIXME("(%p)\n",This);
207 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
209 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
210 FIXME("(%p)\n",This);
213 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
215 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
216 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
220 TRACE("(%p, %s)\n",This, debugstr_w(pszFileName));
222 r = CreateStreamOnFile(pszFileName, dwMode, &stm);
225 r = IPersistStream_Load(StreamThis, stm);
226 IStream_Release( stm );
232 static BOOL StartLinkProcessor( LPCOLESTR szLink )
234 const WCHAR szFormat[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
235 ' ','-','r',' ','"','%','s','"',0 };
239 PROCESS_INFORMATION pi;
241 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
242 buffer = HeapAlloc( GetProcessHeap(), 0, len );
246 wsprintfW( buffer, szFormat, szLink );
248 TRACE("starting %s\n",debugstr_w(buffer));
250 memset(&si, 0, sizeof(si));
252 if (!CreateProcessW( NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return FALSE;
254 /* wait for a while to throttle the creation of linker processes */
255 if( WAIT_OBJECT_0 != WaitForSingleObject( pi.hProcess, 10000 ) )
256 WARN("Timed out waiting for shell linker\n");
258 CloseHandle( pi.hProcess );
259 CloseHandle( pi.hThread );
264 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
266 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
267 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
271 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
273 if (!pszFileName || !This->sPath)
274 return ERROR_UNKNOWN;
276 r = CreateStreamOnFile(pszFileName, STGM_READWRITE | STGM_CREATE, &stm);
279 r = IPersistStream_Save(StreamThis, stm, FALSE);
280 IStream_Release( stm );
283 StartLinkProcessor( pszFileName );
286 DeleteFileW( pszFileName );
287 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName) );
294 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
296 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
297 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
300 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
302 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
303 FIXME("(%p)\n",This);
307 static ICOM_VTABLE(IPersistFile) pfvt =
309 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
310 IPersistFile_fnQueryInterface,
311 IPersistFile_fnAddRef,
312 IPersistFile_fnRelease,
313 IPersistFile_fnGetClassID,
314 IPersistFile_fnIsDirty,
317 IPersistFile_fnSaveCompleted,
318 IPersistFile_fnGetCurFile
321 /************************************************************************
322 * IPersistStream_QueryInterface
324 static HRESULT WINAPI IPersistStream_fnQueryInterface(
325 IPersistStream* iface,
329 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
331 TRACE("(%p)\n",This);
333 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
336 /************************************************************************
337 * IPersistStream_Release
339 static ULONG WINAPI IPersistStream_fnRelease(
340 IPersistStream* iface)
342 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
344 TRACE("(%p)\n",This);
346 return IShellLinkA_Release((IShellLinkA*)This);
349 /************************************************************************
350 * IPersistStream_AddRef
352 static ULONG WINAPI IPersistStream_fnAddRef(
353 IPersistStream* iface)
355 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
357 TRACE("(%p)\n",This);
359 return IShellLinkA_AddRef((IShellLinkA*)This);
362 /************************************************************************
363 * IPersistStream_GetClassID
366 static HRESULT WINAPI IPersistStream_fnGetClassID(
367 IPersistStream* iface,
370 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
372 TRACE("(%p)\n", This);
377 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
382 /************************************************************************
383 * IPersistStream_IsDirty (IPersistStream)
385 static HRESULT WINAPI IPersistStream_fnIsDirty(
386 IPersistStream* iface)
388 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
390 TRACE("(%p)\n", This);
396 static HRESULT Stream_LoadString( IStream* stm, BOOL unicode, LPWSTR *pstr )
407 r = IStream_Read(stm, &len, sizeof(len), &count);
408 if ( FAILED (r) || ( count != sizeof(len) ) )
412 len *= sizeof (WCHAR);
414 TRACE("reading %d\n", len);
415 temp = HeapAlloc(GetProcessHeap(), 0, len+sizeof(WCHAR));
417 return E_OUTOFMEMORY;
419 r = IStream_Read(stm, temp, len, &count);
420 if( FAILED (r) || ( count != len ) )
422 HeapFree( GetProcessHeap(), 0, temp );
426 TRACE("read %s\n", debugstr_an(temp,len));
428 /* convert to unicode if necessary */
431 count = MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, NULL, 0 );
432 str = HeapAlloc( GetProcessHeap(), 0, (count+1)*sizeof (WCHAR) );
434 MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, str, count );
435 HeapFree( GetProcessHeap(), 0, temp );
449 static HRESULT Stream_LoadLocation( IStream* stm )
458 r = IStream_Read( stm, &size, sizeof(size), &count );
461 if( count != sizeof(loc->dwTotalSize) )
464 loc = HeapAlloc( GetProcessHeap(), 0, size );
466 return E_OUTOFMEMORY;
468 r = IStream_Read( stm, &loc->dwHeaderSize, size-sizeof(size), &count );
471 if( count != (size - sizeof(size)) )
476 loc->dwTotalSize = size;
478 TRACE("Read %ld bytes\n",count);
480 /* FIXME: do something useful with it */
481 HeapFree( GetProcessHeap(), 0, loc );
485 HeapFree( GetProcessHeap(), 0, loc );
489 /************************************************************************
490 * IPersistStream_Load (IPersistStream)
492 static HRESULT WINAPI IPersistStream_fnLoad(
493 IPersistStream* iface,
499 WCHAR sTemp[MAX_PATH];
502 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
504 TRACE("(%p)(%p)\n", This, stm);
507 return STG_E_INVALIDPOINTER;
510 r = IStream_Read(stm, &hdr, sizeof(hdr), &dwBytesRead);
514 if( dwBytesRead != sizeof(hdr))
516 if( hdr.dwSize != sizeof(hdr))
518 if( !IsEqualIID(&hdr.MagicGuid, &CLSID_ShellLink) )
521 /* if( hdr.dwFlags & SCF_PIDL ) */ /* FIXME: seems to always have a PIDL */
523 r = ILLoadFromStream( stm, &This->pPidl );
527 This->wHotKey = hdr.wHotKey;
528 This->iIcoNdx = hdr.nIcon;
529 FileTimeToSystemTime (&hdr.Time1, &This->time1);
530 FileTimeToSystemTime (&hdr.Time2, &This->time2);
531 FileTimeToSystemTime (&hdr.Time3, &This->time3);
533 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
534 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
535 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
536 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
537 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
538 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
541 if( hdr.dwFlags & SCF_NORMAL )
542 r = Stream_LoadLocation( stm );
545 unicode = hdr.dwFlags & SCF_UNICODE;
546 if( hdr.dwFlags & SCF_DESCRIPTION )
548 r = Stream_LoadString( stm, unicode, &This->sDescription );
549 TRACE("Description -> %s\n",debugstr_w(This->sDescription));
554 if( hdr.dwFlags & SCF_RELATIVE )
556 r = Stream_LoadString( stm, unicode, &This->sPathRel );
557 TRACE("Relative Path-> %s\n",debugstr_w(This->sPathRel));
562 if( hdr.dwFlags & SCF_WORKDIR )
564 r = Stream_LoadString( stm, unicode, &This->sWorkDir );
565 TRACE("Working Dir -> %s\n",debugstr_w(This->sWorkDir));
570 if( hdr.dwFlags & SCF_ARGS )
572 r = Stream_LoadString( stm, unicode, &This->sArgs );
573 TRACE("Working Dir -> %s\n",debugstr_w(This->sArgs));
578 if( hdr.dwFlags & SCF_CUSTOMICON )
580 r = Stream_LoadString( stm, unicode, &This->sIcoPath );
581 TRACE("Icon file -> %s\n",debugstr_w(This->sIcoPath));
595 /************************************************************************
598 * Helper function for IPersistStream_Save. Writes a unicode string
599 * with terminating nul byte to a stream, preceded by the its length.
601 static HRESULT Stream_WriteString( IStream* stm, LPCWSTR str )
603 USHORT len = lstrlenW( str ) + 1;
607 r = IStream_Write( stm, &len, sizeof(len), &count );
611 len *= sizeof(WCHAR);
613 r = IStream_Write( stm, str, len, &count );
620 static HRESULT Stream_WriteLocationInfo( IStream* stm, LPCWSTR filename )
625 FIXME("writing empty location info\n");
627 memset( &loc, 0, sizeof(loc) );
628 loc.dwTotalSize = sizeof(loc) - sizeof(loc.dwTotalSize);
630 /* FIXME: fill this in */
632 return IStream_Write( stm, &loc, loc.dwTotalSize, &count );
635 /************************************************************************
636 * IPersistStream_Save (IPersistStream)
638 * FIXME: makes assumptions about byte order
640 static HRESULT WINAPI IPersistStream_fnSave(
641 IPersistStream* iface,
649 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
651 TRACE("(%p) %p %x\n", This, stm, fClearDirty);
653 /* if there's no PIDL, generate one */
658 This->pPidl = ILCreateFromPathW( This->sPath );
661 memset(&header, 0, sizeof(header));
662 header.dwSize = sizeof(header);
663 memcpy(&header.MagicGuid, &CLSID_ShellLink, sizeof(header.MagicGuid) );
665 header.wHotKey = This->wHotKey;
666 header.nIcon = This->iIcoNdx;
667 header.dwFlags = SCF_UNICODE; /* strings are in unicode */
668 header.dwFlags |= SCF_NORMAL; /* how do we determine this ? */
670 header.dwFlags |= SCF_PIDL;
671 if( This->sDescription )
672 header.dwFlags |= SCF_DESCRIPTION;
674 header.dwFlags |= SCF_WORKDIR;
676 header.dwFlags |= SCF_ARGS;
678 header.dwFlags |= SCF_CUSTOMICON;
680 SystemTimeToFileTime ( &This->time1, &header.Time1 );
681 SystemTimeToFileTime ( &This->time2, &header.Time2 );
682 SystemTimeToFileTime ( &This->time3, &header.Time3 );
684 /* write the Shortcut header */
685 r = IStream_Write( stm, &header, sizeof(header), &count );
688 ERR("Write failed at %d\n",__LINE__);
692 TRACE("Writing pidl \n");
694 /* write the PIDL to the shortcut */
697 r = ILSaveToStream( stm, This->pPidl );
700 ERR("Failed to write PIDL at %d\n",__LINE__);
705 TRACE("Path = %s\n", debugstr_w(This->sPath));
708 Stream_WriteLocationInfo( stm, This->sPath );
710 TRACE("Description = %s\n", debugstr_w(This->sDescription));
711 if( This->sDescription )
712 r = Stream_WriteString( stm, This->sDescription );
715 r = Stream_WriteString( stm, This->sPathRel );
718 r = Stream_WriteString( stm, This->sWorkDir );
721 r = Stream_WriteString( stm, This->sArgs );
724 r = Stream_WriteString( stm, This->sIcoPath );
729 /************************************************************************
730 * IPersistStream_GetSizeMax (IPersistStream)
732 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
733 IPersistStream* iface,
734 ULARGE_INTEGER* pcbSize)
736 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
738 TRACE("(%p)\n", This);
743 static ICOM_VTABLE(IPersistStream) psvt =
745 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
746 IPersistStream_fnQueryInterface,
747 IPersistStream_fnAddRef,
748 IPersistStream_fnRelease,
749 IPersistStream_fnGetClassID,
750 IPersistStream_fnIsDirty,
751 IPersistStream_fnLoad,
752 IPersistStream_fnSave,
753 IPersistStream_fnGetSizeMax
756 /**************************************************************************
757 * IShellLink_Constructor
759 HRESULT WINAPI IShellLink_Constructor (
760 IUnknown * pUnkOuter,
766 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
770 if(pUnkOuter) return CLASS_E_NOAGGREGATION;
771 sl = (IShellLinkImpl *) LocalAlloc(GMEM_ZEROINIT,sizeof(IShellLinkImpl));
772 if (!sl) return E_OUTOFMEMORY;
776 sl->lpvtblw = &slvtw;
777 sl->lpvtblPersistFile = &pfvt;
778 sl->lpvtblPersistStream = &psvt;
779 sl->iShowCmd = SW_SHOWNORMAL;
781 TRACE("(%p)->()\n",sl);
783 if (IsEqualIID(riid, &IID_IUnknown) ||
784 IsEqualIID(riid, &IID_IShellLinkA))
786 else if (IsEqualIID(riid, &IID_IShellLinkW))
787 *ppv = &(sl->lpvtblw);
789 LocalFree((HLOCAL)sl);
790 ERR("E_NOINTERFACE\n");
791 return E_NOINTERFACE;
797 /**************************************************************************
798 * IShellLinkA_QueryInterface
800 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
802 ICOM_THIS(IShellLinkImpl, iface);
804 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
808 if(IsEqualIID(riid, &IID_IUnknown) ||
809 IsEqualIID(riid, &IID_IShellLinkA))
813 else if(IsEqualIID(riid, &IID_IShellLinkW))
815 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
817 else if(IsEqualIID(riid, &IID_IPersistFile))
819 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
821 else if(IsEqualIID(riid, &IID_IPersistStream))
823 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
828 IUnknown_AddRef((IUnknown*)(*ppvObj));
829 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
832 TRACE("-- Interface: E_NOINTERFACE\n");
833 return E_NOINTERFACE;
835 /******************************************************************************
838 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
840 ICOM_THIS(IShellLinkImpl, iface);
842 TRACE("(%p)->(count=%lu)\n",This,This->ref);
844 return ++(This->ref);
846 /******************************************************************************
847 * IShellLinkA_Release
849 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
851 ICOM_THIS(IShellLinkImpl, iface);
853 TRACE("(%p)->(count=%lu)\n",This,This->ref);
858 TRACE("-- destroying IShellLink(%p)\n",This);
861 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
864 HeapFree(GetProcessHeap(), 0, This->sArgs);
867 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
869 if (This->sDescription)
870 HeapFree(GetProcessHeap(), 0, This->sDescription);
873 HeapFree(GetProcessHeap(),0,This->sPath);
878 LocalFree((HANDLE)This);
883 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,
884 INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
886 ICOM_THIS(IShellLinkImpl, iface);
888 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
889 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
894 WideCharToMultiByte( CP_ACP, 0, This->sPath, -1,
895 pszFile, cchMaxPath, NULL, NULL);
900 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
902 ICOM_THIS(IShellLinkImpl, iface);
904 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
906 *ppidl = ILClone(This->pPidl);
911 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
913 ICOM_THIS(IShellLinkImpl, iface);
915 TRACE("(%p)->(pidl=%p)\n",This, pidl);
919 This->pPidl = ILClone (pidl);
924 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
926 ICOM_THIS(IShellLinkImpl, iface);
928 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
932 if( This->sDescription )
933 WideCharToMultiByte( CP_ACP, 0, This->sDescription, -1,
934 pszName, cchMaxName, NULL, NULL);
938 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
940 ICOM_THIS(IShellLinkImpl, iface);
942 TRACE("(%p)->(pName=%s)\n", This, pszName);
944 if (This->sDescription)
945 HeapFree(GetProcessHeap(), 0, This->sDescription);
946 This->sDescription = HEAP_strdupAtoW( GetProcessHeap(), 0, pszName);
947 if ( !This->sDescription )
948 return E_OUTOFMEMORY;
953 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
955 ICOM_THIS(IShellLinkImpl, iface);
957 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
962 WideCharToMultiByte( CP_ACP, 0, This->sWorkDir, -1,
963 pszDir, cchMaxPath, NULL, NULL);
968 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
970 ICOM_THIS(IShellLinkImpl, iface);
972 TRACE("(%p)->(dir=%s)\n",This, pszDir);
975 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
976 This->sWorkDir = HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir);
977 if ( !This->sWorkDir )
978 return E_OUTOFMEMORY;
983 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
985 ICOM_THIS(IShellLinkImpl, iface);
987 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
992 WideCharToMultiByte( CP_ACP, 0, This->sArgs, -1,
993 pszArgs, cchMaxPath, NULL, NULL);
998 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1000 ICOM_THIS(IShellLinkImpl, iface);
1002 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1005 HeapFree(GetProcessHeap(), 0, This->sArgs);
1006 This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs);
1008 return E_OUTOFMEMORY;
1013 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1015 ICOM_THIS(IShellLinkImpl, iface);
1017 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1019 *pwHotkey = This->wHotKey;
1024 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1026 ICOM_THIS(IShellLinkImpl, iface);
1028 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1030 This->wHotKey = wHotkey;
1035 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1037 ICOM_THIS(IShellLinkImpl, iface);
1039 TRACE("(%p)->(%p)\n",This, piShowCmd);
1040 *piShowCmd = This->iShowCmd;
1044 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1046 ICOM_THIS(IShellLinkImpl, iface);
1048 TRACE("(%p) %d\n",This, iShowCmd);
1050 This->iShowCmd = iShowCmd;
1055 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1057 ICOM_THIS(IShellLinkImpl, iface);
1059 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1063 if( This->sIcoPath )
1064 WideCharToMultiByte( CP_ACP, 0, This->sIcoPath, -1,
1065 pszIconPath, cchIconPath, NULL, NULL);
1066 *piIcon = This->iIcoNdx;
1071 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1073 ICOM_THIS(IShellLinkImpl, iface);
1075 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1078 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1079 This->sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1080 if ( !This->sIcoPath )
1081 return E_OUTOFMEMORY;
1082 This->iIcoNdx = iIcon;
1087 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1089 ICOM_THIS(IShellLinkImpl, iface);
1091 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1094 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1095 This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1100 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1102 ICOM_THIS(IShellLinkImpl, iface);
1104 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1108 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1110 ICOM_THIS(IShellLinkImpl, iface);
1112 TRACE("(%p)->(path=%s)\n",This, pszFile);
1115 HeapFree(GetProcessHeap(), 0, This->sPath);
1116 This->sPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1118 return E_OUTOFMEMORY;
1123 /**************************************************************************
1124 * IShellLink Implementation
1127 static ICOM_VTABLE(IShellLinkA) slvt =
1129 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1130 IShellLinkA_fnQueryInterface,
1131 IShellLinkA_fnAddRef,
1132 IShellLinkA_fnRelease,
1133 IShellLinkA_fnGetPath,
1134 IShellLinkA_fnGetIDList,
1135 IShellLinkA_fnSetIDList,
1136 IShellLinkA_fnGetDescription,
1137 IShellLinkA_fnSetDescription,
1138 IShellLinkA_fnGetWorkingDirectory,
1139 IShellLinkA_fnSetWorkingDirectory,
1140 IShellLinkA_fnGetArguments,
1141 IShellLinkA_fnSetArguments,
1142 IShellLinkA_fnGetHotkey,
1143 IShellLinkA_fnSetHotkey,
1144 IShellLinkA_fnGetShowCmd,
1145 IShellLinkA_fnSetShowCmd,
1146 IShellLinkA_fnGetIconLocation,
1147 IShellLinkA_fnSetIconLocation,
1148 IShellLinkA_fnSetRelativePath,
1149 IShellLinkA_fnResolve,
1150 IShellLinkA_fnSetPath
1154 /**************************************************************************
1155 * IShellLinkW_fnQueryInterface
1157 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1158 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1160 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1162 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1165 /******************************************************************************
1166 * IShellLinkW_fnAddRef
1168 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1170 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1172 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1174 return IShellLinkA_AddRef((IShellLinkA*)This);
1176 /******************************************************************************
1177 * IShellLinkW_fnRelease
1180 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1182 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1184 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1186 return IShellLinkA_Release((IShellLinkA*)This);
1189 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1191 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1193 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1197 lstrcpynW( pszFile, This->sPath, cchMaxPath );
1202 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1204 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1206 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1209 *ppidl = ILClone( This->pPidl );
1216 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1218 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1220 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1223 ILFree( This->pPidl );
1224 This->pPidl = ILClone( pidl );
1231 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1233 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1235 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1239 if( This->sDescription )
1240 lstrcpynW( pszName, This->sDescription, cchMaxName );
1245 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1247 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1249 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1251 if (This->sDescription)
1252 HeapFree(GetProcessHeap(), 0, This->sDescription);
1253 This->sDescription = HeapAlloc( GetProcessHeap(), 0,
1254 (lstrlenW( pszName )+1)*sizeof(WCHAR) );
1255 if ( !This->sDescription )
1256 return E_OUTOFMEMORY;
1257 lstrcpyW( This->sDescription, pszName );
1262 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1264 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1266 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1270 if( This->sWorkDir )
1271 lstrcpynW( pszDir, This->sWorkDir, cchMaxPath );
1276 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1278 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1280 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1283 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1284 This->sWorkDir = HeapAlloc( GetProcessHeap(), 0,
1285 (lstrlenW( pszDir )+1)*sizeof (WCHAR) );
1286 if ( !This->sWorkDir )
1287 return E_OUTOFMEMORY;
1288 lstrcpyW( This->sWorkDir, pszDir );
1293 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1295 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1297 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1302 lstrcpynW( pszArgs, This->sArgs, cchMaxPath );
1307 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1309 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1311 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1314 HeapFree(GetProcessHeap(), 0, This->sArgs);
1315 This->sArgs = HeapAlloc( GetProcessHeap(), 0,
1316 (lstrlenW( pszArgs )+1)*sizeof (WCHAR) );
1318 return E_OUTOFMEMORY;
1319 lstrcpyW( This->sArgs, pszArgs );
1324 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1326 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1328 TRACE("(%p)->(%p)\n",This, pwHotkey);
1330 *pwHotkey=This->wHotKey;
1335 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1337 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1339 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1341 This->wHotKey = wHotkey;
1346 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1348 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1350 TRACE("(%p)->(%p)\n",This, piShowCmd);
1352 *piShowCmd = This->iShowCmd;
1357 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1359 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1361 This->iShowCmd = iShowCmd;
1366 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1368 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1370 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1374 if( This->sIcoPath )
1375 lstrcpynW( pszIconPath, This->sIcoPath, cchIconPath );
1376 *piIcon = This->iIcoNdx;
1381 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1383 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1385 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1388 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1389 This->sIcoPath = HeapAlloc( GetProcessHeap(), 0,
1390 (lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
1391 if ( !This->sIcoPath )
1392 return E_OUTOFMEMORY;
1393 lstrcpyW( This->sIcoPath, pszIconPath );
1395 This->iIcoNdx = iIcon;
1400 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1402 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1404 TRACE("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1407 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1408 This->sPathRel = HeapAlloc( GetProcessHeap(), 0,
1409 (lstrlenW( pszPathRel )+1) * sizeof (WCHAR) );
1410 if ( !This->sPathRel )
1411 return E_OUTOFMEMORY;
1412 lstrcpyW( This->sPathRel, pszPathRel );
1417 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1419 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1421 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1426 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1428 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1430 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1433 HeapFree(GetProcessHeap(), 0, This->sPath);
1434 This->sPath = HeapAlloc( GetProcessHeap(), 0,
1435 (lstrlenW( pszFile )+1) * sizeof (WCHAR) );
1437 return E_OUTOFMEMORY;
1438 lstrcpyW( This->sPath, pszFile );
1443 /**************************************************************************
1444 * IShellLinkW Implementation
1447 static ICOM_VTABLE(IShellLinkW) slvtw =
1449 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1450 IShellLinkW_fnQueryInterface,
1451 IShellLinkW_fnAddRef,
1452 IShellLinkW_fnRelease,
1453 IShellLinkW_fnGetPath,
1454 IShellLinkW_fnGetIDList,
1455 IShellLinkW_fnSetIDList,
1456 IShellLinkW_fnGetDescription,
1457 IShellLinkW_fnSetDescription,
1458 IShellLinkW_fnGetWorkingDirectory,
1459 IShellLinkW_fnSetWorkingDirectory,
1460 IShellLinkW_fnGetArguments,
1461 IShellLinkW_fnSetArguments,
1462 IShellLinkW_fnGetHotkey,
1463 IShellLinkW_fnSetHotkey,
1464 IShellLinkW_fnGetShowCmd,
1465 IShellLinkW_fnSetShowCmd,
1466 IShellLinkW_fnGetIconLocation,
1467 IShellLinkW_fnSetIconLocation,
1468 IShellLinkW_fnSetRelativePath,
1469 IShellLinkW_fnResolve,
1470 IShellLinkW_fnSetPath