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_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 ICOM_VTABLE(IShellLinkA
) slvt
;
116 static ICOM_VTABLE(IShellLinkW
) slvtw
;
117 static ICOM_VTABLE(IPersistFile
) pfvt
;
118 static ICOM_VTABLE(IPersistStream
) psvt
;
120 /* IShellLink Implementation */
124 ICOM_VFIELD(IShellLinkA
);
127 ICOM_VTABLE(IShellLinkW
)* lpvtblw
;
128 ICOM_VTABLE(IPersistFile
)* lpvtblPersistFile
;
129 ICOM_VTABLE(IPersistStream
)* lpvtblPersistStream
;
131 /* data structures according to the informations in the 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)
158 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset)
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 FIXME("(%p)\n",This
);
228 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
230 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
231 _IPersistStream_From_ICOM_THIS(IPersistStream
, This
);
235 TRACE("(%p, %s)\n",This
, debugstr_w(pszFileName
));
237 r
= CreateStreamOnFile(pszFileName
, dwMode
, &stm
);
240 r
= IPersistStream_Load(StreamThis
, stm
);
241 IStream_Release( stm
);
247 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
249 const WCHAR szFormat
[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
250 ' ','-','r',' ','"','%','s','"',0 };
254 PROCESS_INFORMATION pi
;
256 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
257 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
261 wsprintfW( buffer
, szFormat
, szLink
);
263 TRACE("starting %s\n",debugstr_w(buffer
));
265 memset(&si
, 0, sizeof(si
));
267 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
269 /* wait for a while to throttle the creation of linker processes */
270 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
271 WARN("Timed out waiting for shell linker\n");
273 CloseHandle( pi
.hProcess
);
274 CloseHandle( pi
.hThread
);
279 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
281 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
282 _IPersistStream_From_ICOM_THIS(IPersistStream
, This
);
286 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
288 if (!pszFileName
|| !This
->sPath
)
289 return ERROR_UNKNOWN
;
291 r
= CreateStreamOnFile(pszFileName
, STGM_READWRITE
| STGM_CREATE
, &stm
);
294 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
295 IStream_Release( stm
);
298 StartLinkProcessor( pszFileName
);
301 DeleteFileW( pszFileName
);
302 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
309 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
311 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
312 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
315 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
317 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
318 FIXME("(%p)\n",This
);
322 static ICOM_VTABLE(IPersistFile
) pfvt
=
324 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
325 IPersistFile_fnQueryInterface
,
326 IPersistFile_fnAddRef
,
327 IPersistFile_fnRelease
,
328 IPersistFile_fnGetClassID
,
329 IPersistFile_fnIsDirty
,
332 IPersistFile_fnSaveCompleted
,
333 IPersistFile_fnGetCurFile
336 /************************************************************************
337 * IPersistStream_QueryInterface
339 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
340 IPersistStream
* iface
,
344 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
346 TRACE("(%p)\n",This
);
348 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvoid
);
351 /************************************************************************
352 * IPersistStream_Release
354 static ULONG WINAPI
IPersistStream_fnRelease(
355 IPersistStream
* iface
)
357 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
359 TRACE("(%p)\n",This
);
361 return IShellLinkA_Release((IShellLinkA
*)This
);
364 /************************************************************************
365 * IPersistStream_AddRef
367 static ULONG WINAPI
IPersistStream_fnAddRef(
368 IPersistStream
* iface
)
370 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
372 TRACE("(%p)\n",This
);
374 return IShellLinkA_AddRef((IShellLinkA
*)This
);
377 /************************************************************************
378 * IPersistStream_GetClassID
381 static HRESULT WINAPI
IPersistStream_fnGetClassID(
382 IPersistStream
* iface
,
385 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
387 TRACE("(%p)\n", This
);
392 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
397 /************************************************************************
398 * IPersistStream_IsDirty (IPersistStream)
400 static HRESULT WINAPI
IPersistStream_fnIsDirty(
401 IPersistStream
* iface
)
403 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
405 TRACE("(%p)\n", This
);
411 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
422 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
423 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
427 len
*= sizeof (WCHAR
);
429 TRACE("reading %d\n", len
);
430 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
432 return E_OUTOFMEMORY
;
434 r
= IStream_Read(stm
, temp
, len
, &count
);
435 if( FAILED (r
) || ( count
!= len
) )
437 HeapFree( GetProcessHeap(), 0, temp
);
441 TRACE("read %s\n", debugstr_an(temp
,len
));
443 /* convert to unicode if necessary */
446 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
447 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
449 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
450 HeapFree( GetProcessHeap(), 0, temp
);
464 static HRESULT
Stream_LoadLocation( IStream
* stm
)
473 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
476 if( count
!= sizeof(loc
->dwTotalSize
) )
479 loc
= HeapAlloc( GetProcessHeap(), 0, size
);
481 return E_OUTOFMEMORY
;
483 r
= IStream_Read( stm
, &loc
->dwHeaderSize
, size
-sizeof(size
), &count
);
486 if( count
!= (size
- sizeof(size
)) )
491 loc
->dwTotalSize
= size
;
493 TRACE("Read %ld bytes\n",count
);
495 /* FIXME: do something useful with it */
496 HeapFree( GetProcessHeap(), 0, loc
);
500 HeapFree( GetProcessHeap(), 0, loc
);
504 /************************************************************************
505 * IPersistStream_Load (IPersistStream)
507 static HRESULT WINAPI
IPersistStream_fnLoad(
508 IPersistStream
* iface
,
514 WCHAR sTemp
[MAX_PATH
];
517 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
519 TRACE("(%p)(%p)\n", This
, stm
);
522 return STG_E_INVALIDPOINTER
;
525 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
529 if( dwBytesRead
!= sizeof(hdr
))
531 if( hdr
.dwSize
!= sizeof(hdr
))
533 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
536 if( hdr
.dwFlags
& SCF_PIDL
)
538 r
= ILLoadFromStream( stm
, &This
->pPidl
);
542 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
543 This
->iIcoNdx
= hdr
.nIcon
;
544 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
545 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
546 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
548 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time1
, NULL
, sTemp
, 256);
549 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
550 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time2
, NULL
, sTemp
, 256);
551 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
552 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time3
, NULL
, sTemp
, 256);
553 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
556 if( hdr
.dwFlags
& SCF_NORMAL
)
557 r
= Stream_LoadLocation( stm
);
560 unicode
= hdr
.dwFlags
& SCF_UNICODE
;
561 if( hdr
.dwFlags
& SCF_DESCRIPTION
)
563 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
564 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
569 if( hdr
.dwFlags
& SCF_RELATIVE
)
571 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
572 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
577 if( hdr
.dwFlags
& SCF_WORKDIR
)
579 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
580 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
585 if( hdr
.dwFlags
& SCF_ARGS
)
587 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
588 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
593 if( hdr
.dwFlags
& SCF_CUSTOMICON
)
595 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
596 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
610 /************************************************************************
613 * Helper function for IPersistStream_Save. Writes a unicode string
614 * with terminating nul byte to a stream, preceded by the its length.
616 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
618 USHORT len
= lstrlenW( str
) + 1;
622 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
626 len
*= sizeof(WCHAR
);
628 r
= IStream_Write( stm
, str
, len
, &count
);
635 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR filename
)
640 FIXME("writing empty location info\n");
642 memset( &loc
, 0, sizeof(loc
) );
643 loc
.dwTotalSize
= sizeof(loc
) - sizeof(loc
.dwTotalSize
);
645 /* FIXME: fill this in */
647 return IStream_Write( stm
, &loc
, loc
.dwTotalSize
, &count
);
650 /************************************************************************
651 * IPersistStream_Save (IPersistStream)
653 * FIXME: makes assumptions about byte order
655 static HRESULT WINAPI
IPersistStream_fnSave(
656 IPersistStream
* iface
,
660 static const WCHAR wOpen
[] = {'o','p','e','n',0};
663 WCHAR exePath
[MAX_PATH
];
667 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
669 TRACE("(%p) %p %x\n", This
, stm
, fClearDirty
);
674 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, MAX_PATH
, NULL
, NULL
, NULL
, NULL
);
676 /* if there's no PIDL, generate one */
682 This
->pPidl
= ILCreateFromPathW(exePath
);
685 memset(&header
, 0, sizeof(header
));
686 header
.dwSize
= sizeof(header
);
687 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
689 header
.wHotKey
= This
->wHotKey
;
690 header
.nIcon
= This
->iIcoNdx
;
691 header
.dwFlags
= SCF_UNICODE
; /* strings are in unicode */
692 header
.dwFlags
|= SCF_NORMAL
; /* how do we determine this ? */
694 header
.dwFlags
|= SCF_PIDL
;
695 if( This
->sDescription
)
696 header
.dwFlags
|= SCF_DESCRIPTION
;
698 header
.dwFlags
|= SCF_WORKDIR
;
700 header
.dwFlags
|= SCF_ARGS
;
702 header
.dwFlags
|= SCF_CUSTOMICON
;
704 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
705 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
706 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
708 /* write the Shortcut header */
709 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
712 ERR("Write failed at %d\n",__LINE__
);
716 TRACE("Writing pidl \n");
718 /* write the PIDL to the shortcut */
721 r
= ILSaveToStream( stm
, This
->pPidl
);
724 ERR("Failed to write PIDL at %d\n",__LINE__
);
729 Stream_WriteLocationInfo( stm
, exePath
);
731 TRACE("Description = %s\n", debugstr_w(This
->sDescription
));
732 if( This
->sDescription
)
733 r
= Stream_WriteString( stm
, This
->sDescription
);
736 r
= Stream_WriteString( stm
, This
->sPathRel
);
739 r
= Stream_WriteString( stm
, This
->sWorkDir
);
742 r
= Stream_WriteString( stm
, This
->sArgs
);
745 r
= Stream_WriteString( stm
, This
->sIcoPath
);
750 /************************************************************************
751 * IPersistStream_GetSizeMax (IPersistStream)
753 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
754 IPersistStream
* iface
,
755 ULARGE_INTEGER
* pcbSize
)
757 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
759 TRACE("(%p)\n", This
);
764 static ICOM_VTABLE(IPersistStream
) psvt
=
766 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
767 IPersistStream_fnQueryInterface
,
768 IPersistStream_fnAddRef
,
769 IPersistStream_fnRelease
,
770 IPersistStream_fnGetClassID
,
771 IPersistStream_fnIsDirty
,
772 IPersistStream_fnLoad
,
773 IPersistStream_fnSave
,
774 IPersistStream_fnGetSizeMax
777 /**************************************************************************
778 * IShellLink_Constructor
780 HRESULT WINAPI
IShellLink_Constructor (
781 IUnknown
* pUnkOuter
,
787 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
791 if(pUnkOuter
) return CLASS_E_NOAGGREGATION
;
792 sl
= (IShellLinkImpl
*) LocalAlloc(GMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
793 if (!sl
) return E_OUTOFMEMORY
;
797 sl
->lpvtblw
= &slvtw
;
798 sl
->lpvtblPersistFile
= &pfvt
;
799 sl
->lpvtblPersistStream
= &psvt
;
800 sl
->iShowCmd
= SW_SHOWNORMAL
;
803 TRACE("(%p)->()\n",sl
);
805 if (IsEqualIID(riid
, &IID_IUnknown
) ||
806 IsEqualIID(riid
, &IID_IShellLinkA
))
808 else if (IsEqualIID(riid
, &IID_IShellLinkW
))
809 *ppv
= &(sl
->lpvtblw
);
811 LocalFree((HLOCAL
)sl
);
812 ERR("E_NOINTERFACE\n");
813 return E_NOINTERFACE
;
819 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
821 HANDLE hfile
= CreateFileW(path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
823 if (hfile
!= INVALID_HANDLE_VALUE
) {
830 /**************************************************************************
831 * SHELL_ShellLink_UpdatePath
832 * update absolute path in sPath using relative path in sPathRel
834 static HRESULT
SHELL_ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
836 if (!path
|| !psPath
)
839 if (!*psPath
&& sPathRel
) {
840 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
842 /* first try if [directory of link file] + [relative path] finds an existing file */
844 LPWSTR last_slash
= NULL
;
845 LPWSTR dest
= buffer
;
848 /* copy path without file name to buffer */
850 if (*src
=='/' || *src
=='\\')
856 lstrcpyW(last_slash
? last_slash
+1: buffer
, sPathRel
);
860 if (SHELL_ExistsFileW(buffer
)) {
861 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
862 lstrcpyW(abs_path
, buffer
);
864 /* try if [working directory] + [relative path] finds an existing file */
866 lstrcpyW(buffer
, sWorkDir
);
867 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
869 if (SHELL_ExistsFileW(buffer
))
870 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
871 lstrcpyW(abs_path
, buffer
);
875 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
877 lstrcpyW(abs_path
, sPathRel
);
879 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
881 return E_OUTOFMEMORY
;
883 lstrcpyW(*psPath
, abs_path
);
889 /**************************************************************************
890 * IShellLink_ConstructFromFile
892 HRESULT WINAPI
IShellLink_ConstructFromFile (
901 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
908 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
911 WCHAR path
[MAX_PATH
];
913 if (SHGetPathFromIDListW(pidl
, path
)) {
914 hr
= IPersistFile_Load(ppf
, path
, 0);
917 *ppv
= (IUnknown
*) psl
;
920 The following code is here, not in IPersistStream_fnLoad() because
921 to be able to convert the relative path into the absolute path,
922 we need to know the path of the shell link file.
924 if (IsEqualIID(riid
, &IID_IShellLinkW
)) {
925 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, psl
);
927 hr
= SHELL_ShellLink_UpdatePath(This
->sPathRel
, path
, This
->sWorkDir
, &This
->sPath
);
929 ICOM_THIS(IShellLinkImpl
, psl
);
931 hr
= SHELL_ShellLink_UpdatePath(This
->sPathRel
, path
, This
->sWorkDir
, &This
->sPath
);
936 IPersistFile_Release(ppf
);
940 IShellLinkW_Release(psl
);
946 /**************************************************************************
947 * IShellLinkA_QueryInterface
949 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
951 ICOM_THIS(IShellLinkImpl
, iface
);
953 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
957 if(IsEqualIID(riid
, &IID_IUnknown
) ||
958 IsEqualIID(riid
, &IID_IShellLinkA
))
962 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
964 *ppvObj
= (IShellLinkW
*)&(This
->lpvtblw
);
966 else if(IsEqualIID(riid
, &IID_IPersistFile
))
968 *ppvObj
= (IPersistFile
*)&(This
->lpvtblPersistFile
);
970 else if(IsEqualIID(riid
, &IID_IPersistStream
))
972 *ppvObj
= (IPersistStream
*)&(This
->lpvtblPersistStream
);
977 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
978 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
981 TRACE("-- Interface: E_NOINTERFACE\n");
982 return E_NOINTERFACE
;
985 /******************************************************************************
988 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
990 ICOM_THIS(IShellLinkImpl
, iface
);
992 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
994 return ++(This
->ref
);
997 /******************************************************************************
998 * IShellLinkA_Release
1000 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
1002 ICOM_THIS(IShellLinkImpl
, iface
);
1004 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1009 TRACE("-- destroying IShellLink(%p)\n",This
);
1012 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1015 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1018 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1020 if (This
->sDescription
)
1021 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1024 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1027 ILFree(This
->pPidl
);
1029 LocalFree((HANDLE
)This
);
1034 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1035 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1037 ICOM_THIS(IShellLinkImpl
, iface
);
1039 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1040 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1045 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1046 pszFile
, cchMaxPath
, NULL
, NULL
);
1050 FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1057 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1059 ICOM_THIS(IShellLinkImpl
, iface
);
1061 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1063 *ppidl
= ILClone(This
->pPidl
);
1068 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1070 ICOM_THIS(IShellLinkImpl
, iface
);
1072 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1075 ILFree(This
->pPidl
);
1077 This
->pPidl
= ILClone (pidl
);
1078 This
->bDirty
= TRUE
;
1083 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1085 ICOM_THIS(IShellLinkImpl
, iface
);
1087 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1091 if( This
->sDescription
)
1092 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1093 pszName
, cchMaxName
, NULL
, NULL
);
1097 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1099 ICOM_THIS(IShellLinkImpl
, iface
);
1101 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1103 if (This
->sDescription
)
1104 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1105 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1106 if ( !This
->sDescription
)
1107 return E_OUTOFMEMORY
;
1109 This
->bDirty
= TRUE
;
1114 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1116 ICOM_THIS(IShellLinkImpl
, iface
);
1118 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1122 if( This
->sWorkDir
)
1123 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1124 pszDir
, cchMaxPath
, NULL
, NULL
);
1129 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1131 ICOM_THIS(IShellLinkImpl
, iface
);
1133 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1136 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1137 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1138 if ( !This
->sWorkDir
)
1139 return E_OUTOFMEMORY
;
1141 This
->bDirty
= TRUE
;
1146 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1148 ICOM_THIS(IShellLinkImpl
, iface
);
1150 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1155 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1156 pszArgs
, cchMaxPath
, NULL
, NULL
);
1161 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1163 ICOM_THIS(IShellLinkImpl
, iface
);
1165 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1168 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1169 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1171 return E_OUTOFMEMORY
;
1173 This
->bDirty
= TRUE
;
1178 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1180 ICOM_THIS(IShellLinkImpl
, iface
);
1182 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1184 *pwHotkey
= This
->wHotKey
;
1189 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1191 ICOM_THIS(IShellLinkImpl
, iface
);
1193 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1195 This
->wHotKey
= wHotkey
;
1196 This
->bDirty
= TRUE
;
1201 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1203 ICOM_THIS(IShellLinkImpl
, iface
);
1205 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1206 *piShowCmd
= This
->iShowCmd
;
1210 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1212 ICOM_THIS(IShellLinkImpl
, iface
);
1214 TRACE("(%p) %d\n",This
, iShowCmd
);
1216 This
->iShowCmd
= iShowCmd
;
1217 This
->bDirty
= TRUE
;
1222 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1224 LPCITEMIDLIST pidlLast
;
1226 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1228 if (SUCCEEDED(hr
)) {
1231 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1233 if (SUCCEEDED(hr
)) {
1234 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1236 IExtractIconA_Release(pei
);
1239 IShellFolder_Release(psf
);
1245 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1247 ICOM_THIS(IShellLinkImpl
, iface
);
1249 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1254 if (This
->sIcoPath
) {
1255 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1256 *piIcon
= This
->iIcoNdx
;
1260 if (This
->pPidl
|| This
->sPath
) {
1263 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1265 if (SUCCEEDED(hr
)) {
1266 /* first look for an icon using the PIDL (if present) */
1268 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1272 /* if we couldn't find an icon yet, look for it using the file system path */
1273 if (FAILED(hr
) && This
->sPath
) {
1276 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1278 if (SUCCEEDED(hr
)) {
1279 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1285 IShellFolder_Release(pdsk
);
1293 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
, INT iIcon
)
1295 ICOM_THIS(IShellLinkImpl
, iface
);
1297 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1300 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1301 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1302 if ( !This
->sIcoPath
)
1303 return E_OUTOFMEMORY
;
1305 This
->iIcoNdx
= iIcon
;
1306 This
->bDirty
= TRUE
;
1311 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1313 ICOM_THIS(IShellLinkImpl
, iface
);
1315 FIXME("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1318 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1320 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1321 This
->bDirty
= TRUE
;
1323 return SHELL_ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1326 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1330 ICOM_THIS(IShellLinkImpl
, iface
);
1332 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1334 /*FIXME: use IResolveShellLink interface */
1336 if (!This
->sPath
&& This
->pPidl
) {
1337 WCHAR buffer
[MAX_PATH
];
1339 hr
= SHELL_GetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1341 if (SUCCEEDED(hr
) && *buffer
) {
1342 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1344 return E_OUTOFMEMORY
;
1346 lstrcpyW(This
->sPath
, buffer
);
1348 This
->bDirty
= TRUE
;
1350 hr
= S_OK
; /* don't report any error occured while just caching information */
1353 if (!This
->sIcoPath
&& This
->sPath
) {
1354 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1355 if (!This
->sIcoPath
)
1356 return E_OUTOFMEMORY
;
1358 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1361 This
->bDirty
= TRUE
;
1367 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1369 ICOM_THIS(IShellLinkImpl
, iface
);
1371 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1374 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1375 This
->sPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile
);
1377 return E_OUTOFMEMORY
;
1379 This
->bDirty
= TRUE
;
1384 /**************************************************************************
1385 * IShellLink Implementation
1388 static ICOM_VTABLE(IShellLinkA
) slvt
=
1390 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1391 IShellLinkA_fnQueryInterface
,
1392 IShellLinkA_fnAddRef
,
1393 IShellLinkA_fnRelease
,
1394 IShellLinkA_fnGetPath
,
1395 IShellLinkA_fnGetIDList
,
1396 IShellLinkA_fnSetIDList
,
1397 IShellLinkA_fnGetDescription
,
1398 IShellLinkA_fnSetDescription
,
1399 IShellLinkA_fnGetWorkingDirectory
,
1400 IShellLinkA_fnSetWorkingDirectory
,
1401 IShellLinkA_fnGetArguments
,
1402 IShellLinkA_fnSetArguments
,
1403 IShellLinkA_fnGetHotkey
,
1404 IShellLinkA_fnSetHotkey
,
1405 IShellLinkA_fnGetShowCmd
,
1406 IShellLinkA_fnSetShowCmd
,
1407 IShellLinkA_fnGetIconLocation
,
1408 IShellLinkA_fnSetIconLocation
,
1409 IShellLinkA_fnSetRelativePath
,
1410 IShellLinkA_fnResolve
,
1411 IShellLinkA_fnSetPath
1415 /**************************************************************************
1416 * IShellLinkW_fnQueryInterface
1418 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1419 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1421 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1423 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
1426 /******************************************************************************
1427 * IShellLinkW_fnAddRef
1429 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1431 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1433 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1435 return IShellLinkA_AddRef((IShellLinkA
*)This
);
1437 /******************************************************************************
1438 * IShellLinkW_fnRelease
1441 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1443 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1445 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1447 return IShellLinkA_Release((IShellLinkA
*)This
);
1450 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1452 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1454 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",
1455 This
, pszFile
, cchMaxPath
, pfd
, fFlags
);
1460 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1464 FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1471 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1473 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1475 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1478 *ppidl
= ILClone( This
->pPidl
);
1485 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1487 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1489 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1492 ILFree( This
->pPidl
);
1493 This
->pPidl
= ILClone( pidl
);
1497 This
->bDirty
= TRUE
;
1502 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1504 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1506 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1510 if( This
->sDescription
)
1511 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1516 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1518 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1520 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1522 if (This
->sDescription
)
1523 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1524 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1525 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1526 if ( !This
->sDescription
)
1527 return E_OUTOFMEMORY
;
1529 lstrcpyW( This
->sDescription
, pszName
);
1530 This
->bDirty
= TRUE
;
1535 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1537 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1539 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1543 if( This
->sWorkDir
)
1544 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1549 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1551 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1553 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1556 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1557 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1558 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1559 if ( !This
->sWorkDir
)
1560 return E_OUTOFMEMORY
;
1562 lstrcpyW( This
->sWorkDir
, pszDir
);
1563 This
->bDirty
= TRUE
;
1568 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1570 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1572 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1577 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1582 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1584 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1586 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1589 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1590 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1591 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1593 return E_OUTOFMEMORY
;
1595 lstrcpyW( This
->sArgs
, pszArgs
);
1596 This
->bDirty
= TRUE
;
1601 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1603 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1605 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1607 *pwHotkey
=This
->wHotKey
;
1612 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1614 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1616 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1618 This
->wHotKey
= wHotkey
;
1619 This
->bDirty
= TRUE
;
1624 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1626 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1628 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1630 *piShowCmd
= This
->iShowCmd
;
1635 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1637 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1639 This
->iShowCmd
= iShowCmd
;
1640 This
->bDirty
= TRUE
;
1645 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1647 LPCITEMIDLIST pidlLast
;
1649 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1651 if (SUCCEEDED(hr
)) {
1654 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1656 if (SUCCEEDED(hr
)) {
1657 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1659 IExtractIconW_Release(pei
);
1662 IShellFolder_Release(psf
);
1668 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1670 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1672 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1677 if (This
->sIcoPath
) {
1678 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1679 *piIcon
= This
->iIcoNdx
;
1683 if (This
->pPidl
|| This
->sPath
) {
1686 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1688 if (SUCCEEDED(hr
)) {
1689 /* first look for an icon using the PIDL (if present) */
1691 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1695 /* if we couldn't find an icon yet, look for it using the file system path */
1696 if (FAILED(hr
) && This
->sPath
) {
1699 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1701 if (SUCCEEDED(hr
)) {
1702 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1708 IShellFolder_Release(pdsk
);
1716 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
, INT iIcon
)
1718 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1720 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1723 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1724 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1725 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1726 if ( !This
->sIcoPath
)
1727 return E_OUTOFMEMORY
;
1728 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1730 This
->iIcoNdx
= iIcon
;
1731 This
->bDirty
= TRUE
;
1736 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1738 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1740 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1743 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1744 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1745 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1746 if ( !This
->sPathRel
)
1747 return E_OUTOFMEMORY
;
1749 lstrcpyW( This
->sPathRel
, pszPathRel
);
1750 This
->bDirty
= TRUE
;
1752 return SHELL_ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1755 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1759 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1761 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1763 /*FIXME: use IResolveShellLink interface */
1765 if (!This
->sPath
&& This
->pPidl
) {
1766 WCHAR buffer
[MAX_PATH
];
1768 hr
= SHELL_GetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1770 if (SUCCEEDED(hr
) && *buffer
) {
1771 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1773 return E_OUTOFMEMORY
;
1775 lstrcpyW(This
->sPath
, buffer
);
1777 This
->bDirty
= TRUE
;
1779 hr
= S_OK
; /* don't report any error occured while just caching information */
1782 if (!This
->sIcoPath
&& This
->sPath
) {
1783 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1784 if (!This
->sIcoPath
)
1785 return E_OUTOFMEMORY
;
1787 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1790 This
->bDirty
= TRUE
;
1796 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
1798 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1800 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
1803 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1804 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
1805 (lstrlenW( pszFile
)+1) * sizeof (WCHAR
) );
1807 return E_OUTOFMEMORY
;
1809 lstrcpyW( This
->sPath
, pszFile
);
1810 This
->bDirty
= TRUE
;
1815 /**************************************************************************
1816 * IShellLinkW Implementation
1819 static ICOM_VTABLE(IShellLinkW
) slvtw
=
1821 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1822 IShellLinkW_fnQueryInterface
,
1823 IShellLinkW_fnAddRef
,
1824 IShellLinkW_fnRelease
,
1825 IShellLinkW_fnGetPath
,
1826 IShellLinkW_fnGetIDList
,
1827 IShellLinkW_fnSetIDList
,
1828 IShellLinkW_fnGetDescription
,
1829 IShellLinkW_fnSetDescription
,
1830 IShellLinkW_fnGetWorkingDirectory
,
1831 IShellLinkW_fnSetWorkingDirectory
,
1832 IShellLinkW_fnGetArguments
,
1833 IShellLinkW_fnSetArguments
,
1834 IShellLinkW_fnGetHotkey
,
1835 IShellLinkW_fnSetHotkey
,
1836 IShellLinkW_fnGetShowCmd
,
1837 IShellLinkW_fnSetShowCmd
,
1838 IShellLinkW_fnGetIconLocation
,
1839 IShellLinkW_fnSetIconLocation
,
1840 IShellLinkW_fnSetRelativePath
,
1841 IShellLinkW_fnResolve
,
1842 IShellLinkW_fnSetPath