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"
54 #include "shell32_main.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(shell);
59 /* link file formats */
61 /* flag1: lnk elements: simple link has 0x0B */
64 #define SCF_DESCRIPTION 4
65 #define SCF_RELATIVE 8
66 #define SCF_WORKDIR 0x10
68 #define SCF_CUSTOMICON 0x40
70 #define SCF_UNICODE 0x1000
74 typedef struct _LINK_HEADER
76 DWORD dwSize; /* 0x00 size of the header - 0x4c */
77 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
78 DWORD dwFlags; /* 0x14 describes elements following */
79 DWORD dwFileAttr; /* 0x18 attributes of the target file */
80 FILETIME Time1; /* 0x1c */
81 FILETIME Time2; /* 0x24 */
82 FILETIME Time3; /* 0x2c */
83 DWORD dwFileLength; /* 0x34 File length */
84 DWORD nIcon; /* 0x38 icon number */
85 DWORD fStartup; /* 0x3c startup type */
86 DWORD wHotKey; /* 0x40 hotkey */
87 DWORD Unknown5; /* 0x44 */
88 DWORD Unknown6; /* 0x48 */
89 } LINK_HEADER, * PLINK_HEADER;
91 #define SHLINK_LOCAL 0
92 #define SHLINK_REMOTE 1
94 typedef struct _LOCATION_INFO
100 DWORD dwLocalPathOfs;
101 DWORD dwNetworkVolTableOfs;
102 DWORD dwFinalPathOfs;
105 typedef struct _LOCAL_VOLUME_INFO
115 static ICOM_VTABLE(IShellLinkA) slvt;
116 static ICOM_VTABLE(IShellLinkW) slvtw;
117 static ICOM_VTABLE(IPersistFile) pfvt;
118 static ICOM_VTABLE(IPersistStream) psvt;
120 /* IShellLink Implementation */
124 ICOM_VFIELD(IShellLinkA);
127 ICOM_VTABLE(IShellLinkW)* lpvtblw;
128 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
129 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
131 /* data structures according to the informations in the lnk */
148 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
149 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
151 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
152 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
154 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
155 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
156 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset)
159 /* strdup on the process heap */
160 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str)
162 INT len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
163 LPWSTR p = HeapAlloc( heap, flags, len*sizeof (WCHAR) );
166 MultiByteToWideChar( CP_ACP, 0, str, -1, p, len );
171 /**************************************************************************
172 * IPersistFile_QueryInterface
174 static HRESULT WINAPI IPersistFile_fnQueryInterface(
179 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
181 TRACE("(%p)\n",This);
183 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
186 /******************************************************************************
187 * IPersistFile_AddRef
189 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
191 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
193 TRACE("(%p)->(count=%lu)\n",This,This->ref);
195 return IShellLinkA_AddRef((IShellLinkA*)This);
197 /******************************************************************************
198 * IPersistFile_Release
200 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
202 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
204 TRACE("(%p)->(count=%lu)\n",This,This->ref);
206 return IShellLinkA_Release((IShellLinkA*)This);
209 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
211 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
212 FIXME("(%p)\n",This);
215 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
217 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
218 FIXME("(%p)\n",This);
221 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
223 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
224 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
228 TRACE("(%p, %s)\n",This, debugstr_w(pszFileName));
230 r = CreateStreamOnFile(pszFileName, dwMode, &stm);
233 r = IPersistStream_Load(StreamThis, stm);
234 IStream_Release( stm );
240 static BOOL StartLinkProcessor( LPCOLESTR szLink )
242 const WCHAR szFormat[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
243 ' ','-','r',' ','"','%','s','"',0 };
247 PROCESS_INFORMATION pi;
249 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
250 buffer = HeapAlloc( GetProcessHeap(), 0, len );
254 wsprintfW( buffer, szFormat, szLink );
256 TRACE("starting %s\n",debugstr_w(buffer));
258 memset(&si, 0, sizeof(si));
260 if (!CreateProcessW( NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return FALSE;
262 /* wait for a while to throttle the creation of linker processes */
263 if( WAIT_OBJECT_0 != WaitForSingleObject( pi.hProcess, 10000 ) )
264 WARN("Timed out waiting for shell linker\n");
266 CloseHandle( pi.hProcess );
267 CloseHandle( pi.hThread );
272 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
274 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
275 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
279 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
281 if (!pszFileName || !This->sPath)
282 return ERROR_UNKNOWN;
284 r = CreateStreamOnFile(pszFileName, STGM_READWRITE | STGM_CREATE, &stm);
287 r = IPersistStream_Save(StreamThis, stm, FALSE);
288 IStream_Release( stm );
291 StartLinkProcessor( pszFileName );
294 DeleteFileW( pszFileName );
295 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName) );
302 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
304 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
305 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
308 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
310 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
311 FIXME("(%p)\n",This);
315 static ICOM_VTABLE(IPersistFile) pfvt =
317 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
318 IPersistFile_fnQueryInterface,
319 IPersistFile_fnAddRef,
320 IPersistFile_fnRelease,
321 IPersistFile_fnGetClassID,
322 IPersistFile_fnIsDirty,
325 IPersistFile_fnSaveCompleted,
326 IPersistFile_fnGetCurFile
329 /************************************************************************
330 * IPersistStream_QueryInterface
332 static HRESULT WINAPI IPersistStream_fnQueryInterface(
333 IPersistStream* iface,
337 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
339 TRACE("(%p)\n",This);
341 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
344 /************************************************************************
345 * IPersistStream_Release
347 static ULONG WINAPI IPersistStream_fnRelease(
348 IPersistStream* iface)
350 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
352 TRACE("(%p)\n",This);
354 return IShellLinkA_Release((IShellLinkA*)This);
357 /************************************************************************
358 * IPersistStream_AddRef
360 static ULONG WINAPI IPersistStream_fnAddRef(
361 IPersistStream* iface)
363 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
365 TRACE("(%p)\n",This);
367 return IShellLinkA_AddRef((IShellLinkA*)This);
370 /************************************************************************
371 * IPersistStream_GetClassID
374 static HRESULT WINAPI IPersistStream_fnGetClassID(
375 IPersistStream* iface,
378 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
380 TRACE("(%p)\n", This);
385 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
390 /************************************************************************
391 * IPersistStream_IsDirty (IPersistStream)
393 static HRESULT WINAPI IPersistStream_fnIsDirty(
394 IPersistStream* iface)
396 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
398 TRACE("(%p)\n", This);
404 static HRESULT Stream_LoadString( IStream* stm, BOOL unicode, LPWSTR *pstr )
415 r = IStream_Read(stm, &len, sizeof(len), &count);
416 if ( FAILED (r) || ( count != sizeof(len) ) )
420 len *= sizeof (WCHAR);
422 TRACE("reading %d\n", len);
423 temp = HeapAlloc(GetProcessHeap(), 0, len+sizeof(WCHAR));
425 return E_OUTOFMEMORY;
427 r = IStream_Read(stm, temp, len, &count);
428 if( FAILED (r) || ( count != len ) )
430 HeapFree( GetProcessHeap(), 0, temp );
434 TRACE("read %s\n", debugstr_an(temp,len));
436 /* convert to unicode if necessary */
439 count = MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, NULL, 0 );
440 str = HeapAlloc( GetProcessHeap(), 0, (count+1)*sizeof (WCHAR) );
442 MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, str, count );
443 HeapFree( GetProcessHeap(), 0, temp );
457 static HRESULT Stream_LoadLocation( IStream* stm )
466 r = IStream_Read( stm, &size, sizeof(size), &count );
469 if( count != sizeof(loc->dwTotalSize) )
472 loc = HeapAlloc( GetProcessHeap(), 0, size );
474 return E_OUTOFMEMORY;
476 r = IStream_Read( stm, &loc->dwHeaderSize, size-sizeof(size), &count );
479 if( count != (size - sizeof(size)) )
484 loc->dwTotalSize = size;
486 TRACE("Read %ld bytes\n",count);
488 /* FIXME: do something useful with it */
489 HeapFree( GetProcessHeap(), 0, loc );
493 HeapFree( GetProcessHeap(), 0, loc );
497 /************************************************************************
498 * IPersistStream_Load (IPersistStream)
500 static HRESULT WINAPI IPersistStream_fnLoad(
501 IPersistStream* iface,
507 WCHAR sTemp[MAX_PATH];
510 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
512 TRACE("(%p)(%p)\n", This, stm);
515 return STG_E_INVALIDPOINTER;
518 r = IStream_Read(stm, &hdr, sizeof(hdr), &dwBytesRead);
522 if( dwBytesRead != sizeof(hdr))
524 if( hdr.dwSize != sizeof(hdr))
526 if( !IsEqualIID(&hdr.MagicGuid, &CLSID_ShellLink) )
529 /* if( hdr.dwFlags & SCF_PIDL ) */ /* FIXME: seems to always have a PIDL */
531 r = ILLoadFromStream( stm, &This->pPidl );
535 This->wHotKey = hdr.wHotKey;
536 This->iIcoNdx = hdr.nIcon;
537 FileTimeToSystemTime (&hdr.Time1, &This->time1);
538 FileTimeToSystemTime (&hdr.Time2, &This->time2);
539 FileTimeToSystemTime (&hdr.Time3, &This->time3);
541 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
542 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
543 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
544 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
545 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
546 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
549 if( hdr.dwFlags & SCF_NORMAL )
550 r = Stream_LoadLocation( stm );
553 unicode = hdr.dwFlags & SCF_UNICODE;
554 if( hdr.dwFlags & SCF_DESCRIPTION )
556 r = Stream_LoadString( stm, unicode, &This->sDescription );
557 TRACE("Description -> %s\n",debugstr_w(This->sDescription));
562 if( hdr.dwFlags & SCF_RELATIVE )
564 r = Stream_LoadString( stm, unicode, &This->sPathRel );
565 TRACE("Relative Path-> %s\n",debugstr_w(This->sPathRel));
570 if( hdr.dwFlags & SCF_WORKDIR )
572 r = Stream_LoadString( stm, unicode, &This->sWorkDir );
573 TRACE("Working Dir -> %s\n",debugstr_w(This->sWorkDir));
578 if( hdr.dwFlags & SCF_ARGS )
580 r = Stream_LoadString( stm, unicode, &This->sArgs );
581 TRACE("Working Dir -> %s\n",debugstr_w(This->sArgs));
586 if( hdr.dwFlags & SCF_CUSTOMICON )
588 r = Stream_LoadString( stm, unicode, &This->sIcoPath );
589 TRACE("Icon file -> %s\n",debugstr_w(This->sIcoPath));
603 /************************************************************************
606 * Helper function for IPersistStream_Save. Writes a unicode string
607 * with terminating nul byte to a stream, preceded by the its length.
609 static HRESULT Stream_WriteString( IStream* stm, LPCWSTR str )
611 USHORT len = lstrlenW( str ) + 1;
615 r = IStream_Write( stm, &len, sizeof(len), &count );
619 len *= sizeof(WCHAR);
621 r = IStream_Write( stm, str, len, &count );
628 static HRESULT Stream_WriteLocationInfo( IStream* stm, LPCWSTR filename )
633 FIXME("writing empty location info\n");
635 memset( &loc, 0, sizeof(loc) );
636 loc.dwTotalSize = sizeof(loc) - sizeof(loc.dwTotalSize);
638 /* FIXME: fill this in */
640 return IStream_Write( stm, &loc, loc.dwTotalSize, &count );
643 /************************************************************************
644 * IPersistStream_Save (IPersistStream)
646 * FIXME: makes assumptions about byte order
648 static HRESULT WINAPI IPersistStream_fnSave(
649 IPersistStream* iface,
657 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
659 TRACE("(%p) %p %x\n", This, stm, fClearDirty);
661 /* if there's no PIDL, generate one */
666 This->pPidl = ILCreateFromPathW( This->sPath );
669 memset(&header, 0, sizeof(header));
670 header.dwSize = sizeof(header);
671 memcpy(&header.MagicGuid, &CLSID_ShellLink, sizeof(header.MagicGuid) );
673 header.wHotKey = This->wHotKey;
674 header.nIcon = This->iIcoNdx;
675 header.dwFlags = SCF_UNICODE; /* strings are in unicode */
676 header.dwFlags |= SCF_NORMAL; /* how do we determine this ? */
678 header.dwFlags |= SCF_PIDL;
679 if( This->sDescription )
680 header.dwFlags |= SCF_DESCRIPTION;
682 header.dwFlags |= SCF_WORKDIR;
684 header.dwFlags |= SCF_ARGS;
686 header.dwFlags |= SCF_CUSTOMICON;
688 SystemTimeToFileTime ( &This->time1, &header.Time1 );
689 SystemTimeToFileTime ( &This->time2, &header.Time2 );
690 SystemTimeToFileTime ( &This->time3, &header.Time3 );
692 /* write the Shortcut header */
693 r = IStream_Write( stm, &header, sizeof(header), &count );
696 ERR("Write failed at %d\n",__LINE__);
700 TRACE("Writing pidl \n");
702 /* write the PIDL to the shortcut */
705 r = ILSaveToStream( stm, This->pPidl );
708 ERR("Failed to write PIDL at %d\n",__LINE__);
713 TRACE("Path = %s\n", debugstr_w(This->sPath));
716 Stream_WriteLocationInfo( stm, This->sPath );
718 TRACE("Description = %s\n", debugstr_w(This->sDescription));
719 if( This->sDescription )
720 r = Stream_WriteString( stm, This->sDescription );
723 r = Stream_WriteString( stm, This->sPathRel );
726 r = Stream_WriteString( stm, This->sWorkDir );
729 r = Stream_WriteString( stm, This->sArgs );
732 r = Stream_WriteString( stm, This->sIcoPath );
737 /************************************************************************
738 * IPersistStream_GetSizeMax (IPersistStream)
740 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
741 IPersistStream* iface,
742 ULARGE_INTEGER* pcbSize)
744 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
746 TRACE("(%p)\n", This);
751 static ICOM_VTABLE(IPersistStream) psvt =
753 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
754 IPersistStream_fnQueryInterface,
755 IPersistStream_fnAddRef,
756 IPersistStream_fnRelease,
757 IPersistStream_fnGetClassID,
758 IPersistStream_fnIsDirty,
759 IPersistStream_fnLoad,
760 IPersistStream_fnSave,
761 IPersistStream_fnGetSizeMax
764 /**************************************************************************
765 * IShellLink_Constructor
767 HRESULT WINAPI IShellLink_Constructor (
768 IUnknown * pUnkOuter,
774 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
778 if(pUnkOuter) return CLASS_E_NOAGGREGATION;
779 sl = (IShellLinkImpl *) LocalAlloc(GMEM_ZEROINIT,sizeof(IShellLinkImpl));
780 if (!sl) return E_OUTOFMEMORY;
784 sl->lpvtblw = &slvtw;
785 sl->lpvtblPersistFile = &pfvt;
786 sl->lpvtblPersistStream = &psvt;
787 sl->iShowCmd = SW_SHOWNORMAL;
789 TRACE("(%p)->()\n",sl);
791 if (IsEqualIID(riid, &IID_IUnknown) ||
792 IsEqualIID(riid, &IID_IShellLinkA))
794 else if (IsEqualIID(riid, &IID_IShellLinkW))
795 *ppv = &(sl->lpvtblw);
797 LocalFree((HLOCAL)sl);
798 ERR("E_NOINTERFACE\n");
799 return E_NOINTERFACE;
805 /**************************************************************************
806 * IShellLinkA_QueryInterface
808 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
810 ICOM_THIS(IShellLinkImpl, iface);
812 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
816 if(IsEqualIID(riid, &IID_IUnknown) ||
817 IsEqualIID(riid, &IID_IShellLinkA))
821 else if(IsEqualIID(riid, &IID_IShellLinkW))
823 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
825 else if(IsEqualIID(riid, &IID_IPersistFile))
827 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
829 else if(IsEqualIID(riid, &IID_IPersistStream))
831 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
836 IUnknown_AddRef((IUnknown*)(*ppvObj));
837 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
840 TRACE("-- Interface: E_NOINTERFACE\n");
841 return E_NOINTERFACE;
843 /******************************************************************************
846 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
848 ICOM_THIS(IShellLinkImpl, iface);
850 TRACE("(%p)->(count=%lu)\n",This,This->ref);
852 return ++(This->ref);
854 /******************************************************************************
855 * IShellLinkA_Release
857 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
859 ICOM_THIS(IShellLinkImpl, iface);
861 TRACE("(%p)->(count=%lu)\n",This,This->ref);
866 TRACE("-- destroying IShellLink(%p)\n",This);
869 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
872 HeapFree(GetProcessHeap(), 0, This->sArgs);
875 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
877 if (This->sDescription)
878 HeapFree(GetProcessHeap(), 0, This->sDescription);
881 HeapFree(GetProcessHeap(),0,This->sPath);
886 LocalFree((HANDLE)This);
891 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,
892 INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
894 ICOM_THIS(IShellLinkImpl, iface);
896 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
897 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
902 WideCharToMultiByte( CP_ACP, 0, This->sPath, -1,
903 pszFile, cchMaxPath, NULL, NULL);
908 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
910 ICOM_THIS(IShellLinkImpl, iface);
912 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
914 *ppidl = ILClone(This->pPidl);
919 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
921 ICOM_THIS(IShellLinkImpl, iface);
923 TRACE("(%p)->(pidl=%p)\n",This, pidl);
927 This->pPidl = ILClone (pidl);
932 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
934 ICOM_THIS(IShellLinkImpl, iface);
936 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
940 if( This->sDescription )
941 WideCharToMultiByte( CP_ACP, 0, This->sDescription, -1,
942 pszName, cchMaxName, NULL, NULL);
946 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
948 ICOM_THIS(IShellLinkImpl, iface);
950 TRACE("(%p)->(pName=%s)\n", This, pszName);
952 if (This->sDescription)
953 HeapFree(GetProcessHeap(), 0, This->sDescription);
954 This->sDescription = HEAP_strdupAtoW( GetProcessHeap(), 0, pszName);
955 if ( !This->sDescription )
956 return E_OUTOFMEMORY;
961 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
963 ICOM_THIS(IShellLinkImpl, iface);
965 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
970 WideCharToMultiByte( CP_ACP, 0, This->sWorkDir, -1,
971 pszDir, cchMaxPath, NULL, NULL);
976 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
978 ICOM_THIS(IShellLinkImpl, iface);
980 TRACE("(%p)->(dir=%s)\n",This, pszDir);
983 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
984 This->sWorkDir = HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir);
985 if ( !This->sWorkDir )
986 return E_OUTOFMEMORY;
991 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
993 ICOM_THIS(IShellLinkImpl, iface);
995 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1000 WideCharToMultiByte( CP_ACP, 0, This->sArgs, -1,
1001 pszArgs, cchMaxPath, NULL, NULL);
1006 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1008 ICOM_THIS(IShellLinkImpl, iface);
1010 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1013 HeapFree(GetProcessHeap(), 0, This->sArgs);
1014 This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs);
1016 return E_OUTOFMEMORY;
1021 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1023 ICOM_THIS(IShellLinkImpl, iface);
1025 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1027 *pwHotkey = This->wHotKey;
1032 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1034 ICOM_THIS(IShellLinkImpl, iface);
1036 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1038 This->wHotKey = wHotkey;
1043 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1045 ICOM_THIS(IShellLinkImpl, iface);
1047 TRACE("(%p)->(%p)\n",This, piShowCmd);
1048 *piShowCmd = This->iShowCmd;
1052 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1054 ICOM_THIS(IShellLinkImpl, iface);
1056 TRACE("(%p) %d\n",This, iShowCmd);
1058 This->iShowCmd = iShowCmd;
1063 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1065 ICOM_THIS(IShellLinkImpl, iface);
1067 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1071 if( This->sIcoPath )
1072 WideCharToMultiByte( CP_ACP, 0, This->sIcoPath, -1,
1073 pszIconPath, cchIconPath, NULL, NULL);
1074 *piIcon = This->iIcoNdx;
1079 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1081 ICOM_THIS(IShellLinkImpl, iface);
1083 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1086 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1087 This->sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1088 if ( !This->sIcoPath )
1089 return E_OUTOFMEMORY;
1090 This->iIcoNdx = iIcon;
1095 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1097 ICOM_THIS(IShellLinkImpl, iface);
1099 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1102 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1103 This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1108 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1110 ICOM_THIS(IShellLinkImpl, iface);
1112 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1116 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1118 ICOM_THIS(IShellLinkImpl, iface);
1120 TRACE("(%p)->(path=%s)\n",This, pszFile);
1123 HeapFree(GetProcessHeap(), 0, This->sPath);
1124 This->sPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1126 return E_OUTOFMEMORY;
1131 /**************************************************************************
1132 * IShellLink Implementation
1135 static ICOM_VTABLE(IShellLinkA) slvt =
1137 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1138 IShellLinkA_fnQueryInterface,
1139 IShellLinkA_fnAddRef,
1140 IShellLinkA_fnRelease,
1141 IShellLinkA_fnGetPath,
1142 IShellLinkA_fnGetIDList,
1143 IShellLinkA_fnSetIDList,
1144 IShellLinkA_fnGetDescription,
1145 IShellLinkA_fnSetDescription,
1146 IShellLinkA_fnGetWorkingDirectory,
1147 IShellLinkA_fnSetWorkingDirectory,
1148 IShellLinkA_fnGetArguments,
1149 IShellLinkA_fnSetArguments,
1150 IShellLinkA_fnGetHotkey,
1151 IShellLinkA_fnSetHotkey,
1152 IShellLinkA_fnGetShowCmd,
1153 IShellLinkA_fnSetShowCmd,
1154 IShellLinkA_fnGetIconLocation,
1155 IShellLinkA_fnSetIconLocation,
1156 IShellLinkA_fnSetRelativePath,
1157 IShellLinkA_fnResolve,
1158 IShellLinkA_fnSetPath
1162 /**************************************************************************
1163 * IShellLinkW_fnQueryInterface
1165 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1166 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1168 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1170 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1173 /******************************************************************************
1174 * IShellLinkW_fnAddRef
1176 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1178 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1180 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1182 return IShellLinkA_AddRef((IShellLinkA*)This);
1184 /******************************************************************************
1185 * IShellLinkW_fnRelease
1188 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1190 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1192 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1194 return IShellLinkA_Release((IShellLinkA*)This);
1197 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags)
1199 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1201 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1205 lstrcpynW( pszFile, This->sPath, cchMaxPath );
1210 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1212 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1214 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1217 *ppidl = ILClone( This->pPidl );
1224 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1226 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1228 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1231 ILFree( This->pPidl );
1232 This->pPidl = ILClone( pidl );
1239 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1241 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1243 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1247 if( This->sDescription )
1248 lstrcpynW( pszName, This->sDescription, cchMaxName );
1253 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1255 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1257 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1259 if (This->sDescription)
1260 HeapFree(GetProcessHeap(), 0, This->sDescription);
1261 This->sDescription = HeapAlloc( GetProcessHeap(), 0,
1262 (lstrlenW( pszName )+1)*sizeof(WCHAR) );
1263 if ( !This->sDescription )
1264 return E_OUTOFMEMORY;
1265 lstrcpyW( This->sDescription, pszName );
1270 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1272 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1274 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1278 if( This->sWorkDir )
1279 lstrcpynW( pszDir, This->sWorkDir, cchMaxPath );
1284 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1286 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1288 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1291 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1292 This->sWorkDir = HeapAlloc( GetProcessHeap(), 0,
1293 (lstrlenW( pszDir )+1)*sizeof (WCHAR) );
1294 if ( !This->sWorkDir )
1295 return E_OUTOFMEMORY;
1296 lstrcpyW( This->sWorkDir, pszDir );
1301 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1303 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1305 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1310 lstrcpynW( pszArgs, This->sArgs, cchMaxPath );
1315 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1317 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1319 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1322 HeapFree(GetProcessHeap(), 0, This->sArgs);
1323 This->sArgs = HeapAlloc( GetProcessHeap(), 0,
1324 (lstrlenW( pszArgs )+1)*sizeof (WCHAR) );
1326 return E_OUTOFMEMORY;
1327 lstrcpyW( This->sArgs, pszArgs );
1332 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1334 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1336 TRACE("(%p)->(%p)\n",This, pwHotkey);
1338 *pwHotkey=This->wHotKey;
1343 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1345 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1347 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1349 This->wHotKey = wHotkey;
1354 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1356 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1358 TRACE("(%p)->(%p)\n",This, piShowCmd);
1360 *piShowCmd = This->iShowCmd;
1365 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1367 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1369 This->iShowCmd = iShowCmd;
1374 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1376 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1378 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1382 if( This->sIcoPath )
1383 lstrcpynW( pszIconPath, This->sIcoPath, cchIconPath );
1384 *piIcon = This->iIcoNdx;
1389 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1391 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1393 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1396 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1397 This->sIcoPath = HeapAlloc( GetProcessHeap(), 0,
1398 (lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
1399 if ( !This->sIcoPath )
1400 return E_OUTOFMEMORY;
1401 lstrcpyW( This->sIcoPath, pszIconPath );
1403 This->iIcoNdx = iIcon;
1408 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1410 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1412 TRACE("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1415 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1416 This->sPathRel = HeapAlloc( GetProcessHeap(), 0,
1417 (lstrlenW( pszPathRel )+1) * sizeof (WCHAR) );
1418 if ( !This->sPathRel )
1419 return E_OUTOFMEMORY;
1420 lstrcpyW( This->sPathRel, pszPathRel );
1425 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1427 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1429 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1434 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1436 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1438 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1441 HeapFree(GetProcessHeap(), 0, This->sPath);
1442 This->sPath = HeapAlloc( GetProcessHeap(), 0,
1443 (lstrlenW( pszFile )+1) * sizeof (WCHAR) );
1445 return E_OUTOFMEMORY;
1446 lstrcpyW( This->sPath, pszFile );
1451 /**************************************************************************
1452 * IShellLinkW Implementation
1455 static ICOM_VTABLE(IShellLinkW) slvtw =
1457 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1458 IShellLinkW_fnQueryInterface,
1459 IShellLinkW_fnAddRef,
1460 IShellLinkW_fnRelease,
1461 IShellLinkW_fnGetPath,
1462 IShellLinkW_fnGetIDList,
1463 IShellLinkW_fnSetIDList,
1464 IShellLinkW_fnGetDescription,
1465 IShellLinkW_fnSetDescription,
1466 IShellLinkW_fnGetWorkingDirectory,
1467 IShellLinkW_fnSetWorkingDirectory,
1468 IShellLinkW_fnGetArguments,
1469 IShellLinkW_fnSetArguments,
1470 IShellLinkW_fnGetHotkey,
1471 IShellLinkW_fnSetHotkey,
1472 IShellLinkW_fnGetShowCmd,
1473 IShellLinkW_fnSetShowCmd,
1474 IShellLinkW_fnGetIconLocation,
1475 IShellLinkW_fnSetIconLocation,
1476 IShellLinkW_fnSetRelativePath,
1477 IShellLinkW_fnResolve,
1478 IShellLinkW_fnSetPath