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 available at http://www.wotsit.org
27 #include "wine/port.h"
38 #ifdef HAVE_SYS_WAIT_H
39 # include <sys/wait.h>
41 #include "wine/debug.h"
51 #include "undocshell.h"
54 #include "shell32_main.h"
58 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
60 /* link file formats */
62 /* flag1: lnk elements: simple link has 0x0B */
65 #define SCF_DESCRIPTION 4
66 #define SCF_RELATIVE 8
67 #define SCF_WORKDIR 0x10
69 #define SCF_CUSTOMICON 0x40
70 #define SCF_UNICODE 0x80
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 IShellLinkAVtbl slvt
;
116 static IShellLinkWVtbl slvtw
;
117 static IPersistFileVtbl pfvt
;
118 static IPersistStreamVtbl psvt
;
120 /* IShellLink Implementation */
124 IShellLinkAVtbl
*lpVtbl
;
127 IShellLinkWVtbl
*lpvtblw
;
128 IPersistFileVtbl
*lpvtblPersistFile
;
129 IPersistStreamVtbl
*lpvtblPersistStream
;
131 /* data structures according to the informations in the link */
150 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
151 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
153 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
154 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
156 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
157 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
159 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
161 /* strdup on the process heap */
162 inline static LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
164 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
165 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
168 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
173 /**************************************************************************
174 * IPersistFile_QueryInterface
176 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
181 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
183 TRACE("(%p)\n",This
);
185 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
188 /******************************************************************************
189 * IPersistFile_AddRef
191 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
193 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
195 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
197 return IShellLinkA_AddRef((IShellLinkA
*)This
);
199 /******************************************************************************
200 * IPersistFile_Release
202 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
204 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
206 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
208 return IShellLinkA_Release((IShellLinkA
*)This
);
211 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
213 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
214 FIXME("(%p)\n",This
);
217 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
219 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
221 TRACE("(%p)\n",This
);
228 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
230 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
231 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
235 TRACE("(%p, %s)\n",This
, debugstr_w(pszFileName
));
237 r
= CreateStreamOnFile(pszFileName
, dwMode
, &stm
);
240 r
= IPersistStream_Load(StreamThis
, stm
);
241 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
242 IStream_Release( stm
);
243 This
->bDirty
= FALSE
;
249 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
251 static const WCHAR szFormat
[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
252 ' ','-','r',' ','"','%','s','"',0 };
256 PROCESS_INFORMATION pi
;
258 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
259 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
263 wsprintfW( buffer
, szFormat
, szLink
);
265 TRACE("starting %s\n",debugstr_w(buffer
));
267 memset(&si
, 0, sizeof(si
));
269 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
271 /* wait for a while to throttle the creation of linker processes */
272 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
273 WARN("Timed out waiting for shell linker\n");
275 CloseHandle( pi
.hProcess
);
276 CloseHandle( pi
.hThread
);
281 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
283 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
284 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
288 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
290 if (!pszFileName
|| !This
->sPath
)
293 r
= CreateStreamOnFile(pszFileName
, STGM_READWRITE
| STGM_CREATE
, &stm
);
296 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
297 IStream_Release( stm
);
301 StartLinkProcessor( pszFileName
);
303 This
->bDirty
= FALSE
;
307 DeleteFileW( pszFileName
);
308 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
315 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
317 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
318 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
321 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
323 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
324 FIXME("(%p)\n",This
);
328 static IPersistFileVtbl pfvt
=
330 IPersistFile_fnQueryInterface
,
331 IPersistFile_fnAddRef
,
332 IPersistFile_fnRelease
,
333 IPersistFile_fnGetClassID
,
334 IPersistFile_fnIsDirty
,
337 IPersistFile_fnSaveCompleted
,
338 IPersistFile_fnGetCurFile
341 /************************************************************************
342 * IPersistStream_QueryInterface
344 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
345 IPersistStream
* iface
,
349 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
351 TRACE("(%p)\n",This
);
353 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvoid
);
356 /************************************************************************
357 * IPersistStream_Release
359 static ULONG WINAPI
IPersistStream_fnRelease(
360 IPersistStream
* iface
)
362 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
364 TRACE("(%p)\n",This
);
366 return IShellLinkA_Release((IShellLinkA
*)This
);
369 /************************************************************************
370 * IPersistStream_AddRef
372 static ULONG WINAPI
IPersistStream_fnAddRef(
373 IPersistStream
* iface
)
375 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
377 TRACE("(%p)\n",This
);
379 return IShellLinkA_AddRef((IShellLinkA
*)This
);
382 /************************************************************************
383 * IPersistStream_GetClassID
386 static HRESULT WINAPI
IPersistStream_fnGetClassID(
387 IPersistStream
* iface
,
390 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
392 TRACE("(%p)\n", This
);
397 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
402 /************************************************************************
403 * IPersistStream_IsDirty (IPersistStream)
405 static HRESULT WINAPI
IPersistStream_fnIsDirty(
406 IPersistStream
* iface
)
408 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
410 TRACE("(%p)\n", This
);
416 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
427 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
428 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
432 len
*= sizeof (WCHAR
);
434 TRACE("reading %d\n", len
);
435 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
437 return E_OUTOFMEMORY
;
439 r
= IStream_Read(stm
, temp
, len
, &count
);
440 if( FAILED (r
) || ( count
!= len
) )
442 HeapFree( GetProcessHeap(), 0, temp
);
446 TRACE("read %s\n", debugstr_an(temp
,len
));
448 /* convert to unicode if necessary */
451 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
452 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
454 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
455 HeapFree( GetProcessHeap(), 0, temp
);
469 static HRESULT
Stream_LoadLocation( IStream
* stm
)
478 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
481 if( count
!= sizeof(loc
->dwTotalSize
) )
484 loc
= HeapAlloc( GetProcessHeap(), 0, size
);
486 return E_OUTOFMEMORY
;
488 r
= IStream_Read( stm
, &loc
->dwHeaderSize
, size
-sizeof(size
), &count
);
491 if( count
!= (size
- sizeof(size
)) )
496 loc
->dwTotalSize
= size
;
498 TRACE("Read %ld bytes\n",count
);
500 /* FIXME: do something useful with it */
501 HeapFree( GetProcessHeap(), 0, loc
);
505 HeapFree( GetProcessHeap(), 0, loc
);
509 /************************************************************************
510 * IPersistStream_Load (IPersistStream)
512 static HRESULT WINAPI
IPersistStream_fnLoad(
513 IPersistStream
* iface
,
519 WCHAR sTemp
[MAX_PATH
];
522 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
524 TRACE("(%p)(%p)\n", This
, stm
);
527 return STG_E_INVALIDPOINTER
;
530 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
534 if( dwBytesRead
!= sizeof(hdr
))
536 if( hdr
.dwSize
!= sizeof(hdr
))
538 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
541 /* if( hdr.dwFlags & SCF_PIDL ) */ /* FIXME: seems to always have a PIDL */
543 r
= ILLoadFromStream( stm
, &This
->pPidl
);
547 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
548 This
->iIcoNdx
= hdr
.nIcon
;
549 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
550 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
551 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
553 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time1
, NULL
, sTemp
, 256);
554 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
555 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time2
, NULL
, sTemp
, 256);
556 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
557 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time3
, NULL
, sTemp
, 256);
558 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
561 if( hdr
.dwFlags
& SCF_NORMAL
)
562 r
= Stream_LoadLocation( stm
);
565 unicode
= hdr
.dwFlags
& SCF_UNICODE
;
566 if( hdr
.dwFlags
& SCF_DESCRIPTION
)
568 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
569 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
574 if( hdr
.dwFlags
& SCF_RELATIVE
)
576 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
577 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
582 if( hdr
.dwFlags
& SCF_WORKDIR
)
584 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
585 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
590 if( hdr
.dwFlags
& SCF_ARGS
)
592 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
593 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
598 if( hdr
.dwFlags
& SCF_CUSTOMICON
)
600 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
601 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
615 /************************************************************************
618 * Helper function for IPersistStream_Save. Writes a unicode string
619 * with terminating nul byte to a stream, preceded by the its length.
621 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
623 USHORT len
= lstrlenW( str
) + 1;
627 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
631 len
*= sizeof(WCHAR
);
633 r
= IStream_Write( stm
, str
, len
, &count
);
640 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR filename
)
645 FIXME("writing empty location info\n");
647 memset( &loc
, 0, sizeof(loc
) );
648 loc
.dwTotalSize
= sizeof(loc
) - sizeof(loc
.dwTotalSize
);
650 /* FIXME: fill this in */
652 return IStream_Write( stm
, &loc
, loc
.dwTotalSize
, &count
);
655 /************************************************************************
656 * IPersistStream_Save (IPersistStream)
658 * FIXME: makes assumptions about byte order
660 static HRESULT WINAPI
IPersistStream_fnSave(
661 IPersistStream
* iface
,
665 static const WCHAR wOpen
[] = {'o','p','e','n',0};
668 WCHAR exePath
[MAX_PATH
];
672 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
674 TRACE("(%p) %p %x\n", This
, stm
, fClearDirty
);
680 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, MAX_PATH
, NULL
, NULL
, NULL
, NULL
);
682 * windows can create lnk files to executables that do not exist yet
683 * so if the executable does not exist the just trust the path they
686 if( !*exePath
) strcpyW(exePath
,This
->sPath
);
689 /* if there's no PIDL, generate one */
690 if( ! This
->pPidl
) This
->pPidl
= ILCreateFromPathW(exePath
);
692 memset(&header
, 0, sizeof(header
));
693 header
.dwSize
= sizeof(header
);
694 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
696 header
.wHotKey
= This
->wHotKey
;
697 header
.nIcon
= This
->iIcoNdx
;
698 header
.dwFlags
= SCF_UNICODE
; /* strings are in unicode */
699 header
.dwFlags
|= SCF_NORMAL
; /* how do we determine this ? */
701 header
.dwFlags
|= SCF_PIDL
;
702 if( This
->sDescription
)
703 header
.dwFlags
|= SCF_DESCRIPTION
;
705 header
.dwFlags
|= SCF_WORKDIR
;
707 header
.dwFlags
|= SCF_ARGS
;
709 header
.dwFlags
|= SCF_CUSTOMICON
;
711 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
712 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
713 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
715 /* write the Shortcut header */
716 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
719 ERR("Write failed at %d\n",__LINE__
);
723 TRACE("Writing pidl \n");
725 /* write the PIDL to the shortcut */
728 r
= ILSaveToStream( stm
, This
->pPidl
);
731 ERR("Failed to write PIDL at %d\n",__LINE__
);
736 Stream_WriteLocationInfo( stm
, exePath
);
738 TRACE("Description = %s\n", debugstr_w(This
->sDescription
));
739 if( This
->sDescription
)
740 r
= Stream_WriteString( stm
, This
->sDescription
);
743 r
= Stream_WriteString( stm
, This
->sPathRel
);
746 r
= Stream_WriteString( stm
, This
->sWorkDir
);
749 r
= Stream_WriteString( stm
, This
->sArgs
);
752 r
= Stream_WriteString( stm
, This
->sIcoPath
);
757 /************************************************************************
758 * IPersistStream_GetSizeMax (IPersistStream)
760 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
761 IPersistStream
* iface
,
762 ULARGE_INTEGER
* pcbSize
)
764 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
766 TRACE("(%p)\n", This
);
771 static IPersistStreamVtbl psvt
=
773 IPersistStream_fnQueryInterface
,
774 IPersistStream_fnAddRef
,
775 IPersistStream_fnRelease
,
776 IPersistStream_fnGetClassID
,
777 IPersistStream_fnIsDirty
,
778 IPersistStream_fnLoad
,
779 IPersistStream_fnSave
,
780 IPersistStream_fnGetSizeMax
783 /**************************************************************************
784 * IShellLink_Constructor
786 HRESULT WINAPI
IShellLink_Constructor (
787 IUnknown
* pUnkOuter
,
793 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
797 if(pUnkOuter
) return CLASS_E_NOAGGREGATION
;
798 sl
= (IShellLinkImpl
*) LocalAlloc(GMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
799 if (!sl
) return E_OUTOFMEMORY
;
803 sl
->lpvtblw
= &slvtw
;
804 sl
->lpvtblPersistFile
= &pfvt
;
805 sl
->lpvtblPersistStream
= &psvt
;
806 sl
->iShowCmd
= SW_SHOWNORMAL
;
809 TRACE("(%p)->()\n",sl
);
811 if (IsEqualIID(riid
, &IID_IUnknown
) ||
812 IsEqualIID(riid
, &IID_IShellLinkA
))
814 else if (IsEqualIID(riid
, &IID_IShellLinkW
))
815 *ppv
= &(sl
->lpvtblw
);
817 LocalFree((HLOCAL
)sl
);
818 ERR("E_NOINTERFACE\n");
819 return E_NOINTERFACE
;
826 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
828 HANDLE hfile
= CreateFileW(path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
830 if (hfile
!= INVALID_HANDLE_VALUE
) {
837 /**************************************************************************
838 * ShellLink_UpdatePath
839 * update absolute path in sPath using relative path in sPathRel
841 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
843 if (!path
|| !psPath
)
846 if (!*psPath
&& sPathRel
) {
847 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
850 /* first try if [directory of link file] + [relative path] finds an existing file */
852 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
855 lstrcpyW(final
, sPathRel
);
859 if (SHELL_ExistsFileW(buffer
)) {
860 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
861 lstrcpyW(abs_path
, buffer
);
863 /* try if [working directory] + [relative path] finds an existing file */
865 lstrcpyW(buffer
, sWorkDir
);
866 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
868 if (SHELL_ExistsFileW(buffer
))
869 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
870 lstrcpyW(abs_path
, buffer
);
874 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
876 lstrcpyW(abs_path
, sPathRel
);
878 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
880 return E_OUTOFMEMORY
;
882 lstrcpyW(*psPath
, abs_path
);
888 /**************************************************************************
889 * IShellLink_ConstructFromFile
891 HRESULT WINAPI
IShellLink_ConstructFromFile (
900 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
907 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
910 WCHAR path
[MAX_PATH
];
912 if (SHGetPathFromIDListW(pidl
, path
))
913 hr
= IPersistFile_Load(ppf
, path
, 0);
918 *ppv
= (IUnknown
*) psl
;
920 IPersistFile_Release(ppf
);
924 IShellLinkW_Release(psl
);
930 /**************************************************************************
931 * IShellLinkA_QueryInterface
933 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
935 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
937 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
941 if(IsEqualIID(riid
, &IID_IUnknown
) ||
942 IsEqualIID(riid
, &IID_IShellLinkA
))
946 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
948 *ppvObj
= (IShellLinkW
*)&(This
->lpvtblw
);
950 else if(IsEqualIID(riid
, &IID_IPersistFile
))
952 *ppvObj
= (IPersistFile
*)&(This
->lpvtblPersistFile
);
954 else if(IsEqualIID(riid
, &IID_IPersistStream
))
956 *ppvObj
= (IPersistStream
*)&(This
->lpvtblPersistStream
);
961 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
962 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
965 TRACE("-- Interface: E_NOINTERFACE\n");
966 return E_NOINTERFACE
;
968 /******************************************************************************
971 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
973 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
975 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
977 return ++(This
->ref
);
979 /******************************************************************************
980 * IShellLinkA_Release
982 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
984 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
986 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
991 TRACE("-- destroying IShellLink(%p)\n",This
);
994 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
997 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1000 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1002 if (This
->sDescription
)
1003 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1006 HeapFree(GetProcessHeap(),0,This
->sPath
);
1009 ILFree(This
->pPidl
);
1011 LocalFree((HANDLE
)This
);
1016 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1017 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1019 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1021 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1022 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1027 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1028 pszFile
, cchMaxPath
, NULL
, NULL
);
1033 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1035 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1037 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1039 *ppidl
= ILClone(This
->pPidl
);
1044 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1046 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1048 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1051 ILFree(This
->pPidl
);
1052 This
->pPidl
= ILClone (pidl
);
1053 This
->bDirty
= TRUE
;
1058 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1060 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1062 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1066 if( This
->sDescription
)
1067 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1068 pszName
, cchMaxName
, NULL
, NULL
);
1072 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1074 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1076 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1078 if (This
->sDescription
)
1079 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1080 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1081 if ( !This
->sDescription
)
1082 return E_OUTOFMEMORY
;
1084 This
->bDirty
= TRUE
;
1089 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1091 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1093 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1097 if( This
->sWorkDir
)
1098 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1099 pszDir
, cchMaxPath
, NULL
, NULL
);
1104 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1106 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1108 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1111 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1112 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1113 if ( !This
->sWorkDir
)
1114 return E_OUTOFMEMORY
;
1116 This
->bDirty
= TRUE
;
1121 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1123 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1125 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1130 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1131 pszArgs
, cchMaxPath
, NULL
, NULL
);
1136 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1138 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1140 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1143 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1144 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1146 return E_OUTOFMEMORY
;
1148 This
->bDirty
= TRUE
;
1153 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1155 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1157 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1159 *pwHotkey
= This
->wHotKey
;
1164 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1166 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1168 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1170 This
->wHotKey
= wHotkey
;
1171 This
->bDirty
= TRUE
;
1176 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1178 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1180 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1181 *piShowCmd
= This
->iShowCmd
;
1185 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1187 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1189 TRACE("(%p) %d\n",This
, iShowCmd
);
1191 This
->iShowCmd
= iShowCmd
;
1192 This
->bDirty
= TRUE
;
1197 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1199 LPCITEMIDLIST pidlLast
;
1201 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1203 if (SUCCEEDED(hr
)) {
1206 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1208 if (SUCCEEDED(hr
)) {
1209 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1211 IExtractIconA_Release(pei
);
1214 IShellFolder_Release(psf
);
1220 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1222 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1224 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1229 if (This
->sIcoPath
) {
1230 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1231 *piIcon
= This
->iIcoNdx
;
1235 if (This
->pPidl
|| This
->sPath
) {
1238 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1240 if (SUCCEEDED(hr
)) {
1241 /* first look for an icon using the PIDL (if present) */
1243 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1247 /* if we couldn't find an icon yet, look for it using the file system path */
1248 if (FAILED(hr
) && This
->sPath
) {
1251 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1253 if (SUCCEEDED(hr
)) {
1254 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1260 IShellFolder_Release(pdsk
);
1268 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1270 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1272 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1275 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1276 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1277 if ( !This
->sIcoPath
)
1278 return E_OUTOFMEMORY
;
1280 This
->iIcoNdx
= iIcon
;
1281 This
->bDirty
= TRUE
;
1286 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1288 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1290 FIXME("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1293 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1294 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1295 This
->bDirty
= TRUE
;
1297 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1300 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1302 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1304 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1308 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1310 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1312 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1315 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1316 This
->sPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1318 return E_OUTOFMEMORY
;
1320 This
->bDirty
= TRUE
;
1325 /**************************************************************************
1326 * IShellLink Implementation
1329 static IShellLinkAVtbl slvt
=
1331 IShellLinkA_fnQueryInterface
,
1332 IShellLinkA_fnAddRef
,
1333 IShellLinkA_fnRelease
,
1334 IShellLinkA_fnGetPath
,
1335 IShellLinkA_fnGetIDList
,
1336 IShellLinkA_fnSetIDList
,
1337 IShellLinkA_fnGetDescription
,
1338 IShellLinkA_fnSetDescription
,
1339 IShellLinkA_fnGetWorkingDirectory
,
1340 IShellLinkA_fnSetWorkingDirectory
,
1341 IShellLinkA_fnGetArguments
,
1342 IShellLinkA_fnSetArguments
,
1343 IShellLinkA_fnGetHotkey
,
1344 IShellLinkA_fnSetHotkey
,
1345 IShellLinkA_fnGetShowCmd
,
1346 IShellLinkA_fnSetShowCmd
,
1347 IShellLinkA_fnGetIconLocation
,
1348 IShellLinkA_fnSetIconLocation
,
1349 IShellLinkA_fnSetRelativePath
,
1350 IShellLinkA_fnResolve
,
1351 IShellLinkA_fnSetPath
1355 /**************************************************************************
1356 * IShellLinkW_fnQueryInterface
1358 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1359 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1361 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1363 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
1366 /******************************************************************************
1367 * IShellLinkW_fnAddRef
1369 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1371 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1373 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1375 return IShellLinkA_AddRef((IShellLinkA
*)This
);
1377 /******************************************************************************
1378 * IShellLinkW_fnRelease
1381 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1383 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1385 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1387 return IShellLinkA_Release((IShellLinkA
*)This
);
1390 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1392 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1394 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This
, pszFile
, cchMaxPath
, pfd
, fFlags
);
1398 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1403 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1405 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1407 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1410 *ppidl
= ILClone( This
->pPidl
);
1417 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1419 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1421 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1424 ILFree( This
->pPidl
);
1425 This
->pPidl
= ILClone( pidl
);
1429 This
->bDirty
= TRUE
;
1434 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1436 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1438 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1442 if( This
->sDescription
)
1443 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1448 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1450 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1452 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1454 if (This
->sDescription
)
1455 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1456 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1457 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1458 if ( !This
->sDescription
)
1459 return E_OUTOFMEMORY
;
1461 lstrcpyW( This
->sDescription
, pszName
);
1462 This
->bDirty
= TRUE
;
1467 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1469 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1471 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1475 if( This
->sWorkDir
)
1476 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1481 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1483 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1485 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1488 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1489 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1490 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1491 if ( !This
->sWorkDir
)
1492 return E_OUTOFMEMORY
;
1493 lstrcpyW( This
->sWorkDir
, pszDir
);
1494 This
->bDirty
= TRUE
;
1499 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1501 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1503 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1508 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1513 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1515 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1517 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1520 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1521 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1522 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1524 return E_OUTOFMEMORY
;
1525 lstrcpyW( This
->sArgs
, pszArgs
);
1526 This
->bDirty
= TRUE
;
1531 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1533 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1535 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1537 *pwHotkey
=This
->wHotKey
;
1542 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1544 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1546 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1548 This
->wHotKey
= wHotkey
;
1549 This
->bDirty
= TRUE
;
1554 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1556 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1558 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1560 *piShowCmd
= This
->iShowCmd
;
1565 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1567 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1569 This
->iShowCmd
= iShowCmd
;
1570 This
->bDirty
= TRUE
;
1575 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1577 LPCITEMIDLIST pidlLast
;
1579 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1581 if (SUCCEEDED(hr
)) {
1584 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1586 if (SUCCEEDED(hr
)) {
1587 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1589 IExtractIconW_Release(pei
);
1592 IShellFolder_Release(psf
);
1598 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1600 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1602 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1607 if (This
->sIcoPath
) {
1608 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1609 *piIcon
= This
->iIcoNdx
;
1613 if (This
->pPidl
|| This
->sPath
) {
1616 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1618 if (SUCCEEDED(hr
)) {
1619 /* first look for an icon using the PIDL (if present) */
1621 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1625 /* if we couldn't find an icon yet, look for it using the file system path */
1626 if (FAILED(hr
) && This
->sPath
) {
1629 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1631 if (SUCCEEDED(hr
)) {
1632 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1638 IShellFolder_Release(pdsk
);
1646 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1648 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1650 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1653 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1654 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1655 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1656 if ( !This
->sIcoPath
)
1657 return E_OUTOFMEMORY
;
1658 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1660 This
->iIcoNdx
= iIcon
;
1661 This
->bDirty
= TRUE
;
1666 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1668 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1670 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1673 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1674 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1675 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1676 if ( !This
->sPathRel
)
1677 return E_OUTOFMEMORY
;
1678 lstrcpyW( This
->sPathRel
, pszPathRel
);
1679 This
->bDirty
= TRUE
;
1681 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1684 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1686 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1688 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1693 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
1695 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1697 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
1700 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1701 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
1702 (lstrlenW( pszFile
)+1) * sizeof (WCHAR
) );
1704 return E_OUTOFMEMORY
;
1706 lstrcpyW( This
->sPath
, pszFile
);
1707 This
->bDirty
= TRUE
;
1712 /**************************************************************************
1713 * IShellLinkW Implementation
1716 static IShellLinkWVtbl slvtw
=
1718 IShellLinkW_fnQueryInterface
,
1719 IShellLinkW_fnAddRef
,
1720 IShellLinkW_fnRelease
,
1721 IShellLinkW_fnGetPath
,
1722 IShellLinkW_fnGetIDList
,
1723 IShellLinkW_fnSetIDList
,
1724 IShellLinkW_fnGetDescription
,
1725 IShellLinkW_fnSetDescription
,
1726 IShellLinkW_fnGetWorkingDirectory
,
1727 IShellLinkW_fnSetWorkingDirectory
,
1728 IShellLinkW_fnGetArguments
,
1729 IShellLinkW_fnSetArguments
,
1730 IShellLinkW_fnGetHotkey
,
1731 IShellLinkW_fnSetHotkey
,
1732 IShellLinkW_fnGetShowCmd
,
1733 IShellLinkW_fnSetShowCmd
,
1734 IShellLinkW_fnGetIconLocation
,
1735 IShellLinkW_fnSetIconLocation
,
1736 IShellLinkW_fnSetRelativePath
,
1737 IShellLinkW_fnResolve
,
1738 IShellLinkW_fnSetPath