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)
160 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
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 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
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
, MAX_PATH
, 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 * ShellLink_UpdatePath
834 * update absolute path in sPath using relative path in sPathRel
836 static HRESULT
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 hr
= SHELL_GetPathFromIDListW(pidl
, path
, MAX_PATH
);
918 hr
= IPersistFile_Load(ppf
, path
, 0);
921 *ppv
= (IUnknown
*) psl
;
924 IPersistFile_Release(ppf
);
928 IShellLinkW_Release(psl
);
934 /**************************************************************************
935 * IShellLinkA_QueryInterface
937 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
939 ICOM_THIS(IShellLinkImpl
, iface
);
941 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
945 if(IsEqualIID(riid
, &IID_IUnknown
) ||
946 IsEqualIID(riid
, &IID_IShellLinkA
))
950 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
952 *ppvObj
= (IShellLinkW
*)&(This
->lpvtblw
);
954 else if(IsEqualIID(riid
, &IID_IPersistFile
))
956 *ppvObj
= (IPersistFile
*)&(This
->lpvtblPersistFile
);
958 else if(IsEqualIID(riid
, &IID_IPersistStream
))
960 *ppvObj
= (IPersistStream
*)&(This
->lpvtblPersistStream
);
965 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
966 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
969 TRACE("-- Interface: E_NOINTERFACE\n");
970 return E_NOINTERFACE
;
973 /******************************************************************************
976 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
978 ICOM_THIS(IShellLinkImpl
, iface
);
980 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
982 return ++(This
->ref
);
985 /******************************************************************************
986 * IShellLinkA_Release
988 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
990 ICOM_THIS(IShellLinkImpl
, iface
);
992 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
997 TRACE("-- destroying IShellLink(%p)\n",This
);
1000 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1003 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1006 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1008 if (This
->sDescription
)
1009 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1012 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1015 ILFree(This
->pPidl
);
1017 LocalFree((HANDLE
)This
);
1022 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1023 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1025 ICOM_THIS(IShellLinkImpl
, iface
);
1027 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1028 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1033 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1034 pszFile
, cchMaxPath
, NULL
, NULL
);
1038 FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1045 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1047 ICOM_THIS(IShellLinkImpl
, iface
);
1049 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1051 *ppidl
= ILClone(This
->pPidl
);
1056 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1058 ICOM_THIS(IShellLinkImpl
, iface
);
1060 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1063 ILFree(This
->pPidl
);
1065 This
->pPidl
= ILClone (pidl
);
1066 This
->bDirty
= TRUE
;
1071 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1073 ICOM_THIS(IShellLinkImpl
, iface
);
1075 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1079 if( This
->sDescription
)
1080 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1081 pszName
, cchMaxName
, NULL
, NULL
);
1085 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1087 ICOM_THIS(IShellLinkImpl
, iface
);
1089 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1091 if (This
->sDescription
)
1092 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1093 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1094 if ( !This
->sDescription
)
1095 return E_OUTOFMEMORY
;
1097 This
->bDirty
= TRUE
;
1102 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1104 ICOM_THIS(IShellLinkImpl
, iface
);
1106 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1110 if( This
->sWorkDir
)
1111 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1112 pszDir
, cchMaxPath
, NULL
, NULL
);
1117 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1119 ICOM_THIS(IShellLinkImpl
, iface
);
1121 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1124 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1125 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1126 if ( !This
->sWorkDir
)
1127 return E_OUTOFMEMORY
;
1129 This
->bDirty
= TRUE
;
1134 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1136 ICOM_THIS(IShellLinkImpl
, iface
);
1138 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1143 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1144 pszArgs
, cchMaxPath
, NULL
, NULL
);
1149 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1151 ICOM_THIS(IShellLinkImpl
, iface
);
1153 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1156 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1157 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1159 return E_OUTOFMEMORY
;
1161 This
->bDirty
= TRUE
;
1166 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1168 ICOM_THIS(IShellLinkImpl
, iface
);
1170 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1172 *pwHotkey
= This
->wHotKey
;
1177 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1179 ICOM_THIS(IShellLinkImpl
, iface
);
1181 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1183 This
->wHotKey
= wHotkey
;
1184 This
->bDirty
= TRUE
;
1189 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1191 ICOM_THIS(IShellLinkImpl
, iface
);
1193 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1194 *piShowCmd
= This
->iShowCmd
;
1198 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1200 ICOM_THIS(IShellLinkImpl
, iface
);
1202 TRACE("(%p) %d\n",This
, iShowCmd
);
1204 This
->iShowCmd
= iShowCmd
;
1205 This
->bDirty
= TRUE
;
1210 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1212 LPCITEMIDLIST pidlLast
;
1214 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1216 if (SUCCEEDED(hr
)) {
1219 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1221 if (SUCCEEDED(hr
)) {
1222 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1224 IExtractIconA_Release(pei
);
1227 IShellFolder_Release(psf
);
1233 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1235 ICOM_THIS(IShellLinkImpl
, iface
);
1237 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1242 if (This
->sIcoPath
) {
1243 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1244 *piIcon
= This
->iIcoNdx
;
1248 if (This
->pPidl
|| This
->sPath
) {
1251 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1253 if (SUCCEEDED(hr
)) {
1254 /* first look for an icon using the PIDL (if present) */
1256 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1260 /* if we couldn't find an icon yet, look for it using the file system path */
1261 if (FAILED(hr
) && This
->sPath
) {
1264 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1266 if (SUCCEEDED(hr
)) {
1267 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1273 IShellFolder_Release(pdsk
);
1281 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
, INT iIcon
)
1283 ICOM_THIS(IShellLinkImpl
, iface
);
1285 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1288 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1289 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1290 if ( !This
->sIcoPath
)
1291 return E_OUTOFMEMORY
;
1293 This
->iIcoNdx
= iIcon
;
1294 This
->bDirty
= TRUE
;
1299 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1301 ICOM_THIS(IShellLinkImpl
, iface
);
1303 FIXME("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1306 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1308 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1309 This
->bDirty
= TRUE
;
1311 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1314 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1318 ICOM_THIS(IShellLinkImpl
, iface
);
1320 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1322 /*FIXME: use IResolveShellLink interface */
1324 if (!This
->sPath
&& This
->pPidl
) {
1325 WCHAR buffer
[MAX_PATH
];
1327 hr
= SHELL_GetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1329 if (SUCCEEDED(hr
) && *buffer
) {
1330 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1332 return E_OUTOFMEMORY
;
1334 lstrcpyW(This
->sPath
, buffer
);
1336 This
->bDirty
= TRUE
;
1338 hr
= S_OK
; /* don't report any error occured while just caching information */
1341 if (!This
->sIcoPath
&& This
->sPath
) {
1342 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1343 if (!This
->sIcoPath
)
1344 return E_OUTOFMEMORY
;
1346 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1349 This
->bDirty
= TRUE
;
1355 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1357 ICOM_THIS(IShellLinkImpl
, iface
);
1358 char buffer
[MAX_PATH
];
1361 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1363 if (!GetFullPathNameA(pszFile
, MAX_PATH
, buffer
, &fname
))
1367 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1369 This
->sPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, buffer
);
1371 return E_OUTOFMEMORY
;
1373 This
->bDirty
= TRUE
;
1378 /**************************************************************************
1379 * IShellLink Implementation
1382 static ICOM_VTABLE(IShellLinkA
) slvt
=
1384 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1385 IShellLinkA_fnQueryInterface
,
1386 IShellLinkA_fnAddRef
,
1387 IShellLinkA_fnRelease
,
1388 IShellLinkA_fnGetPath
,
1389 IShellLinkA_fnGetIDList
,
1390 IShellLinkA_fnSetIDList
,
1391 IShellLinkA_fnGetDescription
,
1392 IShellLinkA_fnSetDescription
,
1393 IShellLinkA_fnGetWorkingDirectory
,
1394 IShellLinkA_fnSetWorkingDirectory
,
1395 IShellLinkA_fnGetArguments
,
1396 IShellLinkA_fnSetArguments
,
1397 IShellLinkA_fnGetHotkey
,
1398 IShellLinkA_fnSetHotkey
,
1399 IShellLinkA_fnGetShowCmd
,
1400 IShellLinkA_fnSetShowCmd
,
1401 IShellLinkA_fnGetIconLocation
,
1402 IShellLinkA_fnSetIconLocation
,
1403 IShellLinkA_fnSetRelativePath
,
1404 IShellLinkA_fnResolve
,
1405 IShellLinkA_fnSetPath
1409 /**************************************************************************
1410 * IShellLinkW_fnQueryInterface
1412 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1413 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1415 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1417 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
1420 /******************************************************************************
1421 * IShellLinkW_fnAddRef
1423 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1425 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1427 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1429 return IShellLinkA_AddRef((IShellLinkA
*)This
);
1431 /******************************************************************************
1432 * IShellLinkW_fnRelease
1435 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1437 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1439 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1441 return IShellLinkA_Release((IShellLinkA
*)This
);
1444 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1446 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1448 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",
1449 This
, pszFile
, cchMaxPath
, pfd
, fFlags
);
1454 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1458 FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1465 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1467 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1469 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1472 *ppidl
= ILClone( This
->pPidl
);
1479 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1481 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1483 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1486 ILFree( This
->pPidl
);
1487 This
->pPidl
= ILClone( pidl
);
1491 This
->bDirty
= TRUE
;
1496 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1498 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1500 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1504 if( This
->sDescription
)
1505 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1510 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1512 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1514 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1516 if (This
->sDescription
)
1517 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1518 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1519 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1520 if ( !This
->sDescription
)
1521 return E_OUTOFMEMORY
;
1523 lstrcpyW( This
->sDescription
, pszName
);
1524 This
->bDirty
= TRUE
;
1529 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1531 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1533 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1537 if( This
->sWorkDir
)
1538 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1543 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1545 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1547 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1550 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1551 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1552 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1553 if ( !This
->sWorkDir
)
1554 return E_OUTOFMEMORY
;
1556 lstrcpyW( This
->sWorkDir
, pszDir
);
1557 This
->bDirty
= TRUE
;
1562 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1564 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1566 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1571 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1576 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1578 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1580 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1583 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1584 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1585 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1587 return E_OUTOFMEMORY
;
1589 lstrcpyW( This
->sArgs
, pszArgs
);
1590 This
->bDirty
= TRUE
;
1595 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1597 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1599 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1601 *pwHotkey
=This
->wHotKey
;
1606 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1608 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1610 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1612 This
->wHotKey
= wHotkey
;
1613 This
->bDirty
= TRUE
;
1618 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1620 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1622 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1624 *piShowCmd
= This
->iShowCmd
;
1629 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1631 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1633 This
->iShowCmd
= iShowCmd
;
1634 This
->bDirty
= TRUE
;
1639 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1641 LPCITEMIDLIST pidlLast
;
1643 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1645 if (SUCCEEDED(hr
)) {
1648 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1650 if (SUCCEEDED(hr
)) {
1651 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1653 IExtractIconW_Release(pei
);
1656 IShellFolder_Release(psf
);
1662 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
, INT cchIconPath
, INT
*piIcon
)
1664 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1666 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1671 if (This
->sIcoPath
) {
1672 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1673 *piIcon
= This
->iIcoNdx
;
1677 if (This
->pPidl
|| This
->sPath
) {
1680 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1682 if (SUCCEEDED(hr
)) {
1683 /* first look for an icon using the PIDL (if present) */
1685 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1689 /* if we couldn't find an icon yet, look for it using the file system path */
1690 if (FAILED(hr
) && This
->sPath
) {
1693 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1695 if (SUCCEEDED(hr
)) {
1696 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1702 IShellFolder_Release(pdsk
);
1710 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
, INT iIcon
)
1712 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1714 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1717 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1718 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1719 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1720 if ( !This
->sIcoPath
)
1721 return E_OUTOFMEMORY
;
1722 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1724 This
->iIcoNdx
= iIcon
;
1725 This
->bDirty
= TRUE
;
1730 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1732 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1734 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1737 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1738 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1739 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1740 if ( !This
->sPathRel
)
1741 return E_OUTOFMEMORY
;
1743 lstrcpyW( This
->sPathRel
, pszPathRel
);
1744 This
->bDirty
= TRUE
;
1746 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1749 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1753 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1755 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1757 /*FIXME: use IResolveShellLink interface */
1759 if (!This
->sPath
&& This
->pPidl
) {
1760 WCHAR buffer
[MAX_PATH
];
1762 hr
= SHELL_GetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1764 if (SUCCEEDED(hr
) && *buffer
) {
1765 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1767 return E_OUTOFMEMORY
;
1769 lstrcpyW(This
->sPath
, buffer
);
1771 This
->bDirty
= TRUE
;
1773 hr
= S_OK
; /* don't report any error occured while just caching information */
1776 if (!This
->sIcoPath
&& This
->sPath
) {
1777 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1778 if (!This
->sIcoPath
)
1779 return E_OUTOFMEMORY
;
1781 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1784 This
->bDirty
= TRUE
;
1790 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
1792 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1793 WCHAR buffer
[MAX_PATH
];
1796 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
1798 if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
1802 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1804 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
1805 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
1807 return E_OUTOFMEMORY
;
1809 lstrcpyW( This
->sPath
, buffer
);
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