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
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"
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_UNC 0x80
71 //#define SCF_UNICODE 0x1000
72 #define SCF_UNICODE 0x80
76 typedef struct _LINK_HEADER
78 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
79 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
80 DWORD dwFlags
; /* 0x14 describes elements following */
81 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
82 FILETIME Time1
; /* 0x1c */
83 FILETIME Time2
; /* 0x24 */
84 FILETIME Time3
; /* 0x2c */
85 DWORD dwFileLength
; /* 0x34 File length */
86 DWORD nIcon
; /* 0x38 icon number */
87 DWORD fStartup
; /* 0x3c startup type */
88 DWORD wHotKey
; /* 0x40 hotkey */
89 DWORD Unknown5
; /* 0x44 */
90 DWORD Unknown6
; /* 0x48 */
91 } LINK_HEADER
, * PLINK_HEADER
;
93 #define SHLINK_LOCAL 0
94 #define SHLINK_REMOTE 1
96 typedef struct _LOCATION_INFO
102 DWORD dwLocalPathOfs
;
103 DWORD dwNetworkVolTableOfs
;
104 DWORD dwFinalPathOfs
;
107 typedef struct _LOCAL_VOLUME_INFO
117 static ICOM_VTABLE(IShellLinkA
) slvt
;
118 static ICOM_VTABLE(IShellLinkW
) slvtw
;
119 static ICOM_VTABLE(IPersistFile
) pfvt
;
120 static ICOM_VTABLE(IPersistStream
) psvt
;
122 /* IShellLink Implementation */
126 ICOM_VFIELD(IShellLinkA
);
129 ICOM_VTABLE(IShellLinkW
)* lpvtblw
;
130 ICOM_VTABLE(IPersistFile
)* lpvtblPersistFile
;
131 ICOM_VTABLE(IPersistStream
)* lpvtblPersistStream
;
133 /* data structures according to the informations in the link */
152 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
153 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
155 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
156 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
158 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
159 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
160 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset)
163 /* strdup on the process heap */
164 inline static LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
166 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
167 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
170 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
175 /**************************************************************************
176 * IPersistFile_QueryInterface
178 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
183 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
185 TRACE("(%p)\n",This
);
187 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
190 /******************************************************************************
191 * IPersistFile_AddRef
193 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
195 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
197 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
199 return IShellLinkA_AddRef((IShellLinkA
*)This
);
201 /******************************************************************************
202 * IPersistFile_Release
204 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
206 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
208 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
210 return IShellLinkA_Release((IShellLinkA
*)This
);
213 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
215 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
216 FIXME("(%p)\n",This
);
219 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
221 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
223 FIXME("(%p)\n",This
);
230 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
232 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
233 _IPersistStream_From_ICOM_THIS(IPersistStream
, This
);
237 TRACE("(%p, %s)\n",This
, debugstr_w(pszFileName
));
239 r
= CreateStreamOnFile(pszFileName
, dwMode
, &stm
);
242 r
= IPersistStream_Load(StreamThis
, stm
);
243 IStream_Release( stm
);
249 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
251 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_From_ICOM_THIS(IPersistStream
, This
);
288 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
290 if (!pszFileName
|| !This
->sPath
)
291 return ERROR_UNKNOWN
;
293 r
= CreateStreamOnFile(pszFileName
, STGM_READWRITE
| STGM_CREATE
, &stm
);
296 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
297 IStream_Release( stm
);
300 StartLinkProcessor( pszFileName
);
303 DeleteFileW( pszFileName
);
304 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
311 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
313 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
314 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
317 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
319 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
320 FIXME("(%p)\n",This
);
324 static ICOM_VTABLE(IPersistFile
) pfvt
=
326 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
327 IPersistFile_fnQueryInterface
,
328 IPersistFile_fnAddRef
,
329 IPersistFile_fnRelease
,
330 IPersistFile_fnGetClassID
,
331 IPersistFile_fnIsDirty
,
334 IPersistFile_fnSaveCompleted
,
335 IPersistFile_fnGetCurFile
338 /************************************************************************
339 * IPersistStream_QueryInterface
341 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
342 IPersistStream
* iface
,
346 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
348 TRACE("(%p)\n",This
);
350 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvoid
);
353 /************************************************************************
354 * IPersistStream_Release
356 static ULONG WINAPI
IPersistStream_fnRelease(
357 IPersistStream
* iface
)
359 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
361 TRACE("(%p)\n",This
);
363 return IShellLinkA_Release((IShellLinkA
*)This
);
366 /************************************************************************
367 * IPersistStream_AddRef
369 static ULONG WINAPI
IPersistStream_fnAddRef(
370 IPersistStream
* iface
)
372 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
374 TRACE("(%p)\n",This
);
376 return IShellLinkA_AddRef((IShellLinkA
*)This
);
379 /************************************************************************
380 * IPersistStream_GetClassID
383 static HRESULT WINAPI
IPersistStream_fnGetClassID(
384 IPersistStream
* iface
,
387 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
389 TRACE("(%p)\n", This
);
394 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
399 /************************************************************************
400 * IPersistStream_IsDirty (IPersistStream)
402 static HRESULT WINAPI
IPersistStream_fnIsDirty(
403 IPersistStream
* iface
)
405 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
407 TRACE("(%p)\n", This
);
413 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
424 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
425 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
429 len
*= sizeof (WCHAR
);
431 TRACE("reading %d\n", len
);
432 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
434 return E_OUTOFMEMORY
;
436 r
= IStream_Read(stm
, temp
, len
, &count
);
437 if( FAILED (r
) || ( count
!= len
) )
439 HeapFree( GetProcessHeap(), 0, temp
);
443 TRACE("read %s\n", debugstr_an(temp
,len
));
445 /* convert to unicode if necessary */
448 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
449 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
451 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
452 HeapFree( GetProcessHeap(), 0, temp
);
466 static HRESULT
Stream_LoadLocation( IStream
* stm
)
475 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
478 if( count
!= sizeof(loc
->dwTotalSize
) )
481 loc
= HeapAlloc( GetProcessHeap(), 0, size
);
483 return E_OUTOFMEMORY
;
485 r
= IStream_Read( stm
, &loc
->dwHeaderSize
, size
-sizeof(size
), &count
);
488 if( count
!= (size
- sizeof(size
)) )
493 loc
->dwTotalSize
= size
;
495 TRACE("Read %ld bytes\n",count
);
497 /* FIXME: do something useful with it */
498 HeapFree( GetProcessHeap(), 0, loc
);
502 HeapFree( GetProcessHeap(), 0, loc
);
506 /************************************************************************
507 * IPersistStream_Load (IPersistStream)
509 static HRESULT WINAPI
IPersistStream_fnLoad(
510 IPersistStream
* iface
,
516 WCHAR sTemp
[MAX_PATH
];
519 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
521 TRACE("(%p)(%p)\n", This
, stm
);
524 return STG_E_INVALIDPOINTER
;
527 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
531 if( dwBytesRead
!= sizeof(hdr
))
533 if( hdr
.dwSize
!= sizeof(hdr
))
535 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
538 if( hdr
.dwFlags
& SCF_PIDL
)
540 r
= ILLoadFromStream( stm
, &This
->pPidl
);
544 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
545 This
->iIcoNdx
= hdr
.nIcon
;
546 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
547 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
548 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
550 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time1
, NULL
, sTemp
, 256);
551 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
552 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time2
, NULL
, sTemp
, 256);
553 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
554 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time3
, NULL
, sTemp
, 256);
555 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
558 if( hdr
.dwFlags
& SCF_NORMAL
)
559 r
= Stream_LoadLocation( stm
);
562 unicode
= hdr
.dwFlags
& SCF_UNICODE
;
563 if( hdr
.dwFlags
& SCF_DESCRIPTION
)
565 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
566 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
571 if( hdr
.dwFlags
& SCF_RELATIVE
)
573 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
574 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
579 if( hdr
.dwFlags
& SCF_WORKDIR
)
581 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
582 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
587 if( hdr
.dwFlags
& SCF_ARGS
)
589 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
590 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
595 if( hdr
.dwFlags
& SCF_CUSTOMICON
)
597 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
598 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
612 /************************************************************************
615 * Helper function for IPersistStream_Save. Writes a unicode string
616 * with terminating nul byte to a stream, preceded by the its length.
618 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
620 USHORT len
= lstrlenW( str
) + 1;
624 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
628 len
*= sizeof(WCHAR
);
630 r
= IStream_Write( stm
, str
, len
, &count
);
637 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR filename
)
642 FIXME("writing empty location info\n");
644 memset( &loc
, 0, sizeof(loc
) );
645 loc
.dwTotalSize
= sizeof(loc
) - sizeof(loc
.dwTotalSize
);
647 /* FIXME: fill this in */
649 return IStream_Write( stm
, &loc
, loc
.dwTotalSize
, &count
);
652 /************************************************************************
653 * IPersistStream_Save (IPersistStream)
655 * FIXME: makes assumptions about byte order
657 static HRESULT WINAPI
IPersistStream_fnSave(
658 IPersistStream
* iface
,
662 static const WCHAR wOpen
[] = {'o','p','e','n',0};
665 WCHAR exePath
[MAX_PATH
];
669 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
671 TRACE("(%p) %p %x\n", This
, stm
, fClearDirty
);
676 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, NULL
, NULL
, NULL
, NULL
);
678 /* if there's no PIDL, generate one */
684 This
->pPidl
= ILCreateFromPathW(exePath
);
687 memset(&header
, 0, sizeof(header
));
688 header
.dwSize
= sizeof(header
);
689 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
691 header
.wHotKey
= This
->wHotKey
;
692 header
.nIcon
= This
->iIcoNdx
;
693 header
.dwFlags
= SCF_UNICODE
; /* strings are in unicode */
694 header
.dwFlags
|= SCF_NORMAL
; /* how do we determine this ? */
696 header
.dwFlags
|= SCF_PIDL
;
697 if( This
->sDescription
)
698 header
.dwFlags
|= SCF_DESCRIPTION
;
700 header
.dwFlags
|= SCF_WORKDIR
;
702 header
.dwFlags
|= SCF_ARGS
;
704 header
.dwFlags
|= SCF_CUSTOMICON
;
706 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
707 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
708 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
710 /* write the Shortcut header */
711 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
714 ERR("Write failed at %d\n",__LINE__
);
718 TRACE("Writing pidl \n");
720 /* write the PIDL to the shortcut */
723 r
= ILSaveToStream( stm
, This
->pPidl
);
726 ERR("Failed to write PIDL at %d\n",__LINE__
);
731 Stream_WriteLocationInfo( stm
, exePath
);
733 TRACE("Description = %s\n", debugstr_w(This
->sDescription
));
734 if( This
->sDescription
)
735 r
= Stream_WriteString( stm
, This
->sDescription
);
738 r
= Stream_WriteString( stm
, This
->sPathRel
);
741 r
= Stream_WriteString( stm
, This
->sWorkDir
);
744 r
= Stream_WriteString( stm
, This
->sArgs
);
747 r
= Stream_WriteString( stm
, This
->sIcoPath
);
752 /************************************************************************
753 * IPersistStream_GetSizeMax (IPersistStream)
755 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
756 IPersistStream
* iface
,
757 ULARGE_INTEGER
* pcbSize
)
759 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
761 TRACE("(%p)\n", This
);
766 static ICOM_VTABLE(IPersistStream
) psvt
=
768 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
769 IPersistStream_fnQueryInterface
,
770 IPersistStream_fnAddRef
,
771 IPersistStream_fnRelease
,
772 IPersistStream_fnGetClassID
,
773 IPersistStream_fnIsDirty
,
774 IPersistStream_fnLoad
,
775 IPersistStream_fnSave
,
776 IPersistStream_fnGetSizeMax
779 /**************************************************************************
780 * IShellLink_Constructor
782 HRESULT WINAPI
IShellLink_Constructor (
783 IUnknown
* pUnkOuter
,
789 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
793 if(pUnkOuter
) return CLASS_E_NOAGGREGATION
;
794 sl
= (IShellLinkImpl
*) LocalAlloc(GMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
795 if (!sl
) return E_OUTOFMEMORY
;
799 sl
->lpvtblw
= &slvtw
;
800 sl
->lpvtblPersistFile
= &pfvt
;
801 sl
->lpvtblPersistStream
= &psvt
;
802 sl
->iShowCmd
= SW_SHOWNORMAL
;
805 TRACE("(%p)->()\n",sl
);
807 if (IsEqualIID(riid
, &IID_IUnknown
) ||
808 IsEqualIID(riid
, &IID_IShellLinkA
))
810 else if (IsEqualIID(riid
, &IID_IShellLinkW
))
811 *ppv
= &(sl
->lpvtblw
);
813 LocalFree((HLOCAL
)sl
);
814 ERR("E_NOINTERFACE\n");
815 return E_NOINTERFACE
;
821 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
823 HANDLE hfile
= CreateFileW(path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
825 if (hfile
!= INVALID_HANDLE_VALUE
) {
832 /**************************************************************************
833 * SHELL_ShellLink_UpdatePath
834 * update absolute path in sPath using relative path in sPathRel
836 static HRESULT
SHELL_ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
838 if (!path
|| !psPath
)
841 if (!*psPath
&& sPathRel
) {
842 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
844 /* first try if [directory of link file] + [relative path] finds an existing file */
846 LPWSTR last_slash
= NULL
;
847 LPWSTR dest
= buffer
;
850 /* copy path without file name to buffer */
852 if (*src
=='/' || *src
=='\\')
858 lstrcpyW(last_slash
? last_slash
+1: buffer
, sPathRel
);
862 if (SHELL_ExistsFileW(buffer
)) {
863 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
864 lstrcpyW(abs_path
, buffer
);
866 /* try if [working directory] + [relative path] finds an existing file */
868 lstrcpyW(buffer
, sWorkDir
);
869 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
871 if (SHELL_ExistsFileW(buffer
))
872 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
873 lstrcpyW(abs_path
, buffer
);
877 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
879 lstrcpyW(abs_path
, sPathRel
);
881 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
883 return E_OUTOFMEMORY
;
885 lstrcpyW(*psPath
, abs_path
);
891 /**************************************************************************
892 * IShellLink_ConstructFromFile
894 HRESULT WINAPI
IShellLink_ConstructFromFile (
903 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
910 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
913 WCHAR path
[MAX_PATH
];
915 if (SHGetPathFromIDListW(pidl
, path
)) {
916 hr
= IPersistFile_Load(ppf
, path
, 0);
919 *ppv
= (IUnknown
*) psl
;
922 The following code is here, not in IPersistStream_fnLoad() because
923 to be able to convert the relative path into the absolute path,
924 we need to know the path of the shell link file.
926 if (IsEqualIID(riid
, &IID_IShellLinkW
)) {
927 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, psl
);
929 hr
= SHELL_ShellLink_UpdatePath(This
->sPathRel
, path
, This
->sWorkDir
, &This
->sPath
);
931 ICOM_THIS(IShellLinkImpl
, psl
);
933 hr
= SHELL_ShellLink_UpdatePath(This
->sPathRel
, path
, This
->sWorkDir
, &This
->sPath
);
938 IPersistFile_Release(ppf
);
942 IShellLinkW_Release(psl
);
948 /**************************************************************************
949 * IShellLinkA_QueryInterface
951 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
953 ICOM_THIS(IShellLinkImpl
, iface
);
955 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
959 if(IsEqualIID(riid
, &IID_IUnknown
) ||
960 IsEqualIID(riid
, &IID_IShellLinkA
))
964 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
966 *ppvObj
= (IShellLinkW
*)&(This
->lpvtblw
);
968 else if(IsEqualIID(riid
, &IID_IPersistFile
))
970 *ppvObj
= (IPersistFile
*)&(This
->lpvtblPersistFile
);
972 else if(IsEqualIID(riid
, &IID_IPersistStream
))
974 *ppvObj
= (IPersistStream
*)&(This
->lpvtblPersistStream
);
979 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
980 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
983 TRACE("-- Interface: E_NOINTERFACE\n");
984 return E_NOINTERFACE
;
987 /******************************************************************************
990 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
992 ICOM_THIS(IShellLinkImpl
, iface
);
994 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
996 return ++(This
->ref
);
999 /******************************************************************************
1000 * IShellLinkA_Release
1002 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1004 ICOM_THIS(IShellLinkImpl
, iface
);
1006 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1011 TRACE("-- destroying IShellLink(%p)\n",This
);
1014 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1017 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1020 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1022 if (This
->sDescription
)
1023 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1026 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1029 ILFree(This
->pPidl
);
1031 LocalFree((HANDLE
)This
);
1036 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1037 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1039 ICOM_THIS(IShellLinkImpl
, iface
);
1041 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1042 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1047 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1048 pszFile
, cchMaxPath
, NULL
, NULL
);
1052 FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1059 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1061 ICOM_THIS(IShellLinkImpl
, iface
);
1063 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1065 *ppidl
= ILClone(This
->pPidl
);
1070 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1072 ICOM_THIS(IShellLinkImpl
, iface
);
1074 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1077 ILFree(This
->pPidl
);
1079 This
->pPidl
= ILClone (pidl
);
1080 This
->bDirty
= TRUE
;
1085 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1087 ICOM_THIS(IShellLinkImpl
, iface
);
1089 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1093 if( This
->sDescription
)
1094 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1095 pszName
, cchMaxName
, NULL
, NULL
);
1099 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1101 ICOM_THIS(IShellLinkImpl
, iface
);
1103 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1105 if (This
->sDescription
)
1106 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1107 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1108 if ( !This
->sDescription
)
1109 return E_OUTOFMEMORY
;
1111 This
->bDirty
= TRUE
;
1116 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1118 ICOM_THIS(IShellLinkImpl
, iface
);
1120 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1124 if( This
->sWorkDir
)
1125 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1126 pszDir
, cchMaxPath
, NULL
, NULL
);
1131 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1133 ICOM_THIS(IShellLinkImpl
, iface
);
1135 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1138 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1139 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1140 if ( !This
->sWorkDir
)
1141 return E_OUTOFMEMORY
;
1143 This
->bDirty
= TRUE
;
1148 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1150 ICOM_THIS(IShellLinkImpl
, iface
);
1152 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1157 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1158 pszArgs
, cchMaxPath
, NULL
, NULL
);
1163 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1165 ICOM_THIS(IShellLinkImpl
, iface
);
1167 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1170 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1171 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1173 return E_OUTOFMEMORY
;
1175 This
->bDirty
= TRUE
;
1180 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1182 ICOM_THIS(IShellLinkImpl
, iface
);
1184 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1186 *pwHotkey
= This
->wHotKey
;
1191 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1193 ICOM_THIS(IShellLinkImpl
, iface
);
1195 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1197 This
->wHotKey
= wHotkey
;
1198 This
->bDirty
= TRUE
;
1203 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1205 ICOM_THIS(IShellLinkImpl
, iface
);
1207 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1208 *piShowCmd
= This
->iShowCmd
;
1212 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1214 ICOM_THIS(IShellLinkImpl
, iface
);
1216 TRACE("(%p) %d\n",This
, iShowCmd
);
1218 This
->iShowCmd
= iShowCmd
;
1219 This
->bDirty
= TRUE
;
1224 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1226 LPCITEMIDLIST pidlLast
;
1228 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1230 if (SUCCEEDED(hr
)) {
1233 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1235 if (SUCCEEDED(hr
)) {
1236 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1238 IExtractIconA_Release(pei
);
1241 IShellFolder_Release(psf
);
1247 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1249 ICOM_THIS(IShellLinkImpl
, iface
);
1251 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1256 if (This
->sIcoPath
) {
1257 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1258 *piIcon
= This
->iIcoNdx
;
1262 if (This
->pPidl
|| This
->sPath
) {
1265 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1267 if (SUCCEEDED(hr
)) {
1268 /* first look for an icon using the PIDL (if present) */
1270 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1274 /* if we couldn't find an icon yet, look for it using the file system path */
1275 if (FAILED(hr
) && This
->sPath
) {
1278 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1280 if (SUCCEEDED(hr
)) {
1281 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1287 IShellFolder_Release(pdsk
);
1295 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
, INT iIcon
)
1297 ICOM_THIS(IShellLinkImpl
, iface
);
1299 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1302 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1303 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1304 if ( !This
->sIcoPath
)
1305 return E_OUTOFMEMORY
;
1307 This
->iIcoNdx
= iIcon
;
1308 This
->bDirty
= TRUE
;
1313 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1315 ICOM_THIS(IShellLinkImpl
, iface
);
1317 FIXME("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1320 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1322 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1323 This
->bDirty
= TRUE
;
1325 return SHELL_ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1328 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1332 ICOM_THIS(IShellLinkImpl
, iface
);
1334 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1336 /*FIXME: use IResolveShellLink interface */
1338 if (!This
->sPath
&& This
->pPidl
) {
1339 WCHAR buffer
[MAX_PATH
];
1341 hr
= SHELL_GetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1343 if (SUCCEEDED(hr
) && *buffer
) {
1344 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1346 return E_OUTOFMEMORY
;
1348 lstrcpyW(This
->sPath
, buffer
);
1350 This
->bDirty
= TRUE
;
1352 hr
= S_OK
; /* don't report any error occured while just caching information */
1355 if (!This
->sIcoPath
&& This
->sPath
) {
1356 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1357 if (!This
->sIcoPath
)
1358 return E_OUTOFMEMORY
;
1360 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1363 This
->bDirty
= TRUE
;
1369 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1371 ICOM_THIS(IShellLinkImpl
, iface
);
1373 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1376 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1377 This
->sPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1379 return E_OUTOFMEMORY
;
1381 This
->bDirty
= TRUE
;
1386 /**************************************************************************
1387 * IShellLink Implementation
1390 static ICOM_VTABLE(IShellLinkA
) slvt
=
1392 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1393 IShellLinkA_fnQueryInterface
,
1394 IShellLinkA_fnAddRef
,
1395 IShellLinkA_fnRelease
,
1396 IShellLinkA_fnGetPath
,
1397 IShellLinkA_fnGetIDList
,
1398 IShellLinkA_fnSetIDList
,
1399 IShellLinkA_fnGetDescription
,
1400 IShellLinkA_fnSetDescription
,
1401 IShellLinkA_fnGetWorkingDirectory
,
1402 IShellLinkA_fnSetWorkingDirectory
,
1403 IShellLinkA_fnGetArguments
,
1404 IShellLinkA_fnSetArguments
,
1405 IShellLinkA_fnGetHotkey
,
1406 IShellLinkA_fnSetHotkey
,
1407 IShellLinkA_fnGetShowCmd
,
1408 IShellLinkA_fnSetShowCmd
,
1409 IShellLinkA_fnGetIconLocation
,
1410 IShellLinkA_fnSetIconLocation
,
1411 IShellLinkA_fnSetRelativePath
,
1412 IShellLinkA_fnResolve
,
1413 IShellLinkA_fnSetPath
1417 /**************************************************************************
1418 * IShellLinkW_fnQueryInterface
1420 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1421 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1423 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1425 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
1428 /******************************************************************************
1429 * IShellLinkW_fnAddRef
1431 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1433 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1435 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1437 return IShellLinkA_AddRef((IShellLinkA
*)This
);
1439 /******************************************************************************
1440 * IShellLinkW_fnRelease
1443 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1445 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1447 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1449 return IShellLinkA_Release((IShellLinkA
*)This
);
1452 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1454 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1456 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",
1457 This
, pszFile
, cchMaxPath
, pfd
, fFlags
);
1462 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1466 FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1473 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1475 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1477 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1480 *ppidl
= ILClone( This
->pPidl
);
1487 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1489 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1491 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1494 ILFree( This
->pPidl
);
1495 This
->pPidl
= ILClone( pidl
);
1499 This
->bDirty
= TRUE
;
1504 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1506 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1508 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1512 if( This
->sDescription
)
1513 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1518 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1520 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1522 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1524 if (This
->sDescription
)
1525 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1526 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1527 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1528 if ( !This
->sDescription
)
1529 return E_OUTOFMEMORY
;
1531 lstrcpyW( This
->sDescription
, pszName
);
1532 This
->bDirty
= TRUE
;
1537 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1539 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1541 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1545 if( This
->sWorkDir
)
1546 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1551 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1553 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1555 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1558 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1559 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1560 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1561 if ( !This
->sWorkDir
)
1562 return E_OUTOFMEMORY
;
1564 lstrcpyW( This
->sWorkDir
, pszDir
);
1565 This
->bDirty
= TRUE
;
1570 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1572 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1574 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1579 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1584 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1586 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1588 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1591 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1592 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1593 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1595 return E_OUTOFMEMORY
;
1597 lstrcpyW( This
->sArgs
, pszArgs
);
1598 This
->bDirty
= TRUE
;
1603 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1605 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1607 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1609 *pwHotkey
=This
->wHotKey
;
1614 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1616 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1618 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1620 This
->wHotKey
= wHotkey
;
1621 This
->bDirty
= TRUE
;
1626 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1628 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1630 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1632 *piShowCmd
= This
->iShowCmd
;
1637 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1639 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1641 This
->iShowCmd
= iShowCmd
;
1642 This
->bDirty
= TRUE
;
1647 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1649 LPCITEMIDLIST pidlLast
;
1651 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1653 if (SUCCEEDED(hr
)) {
1656 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1658 if (SUCCEEDED(hr
)) {
1659 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1661 IExtractIconW_Release(pei
);
1664 IShellFolder_Release(psf
);
1670 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1672 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1674 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1679 if (This
->sIcoPath
) {
1680 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1681 *piIcon
= This
->iIcoNdx
;
1685 if (This
->pPidl
|| This
->sPath
) {
1688 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1690 if (SUCCEEDED(hr
)) {
1691 /* first look for an icon using the PIDL (if present) */
1693 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1697 /* if we couldn't find an icon yet, look for it using the file system path */
1698 if (FAILED(hr
) && This
->sPath
) {
1701 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1703 if (SUCCEEDED(hr
)) {
1704 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1710 IShellFolder_Release(pdsk
);
1718 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
, INT iIcon
)
1720 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1722 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1725 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1726 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1727 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1728 if ( !This
->sIcoPath
)
1729 return E_OUTOFMEMORY
;
1730 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1732 This
->iIcoNdx
= iIcon
;
1733 This
->bDirty
= TRUE
;
1738 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1740 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1742 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1745 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1746 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1747 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1748 if ( !This
->sPathRel
)
1749 return E_OUTOFMEMORY
;
1751 lstrcpyW( This
->sPathRel
, pszPathRel
);
1752 This
->bDirty
= TRUE
;
1754 return SHELL_ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1757 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1761 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1763 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1765 /*FIXME: use IResolveShellLink interface */
1767 if (!This
->sPath
&& This
->pPidl
) {
1768 WCHAR buffer
[MAX_PATH
];
1770 hr
= SHELL_GetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1772 if (SUCCEEDED(hr
) && *buffer
) {
1773 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1775 return E_OUTOFMEMORY
;
1777 lstrcpyW(This
->sPath
, buffer
);
1779 This
->bDirty
= TRUE
;
1781 hr
= S_OK
; /* don't report any error occured while just caching information */
1784 if (!This
->sIcoPath
&& This
->sPath
) {
1785 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1786 if (!This
->sIcoPath
)
1787 return E_OUTOFMEMORY
;
1789 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1792 This
->bDirty
= TRUE
;
1798 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
1800 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1802 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
1805 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1806 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
1807 (lstrlenW( pszFile
)+1) * sizeof (WCHAR
) );
1809 return E_OUTOFMEMORY
;
1811 lstrcpyW( This
->sPath
, pszFile
);
1812 This
->bDirty
= TRUE
;
1817 /**************************************************************************
1818 * IShellLinkW Implementation
1821 static ICOM_VTABLE(IShellLinkW
) slvtw
=
1823 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1824 IShellLinkW_fnQueryInterface
,
1825 IShellLinkW_fnAddRef
,
1826 IShellLinkW_fnRelease
,
1827 IShellLinkW_fnGetPath
,
1828 IShellLinkW_fnGetIDList
,
1829 IShellLinkW_fnSetIDList
,
1830 IShellLinkW_fnGetDescription
,
1831 IShellLinkW_fnSetDescription
,
1832 IShellLinkW_fnGetWorkingDirectory
,
1833 IShellLinkW_fnSetWorkingDirectory
,
1834 IShellLinkW_fnGetArguments
,
1835 IShellLinkW_fnSetArguments
,
1836 IShellLinkW_fnGetHotkey
,
1837 IShellLinkW_fnSetHotkey
,
1838 IShellLinkW_fnGetShowCmd
,
1839 IShellLinkW_fnSetShowCmd
,
1840 IShellLinkW_fnGetIconLocation
,
1841 IShellLinkW_fnSetIconLocation
,
1842 IShellLinkW_fnSetRelativePath
,
1843 IShellLinkW_fnResolve
,
1844 IShellLinkW_fnSetPath