3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Nearly complete informations about the binary formats
22 * of .lnk files available at http://www.wotsit.org
27 #include "wine/port.h"
38 #ifdef HAVE_SYS_WAIT_H
39 # include <sys/wait.h>
44 #include "wine/debug.h"
54 #include "undocshell.h"
57 #include "shell32_main.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
63 /* link file formats */
65 /* flag1: lnk elements: simple link has 0x0B */
68 #define SCF_DESCRIPTION 4
69 #define SCF_RELATIVE 8
70 #define SCF_WORKDIR 0x10
72 #define SCF_CUSTOMICON 0x40
73 #define SCF_UNICODE 0x80
77 typedef struct _LINK_HEADER
79 DWORD dwSize
; /* 0x00 size of the header - 0x4c */
80 GUID MagicGuid
; /* 0x04 is CLSID_ShellLink */
81 DWORD dwFlags
; /* 0x14 describes elements following */
82 DWORD dwFileAttr
; /* 0x18 attributes of the target file */
83 FILETIME Time1
; /* 0x1c */
84 FILETIME Time2
; /* 0x24 */
85 FILETIME Time3
; /* 0x2c */
86 DWORD dwFileLength
; /* 0x34 File length */
87 DWORD nIcon
; /* 0x38 icon number */
88 DWORD fStartup
; /* 0x3c startup type */
89 DWORD wHotKey
; /* 0x40 hotkey */
90 DWORD Unknown5
; /* 0x44 */
91 DWORD Unknown6
; /* 0x48 */
92 } LINK_HEADER
, * PLINK_HEADER
;
94 #define SHLINK_LOCAL 0
95 #define SHLINK_REMOTE 1
97 typedef struct _LOCATION_INFO
103 DWORD dwLocalPathOfs
;
104 DWORD dwNetworkVolTableOfs
;
105 DWORD dwFinalPathOfs
;
108 typedef struct _LOCAL_VOLUME_INFO
118 static IShellLinkAVtbl slvt
;
119 static IShellLinkWVtbl slvtw
;
120 static IPersistFileVtbl pfvt
;
121 static IPersistStreamVtbl psvt
;
123 /* IShellLink Implementation */
127 IShellLinkAVtbl
*lpVtbl
;
130 IShellLinkWVtbl
*lpvtblw
;
131 IPersistFileVtbl
*lpvtblPersistFile
;
132 IPersistStreamVtbl
*lpvtblPersistStream
;
134 /* data structures according to the informations in the link */
153 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
154 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
156 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
157 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
159 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
160 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
162 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
);
164 /* strdup on the process heap */
165 inline static LPWSTR
HEAP_strdupAtoW( HANDLE heap
, DWORD flags
, LPCSTR str
)
167 INT len
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, NULL
, 0 );
168 LPWSTR p
= HeapAlloc( heap
, flags
, len
*sizeof (WCHAR
) );
171 MultiByteToWideChar( CP_ACP
, 0, str
, -1, p
, len
);
176 /**************************************************************************
177 * IPersistFile_QueryInterface
179 static HRESULT WINAPI
IPersistFile_fnQueryInterface(
184 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
186 TRACE("(%p)\n",This
);
188 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
191 /******************************************************************************
192 * IPersistFile_AddRef
194 static ULONG WINAPI
IPersistFile_fnAddRef(IPersistFile
* iface
)
196 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
198 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
200 return IShellLinkA_AddRef((IShellLinkA
*)This
);
202 /******************************************************************************
203 * IPersistFile_Release
205 static ULONG WINAPI
IPersistFile_fnRelease(IPersistFile
* iface
)
207 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
209 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
211 return IShellLinkA_Release((IShellLinkA
*)This
);
214 static HRESULT WINAPI
IPersistFile_fnGetClassID(IPersistFile
* iface
, CLSID
*pClassID
)
216 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
217 FIXME("(%p)\n",This
);
220 static HRESULT WINAPI
IPersistFile_fnIsDirty(IPersistFile
* iface
)
222 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
224 TRACE("(%p)\n",This
);
231 static HRESULT WINAPI
IPersistFile_fnLoad(IPersistFile
* iface
, LPCOLESTR pszFileName
, DWORD dwMode
)
233 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
234 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
238 TRACE("(%p, %s)\n",This
, debugstr_w(pszFileName
));
240 r
= CreateStreamOnFile(pszFileName
, dwMode
, &stm
);
243 r
= IPersistStream_Load(StreamThis
, stm
);
244 ShellLink_UpdatePath(This
->sPathRel
, pszFileName
, This
->sWorkDir
, &This
->sPath
);
245 IStream_Release( stm
);
246 This
->bDirty
= FALSE
;
252 static BOOL
StartLinkProcessor( LPCOLESTR szLink
)
254 static const WCHAR szFormat
[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
255 ' ','-','r',' ','"','%','s','"',0 };
259 PROCESS_INFORMATION pi
;
261 len
= sizeof(szFormat
) + lstrlenW( szLink
) * sizeof(WCHAR
);
262 buffer
= HeapAlloc( GetProcessHeap(), 0, len
);
266 wsprintfW( buffer
, szFormat
, szLink
);
268 TRACE("starting %s\n",debugstr_w(buffer
));
270 memset(&si
, 0, sizeof(si
));
272 if (!CreateProcessW( NULL
, buffer
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
)) return FALSE
;
274 /* wait for a while to throttle the creation of linker processes */
275 if( WAIT_OBJECT_0
!= WaitForSingleObject( pi
.hProcess
, 10000 ) )
276 WARN("Timed out waiting for shell linker\n");
278 CloseHandle( pi
.hProcess
);
279 CloseHandle( pi
.hThread
);
284 static HRESULT WINAPI
IPersistFile_fnSave(IPersistFile
* iface
, LPCOLESTR pszFileName
, BOOL fRemember
)
286 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
287 IPersistStream
*StreamThis
= (IPersistStream
*)&This
->lpvtblPersistStream
;
291 TRACE("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
293 if (!pszFileName
|| !This
->sPath
)
296 r
= CreateStreamOnFile(pszFileName
, STGM_READWRITE
| STGM_CREATE
, &stm
);
299 r
= IPersistStream_Save(StreamThis
, stm
, FALSE
);
300 IStream_Release( stm
);
304 StartLinkProcessor( pszFileName
);
306 This
->bDirty
= FALSE
;
310 DeleteFileW( pszFileName
);
311 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName
) );
318 static HRESULT WINAPI
IPersistFile_fnSaveCompleted(IPersistFile
* iface
, LPCOLESTR pszFileName
)
320 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
321 FIXME("(%p)->(%s)\n",This
,debugstr_w(pszFileName
));
324 static HRESULT WINAPI
IPersistFile_fnGetCurFile(IPersistFile
* iface
, LPOLESTR
*ppszFileName
)
326 _ICOM_THIS_From_IPersistFile(IShellLinkImpl
, iface
);
327 FIXME("(%p)\n",This
);
331 static IPersistFileVtbl pfvt
=
333 IPersistFile_fnQueryInterface
,
334 IPersistFile_fnAddRef
,
335 IPersistFile_fnRelease
,
336 IPersistFile_fnGetClassID
,
337 IPersistFile_fnIsDirty
,
340 IPersistFile_fnSaveCompleted
,
341 IPersistFile_fnGetCurFile
344 /************************************************************************
345 * IPersistStream_QueryInterface
347 static HRESULT WINAPI
IPersistStream_fnQueryInterface(
348 IPersistStream
* iface
,
352 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
354 TRACE("(%p)\n",This
);
356 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvoid
);
359 /************************************************************************
360 * IPersistStream_Release
362 static ULONG WINAPI
IPersistStream_fnRelease(
363 IPersistStream
* iface
)
365 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
367 TRACE("(%p)\n",This
);
369 return IShellLinkA_Release((IShellLinkA
*)This
);
372 /************************************************************************
373 * IPersistStream_AddRef
375 static ULONG WINAPI
IPersistStream_fnAddRef(
376 IPersistStream
* iface
)
378 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
380 TRACE("(%p)\n",This
);
382 return IShellLinkA_AddRef((IShellLinkA
*)This
);
385 /************************************************************************
386 * IPersistStream_GetClassID
389 static HRESULT WINAPI
IPersistStream_fnGetClassID(
390 IPersistStream
* iface
,
393 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
395 TRACE("(%p)\n", This
);
400 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
405 /************************************************************************
406 * IPersistStream_IsDirty (IPersistStream)
408 static HRESULT WINAPI
IPersistStream_fnIsDirty(
409 IPersistStream
* iface
)
411 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
413 TRACE("(%p)\n", This
);
419 static HRESULT
Stream_LoadString( IStream
* stm
, BOOL unicode
, LPWSTR
*pstr
)
430 r
= IStream_Read(stm
, &len
, sizeof(len
), &count
);
431 if ( FAILED (r
) || ( count
!= sizeof(len
) ) )
435 len
*= sizeof (WCHAR
);
437 TRACE("reading %d\n", len
);
438 temp
= HeapAlloc(GetProcessHeap(), 0, len
+sizeof(WCHAR
));
440 return E_OUTOFMEMORY
;
442 r
= IStream_Read(stm
, temp
, len
, &count
);
443 if( FAILED (r
) || ( count
!= len
) )
445 HeapFree( GetProcessHeap(), 0, temp
);
449 TRACE("read %s\n", debugstr_an(temp
,len
));
451 /* convert to unicode if necessary */
454 count
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, NULL
, 0 );
455 str
= HeapAlloc( GetProcessHeap(), 0, (count
+1)*sizeof (WCHAR
) );
457 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
) temp
, len
, str
, count
);
458 HeapFree( GetProcessHeap(), 0, temp
);
472 static HRESULT
Stream_LoadLocation( IStream
* stm
)
481 r
= IStream_Read( stm
, &size
, sizeof(size
), &count
);
484 if( count
!= sizeof(loc
->dwTotalSize
) )
487 loc
= HeapAlloc( GetProcessHeap(), 0, size
);
489 return E_OUTOFMEMORY
;
491 r
= IStream_Read( stm
, &loc
->dwHeaderSize
, size
-sizeof(size
), &count
);
494 if( count
!= (size
- sizeof(size
)) )
499 loc
->dwTotalSize
= size
;
501 TRACE("Read %ld bytes\n",count
);
503 /* FIXME: do something useful with it */
504 HeapFree( GetProcessHeap(), 0, loc
);
508 HeapFree( GetProcessHeap(), 0, loc
);
512 /************************************************************************
513 * IPersistStream_Load (IPersistStream)
515 static HRESULT WINAPI
IPersistStream_fnLoad(
516 IPersistStream
* iface
,
522 WCHAR sTemp
[MAX_PATH
];
525 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
527 TRACE("(%p)(%p)\n", This
, stm
);
530 return STG_E_INVALIDPOINTER
;
533 r
= IStream_Read(stm
, &hdr
, sizeof(hdr
), &dwBytesRead
);
537 if( dwBytesRead
!= sizeof(hdr
))
539 if( hdr
.dwSize
!= sizeof(hdr
))
541 if( !IsEqualIID(&hdr
.MagicGuid
, &CLSID_ShellLink
) )
544 /* if( hdr.dwFlags & SCF_PIDL ) */ /* FIXME: seems to always have a PIDL */
546 r
= ILLoadFromStream( stm
, &This
->pPidl
);
550 This
->wHotKey
= (WORD
)hdr
.wHotKey
;
551 This
->iIcoNdx
= hdr
.nIcon
;
552 FileTimeToSystemTime (&hdr
.Time1
, &This
->time1
);
553 FileTimeToSystemTime (&hdr
.Time2
, &This
->time2
);
554 FileTimeToSystemTime (&hdr
.Time3
, &This
->time3
);
556 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time1
, NULL
, sTemp
, 256);
557 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
558 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time2
, NULL
, sTemp
, 256);
559 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
560 GetDateFormatW(LOCALE_USER_DEFAULT
,DATE_SHORTDATE
,&This
->time3
, NULL
, sTemp
, 256);
561 TRACE("-- time1: %s\n", debugstr_w(sTemp
) );
564 if( hdr
.dwFlags
& SCF_NORMAL
)
565 r
= Stream_LoadLocation( stm
);
568 unicode
= hdr
.dwFlags
& SCF_UNICODE
;
569 if( hdr
.dwFlags
& SCF_DESCRIPTION
)
571 r
= Stream_LoadString( stm
, unicode
, &This
->sDescription
);
572 TRACE("Description -> %s\n",debugstr_w(This
->sDescription
));
577 if( hdr
.dwFlags
& SCF_RELATIVE
)
579 r
= Stream_LoadString( stm
, unicode
, &This
->sPathRel
);
580 TRACE("Relative Path-> %s\n",debugstr_w(This
->sPathRel
));
585 if( hdr
.dwFlags
& SCF_WORKDIR
)
587 r
= Stream_LoadString( stm
, unicode
, &This
->sWorkDir
);
588 TRACE("Working Dir -> %s\n",debugstr_w(This
->sWorkDir
));
593 if( hdr
.dwFlags
& SCF_ARGS
)
595 r
= Stream_LoadString( stm
, unicode
, &This
->sArgs
);
596 TRACE("Working Dir -> %s\n",debugstr_w(This
->sArgs
));
601 if( hdr
.dwFlags
& SCF_CUSTOMICON
)
603 r
= Stream_LoadString( stm
, unicode
, &This
->sIcoPath
);
604 TRACE("Icon file -> %s\n",debugstr_w(This
->sIcoPath
));
618 /************************************************************************
621 * Helper function for IPersistStream_Save. Writes a unicode string
622 * with terminating nul byte to a stream, preceded by the its length.
624 static HRESULT
Stream_WriteString( IStream
* stm
, LPCWSTR str
)
626 USHORT len
= lstrlenW( str
) + 1;
630 r
= IStream_Write( stm
, &len
, sizeof(len
), &count
);
634 len
*= sizeof(WCHAR
);
636 r
= IStream_Write( stm
, str
, len
, &count
);
643 static HRESULT
Stream_WriteLocationInfo( IStream
* stm
, LPCWSTR filename
)
648 FIXME("writing empty location info\n");
650 memset( &loc
, 0, sizeof(loc
) );
651 loc
.dwTotalSize
= sizeof(loc
) - sizeof(loc
.dwTotalSize
);
653 /* FIXME: fill this in */
655 return IStream_Write( stm
, &loc
, loc
.dwTotalSize
, &count
);
658 /************************************************************************
659 * IPersistStream_Save (IPersistStream)
661 * FIXME: makes assumptions about byte order
663 static HRESULT WINAPI
IPersistStream_fnSave(
664 IPersistStream
* iface
,
668 static const WCHAR wOpen
[] = {'o','p','e','n',0};
671 WCHAR exePath
[MAX_PATH
];
675 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
677 TRACE("(%p) %p %x\n", This
, stm
, fClearDirty
);
683 SHELL_FindExecutable(NULL
, This
->sPath
, wOpen
, exePath
, MAX_PATH
, NULL
, NULL
, NULL
, NULL
);
685 * windows can create lnk files to executables that do not exist yet
686 * so if the executable does not exist the just trust the path they
689 if( !*exePath
) strcpyW(exePath
,This
->sPath
);
692 /* if there's no PIDL, generate one */
693 if( ! This
->pPidl
) This
->pPidl
= ILCreateFromPathW(exePath
);
695 memset(&header
, 0, sizeof(header
));
696 header
.dwSize
= sizeof(header
);
697 memcpy(&header
.MagicGuid
, &CLSID_ShellLink
, sizeof(header
.MagicGuid
) );
699 header
.wHotKey
= This
->wHotKey
;
700 header
.nIcon
= This
->iIcoNdx
;
701 header
.dwFlags
= SCF_UNICODE
; /* strings are in unicode */
702 header
.dwFlags
|= SCF_NORMAL
; /* how do we determine this ? */
704 header
.dwFlags
|= SCF_PIDL
;
705 if( This
->sDescription
)
706 header
.dwFlags
|= SCF_DESCRIPTION
;
708 header
.dwFlags
|= SCF_WORKDIR
;
710 header
.dwFlags
|= SCF_ARGS
;
712 header
.dwFlags
|= SCF_CUSTOMICON
;
714 SystemTimeToFileTime ( &This
->time1
, &header
.Time1
);
715 SystemTimeToFileTime ( &This
->time2
, &header
.Time2
);
716 SystemTimeToFileTime ( &This
->time3
, &header
.Time3
);
718 /* write the Shortcut header */
719 r
= IStream_Write( stm
, &header
, sizeof(header
), &count
);
722 ERR("Write failed at %d\n",__LINE__
);
726 TRACE("Writing pidl \n");
728 /* write the PIDL to the shortcut */
731 r
= ILSaveToStream( stm
, This
->pPidl
);
734 ERR("Failed to write PIDL at %d\n",__LINE__
);
739 Stream_WriteLocationInfo( stm
, exePath
);
741 TRACE("Description = %s\n", debugstr_w(This
->sDescription
));
742 if( This
->sDescription
)
743 r
= Stream_WriteString( stm
, This
->sDescription
);
746 r
= Stream_WriteString( stm
, This
->sPathRel
);
749 r
= Stream_WriteString( stm
, This
->sWorkDir
);
752 r
= Stream_WriteString( stm
, This
->sArgs
);
755 r
= Stream_WriteString( stm
, This
->sIcoPath
);
760 /************************************************************************
761 * IPersistStream_GetSizeMax (IPersistStream)
763 static HRESULT WINAPI
IPersistStream_fnGetSizeMax(
764 IPersistStream
* iface
,
765 ULARGE_INTEGER
* pcbSize
)
767 _ICOM_THIS_From_IPersistStream(IShellLinkImpl
, iface
);
769 TRACE("(%p)\n", This
);
774 static IPersistStreamVtbl psvt
=
776 IPersistStream_fnQueryInterface
,
777 IPersistStream_fnAddRef
,
778 IPersistStream_fnRelease
,
779 IPersistStream_fnGetClassID
,
780 IPersistStream_fnIsDirty
,
781 IPersistStream_fnLoad
,
782 IPersistStream_fnSave
,
783 IPersistStream_fnGetSizeMax
786 /**************************************************************************
787 * IShellLink_Constructor
789 HRESULT WINAPI
IShellLink_Constructor (
790 IUnknown
* pUnkOuter
,
796 TRACE("unkOut=%p riid=%s\n",pUnkOuter
, debugstr_guid(riid
));
800 if(pUnkOuter
) return CLASS_E_NOAGGREGATION
;
801 sl
= (IShellLinkImpl
*) LocalAlloc(GMEM_ZEROINIT
,sizeof(IShellLinkImpl
));
802 if (!sl
) return E_OUTOFMEMORY
;
806 sl
->lpvtblw
= &slvtw
;
807 sl
->lpvtblPersistFile
= &pfvt
;
808 sl
->lpvtblPersistStream
= &psvt
;
809 sl
->iShowCmd
= SW_SHOWNORMAL
;
812 TRACE("(%p)->()\n",sl
);
814 if (IsEqualIID(riid
, &IID_IUnknown
) ||
815 IsEqualIID(riid
, &IID_IShellLinkA
))
817 else if (IsEqualIID(riid
, &IID_IShellLinkW
))
818 *ppv
= &(sl
->lpvtblw
);
820 LocalFree((HLOCAL
)sl
);
821 ERR("E_NOINTERFACE\n");
822 return E_NOINTERFACE
;
829 static BOOL
SHELL_ExistsFileW(LPCWSTR path
)
831 HANDLE hfile
= CreateFileW(path
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, NULL
);
833 if (hfile
!= INVALID_HANDLE_VALUE
) {
840 /**************************************************************************
841 * ShellLink_UpdatePath
842 * update absolute path in sPath using relative path in sPathRel
844 static HRESULT
ShellLink_UpdatePath(LPWSTR sPathRel
, LPCWSTR path
, LPCWSTR sWorkDir
, LPWSTR
* psPath
)
846 if (!path
|| !psPath
)
849 if (!*psPath
&& sPathRel
) {
850 WCHAR buffer
[2*MAX_PATH
], abs_path
[2*MAX_PATH
];
853 /* first try if [directory of link file] + [relative path] finds an existing file */
855 GetFullPathNameW( path
, MAX_PATH
*2, buffer
, &final
);
858 lstrcpyW(final
, sPathRel
);
862 if (SHELL_ExistsFileW(buffer
)) {
863 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
864 lstrcpyW(abs_path
, buffer
);
866 /* try if [working directory] + [relative path] finds an existing file */
868 lstrcpyW(buffer
, sWorkDir
);
869 lstrcpyW(PathAddBackslashW(buffer
), sPathRel
);
871 if (SHELL_ExistsFileW(buffer
))
872 if (!GetFullPathNameW(buffer
, MAX_PATH
, abs_path
, &final
))
873 lstrcpyW(abs_path
, buffer
);
877 /* FIXME: This is even not enough - not all shell links can be resolved using this algorithm. */
879 lstrcpyW(abs_path
, sPathRel
);
881 *psPath
= HeapAlloc(GetProcessHeap(), 0, (lstrlenW(abs_path
)+1)*sizeof(WCHAR
));
883 return E_OUTOFMEMORY
;
885 lstrcpyW(*psPath
, abs_path
);
891 /**************************************************************************
892 * IShellLink_ConstructFromFile
894 HRESULT WINAPI
IShellLink_ConstructFromFile (
903 HRESULT hr
= IShellLink_Constructor(NULL
, riid
, (LPVOID
*)&psl
);
910 hr
= IShellLinkW_QueryInterface(psl
, &IID_IPersistFile
, (LPVOID
*)&ppf
);
913 WCHAR path
[MAX_PATH
];
915 if (SHGetPathFromIDListW(pidl
, path
))
916 hr
= IPersistFile_Load(ppf
, path
, 0);
921 *ppv
= (IUnknown
*) psl
;
923 IPersistFile_Release(ppf
);
927 IShellLinkW_Release(psl
);
933 /**************************************************************************
934 * IShellLinkA_QueryInterface
936 static HRESULT WINAPI
IShellLinkA_fnQueryInterface( IShellLinkA
* iface
, REFIID riid
, LPVOID
*ppvObj
)
938 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
940 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
944 if(IsEqualIID(riid
, &IID_IUnknown
) ||
945 IsEqualIID(riid
, &IID_IShellLinkA
))
949 else if(IsEqualIID(riid
, &IID_IShellLinkW
))
951 *ppvObj
= (IShellLinkW
*)&(This
->lpvtblw
);
953 else if(IsEqualIID(riid
, &IID_IPersistFile
))
955 *ppvObj
= (IPersistFile
*)&(This
->lpvtblPersistFile
);
957 else if(IsEqualIID(riid
, &IID_IPersistStream
))
959 *ppvObj
= (IPersistStream
*)&(This
->lpvtblPersistStream
);
964 IUnknown_AddRef((IUnknown
*)(*ppvObj
));
965 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
968 TRACE("-- Interface: E_NOINTERFACE\n");
969 return E_NOINTERFACE
;
971 /******************************************************************************
974 static ULONG WINAPI
IShellLinkA_fnAddRef(IShellLinkA
* iface
)
976 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
978 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
980 return ++(This
->ref
);
982 /******************************************************************************
983 * IShellLinkA_Release
985 static ULONG WINAPI
IShellLinkA_fnRelease(IShellLinkA
* iface
)
987 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
989 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
994 TRACE("-- destroying IShellLink(%p)\n",This
);
997 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1000 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1003 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1005 if (This
->sDescription
)
1006 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1009 HeapFree(GetProcessHeap(),0,This
->sPath
);
1012 ILFree(This
->pPidl
);
1014 LocalFree((HANDLE
)This
);
1019 static HRESULT WINAPI
IShellLinkA_fnGetPath(IShellLinkA
* iface
, LPSTR pszFile
,
1020 INT cchMaxPath
, WIN32_FIND_DATAA
*pfd
, DWORD fFlags
)
1022 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1024 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
1025 This
, pszFile
, cchMaxPath
, pfd
, fFlags
, debugstr_w(This
->sPath
));
1030 WideCharToMultiByte( CP_ACP
, 0, This
->sPath
, -1,
1031 pszFile
, cchMaxPath
, NULL
, NULL
);
1033 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1038 static HRESULT WINAPI
IShellLinkA_fnGetIDList(IShellLinkA
* iface
, LPITEMIDLIST
* ppidl
)
1040 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1042 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1044 *ppidl
= ILClone(This
->pPidl
);
1049 static HRESULT WINAPI
IShellLinkA_fnSetIDList(IShellLinkA
* iface
, LPCITEMIDLIST pidl
)
1051 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1053 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1056 ILFree(This
->pPidl
);
1057 This
->pPidl
= ILClone (pidl
);
1058 This
->bDirty
= TRUE
;
1063 static HRESULT WINAPI
IShellLinkA_fnGetDescription(IShellLinkA
* iface
, LPSTR pszName
,INT cchMaxName
)
1065 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1067 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1071 if( This
->sDescription
)
1072 WideCharToMultiByte( CP_ACP
, 0, This
->sDescription
, -1,
1073 pszName
, cchMaxName
, NULL
, NULL
);
1077 static HRESULT WINAPI
IShellLinkA_fnSetDescription(IShellLinkA
* iface
, LPCSTR pszName
)
1079 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1081 TRACE("(%p)->(pName=%s)\n", This
, pszName
);
1083 if (This
->sDescription
)
1084 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1085 This
->sDescription
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszName
);
1086 if ( !This
->sDescription
)
1087 return E_OUTOFMEMORY
;
1089 This
->bDirty
= TRUE
;
1094 static HRESULT WINAPI
IShellLinkA_fnGetWorkingDirectory(IShellLinkA
* iface
, LPSTR pszDir
,INT cchMaxPath
)
1096 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1098 TRACE("(%p)->(%p len=%u)\n", This
, pszDir
, cchMaxPath
);
1102 if( This
->sWorkDir
)
1103 WideCharToMultiByte( CP_ACP
, 0, This
->sWorkDir
, -1,
1104 pszDir
, cchMaxPath
, NULL
, NULL
);
1109 static HRESULT WINAPI
IShellLinkA_fnSetWorkingDirectory(IShellLinkA
* iface
, LPCSTR pszDir
)
1111 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1113 TRACE("(%p)->(dir=%s)\n",This
, pszDir
);
1116 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1117 This
->sWorkDir
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir
);
1118 if ( !This
->sWorkDir
)
1119 return E_OUTOFMEMORY
;
1121 This
->bDirty
= TRUE
;
1126 static HRESULT WINAPI
IShellLinkA_fnGetArguments(IShellLinkA
* iface
, LPSTR pszArgs
,INT cchMaxPath
)
1128 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1130 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1135 WideCharToMultiByte( CP_ACP
, 0, This
->sArgs
, -1,
1136 pszArgs
, cchMaxPath
, NULL
, NULL
);
1141 static HRESULT WINAPI
IShellLinkA_fnSetArguments(IShellLinkA
* iface
, LPCSTR pszArgs
)
1143 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1145 TRACE("(%p)->(args=%s)\n",This
, pszArgs
);
1148 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1149 This
->sArgs
= HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs
);
1151 return E_OUTOFMEMORY
;
1153 This
->bDirty
= TRUE
;
1158 static HRESULT WINAPI
IShellLinkA_fnGetHotkey(IShellLinkA
* iface
, WORD
*pwHotkey
)
1160 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1162 TRACE("(%p)->(%p)(0x%08x)\n",This
, pwHotkey
, This
->wHotKey
);
1164 *pwHotkey
= This
->wHotKey
;
1169 static HRESULT WINAPI
IShellLinkA_fnSetHotkey(IShellLinkA
* iface
, WORD wHotkey
)
1171 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1173 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1175 This
->wHotKey
= wHotkey
;
1176 This
->bDirty
= TRUE
;
1181 static HRESULT WINAPI
IShellLinkA_fnGetShowCmd(IShellLinkA
* iface
, INT
*piShowCmd
)
1183 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1185 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1186 *piShowCmd
= This
->iShowCmd
;
1190 static HRESULT WINAPI
IShellLinkA_fnSetShowCmd(IShellLinkA
* iface
, INT iShowCmd
)
1192 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1194 TRACE("(%p) %d\n",This
, iShowCmd
);
1196 This
->iShowCmd
= iShowCmd
;
1197 This
->bDirty
= TRUE
;
1202 static HRESULT
SHELL_PidlGeticonLocationA(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1204 LPCITEMIDLIST pidlLast
;
1206 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1208 if (SUCCEEDED(hr
)) {
1211 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconA
, NULL
, (LPVOID
*)&pei
);
1213 if (SUCCEEDED(hr
)) {
1214 hr
= IExtractIconA_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1216 IExtractIconA_Release(pei
);
1219 IShellFolder_Release(psf
);
1225 static HRESULT WINAPI
IShellLinkA_fnGetIconLocation(IShellLinkA
* iface
, LPSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1227 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1229 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1234 if (This
->sIcoPath
) {
1235 WideCharToMultiByte(CP_ACP
, 0, This
->sIcoPath
, -1, pszIconPath
, cchIconPath
, NULL
, NULL
);
1236 *piIcon
= This
->iIcoNdx
;
1240 if (This
->pPidl
|| This
->sPath
) {
1243 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1245 if (SUCCEEDED(hr
)) {
1246 /* first look for an icon using the PIDL (if present) */
1248 hr
= SHELL_PidlGeticonLocationA(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1252 /* if we couldn't find an icon yet, look for it using the file system path */
1253 if (FAILED(hr
) && This
->sPath
) {
1256 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1258 if (SUCCEEDED(hr
)) {
1259 hr
= SHELL_PidlGeticonLocationA(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1265 IShellFolder_Release(pdsk
);
1273 static HRESULT WINAPI
IShellLinkA_fnSetIconLocation(IShellLinkA
* iface
, LPCSTR pszIconPath
,INT iIcon
)
1275 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1277 TRACE("(%p)->(path=%s iicon=%u)\n",This
, pszIconPath
, iIcon
);
1280 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1281 This
->sIcoPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath
);
1282 if ( !This
->sIcoPath
)
1283 return E_OUTOFMEMORY
;
1285 This
->iIcoNdx
= iIcon
;
1286 This
->bDirty
= TRUE
;
1291 static HRESULT WINAPI
IShellLinkA_fnSetRelativePath(IShellLinkA
* iface
, LPCSTR pszPathRel
, DWORD dwReserved
)
1293 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1295 FIXME("(%p)->(path=%s %lx)\n",This
, pszPathRel
, dwReserved
);
1298 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1299 This
->sPathRel
= HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel
);
1300 This
->bDirty
= TRUE
;
1302 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1305 static HRESULT WINAPI
IShellLinkA_fnResolve(IShellLinkA
* iface
, HWND hwnd
, DWORD fFlags
)
1309 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1311 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1313 /*FIXME: use IResolveShellLink interface */
1315 if (!This
->sPath
&& This
->pPidl
) {
1316 WCHAR buffer
[MAX_PATH
];
1318 hr
= SHELL_GetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1320 if (SUCCEEDED(hr
) && *buffer
) {
1321 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1323 return E_OUTOFMEMORY
;
1325 lstrcpyW(This
->sPath
, buffer
);
1327 This
->bDirty
= TRUE
;
1329 hr
= S_OK
; /* don't report an error occurred while just caching information */
1332 if (!This
->sIcoPath
&& This
->sPath
) {
1333 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1334 if (!This
->sIcoPath
)
1335 return E_OUTOFMEMORY
;
1337 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1340 This
->bDirty
= TRUE
;
1346 static HRESULT WINAPI
IShellLinkA_fnSetPath(IShellLinkA
* iface
, LPCSTR pszFile
)
1348 IShellLinkImpl
*This
= (IShellLinkImpl
*)iface
;
1349 char buffer
[MAX_PATH
];
1352 TRACE("(%p)->(path=%s)\n",This
, pszFile
);
1354 if (!GetFullPathNameA(pszFile
, MAX_PATH
, buffer
, &fname
))
1358 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1360 This
->sPath
= HEAP_strdupAtoW(GetProcessHeap(), 0, buffer
);
1362 return E_OUTOFMEMORY
;
1364 This
->bDirty
= TRUE
;
1369 /**************************************************************************
1370 * IShellLink Implementation
1373 static IShellLinkAVtbl slvt
=
1375 IShellLinkA_fnQueryInterface
,
1376 IShellLinkA_fnAddRef
,
1377 IShellLinkA_fnRelease
,
1378 IShellLinkA_fnGetPath
,
1379 IShellLinkA_fnGetIDList
,
1380 IShellLinkA_fnSetIDList
,
1381 IShellLinkA_fnGetDescription
,
1382 IShellLinkA_fnSetDescription
,
1383 IShellLinkA_fnGetWorkingDirectory
,
1384 IShellLinkA_fnSetWorkingDirectory
,
1385 IShellLinkA_fnGetArguments
,
1386 IShellLinkA_fnSetArguments
,
1387 IShellLinkA_fnGetHotkey
,
1388 IShellLinkA_fnSetHotkey
,
1389 IShellLinkA_fnGetShowCmd
,
1390 IShellLinkA_fnSetShowCmd
,
1391 IShellLinkA_fnGetIconLocation
,
1392 IShellLinkA_fnSetIconLocation
,
1393 IShellLinkA_fnSetRelativePath
,
1394 IShellLinkA_fnResolve
,
1395 IShellLinkA_fnSetPath
1399 /**************************************************************************
1400 * IShellLinkW_fnQueryInterface
1402 static HRESULT WINAPI
IShellLinkW_fnQueryInterface(
1403 IShellLinkW
* iface
, REFIID riid
, LPVOID
*ppvObj
)
1405 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1407 return IShellLinkA_QueryInterface((IShellLinkA
*)This
, riid
, ppvObj
);
1410 /******************************************************************************
1411 * IShellLinkW_fnAddRef
1413 static ULONG WINAPI
IShellLinkW_fnAddRef(IShellLinkW
* iface
)
1415 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1417 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1419 return IShellLinkA_AddRef((IShellLinkA
*)This
);
1421 /******************************************************************************
1422 * IShellLinkW_fnRelease
1425 static ULONG WINAPI
IShellLinkW_fnRelease(IShellLinkW
* iface
)
1427 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1429 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
1431 return IShellLinkA_Release((IShellLinkA
*)This
);
1434 static HRESULT WINAPI
IShellLinkW_fnGetPath(IShellLinkW
* iface
, LPWSTR pszFile
,INT cchMaxPath
, WIN32_FIND_DATAW
*pfd
, DWORD fFlags
)
1436 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1438 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",
1439 This
, pszFile
, cchMaxPath
, pfd
, fFlags
);
1444 lstrcpynW( pszFile
, This
->sPath
, cchMaxPath
);
1446 if (pfd
) FIXME("(%p): WIN32_FIND_DATA is not yet filled.\n", This
);
1451 static HRESULT WINAPI
IShellLinkW_fnGetIDList(IShellLinkW
* iface
, LPITEMIDLIST
* ppidl
)
1453 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1455 TRACE("(%p)->(ppidl=%p)\n",This
, ppidl
);
1458 *ppidl
= ILClone( This
->pPidl
);
1465 static HRESULT WINAPI
IShellLinkW_fnSetIDList(IShellLinkW
* iface
, LPCITEMIDLIST pidl
)
1467 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1469 TRACE("(%p)->(pidl=%p)\n",This
, pidl
);
1472 ILFree( This
->pPidl
);
1473 This
->pPidl
= ILClone( pidl
);
1477 This
->bDirty
= TRUE
;
1482 static HRESULT WINAPI
IShellLinkW_fnGetDescription(IShellLinkW
* iface
, LPWSTR pszName
,INT cchMaxName
)
1484 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1486 TRACE("(%p)->(%p len=%u)\n",This
, pszName
, cchMaxName
);
1490 if( This
->sDescription
)
1491 lstrcpynW( pszName
, This
->sDescription
, cchMaxName
);
1496 static HRESULT WINAPI
IShellLinkW_fnSetDescription(IShellLinkW
* iface
, LPCWSTR pszName
)
1498 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1500 TRACE("(%p)->(desc=%s)\n",This
, debugstr_w(pszName
));
1502 if (This
->sDescription
)
1503 HeapFree(GetProcessHeap(), 0, This
->sDescription
);
1504 This
->sDescription
= HeapAlloc( GetProcessHeap(), 0,
1505 (lstrlenW( pszName
)+1)*sizeof(WCHAR
) );
1506 if ( !This
->sDescription
)
1507 return E_OUTOFMEMORY
;
1509 lstrcpyW( This
->sDescription
, pszName
);
1510 This
->bDirty
= TRUE
;
1515 static HRESULT WINAPI
IShellLinkW_fnGetWorkingDirectory(IShellLinkW
* iface
, LPWSTR pszDir
,INT cchMaxPath
)
1517 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1519 TRACE("(%p)->(%p len %u)\n", This
, pszDir
, cchMaxPath
);
1523 if( This
->sWorkDir
)
1524 lstrcpynW( pszDir
, This
->sWorkDir
, cchMaxPath
);
1529 static HRESULT WINAPI
IShellLinkW_fnSetWorkingDirectory(IShellLinkW
* iface
, LPCWSTR pszDir
)
1531 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1533 TRACE("(%p)->(dir=%s)\n",This
, debugstr_w(pszDir
));
1536 HeapFree(GetProcessHeap(), 0, This
->sWorkDir
);
1537 This
->sWorkDir
= HeapAlloc( GetProcessHeap(), 0,
1538 (lstrlenW( pszDir
)+1)*sizeof (WCHAR
) );
1539 if ( !This
->sWorkDir
)
1540 return E_OUTOFMEMORY
;
1541 lstrcpyW( This
->sWorkDir
, pszDir
);
1542 This
->bDirty
= TRUE
;
1547 static HRESULT WINAPI
IShellLinkW_fnGetArguments(IShellLinkW
* iface
, LPWSTR pszArgs
,INT cchMaxPath
)
1549 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1551 TRACE("(%p)->(%p len=%u)\n", This
, pszArgs
, cchMaxPath
);
1556 lstrcpynW( pszArgs
, This
->sArgs
, cchMaxPath
);
1561 static HRESULT WINAPI
IShellLinkW_fnSetArguments(IShellLinkW
* iface
, LPCWSTR pszArgs
)
1563 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1565 TRACE("(%p)->(args=%s)\n",This
, debugstr_w(pszArgs
));
1568 HeapFree(GetProcessHeap(), 0, This
->sArgs
);
1569 This
->sArgs
= HeapAlloc( GetProcessHeap(), 0,
1570 (lstrlenW( pszArgs
)+1)*sizeof (WCHAR
) );
1572 return E_OUTOFMEMORY
;
1573 lstrcpyW( This
->sArgs
, pszArgs
);
1574 This
->bDirty
= TRUE
;
1579 static HRESULT WINAPI
IShellLinkW_fnGetHotkey(IShellLinkW
* iface
, WORD
*pwHotkey
)
1581 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1583 TRACE("(%p)->(%p)\n",This
, pwHotkey
);
1585 *pwHotkey
=This
->wHotKey
;
1590 static HRESULT WINAPI
IShellLinkW_fnSetHotkey(IShellLinkW
* iface
, WORD wHotkey
)
1592 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1594 TRACE("(%p)->(hotkey=%x)\n",This
, wHotkey
);
1596 This
->wHotKey
= wHotkey
;
1597 This
->bDirty
= TRUE
;
1602 static HRESULT WINAPI
IShellLinkW_fnGetShowCmd(IShellLinkW
* iface
, INT
*piShowCmd
)
1604 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1606 TRACE("(%p)->(%p)\n",This
, piShowCmd
);
1608 *piShowCmd
= This
->iShowCmd
;
1613 static HRESULT WINAPI
IShellLinkW_fnSetShowCmd(IShellLinkW
* iface
, INT iShowCmd
)
1615 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1617 This
->iShowCmd
= iShowCmd
;
1618 This
->bDirty
= TRUE
;
1623 static HRESULT
SHELL_PidlGeticonLocationW(IShellFolder
* psf
, LPITEMIDLIST pidl
, LPWSTR pszIconPath
, int cchIconPath
, int* piIcon
)
1625 LPCITEMIDLIST pidlLast
;
1627 HRESULT hr
= SHBindToParent(pidl
, &IID_IShellFolder
, (LPVOID
*)&psf
, &pidlLast
);
1629 if (SUCCEEDED(hr
)) {
1632 hr
= IShellFolder_GetUIObjectOf(psf
, 0, 1, (LPCITEMIDLIST
*)&pidlLast
, &IID_IExtractIconW
, NULL
, (LPVOID
*)&pei
);
1634 if (SUCCEEDED(hr
)) {
1635 hr
= IExtractIconW_GetIconLocation(pei
, 0, pszIconPath
, MAX_PATH
, piIcon
, NULL
);
1637 IExtractIconW_Release(pei
);
1640 IShellFolder_Release(psf
);
1646 static HRESULT WINAPI
IShellLinkW_fnGetIconLocation(IShellLinkW
* iface
, LPWSTR pszIconPath
,INT cchIconPath
,INT
*piIcon
)
1648 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1650 TRACE("(%p)->(%p len=%u iicon=%p)\n", This
, pszIconPath
, cchIconPath
, piIcon
);
1655 if (This
->sIcoPath
) {
1656 lstrcpynW(pszIconPath
, This
->sIcoPath
, cchIconPath
);
1657 *piIcon
= This
->iIcoNdx
;
1661 if (This
->pPidl
|| This
->sPath
) {
1664 HRESULT hr
= SHGetDesktopFolder(&pdsk
);
1666 if (SUCCEEDED(hr
)) {
1667 /* first look for an icon using the PIDL (if present) */
1669 hr
= SHELL_PidlGeticonLocationW(pdsk
, This
->pPidl
, pszIconPath
, cchIconPath
, piIcon
);
1673 /* if we couldn't find an icon yet, look for it using the file system path */
1674 if (FAILED(hr
) && This
->sPath
) {
1677 hr
= IShellFolder_ParseDisplayName(pdsk
, 0, NULL
, This
->sPath
, NULL
, &pidl
, NULL
);
1679 if (SUCCEEDED(hr
)) {
1680 hr
= SHELL_PidlGeticonLocationW(pdsk
, pidl
, pszIconPath
, cchIconPath
, piIcon
);
1686 IShellFolder_Release(pdsk
);
1694 static HRESULT WINAPI
IShellLinkW_fnSetIconLocation(IShellLinkW
* iface
, LPCWSTR pszIconPath
,INT iIcon
)
1696 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1698 TRACE("(%p)->(path=%s iicon=%u)\n",This
, debugstr_w(pszIconPath
), iIcon
);
1701 HeapFree(GetProcessHeap(), 0, This
->sIcoPath
);
1702 This
->sIcoPath
= HeapAlloc( GetProcessHeap(), 0,
1703 (lstrlenW( pszIconPath
)+1)*sizeof (WCHAR
) );
1704 if ( !This
->sIcoPath
)
1705 return E_OUTOFMEMORY
;
1706 lstrcpyW( This
->sIcoPath
, pszIconPath
);
1708 This
->iIcoNdx
= iIcon
;
1709 This
->bDirty
= TRUE
;
1714 static HRESULT WINAPI
IShellLinkW_fnSetRelativePath(IShellLinkW
* iface
, LPCWSTR pszPathRel
, DWORD dwReserved
)
1716 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1718 TRACE("(%p)->(path=%s %lx)\n",This
, debugstr_w(pszPathRel
), dwReserved
);
1721 HeapFree(GetProcessHeap(), 0, This
->sPathRel
);
1722 This
->sPathRel
= HeapAlloc( GetProcessHeap(), 0,
1723 (lstrlenW( pszPathRel
)+1) * sizeof (WCHAR
) );
1724 if ( !This
->sPathRel
)
1725 return E_OUTOFMEMORY
;
1726 lstrcpyW( This
->sPathRel
, pszPathRel
);
1727 This
->bDirty
= TRUE
;
1729 return ShellLink_UpdatePath(This
->sPathRel
, This
->sPath
, This
->sWorkDir
, &This
->sPath
);
1732 static HRESULT WINAPI
IShellLinkW_fnResolve(IShellLinkW
* iface
, HWND hwnd
, DWORD fFlags
)
1736 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1738 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This
, hwnd
, fFlags
);
1740 /*FIXME: use IResolveShellLink interface */
1742 if (!This
->sPath
&& This
->pPidl
) {
1743 WCHAR buffer
[MAX_PATH
];
1745 hr
= SHELL_GetPathFromIDListW(This
->pPidl
, buffer
, MAX_PATH
);
1747 if (SUCCEEDED(hr
) && *buffer
) {
1748 This
->sPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(buffer
)+1)*sizeof(WCHAR
));
1750 return E_OUTOFMEMORY
;
1752 lstrcpyW(This
->sPath
, buffer
);
1754 This
->bDirty
= TRUE
;
1756 hr
= S_OK
; /* don't report an error occurred while just caching information */
1759 if (!This
->sIcoPath
&& This
->sPath
) {
1760 This
->sIcoPath
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, (lstrlenW(This
->sPath
)+1)*sizeof(WCHAR
));
1761 if (!This
->sIcoPath
)
1762 return E_OUTOFMEMORY
;
1764 lstrcpyW(This
->sIcoPath
, This
->sPath
);
1767 This
->bDirty
= TRUE
;
1773 static HRESULT WINAPI
IShellLinkW_fnSetPath(IShellLinkW
* iface
, LPCWSTR pszFile
)
1775 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl
, iface
);
1776 WCHAR buffer
[MAX_PATH
];
1779 TRACE("(%p)->(path=%s)\n",This
, debugstr_w(pszFile
));
1781 if (!GetFullPathNameW(pszFile
, MAX_PATH
, buffer
, &fname
))
1785 HeapFree(GetProcessHeap(), 0, This
->sPath
);
1787 This
->sPath
= HeapAlloc( GetProcessHeap(), 0,
1788 (lstrlenW( buffer
)+1) * sizeof (WCHAR
) );
1790 return E_OUTOFMEMORY
;
1792 lstrcpyW(This
->sPath
, buffer
);
1793 This
->bDirty
= TRUE
;
1798 /**************************************************************************
1799 * IShellLinkW Implementation
1802 static IShellLinkWVtbl slvtw
=
1804 IShellLinkW_fnQueryInterface
,
1805 IShellLinkW_fnAddRef
,
1806 IShellLinkW_fnRelease
,
1807 IShellLinkW_fnGetPath
,
1808 IShellLinkW_fnGetIDList
,
1809 IShellLinkW_fnSetIDList
,
1810 IShellLinkW_fnGetDescription
,
1811 IShellLinkW_fnSetDescription
,
1812 IShellLinkW_fnGetWorkingDirectory
,
1813 IShellLinkW_fnSetWorkingDirectory
,
1814 IShellLinkW_fnGetArguments
,
1815 IShellLinkW_fnSetArguments
,
1816 IShellLinkW_fnGetHotkey
,
1817 IShellLinkW_fnSetHotkey
,
1818 IShellLinkW_fnGetShowCmd
,
1819 IShellLinkW_fnSetShowCmd
,
1820 IShellLinkW_fnGetIconLocation
,
1821 IShellLinkW_fnSetIconLocation
,
1822 IShellLinkW_fnSetRelativePath
,
1823 IShellLinkW_fnResolve
,
1824 IShellLinkW_fnSetPath