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"
57 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
59 /* link file formats */
61 /* flag1: lnk elements: simple link has 0x0B */
64 #define SCF_DESCRIPTION 4
65 #define SCF_RELATIVE 8
66 #define SCF_WORKDIR 0x10
68 #define SCF_CUSTOMICON 0x40
69 //#define SCF_UNC 0x80
70 //#define SCF_UNICODE 0x1000
71 #define SCF_UNICODE 0x80
75 typedef struct _LINK_HEADER
77 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
78 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
79 DWORD dwFlags
; /* 0x14 describes elements following */
80 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
81 FILETIME Time1
; /* 0x1c */
82 FILETIME Time2
; /* 0x24 */
83 FILETIME Time3
; /* 0x2c */
84 DWORD dwFileLength
; /* 0x34 File length */
85 DWORD nIcon
; /* 0x38 icon number */
86 DWORD fStartup
; /* 0x3c startup type */
87 DWORD wHotKey
; /* 0x40 hotkey */
88 DWORD Unknown5
; /* 0x44 */
89 DWORD Unknown6
; /* 0x48 */
90 } LINK_HEADER
, * PLINK_HEADER
;
92 #define SHLINK_LOCAL 0
93 #define SHLINK_REMOTE 1
95 typedef struct _LOCATION_INFO
101 DWORD dwLocalPathOfs
;
102 DWORD dwNetworkVolTableOfs
;
103 DWORD dwFinalPathOfs
;
106 typedef struct _LOCAL_VOLUME_INFO
116 static ICOM_VTABLE(IShellLinkA
) slvt
;
117 static ICOM_VTABLE(IShellLinkW
) slvtw
;
118 static ICOM_VTABLE(IPersistFile
) pfvt
;
119 static ICOM_VTABLE(IPersistStream
) psvt
;
121 /* IShellLink Implementation */
125 ICOM_VFIELD(IShellLinkA
);
128 ICOM_VTABLE(IShellLinkW
)* lpvtblw
;
129 ICOM_VTABLE(IPersistFile
)* lpvtblPersistFile
;
130 ICOM_VTABLE(IPersistStream
)* lpvtblPersistStream
;
132 /* data structures according to the informations in the link */
151 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
152 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
154 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
155 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
157 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
158 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
159 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset)
162 /* strdup on the process heap */
163 inline static LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
165 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
166 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
169 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
174 /**************************************************************************
175 * IPersistFile_QueryInterface
177 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
182 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
184 TRACE("(%p)\n",This
);
186 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
189 /******************************************************************************
190 * IPersistFile_AddRef
192 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
194 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
196 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
198 return IShellLinkA_AddRef((IShellLinkA
*)This
);
200 /******************************************************************************
201 * IPersistFile_Release
203 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
205 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
207 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
209 return IShellLinkA_Release((IShellLinkA
*)This
);
212 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
214 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
215 FIXME("(%p)\n",This
);
218 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
220 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
222 FIXME("(%p)\n",This
);
229 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
231 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
232 _IPersistStream_From_ICOM_THIS(IPersistStream
, This
);
236 TRACE("(%p, %s)\n",This
, debugstr_w(pszFileName
));
238 r
= CreateStreamOnFile(pszFileName
, dwMode
, &stm
);
241 r
= IPersistStream_Load(StreamThis
, stm
);
242 IStream_Release( stm
);
248 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
250 const WCHAR szFormat
[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
251 ' ','-','r',' ','"','%','s','"',0 };
255 PROCESS_INFORMATION pi
;
257 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
258 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
262 wsprintfW( buffer
, szFormat
, szLink
);
264 TRACE("starting %s\n",debugstr_w(buffer
));
266 memset(&si
, 0, sizeof(si
));
268 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
270 /* wait for a while to throttle the creation of linker processes */
271 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
272 WARN("Timed out waiting for shell linker\n");
274 CloseHandle( pi
.hProcess
);
275 CloseHandle( pi
.hThread
);
280 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
282 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
283 _IPersistStream_From_ICOM_THIS(IPersistStream
, This
);
287 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
289 if (!pszFileName
|| !This
->sPath
)
290 return ERROR_UNKNOWN
;
292 r
= CreateStreamOnFile(pszFileName
, STGM_READWRITE
| STGM_CREATE
, &stm
);
295 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
296 IStream_Release( stm
);
299 StartLinkProcessor( pszFileName
);
302 DeleteFileW( pszFileName
);
303 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
310 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
312 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
313 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
316 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
318 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
319 FIXME("(%p)\n",This
);
323 static ICOM_VTABLE(IPersistFile
) pfvt
=
325 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
326 IPersistFile_fnQueryInterface
,
327 IPersistFile_fnAddRef
,
328 IPersistFile_fnRelease
,
329 IPersistFile_fnGetClassID
,
330 IPersistFile_fnIsDirty
,
333 IPersistFile_fnSaveCompleted
,
334 IPersistFile_fnGetCurFile
337 /************************************************************************
338 * IPersistStream_QueryInterface
340 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
341 IPersistStream
* iface
,
345 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
347 TRACE("(%p)\n",This
);
349 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvoid
);
352 /************************************************************************
353 * IPersistStream_Release
355 static ULONG WINAPI
IPersistStream_fnRelease(
356 IPersistStream
* iface
)
358 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
360 TRACE("(%p)\n",This
);
362 return IShellLinkA_Release((IShellLinkA
*)This
);
365 /************************************************************************
366 * IPersistStream_AddRef
368 static ULONG WINAPI
IPersistStream_fnAddRef(
369 IPersistStream
* iface
)
371 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
373 TRACE("(%p)\n",This
);
375 return IShellLinkA_AddRef((IShellLinkA
*)This
);
378 /************************************************************************
379 * IPersistStream_GetClassID
382 static HRESULT WINAPI
IPersistStream_fnGetClassID(
383 IPersistStream
* iface
,
386 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
388 TRACE("(%p)\n", This
);
393 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
398 /************************************************************************
399 * IPersistStream_IsDirty (IPersistStream)
401 static HRESULT WINAPI
IPersistStream_fnIsDirty(
402 IPersistStream
* iface
)
404 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
406 TRACE("(%p)\n", This
);
412 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
423 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
424 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
428 len
*= sizeof (WCHAR
);
430 TRACE("reading %d\n", len
);
431 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
433 return E_OUTOFMEMORY
;
435 r
= IStream_Read(stm
, temp
, len
, &count
);
436 if( FAILED (r
) || ( count
!= len
) )
438 HeapFree( GetProcessHeap(), 0, temp
);
442 TRACE("read %s\n", debugstr_an(temp
,len
));
444 /* convert to unicode if necessary */
447 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
448 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
450 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
451 HeapFree( GetProcessHeap(), 0, temp
);
465 static HRESULT
Stream_LoadLocation( IStream
* stm
)
474 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
477 if( count
!= sizeof(loc
->dwTotalSize
) )
480 loc
= HeapAlloc( GetProcessHeap(), 0, size
);
482 return E_OUTOFMEMORY
;
484 r
= IStream_Read( stm
, &loc
->dwHeaderSize
, size
-sizeof(size
), &count
);
487 if( count
!= (size
- sizeof(size
)) )
492 loc
->dwTotalSize
= size
;
494 TRACE("Read %ld bytes\n",count
);
496 /* FIXME: do something useful with it */
497 HeapFree( GetProcessHeap(), 0, loc
);
501 HeapFree( GetProcessHeap(), 0, loc
);
505 /************************************************************************
506 * IPersistStream_Load (IPersistStream)
508 static HRESULT WINAPI
IPersistStream_fnLoad(
509 IPersistStream
* iface
,
515 WCHAR sTemp
[MAX_PATH
];
518 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
520 TRACE("(%p)(%p)\n", This
, stm
);
523 return STG_E_INVALIDPOINTER
;
526 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
530 if( dwBytesRead
!= sizeof(hdr
))
532 if( hdr
.dwSize
!= sizeof(hdr
))
534 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
537 if( hdr
.dwFlags
& SCF_PIDL
)
539 r
= ILLoadFromStream( stm
, &This
->pPidl
);
543 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
544 This
->iIcoNdx
= hdr
.nIcon
;
545 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
546 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
547 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
549 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time1
, NULL
, sTemp
, 256);
550 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
551 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time2
, NULL
, sTemp
, 256);
552 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
553 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time3
, NULL
, sTemp
, 256);
554 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
557 if( hdr
.dwFlags
& SCF_NORMAL
)
558 r
= Stream_LoadLocation( stm
);
561 unicode
= hdr
.dwFlags
& SCF_UNICODE
;
562 if( hdr
.dwFlags
& SCF_DESCRIPTION
)
564 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
565 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
570 if( hdr
.dwFlags
& SCF_RELATIVE
)
572 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
573 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
578 if( hdr
.dwFlags
& SCF_WORKDIR
)
580 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
581 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
586 if( hdr
.dwFlags
& SCF_ARGS
)
588 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
589 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
594 if( hdr
.dwFlags
& SCF_CUSTOMICON
)
596 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
597 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
611 /************************************************************************
614 * Helper function for IPersistStream_Save. Writes a unicode string
615 * with terminating nul byte to a stream, preceded by the its length.
617 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
619 USHORT len
= lstrlenW( str
) + 1;
623 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
627 len
*= sizeof(WCHAR
);
629 r
= IStream_Write( stm
, str
, len
, &count
);
636 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCSTR filename
)
641 FIXME("writing empty location info\n");
643 memset( &loc
, 0, sizeof(loc
) );
644 loc
.dwTotalSize
= sizeof(loc
) - sizeof(loc
.dwTotalSize
);
646 /* FIXME: fill this in */
648 return IStream_Write( stm
, &loc
, loc
.dwTotalSize
, &count
);
651 extern UINT
SHELL_FindExecutable(LPCSTR lpPath
, LPCSTR lpFile
, LPCSTR lpOperation
,
652 LPSTR lpResult
, LPSTR key
, void **env
, LPCSTR args
);
654 /************************************************************************
655 * IPersistStream_Save (IPersistStream)
657 * FIXME: makes assumptions about byte order
659 static HRESULT WINAPI
IPersistStream_fnSave(
660 IPersistStream
* iface
,
665 char buffer
[MAX_PATH
];
666 char exePath
[MAX_PATH
];
670 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
672 TRACE("(%p) %p %x\n", This
, stm
, fClearDirty
);
677 WideCharToMultiByte(CP_ACP
, 0, This
->sPath
, -1, buffer
, MAX_PATH
, 0, 0);
679 SHELL_FindExecutable(NULL
, buffer
, "open", exePath
, NULL
, NULL
, NULL
);
682 /* if there's no PIDL, generate one */
688 This
->pPidl
= ILCreateFromPathA(exePath
);
691 memset(&header
, 0, sizeof(header
));
692 header
.dwSize
= sizeof(header
);
693 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
695 header
.wHotKey
= This
->wHotKey
;
696 header
.nIcon
= This
->iIcoNdx
;
697 header
.dwFlags
= SCF_UNICODE
; /* strings are in unicode */
698 header
.dwFlags
|= SCF_NORMAL
; /* how do we determine this ? */
700 header
.dwFlags
|= SCF_PIDL
;
701 if( This
->sDescription
)
702 header
.dwFlags
|= SCF_DESCRIPTION
;
704 header
.dwFlags
|= SCF_WORKDIR
;
706 header
.dwFlags
|= SCF_ARGS
;
708 header
.dwFlags
|= SCF_CUSTOMICON
;
710 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
711 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
712 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
714 /* write the Shortcut header */
715 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
718 ERR("Write failed at %d\n",__LINE__
);
722 TRACE("Writing pidl \n");
724 /* write the PIDL to the shortcut */
727 r
= ILSaveToStream( stm
, This
->pPidl
);
730 ERR("Failed to write PIDL at %d\n",__LINE__
);
735 Stream_WriteLocationInfo( stm
, exePath
);
737 TRACE("Description = %s\n", debugstr_w(This
->sDescription
));
738 if( This
->sDescription
)
739 r
= Stream_WriteString( stm
, This
->sDescription
);
742 r
= Stream_WriteString( stm
, This
->sPathRel
);
745 r
= Stream_WriteString( stm
, This
->sWorkDir
);
748 r
= Stream_WriteString( stm
, This
->sArgs
);
751 r
= Stream_WriteString( stm
, This
->sIcoPath
);
756 /************************************************************************
757 * IPersistStream_GetSizeMax (IPersistStream)
759 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
760 IPersistStream
* iface
,
761 ULARGE_INTEGER
* pcbSize
)
763 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
765 TRACE("(%p)\n", This
);
770 static ICOM_VTABLE(IPersistStream
) psvt
=
772 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
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
;
825 /**************************************************************************
826 * _IShellLink_UpdatePath
827 * update absolute path in sPath using relative path in sPathRel
829 static HRESULT
_IShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPWSTR
* psPath
)
831 if (!path
|| !psPath
)
834 if (!*psPath
&& sPathRel
) {
835 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
837 LPWSTR last_slash
= NULL
;
838 LPWSTR dest
= buffer
;
841 /* copy path without file name to buffer */
843 if (*src
=='/' || *src
=='\\')
849 lstrcpyW(last_slash
? last_slash
+1: buffer
, sPathRel
);
851 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
852 lstrcpyW(abs_path
, buffer
);
854 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
856 return E_OUTOFMEMORY
;
858 lstrcpyW(*psPath
, abs_path
);
864 /**************************************************************************
865 * IShellLink_ConstructFromFile
867 HRESULT WINAPI
IShellLink_ConstructFromFile (
876 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
883 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
886 WCHAR path
[MAX_PATH
];
888 if (SHGetPathFromIDListW(pidl
, path
)) {
889 hr
= IPersistFile_Load(ppf
, path
, 0);
892 *ppv
= (IUnknown
*) psl
;
895 The following code is here, not in IPersistStream_fnLoad() because
896 we need to know the path of the shell link file to convert the
897 relative path into the absolute path.
899 if (IsEqualIID(riid
, &IID_IShellLinkW
)) {
900 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, psl
);
902 hr
= _IShellLink_UpdatePath(This
->sPathRel
, path
, &This
->sPath
);
904 ICOM_THIS(IShellLinkImpl
, psl
);
906 hr
= _IShellLink_UpdatePath(This
->sPathRel
, path
, &This
->sPath
);
911 IPersistFile_Release(ppf
);
915 IShellLinkW_Release(psl
);
921 /**************************************************************************
922 * IShellLinkA_QueryInterface
924 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
926 ICOM_THIS(IShellLinkImpl
, iface
);
928 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
932 if(IsEqualIID(riid
, &IID_IUnknown
) ||
933 IsEqualIID(riid
, &IID_IShellLinkA
))
937 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
939 *ppvObj
= (IShellLinkW
*)&(This
->lpvtblw
);
941 else if(IsEqualIID(riid
, &IID_IPersistFile
))
943 *ppvObj
= (IPersistFile
*)&(This
->lpvtblPersistFile
);
945 else if(IsEqualIID(riid
, &IID_IPersistStream
))
947 *ppvObj
= (IPersistStream
*)&(This
->lpvtblPersistStream
);
952 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
953 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
956 TRACE("-- Interface: E_NOINTERFACE\n");
957 return E_NOINTERFACE
;
960 /******************************************************************************
963 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
965 ICOM_THIS(IShellLinkImpl
, iface
);
967 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
969 return ++(This
->ref
);
972 /******************************************************************************
973 * IShellLinkA_Release
975 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
977 ICOM_THIS(IShellLinkImpl
, iface
);
979 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
984 TRACE("-- destroying IShellLink(%p)\n",This
);
987 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
990 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
993 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
995 if (This
->sDescription
)
996 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
999 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1002 ILFree(This
->pPidl
);
1004 LocalFree((HANDLE
)This
);
1009 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1010 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1012 ICOM_THIS(IShellLinkImpl
, iface
);
1014 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1015 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1020 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1021 pszFile
, cchMaxPath
, NULL
, NULL
);
1025 FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1032 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1034 ICOM_THIS(IShellLinkImpl
, iface
);
1036 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1038 *ppidl
= ILClone(This
->pPidl
);
1043 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1045 ICOM_THIS(IShellLinkImpl
, iface
);
1047 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1050 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 ICOM_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 ICOM_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 ICOM_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 ICOM_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 ICOM_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 ICOM_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 ICOM_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 ICOM_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 ICOM_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 ICOM_THIS(IShellLinkImpl
, iface
);
1189 TRACE("(%p) %d\n",This
, iShowCmd
);
1191 This
->iShowCmd
= iShowCmd
;
1192 This
->bDirty
= TRUE
;
1197 static HRESULT
_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 ICOM_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
= _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
= _PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1260 IShellFolder_Release(pdsk
);
1268 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
, INT iIcon
)
1270 ICOM_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 ICOM_THIS(IShellLinkImpl
, iface
);
1290 FIXME("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1293 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1295 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1296 This
->bDirty
= TRUE
;
1298 return _IShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, &This
->sPath
);
1301 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1305 ICOM_THIS(IShellLinkImpl
, iface
);
1307 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1309 if (!This
->sPath
&& This
->pPidl
) {
1310 WCHAR buffer
[MAX_PATH
];
1312 hr
= _SHGetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1314 if (SUCCEEDED(hr
) && *buffer
) {
1315 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1317 return E_OUTOFMEMORY
;
1319 lstrcpyW(This
->sPath
, buffer
);
1321 This
->bDirty
= TRUE
;
1323 hr
= S_OK
; /* don't report any error occured while just caching information */
1326 if (!This
->sIcoPath
&& This
->sPath
) {
1327 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1328 if (!This
->sIcoPath
)
1329 return E_OUTOFMEMORY
;
1331 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1334 This
->bDirty
= TRUE
;
1340 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1342 ICOM_THIS(IShellLinkImpl
, iface
);
1344 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1347 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1348 This
->sPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1350 return E_OUTOFMEMORY
;
1352 This
->bDirty
= TRUE
;
1357 /**************************************************************************
1358 * IShellLink Implementation
1361 static ICOM_VTABLE(IShellLinkA
) slvt
=
1363 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1364 IShellLinkA_fnQueryInterface
,
1365 IShellLinkA_fnAddRef
,
1366 IShellLinkA_fnRelease
,
1367 IShellLinkA_fnGetPath
,
1368 IShellLinkA_fnGetIDList
,
1369 IShellLinkA_fnSetIDList
,
1370 IShellLinkA_fnGetDescription
,
1371 IShellLinkA_fnSetDescription
,
1372 IShellLinkA_fnGetWorkingDirectory
,
1373 IShellLinkA_fnSetWorkingDirectory
,
1374 IShellLinkA_fnGetArguments
,
1375 IShellLinkA_fnSetArguments
,
1376 IShellLinkA_fnGetHotkey
,
1377 IShellLinkA_fnSetHotkey
,
1378 IShellLinkA_fnGetShowCmd
,
1379 IShellLinkA_fnSetShowCmd
,
1380 IShellLinkA_fnGetIconLocation
,
1381 IShellLinkA_fnSetIconLocation
,
1382 IShellLinkA_fnSetRelativePath
,
1383 IShellLinkA_fnResolve
,
1384 IShellLinkA_fnSetPath
1388 /**************************************************************************
1389 * IShellLinkW_fnQueryInterface
1391 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1392 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1394 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1396 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
1399 /******************************************************************************
1400 * IShellLinkW_fnAddRef
1402 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1404 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1406 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1408 return IShellLinkA_AddRef((IShellLinkA
*)This
);
1410 /******************************************************************************
1411 * IShellLinkW_fnRelease
1414 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1416 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1418 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1420 return IShellLinkA_Release((IShellLinkA
*)This
);
1423 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1425 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1427 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",
1428 This
, pszFile
, cchMaxPath
, pfd
, fFlags
);
1433 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1437 FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1444 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1446 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1448 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1451 *ppidl
= ILClone( This
->pPidl
);
1458 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1460 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1462 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1465 ILFree( This
->pPidl
);
1466 This
->pPidl
= ILClone( pidl
);
1470 This
->bDirty
= TRUE
;
1475 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1477 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1479 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1483 if( This
->sDescription
)
1484 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1489 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1491 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1493 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1495 if (This
->sDescription
)
1496 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1497 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1498 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1499 if ( !This
->sDescription
)
1500 return E_OUTOFMEMORY
;
1502 lstrcpyW( This
->sDescription
, pszName
);
1503 This
->bDirty
= TRUE
;
1508 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1510 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1512 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1516 if( This
->sWorkDir
)
1517 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1522 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1524 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1526 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1529 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1530 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1531 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1532 if ( !This
->sWorkDir
)
1533 return E_OUTOFMEMORY
;
1535 lstrcpyW( This
->sWorkDir
, pszDir
);
1536 This
->bDirty
= TRUE
;
1541 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1543 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1545 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1550 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1555 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1557 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1559 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1562 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1563 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1564 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1566 return E_OUTOFMEMORY
;
1568 lstrcpyW( This
->sArgs
, pszArgs
);
1569 This
->bDirty
= TRUE
;
1574 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1576 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1578 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1580 *pwHotkey
=This
->wHotKey
;
1585 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1587 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1589 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1591 This
->wHotKey
= wHotkey
;
1592 This
->bDirty
= TRUE
;
1597 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1599 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1601 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1603 *piShowCmd
= This
->iShowCmd
;
1608 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1610 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1612 This
->iShowCmd
= iShowCmd
;
1613 This
->bDirty
= TRUE
;
1618 static HRESULT
_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1620 LPCITEMIDLIST pidlLast
;
1622 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1624 if (SUCCEEDED(hr
)) {
1627 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1629 if (SUCCEEDED(hr
)) {
1630 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1632 IExtractIconW_Release(pei
);
1635 IShellFolder_Release(psf
);
1641 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1643 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1645 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1650 if (This
->sIcoPath
) {
1651 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1652 *piIcon
= This
->iIcoNdx
;
1656 if (This
->pPidl
|| This
->sPath
) {
1659 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1661 if (SUCCEEDED(hr
)) {
1662 /* first look for an icon using the PIDL (if present) */
1664 hr
= _PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1668 /* if we couldn't find an icon yet, look for it using the file system path */
1669 if (FAILED(hr
) && This
->sPath
) {
1672 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1674 if (SUCCEEDED(hr
)) {
1675 hr
= _PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1681 IShellFolder_Release(pdsk
);
1689 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
, INT iIcon
)
1691 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1693 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1696 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1697 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1698 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1699 if ( !This
->sIcoPath
)
1700 return E_OUTOFMEMORY
;
1701 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1703 This
->iIcoNdx
= iIcon
;
1704 This
->bDirty
= TRUE
;
1709 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1711 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1713 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1716 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1717 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1718 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1719 if ( !This
->sPathRel
)
1720 return E_OUTOFMEMORY
;
1722 lstrcpyW( This
->sPathRel
, pszPathRel
);
1723 This
->bDirty
= TRUE
;
1725 return _IShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, &This
->sPath
);
1728 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1732 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1734 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1736 if (!This
->sPath
&& This
->pPidl
) {
1737 WCHAR buffer
[MAX_PATH
];
1739 hr
= _SHGetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1741 if (SUCCEEDED(hr
) && *buffer
) {
1742 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1744 return E_OUTOFMEMORY
;
1746 lstrcpyW(This
->sPath
, buffer
);
1748 This
->bDirty
= TRUE
;
1750 hr
= S_OK
; /* don't report any error occured while just caching information */
1753 if (!This
->sIcoPath
&& This
->sPath
) {
1754 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1755 if (!This
->sIcoPath
)
1756 return E_OUTOFMEMORY
;
1758 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1761 This
->bDirty
= TRUE
;
1767 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
1769 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1771 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
1774 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1775 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
1776 (lstrlenW( pszFile
)+1) * sizeof (WCHAR
) );
1778 return E_OUTOFMEMORY
;
1780 lstrcpyW( This
->sPath
, pszFile
);
1781 This
->bDirty
= TRUE
;
1786 /**************************************************************************
1787 * IShellLinkW Implementation
1790 static ICOM_VTABLE(IShellLinkW
) slvtw
=
1792 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1793 IShellLinkW_fnQueryInterface
,
1794 IShellLinkW_fnAddRef
,
1795 IShellLinkW_fnRelease
,
1796 IShellLinkW_fnGetPath
,
1797 IShellLinkW_fnGetIDList
,
1798 IShellLinkW_fnSetIDList
,
1799 IShellLinkW_fnGetDescription
,
1800 IShellLinkW_fnSetDescription
,
1801 IShellLinkW_fnGetWorkingDirectory
,
1802 IShellLinkW_fnSetWorkingDirectory
,
1803 IShellLinkW_fnGetArguments
,
1804 IShellLinkW_fnSetArguments
,
1805 IShellLinkW_fnGetHotkey
,
1806 IShellLinkW_fnSetHotkey
,
1807 IShellLinkW_fnGetShowCmd
,
1808 IShellLinkW_fnSetShowCmd
,
1809 IShellLinkW_fnGetIconLocation
,
1810 IShellLinkW_fnSetIconLocation
,
1811 IShellLinkW_fnSetRelativePath
,
1812 IShellLinkW_fnResolve
,
1813 IShellLinkW_fnSetPath