Avoid crashing when releasing an NdrCStdStubBuffer that had been
[wine/dcerpc.git] / dlls / shell32 / shelllink.c
blob64d585114b236446ca2171b16b24d6c91889deeb
1 /*
3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include <string.h>
24 #include <stdio.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include <errno.h>
29 #ifdef HAVE_SYS_WAIT_H
30 # include <sys/wait.h>
31 #endif
32 #include "wine/debug.h"
33 #include "wine/port.h"
34 #include "winerror.h"
35 #include "winbase.h"
36 #include "winnls.h"
37 #include "winreg.h"
39 #include "shlobj.h"
40 #include "undocshell.h"
41 #include "bitmaps/wine.xpm"
43 #include "heap.h"
44 #include "pidl.h"
45 #include "shell32_main.h"
46 #include "shlguid.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 /* link file formats */
52 #include "pshpack1.h"
54 /* flag1: lnk elements: simple link has 0x0B */
55 #define WORKDIR 0x10
56 #define ARGUMENT 0x20
57 #define ICON 0x40
58 #define UNC 0x80
60 /* fStartup */
61 #define NORMAL 0x01
62 #define MAXIMIZED 0x03
63 #define MINIMIZED 0x07
65 typedef struct _LINK_HEADER
66 { DWORD MagicStr; /* 0x00 'L','\0','\0','\0' */
67 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
68 DWORD Flag1; /* 0x14 describes elements following */
69 DWORD Flag2; /* 0x18 */
70 FILETIME Time1; /* 0x1c */
71 FILETIME Time2; /* 0x24 */
72 FILETIME Time3; /* 0x2c */
73 DWORD Unknown1; /* 0x34 */
74 DWORD Unknown2; /* 0x38 icon number */
75 DWORD fStartup; /* 0x3c startup type */
76 DWORD wHotKey; /* 0x40 hotkey */
77 DWORD Unknown5; /* 0x44 */
78 DWORD Unknown6; /* 0x48 */
79 USHORT PidlSize; /* 0x4c */
80 ITEMIDLIST Pidl; /* 0x4e */
81 } LINK_HEADER, * PLINK_HEADER;
83 #define LINK_HEADER_SIZE (sizeof(LINK_HEADER)-sizeof(ITEMIDLIST))
85 typedef struct
87 BYTE bWidth;
88 BYTE bHeight;
89 BYTE bColorCount;
90 BYTE bReserved;
91 WORD wPlanes;
92 WORD wBitCount;
93 DWORD dwBytesInRes;
94 WORD nID;
95 } GRPICONDIRENTRY;
97 typedef struct
99 WORD idReserved;
100 WORD idType;
101 WORD idCount;
102 GRPICONDIRENTRY idEntries[1];
103 } GRPICONDIR;
105 typedef struct
107 BYTE bWidth;
108 BYTE bHeight;
109 BYTE bColorCount;
110 BYTE bReserved;
111 WORD wPlanes;
112 WORD wBitCount;
113 DWORD dwBytesInRes;
114 DWORD dwImageOffset;
115 } ICONDIRENTRY;
117 typedef struct
119 WORD idReserved;
120 WORD idType;
121 WORD idCount;
122 } ICONDIR;
125 #include "poppack.h"
127 typedef struct
129 HRSRC *pResInfo;
130 int nIndex;
131 } ENUMRESSTRUCT;
133 static ICOM_VTABLE(IShellLinkA) slvt;
134 static ICOM_VTABLE(IShellLinkW) slvtw;
135 static ICOM_VTABLE(IPersistFile) pfvt;
136 static ICOM_VTABLE(IPersistStream) psvt;
138 /* IShellLink Implementation */
140 typedef struct
142 ICOM_VFIELD(IShellLinkA);
143 DWORD ref;
145 ICOM_VTABLE(IShellLinkW)* lpvtblw;
146 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
147 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
149 /* internal stream of the IPersistFile interface */
150 IStream* lpFileStream;
152 /* data structures according to the informations in the lnk */
153 LPSTR sPath;
154 LPITEMIDLIST pPidl;
155 WORD wHotKey;
156 SYSTEMTIME time1;
157 SYSTEMTIME time2;
158 SYSTEMTIME time3;
160 LPSTR sIcoPath;
161 INT iIcoNdx;
162 LPSTR sArgs;
163 LPSTR sWorkDir;
164 LPSTR sDescription;
165 } IShellLinkImpl;
167 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
168 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset);
170 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
171 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
173 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
174 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset);
175 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset);
178 /* strdup on the process heap */
179 inline static LPSTR heap_strdup( LPCSTR str )
181 INT len = strlen(str) + 1;
182 LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
183 if (p) memcpy( p, str, len );
184 return p;
188 /**************************************************************************
189 * IPersistFile_QueryInterface
191 static HRESULT WINAPI IPersistFile_fnQueryInterface(
192 IPersistFile* iface,
193 REFIID riid,
194 LPVOID *ppvObj)
196 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
198 TRACE("(%p)\n",This);
200 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
203 /******************************************************************************
204 * IPersistFile_AddRef
206 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
208 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
210 TRACE("(%p)->(count=%lu)\n",This,This->ref);
212 return IShellLinkA_AddRef((IShellLinkA*)This);
214 /******************************************************************************
215 * IPersistFile_Release
217 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
219 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
221 TRACE("(%p)->(count=%lu)\n",This,This->ref);
223 return IShellLinkA_Release((IShellLinkA*)This);
226 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
228 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
229 FIXME("(%p)\n",This);
230 return NOERROR;
232 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
234 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
235 FIXME("(%p)\n",This);
236 return NOERROR;
238 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
240 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
241 _IPersistStream_From_ICOM_THIS(IPersistStream, This)
243 LPSTR sFile = HEAP_strdupWtoA ( GetProcessHeap(), 0, pszFileName);
244 HRESULT hRet = E_FAIL;
246 TRACE("(%p, %s)\n",This, sFile);
249 if (This->lpFileStream)
250 IStream_Release(This->lpFileStream);
252 if SUCCEEDED(CreateStreamOnFile(sFile, &(This->lpFileStream)))
254 if SUCCEEDED (IPersistStream_Load(StreamThis, This->lpFileStream))
256 return NOERROR;
260 return hRet;
264 /* Icon extraction routines
266 * FIXME: should use PrivateExtractIcons and friends
267 * FIXME: should not use stdio
270 static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName)
272 FILE *fXPMFile;
273 int nHeight;
274 int nXORWidthBytes;
275 int nANDWidthBytes;
276 BOOL b8BitColors;
277 int nColors;
278 BYTE *pXOR;
279 BYTE *pAND;
280 BOOL aColorUsed[256] = {0};
281 int nColorsUsed = 0;
282 int i,j;
284 if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8)))
285 return 0;
287 if (!(fXPMFile = fopen(szXPMFileName, "w")))
288 return 0;
290 nHeight = pIcon->bmiHeader.biHeight / 2;
291 nXORWidthBytes = 4 * ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount / 32)
292 + ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount % 32) > 0));
293 nANDWidthBytes = 4 * ((pIcon->bmiHeader.biWidth / 32)
294 + ((pIcon->bmiHeader.biWidth % 32) > 0));
295 b8BitColors = pIcon->bmiHeader.biBitCount == 8;
296 nColors = pIcon->bmiHeader.biClrUsed ? pIcon->bmiHeader.biClrUsed
297 : 1 << pIcon->bmiHeader.biBitCount;
298 pXOR = (BYTE*) pIcon + sizeof (BITMAPINFOHEADER) + (nColors * sizeof (RGBQUAD));
299 pAND = pXOR + nHeight * nXORWidthBytes;
301 #define MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
302 #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)
304 for (i = 0; i < nHeight; i++)
305 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
306 if (!aColorUsed[COLOR(j,i)] && !MASK(j,i))
308 aColorUsed[COLOR(j,i)] = TRUE;
309 nColorsUsed++;
312 if (fprintf(fXPMFile, "/* XPM */\nstatic char *icon[] = {\n") <= 0)
313 goto error;
314 if (fprintf(fXPMFile, "\"%d %d %d %d\",\n",
315 (int) pIcon->bmiHeader.biWidth, nHeight, nColorsUsed + 1, 2) <=0)
316 goto error;
318 for (i = 0; i < nColors; i++)
319 if (aColorUsed[i])
320 if (fprintf(fXPMFile, "\"%.2X c #%.2X%.2X%.2X\",\n", i, pIcon->bmiColors[i].rgbRed,
321 pIcon->bmiColors[i].rgbGreen, pIcon->bmiColors[i].rgbBlue) <= 0)
322 goto error;
323 if (fprintf(fXPMFile, "\" c None\"") <= 0)
324 goto error;
326 for (i = 0; i < nHeight; i++)
328 if (fprintf(fXPMFile, ",\n\"") <= 0)
329 goto error;
330 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
332 if MASK(j,i)
334 if (fprintf(fXPMFile, " ") <= 0)
335 goto error;
337 else
338 if (fprintf(fXPMFile, "%.2X", COLOR(j,i)) <= 0)
339 goto error;
341 if (fprintf(fXPMFile, "\"") <= 0)
342 goto error;
344 if (fprintf(fXPMFile, "};\n") <= 0)
345 goto error;
347 #undef MASK
348 #undef COLOR
350 fclose(fXPMFile);
351 return 1;
353 error:
354 fclose(fXPMFile);
355 unlink( szXPMFileName );
356 return 0;
359 static BOOL CALLBACK EnumResNameProc(HANDLE hModule, const char *lpszType, char *lpszName, LONG lParam)
361 ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam;
363 if (!sEnumRes->nIndex--)
365 *sEnumRes->pResInfo = FindResourceA(hModule, lpszName, RT_GROUP_ICONA);
366 return FALSE;
368 else
369 return TRUE;
372 static int ExtractFromEXEDLL(const char *szFileName, int nIndex, const char *szXPMFileName)
374 HMODULE hModule;
375 HRSRC hResInfo;
376 char *lpName = NULL;
377 HGLOBAL hResData;
378 GRPICONDIR *pIconDir;
379 BITMAPINFO *pIcon;
380 ENUMRESSTRUCT sEnumRes;
381 int nMax = 0;
382 int nMaxBits = 0;
383 int i;
385 if (!(hModule = LoadLibraryExA(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE)))
387 TRACE("LoadLibraryExA (%s) failed, error %ld\n", szFileName, GetLastError());
388 goto error1;
391 if (nIndex < 0)
393 hResInfo = FindResourceA(hModule, MAKEINTRESOURCEA(-nIndex), RT_GROUP_ICONA);
394 TRACE("FindResourceA (%s) called, return 0x%x, error %ld\n", szFileName, hResInfo, GetLastError());
396 else
398 sEnumRes.pResInfo = &hResInfo;
399 sEnumRes.nIndex = nIndex;
400 if (EnumResourceNamesA(hModule, RT_GROUP_ICONA, &EnumResNameProc, (LONG) &sEnumRes))
402 TRACE("EnumResourceNamesA failed, error %ld\n", GetLastError());
403 goto error2;
407 if (!hResInfo)
409 TRACE("ExtractFromEXEDLL failed, error %ld\n", GetLastError());
410 goto error2;
413 if (!(hResData = LoadResource(hModule, hResInfo)))
415 TRACE("LoadResource failed, error %ld\n", GetLastError());
416 goto error2;
418 if (!(pIconDir = LockResource(hResData)))
420 TRACE("LockResource failed, error %ld\n", GetLastError());
421 goto error3;
424 for (i = 0; i < pIconDir->idCount; i++)
425 if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8))
427 if (pIconDir->idEntries[i].wBitCount > nMaxBits)
429 nMaxBits = pIconDir->idEntries[i].wBitCount;
430 nMax = 0;
432 if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax)
434 lpName = MAKEINTRESOURCEA(pIconDir->idEntries[i].nID);
435 nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
439 FreeResource(hResData);
441 if (!(hResInfo = FindResourceA(hModule, lpName, RT_ICONA)))
443 TRACE("Second FindResourceA failed, error %ld\n", GetLastError());
444 goto error2;
446 if (!(hResData = LoadResource(hModule, hResInfo)))
448 TRACE("Second LoadResource failed, error %ld\n", GetLastError());
449 goto error2;
451 if (!(pIcon = LockResource(hResData)))
453 TRACE("Second LockResource failed, error %ld\n", GetLastError());
454 goto error3;
457 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
459 TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
460 goto error3;
463 FreeResource(hResData);
464 FreeLibrary(hModule);
466 return 1;
468 error3:
469 FreeResource(hResData);
470 error2:
471 FreeLibrary(hModule);
472 error1:
473 return 0;
476 /* get the Unix file name for a given path, allocating the string */
477 inline static char *get_unix_file_name( const char *dos )
479 char buffer[MAX_PATH];
481 if (!wine_get_unix_file_name( dos, buffer, sizeof(buffer) )) return NULL;
482 return heap_strdup( buffer );
485 static int ExtractFromICO(const char *szFileName, const char *szXPMFileName)
487 FILE *fICOFile;
488 ICONDIR iconDir;
489 ICONDIRENTRY *pIconDirEntry;
490 int nMax = 0;
491 int nIndex = 0;
492 void *pIcon;
493 int i;
494 char *filename;
496 filename = get_unix_file_name(szFileName);
497 if (!(fICOFile = fopen(filename, "r")))
498 goto error1;
500 if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
501 goto error2;
502 if ((iconDir.idReserved != 0) || (iconDir.idType != 1))
503 goto error2;
505 if ((pIconDirEntry = malloc(iconDir.idCount * sizeof (ICONDIRENTRY))) == NULL)
506 goto error2;
507 if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
508 goto error3;
510 for (i = 0; i < iconDir.idCount; i++)
511 if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
513 nIndex = i;
514 nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
516 if ((pIcon = malloc(pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
517 goto error3;
518 if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
519 goto error4;
520 if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
521 goto error4;
523 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
524 goto error4;
526 free(pIcon);
527 free(pIconDirEntry);
528 fclose(fICOFile);
530 return 1;
532 error4:
533 free(pIcon);
534 error3:
535 free(pIconDirEntry);
536 error2:
537 fclose(fICOFile);
538 error1:
539 HeapFree(GetProcessHeap(), 0, filename);
540 return 0;
543 static BOOL create_default_icon( const char *filename )
545 FILE *fXPM;
546 int i;
548 if (!(fXPM = fopen(filename, "w"))) return FALSE;
549 fprintf(fXPM, "/* XPM */\nstatic char * icon[] = {");
550 for (i = 0; i < sizeof(wine_xpm)/sizeof(wine_xpm[0]); i++)
551 fprintf( fXPM, "\n\"%s\",", wine_xpm[i]);
552 fprintf( fXPM, "};\n" );
553 fclose( fXPM );
554 return TRUE;
557 /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
558 static char *extract_icon( const char *path, int index)
560 int fd, nodefault = 1;
561 char *filename, tmpfn[25];
563 strcpy(tmpfn,"/tmp/icon.XXXXXX");
564 fd = mkstemp( tmpfn );
565 if (fd == -1)
566 return NULL;
567 filename = heap_strdup( tmpfn );
568 close(fd); /* not needed */
570 /* If icon path begins with a '*' then this is a deferred call */
571 if (path[0] == '*')
573 path++;
574 nodefault = 0;
576 if (ExtractFromEXEDLL( path, index, filename )) return filename;
577 if (ExtractFromICO( path, filename )) return filename;
578 if (!nodefault)
579 if (create_default_icon( filename )) return filename;
580 HeapFree( GetProcessHeap(), 0, filename );
581 return NULL;
584 /* This escapes \ in filenames */
585 static LPSTR
586 escape(LPCSTR arg) {
587 LPSTR narg, x;
589 narg = HeapAlloc(GetProcessHeap(),0,2*strlen(arg)+2);
590 x = narg;
591 while (*arg) {
592 *x++ = *arg;
593 if (*arg == '\\')
594 *x++='\\'; /* escape \ */
595 arg++;
597 *x = 0;
598 return narg;
601 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
603 HRESULT ret = NOERROR;
604 int pid, status;
605 char buffer[MAX_PATH], buff2[MAX_PATH], ascii_filename[MAX_PATH];
606 char *filename, *link_name, *p;
607 char *shell_link_app = NULL;
608 char *icon_name = NULL;
609 char *work_dir = NULL;
610 char *escaped_path = NULL;
611 char *escaped_args = NULL;
612 BOOL bDesktop;
613 HKEY hkey;
615 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
617 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
619 if (!pszFileName || !This->sPath)
620 return ERROR_UNKNOWN;
622 /* check for .exe extension */
623 if (!(p = strrchr( This->sPath, '.' ))) return NOERROR;
624 if (strchr( p, '\\' ) || strchr( p, '/' )) return NOERROR;
625 if (strcasecmp( p, ".exe" )) return NOERROR;
627 /* check if ShellLinker configured */
628 buffer[0] = 0;
629 if (!RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine",
630 0, KEY_ALL_ACCESS, &hkey ))
632 DWORD type, count = sizeof(buffer);
633 if (RegQueryValueExA( hkey, "ShellLinker", 0, &type, buffer, &count )) buffer[0] = 0;
634 RegCloseKey( hkey );
636 if (!*buffer) return NOERROR;
637 shell_link_app = heap_strdup( buffer );
639 if (!WideCharToMultiByte( CP_ACP, 0, pszFileName, -1, ascii_filename, sizeof(ascii_filename), NULL, NULL))
640 return ERROR_UNKNOWN;
641 GetFullPathNameA( ascii_filename, sizeof(buff2), buff2, NULL );
642 filename = heap_strdup( buff2 );
644 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTUP, FALSE ))
646 /* ignore startup for now */
647 if (!strncasecmp( filename, buffer, strlen(buffer) )) goto done;
649 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_DESKTOPDIRECTORY, FALSE ))
651 if (!strncasecmp( filename, buffer, strlen(buffer) ))
653 link_name = filename + strlen(buffer);
654 bDesktop = TRUE;
655 goto found;
658 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTMENU, FALSE ))
660 if (!strncasecmp( filename, buffer, strlen(buffer) ))
662 link_name = filename + strlen(buffer);
663 bDesktop = FALSE;
664 goto found;
667 goto done;
669 found:
670 /* make link name a Unix name */
671 for (p = link_name; *p; p++) if (*p == '\\') *p = '/';
672 /* strip leading slashes */
673 while (*link_name == '/') link_name++;
674 /* remove extension */
675 if ((p = strrchr( link_name, '.' ))) *p = 0;
677 /* convert app working dir */
678 if (This->sWorkDir) work_dir = get_unix_file_name( This->sWorkDir );
680 /* extract the icon */
681 if (!(icon_name = extract_icon( This->sIcoPath && strlen(This->sIcoPath) ?
682 This->sIcoPath : This->sPath,
683 This->iIcoNdx )))
685 /* Couldn't extract icon -- defer this menu entry to runonce. */
686 HKEY hRunOnce;
687 char* buffer = NULL;
689 TRACE("Deferring icon creation to reboot.\n");
690 if (RegCreateKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce", 0,
691 NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hRunOnce, NULL) != ERROR_SUCCESS)
693 ret = ERROR_UNKNOWN;
694 goto done;
696 buffer = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * 3 + (This->sArgs ? strlen(This->sArgs) : 0) +
697 (This->sDescription ? strlen(This->sDescription) : 0) + 200);
698 sprintf(buffer, "link:%s\xff*%s\xff%d\xff%s\xff%s\xff%s", This->sPath, This->sIcoPath, This->iIcoNdx,
699 This->sArgs ? This->sArgs : "", This->sDescription ? This->sDescription : "",
700 This->sWorkDir ? This->sWorkDir : "");
701 if (RegSetValueExA(hRunOnce, ascii_filename, 0, REG_SZ, buffer, strlen(buffer) + 1) != ERROR_SUCCESS)
703 HeapFree(GetProcessHeap(), 0, buffer);
704 RegCloseKey(hRunOnce);
705 ret = ERROR_UNKNOWN;
706 goto done;
708 HeapFree(GetProcessHeap(), 0, buffer);
709 RegCloseKey(hRunOnce);
710 goto done;
713 TRACE("linker app='%s' link='%s' mode=%s path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
714 shell_link_app, link_name, bDesktop ? "desktop" : "menu", This->sPath,
715 This->sArgs ? This->sArgs : "", icon_name, work_dir ? work_dir : "",
716 This->sDescription ? This->sDescription : "" );
718 if ((pid = fork()) == -1) goto done;
720 escaped_path = escape(This->sPath);
721 if (This->sArgs)
722 escaped_args = escape(This->sArgs);
724 if (!pid)
726 int pos = 0;
727 char *argv[20];
728 argv[pos++] = shell_link_app;
729 argv[pos++] = "--link";
730 argv[pos++] = link_name;
731 argv[pos++] = "--path";
732 argv[pos++] = escaped_path;
733 argv[pos++] = bDesktop ? "--desktop" : "--menu";
734 if (This->sArgs && strlen(This->sArgs))
736 argv[pos++] = "--args";
737 argv[pos++] = escaped_args;
739 if (icon_name)
741 argv[pos++] = "--icon";
742 argv[pos++] = icon_name;
744 if (This->sWorkDir && strlen(This->sWorkDir))
746 argv[pos++] = "--workdir";
747 argv[pos++] = work_dir;
749 if (This->sDescription && strlen(This->sDescription))
751 argv[pos++] = "--descr";
752 argv[pos++] = This->sDescription;
754 argv[pos] = NULL;
755 execvp( shell_link_app, argv );
756 _exit(1);
759 while (waitpid( pid, &status, 0 ) == -1)
761 if (errno != EINTR)
763 ret = ERROR_UNKNOWN;
764 goto done;
767 if (status) ret = E_ACCESSDENIED;
769 done:
770 if (icon_name) unlink( icon_name );
771 HeapFree( GetProcessHeap(), 0, shell_link_app );
772 HeapFree( GetProcessHeap(), 0, filename );
773 HeapFree( GetProcessHeap(), 0, icon_name );
774 HeapFree( GetProcessHeap(), 0, work_dir );
775 if (escaped_args) HeapFree( GetProcessHeap(), 0, escaped_args );
776 if (escaped_path) HeapFree( GetProcessHeap(), 0, escaped_path );
777 return ret;
780 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
782 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
783 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
784 return NOERROR;
786 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
788 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
789 FIXME("(%p)\n",This);
790 return NOERROR;
793 static ICOM_VTABLE(IPersistFile) pfvt =
795 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
796 IPersistFile_fnQueryInterface,
797 IPersistFile_fnAddRef,
798 IPersistFile_fnRelease,
799 IPersistFile_fnGetClassID,
800 IPersistFile_fnIsDirty,
801 IPersistFile_fnLoad,
802 IPersistFile_fnSave,
803 IPersistFile_fnSaveCompleted,
804 IPersistFile_fnGetCurFile
807 /************************************************************************
808 * IPersistStream_QueryInterface
810 static HRESULT WINAPI IPersistStream_fnQueryInterface(
811 IPersistStream* iface,
812 REFIID riid,
813 VOID** ppvoid)
815 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
817 TRACE("(%p)\n",This);
819 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
822 /************************************************************************
823 * IPersistStream_Release
825 static ULONG WINAPI IPersistStream_fnRelease(
826 IPersistStream* iface)
828 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
830 TRACE("(%p)\n",This);
832 return IShellLinkA_Release((IShellLinkA*)This);
835 /************************************************************************
836 * IPersistStream_AddRef
838 static ULONG WINAPI IPersistStream_fnAddRef(
839 IPersistStream* iface)
841 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
843 TRACE("(%p)\n",This);
845 return IShellLinkA_AddRef((IShellLinkA*)This);
848 /************************************************************************
849 * IPersistStream_GetClassID
852 static HRESULT WINAPI IPersistStream_fnGetClassID(
853 IPersistStream* iface,
854 CLSID* pClassID)
856 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
858 TRACE("(%p)\n", This);
860 if (pClassID==0)
861 return E_POINTER;
863 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
865 return S_OK;
868 /************************************************************************
869 * IPersistStream_IsDirty (IPersistStream)
871 static HRESULT WINAPI IPersistStream_fnIsDirty(
872 IPersistStream* iface)
874 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
876 TRACE("(%p)\n", This);
878 return S_OK;
880 /************************************************************************
881 * IPersistStream_Load (IPersistStream)
884 static HRESULT WINAPI IPersistStream_fnLoad(
885 IPersistStream* iface,
886 IStream* pLoadStream)
888 PLINK_HEADER lpLinkHeader = HeapAlloc(GetProcessHeap(), 0, LINK_HEADER_SIZE);
889 ULONG dwBytesRead;
890 DWORD ret = E_FAIL;
891 char sTemp[MAX_PATH];
893 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
895 TRACE("(%p)(%p)\n", This, pLoadStream);
897 if ( ! pLoadStream)
899 return STG_E_INVALIDPOINTER;
902 IStream_AddRef (pLoadStream);
903 if(!lpLinkHeader)
904 goto end;
906 dwBytesRead = 0;
907 if (!(SUCCEEDED(IStream_Read(pLoadStream, lpLinkHeader, LINK_HEADER_SIZE, &dwBytesRead))))
908 goto end;
910 if (dwBytesRead != LINK_HEADER_SIZE)
911 goto end;
913 if ( (lpLinkHeader->MagicStr != 0x0000004CL) || !IsEqualIID(&lpLinkHeader->MagicGuid, &CLSID_ShellLink) )
914 goto end;
916 if(lpLinkHeader->PidlSize)
918 lpLinkHeader = HeapReAlloc(GetProcessHeap(), 0, lpLinkHeader, LINK_HEADER_SIZE+lpLinkHeader->PidlSize);
919 if (!lpLinkHeader)
920 goto end;
921 dwBytesRead = 0;
922 if (!(SUCCEEDED(IStream_Read(pLoadStream, &(lpLinkHeader->Pidl), lpLinkHeader->PidlSize, &dwBytesRead))))
923 goto end;
924 if(dwBytesRead != lpLinkHeader->PidlSize)
925 goto end;
927 if (pcheck (&lpLinkHeader->Pidl))
929 This->pPidl = ILClone (&lpLinkHeader->Pidl);
931 SHGetPathFromIDListA(&lpLinkHeader->Pidl, sTemp);
932 This->sPath = heap_strdup( sTemp );
935 This->wHotKey = lpLinkHeader->wHotKey;
936 FileTimeToSystemTime (&lpLinkHeader->Time1, &This->time1);
937 FileTimeToSystemTime (&lpLinkHeader->Time2, &This->time2);
938 FileTimeToSystemTime (&lpLinkHeader->Time3, &This->time3);
939 #if 1
940 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
941 TRACE("-- time1: %s\n", sTemp);
942 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
943 TRACE("-- time1: %s\n", sTemp);
944 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
945 TRACE("-- time1: %s\n", sTemp);
946 pdump (This->pPidl);
947 #endif
948 ret = S_OK;
950 end:
951 IStream_Release (pLoadStream);
953 pdump(This->pPidl);
955 HeapFree(GetProcessHeap(), 0, lpLinkHeader);
957 return ret;
960 /************************************************************************
961 * IPersistStream_Save (IPersistStream)
963 static HRESULT WINAPI IPersistStream_fnSave(
964 IPersistStream* iface,
965 IStream* pOutStream,
966 BOOL fClearDirty)
968 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
970 TRACE("(%p) %p %x\n", This, pOutStream, fClearDirty);
972 return E_NOTIMPL;
975 /************************************************************************
976 * IPersistStream_GetSizeMax (IPersistStream)
978 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
979 IPersistStream* iface,
980 ULARGE_INTEGER* pcbSize)
982 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
984 TRACE("(%p)\n", This);
986 return E_NOTIMPL;
989 static ICOM_VTABLE(IPersistStream) psvt =
991 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
992 IPersistStream_fnQueryInterface,
993 IPersistStream_fnAddRef,
994 IPersistStream_fnRelease,
995 IPersistStream_fnGetClassID,
996 IPersistStream_fnIsDirty,
997 IPersistStream_fnLoad,
998 IPersistStream_fnSave,
999 IPersistStream_fnGetSizeMax
1002 /**************************************************************************
1003 * IShellLink_Constructor
1005 HRESULT WINAPI IShellLink_Constructor (
1006 IUnknown * pUnkOuter,
1007 REFIID riid,
1008 LPVOID * ppv)
1010 IShellLinkImpl * sl;
1012 TRACE("unkOut=%p riid=%s\n",pUnkOuter, debugstr_guid(riid));
1014 *ppv = NULL;
1016 if(pUnkOuter) return CLASS_E_NOAGGREGATION;
1017 sl = (IShellLinkImpl *) LocalAlloc(GMEM_ZEROINIT,sizeof(IShellLinkImpl));
1018 if (!sl) return E_OUTOFMEMORY;
1020 sl->ref = 1;
1021 ICOM_VTBL(sl) = &slvt;
1022 sl->lpvtblw = &slvtw;
1023 sl->lpvtblPersistFile = &pfvt;
1024 sl->lpvtblPersistStream = &psvt;
1026 TRACE("(%p)->()\n",sl);
1028 if (IsEqualIID(riid, &IID_IUnknown) ||
1029 IsEqualIID(riid, &IID_IShellLinkA))
1030 *ppv = sl;
1031 else if (IsEqualIID(riid, &IID_IShellLinkW))
1032 *ppv = &(sl->lpvtblw);
1033 else {
1034 LocalFree((HLOCAL)sl);
1035 ERR("E_NOINTERFACE\n");
1036 return E_NOINTERFACE;
1039 return S_OK;
1042 /**************************************************************************
1043 * IShellLinkA_QueryInterface
1045 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
1047 ICOM_THIS(IShellLinkImpl, iface);
1049 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
1051 *ppvObj = NULL;
1053 if(IsEqualIID(riid, &IID_IUnknown) ||
1054 IsEqualIID(riid, &IID_IShellLinkA))
1056 *ppvObj = This;
1058 else if(IsEqualIID(riid, &IID_IShellLinkW))
1060 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
1062 else if(IsEqualIID(riid, &IID_IPersistFile))
1064 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
1066 else if(IsEqualIID(riid, &IID_IPersistStream))
1068 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
1071 if(*ppvObj)
1073 IUnknown_AddRef((IUnknown*)(*ppvObj));
1074 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
1075 return S_OK;
1077 TRACE("-- Interface: E_NOINTERFACE\n");
1078 return E_NOINTERFACE;
1080 /******************************************************************************
1081 * IShellLinkA_AddRef
1083 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
1085 ICOM_THIS(IShellLinkImpl, iface);
1087 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1089 return ++(This->ref);
1091 /******************************************************************************
1092 * IShellLinkA_Release
1094 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
1096 ICOM_THIS(IShellLinkImpl, iface);
1098 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1100 if (!--(This->ref))
1101 { TRACE("-- destroying IShellLink(%p)\n",This);
1103 if (This->sIcoPath)
1104 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1106 if (This->sArgs)
1107 HeapFree(GetProcessHeap(), 0, This->sArgs);
1109 if (This->sWorkDir)
1110 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1112 if (This->sDescription)
1113 HeapFree(GetProcessHeap(), 0, This->sDescription);
1115 if (This->sPath)
1116 HeapFree(GetProcessHeap(),0,This->sPath);
1118 if (This->pPidl)
1119 SHFree(This->pPidl);
1121 if (This->lpFileStream)
1122 IStream_Release(This->lpFileStream);
1124 This->iIcoNdx = 0;
1126 LocalFree((HANDLE)This);
1127 return 0;
1129 return This->ref;
1132 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1134 ICOM_THIS(IShellLinkImpl, iface);
1136 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",This, pszFile, cchMaxPath, pfd, fFlags, debugstr_a(This->sPath));
1138 if (This->sPath)
1139 lstrcpynA(pszFile,This->sPath, cchMaxPath);
1140 else
1141 return E_FAIL;
1143 return NOERROR;
1145 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1147 ICOM_THIS(IShellLinkImpl, iface);
1149 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1151 *ppidl = ILClone(This->pPidl);
1152 return NOERROR;
1154 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1156 ICOM_THIS(IShellLinkImpl, iface);
1158 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1160 if (This->pPidl)
1161 SHFree(This->pPidl);
1162 This->pPidl = ILClone (pidl);
1163 return NOERROR;
1165 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1167 ICOM_THIS(IShellLinkImpl, iface);
1169 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1170 lstrcpynA(pszName,"Description, FIXME",cchMaxName);
1171 return NOERROR;
1173 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1175 ICOM_THIS(IShellLinkImpl, iface);
1177 TRACE("(%p)->(pName=%s)\n", This, pszName);
1179 if (This->sDescription)
1180 HeapFree(GetProcessHeap(), 0, This->sDescription);
1181 if (!(This->sDescription = heap_strdup(pszName)))
1182 return E_OUTOFMEMORY;
1184 return NOERROR;
1186 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1188 ICOM_THIS(IShellLinkImpl, iface);
1190 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1192 lstrcpynA( pszDir, This->sWorkDir ? This->sWorkDir : "", cchMaxPath );
1194 return NOERROR;
1196 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1198 ICOM_THIS(IShellLinkImpl, iface);
1200 TRACE("(%p)->(dir=%s)\n",This, pszDir);
1202 if (This->sWorkDir)
1203 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1204 if (!(This->sWorkDir = heap_strdup(pszDir)))
1205 return E_OUTOFMEMORY;
1207 return NOERROR;
1209 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1211 ICOM_THIS(IShellLinkImpl, iface);
1213 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1215 lstrcpynA( pszArgs, This->sArgs ? This->sArgs : "", cchMaxPath );
1217 return NOERROR;
1219 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1221 ICOM_THIS(IShellLinkImpl, iface);
1223 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1225 if (This->sArgs)
1226 HeapFree(GetProcessHeap(), 0, This->sArgs);
1227 if (!(This->sArgs = heap_strdup(pszArgs)))
1228 return E_OUTOFMEMORY;
1230 return NOERROR;
1232 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1234 ICOM_THIS(IShellLinkImpl, iface);
1236 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1238 *pwHotkey = This->wHotKey;
1240 return NOERROR;
1242 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1244 ICOM_THIS(IShellLinkImpl, iface);
1246 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1248 This->wHotKey = wHotkey;
1250 return NOERROR;
1252 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1254 ICOM_THIS(IShellLinkImpl, iface);
1256 FIXME("(%p)->(%p)\n",This, piShowCmd);
1257 *piShowCmd=0;
1258 return NOERROR;
1260 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1262 ICOM_THIS(IShellLinkImpl, iface);
1264 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1265 return NOERROR;
1267 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1269 ICOM_THIS(IShellLinkImpl, iface);
1271 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1273 lstrcpynA( pszIconPath, This->sIcoPath ? This->sIcoPath : "", cchIconPath );
1274 *piIcon = This->iIcoNdx;
1276 return NOERROR;
1278 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1280 ICOM_THIS(IShellLinkImpl, iface);
1282 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1284 if (This->sIcoPath)
1285 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1286 if (!(This->sIcoPath = heap_strdup(pszIconPath)))
1287 return E_OUTOFMEMORY;
1288 This->iIcoNdx = iIcon;
1290 return NOERROR;
1292 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1294 ICOM_THIS(IShellLinkImpl, iface);
1296 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1297 return NOERROR;
1299 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1301 ICOM_THIS(IShellLinkImpl, iface);
1303 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1304 return NOERROR;
1306 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1308 ICOM_THIS(IShellLinkImpl, iface);
1310 TRACE("(%p)->(path=%s)\n",This, pszFile);
1312 if (This->sPath)
1313 HeapFree(GetProcessHeap(), 0, This->sPath);
1314 if (!(This->sPath = heap_strdup(pszFile)))
1315 return E_OUTOFMEMORY;
1317 return NOERROR;
1320 /**************************************************************************
1321 * IShellLink Implementation
1324 static ICOM_VTABLE(IShellLinkA) slvt =
1326 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1327 IShellLinkA_fnQueryInterface,
1328 IShellLinkA_fnAddRef,
1329 IShellLinkA_fnRelease,
1330 IShellLinkA_fnGetPath,
1331 IShellLinkA_fnGetIDList,
1332 IShellLinkA_fnSetIDList,
1333 IShellLinkA_fnGetDescription,
1334 IShellLinkA_fnSetDescription,
1335 IShellLinkA_fnGetWorkingDirectory,
1336 IShellLinkA_fnSetWorkingDirectory,
1337 IShellLinkA_fnGetArguments,
1338 IShellLinkA_fnSetArguments,
1339 IShellLinkA_fnGetHotkey,
1340 IShellLinkA_fnSetHotkey,
1341 IShellLinkA_fnGetShowCmd,
1342 IShellLinkA_fnSetShowCmd,
1343 IShellLinkA_fnGetIconLocation,
1344 IShellLinkA_fnSetIconLocation,
1345 IShellLinkA_fnSetRelativePath,
1346 IShellLinkA_fnResolve,
1347 IShellLinkA_fnSetPath
1351 /**************************************************************************
1352 * IShellLinkW_fnQueryInterface
1354 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1355 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1357 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1359 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1362 /******************************************************************************
1363 * IShellLinkW_fnAddRef
1365 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1367 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1369 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1371 return IShellLinkA_AddRef((IShellLinkA*)This);
1373 /******************************************************************************
1374 * IShellLinkW_fnRelease
1377 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1379 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1381 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1383 return IShellLinkA_Release((IShellLinkA*)This);
1386 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1388 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1390 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1391 MultiByteToWideChar( CP_ACP, 0, "c:\\foo.bar", -1, pszFile, cchMaxPath );
1392 return NOERROR;
1395 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1397 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1399 FIXME("(%p)->(ppidl=%p)\n",This, ppidl);
1400 *ppidl = _ILCreateDesktop();
1401 return NOERROR;
1404 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1406 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1408 FIXME("(%p)->(pidl=%p)\n",This, pidl);
1409 return NOERROR;
1412 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1414 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1416 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1417 MultiByteToWideChar( CP_ACP, 0, "Description, FIXME", -1, pszName, cchMaxName );
1418 return NOERROR;
1421 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1423 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1425 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1427 if (This->sDescription)
1428 HeapFree(GetProcessHeap(), 0, This->sDescription);
1429 if (!(This->sDescription = HEAP_strdupWtoA(GetProcessHeap(), 0, pszName)))
1430 return E_OUTOFMEMORY;
1432 return NOERROR;
1435 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1437 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1439 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1441 MultiByteToWideChar( CP_ACP, 0, This->sWorkDir ? This->sWorkDir : "", -1, pszDir, cchMaxPath );
1443 return NOERROR;
1446 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1448 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1450 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1452 if (This->sWorkDir)
1453 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1454 if (!(This->sWorkDir = HEAP_strdupWtoA(GetProcessHeap(), 0, pszDir)))
1455 return E_OUTOFMEMORY;
1457 return NOERROR;
1460 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1462 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1464 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1466 MultiByteToWideChar( CP_ACP, 0, This->sArgs ? This->sArgs : "", -1, pszArgs, cchMaxPath );
1468 return NOERROR;
1471 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1473 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1475 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1477 if (This->sArgs)
1478 HeapFree(GetProcessHeap(), 0, This->sArgs);
1479 if (!(This->sArgs = HEAP_strdupWtoA(GetProcessHeap(), 0, pszArgs)))
1480 return E_OUTOFMEMORY;
1482 return NOERROR;
1485 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1487 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1489 FIXME("(%p)->(%p)\n",This, pwHotkey);
1490 *pwHotkey=0x0;
1491 return NOERROR;
1494 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1496 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1498 FIXME("(%p)->(hotkey=%x)\n",This, wHotkey);
1499 return NOERROR;
1502 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1504 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1506 FIXME("(%p)->(%p)\n",This, piShowCmd);
1507 *piShowCmd=0;
1508 return NOERROR;
1511 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1513 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1515 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1516 return NOERROR;
1519 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1521 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1523 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1525 MultiByteToWideChar( CP_ACP, 0, This->sIcoPath ? This->sIcoPath : "", -1, pszIconPath, cchIconPath );
1526 *piIcon = This->iIcoNdx;
1528 return NOERROR;
1531 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1533 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1535 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1537 if (This->sIcoPath)
1538 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1539 if (!(This->sIcoPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszIconPath)))
1540 return E_OUTOFMEMORY;
1541 This->iIcoNdx = iIcon;
1543 return NOERROR;
1546 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1548 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1550 FIXME("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1551 return NOERROR;
1554 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1556 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1558 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1559 return NOERROR;
1562 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1564 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1566 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1568 if (This->sPath)
1569 HeapFree(GetProcessHeap(), 0, This->sPath);
1570 if (!(This->sPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszFile)))
1571 return E_OUTOFMEMORY;
1573 return NOERROR;
1576 /**************************************************************************
1577 * IShellLinkW Implementation
1580 static ICOM_VTABLE(IShellLinkW) slvtw =
1582 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1583 IShellLinkW_fnQueryInterface,
1584 IShellLinkW_fnAddRef,
1585 IShellLinkW_fnRelease,
1586 IShellLinkW_fnGetPath,
1587 IShellLinkW_fnGetIDList,
1588 IShellLinkW_fnSetIDList,
1589 IShellLinkW_fnGetDescription,
1590 IShellLinkW_fnSetDescription,
1591 IShellLinkW_fnGetWorkingDirectory,
1592 IShellLinkW_fnSetWorkingDirectory,
1593 IShellLinkW_fnGetArguments,
1594 IShellLinkW_fnSetArguments,
1595 IShellLinkW_fnGetHotkey,
1596 IShellLinkW_fnSetHotkey,
1597 IShellLinkW_fnGetShowCmd,
1598 IShellLinkW_fnSetShowCmd,
1599 IShellLinkW_fnGetIconLocation,
1600 IShellLinkW_fnSetIconLocation,
1601 IShellLinkW_fnSetRelativePath,
1602 IShellLinkW_fnResolve,
1603 IShellLinkW_fnSetPath