Void functions can't return a value, even if it is the return value
[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     int nodefault = 1;
555     char *filename = heap_strdup( tmpnam(NULL) );
556
557     /* If icon path begins with a '*' then this is a deferred call */
558     if (path[0] == '*')
559     {
560         path++;
561         nodefault = 0;
562     }
563     if (ExtractFromEXEDLL( path, index, filename )) return filename;
564     if (ExtractFromICO( path, filename )) return filename;
565     if (!nodefault)
566         if (create_default_icon( filename )) return filename;
567     HeapFree( GetProcessHeap(), 0, filename );
568     return NULL;
569 }
570
571
572 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
573 {
574     HRESULT ret = NOERROR;
575     int pid, status;
576     char buffer[MAX_PATH], buff2[MAX_PATH], ascii_filename[MAX_PATH];
577     char *filename, *link_name, *p;
578     char *shell_link_app = NULL;
579     char *icon_name = NULL;
580     char *work_dir = NULL;
581     BOOL bDesktop;
582     HKEY hkey;
583
584     _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
585
586     TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
587
588     if (!pszFileName || !This->sPath)
589         return ERROR_UNKNOWN;
590
591     /* check for .exe extension */
592     if (!(p = strrchr( This->sPath, '.' ))) return NOERROR;
593     if (strchr( p, '\\' ) || strchr( p, '/' )) return NOERROR;
594     if (strcasecmp( p, ".exe" )) return NOERROR;
595
596     /* check if ShellLinker configured */
597     buffer[0] = 0;
598     if (!RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine",
599                         0, KEY_ALL_ACCESS, &hkey ))
600     {
601         DWORD type, count = sizeof(buffer);
602         if (RegQueryValueExA( hkey, "ShellLinker", 0, &type, buffer, &count )) buffer[0] = 0;
603         RegCloseKey( hkey );
604     }
605     if (!*buffer) return NOERROR;
606     shell_link_app = heap_strdup( buffer );
607
608     if (!WideCharToMultiByte( CP_ACP, 0, pszFileName, -1, ascii_filename, sizeof(ascii_filename), NULL, NULL))
609         return ERROR_UNKNOWN;
610     GetFullPathNameA( ascii_filename, sizeof(buff2), buff2, NULL );
611     filename = heap_strdup( buff2 );
612
613     if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTUP, FALSE ))
614     {
615         /* ignore startup for now */
616         if (!strncasecmp( filename, buffer, strlen(buffer) )) goto done;
617     }
618     if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_DESKTOPDIRECTORY, FALSE ))
619     {
620         if (!strncasecmp( filename, buffer, strlen(buffer) ))
621         {
622             link_name = filename + strlen(buffer);
623             bDesktop = TRUE;
624             goto found;
625         }
626     }
627     if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTMENU, FALSE ))
628     {
629         if (!strncasecmp( filename, buffer, strlen(buffer) ))
630         {
631             link_name = filename + strlen(buffer);
632             bDesktop = FALSE;
633             goto found;
634         }
635     }
636     goto done;
637
638  found:
639     /* make link name a Unix name */
640     for (p = link_name; *p; p++) if (*p == '\\') *p = '/';
641     /* strip leading slashes */
642     while (*link_name == '/') link_name++;
643     /* remove extension */
644     if ((p = strrchr( link_name, '.' ))) *p = 0;
645
646     /* convert app working dir */
647     if (This->sWorkDir) work_dir = get_unix_file_name( This->sWorkDir );
648
649     /* extract the icon */
650     if (!(icon_name = extract_icon( This->sIcoPath && strlen(This->sIcoPath) ?
651                                       This->sIcoPath : This->sPath,
652                                       This->iIcoNdx )))
653     {
654         /* Couldn't extract icon --  defer this menu entry to runonce. */
655         HKEY hRunOnce;
656         char* buffer = NULL;
657
658         TRACE("Deferring icon creation to reboot.\n");
659         if (RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce", 0,
660                 NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hRunOnce, NULL) != ERROR_SUCCESS)
661         {
662             ret = ERROR_UNKNOWN;
663             goto done;
664         }
665         buffer = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * 3 + (This->sArgs ? strlen(This->sArgs) : 0) +
666                            (This->sDescription ? strlen(This->sDescription) : 0) + 200);
667         sprintf(buffer, "link:%s\xff*%s\xff%d\xff%s\xff%s\xff%s", This->sPath, This->sIcoPath, This->iIcoNdx,
668             This->sArgs ? This->sArgs : "", This->sDescription ? This->sDescription : "",
669             This->sWorkDir ? This->sWorkDir : "");
670         if (RegSetValueExA(hRunOnce, ascii_filename, 0, REG_SZ, buffer, strlen(buffer) + 1) != ERROR_SUCCESS)
671         {
672             HeapFree(GetProcessHeap(), 0, buffer);
673             RegCloseKey(hRunOnce);
674             ret = ERROR_UNKNOWN;
675             goto done;
676         }
677         HeapFree(GetProcessHeap(), 0, buffer);
678         RegCloseKey(hRunOnce);
679         goto done;
680     }
681
682     TRACE("linker app='%s' link='%s' mode=%s path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
683         shell_link_app, link_name, bDesktop ? "desktop" : "menu", This->sPath,
684         This->sArgs ? This->sArgs : "", icon_name, work_dir ? work_dir : "",
685         This->sDescription ? This->sDescription : "" );
686
687     if ((pid = fork()) == -1) goto done;
688     if (!pid)
689     {
690         int pos = 0;
691         char *argv[20];
692         argv[pos++] = shell_link_app;
693         argv[pos++] = "--link";
694         argv[pos++] = link_name;
695         argv[pos++] = "--path";
696         argv[pos++] = This->sPath;
697         argv[pos++] = bDesktop ? "--desktop" : "--menu";
698         if (This->sArgs && strlen(This->sArgs))
699         {
700             argv[pos++] = "--args";
701             argv[pos++] = This->sArgs;
702         }
703         if (icon_name)
704         {
705             argv[pos++] = "--icon";
706             argv[pos++] = icon_name;
707         }
708         if (This->sWorkDir && strlen(This->sWorkDir))
709         {
710             argv[pos++] = "--workdir";
711             argv[pos++] = This->sWorkDir;
712         }
713         if (This->sDescription && strlen(This->sDescription))
714         {
715             argv[pos++] = "--descr";
716             argv[pos++] = This->sDescription;
717         }
718         argv[pos] = NULL;
719         execvp( shell_link_app, argv );
720         _exit(1);
721     }
722
723     while (waitpid( pid, &status, 0 ) == -1)
724     {
725         if (errno != EINTR)
726         {
727             ret = ERROR_UNKNOWN;
728             goto done;
729         }
730     }
731     if (status) ret = E_ACCESSDENIED;
732
733  done:
734     if (icon_name) unlink( icon_name );
735     HeapFree( GetProcessHeap(), 0, shell_link_app );
736     HeapFree( GetProcessHeap(), 0, filename );
737     HeapFree( GetProcessHeap(), 0, icon_name );
738     HeapFree( GetProcessHeap(), 0, work_dir );
739     return ret;
740 }
741
742 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
743 {
744         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
745         FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
746         return NOERROR;
747 }
748 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
749 {
750         _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
751         FIXME("(%p)\n",This);
752         return NOERROR;
753 }
754
755 static ICOM_VTABLE(IPersistFile) pfvt =
756 {
757         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
758         IPersistFile_fnQueryInterface,
759         IPersistFile_fnAddRef,
760         IPersistFile_fnRelease,
761         IPersistFile_fnGetClassID,
762         IPersistFile_fnIsDirty,
763         IPersistFile_fnLoad,
764         IPersistFile_fnSave,
765         IPersistFile_fnSaveCompleted,
766         IPersistFile_fnGetCurFile
767 };
768
769 /************************************************************************
770  * IPersistStream_QueryInterface
771  */
772 static HRESULT WINAPI IPersistStream_fnQueryInterface(
773         IPersistStream* iface,
774         REFIID     riid,
775         VOID**     ppvoid)
776 {
777         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
778
779         TRACE("(%p)\n",This);
780
781         return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
782 }
783
784 /************************************************************************
785  * IPersistStream_Release
786  */
787 static ULONG WINAPI IPersistStream_fnRelease(
788         IPersistStream* iface)
789 {
790         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
791
792         TRACE("(%p)\n",This);
793
794         return IShellLinkA_Release((IShellLinkA*)This);
795 }
796
797 /************************************************************************
798  * IPersistStream_AddRef
799  */
800 static ULONG WINAPI IPersistStream_fnAddRef(
801         IPersistStream* iface)
802 {
803         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
804
805         TRACE("(%p)\n",This);
806
807         return IShellLinkA_AddRef((IShellLinkA*)This);
808 }
809
810 /************************************************************************
811  * IPersistStream_GetClassID
812  *
813  */
814 static HRESULT WINAPI IPersistStream_fnGetClassID(
815         IPersistStream* iface,
816         CLSID* pClassID)
817 {
818         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
819
820         TRACE("(%p)\n", This);
821
822         if (pClassID==0)
823           return E_POINTER;
824
825 /*      memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
826
827         return S_OK;
828 }
829
830 /************************************************************************
831  * IPersistStream_IsDirty (IPersistStream)
832  */
833 static HRESULT WINAPI IPersistStream_fnIsDirty(
834         IPersistStream*  iface)
835 {
836         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
837
838         TRACE("(%p)\n", This);
839
840         return S_OK;
841 }
842 /************************************************************************
843  * IPersistStream_Load (IPersistStream)
844  */
845
846 static HRESULT WINAPI IPersistStream_fnLoad(
847         IPersistStream*  iface,
848         IStream*         pLoadStream)
849 {
850         PLINK_HEADER lpLinkHeader = HeapAlloc(GetProcessHeap(), 0, LINK_HEADER_SIZE);
851         ULONG   dwBytesRead;
852         DWORD   ret = E_FAIL;
853         char    sTemp[MAX_PATH];
854
855         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
856
857         TRACE("(%p)(%p)\n", This, pLoadStream);
858
859         if ( ! pLoadStream)
860         {
861           return STG_E_INVALIDPOINTER;
862         }
863
864         IStream_AddRef (pLoadStream);
865         if(lpLinkHeader)
866         {
867           if (SUCCEEDED(IStream_Read(pLoadStream, lpLinkHeader, LINK_HEADER_SIZE, &dwBytesRead)))
868           {
869             if ((lpLinkHeader->MagicStr == 0x0000004CL) && IsEqualIID(&lpLinkHeader->MagicGuid, &CLSID_ShellLink))
870             {
871               lpLinkHeader = HeapReAlloc(GetProcessHeap(), 0, lpLinkHeader, LINK_HEADER_SIZE+lpLinkHeader->PidlSize);
872               if (lpLinkHeader)
873               {
874                 if (SUCCEEDED(IStream_Read(pLoadStream, &(lpLinkHeader->Pidl), lpLinkHeader->PidlSize, &dwBytesRead)))
875                 {
876                   if (pcheck (&lpLinkHeader->Pidl))
877                   {
878                     This->pPidl = ILClone (&lpLinkHeader->Pidl);
879
880                     SHGetPathFromIDListA(&lpLinkHeader->Pidl, sTemp);
881                     This->sPath = heap_strdup( sTemp );
882                   }
883                   This->wHotKey = lpLinkHeader->wHotKey;
884                   FileTimeToSystemTime (&lpLinkHeader->Time1, &This->time1);
885                   FileTimeToSystemTime (&lpLinkHeader->Time2, &This->time2);
886                   FileTimeToSystemTime (&lpLinkHeader->Time3, &This->time3);
887 #if 1
888                   GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
889                   TRACE("-- time1: %s\n", sTemp);
890                   GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
891                   TRACE("-- time1: %s\n", sTemp);
892                   GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
893                   TRACE("-- time1: %s\n", sTemp);
894                   pdump (This->pPidl);
895 #endif
896                   ret = S_OK;
897                 }
898               }
899             }
900             else
901             {
902               WARN("stream contains no link!\n");
903             }
904           }
905         }
906
907         IStream_Release (pLoadStream);
908
909         pdump(This->pPidl);
910
911         HeapFree(GetProcessHeap(), 0, lpLinkHeader);
912
913         return ret;
914 }
915
916 /************************************************************************
917  * IPersistStream_Save (IPersistStream)
918  */
919 static HRESULT WINAPI IPersistStream_fnSave(
920         IPersistStream*  iface,
921         IStream*         pOutStream,
922         BOOL             fClearDirty)
923 {
924         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
925
926         TRACE("(%p) %p %x\n", This, pOutStream, fClearDirty);
927
928         return E_NOTIMPL;
929 }
930
931 /************************************************************************
932  * IPersistStream_GetSizeMax (IPersistStream)
933  */
934 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
935         IPersistStream*  iface,
936         ULARGE_INTEGER*  pcbSize)
937 {
938         _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
939
940         TRACE("(%p)\n", This);
941
942         return E_NOTIMPL;
943 }
944
945 static ICOM_VTABLE(IPersistStream) psvt =
946 {
947         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
948         IPersistStream_fnQueryInterface,
949         IPersistStream_fnAddRef,
950         IPersistStream_fnRelease,
951         IPersistStream_fnGetClassID,
952         IPersistStream_fnIsDirty,
953         IPersistStream_fnLoad,
954         IPersistStream_fnSave,
955         IPersistStream_fnGetSizeMax
956 };
957
958 /**************************************************************************
959  *        IShellLink_Constructor
960  */
961 HRESULT WINAPI IShellLink_Constructor (
962         IUnknown * pUnkOuter,
963         REFIID riid,
964         LPVOID * ppv)
965 {
966         IShellLinkImpl * sl;
967
968         TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
969
970         *ppv = NULL;
971
972         if(pUnkOuter) return CLASS_E_NOAGGREGATION;
973         sl = (IShellLinkImpl *) LocalAlloc(GMEM_ZEROINIT,sizeof(IShellLinkImpl));
974         if (!sl) return E_OUTOFMEMORY;
975
976         sl->ref = 1;
977         ICOM_VTBL(sl) = &slvt;
978         sl->lpvtblw = &slvtw;
979         sl->lpvtblPersistFile = &pfvt;
980         sl->lpvtblPersistStream = &psvt;
981
982         TRACE("(%p)->()\n",sl);
983
984         if (IsEqualIID(riid, &IID_IShellLinkA))
985             *ppv = sl;
986         else if (IsEqualIID(riid, &IID_IShellLinkW))
987             *ppv = &(sl->lpvtblw);
988         else {
989             LocalFree((HLOCAL)sl);
990             ERR("E_NOINTERFACE\n");
991             return E_NOINTERFACE;
992         }
993
994         shell32_ObjCount++;
995         return S_OK;
996 }
997
998 /**************************************************************************
999  *  IShellLinkA_QueryInterface
1000  */
1001 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid,  LPVOID *ppvObj)
1002 {
1003         ICOM_THIS(IShellLinkImpl, iface);
1004
1005         TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
1006
1007         *ppvObj = NULL;
1008
1009         if(IsEqualIID(riid, &IID_IUnknown) ||
1010            IsEqualIID(riid, &IID_IShellLinkA))
1011         {
1012           *ppvObj = This;
1013         }
1014         else if(IsEqualIID(riid, &IID_IShellLinkW))
1015         {
1016           *ppvObj = (IShellLinkW *)&(This->lpvtblw);
1017         }
1018         else if(IsEqualIID(riid, &IID_IPersistFile))
1019         {
1020           *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
1021         }
1022         else if(IsEqualIID(riid, &IID_IPersistStream))
1023         {
1024           *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
1025         }
1026
1027         if(*ppvObj)
1028         {
1029           IUnknown_AddRef((IUnknown*)(*ppvObj));
1030           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
1031           return S_OK;
1032         }
1033         TRACE("-- Interface: E_NOINTERFACE\n");
1034         return E_NOINTERFACE;
1035 }
1036 /******************************************************************************
1037  * IShellLinkA_AddRef
1038  */
1039 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
1040 {
1041         ICOM_THIS(IShellLinkImpl, iface);
1042
1043         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1044
1045         shell32_ObjCount++;
1046         return ++(This->ref);
1047 }
1048 /******************************************************************************
1049  *      IShellLinkA_Release
1050  */
1051 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
1052 {
1053         ICOM_THIS(IShellLinkImpl, iface);
1054
1055         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1056
1057         shell32_ObjCount--;
1058         if (!--(This->ref))
1059         { TRACE("-- destroying IShellLink(%p)\n",This);
1060
1061           if (This->sIcoPath)
1062             HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1063
1064           if (This->sArgs)
1065             HeapFree(GetProcessHeap(), 0, This->sArgs);
1066
1067           if (This->sWorkDir)
1068             HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1069
1070           if (This->sDescription)
1071             HeapFree(GetProcessHeap(), 0, This->sDescription);
1072
1073           if (This->sPath)
1074             HeapFree(GetProcessHeap(),0,This->sPath);
1075
1076           if (This->pPidl)
1077             SHFree(This->pPidl);
1078
1079           if (This->lpFileStream)
1080             IStream_Release(This->lpFileStream);
1081
1082           This->iIcoNdx = 0;
1083
1084           LocalFree((HANDLE)This);
1085           return 0;
1086         }
1087         return This->ref;
1088 }
1089
1090 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1091 {
1092         ICOM_THIS(IShellLinkImpl, iface);
1093
1094         TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",This, pszFile, cchMaxPath, pfd, fFlags, debugstr_a(This->sPath));
1095
1096         if (This->sPath)
1097           lstrcpynA(pszFile,This->sPath, cchMaxPath);
1098         else
1099           return E_FAIL;
1100
1101         return NOERROR;
1102 }
1103 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1104 {
1105         ICOM_THIS(IShellLinkImpl, iface);
1106
1107         TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1108
1109         *ppidl = ILClone(This->pPidl);
1110         return NOERROR;
1111 }
1112 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1113 {
1114         ICOM_THIS(IShellLinkImpl, iface);
1115
1116         TRACE("(%p)->(pidl=%p)\n",This, pidl);
1117
1118         if (This->pPidl)
1119             SHFree(This->pPidl);
1120         This->pPidl = ILClone (pidl);
1121         return NOERROR;
1122 }
1123 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1124 {
1125         ICOM_THIS(IShellLinkImpl, iface);
1126
1127         FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1128         lstrcpynA(pszName,"Description, FIXME",cchMaxName);
1129         return NOERROR;
1130 }
1131 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1132 {
1133         ICOM_THIS(IShellLinkImpl, iface);
1134
1135         TRACE("(%p)->(pName=%s)\n", This, pszName);
1136
1137         if (This->sDescription)
1138             HeapFree(GetProcessHeap(), 0, This->sDescription);
1139         if (!(This->sDescription = heap_strdup(pszName)))
1140             return E_OUTOFMEMORY;
1141
1142         return NOERROR;
1143 }
1144 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1145 {
1146         ICOM_THIS(IShellLinkImpl, iface);
1147
1148         TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1149
1150         lstrcpynA( pszDir, This->sWorkDir ? This->sWorkDir : "", cchMaxPath );
1151
1152         return NOERROR;
1153 }
1154 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1155 {
1156         ICOM_THIS(IShellLinkImpl, iface);
1157
1158         TRACE("(%p)->(dir=%s)\n",This, pszDir);
1159
1160         if (This->sWorkDir)
1161             HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1162         if (!(This->sWorkDir = heap_strdup(pszDir)))
1163             return E_OUTOFMEMORY;
1164
1165         return NOERROR;
1166 }
1167 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1168 {
1169         ICOM_THIS(IShellLinkImpl, iface);
1170
1171         TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1172
1173         lstrcpynA( pszArgs, This->sArgs ? This->sArgs : "", cchMaxPath );
1174
1175         return NOERROR;
1176 }
1177 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1178 {
1179         ICOM_THIS(IShellLinkImpl, iface);
1180
1181         TRACE("(%p)->(args=%s)\n",This, pszArgs);
1182
1183         if (This->sArgs)
1184             HeapFree(GetProcessHeap(), 0, This->sArgs);
1185         if (!(This->sArgs = heap_strdup(pszArgs)))
1186             return E_OUTOFMEMORY;
1187
1188         return NOERROR;
1189 }
1190 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1191 {
1192         ICOM_THIS(IShellLinkImpl, iface);
1193
1194         TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1195
1196         *pwHotkey = This->wHotKey;
1197
1198         return NOERROR;
1199 }
1200 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1201 {
1202         ICOM_THIS(IShellLinkImpl, iface);
1203
1204         TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1205
1206         This->wHotKey = wHotkey;
1207
1208         return NOERROR;
1209 }
1210 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1211 {
1212         ICOM_THIS(IShellLinkImpl, iface);
1213
1214         FIXME("(%p)->(%p)\n",This, piShowCmd);
1215         *piShowCmd=0;
1216         return NOERROR;
1217 }
1218 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1219 {
1220         ICOM_THIS(IShellLinkImpl, iface);
1221
1222         FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1223         return NOERROR;
1224 }
1225 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1226 {
1227         ICOM_THIS(IShellLinkImpl, iface);
1228
1229         TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1230
1231         lstrcpynA( pszIconPath, This->sIcoPath ? This->sIcoPath : "", cchIconPath );
1232         *piIcon = This->iIcoNdx;
1233
1234         return NOERROR;
1235 }
1236 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1237 {
1238         ICOM_THIS(IShellLinkImpl, iface);
1239
1240         TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1241
1242         if (This->sIcoPath)
1243             HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1244         if (!(This->sIcoPath = heap_strdup(pszIconPath)))
1245             return E_OUTOFMEMORY;
1246         This->iIcoNdx = iIcon;
1247
1248         return NOERROR;
1249 }
1250 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1251 {
1252         ICOM_THIS(IShellLinkImpl, iface);
1253
1254         FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1255         return NOERROR;
1256 }
1257 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1258 {
1259         ICOM_THIS(IShellLinkImpl, iface);
1260
1261         FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1262         return NOERROR;
1263 }
1264 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1265 {
1266         ICOM_THIS(IShellLinkImpl, iface);
1267
1268         TRACE("(%p)->(path=%s)\n",This, pszFile);
1269
1270         if (This->sPath)
1271             HeapFree(GetProcessHeap(), 0, This->sPath);
1272         if (!(This->sPath = heap_strdup(pszFile)))
1273             return E_OUTOFMEMORY;
1274
1275         return NOERROR;
1276 }
1277
1278 /**************************************************************************
1279 * IShellLink Implementation
1280 */
1281
1282 static ICOM_VTABLE(IShellLinkA) slvt =
1283 {
1284         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1285         IShellLinkA_fnQueryInterface,
1286         IShellLinkA_fnAddRef,
1287         IShellLinkA_fnRelease,
1288         IShellLinkA_fnGetPath,
1289         IShellLinkA_fnGetIDList,
1290         IShellLinkA_fnSetIDList,
1291         IShellLinkA_fnGetDescription,
1292         IShellLinkA_fnSetDescription,
1293         IShellLinkA_fnGetWorkingDirectory,
1294         IShellLinkA_fnSetWorkingDirectory,
1295         IShellLinkA_fnGetArguments,
1296         IShellLinkA_fnSetArguments,
1297         IShellLinkA_fnGetHotkey,
1298         IShellLinkA_fnSetHotkey,
1299         IShellLinkA_fnGetShowCmd,
1300         IShellLinkA_fnSetShowCmd,
1301         IShellLinkA_fnGetIconLocation,
1302         IShellLinkA_fnSetIconLocation,
1303         IShellLinkA_fnSetRelativePath,
1304         IShellLinkA_fnResolve,
1305         IShellLinkA_fnSetPath
1306 };
1307
1308
1309 /**************************************************************************
1310  *  IShellLinkW_fnQueryInterface
1311  */
1312 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1313   IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1314 {
1315         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1316
1317         return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1318 }
1319
1320 /******************************************************************************
1321  * IShellLinkW_fnAddRef
1322  */
1323 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1324 {
1325         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1326
1327         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1328
1329         return IShellLinkA_AddRef((IShellLinkA*)This);
1330 }
1331 /******************************************************************************
1332  * IShellLinkW_fnRelease
1333  */
1334
1335 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1336 {
1337         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1338
1339         TRACE("(%p)->(count=%lu)\n",This,This->ref);
1340
1341         return IShellLinkA_Release((IShellLinkA*)This);
1342 }
1343
1344 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1345 {
1346         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1347
1348         FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1349         MultiByteToWideChar( CP_ACP, 0, "c:\\foo.bar", -1, pszFile, cchMaxPath );
1350         return NOERROR;
1351 }
1352
1353 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1354 {
1355         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1356
1357         FIXME("(%p)->(ppidl=%p)\n",This, ppidl);
1358         *ppidl = _ILCreateDesktop();
1359         return NOERROR;
1360 }
1361
1362 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1363 {
1364         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1365
1366         FIXME("(%p)->(pidl=%p)\n",This, pidl);
1367         return NOERROR;
1368 }
1369
1370 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1371 {
1372         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1373
1374         FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1375         MultiByteToWideChar( CP_ACP, 0, "Description, FIXME", -1, pszName, cchMaxName );
1376         return NOERROR;
1377 }
1378
1379 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1380 {
1381         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1382
1383         TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1384
1385         if (This->sDescription)
1386             HeapFree(GetProcessHeap(), 0, This->sDescription);
1387         if (!(This->sDescription = HEAP_strdupWtoA(GetProcessHeap(), 0, pszName)))
1388             return E_OUTOFMEMORY;
1389
1390         return NOERROR;
1391 }
1392
1393 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1394 {
1395         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1396
1397         TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1398
1399         MultiByteToWideChar( CP_ACP, 0, This->sWorkDir ? This->sWorkDir : "", -1, pszDir, cchMaxPath );
1400
1401         return NOERROR;
1402 }
1403
1404 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1405 {
1406         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1407
1408         TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1409
1410         if (This->sWorkDir)
1411             HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1412         if (!(This->sWorkDir = HEAP_strdupWtoA(GetProcessHeap(), 0, pszDir)))
1413             return E_OUTOFMEMORY;
1414
1415         return NOERROR;
1416 }
1417
1418 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1419 {
1420         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1421
1422         TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1423
1424         MultiByteToWideChar( CP_ACP, 0, This->sArgs ? This->sArgs : "", -1, pszArgs, cchMaxPath );
1425
1426         return NOERROR;
1427 }
1428
1429 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1430 {
1431         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1432
1433         TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1434
1435         if (This->sArgs)
1436             HeapFree(GetProcessHeap(), 0, This->sArgs);
1437         if (!(This->sArgs = HEAP_strdupWtoA(GetProcessHeap(), 0, pszArgs)))
1438             return E_OUTOFMEMORY;
1439
1440         return NOERROR;
1441 }
1442
1443 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1444 {
1445         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1446
1447         FIXME("(%p)->(%p)\n",This, pwHotkey);
1448         *pwHotkey=0x0;
1449         return NOERROR;
1450 }
1451
1452 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1453 {
1454         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1455
1456         FIXME("(%p)->(hotkey=%x)\n",This, wHotkey);
1457         return NOERROR;
1458 }
1459
1460 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1461 {
1462         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1463
1464         FIXME("(%p)->(%p)\n",This, piShowCmd);
1465         *piShowCmd=0;
1466         return NOERROR;
1467 }
1468
1469 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1470 {
1471         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1472
1473         FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1474         return NOERROR;
1475 }
1476
1477 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1478 {
1479         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1480
1481         TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1482
1483         MultiByteToWideChar( CP_ACP, 0, This->sIcoPath ? This->sIcoPath : "", -1, pszIconPath, cchIconPath );
1484         *piIcon = This->iIcoNdx;
1485
1486         return NOERROR;
1487 }
1488
1489 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1490 {
1491         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1492
1493         TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1494
1495         if (This->sIcoPath)
1496             HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1497         if (!(This->sIcoPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszIconPath)))
1498             return E_OUTOFMEMORY;
1499         This->iIcoNdx = iIcon;
1500
1501         return NOERROR;
1502 }
1503
1504 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1505 {
1506         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1507
1508         FIXME("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1509         return NOERROR;
1510 }
1511
1512 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1513 {
1514         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1515
1516         FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1517         return NOERROR;
1518 }
1519
1520 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1521 {
1522         _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1523
1524         TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1525
1526         if (This->sPath)
1527             HeapFree(GetProcessHeap(), 0, This->sPath);
1528         if (!(This->sPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszFile)))
1529             return E_OUTOFMEMORY;
1530
1531         return NOERROR;
1532 }
1533
1534 /**************************************************************************
1535 * IShellLinkW Implementation
1536 */
1537
1538 static ICOM_VTABLE(IShellLinkW) slvtw =
1539 {
1540         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1541         IShellLinkW_fnQueryInterface,
1542         IShellLinkW_fnAddRef,
1543         IShellLinkW_fnRelease,
1544         IShellLinkW_fnGetPath,
1545         IShellLinkW_fnGetIDList,
1546         IShellLinkW_fnSetIDList,
1547         IShellLinkW_fnGetDescription,
1548         IShellLinkW_fnSetDescription,
1549         IShellLinkW_fnGetWorkingDirectory,
1550         IShellLinkW_fnSetWorkingDirectory,
1551         IShellLinkW_fnGetArguments,
1552         IShellLinkW_fnSetArguments,
1553         IShellLinkW_fnGetHotkey,
1554         IShellLinkW_fnSetHotkey,
1555         IShellLinkW_fnGetShowCmd,
1556         IShellLinkW_fnSetShowCmd,
1557         IShellLinkW_fnGetIconLocation,
1558         IShellLinkW_fnSetIconLocation,
1559         IShellLinkW_fnSetRelativePath,
1560         IShellLinkW_fnResolve,
1561         IShellLinkW_fnSetPath
1562 };