Added LGPL standard comment, and copyright notices where necessary.
[wine] / dlls / shell32 / shelllink.c
1 /*
2  *
3  *      Copyright 1997  Marcus Meissner
4  *      Copyright 1998  Juergen Schmied
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22
23 #include <string.h>
24 #include <stdio.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #ifdef HAVE_SYS_WAIT_H
28 # include <sys/wait.h>
29 #endif
30 #include "wine/debug.h"
31 #include "winerror.h"
32 #include "winbase.h"
33 #include "winnls.h"
34 #include "winreg.h"
35
36 #include "shlobj.h"
37 #include "undocshell.h"
38 #include "bitmaps/wine.xpm"
39
40 #include "heap.h"
41 #include "pidl.h"
42 #include "shell32_main.h"
43 #include "shlguid.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(shell);
46
47 /* link file formats */
48
49 #include "pshpack1.h"
50
51 /* flag1: lnk elements: simple link has 0x0B */
52 #define WORKDIR         0x10
53 #define ARGUMENT        0x20
54 #define ICON            0x40
55 #define UNC             0x80
56
57 /* fStartup */
58 #define NORMAL          0x01
59 #define MAXIMIZED       0x03
60 #define MINIMIZED       0x07
61
62 typedef struct _LINK_HEADER     
63 {       DWORD   MagicStr;       /* 0x00 'L','\0','\0','\0' */
64         GUID    MagicGuid;      /* 0x04 is CLSID_ShellLink */
65         DWORD   Flag1;          /* 0x14 describes elements following */
66         DWORD   Flag2;          /* 0x18 */
67         FILETIME Time1;         /* 0x1c */
68         FILETIME Time2;         /* 0x24 */
69         FILETIME Time3;         /* 0x2c */
70         DWORD   Unknown1;       /* 0x34 */
71         DWORD   Unknown2;       /* 0x38 icon number */
72         DWORD   fStartup;       /* 0x3c startup type */
73         DWORD   wHotKey;        /* 0x40 hotkey */
74         DWORD   Unknown5;       /* 0x44 */
75         DWORD   Unknown6;       /* 0x48 */
76         USHORT  PidlSize;       /* 0x4c */
77         ITEMIDLIST Pidl;        /* 0x4e */
78 } LINK_HEADER, * PLINK_HEADER;
79
80 #define LINK_HEADER_SIZE (sizeof(LINK_HEADER)-sizeof(ITEMIDLIST))
81
82 typedef struct
83 {
84         BYTE bWidth;
85         BYTE bHeight;
86         BYTE bColorCount;
87         BYTE bReserved;
88         WORD wPlanes;
89         WORD wBitCount;
90         DWORD dwBytesInRes;
91         WORD nID;
92 } GRPICONDIRENTRY;
93
94 typedef struct
95 {
96         WORD idReserved;
97         WORD idType;
98         WORD idCount;
99         GRPICONDIRENTRY idEntries[1];
100 } GRPICONDIR;
101
102 typedef struct
103 {
104         BYTE bWidth;
105         BYTE bHeight;
106         BYTE bColorCount;
107         BYTE bReserved;
108         WORD wPlanes;
109         WORD wBitCount;
110         DWORD dwBytesInRes;
111         DWORD dwImageOffset;
112 } ICONDIRENTRY;
113
114 typedef struct
115 {
116         WORD idReserved;
117         WORD idType;
118         WORD idCount;
119 } ICONDIR;
120
121
122 #include "poppack.h"
123
124 typedef struct
125 {
126         HRSRC *pResInfo;
127         int   nIndex;
128 } ENUMRESSTRUCT;
129
130 static ICOM_VTABLE(IShellLinkA)         slvt;
131 static ICOM_VTABLE(IShellLinkW)         slvtw;
132 static ICOM_VTABLE(IPersistFile)        pfvt;
133 static ICOM_VTABLE(IPersistStream)      psvt;
134
135 /* IShellLink Implementation */
136
137 typedef struct
138 {
139         ICOM_VFIELD(IShellLinkA);
140         DWORD                           ref;
141
142         ICOM_VTABLE(IShellLinkW)*       lpvtblw;
143         ICOM_VTABLE(IPersistFile)*      lpvtblPersistFile;
144         ICOM_VTABLE(IPersistStream)*    lpvtblPersistStream;
145         
146         /* internal stream of the IPersistFile interface */
147         IStream*                        lpFileStream;
148         
149         /* data structures according to the informations in the lnk */
150         LPSTR           sPath;
151         LPITEMIDLIST    pPidl;
152         WORD            wHotKey;
153         SYSTEMTIME      time1;
154         SYSTEMTIME      time2;
155         SYSTEMTIME      time3;
156
157         LPSTR           sIcoPath;
158         INT             iIcoNdx;
159         LPSTR           sArgs;
160         LPSTR           sWorkDir;
161         LPSTR           sDescription;
162 } IShellLinkImpl;
163
164 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
165 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset);
166
167 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
168 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
169
170 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
171 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset);
172 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset);
173
174
175 /* strdup on the process heap */
176 inline static LPSTR heap_strdup( LPCSTR str )
177 {
178     INT len = strlen(str) + 1;
179     LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
180     if (p) memcpy( p, str, len );
181     return p;
182 }
183
184
185 /**************************************************************************
186  *  IPersistFile_QueryInterface
187  */
188 static HRESULT WINAPI IPersistFile_fnQueryInterface(
189         IPersistFile* iface,
190         REFIID riid,
191         LPVOID *ppvObj)
192 {
193         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
194
195         TRACE("(%p)\n",This);
196
197         return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
198 }
199
200 /******************************************************************************
201  * IPersistFile_AddRef
202  */
203 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
204 {
205         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
206
207         TRACE("(%p)->(count=%lu)\n",This,This->ref);
208
209         return IShellLinkA_AddRef((IShellLinkA*)This);
210 }
211 /******************************************************************************
212  * IPersistFile_Release
213  */
214 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
215 {
216         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
217
218         TRACE("(%p)->(count=%lu)\n",This,This->ref);
219
220         return IShellLinkA_Release((IShellLinkA*)This);
221 }
222
223 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
224 {
225         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
226         FIXME("(%p)\n",This);
227         return NOERROR;
228 }
229 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
230 {
231         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
232         FIXME("(%p)\n",This);
233         return NOERROR;
234 }
235 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
236 {
237         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
238         _IPersistStream_From_ICOM_THIS(IPersistStream, This)
239
240         LPSTR           sFile = HEAP_strdupWtoA ( GetProcessHeap(), 0, pszFileName);
241         HRESULT         hRet = E_FAIL;
242
243         TRACE("(%p, %s)\n",This, sFile);
244         
245
246         if (This->lpFileStream)
247           IStream_Release(This->lpFileStream);
248         
249         if SUCCEEDED(CreateStreamOnFile(sFile, &(This->lpFileStream)))
250         {
251           if SUCCEEDED (IPersistStream_Load(StreamThis, This->lpFileStream))
252           {
253             return NOERROR;
254           }
255         }
256         
257         return hRet;
258 }
259
260
261 /* Icon extraction routines
262  *
263  * FIXME: should use PrivateExtractIcons and friends
264  * FIXME: should not use stdio
265  */
266
267 static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName)
268 {
269     FILE *fXPMFile;
270     int nHeight;
271     int nXORWidthBytes;
272     int nANDWidthBytes;
273     BOOL b8BitColors;
274     int nColors;
275     BYTE *pXOR;
276     BYTE *pAND;
277     BOOL aColorUsed[256] = {0};
278     int nColorsUsed = 0;
279     int i,j;
280
281     if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8)))
282         return 0;
283
284     if (!(fXPMFile = fopen(szXPMFileName, "w")))
285         return 0;
286
287     nHeight = pIcon->bmiHeader.biHeight / 2;
288     nXORWidthBytes = 4 * ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount / 32)
289                           + ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount % 32) > 0));
290     nANDWidthBytes = 4 * ((pIcon->bmiHeader.biWidth / 32)
291                           + ((pIcon->bmiHeader.biWidth % 32) > 0));
292     b8BitColors = pIcon->bmiHeader.biBitCount == 8;
293     nColors = pIcon->bmiHeader.biClrUsed ? pIcon->bmiHeader.biClrUsed
294         : 1 << pIcon->bmiHeader.biBitCount;
295     pXOR = (BYTE*) pIcon + sizeof (BITMAPINFOHEADER) + (nColors * sizeof (RGBQUAD));
296     pAND = pXOR + nHeight * nXORWidthBytes;
297
298 #define MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
299 #define COLOR(x,y) (b8BitColors ? pXOR[(x) + (nHeight - (y) - 1) * nXORWidthBytes] : (x) % 2 ? pXOR[(x) / 2 + (nHeight - (y) - 1) * nXORWidthBytes] & 0xF : (pXOR[(x) / 2 + (nHeight - (y) - 1) * nXORWidthBytes] & 0xF0) >> 4)
300
301     for (i = 0; i < nHeight; i++)
302         for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
303             if (!aColorUsed[COLOR(j,i)] && !MASK(j,i))
304             {
305                 aColorUsed[COLOR(j,i)] = TRUE;
306                 nColorsUsed++;
307             }
308
309     if (fprintf(fXPMFile, "/* XPM */\nstatic char *icon[] = {\n") <= 0)
310         goto error;
311     if (fprintf(fXPMFile, "\"%d %d %d %d\",\n",
312                 (int) pIcon->bmiHeader.biWidth, nHeight, nColorsUsed + 1, 2) <=0)
313         goto error;
314
315     for (i = 0; i < nColors; i++)
316         if (aColorUsed[i])
317             if (fprintf(fXPMFile, "\"%.2X c #%.2X%.2X%.2X\",\n", i, pIcon->bmiColors[i].rgbRed,
318                         pIcon->bmiColors[i].rgbGreen, pIcon->bmiColors[i].rgbBlue) <= 0)
319                 goto error;
320     if (fprintf(fXPMFile, "\"   c None\"") <= 0)
321         goto error;
322
323     for (i = 0; i < nHeight; i++)
324     {
325         if (fprintf(fXPMFile, ",\n\"") <= 0)
326             goto error;
327         for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
328         {
329             if MASK(j,i)
330                 {
331                     if (fprintf(fXPMFile, "  ") <= 0)
332                         goto error;
333                 }
334             else
335                 if (fprintf(fXPMFile, "%.2X", COLOR(j,i)) <= 0)
336                     goto error;
337         }
338         if (fprintf(fXPMFile, "\"") <= 0)
339             goto error;
340     }
341     if (fprintf(fXPMFile, "};\n") <= 0)
342         goto error;
343
344 #undef MASK
345 #undef COLOR
346
347     fclose(fXPMFile);
348     return 1;
349
350  error:
351     fclose(fXPMFile);
352     unlink( szXPMFileName );
353     return 0;
354 }
355
356 static BOOL CALLBACK EnumResNameProc(HANDLE hModule, const char *lpszType, char *lpszName, LONG lParam)
357 {
358     ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam;
359     
360     if (!sEnumRes->nIndex--)
361     {
362       *sEnumRes->pResInfo = FindResourceA(hModule, lpszName, RT_GROUP_ICONA);
363       return FALSE;
364     }
365     else
366       return TRUE;
367 }
368
369 static int ExtractFromEXEDLL(const char *szFileName, int nIndex, const char *szXPMFileName)
370 {
371     HMODULE hModule;
372     HRSRC hResInfo;
373     char *lpName = NULL;
374     HGLOBAL hResData;
375     GRPICONDIR *pIconDir;
376     BITMAPINFO *pIcon;
377     ENUMRESSTRUCT sEnumRes;
378     int nMax = 0;
379     int nMaxBits = 0;
380     int i;
381
382     if (!(hModule = LoadLibraryExA(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE)))
383     {
384         TRACE("LoadLibraryExA (%s) failed, error %ld\n", szFileName, GetLastError());
385         goto error1;
386     }
387
388     if (nIndex < 0)
389     {
390         hResInfo = FindResourceA(hModule, MAKEINTRESOURCEA(-nIndex), RT_GROUP_ICONA);
391         TRACE("FindResourceA (%s) called, return 0x%x, error %ld\n", szFileName, hResInfo, GetLastError());
392     }
393     else
394     {
395         sEnumRes.pResInfo = &hResInfo;
396         sEnumRes.nIndex = nIndex;
397         if (EnumResourceNamesA(hModule, RT_GROUP_ICONA, &EnumResNameProc, (LONG) &sEnumRes))
398         {
399             TRACE("EnumResourceNamesA failed, error %ld\n", GetLastError());
400             goto error2;
401         }
402     }
403
404     if (!hResInfo)
405     {
406         TRACE("ExtractFromEXEDLL failed, error %ld\n", GetLastError());
407         goto error2;
408     }
409
410     if (!(hResData = LoadResource(hModule, hResInfo)))
411     {
412         TRACE("LoadResource failed, error %ld\n", GetLastError());
413         goto error2;
414     }
415     if (!(pIconDir = LockResource(hResData)))
416     {
417         TRACE("LockResource failed, error %ld\n", GetLastError());
418         goto error3;
419     }
420
421     for (i = 0; i < pIconDir->idCount; i++)
422         if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8))
423         {
424           if (pIconDir->idEntries[i].wBitCount > nMaxBits)
425           {
426               nMaxBits = pIconDir->idEntries[i].wBitCount;
427               nMax = 0;
428           }
429           if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax)
430           {
431               lpName = MAKEINTRESOURCEA(pIconDir->idEntries[i].nID);
432               nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
433           }
434         }
435
436     FreeResource(hResData);
437
438     if (!(hResInfo = FindResourceA(hModule, lpName, RT_ICONA)))
439     {
440         TRACE("Second FindResourceA failed, error %ld\n", GetLastError());
441         goto error2;
442     }
443     if (!(hResData = LoadResource(hModule, hResInfo)))
444     {
445         TRACE("Second LoadResource failed, error %ld\n", GetLastError());
446         goto error2;
447     }
448     if (!(pIcon = LockResource(hResData)))
449     {
450         TRACE("Second LockResource failed, error %ld\n", GetLastError());
451         goto error3;
452     }
453
454     if(!SaveIconResAsXPM(pIcon, szXPMFileName))
455     {
456         TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
457         goto error3;
458     }
459
460     FreeResource(hResData);
461     FreeLibrary(hModule);
462
463     return 1;
464
465  error3:
466     FreeResource(hResData);
467  error2:
468     FreeLibrary(hModule);
469  error1:
470     return 0;
471 }
472
473 static int ExtractFromICO(const char *szFileName, const char *szXPMFileName)
474 {
475     FILE *fICOFile;
476     ICONDIR iconDir;
477     ICONDIRENTRY *pIconDirEntry;
478     int nMax = 0;
479     int nIndex = 0;
480     void *pIcon;
481     int i;
482
483     if (!(fICOFile = fopen(szFileName, "r")))
484         goto error1;
485
486     if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
487         goto error2;
488     if ((iconDir.idReserved != 0) || (iconDir.idType != 1))
489         goto error2;
490
491     if ((pIconDirEntry = malloc(iconDir.idCount * sizeof (ICONDIRENTRY))) == NULL)
492         goto error2;
493     if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
494         goto error3;
495
496     for (i = 0; i < iconDir.idCount; i++)
497         if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
498         {
499             nIndex = i;
500             nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
501         }
502     if ((pIcon = malloc(pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
503         goto error3;
504     if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
505         goto error4;
506     if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
507         goto error4;
508
509     if(!SaveIconResAsXPM(pIcon, szXPMFileName))
510         goto error4;
511
512     free(pIcon);
513     free(pIconDirEntry);
514     fclose(fICOFile);
515
516     return 1;
517
518  error4:
519     free(pIcon);
520  error3:
521     free(pIconDirEntry);
522  error2:
523     fclose(fICOFile);
524  error1:
525     return 0;
526 }
527
528 /* get the Unix file name for a given path, allocating the string */
529 inline static char *get_unix_file_name( const char *dos )
530 {
531     char buffer[MAX_PATH];
532
533     if (!wine_get_unix_file_name( dos, buffer, sizeof(buffer) )) return NULL;
534     return heap_strdup( buffer );
535 }
536
537 static BOOL create_default_icon( const char *filename )
538 {
539     FILE *fXPM;
540     int i;
541
542     if (!(fXPM = fopen(filename, "w"))) return FALSE;
543     fprintf(fXPM, "/* XPM */\nstatic char * icon[] = {");
544     for (i = 0; i < sizeof(wine_xpm)/sizeof(wine_xpm[0]); i++)
545         fprintf( fXPM, "\n\"%s\",", wine_xpm[i]);
546     fprintf( fXPM, "};\n" );
547     fclose( fXPM );
548     return TRUE;
549 }
550
551 /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
552 static char *extract_icon( const char *path, int index )
553 {
554     char *filename = heap_strdup( tmpnam(NULL) );
555     if (ExtractFromEXEDLL( path, index, filename )) return filename;
556     if (ExtractFromICO( path, filename )) return filename;
557     if (create_default_icon( filename )) return filename;
558     HeapFree( GetProcessHeap(), 0, filename );
559     return NULL;
560 }
561
562
563 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
564 {
565     HRESULT ret = NOERROR;
566     int pid, status;
567     char buffer[MAX_PATH], buff2[MAX_PATH];
568     char *filename, *link_name, *p;
569     char *shell_link_app = NULL;
570     char *icon_name = NULL;
571     char *path_name = NULL;
572     char *work_dir = NULL;
573     BOOL bDesktop;
574     HKEY hkey;
575
576     _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
577
578     TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
579
580     if (!pszFileName || !This->sPath)
581         return ERROR_UNKNOWN;
582
583     /* check for .exe extension */
584     if (!(p = strrchr( This->sPath, '.' ))) return NOERROR;
585     if (strchr( p, '\\' ) || strchr( p, '/' )) return NOERROR;
586     if (strcasecmp( p, ".exe" )) return NOERROR;
587
588     /* check if ShellLinker configured */
589     buffer[0] = 0;
590     if (!RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine",
591                         0, KEY_ALL_ACCESS, &hkey ))
592     {
593         DWORD type, count = sizeof(buffer);
594         if (RegQueryValueExA( hkey, "ShellLinker", 0, &type, buffer, &count )) buffer[0] = 0;
595         RegCloseKey( hkey );
596     }
597     if (!*buffer) return NOERROR;
598     shell_link_app = heap_strdup( buffer );
599
600     if (!WideCharToMultiByte( CP_ACP, 0, pszFileName, -1, buffer, sizeof(buffer), NULL, NULL))
601         return ERROR_UNKNOWN;
602     GetFullPathNameA( buffer, sizeof(buff2), buff2, NULL );
603     filename = heap_strdup( buff2 );
604
605     if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTUP, FALSE ))
606     {
607         /* ignore startup for now */
608         if (!strncasecmp( filename, buffer, strlen(buffer) )) goto done;
609     }
610     if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_DESKTOPDIRECTORY, FALSE ))
611     {
612         if (!strncasecmp( filename, buffer, strlen(buffer) ))
613         {
614             link_name = filename + strlen(buffer);
615             bDesktop = TRUE;
616             goto found;
617         }
618     }
619     if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTMENU, FALSE ))
620     {
621         if (!strncasecmp( filename, buffer, strlen(buffer) ))
622         {
623             link_name = filename + strlen(buffer);
624             bDesktop = FALSE;
625             goto found;
626         }
627     }
628     goto done;
629
630  found:
631     /* make link name a Unix name */
632     for (p = link_name; *p; p++) if (*p == '\\') *p = '/';
633     /* strip leading slashes */
634     while (*link_name == '/') link_name++;
635     /* remove extension */
636     if ((p = strrchr( link_name, '.' ))) *p = 0;
637
638     /* convert app path name */
639     path_name = get_unix_file_name( This->sPath );
640
641     /* convert app working dir */
642     if (This->sWorkDir) work_dir = get_unix_file_name( This->sWorkDir );
643
644     /* extract the icon */
645     if (!(icon_name = extract_icon( This->sIcoPath && strlen(This->sIcoPath) ? 
646                                       This->sIcoPath : This->sPath,
647                                       This->iIcoNdx ))) goto done;
648
649
650     TRACE("linker app='%s' link='%s' mode=%s path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
651         shell_link_app, link_name, bDesktop ? "desktop" : "menu", path_name,
652         This->sArgs ? This->sArgs : "", icon_name, work_dir ? work_dir : "",
653         This->sDescription ? This->sDescription : "" );
654
655     if ((pid = fork()) == -1) goto done;
656     if (!pid)
657     {
658         int pos = 0;
659         char *argv[20];
660         argv[pos++] = shell_link_app;
661         argv[pos++] = "--link";
662         argv[pos++] = link_name;
663         argv[pos++] = "--path";
664         argv[pos++] = path_name;
665         argv[pos++] = bDesktop ? "--desktop" : "--menu";
666         if (This->sArgs && strlen(This->sArgs))
667         {
668             argv[pos++] = "--args";
669             argv[pos++] = This->sArgs;
670         }
671         if (icon_name)
672         {
673             argv[pos++] = "--icon";
674             argv[pos++] = icon_name;
675         }
676         if (This->sWorkDir && strlen(This->sWorkDir))
677         {
678             argv[pos++] = "--workdir";
679             argv[pos++] = This->sWorkDir;
680         }
681         if (This->sDescription && strlen(This->sDescription))
682         {
683             argv[pos++] = "--descr";
684             argv[pos++] = This->sDescription;
685         }
686         argv[pos] = NULL;
687         execvp( shell_link_app, argv );
688         _exit(1);
689     }
690
691     while (waitpid( pid, &status, 0 ) == -1)
692     {
693         if (errno != EINTR)
694         {
695             ret = ERROR_UNKNOWN;
696             goto done;
697         }
698     }
699     if (status) ret = E_ACCESSDENIED;
700
701  done:
702     if (icon_name) unlink( icon_name );
703     HeapFree( GetProcessHeap(), 0, shell_link_app );
704     HeapFree( GetProcessHeap(), 0, filename );
705     HeapFree( GetProcessHeap(), 0, icon_name );
706     HeapFree( GetProcessHeap(), 0, path_name );
707     HeapFree( GetProcessHeap(), 0, work_dir );
708     return ret;
709 }
710
711 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
712 {
713         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
714         FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
715         return NOERROR;
716 }
717 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
718 {
719         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
720         FIXME("(%p)\n",This);
721         return NOERROR;
722 }
723
724 static ICOM_VTABLE(IPersistFile) pfvt = 
725 {
726         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
727         IPersistFile_fnQueryInterface,
728         IPersistFile_fnAddRef,
729         IPersistFile_fnRelease,
730         IPersistFile_fnGetClassID,
731         IPersistFile_fnIsDirty,
732         IPersistFile_fnLoad,
733         IPersistFile_fnSave,
734         IPersistFile_fnSaveCompleted,
735         IPersistFile_fnGetCurFile
736 };
737
738 /************************************************************************
739  * IPersistStream_QueryInterface
740  */
741 static HRESULT WINAPI IPersistStream_fnQueryInterface(
742         IPersistStream* iface,
743         REFIID     riid,
744         VOID**     ppvoid)
745 {
746         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
747
748         TRACE("(%p)\n",This);
749
750         return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
751 }
752
753 /************************************************************************
754  * IPersistStream_Release
755  */
756 static ULONG WINAPI IPersistStream_fnRelease(
757         IPersistStream* iface)
758 {
759         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
760
761         TRACE("(%p)\n",This);
762
763         return IShellLinkA_Release((IShellLinkA*)This);
764 }
765
766 /************************************************************************
767  * IPersistStream_AddRef
768  */
769 static ULONG WINAPI IPersistStream_fnAddRef(
770         IPersistStream* iface)
771 {
772         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
773
774         TRACE("(%p)\n",This);
775
776         return IShellLinkA_AddRef((IShellLinkA*)This);
777
778
779 /************************************************************************
780  * IPersistStream_GetClassID
781  *
782  */
783 static HRESULT WINAPI IPersistStream_fnGetClassID(
784         IPersistStream* iface,
785         CLSID* pClassID)
786 {
787         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
788
789         TRACE("(%p)\n", This);
790
791         if (pClassID==0)
792           return E_POINTER;
793
794 /*      memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
795
796         return S_OK;
797 }
798
799 /************************************************************************
800  * IPersistStream_IsDirty (IPersistStream)
801  */
802 static HRESULT WINAPI IPersistStream_fnIsDirty(
803         IPersistStream*  iface)
804 {
805         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
806
807         TRACE("(%p)\n", This);
808
809         return S_OK;
810 }
811 /************************************************************************
812  * IPersistStream_Load (IPersistStream)
813  */
814
815 static HRESULT WINAPI IPersistStream_fnLoad(
816         IPersistStream*  iface,
817         IStream*         pLoadStream)
818 {
819         PLINK_HEADER lpLinkHeader = HeapAlloc(GetProcessHeap(), 0, LINK_HEADER_SIZE);
820         ULONG   dwBytesRead;
821         DWORD   ret = E_FAIL;
822         char    sTemp[MAX_PATH];
823         
824         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
825
826         TRACE("(%p)(%p)\n", This, pLoadStream);
827
828         if ( ! pLoadStream)
829         {
830           return STG_E_INVALIDPOINTER;
831         }
832         
833         IStream_AddRef (pLoadStream);
834         if(lpLinkHeader)
835         {
836           if (SUCCEEDED(IStream_Read(pLoadStream, lpLinkHeader, LINK_HEADER_SIZE, &dwBytesRead)))
837           {
838             if ((lpLinkHeader->MagicStr == 0x0000004CL) && IsEqualIID(&lpLinkHeader->MagicGuid, &CLSID_ShellLink))
839             {
840               lpLinkHeader = HeapReAlloc(GetProcessHeap(), 0, lpLinkHeader, LINK_HEADER_SIZE+lpLinkHeader->PidlSize);
841               if (lpLinkHeader)
842               {
843                 if (SUCCEEDED(IStream_Read(pLoadStream, &(lpLinkHeader->Pidl), lpLinkHeader->PidlSize, &dwBytesRead)))
844                 {
845                   if (pcheck (&lpLinkHeader->Pidl))
846                   {     
847                     This->pPidl = ILClone (&lpLinkHeader->Pidl);
848
849                     SHGetPathFromIDListA(&lpLinkHeader->Pidl, sTemp);
850                     This->sPath = heap_strdup( sTemp );
851                   }
852                   This->wHotKey = lpLinkHeader->wHotKey;
853                   FileTimeToSystemTime (&lpLinkHeader->Time1, &This->time1);
854                   FileTimeToSystemTime (&lpLinkHeader->Time2, &This->time2);
855                   FileTimeToSystemTime (&lpLinkHeader->Time3, &This->time3);
856 #if 1
857                   GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
858                   TRACE("-- time1: %s\n", sTemp);
859                   GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
860                   TRACE("-- time1: %s\n", sTemp);
861                   GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
862                   TRACE("-- time1: %s\n", sTemp);
863                   pdump (This->pPidl);
864 #endif            
865                   ret = S_OK;
866                 }
867               }
868             }
869             else
870             {
871               WARN("stream contains no link!\n");
872             }
873           }
874         }
875
876         IStream_Release (pLoadStream);
877
878         pdump(This->pPidl);
879         
880         HeapFree(GetProcessHeap(), 0, lpLinkHeader);
881
882         return ret;
883 }
884
885 /************************************************************************
886  * IPersistStream_Save (IPersistStream)
887  */
888 static HRESULT WINAPI IPersistStream_fnSave(
889         IPersistStream*  iface,
890         IStream*         pOutStream,
891         BOOL             fClearDirty)
892 {
893         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
894         
895         TRACE("(%p) %p %x\n", This, pOutStream, fClearDirty);
896
897         return E_NOTIMPL;
898 }
899
900 /************************************************************************
901  * IPersistStream_GetSizeMax (IPersistStream)
902  */
903 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
904         IPersistStream*  iface,
905         ULARGE_INTEGER*  pcbSize)
906 {
907         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
908         
909         TRACE("(%p)\n", This);
910
911         return E_NOTIMPL;
912 }
913
914 static ICOM_VTABLE(IPersistStream) psvt =
915 {
916         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
917         IPersistStream_fnQueryInterface,
918         IPersistStream_fnAddRef,
919         IPersistStream_fnRelease,
920         IPersistStream_fnGetClassID,
921         IPersistStream_fnIsDirty,
922         IPersistStream_fnLoad,
923         IPersistStream_fnSave,
924         IPersistStream_fnGetSizeMax
925 };
926
927 /**************************************************************************
928  *        IShellLink_Constructor
929  */
930 IShellLinkA * IShellLink_Constructor(BOOL bUnicode) 
931 {       IShellLinkImpl * sl;
932
933         sl = (IShellLinkImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IShellLinkImpl));
934         sl->ref = 1;
935         ICOM_VTBL(sl) = &slvt;
936         sl->lpvtblw = &slvtw;
937         sl->lpvtblPersistFile = &pfvt;
938         sl->lpvtblPersistStream = &psvt;
939         
940         TRACE("(%p)->()\n",sl);
941         shell32_ObjCount++;
942         return bUnicode ? (IShellLinkA *) &(sl->lpvtblw) : (IShellLinkA *)sl;
943 }
944
945 /**************************************************************************
946  *  IShellLinkA_QueryInterface
947  */
948 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid,  LPVOID *ppvObj)
949 {
950         ICOM_THIS(IShellLinkImpl, iface);
951         
952         TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
953
954         *ppvObj = NULL;
955
956         if(IsEqualIID(riid, &IID_IUnknown) ||
957            IsEqualIID(riid, &IID_IShellLinkA))
958         {
959           *ppvObj = This;
960         }   
961         else if(IsEqualIID(riid, &IID_IShellLinkW))
962         {
963           *ppvObj = (IShellLinkW *)&(This->lpvtblw);
964         }   
965         else if(IsEqualIID(riid, &IID_IPersistFile))
966         {
967           *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
968         }
969         else if(IsEqualIID(riid, &IID_IPersistStream))
970         {
971           *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
972         }   
973
974         if(*ppvObj)
975         {
976           IUnknown_AddRef((IUnknown*)(*ppvObj));
977           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
978           return S_OK;
979         }
980         TRACE("-- Interface: E_NOINTERFACE\n");
981         return E_NOINTERFACE;
982 }  
983 /******************************************************************************
984  * IShellLinkA_AddRef
985  */
986 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
987 {
988         ICOM_THIS(IShellLinkImpl, iface);
989         
990         TRACE("(%p)->(count=%lu)\n",This,This->ref);
991
992         shell32_ObjCount++;
993         return ++(This->ref);
994 }
995 /******************************************************************************
996  *      IShellLinkA_Release
997  */
998 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
999 {
1000         ICOM_THIS(IShellLinkImpl, iface);
1001         
1002         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1003
1004         shell32_ObjCount--;
1005         if (!--(This->ref)) 
1006         { TRACE("-- destroying IShellLink(%p)\n",This);
1007         
1008           if (This->sIcoPath)
1009             HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1010             
1011           if (This->sArgs)
1012             HeapFree(GetProcessHeap(), 0, This->sArgs);
1013
1014           if (This->sWorkDir)
1015             HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1016             
1017           if (This->sDescription)
1018             HeapFree(GetProcessHeap(), 0, This->sDescription);
1019
1020           if (This->sPath)
1021             HeapFree(GetProcessHeap(),0,This->sPath);
1022
1023           if (This->pPidl)
1024             SHFree(This->pPidl);
1025
1026           if (This->lpFileStream)
1027             IStream_Release(This->lpFileStream);
1028         
1029           This->iIcoNdx = 0;
1030
1031           HeapFree(GetProcessHeap(),0,This);
1032           return 0;
1033         }
1034         return This->ref;
1035 }
1036
1037 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1038 {
1039         ICOM_THIS(IShellLinkImpl, iface);
1040         
1041         TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",This, pszFile, cchMaxPath, pfd, fFlags, debugstr_a(This->sPath));
1042
1043         if (This->sPath)
1044           lstrcpynA(pszFile,This->sPath, cchMaxPath);
1045         else
1046           return E_FAIL;
1047
1048         return NOERROR;
1049 }
1050 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1051 {
1052         ICOM_THIS(IShellLinkImpl, iface);
1053         
1054         TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1055
1056         *ppidl = ILClone(This->pPidl);
1057         return NOERROR;
1058 }
1059 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1060 {
1061         ICOM_THIS(IShellLinkImpl, iface);
1062         
1063         TRACE("(%p)->(pidl=%p)\n",This, pidl);
1064
1065         if (This->pPidl)
1066             SHFree(This->pPidl);
1067         This->pPidl = ILClone (pidl);
1068         return NOERROR;
1069 }
1070 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1071 {
1072         ICOM_THIS(IShellLinkImpl, iface);
1073         
1074         FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1075         lstrcpynA(pszName,"Description, FIXME",cchMaxName);
1076         return NOERROR;
1077 }
1078 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1079 {
1080         ICOM_THIS(IShellLinkImpl, iface);
1081         
1082         TRACE("(%p)->(pName=%s)\n", This, pszName);
1083
1084         if (This->sDescription)
1085             HeapFree(GetProcessHeap(), 0, This->sDescription);
1086         if (!(This->sDescription = heap_strdup(pszName)))
1087             return E_OUTOFMEMORY;
1088
1089         return NOERROR;
1090 }
1091 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1092 {
1093         ICOM_THIS(IShellLinkImpl, iface);
1094         
1095         TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1096
1097         lstrcpynA( pszDir, This->sWorkDir ? This->sWorkDir : "", cchMaxPath );
1098
1099         return NOERROR;
1100 }
1101 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1102 {
1103         ICOM_THIS(IShellLinkImpl, iface);
1104         
1105         TRACE("(%p)->(dir=%s)\n",This, pszDir);
1106
1107         if (This->sWorkDir)
1108             HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1109         if (!(This->sWorkDir = heap_strdup(pszDir)))
1110             return E_OUTOFMEMORY;
1111
1112         return NOERROR;
1113 }
1114 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1115 {
1116         ICOM_THIS(IShellLinkImpl, iface);
1117         
1118         TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1119
1120         lstrcpynA( pszArgs, This->sArgs ? This->sArgs : "", cchMaxPath );
1121
1122         return NOERROR;
1123 }
1124 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1125 {
1126         ICOM_THIS(IShellLinkImpl, iface);
1127         
1128         TRACE("(%p)->(args=%s)\n",This, pszArgs);
1129
1130         if (This->sArgs)
1131             HeapFree(GetProcessHeap(), 0, This->sArgs);
1132         if (!(This->sArgs = heap_strdup(pszArgs)))
1133             return E_OUTOFMEMORY;
1134
1135         return NOERROR;
1136 }
1137 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1138 {
1139         ICOM_THIS(IShellLinkImpl, iface);
1140         
1141         TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1142
1143         *pwHotkey = This->wHotKey;
1144
1145         return NOERROR;
1146 }
1147 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1148 {
1149         ICOM_THIS(IShellLinkImpl, iface);
1150         
1151         TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1152         
1153         This->wHotKey = wHotkey;
1154
1155         return NOERROR;
1156 }
1157 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1158 {
1159         ICOM_THIS(IShellLinkImpl, iface);
1160         
1161         FIXME("(%p)->(%p)\n",This, piShowCmd);
1162         *piShowCmd=0;
1163         return NOERROR;
1164 }
1165 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1166 {
1167         ICOM_THIS(IShellLinkImpl, iface);
1168         
1169         FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1170         return NOERROR;
1171 }
1172 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1173 {
1174         ICOM_THIS(IShellLinkImpl, iface);
1175         
1176         TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1177
1178         lstrcpynA( pszIconPath, This->sIcoPath ? This->sIcoPath : "", cchIconPath );
1179         *piIcon = This->iIcoNdx;
1180
1181         return NOERROR;
1182 }
1183 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1184 {
1185         ICOM_THIS(IShellLinkImpl, iface);
1186         
1187         TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1188         
1189         if (This->sIcoPath)
1190             HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1191         if (!(This->sIcoPath = heap_strdup(pszIconPath)))
1192             return E_OUTOFMEMORY;       
1193         This->iIcoNdx = iIcon;
1194         
1195         return NOERROR;
1196 }
1197 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1198 {
1199         ICOM_THIS(IShellLinkImpl, iface);
1200         
1201         FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1202         return NOERROR;
1203 }
1204 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1205 {
1206         ICOM_THIS(IShellLinkImpl, iface);
1207         
1208         FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1209         return NOERROR;
1210 }
1211 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1212 {
1213         ICOM_THIS(IShellLinkImpl, iface);
1214         
1215         TRACE("(%p)->(path=%s)\n",This, pszFile);
1216
1217         if (This->sPath)
1218             HeapFree(GetProcessHeap(), 0, This->sPath);
1219         if (!(This->sPath = heap_strdup(pszFile)))
1220             return E_OUTOFMEMORY;
1221         
1222         return NOERROR;
1223 }
1224
1225 /**************************************************************************
1226 * IShellLink Implementation
1227 */
1228
1229 static ICOM_VTABLE(IShellLinkA) slvt = 
1230 {       
1231         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1232         IShellLinkA_fnQueryInterface,
1233         IShellLinkA_fnAddRef,
1234         IShellLinkA_fnRelease,
1235         IShellLinkA_fnGetPath,
1236         IShellLinkA_fnGetIDList,
1237         IShellLinkA_fnSetIDList,
1238         IShellLinkA_fnGetDescription,
1239         IShellLinkA_fnSetDescription,
1240         IShellLinkA_fnGetWorkingDirectory,
1241         IShellLinkA_fnSetWorkingDirectory,
1242         IShellLinkA_fnGetArguments,
1243         IShellLinkA_fnSetArguments,
1244         IShellLinkA_fnGetHotkey,
1245         IShellLinkA_fnSetHotkey,
1246         IShellLinkA_fnGetShowCmd,
1247         IShellLinkA_fnSetShowCmd,
1248         IShellLinkA_fnGetIconLocation,
1249         IShellLinkA_fnSetIconLocation,
1250         IShellLinkA_fnSetRelativePath,
1251         IShellLinkA_fnResolve,
1252         IShellLinkA_fnSetPath
1253 };
1254
1255
1256 /**************************************************************************
1257  *  IShellLinkW_fnQueryInterface
1258  */
1259 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1260   IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1261 {
1262         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1263         
1264         return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1265 }
1266
1267 /******************************************************************************
1268  * IShellLinkW_fnAddRef
1269  */
1270 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1271 {
1272         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1273         
1274         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1275
1276         return IShellLinkA_AddRef((IShellLinkA*)This);
1277 }
1278 /******************************************************************************
1279  * IShellLinkW_fnRelease
1280  */
1281
1282 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1283 {
1284         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1285         
1286         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1287
1288         return IShellLinkA_Release((IShellLinkA*)This);
1289 }
1290
1291 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1292 {
1293         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1294         
1295         FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1296         MultiByteToWideChar( CP_ACP, 0, "c:\\foo.bar", -1, pszFile, cchMaxPath );
1297         return NOERROR;
1298 }
1299
1300 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1301 {
1302         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1303         
1304         FIXME("(%p)->(ppidl=%p)\n",This, ppidl);
1305         *ppidl = _ILCreateDesktop();
1306         return NOERROR;
1307 }
1308
1309 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1310 {
1311         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1312         
1313         FIXME("(%p)->(pidl=%p)\n",This, pidl);
1314         return NOERROR;
1315 }
1316
1317 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1318 {
1319         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1320         
1321         FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1322         MultiByteToWideChar( CP_ACP, 0, "Description, FIXME", -1, pszName, cchMaxName );
1323         return NOERROR;
1324 }
1325
1326 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1327 {
1328         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1329         
1330         TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1331
1332         if (This->sDescription)
1333             HeapFree(GetProcessHeap(), 0, This->sDescription);
1334         if (!(This->sDescription = HEAP_strdupWtoA(GetProcessHeap(), 0, pszName)))
1335             return E_OUTOFMEMORY;
1336                 
1337         return NOERROR;
1338 }
1339
1340 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1341 {
1342         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1343         
1344         TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1345
1346         MultiByteToWideChar( CP_ACP, 0, This->sWorkDir ? This->sWorkDir : "", -1, pszDir, cchMaxPath );
1347
1348         return NOERROR;
1349 }
1350
1351 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1352 {
1353         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1354         
1355         TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1356
1357         if (This->sWorkDir)
1358             HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1359         if (!(This->sWorkDir = HEAP_strdupWtoA(GetProcessHeap(), 0, pszDir)))
1360             return E_OUTOFMEMORY;
1361
1362         return NOERROR;
1363 }
1364
1365 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1366 {
1367         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1368         
1369         TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1370
1371         MultiByteToWideChar( CP_ACP, 0, This->sArgs ? This->sArgs : "", -1, pszArgs, cchMaxPath );
1372
1373         return NOERROR;
1374 }
1375
1376 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1377 {
1378         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1379         
1380         TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1381         
1382         if (This->sArgs)
1383             HeapFree(GetProcessHeap(), 0, This->sArgs);
1384         if (!(This->sArgs = HEAP_strdupWtoA(GetProcessHeap(), 0, pszArgs)))
1385             return E_OUTOFMEMORY;
1386         
1387         return NOERROR;
1388 }
1389
1390 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1391 {
1392         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1393         
1394         FIXME("(%p)->(%p)\n",This, pwHotkey);
1395         *pwHotkey=0x0;
1396         return NOERROR;
1397 }
1398
1399 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1400 {
1401         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1402         
1403         FIXME("(%p)->(hotkey=%x)\n",This, wHotkey);
1404         return NOERROR;
1405 }
1406
1407 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1408 {
1409         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1410         
1411         FIXME("(%p)->(%p)\n",This, piShowCmd);
1412         *piShowCmd=0;
1413         return NOERROR;
1414 }
1415
1416 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1417 {
1418         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1419         
1420         FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1421         return NOERROR;
1422 }
1423
1424 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1425 {
1426         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1427         
1428         TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1429
1430         MultiByteToWideChar( CP_ACP, 0, This->sIcoPath ? This->sIcoPath : "", -1, pszIconPath, cchIconPath );
1431         *piIcon = This->iIcoNdx;
1432
1433         return NOERROR;
1434 }
1435
1436 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1437 {
1438         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1439         
1440         TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1441
1442         if (This->sIcoPath)
1443             HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1444         if (!(This->sIcoPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszIconPath)))
1445             return E_OUTOFMEMORY;       
1446         This->iIcoNdx = iIcon;
1447
1448         return NOERROR;
1449 }
1450
1451 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1452 {
1453         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1454         
1455         FIXME("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1456         return NOERROR;
1457 }
1458
1459 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1460 {
1461         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1462         
1463         FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1464         return NOERROR;
1465 }
1466
1467 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1468 {
1469         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1470         
1471         TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1472         
1473         if (This->sPath)
1474             HeapFree(GetProcessHeap(), 0, This->sPath);
1475         if (!(This->sPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszFile)))
1476             return E_OUTOFMEMORY;       
1477         
1478         return NOERROR;
1479 }
1480
1481 /**************************************************************************
1482 * IShellLinkW Implementation
1483 */
1484
1485 static ICOM_VTABLE(IShellLinkW) slvtw = 
1486 {       
1487         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1488         IShellLinkW_fnQueryInterface,
1489         IShellLinkW_fnAddRef,
1490         IShellLinkW_fnRelease,
1491         IShellLinkW_fnGetPath,
1492         IShellLinkW_fnGetIDList,
1493         IShellLinkW_fnSetIDList,
1494         IShellLinkW_fnGetDescription,
1495         IShellLinkW_fnSetDescription,
1496         IShellLinkW_fnGetWorkingDirectory,
1497         IShellLinkW_fnSetWorkingDirectory,
1498         IShellLinkW_fnGetArguments,
1499         IShellLinkW_fnSetArguments,
1500         IShellLinkW_fnGetHotkey,
1501         IShellLinkW_fnSetHotkey,
1502         IShellLinkW_fnGetShowCmd,
1503         IShellLinkW_fnSetShowCmd,
1504         IShellLinkW_fnGetIconLocation,
1505         IShellLinkW_fnSetIconLocation,
1506         IShellLinkW_fnSetRelativePath,
1507         IShellLinkW_fnResolve,
1508         IShellLinkW_fnSetPath
1509 };
1510