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
32 #ifdef HAVE_SYS_WAIT_H
33 # include <sys/wait.h>
35 #include "wine/debug.h"
36 #include "wine/port.h"
46 #include "undocshell.h"
50 #include "shell32_main.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55 /* link file formats */
57 /* flag1: lnk elements: simple link has 0x0B */
60 #define SCF_DESCRIPTION 4
61 #define SCF_RELATIVE 8
62 #define SCF_WORKDIR 0x10
64 #define SCF_CUSTOMICON 0x40
66 #define SCF_UNICODE 0x1000
70 typedef struct _LINK_HEADER
72 DWORD dwSize; /* 0x00 size of the header - 0x4c */
73 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
74 DWORD dwFlags; /* 0x14 describes elements following */
75 DWORD dwFileAttr; /* 0x18 attributes of the target file */
76 FILETIME Time1; /* 0x1c */
77 FILETIME Time2; /* 0x24 */
78 FILETIME Time3; /* 0x2c */
79 DWORD dwFileLength; /* 0x34 File length */
80 DWORD nIcon; /* 0x38 icon number */
81 DWORD fStartup; /* 0x3c startup type */
82 DWORD wHotKey; /* 0x40 hotkey */
83 DWORD Unknown5; /* 0x44 */
84 DWORD Unknown6; /* 0x48 */
85 } LINK_HEADER, * PLINK_HEADER;
87 #define SHLINK_LOCAL 0
88 #define SHLINK_REMOTE 1
90 typedef struct _LOCATION_INFO
97 DWORD dwNetworkVolTableOfs;
101 typedef struct _LOCAL_VOLUME_INFO
111 static ICOM_VTABLE(IShellLinkA) slvt;
112 static ICOM_VTABLE(IShellLinkW) slvtw;
113 static ICOM_VTABLE(IPersistFile) pfvt;
114 static ICOM_VTABLE(IPersistStream) psvt;
116 /* IShellLink Implementation */
120 ICOM_VFIELD(IShellLinkA);
123 ICOM_VTABLE(IShellLinkW)* lpvtblw;
124 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
125 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
127 /* data structures according to the informations in the lnk */
144 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
145 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
147 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
148 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
150 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
151 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
152 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset)
155 /* strdup on the process heap */
156 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str)
158 INT len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
159 LPWSTR p = HeapAlloc( heap, flags, len*sizeof (WCHAR) );
162 MultiByteToWideChar( CP_ACP, 0, str, -1, p, len );
167 /**************************************************************************
168 * IPersistFile_QueryInterface
170 static HRESULT WINAPI IPersistFile_fnQueryInterface(
175 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
177 TRACE("(%p)\n",This);
179 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
182 /******************************************************************************
183 * IPersistFile_AddRef
185 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
187 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
189 TRACE("(%p)->(count=%lu)\n",This,This->ref);
191 return IShellLinkA_AddRef((IShellLinkA*)This);
193 /******************************************************************************
194 * IPersistFile_Release
196 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
198 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
200 TRACE("(%p)->(count=%lu)\n",This,This->ref);
202 return IShellLinkA_Release((IShellLinkA*)This);
205 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
207 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
208 FIXME("(%p)\n",This);
211 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
213 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
214 FIXME("(%p)\n",This);
217 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
219 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
220 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
224 TRACE("(%p, %s)\n",This, debugstr_w(pszFileName));
226 r = CreateStreamOnFile(pszFileName, dwMode, &stm);
229 r = IPersistStream_Load(StreamThis, stm);
230 IStream_Release( stm );
236 static BOOL StartLinkProcessor( LPCOLESTR szLink )
238 const WCHAR szFormat[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
239 ' ','-','r',' ','"','%','s','"',0 };
243 PROCESS_INFORMATION pi;
245 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
246 buffer = HeapAlloc( GetProcessHeap(), 0, len );
250 wsprintfW( buffer, szFormat, szLink );
252 TRACE("starting %s\n",debugstr_w(buffer));
254 memset(&si, 0, sizeof(si));
256 if (!CreateProcessW( NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return FALSE;
258 /* wait for a while to throttle the creation of linker processes */
259 if( WAIT_OBJECT_0 != WaitForSingleObject( pi.hProcess, 10000 ) )
260 WARN("Timed out waiting for shell linker\n");
262 CloseHandle( pi.hProcess );
263 CloseHandle( pi.hThread );
268 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
270 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
271 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
275 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
277 if (!pszFileName || !This->sPath)
278 return ERROR_UNKNOWN;
280 r = CreateStreamOnFile(pszFileName, STGM_READWRITE | STGM_CREATE, &stm);
283 r = IPersistStream_Save(StreamThis, stm, FALSE);
284 IStream_Release( stm );
287 StartLinkProcessor( pszFileName );
290 DeleteFileW( pszFileName );
291 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName) );
298 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
300 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
301 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
304 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
306 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
307 FIXME("(%p)\n",This);
311 static ICOM_VTABLE(IPersistFile) pfvt =
313 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
314 IPersistFile_fnQueryInterface,
315 IPersistFile_fnAddRef,
316 IPersistFile_fnRelease,
317 IPersistFile_fnGetClassID,
318 IPersistFile_fnIsDirty,
321 IPersistFile_fnSaveCompleted,
322 IPersistFile_fnGetCurFile
325 /************************************************************************
326 * IPersistStream_QueryInterface
328 static HRESULT WINAPI IPersistStream_fnQueryInterface(
329 IPersistStream* iface,
333 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
335 TRACE("(%p)\n",This);
337 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
340 /************************************************************************
341 * IPersistStream_Release
343 static ULONG WINAPI IPersistStream_fnRelease(
344 IPersistStream* iface)
346 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
348 TRACE("(%p)\n",This);
350 return IShellLinkA_Release((IShellLinkA*)This);
353 /************************************************************************
354 * IPersistStream_AddRef
356 static ULONG WINAPI IPersistStream_fnAddRef(
357 IPersistStream* iface)
359 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
361 TRACE("(%p)\n",This);
363 return IShellLinkA_AddRef((IShellLinkA*)This);
366 /************************************************************************
367 * IPersistStream_GetClassID
370 static HRESULT WINAPI IPersistStream_fnGetClassID(
371 IPersistStream* iface,
374 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
376 TRACE("(%p)\n", This);
381 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
386 /************************************************************************
387 * IPersistStream_IsDirty (IPersistStream)
389 static HRESULT WINAPI IPersistStream_fnIsDirty(
390 IPersistStream* iface)
392 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
394 TRACE("(%p)\n", This);
400 static HRESULT Stream_LoadString( IStream* stm, BOOL unicode, LPWSTR *pstr )
411 r = IStream_Read(stm, &len, sizeof(len), &count);
412 if ( FAILED (r) || ( count != sizeof(len) ) )
416 len *= sizeof (WCHAR);
418 TRACE("reading %d\n", len);
419 temp = HeapAlloc(GetProcessHeap(), 0, len+sizeof(WCHAR));
421 return E_OUTOFMEMORY;
423 r = IStream_Read(stm, temp, len, &count);
424 if( FAILED (r) || ( count != len ) )
426 HeapFree( GetProcessHeap(), 0, temp );
430 TRACE("read %s\n", debugstr_an(temp,len));
432 /* convert to unicode if necessary */
435 count = MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, NULL, 0 );
436 str = HeapAlloc( GetProcessHeap(), 0, (count+1)*sizeof (WCHAR) );
438 MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, str, count );
439 HeapFree( GetProcessHeap(), 0, temp );
453 static HRESULT Stream_LoadLocation( IStream* stm )
462 r = IStream_Read( stm, &size, sizeof(size), &count );
465 if( count != sizeof(loc->dwTotalSize) )
468 loc = HeapAlloc( GetProcessHeap(), 0, size );
470 return E_OUTOFMEMORY;
472 r = IStream_Read( stm, &loc->dwHeaderSize, size-sizeof(size), &count );
475 if( count != (size - sizeof(size)) )
480 loc->dwTotalSize = size;
482 TRACE("Read %ld bytes\n",count);
484 /* FIXME: do something useful with it */
485 HeapFree( GetProcessHeap(), 0, loc );
489 HeapFree( GetProcessHeap(), 0, loc );
493 /************************************************************************
494 * IPersistStream_Load (IPersistStream)
496 static HRESULT WINAPI IPersistStream_fnLoad(
497 IPersistStream* iface,
503 WCHAR sTemp[MAX_PATH];
506 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
508 TRACE("(%p)(%p)\n", This, stm);
511 return STG_E_INVALIDPOINTER;
514 r = IStream_Read(stm, &hdr, sizeof(hdr), &dwBytesRead);
518 if( dwBytesRead != sizeof(hdr))
520 if( hdr.dwSize != sizeof(hdr))
522 if( !IsEqualIID(&hdr.MagicGuid, &CLSID_ShellLink) )
525 /* if( hdr.dwFlags & SCF_PIDL ) */ /* FIXME: seems to always have a PIDL */
527 r = ILLoadFromStream( stm, &This->pPidl );
531 This->wHotKey = hdr.wHotKey;
532 This->iIcoNdx = hdr.nIcon;
533 FileTimeToSystemTime (&hdr.Time1, &This->time1);
534 FileTimeToSystemTime (&hdr.Time2, &This->time2);
535 FileTimeToSystemTime (&hdr.Time3, &This->time3);
537 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
538 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
539 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
540 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
541 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
542 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
545 if( hdr.dwFlags & SCF_NORMAL )
546 r = Stream_LoadLocation( stm );
549 unicode = hdr.dwFlags & SCF_UNICODE;
550 if( hdr.dwFlags & SCF_DESCRIPTION )
552 r = Stream_LoadString( stm, unicode, &This->sDescription );
553 TRACE("Description -> %s\n",debugstr_w(This->sDescription));
558 if( hdr.dwFlags & SCF_RELATIVE )
560 r = Stream_LoadString( stm, unicode, &This->sPathRel );
561 TRACE("Relative Path-> %s\n",debugstr_w(This->sPathRel));
566 if( hdr.dwFlags & SCF_WORKDIR )
568 r = Stream_LoadString( stm, unicode, &This->sWorkDir );
569 TRACE("Working Dir -> %s\n",debugstr_w(This->sWorkDir));
574 if( hdr.dwFlags & SCF_ARGS )
576 r = Stream_LoadString( stm, unicode, &This->sArgs );
577 TRACE("Working Dir -> %s\n",debugstr_w(This->sArgs));
582 if( hdr.dwFlags & SCF_CUSTOMICON )
584 r = Stream_LoadString( stm, unicode, &This->sIcoPath );
585 TRACE("Icon file -> %s\n",debugstr_w(This->sIcoPath));
599 /************************************************************************
602 * Helper function for IPersistStream_Save. Writes a unicode string
603 * with terminating nul byte to a stream, preceded by the its length.
605 static HRESULT Stream_WriteString( IStream* stm, LPCWSTR str )
607 USHORT len = lstrlenW( str ) + 1;
611 r = IStream_Write( stm, &len, sizeof(len), &count );
615 len *= sizeof(WCHAR);
617 r = IStream_Write( stm, str, len, &count );
624 static HRESULT Stream_WriteLocationInfo( IStream* stm, LPCWSTR filename )
629 FIXME("writing empty location info\n");
631 memset( &loc, 0, sizeof(loc) );
632 loc.dwTotalSize = sizeof(loc) - sizeof(loc.dwTotalSize);
634 /* FIXME: fill this in */
636 return IStream_Write( stm, &loc, loc.dwTotalSize, &count );
639 /************************************************************************
640 * IPersistStream_Save (IPersistStream)
642 * FIXME: makes assumptions about byte order
644 static HRESULT WINAPI IPersistStream_fnSave(
645 IPersistStream* iface,
653 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
655 TRACE("(%p) %p %x\n", This, stm, fClearDirty);
657 /* if there's no PIDL, generate one */
662 This->pPidl = ILCreateFromPathW( This->sPath );
665 memset(&header, 0, sizeof(header));
666 header.dwSize = sizeof(header);
667 memcpy(&header.MagicGuid, &CLSID_ShellLink, sizeof(header.MagicGuid) );
669 header.wHotKey = This->wHotKey;
670 header.nIcon = This->iIcoNdx;
671 header.dwFlags = SCF_UNICODE; /* strings are in unicode */
672 header.dwFlags |= SCF_NORMAL; /* how do we determine this ? */
674 header.dwFlags |= SCF_PIDL;
675 if( This->sDescription )
676 header.dwFlags |= SCF_DESCRIPTION;
678 header.dwFlags |= SCF_WORKDIR;
680 header.dwFlags |= SCF_ARGS;
682 header.dwFlags |= SCF_CUSTOMICON;
684 SystemTimeToFileTime ( &This->time1, &header.Time1 );
685 SystemTimeToFileTime ( &This->time2, &header.Time2 );
686 SystemTimeToFileTime ( &This->time3, &header.Time3 );
688 /* write the Shortcut header */
689 r = IStream_Write( stm, &header, sizeof(header), &count );
692 ERR("Write failed at %d\n",__LINE__);
696 TRACE("Writing pidl \n");
698 /* write the PIDL to the shortcut */
701 r = ILSaveToStream( stm, This->pPidl );
704 ERR("Failed to write PIDL at %d\n",__LINE__);
709 TRACE("Path = %s\n", debugstr_w(This->sPath));
712 Stream_WriteLocationInfo( stm, This->sPath );
714 TRACE("Description = %s\n", debugstr_w(This->sDescription));
715 if( This->sDescription )
716 r = Stream_WriteString( stm, This->sDescription );
719 r = Stream_WriteString( stm, This->sPathRel );
722 r = Stream_WriteString( stm, This->sWorkDir );
725 r = Stream_WriteString( stm, This->sArgs );
728 r = Stream_WriteString( stm, This->sIcoPath );
733 /************************************************************************
734 * IPersistStream_GetSizeMax (IPersistStream)
736 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
737 IPersistStream* iface,
738 ULARGE_INTEGER* pcbSize)
740 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
742 TRACE("(%p)\n", This);
747 static ICOM_VTABLE(IPersistStream) psvt =
749 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
750 IPersistStream_fnQueryInterface,
751 IPersistStream_fnAddRef,
752 IPersistStream_fnRelease,
753 IPersistStream_fnGetClassID,
754 IPersistStream_fnIsDirty,
755 IPersistStream_fnLoad,
756 IPersistStream_fnSave,
757 IPersistStream_fnGetSizeMax
760 /**************************************************************************
761 * IShellLink_Constructor
763 HRESULT WINAPI IShellLink_Constructor (
764 IUnknown * pUnkOuter,
770 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
774 if(pUnkOuter) return CLASS_E_NOAGGREGATION;
775 sl = (IShellLinkImpl *) LocalAlloc(GMEM_ZEROINIT,sizeof(IShellLinkImpl));
776 if (!sl) return E_OUTOFMEMORY;
780 sl->lpvtblw = &slvtw;
781 sl->lpvtblPersistFile = &pfvt;
782 sl->lpvtblPersistStream = &psvt;
783 sl->iShowCmd = SW_SHOWNORMAL;
785 TRACE("(%p)->()\n",sl);
787 if (IsEqualIID(riid, &IID_IUnknown) ||
788 IsEqualIID(riid, &IID_IShellLinkA))
790 else if (IsEqualIID(riid, &IID_IShellLinkW))
791 *ppv = &(sl->lpvtblw);
793 LocalFree((HLOCAL)sl);
794 ERR("E_NOINTERFACE\n");
795 return E_NOINTERFACE;
801 /**************************************************************************
802 * IShellLinkA_QueryInterface
804 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
806 ICOM_THIS(IShellLinkImpl, iface);
808 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
812 if(IsEqualIID(riid, &IID_IUnknown) ||
813 IsEqualIID(riid, &IID_IShellLinkA))
817 else if(IsEqualIID(riid, &IID_IShellLinkW))
819 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
821 else if(IsEqualIID(riid, &IID_IPersistFile))
823 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
825 else if(IsEqualIID(riid, &IID_IPersistStream))
827 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
832 IUnknown_AddRef((IUnknown*)(*ppvObj));
833 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
836 TRACE("-- Interface: E_NOINTERFACE\n");
837 return E_NOINTERFACE;
839 /******************************************************************************
842 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
844 ICOM_THIS(IShellLinkImpl, iface);
846 TRACE("(%p)->(count=%lu)\n",This,This->ref);
848 return ++(This->ref);
850 /******************************************************************************
851 * IShellLinkA_Release
853 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
855 ICOM_THIS(IShellLinkImpl, iface);
857 TRACE("(%p)->(count=%lu)\n",This,This->ref);
862 TRACE("-- destroying IShellLink(%p)\n",This);
865 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
868 HeapFree(GetProcessHeap(), 0, This->sArgs);
871 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
873 if (This->sDescription)
874 HeapFree(GetProcessHeap(), 0, This->sDescription);
877 HeapFree(GetProcessHeap(),0,This->sPath);
882 LocalFree((HANDLE)This);
887 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,
888 INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
890 ICOM_THIS(IShellLinkImpl, iface);
892 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
893 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
898 WideCharToMultiByte( CP_ACP, 0, This->sPath, -1,
899 pszFile, cchMaxPath, NULL, NULL);
904 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
906 ICOM_THIS(IShellLinkImpl, iface);
908 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
910 *ppidl = ILClone(This->pPidl);
915 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
917 ICOM_THIS(IShellLinkImpl, iface);
919 TRACE("(%p)->(pidl=%p)\n",This, pidl);
923 This->pPidl = ILClone (pidl);
928 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
930 ICOM_THIS(IShellLinkImpl, iface);
932 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
936 if( This->sDescription )
937 WideCharToMultiByte( CP_ACP, 0, This->sDescription, -1,
938 pszName, cchMaxName, NULL, NULL);
942 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
944 ICOM_THIS(IShellLinkImpl, iface);
946 TRACE("(%p)->(pName=%s)\n", This, pszName);
948 if (This->sDescription)
949 HeapFree(GetProcessHeap(), 0, This->sDescription);
950 This->sDescription = HEAP_strdupAtoW( GetProcessHeap(), 0, pszName);
951 if ( !This->sDescription )
952 return E_OUTOFMEMORY;
957 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
959 ICOM_THIS(IShellLinkImpl, iface);
961 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
966 WideCharToMultiByte( CP_ACP, 0, This->sWorkDir, -1,
967 pszDir, cchMaxPath, NULL, NULL);
972 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
974 ICOM_THIS(IShellLinkImpl, iface);
976 TRACE("(%p)->(dir=%s)\n",This, pszDir);
979 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
980 This->sWorkDir = HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir);
981 if ( !This->sWorkDir )
982 return E_OUTOFMEMORY;
987 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
989 ICOM_THIS(IShellLinkImpl, iface);
991 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
996 WideCharToMultiByte( CP_ACP, 0, This->sArgs, -1,
997 pszArgs, cchMaxPath, NULL, NULL);
1002 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1004 ICOM_THIS(IShellLinkImpl, iface);
1006 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1009 HeapFree(GetProcessHeap(), 0, This->sArgs);
1010 This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs);
1012 return E_OUTOFMEMORY;
1017 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1019 ICOM_THIS(IShellLinkImpl, iface);
1021 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1023 *pwHotkey = This->wHotKey;
1028 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1030 ICOM_THIS(IShellLinkImpl, iface);
1032 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1034 This->wHotKey = wHotkey;
1039 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1041 ICOM_THIS(IShellLinkImpl, iface);
1043 TRACE("(%p)->(%p)\n",This, piShowCmd);
1044 *piShowCmd = This->iShowCmd;
1048 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1050 ICOM_THIS(IShellLinkImpl, iface);
1052 TRACE("(%p) %d\n",This, iShowCmd);
1054 This->iShowCmd = iShowCmd;
1059 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1061 ICOM_THIS(IShellLinkImpl, iface);
1063 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1067 if( This->sIcoPath )
1068 WideCharToMultiByte( CP_ACP, 0, This->sIcoPath, -1,
1069 pszIconPath, cchIconPath, NULL, NULL);
1070 *piIcon = This->iIcoNdx;
1075 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1077 ICOM_THIS(IShellLinkImpl, iface);
1079 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1082 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1083 This->sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1084 if ( !This->sIcoPath )
1085 return E_OUTOFMEMORY;
1086 This->iIcoNdx = iIcon;
1091 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1093 ICOM_THIS(IShellLinkImpl, iface);
1095 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1098 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1099 This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1104 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1106 ICOM_THIS(IShellLinkImpl, iface);
1108 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1112 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1114 ICOM_THIS(IShellLinkImpl, iface);
1116 TRACE("(%p)->(path=%s)\n",This, pszFile);
1119 HeapFree(GetProcessHeap(), 0, This->sPath);
1120 This->sPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1122 return E_OUTOFMEMORY;
1127 /**************************************************************************
1128 * IShellLink Implementation
1131 static ICOM_VTABLE(IShellLinkA) slvt =
1133 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1134 IShellLinkA_fnQueryInterface,
1135 IShellLinkA_fnAddRef,
1136 IShellLinkA_fnRelease,
1137 IShellLinkA_fnGetPath,
1138 IShellLinkA_fnGetIDList,
1139 IShellLinkA_fnSetIDList,
1140 IShellLinkA_fnGetDescription,
1141 IShellLinkA_fnSetDescription,
1142 IShellLinkA_fnGetWorkingDirectory,
1143 IShellLinkA_fnSetWorkingDirectory,
1144 IShellLinkA_fnGetArguments,
1145 IShellLinkA_fnSetArguments,
1146 IShellLinkA_fnGetHotkey,
1147 IShellLinkA_fnSetHotkey,
1148 IShellLinkA_fnGetShowCmd,
1149 IShellLinkA_fnSetShowCmd,
1150 IShellLinkA_fnGetIconLocation,
1151 IShellLinkA_fnSetIconLocation,
1152 IShellLinkA_fnSetRelativePath,
1153 IShellLinkA_fnResolve,
1154 IShellLinkA_fnSetPath
1158 /**************************************************************************
1159 * IShellLinkW_fnQueryInterface
1161 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1162 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1164 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1166 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1169 /******************************************************************************
1170 * IShellLinkW_fnAddRef
1172 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1174 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1176 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1178 return IShellLinkA_AddRef((IShellLinkA*)This);
1180 /******************************************************************************
1181 * IShellLinkW_fnRelease
1184 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1186 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1188 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1190 return IShellLinkA_Release((IShellLinkA*)This);
1193 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags)
1195 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1197 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1201 lstrcpynW( pszFile, This->sPath, cchMaxPath );
1206 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1208 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1210 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1213 *ppidl = ILClone( This->pPidl );
1220 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1222 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1224 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1227 ILFree( This->pPidl );
1228 This->pPidl = ILClone( pidl );
1235 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1237 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1239 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1243 if( This->sDescription )
1244 lstrcpynW( pszName, This->sDescription, cchMaxName );
1249 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1251 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1253 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1255 if (This->sDescription)
1256 HeapFree(GetProcessHeap(), 0, This->sDescription);
1257 This->sDescription = HeapAlloc( GetProcessHeap(), 0,
1258 (lstrlenW( pszName )+1)*sizeof(WCHAR) );
1259 if ( !This->sDescription )
1260 return E_OUTOFMEMORY;
1261 lstrcpyW( This->sDescription, pszName );
1266 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1268 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1270 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1274 if( This->sWorkDir )
1275 lstrcpynW( pszDir, This->sWorkDir, cchMaxPath );
1280 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1282 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1284 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1287 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1288 This->sWorkDir = HeapAlloc( GetProcessHeap(), 0,
1289 (lstrlenW( pszDir )+1)*sizeof (WCHAR) );
1290 if ( !This->sWorkDir )
1291 return E_OUTOFMEMORY;
1292 lstrcpyW( This->sWorkDir, pszDir );
1297 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1299 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1301 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1306 lstrcpynW( pszArgs, This->sArgs, cchMaxPath );
1311 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1313 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1315 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1318 HeapFree(GetProcessHeap(), 0, This->sArgs);
1319 This->sArgs = HeapAlloc( GetProcessHeap(), 0,
1320 (lstrlenW( pszArgs )+1)*sizeof (WCHAR) );
1322 return E_OUTOFMEMORY;
1323 lstrcpyW( This->sArgs, pszArgs );
1328 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1330 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1332 TRACE("(%p)->(%p)\n",This, pwHotkey);
1334 *pwHotkey=This->wHotKey;
1339 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1341 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1343 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1345 This->wHotKey = wHotkey;
1350 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1352 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1354 TRACE("(%p)->(%p)\n",This, piShowCmd);
1356 *piShowCmd = This->iShowCmd;
1361 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1363 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1365 This->iShowCmd = iShowCmd;
1370 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1372 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1374 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1378 if( This->sIcoPath )
1379 lstrcpynW( pszIconPath, This->sIcoPath, cchIconPath );
1380 *piIcon = This->iIcoNdx;
1385 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1387 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1389 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1392 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1393 This->sIcoPath = HeapAlloc( GetProcessHeap(), 0,
1394 (lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
1395 if ( !This->sIcoPath )
1396 return E_OUTOFMEMORY;
1397 lstrcpyW( This->sIcoPath, pszIconPath );
1399 This->iIcoNdx = iIcon;
1404 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1406 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1408 TRACE("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1411 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1412 This->sPathRel = HeapAlloc( GetProcessHeap(), 0,
1413 (lstrlenW( pszPathRel )+1) * sizeof (WCHAR) );
1414 if ( !This->sPathRel )
1415 return E_OUTOFMEMORY;
1416 lstrcpyW( This->sPathRel, pszPathRel );
1421 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1423 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1425 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1430 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1432 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1434 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1437 HeapFree(GetProcessHeap(), 0, This->sPath);
1438 This->sPath = HeapAlloc( GetProcessHeap(), 0,
1439 (lstrlenW( pszFile )+1) * sizeof (WCHAR) );
1441 return E_OUTOFMEMORY;
1442 lstrcpyW( This->sPath, pszFile );
1447 /**************************************************************************
1448 * IShellLinkW Implementation
1451 static ICOM_VTABLE(IShellLinkW) slvtw =
1453 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1454 IShellLinkW_fnQueryInterface,
1455 IShellLinkW_fnAddRef,
1456 IShellLinkW_fnRelease,
1457 IShellLinkW_fnGetPath,
1458 IShellLinkW_fnGetIDList,
1459 IShellLinkW_fnSetIDList,
1460 IShellLinkW_fnGetDescription,
1461 IShellLinkW_fnSetDescription,
1462 IShellLinkW_fnGetWorkingDirectory,
1463 IShellLinkW_fnSetWorkingDirectory,
1464 IShellLinkW_fnGetArguments,
1465 IShellLinkW_fnSetArguments,
1466 IShellLinkW_fnGetHotkey,
1467 IShellLinkW_fnSetHotkey,
1468 IShellLinkW_fnGetShowCmd,
1469 IShellLinkW_fnSetShowCmd,
1470 IShellLinkW_fnGetIconLocation,
1471 IShellLinkW_fnSetIconLocation,
1472 IShellLinkW_fnSetRelativePath,
1473 IShellLinkW_fnResolve,
1474 IShellLinkW_fnSetPath