Rewrote getenv and _wgetenv to avoid returning a pointer to a freed
[wine/testsucceed.git] / dlls / shell32 / shelllink.c
blob25a39a59931ff6e230a3591e76464578cf59f755
1 /*
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 #include "config.h"
23 #include <ctype.h>
24 #include <string.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <errno.h>
31 #include <limits.h>
32 #ifdef HAVE_SYS_WAIT_H
33 # include <sys/wait.h>
34 #endif
35 #include "wine/debug.h"
36 #include "wine/port.h"
37 #include "winerror.h"
38 #include "windef.h"
39 #include "winbase.h"
40 #include "winnls.h"
41 #include "winreg.h"
43 #include "winuser.h"
44 #include "wingdi.h"
45 #include "shlobj.h"
46 #include "undocshell.h"
48 #include "heap.h"
49 #include "pidl.h"
50 #include "shell32_main.h"
51 #include "shlguid.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(shell);
55 /* link file formats */
57 /* flag1: lnk elements: simple link has 0x0B */
58 #define SCF_PIDL 1
59 #define SCF_NORMAL 2
60 #define SCF_DESCRIPTION 4
61 #define SCF_RELATIVE 8
62 #define SCF_WORKDIR 0x10
63 #define SCF_ARGS 0x20
64 #define SCF_CUSTOMICON 0x40
65 #define SCF_UNC 0x80
66 #define SCF_UNICODE 0x1000
68 #include "pshpack1.h"
70 typedef struct _LINK_HEADER
72 DWORD dwSize; /* 0x00 size of the header - 0x4c */
73 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
74 DWORD dwFlags; /* 0x14 describes elements following */
75 DWORD dwFileAttr; /* 0x18 attributes of the target file */
76 FILETIME Time1; /* 0x1c */
77 FILETIME Time2; /* 0x24 */
78 FILETIME Time3; /* 0x2c */
79 DWORD dwFileLength; /* 0x34 File length */
80 DWORD nIcon; /* 0x38 icon number */
81 DWORD fStartup; /* 0x3c startup type */
82 DWORD wHotKey; /* 0x40 hotkey */
83 DWORD Unknown5; /* 0x44 */
84 DWORD Unknown6; /* 0x48 */
85 } LINK_HEADER, * PLINK_HEADER;
87 #define SHLINK_LOCAL 0
88 #define SHLINK_REMOTE 1
90 typedef struct _LOCATION_INFO
92 DWORD dwTotalSize;
93 DWORD dwHeaderSize;
94 DWORD dwFlags;
95 DWORD dwVolTableOfs;
96 DWORD dwLocalPathOfs;
97 DWORD dwNetworkVolTableOfs;
98 DWORD dwFinalPathOfs;
99 } LOCATION_INFO;
101 typedef struct _LOCAL_VOLUME_INFO
103 DWORD dwSize;
104 DWORD dwType;
105 DWORD dwVolSerial;
106 DWORD dwVolLabelOfs;
107 } LOCAL_VOLUME_INFO;
109 #include "poppack.h"
111 static ICOM_VTABLE(IShellLinkA) slvt;
112 static ICOM_VTABLE(IShellLinkW) slvtw;
113 static ICOM_VTABLE(IPersistFile) pfvt;
114 static ICOM_VTABLE(IPersistStream) psvt;
116 /* IShellLink Implementation */
118 typedef struct
120 ICOM_VFIELD(IShellLinkA);
121 DWORD ref;
123 ICOM_VTABLE(IShellLinkW)* lpvtblw;
124 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
125 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
127 /* data structures according to the informations in the lnk */
128 LPITEMIDLIST pPidl;
129 WORD wHotKey;
130 SYSTEMTIME time1;
131 SYSTEMTIME time2;
132 SYSTEMTIME time3;
134 DWORD iShowCmd;
135 LPWSTR sIcoPath;
136 INT iIcoNdx;
137 LPWSTR sPath;
138 LPWSTR sArgs;
139 LPWSTR sWorkDir;
140 LPWSTR sDescription;
141 LPWSTR sPathRel;
142 } IShellLinkImpl;
144 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
145 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset)
147 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
148 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset)
150 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
151 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset)
152 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset)
155 /* strdup on the process heap */
156 inline static LPWSTR HEAP_strdupAtoW( HANDLE heap, DWORD flags, LPCSTR str)
158 INT len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
159 LPWSTR p = HeapAlloc( heap, flags, len*sizeof (WCHAR) );
160 if( !p )
161 return p;
162 MultiByteToWideChar( CP_ACP, 0, str, -1, p, len );
163 return p;
167 /**************************************************************************
168 * IPersistFile_QueryInterface
170 static HRESULT WINAPI IPersistFile_fnQueryInterface(
171 IPersistFile* iface,
172 REFIID riid,
173 LPVOID *ppvObj)
175 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
177 TRACE("(%p)\n",This);
179 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
182 /******************************************************************************
183 * IPersistFile_AddRef
185 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
187 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
189 TRACE("(%p)->(count=%lu)\n",This,This->ref);
191 return IShellLinkA_AddRef((IShellLinkA*)This);
193 /******************************************************************************
194 * IPersistFile_Release
196 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
198 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
200 TRACE("(%p)->(count=%lu)\n",This,This->ref);
202 return IShellLinkA_Release((IShellLinkA*)This);
205 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
207 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
208 FIXME("(%p)\n",This);
209 return NOERROR;
211 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
213 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
214 FIXME("(%p)\n",This);
215 return NOERROR;
217 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
219 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
220 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
221 HRESULT r;
222 IStream *stm;
224 TRACE("(%p, %s)\n",This, debugstr_w(pszFileName));
226 r = CreateStreamOnFile(pszFileName, dwMode, &stm);
227 if( SUCCEEDED( r ) )
229 r = IPersistStream_Load(StreamThis, stm);
230 IStream_Release( stm );
233 return r;
236 static BOOL StartLinkProcessor( LPCOLESTR szLink )
238 const WCHAR szFormat[] = {'w','i','n','e','m','e','n','u','b','u','i','l','d','e','r','.','e','x','e',
239 ' ','-','r',' ','"','%','s','"',0 };
240 LONG len;
241 LPWSTR buffer;
242 STARTUPINFOW si;
243 PROCESS_INFORMATION pi;
245 len = sizeof(szFormat) + lstrlenW( szLink ) * sizeof(WCHAR);
246 buffer = HeapAlloc( GetProcessHeap(), 0, len );
247 if( !buffer )
248 return FALSE;
250 wsprintfW( buffer, szFormat, szLink );
252 TRACE("starting %s\n",debugstr_w(buffer));
254 memset(&si, 0, sizeof(si));
255 si.cb = sizeof(si);
256 if (!CreateProcessW( NULL, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) return FALSE;
258 /* wait for a while to throttle the creation of linker processes */
259 if( WAIT_OBJECT_0 != WaitForSingleObject( pi.hProcess, 10000 ) )
260 WARN("Timed out waiting for shell linker\n");
262 CloseHandle( pi.hProcess );
263 CloseHandle( pi.hThread );
265 return TRUE;
268 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
270 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
271 _IPersistStream_From_ICOM_THIS(IPersistStream, This);
272 HRESULT r;
273 IStream *stm;
275 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
277 if (!pszFileName || !This->sPath)
278 return ERROR_UNKNOWN;
280 r = CreateStreamOnFile(pszFileName, STGM_READWRITE | STGM_CREATE, &stm);
281 if( SUCCEEDED( r ) )
283 r = IPersistStream_Save(StreamThis, stm, FALSE);
284 IStream_Release( stm );
286 if( SUCCEEDED( r ) )
287 StartLinkProcessor( pszFileName );
288 else
290 DeleteFileW( pszFileName );
291 WARN("Failed to create shortcut %s\n", debugstr_w(pszFileName) );
295 return r;
298 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
300 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
301 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
302 return NOERROR;
304 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
306 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
307 FIXME("(%p)\n",This);
308 return NOERROR;
311 static ICOM_VTABLE(IPersistFile) pfvt =
313 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
314 IPersistFile_fnQueryInterface,
315 IPersistFile_fnAddRef,
316 IPersistFile_fnRelease,
317 IPersistFile_fnGetClassID,
318 IPersistFile_fnIsDirty,
319 IPersistFile_fnLoad,
320 IPersistFile_fnSave,
321 IPersistFile_fnSaveCompleted,
322 IPersistFile_fnGetCurFile
325 /************************************************************************
326 * IPersistStream_QueryInterface
328 static HRESULT WINAPI IPersistStream_fnQueryInterface(
329 IPersistStream* iface,
330 REFIID riid,
331 VOID** ppvoid)
333 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
335 TRACE("(%p)\n",This);
337 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
340 /************************************************************************
341 * IPersistStream_Release
343 static ULONG WINAPI IPersistStream_fnRelease(
344 IPersistStream* iface)
346 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
348 TRACE("(%p)\n",This);
350 return IShellLinkA_Release((IShellLinkA*)This);
353 /************************************************************************
354 * IPersistStream_AddRef
356 static ULONG WINAPI IPersistStream_fnAddRef(
357 IPersistStream* iface)
359 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
361 TRACE("(%p)\n",This);
363 return IShellLinkA_AddRef((IShellLinkA*)This);
366 /************************************************************************
367 * IPersistStream_GetClassID
370 static HRESULT WINAPI IPersistStream_fnGetClassID(
371 IPersistStream* iface,
372 CLSID* pClassID)
374 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
376 TRACE("(%p)\n", This);
378 if (pClassID==0)
379 return E_POINTER;
381 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
383 return S_OK;
386 /************************************************************************
387 * IPersistStream_IsDirty (IPersistStream)
389 static HRESULT WINAPI IPersistStream_fnIsDirty(
390 IPersistStream* iface)
392 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
394 TRACE("(%p)\n", This);
396 return S_OK;
400 static HRESULT Stream_LoadString( IStream* stm, BOOL unicode, LPWSTR *pstr )
402 DWORD count;
403 USHORT len;
404 LPVOID temp;
405 LPWSTR str;
406 HRESULT r;
408 TRACE("%p\n", stm);
410 count = 0;
411 r = IStream_Read(stm, &len, sizeof(len), &count);
412 if ( FAILED (r) || ( count != sizeof(len) ) )
413 return E_FAIL;
415 if( unicode )
416 len *= sizeof (WCHAR);
418 TRACE("reading %d\n", len);
419 temp = HeapAlloc(GetProcessHeap(), 0, len+sizeof(WCHAR));
420 if( !temp )
421 return E_OUTOFMEMORY;
422 count = 0;
423 r = IStream_Read(stm, temp, len, &count);
424 if( FAILED (r) || ( count != len ) )
426 HeapFree( GetProcessHeap(), 0, temp );
427 return E_FAIL;
430 TRACE("read %s\n", debugstr_an(temp,len));
432 /* convert to unicode if necessary */
433 if( !unicode )
435 count = MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, NULL, 0 );
436 str = HeapAlloc( GetProcessHeap(), 0, (count+1)*sizeof (WCHAR) );
437 if( str )
438 MultiByteToWideChar( CP_ACP, 0, (LPSTR) temp, len, str, count );
439 HeapFree( GetProcessHeap(), 0, temp );
441 else
443 count /= 2;
444 str = (LPWSTR) temp;
446 str[count] = 0;
448 *pstr = str;
450 return S_OK;
453 static HRESULT Stream_LoadLocation( IStream* stm )
455 DWORD size;
456 ULONG count;
457 HRESULT r;
458 LOCATION_INFO *loc;
460 TRACE("%p\n",stm);
462 r = IStream_Read( stm, &size, sizeof(size), &count );
463 if( FAILED( r ) )
464 return r;
465 if( count != sizeof(loc->dwTotalSize) )
466 return E_FAIL;
468 loc = HeapAlloc( GetProcessHeap(), 0, size );
469 if( ! loc )
470 return E_OUTOFMEMORY;
472 r = IStream_Read( stm, &loc->dwHeaderSize, size-sizeof(size), &count );
473 if( FAILED( r ) )
474 goto end;
475 if( count != (size - sizeof(size)) )
477 r = E_FAIL;
478 goto end;
480 loc->dwTotalSize = size;
482 TRACE("Read %ld bytes\n",count);
484 /* FIXME: do something useful with it */
485 HeapFree( GetProcessHeap(), 0, loc );
487 return S_OK;
488 end:
489 HeapFree( GetProcessHeap(), 0, loc );
490 return r;
493 /************************************************************************
494 * IPersistStream_Load (IPersistStream)
496 static HRESULT WINAPI IPersistStream_fnLoad(
497 IPersistStream* iface,
498 IStream* stm)
500 LINK_HEADER hdr;
501 ULONG dwBytesRead;
502 BOOL unicode;
503 WCHAR sTemp[MAX_PATH];
504 HRESULT r;
506 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
508 TRACE("(%p)(%p)\n", This, stm);
510 if( !stm )
511 return STG_E_INVALIDPOINTER;
513 dwBytesRead = 0;
514 r = IStream_Read(stm, &hdr, sizeof(hdr), &dwBytesRead);
515 if( FAILED( r ) )
516 return r;
518 if( dwBytesRead != sizeof(hdr))
519 return E_FAIL;
520 if( hdr.dwSize != sizeof(hdr))
521 return E_FAIL;
522 if( !IsEqualIID(&hdr.MagicGuid, &CLSID_ShellLink) )
523 return E_FAIL;
525 /* if( hdr.dwFlags & SCF_PIDL ) */ /* FIXME: seems to always have a PIDL */
527 r = ILLoadFromStream( stm, &This->pPidl );
528 if( FAILED( r ) )
529 return r;
531 This->wHotKey = hdr.wHotKey;
532 This->iIcoNdx = hdr.nIcon;
533 FileTimeToSystemTime (&hdr.Time1, &This->time1);
534 FileTimeToSystemTime (&hdr.Time2, &This->time2);
535 FileTimeToSystemTime (&hdr.Time3, &This->time3);
536 #if 1
537 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
538 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
539 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
540 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
541 GetDateFormatW(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
542 TRACE("-- time1: %s\n", debugstr_w(sTemp) );
543 pdump (This->pPidl);
544 #endif
545 if( hdr.dwFlags & SCF_NORMAL )
546 r = Stream_LoadLocation( stm );
547 if( FAILED( r ) )
548 goto end;
549 unicode = hdr.dwFlags & SCF_UNICODE;
550 if( hdr.dwFlags & SCF_DESCRIPTION )
552 r = Stream_LoadString( stm, unicode, &This->sDescription );
553 TRACE("Description -> %s\n",debugstr_w(This->sDescription));
555 if( FAILED( r ) )
556 goto end;
558 if( hdr.dwFlags & SCF_RELATIVE )
560 r = Stream_LoadString( stm, unicode, &This->sPathRel );
561 TRACE("Relative Path-> %s\n",debugstr_w(This->sPathRel));
563 if( FAILED( r ) )
564 goto end;
566 if( hdr.dwFlags & SCF_WORKDIR )
568 r = Stream_LoadString( stm, unicode, &This->sWorkDir );
569 TRACE("Working Dir -> %s\n",debugstr_w(This->sWorkDir));
571 if( FAILED( r ) )
572 goto end;
574 if( hdr.dwFlags & SCF_ARGS )
576 r = Stream_LoadString( stm, unicode, &This->sArgs );
577 TRACE("Working Dir -> %s\n",debugstr_w(This->sArgs));
579 if( FAILED( r ) )
580 goto end;
582 if( hdr.dwFlags & SCF_CUSTOMICON )
584 r = Stream_LoadString( stm, unicode, &This->sIcoPath );
585 TRACE("Icon file -> %s\n",debugstr_w(This->sIcoPath));
587 if( FAILED( r ) )
588 goto end;
590 TRACE("OK\n");
592 pdump (This->pPidl);
594 return S_OK;
595 end:
596 return r;
599 /************************************************************************
600 * Stream_WriteString
602 * Helper function for IPersistStream_Save. Writes a unicode string
603 * with terminating nul byte to a stream, preceded by the its length.
605 static HRESULT Stream_WriteString( IStream* stm, LPCWSTR str )
607 USHORT len = lstrlenW( str ) + 1;
608 DWORD count;
609 HRESULT r;
611 r = IStream_Write( stm, &len, sizeof(len), &count );
612 if( FAILED( r ) )
613 return r;
615 len *= sizeof(WCHAR);
617 r = IStream_Write( stm, str, len, &count );
618 if( FAILED( r ) )
619 return r;
621 return S_OK;
624 static HRESULT Stream_WriteLocationInfo( IStream* stm, LPCWSTR filename )
626 LOCATION_INFO loc;
627 ULONG count;
629 FIXME("writing empty location info\n");
631 memset( &loc, 0, sizeof(loc) );
632 loc.dwTotalSize = sizeof(loc) - sizeof(loc.dwTotalSize);
634 /* FIXME: fill this in */
636 return IStream_Write( stm, &loc, loc.dwTotalSize, &count );
639 /************************************************************************
640 * IPersistStream_Save (IPersistStream)
642 * FIXME: makes assumptions about byte order
644 static HRESULT WINAPI IPersistStream_fnSave(
645 IPersistStream* iface,
646 IStream* stm,
647 BOOL fClearDirty)
649 LINK_HEADER header;
650 ULONG count;
651 HRESULT r;
653 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
655 TRACE("(%p) %p %x\n", This, stm, fClearDirty);
657 /* if there's no PIDL, generate one */
658 if( ! This->pPidl )
660 if( ! This->sPath )
661 return E_FAIL;
662 This->pPidl = ILCreateFromPathW( This->sPath );
665 memset(&header, 0, sizeof(header));
666 header.dwSize = sizeof(header);
667 memcpy(&header.MagicGuid, &CLSID_ShellLink, sizeof(header.MagicGuid) );
669 header.wHotKey = This->wHotKey;
670 header.nIcon = This->iIcoNdx;
671 header.dwFlags = SCF_UNICODE; /* strings are in unicode */
672 header.dwFlags |= SCF_NORMAL; /* how do we determine this ? */
673 if( This->pPidl )
674 header.dwFlags |= SCF_PIDL;
675 if( This->sDescription )
676 header.dwFlags |= SCF_DESCRIPTION;
677 if( This->sWorkDir )
678 header.dwFlags |= SCF_WORKDIR;
679 if( This->sArgs )
680 header.dwFlags |= SCF_ARGS;
681 if( This->sIcoPath )
682 header.dwFlags |= SCF_CUSTOMICON;
684 SystemTimeToFileTime ( &This->time1, &header.Time1 );
685 SystemTimeToFileTime ( &This->time2, &header.Time2 );
686 SystemTimeToFileTime ( &This->time3, &header.Time3 );
688 /* write the Shortcut header */
689 r = IStream_Write( stm, &header, sizeof(header), &count );
690 if( FAILED( r ) )
692 ERR("Write failed at %d\n",__LINE__);
693 return r;
696 TRACE("Writing pidl \n");
698 /* write the PIDL to the shortcut */
699 if( This->pPidl )
701 r = ILSaveToStream( stm, This->pPidl );
702 if( FAILED( r ) )
704 ERR("Failed to write PIDL at %d\n",__LINE__);
705 return r;
709 TRACE("Path = %s\n", debugstr_w(This->sPath));
710 if( ! This->sPath )
711 return E_FAIL;
712 Stream_WriteLocationInfo( stm, This->sPath );
714 TRACE("Description = %s\n", debugstr_w(This->sDescription));
715 if( This->sDescription )
716 r = Stream_WriteString( stm, This->sDescription );
718 if( This->sPathRel )
719 r = Stream_WriteString( stm, This->sPathRel );
721 if( This->sWorkDir )
722 r = Stream_WriteString( stm, This->sWorkDir );
724 if( This->sArgs )
725 r = Stream_WriteString( stm, This->sArgs );
727 if( This->sIcoPath )
728 r = Stream_WriteString( stm, This->sIcoPath );
730 return S_OK;
733 /************************************************************************
734 * IPersistStream_GetSizeMax (IPersistStream)
736 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
737 IPersistStream* iface,
738 ULARGE_INTEGER* pcbSize)
740 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
742 TRACE("(%p)\n", This);
744 return E_NOTIMPL;
747 static ICOM_VTABLE(IPersistStream) psvt =
749 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
750 IPersistStream_fnQueryInterface,
751 IPersistStream_fnAddRef,
752 IPersistStream_fnRelease,
753 IPersistStream_fnGetClassID,
754 IPersistStream_fnIsDirty,
755 IPersistStream_fnLoad,
756 IPersistStream_fnSave,
757 IPersistStream_fnGetSizeMax
760 /**************************************************************************
761 * IShellLink_Constructor
763 HRESULT WINAPI IShellLink_Constructor (
764 IUnknown * pUnkOuter,
765 REFIID riid,
766 LPVOID * ppv)
768 IShellLinkImpl * sl;
770 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
772 *ppv = NULL;
774 if(pUnkOuter) return CLASS_E_NOAGGREGATION;
775 sl = (IShellLinkImpl *) LocalAlloc(GMEM_ZEROINIT,sizeof(IShellLinkImpl));
776 if (!sl) return E_OUTOFMEMORY;
778 sl->ref = 1;
779 sl->lpVtbl = &slvt;
780 sl->lpvtblw = &slvtw;
781 sl->lpvtblPersistFile = &pfvt;
782 sl->lpvtblPersistStream = &psvt;
783 sl->iShowCmd = SW_SHOWNORMAL;
785 TRACE("(%p)->()\n",sl);
787 if (IsEqualIID(riid, &IID_IUnknown) ||
788 IsEqualIID(riid, &IID_IShellLinkA))
789 *ppv = sl;
790 else if (IsEqualIID(riid, &IID_IShellLinkW))
791 *ppv = &(sl->lpvtblw);
792 else {
793 LocalFree((HLOCAL)sl);
794 ERR("E_NOINTERFACE\n");
795 return E_NOINTERFACE;
798 return S_OK;
801 /**************************************************************************
802 * IShellLinkA_QueryInterface
804 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
806 ICOM_THIS(IShellLinkImpl, iface);
808 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
810 *ppvObj = NULL;
812 if(IsEqualIID(riid, &IID_IUnknown) ||
813 IsEqualIID(riid, &IID_IShellLinkA))
815 *ppvObj = This;
817 else if(IsEqualIID(riid, &IID_IShellLinkW))
819 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
821 else if(IsEqualIID(riid, &IID_IPersistFile))
823 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
825 else if(IsEqualIID(riid, &IID_IPersistStream))
827 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
830 if(*ppvObj)
832 IUnknown_AddRef((IUnknown*)(*ppvObj));
833 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
834 return S_OK;
836 TRACE("-- Interface: E_NOINTERFACE\n");
837 return E_NOINTERFACE;
839 /******************************************************************************
840 * IShellLinkA_AddRef
842 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
844 ICOM_THIS(IShellLinkImpl, iface);
846 TRACE("(%p)->(count=%lu)\n",This,This->ref);
848 return ++(This->ref);
850 /******************************************************************************
851 * IShellLinkA_Release
853 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
855 ICOM_THIS(IShellLinkImpl, iface);
857 TRACE("(%p)->(count=%lu)\n",This,This->ref);
859 if (--(This->ref))
860 return This->ref;
862 TRACE("-- destroying IShellLink(%p)\n",This);
864 if (This->sIcoPath)
865 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
867 if (This->sArgs)
868 HeapFree(GetProcessHeap(), 0, This->sArgs);
870 if (This->sWorkDir)
871 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
873 if (This->sDescription)
874 HeapFree(GetProcessHeap(), 0, This->sDescription);
876 if (This->sPath)
877 HeapFree(GetProcessHeap(),0,This->sPath);
879 if (This->pPidl)
880 ILFree(This->pPidl);
882 LocalFree((HANDLE)This);
884 return 0;
887 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,
888 INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
890 ICOM_THIS(IShellLinkImpl, iface);
892 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",
893 This, pszFile, cchMaxPath, pfd, fFlags, debugstr_w(This->sPath));
895 if( cchMaxPath )
896 pszFile[0] = 0;
897 if (This->sPath)
898 WideCharToMultiByte( CP_ACP, 0, This->sPath, -1,
899 pszFile, cchMaxPath, NULL, NULL);
901 return NOERROR;
904 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
906 ICOM_THIS(IShellLinkImpl, iface);
908 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
910 *ppidl = ILClone(This->pPidl);
912 return NOERROR;
915 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
917 ICOM_THIS(IShellLinkImpl, iface);
919 TRACE("(%p)->(pidl=%p)\n",This, pidl);
921 if (This->pPidl)
922 ILFree(This->pPidl);
923 This->pPidl = ILClone (pidl);
925 return S_OK;
928 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
930 ICOM_THIS(IShellLinkImpl, iface);
932 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
934 if( cchMaxName )
935 pszName[0] = 0;
936 if( This->sDescription )
937 WideCharToMultiByte( CP_ACP, 0, This->sDescription, -1,
938 pszName, cchMaxName, NULL, NULL);
940 return S_OK;
942 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
944 ICOM_THIS(IShellLinkImpl, iface);
946 TRACE("(%p)->(pName=%s)\n", This, pszName);
948 if (This->sDescription)
949 HeapFree(GetProcessHeap(), 0, This->sDescription);
950 This->sDescription = HEAP_strdupAtoW( GetProcessHeap(), 0, pszName);
951 if ( !This->sDescription )
952 return E_OUTOFMEMORY;
954 return S_OK;
957 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
959 ICOM_THIS(IShellLinkImpl, iface);
961 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
963 if( cchMaxPath )
964 pszDir[0] = 0;
965 if( This->sWorkDir )
966 WideCharToMultiByte( CP_ACP, 0, This->sWorkDir, -1,
967 pszDir, cchMaxPath, NULL, NULL);
969 return S_OK;
972 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
974 ICOM_THIS(IShellLinkImpl, iface);
976 TRACE("(%p)->(dir=%s)\n",This, pszDir);
978 if (This->sWorkDir)
979 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
980 This->sWorkDir = HEAP_strdupAtoW( GetProcessHeap(), 0, pszDir);
981 if ( !This->sWorkDir )
982 return E_OUTOFMEMORY;
984 return S_OK;
987 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
989 ICOM_THIS(IShellLinkImpl, iface);
991 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
993 if( cchMaxPath )
994 pszArgs[0] = 0;
995 if( This->sArgs )
996 WideCharToMultiByte( CP_ACP, 0, This->sArgs, -1,
997 pszArgs, cchMaxPath, NULL, NULL);
999 return S_OK;
1002 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1004 ICOM_THIS(IShellLinkImpl, iface);
1006 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1008 if (This->sArgs)
1009 HeapFree(GetProcessHeap(), 0, This->sArgs);
1010 This->sArgs = HEAP_strdupAtoW( GetProcessHeap(), 0, pszArgs);
1011 if( !This->sArgs )
1012 return E_OUTOFMEMORY;
1014 return S_OK;
1017 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1019 ICOM_THIS(IShellLinkImpl, iface);
1021 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1023 *pwHotkey = This->wHotKey;
1025 return S_OK;
1028 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1030 ICOM_THIS(IShellLinkImpl, iface);
1032 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1034 This->wHotKey = wHotkey;
1036 return S_OK;
1039 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1041 ICOM_THIS(IShellLinkImpl, iface);
1043 TRACE("(%p)->(%p)\n",This, piShowCmd);
1044 *piShowCmd = This->iShowCmd;
1045 return S_OK;
1048 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1050 ICOM_THIS(IShellLinkImpl, iface);
1052 TRACE("(%p) %d\n",This, iShowCmd);
1054 This->iShowCmd = iShowCmd;
1056 return NOERROR;
1059 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1061 ICOM_THIS(IShellLinkImpl, iface);
1063 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1065 if( cchIconPath )
1066 pszIconPath[0] = 0;
1067 if( This->sIcoPath )
1068 WideCharToMultiByte( CP_ACP, 0, This->sIcoPath, -1,
1069 pszIconPath, cchIconPath, NULL, NULL);
1070 *piIcon = This->iIcoNdx;
1072 return NOERROR;
1075 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1077 ICOM_THIS(IShellLinkImpl, iface);
1079 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1081 if (This->sIcoPath)
1082 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1083 This->sIcoPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszIconPath);
1084 if ( !This->sIcoPath )
1085 return E_OUTOFMEMORY;
1086 This->iIcoNdx = iIcon;
1088 return S_OK;
1091 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1093 ICOM_THIS(IShellLinkImpl, iface);
1095 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1097 if (This->sPathRel)
1098 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1099 This->sPathRel = HEAP_strdupAtoW(GetProcessHeap(), 0, pszPathRel);
1101 return S_OK;
1104 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1106 ICOM_THIS(IShellLinkImpl, iface);
1108 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1109 return S_OK;
1112 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1114 ICOM_THIS(IShellLinkImpl, iface);
1116 TRACE("(%p)->(path=%s)\n",This, pszFile);
1118 if (This->sPath)
1119 HeapFree(GetProcessHeap(), 0, This->sPath);
1120 This->sPath = HEAP_strdupAtoW(GetProcessHeap(), 0, pszFile);
1121 if( !This->sPath )
1122 return E_OUTOFMEMORY;
1124 return S_OK;
1127 /**************************************************************************
1128 * IShellLink Implementation
1131 static ICOM_VTABLE(IShellLinkA) slvt =
1133 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1134 IShellLinkA_fnQueryInterface,
1135 IShellLinkA_fnAddRef,
1136 IShellLinkA_fnRelease,
1137 IShellLinkA_fnGetPath,
1138 IShellLinkA_fnGetIDList,
1139 IShellLinkA_fnSetIDList,
1140 IShellLinkA_fnGetDescription,
1141 IShellLinkA_fnSetDescription,
1142 IShellLinkA_fnGetWorkingDirectory,
1143 IShellLinkA_fnSetWorkingDirectory,
1144 IShellLinkA_fnGetArguments,
1145 IShellLinkA_fnSetArguments,
1146 IShellLinkA_fnGetHotkey,
1147 IShellLinkA_fnSetHotkey,
1148 IShellLinkA_fnGetShowCmd,
1149 IShellLinkA_fnSetShowCmd,
1150 IShellLinkA_fnGetIconLocation,
1151 IShellLinkA_fnSetIconLocation,
1152 IShellLinkA_fnSetRelativePath,
1153 IShellLinkA_fnResolve,
1154 IShellLinkA_fnSetPath
1158 /**************************************************************************
1159 * IShellLinkW_fnQueryInterface
1161 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1162 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1164 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1166 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1169 /******************************************************************************
1170 * IShellLinkW_fnAddRef
1172 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1174 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1176 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1178 return IShellLinkA_AddRef((IShellLinkA*)This);
1180 /******************************************************************************
1181 * IShellLinkW_fnRelease
1184 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1186 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1188 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1190 return IShellLinkA_Release((IShellLinkA*)This);
1193 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAW *pfd, DWORD fFlags)
1195 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1197 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1198 if( cchMaxPath )
1199 pszFile[0] = 0;
1200 if( This->sPath )
1201 lstrcpynW( pszFile, This->sPath, cchMaxPath );
1203 return NOERROR;
1206 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1208 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1210 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1212 if( This->pPidl)
1213 *ppidl = ILClone( This->pPidl );
1214 else
1215 *ppidl = NULL;
1217 return S_OK;
1220 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1222 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1224 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1226 if( This->pPidl )
1227 ILFree( This->pPidl );
1228 This->pPidl = ILClone( pidl );
1229 if( !This->pPidl )
1230 return E_FAIL;
1232 return S_OK;
1235 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1237 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1239 TRACE("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1241 if( cchMaxName )
1242 pszName[0] = 0;
1243 if( This->sDescription )
1244 lstrcpynW( pszName, This->sDescription, cchMaxName );
1246 return S_OK;
1249 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1251 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1253 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1255 if (This->sDescription)
1256 HeapFree(GetProcessHeap(), 0, This->sDescription);
1257 This->sDescription = HeapAlloc( GetProcessHeap(), 0,
1258 (lstrlenW( pszName )+1)*sizeof(WCHAR) );
1259 if ( !This->sDescription )
1260 return E_OUTOFMEMORY;
1261 lstrcpyW( This->sDescription, pszName );
1263 return S_OK;
1266 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1268 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1270 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1272 if( cchMaxPath )
1273 pszDir[0] = 0;
1274 if( This->sWorkDir )
1275 lstrcpynW( pszDir, This->sWorkDir, cchMaxPath );
1277 return S_OK;
1280 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1282 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1284 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1286 if (This->sWorkDir)
1287 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1288 This->sWorkDir = HeapAlloc( GetProcessHeap(), 0,
1289 (lstrlenW( pszDir )+1)*sizeof (WCHAR) );
1290 if ( !This->sWorkDir )
1291 return E_OUTOFMEMORY;
1292 lstrcpyW( This->sWorkDir, pszDir );
1294 return S_OK;
1297 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1299 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1301 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1303 if( cchMaxPath )
1304 pszArgs[0] = 0;
1305 if( This->sArgs )
1306 lstrcpynW( pszArgs, This->sArgs, cchMaxPath );
1308 return NOERROR;
1311 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1313 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1315 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1317 if (This->sArgs)
1318 HeapFree(GetProcessHeap(), 0, This->sArgs);
1319 This->sArgs = HeapAlloc( GetProcessHeap(), 0,
1320 (lstrlenW( pszArgs )+1)*sizeof (WCHAR) );
1321 if ( !This->sArgs )
1322 return E_OUTOFMEMORY;
1323 lstrcpyW( This->sArgs, pszArgs );
1325 return S_OK;
1328 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1330 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1332 TRACE("(%p)->(%p)\n",This, pwHotkey);
1334 *pwHotkey=This->wHotKey;
1336 return S_OK;
1339 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1341 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1343 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1345 This->wHotKey = wHotkey;
1347 return S_OK;
1350 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1352 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1354 TRACE("(%p)->(%p)\n",This, piShowCmd);
1356 *piShowCmd = This->iShowCmd;
1358 return S_OK;
1361 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1363 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1365 This->iShowCmd = iShowCmd;
1367 return S_OK;
1370 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1372 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1374 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1376 if( cchIconPath )
1377 pszIconPath[0] = 0;
1378 if( This->sIcoPath )
1379 lstrcpynW( pszIconPath, This->sIcoPath, cchIconPath );
1380 *piIcon = This->iIcoNdx;
1382 return S_OK;
1385 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1387 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1389 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1391 if (This->sIcoPath)
1392 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1393 This->sIcoPath = HeapAlloc( GetProcessHeap(), 0,
1394 (lstrlenW( pszIconPath )+1)*sizeof (WCHAR) );
1395 if ( !This->sIcoPath )
1396 return E_OUTOFMEMORY;
1397 lstrcpyW( This->sIcoPath, pszIconPath );
1399 This->iIcoNdx = iIcon;
1401 return S_OK;
1404 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1406 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1408 TRACE("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1410 if (This->sPathRel)
1411 HeapFree(GetProcessHeap(), 0, This->sPathRel);
1412 This->sPathRel = HeapAlloc( GetProcessHeap(), 0,
1413 (lstrlenW( pszPathRel )+1) * sizeof (WCHAR) );
1414 if ( !This->sPathRel )
1415 return E_OUTOFMEMORY;
1416 lstrcpyW( This->sPathRel, pszPathRel );
1418 return S_OK;
1421 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1423 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1425 FIXME("(%p)->(hwnd=%p flags=%lx)\n",This, hwnd, fFlags);
1427 return S_OK;
1430 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1432 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1434 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1436 if (This->sPath)
1437 HeapFree(GetProcessHeap(), 0, This->sPath);
1438 This->sPath = HeapAlloc( GetProcessHeap(), 0,
1439 (lstrlenW( pszFile )+1) * sizeof (WCHAR) );
1440 if ( !This->sPath )
1441 return E_OUTOFMEMORY;
1442 lstrcpyW( This->sPath, pszFile );
1444 return S_OK;
1447 /**************************************************************************
1448 * IShellLinkW Implementation
1451 static ICOM_VTABLE(IShellLinkW) slvtw =
1453 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1454 IShellLinkW_fnQueryInterface,
1455 IShellLinkW_fnAddRef,
1456 IShellLinkW_fnRelease,
1457 IShellLinkW_fnGetPath,
1458 IShellLinkW_fnGetIDList,
1459 IShellLinkW_fnSetIDList,
1460 IShellLinkW_fnGetDescription,
1461 IShellLinkW_fnSetDescription,
1462 IShellLinkW_fnGetWorkingDirectory,
1463 IShellLinkW_fnSetWorkingDirectory,
1464 IShellLinkW_fnGetArguments,
1465 IShellLinkW_fnSetArguments,
1466 IShellLinkW_fnGetHotkey,
1467 IShellLinkW_fnSetHotkey,
1468 IShellLinkW_fnGetShowCmd,
1469 IShellLinkW_fnSetShowCmd,
1470 IShellLinkW_fnGetIconLocation,
1471 IShellLinkW_fnSetIconLocation,
1472 IShellLinkW_fnSetRelativePath,
1473 IShellLinkW_fnResolve,
1474 IShellLinkW_fnSetPath