Merged the two serializer and unserializer functions into one, cleaned
[wine.git] / dlls / shell32 / shelllink.c
blob1689e4993c614e6dc77238a1fe36aa9a891657ef
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 #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"
36 #include "shlobj.h"
37 #include "undocshell.h"
38 #include "bitmaps/wine.xpm"
40 #include "heap.h"
41 #include "pidl.h"
42 #include "shell32_main.h"
43 #include "shlguid.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(shell);
47 /* link file formats */
49 #include "pshpack1.h"
51 /* flag1: lnk elements: simple link has 0x0B */
52 #define WORKDIR 0x10
53 #define ARGUMENT 0x20
54 #define ICON 0x40
55 #define UNC 0x80
57 /* fStartup */
58 #define NORMAL 0x01
59 #define MAXIMIZED 0x03
60 #define MINIMIZED 0x07
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;
80 #define LINK_HEADER_SIZE (sizeof(LINK_HEADER)-sizeof(ITEMIDLIST))
82 typedef struct
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;
94 typedef struct
96 WORD idReserved;
97 WORD idType;
98 WORD idCount;
99 GRPICONDIRENTRY idEntries[1];
100 } GRPICONDIR;
102 typedef struct
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;
114 typedef struct
116 WORD idReserved;
117 WORD idType;
118 WORD idCount;
119 } ICONDIR;
122 #include "poppack.h"
124 typedef struct
126 HRSRC *pResInfo;
127 int nIndex;
128 } ENUMRESSTRUCT;
130 static ICOM_VTABLE(IShellLinkA) slvt;
131 static ICOM_VTABLE(IShellLinkW) slvtw;
132 static ICOM_VTABLE(IPersistFile) pfvt;
133 static ICOM_VTABLE(IPersistStream) psvt;
135 /* IShellLink Implementation */
137 typedef struct
139 ICOM_VFIELD(IShellLinkA);
140 DWORD ref;
142 ICOM_VTABLE(IShellLinkW)* lpvtblw;
143 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
144 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
146 /* internal stream of the IPersistFile interface */
147 IStream* lpFileStream;
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;
157 LPSTR sIcoPath;
158 INT iIcoNdx;
159 LPSTR sArgs;
160 LPSTR sWorkDir;
161 LPSTR sDescription;
162 } IShellLinkImpl;
164 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
165 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset);
167 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
168 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
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);
175 /* strdup on the process heap */
176 inline static LPSTR heap_strdup( LPCSTR str )
178 INT len = strlen(str) + 1;
179 LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
180 if (p) memcpy( p, str, len );
181 return p;
185 /**************************************************************************
186 * IPersistFile_QueryInterface
188 static HRESULT WINAPI IPersistFile_fnQueryInterface(
189 IPersistFile* iface,
190 REFIID riid,
191 LPVOID *ppvObj)
193 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
195 TRACE("(%p)\n",This);
197 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
200 /******************************************************************************
201 * IPersistFile_AddRef
203 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
205 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
207 TRACE("(%p)->(count=%lu)\n",This,This->ref);
209 return IShellLinkA_AddRef((IShellLinkA*)This);
211 /******************************************************************************
212 * IPersistFile_Release
214 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
216 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
218 TRACE("(%p)->(count=%lu)\n",This,This->ref);
220 return IShellLinkA_Release((IShellLinkA*)This);
223 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
225 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
226 FIXME("(%p)\n",This);
227 return NOERROR;
229 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
231 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
232 FIXME("(%p)\n",This);
233 return NOERROR;
235 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
237 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
238 _IPersistStream_From_ICOM_THIS(IPersistStream, This)
240 LPSTR sFile = HEAP_strdupWtoA ( GetProcessHeap(), 0, pszFileName);
241 HRESULT hRet = E_FAIL;
243 TRACE("(%p, %s)\n",This, sFile);
246 if (This->lpFileStream)
247 IStream_Release(This->lpFileStream);
249 if SUCCEEDED(CreateStreamOnFile(sFile, &(This->lpFileStream)))
251 if SUCCEEDED (IPersistStream_Load(StreamThis, This->lpFileStream))
253 return NOERROR;
257 return hRet;
261 /* Icon extraction routines
263 * FIXME: should use PrivateExtractIcons and friends
264 * FIXME: should not use stdio
267 static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName)
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;
281 if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8)))
282 return 0;
284 if (!(fXPMFile = fopen(szXPMFileName, "w")))
285 return 0;
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;
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)
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))
305 aColorUsed[COLOR(j,i)] = TRUE;
306 nColorsUsed++;
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;
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;
323 for (i = 0; i < nHeight; i++)
325 if (fprintf(fXPMFile, ",\n\"") <= 0)
326 goto error;
327 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
329 if MASK(j,i)
331 if (fprintf(fXPMFile, " ") <= 0)
332 goto error;
334 else
335 if (fprintf(fXPMFile, "%.2X", COLOR(j,i)) <= 0)
336 goto error;
338 if (fprintf(fXPMFile, "\"") <= 0)
339 goto error;
341 if (fprintf(fXPMFile, "};\n") <= 0)
342 goto error;
344 #undef MASK
345 #undef COLOR
347 fclose(fXPMFile);
348 return 1;
350 error:
351 fclose(fXPMFile);
352 unlink( szXPMFileName );
353 return 0;
356 static BOOL CALLBACK EnumResNameProc(HANDLE hModule, const char *lpszType, char *lpszName, LONG lParam)
358 ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam;
360 if (!sEnumRes->nIndex--)
362 *sEnumRes->pResInfo = FindResourceA(hModule, lpszName, RT_GROUP_ICONA);
363 return FALSE;
365 else
366 return TRUE;
369 static int ExtractFromEXEDLL(const char *szFileName, int nIndex, const char *szXPMFileName)
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;
382 if (!(hModule = LoadLibraryExA(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE)))
384 TRACE("LoadLibraryExA (%s) failed, error %ld\n", szFileName, GetLastError());
385 goto error1;
388 if (nIndex < 0)
390 hResInfo = FindResourceA(hModule, MAKEINTRESOURCEA(-nIndex), RT_GROUP_ICONA);
391 TRACE("FindResourceA (%s) called, return 0x%x, error %ld\n", szFileName, hResInfo, GetLastError());
393 else
395 sEnumRes.pResInfo = &hResInfo;
396 sEnumRes.nIndex = nIndex;
397 if (EnumResourceNamesA(hModule, RT_GROUP_ICONA, &EnumResNameProc, (LONG) &sEnumRes))
399 TRACE("EnumResourceNamesA failed, error %ld\n", GetLastError());
400 goto error2;
404 if (!hResInfo)
406 TRACE("ExtractFromEXEDLL failed, error %ld\n", GetLastError());
407 goto error2;
410 if (!(hResData = LoadResource(hModule, hResInfo)))
412 TRACE("LoadResource failed, error %ld\n", GetLastError());
413 goto error2;
415 if (!(pIconDir = LockResource(hResData)))
417 TRACE("LockResource failed, error %ld\n", GetLastError());
418 goto error3;
421 for (i = 0; i < pIconDir->idCount; i++)
422 if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8))
424 if (pIconDir->idEntries[i].wBitCount > nMaxBits)
426 nMaxBits = pIconDir->idEntries[i].wBitCount;
427 nMax = 0;
429 if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax)
431 lpName = MAKEINTRESOURCEA(pIconDir->idEntries[i].nID);
432 nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
436 FreeResource(hResData);
438 if (!(hResInfo = FindResourceA(hModule, lpName, RT_ICONA)))
440 TRACE("Second FindResourceA failed, error %ld\n", GetLastError());
441 goto error2;
443 if (!(hResData = LoadResource(hModule, hResInfo)))
445 TRACE("Second LoadResource failed, error %ld\n", GetLastError());
446 goto error2;
448 if (!(pIcon = LockResource(hResData)))
450 TRACE("Second LockResource failed, error %ld\n", GetLastError());
451 goto error3;
454 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
456 TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
457 goto error3;
460 FreeResource(hResData);
461 FreeLibrary(hModule);
463 return 1;
465 error3:
466 FreeResource(hResData);
467 error2:
468 FreeLibrary(hModule);
469 error1:
470 return 0;
473 static int ExtractFromICO(const char *szFileName, const char *szXPMFileName)
475 FILE *fICOFile;
476 ICONDIR iconDir;
477 ICONDIRENTRY *pIconDirEntry;
478 int nMax = 0;
479 int nIndex = 0;
480 void *pIcon;
481 int i;
483 if (!(fICOFile = fopen(szFileName, "r")))
484 goto error1;
486 if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
487 goto error2;
488 if ((iconDir.idReserved != 0) || (iconDir.idType != 1))
489 goto error2;
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;
496 for (i = 0; i < iconDir.idCount; i++)
497 if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
499 nIndex = i;
500 nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
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;
509 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
510 goto error4;
512 free(pIcon);
513 free(pIconDirEntry);
514 fclose(fICOFile);
516 return 1;
518 error4:
519 free(pIcon);
520 error3:
521 free(pIconDirEntry);
522 error2:
523 fclose(fICOFile);
524 error1:
525 return 0;
528 /* get the Unix file name for a given path, allocating the string */
529 inline static char *get_unix_file_name( const char *dos )
531 char buffer[MAX_PATH];
533 if (!wine_get_unix_file_name( dos, buffer, sizeof(buffer) )) return NULL;
534 return heap_strdup( buffer );
537 static BOOL create_default_icon( const char *filename )
539 FILE *fXPM;
540 int i;
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;
551 /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
552 static char *extract_icon( const char *path, int index)
554 int nodefault = 1;
555 char *filename = heap_strdup( tmpnam(NULL) );
557 /* If icon path begins with a '*' then this is a deferred call */
558 if (path[0] == '*')
560 path++;
561 nodefault = 0;
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;
572 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
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;
584 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
586 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
588 if (!pszFileName || !This->sPath)
589 return ERROR_UNKNOWN;
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;
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 ))
601 DWORD type, count = sizeof(buffer);
602 if (RegQueryValueExA( hkey, "ShellLinker", 0, &type, buffer, &count )) buffer[0] = 0;
603 RegCloseKey( hkey );
605 if (!*buffer) return NOERROR;
606 shell_link_app = heap_strdup( buffer );
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 );
613 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTUP, FALSE ))
615 /* ignore startup for now */
616 if (!strncasecmp( filename, buffer, strlen(buffer) )) goto done;
618 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_DESKTOPDIRECTORY, FALSE ))
620 if (!strncasecmp( filename, buffer, strlen(buffer) ))
622 link_name = filename + strlen(buffer);
623 bDesktop = TRUE;
624 goto found;
627 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTMENU, FALSE ))
629 if (!strncasecmp( filename, buffer, strlen(buffer) ))
631 link_name = filename + strlen(buffer);
632 bDesktop = FALSE;
633 goto found;
636 goto done;
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;
646 /* convert app working dir */
647 if (This->sWorkDir) work_dir = get_unix_file_name( This->sWorkDir );
649 /* extract the icon */
650 if (!(icon_name = extract_icon( This->sIcoPath && strlen(This->sIcoPath) ?
651 This->sIcoPath : This->sPath,
652 This->iIcoNdx )))
654 /* Couldn't extract icon -- defer this menu entry to runonce. */
655 HKEY hRunOnce;
656 char* buffer = NULL;
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)
662 ret = ERROR_UNKNOWN;
663 goto done;
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)
672 HeapFree(GetProcessHeap(), 0, buffer);
673 RegCloseKey(hRunOnce);
674 ret = ERROR_UNKNOWN;
675 goto done;
677 HeapFree(GetProcessHeap(), 0, buffer);
678 RegCloseKey(hRunOnce);
679 goto done;
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 : "" );
687 if ((pid = fork()) == -1) goto done;
688 if (!pid)
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))
700 argv[pos++] = "--args";
701 argv[pos++] = This->sArgs;
703 if (icon_name)
705 argv[pos++] = "--icon";
706 argv[pos++] = icon_name;
708 if (This->sWorkDir && strlen(This->sWorkDir))
710 argv[pos++] = "--workdir";
711 argv[pos++] = This->sWorkDir;
713 if (This->sDescription && strlen(This->sDescription))
715 argv[pos++] = "--descr";
716 argv[pos++] = This->sDescription;
718 argv[pos] = NULL;
719 execvp( shell_link_app, argv );
720 _exit(1);
723 while (waitpid( pid, &status, 0 ) == -1)
725 if (errno != EINTR)
727 ret = ERROR_UNKNOWN;
728 goto done;
731 if (status) ret = E_ACCESSDENIED;
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;
742 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
744 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
745 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
746 return NOERROR;
748 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
750 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
751 FIXME("(%p)\n",This);
752 return NOERROR;
755 static ICOM_VTABLE(IPersistFile) pfvt =
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
769 /************************************************************************
770 * IPersistStream_QueryInterface
772 static HRESULT WINAPI IPersistStream_fnQueryInterface(
773 IPersistStream* iface,
774 REFIID riid,
775 VOID** ppvoid)
777 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
779 TRACE("(%p)\n",This);
781 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
784 /************************************************************************
785 * IPersistStream_Release
787 static ULONG WINAPI IPersistStream_fnRelease(
788 IPersistStream* iface)
790 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
792 TRACE("(%p)\n",This);
794 return IShellLinkA_Release((IShellLinkA*)This);
797 /************************************************************************
798 * IPersistStream_AddRef
800 static ULONG WINAPI IPersistStream_fnAddRef(
801 IPersistStream* iface)
803 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
805 TRACE("(%p)\n",This);
807 return IShellLinkA_AddRef((IShellLinkA*)This);
810 /************************************************************************
811 * IPersistStream_GetClassID
814 static HRESULT WINAPI IPersistStream_fnGetClassID(
815 IPersistStream* iface,
816 CLSID* pClassID)
818 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
820 TRACE("(%p)\n", This);
822 if (pClassID==0)
823 return E_POINTER;
825 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
827 return S_OK;
830 /************************************************************************
831 * IPersistStream_IsDirty (IPersistStream)
833 static HRESULT WINAPI IPersistStream_fnIsDirty(
834 IPersistStream* iface)
836 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
838 TRACE("(%p)\n", This);
840 return S_OK;
842 /************************************************************************
843 * IPersistStream_Load (IPersistStream)
846 static HRESULT WINAPI IPersistStream_fnLoad(
847 IPersistStream* iface,
848 IStream* pLoadStream)
850 PLINK_HEADER lpLinkHeader = HeapAlloc(GetProcessHeap(), 0, LINK_HEADER_SIZE);
851 ULONG dwBytesRead;
852 DWORD ret = E_FAIL;
853 char sTemp[MAX_PATH];
855 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
857 TRACE("(%p)(%p)\n", This, pLoadStream);
859 if ( ! pLoadStream)
861 return STG_E_INVALIDPOINTER;
864 IStream_AddRef (pLoadStream);
865 if(lpLinkHeader)
867 if (SUCCEEDED(IStream_Read(pLoadStream, lpLinkHeader, LINK_HEADER_SIZE, &dwBytesRead)))
869 if ((lpLinkHeader->MagicStr == 0x0000004CL) && IsEqualIID(&lpLinkHeader->MagicGuid, &CLSID_ShellLink))
871 lpLinkHeader = HeapReAlloc(GetProcessHeap(), 0, lpLinkHeader, LINK_HEADER_SIZE+lpLinkHeader->PidlSize);
872 if (lpLinkHeader)
874 if (SUCCEEDED(IStream_Read(pLoadStream, &(lpLinkHeader->Pidl), lpLinkHeader->PidlSize, &dwBytesRead)))
876 if (pcheck (&lpLinkHeader->Pidl))
878 This->pPidl = ILClone (&lpLinkHeader->Pidl);
880 SHGetPathFromIDListA(&lpLinkHeader->Pidl, sTemp);
881 This->sPath = heap_strdup( sTemp );
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;
900 else
902 WARN("stream contains no link!\n");
907 IStream_Release (pLoadStream);
909 pdump(This->pPidl);
911 HeapFree(GetProcessHeap(), 0, lpLinkHeader);
913 return ret;
916 /************************************************************************
917 * IPersistStream_Save (IPersistStream)
919 static HRESULT WINAPI IPersistStream_fnSave(
920 IPersistStream* iface,
921 IStream* pOutStream,
922 BOOL fClearDirty)
924 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
926 TRACE("(%p) %p %x\n", This, pOutStream, fClearDirty);
928 return E_NOTIMPL;
931 /************************************************************************
932 * IPersistStream_GetSizeMax (IPersistStream)
934 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
935 IPersistStream* iface,
936 ULARGE_INTEGER* pcbSize)
938 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
940 TRACE("(%p)\n", This);
942 return E_NOTIMPL;
945 static ICOM_VTABLE(IPersistStream) psvt =
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
958 /**************************************************************************
959 * IShellLink_Constructor
961 IShellLinkA * IShellLink_Constructor(BOOL bUnicode)
962 { IShellLinkImpl * sl;
964 sl = (IShellLinkImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IShellLinkImpl));
965 sl->ref = 1;
966 ICOM_VTBL(sl) = &slvt;
967 sl->lpvtblw = &slvtw;
968 sl->lpvtblPersistFile = &pfvt;
969 sl->lpvtblPersistStream = &psvt;
971 TRACE("(%p)->()\n",sl);
972 shell32_ObjCount++;
973 return bUnicode ? (IShellLinkA *) &(sl->lpvtblw) : (IShellLinkA *)sl;
976 /**************************************************************************
977 * IShellLinkA_QueryInterface
979 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
981 ICOM_THIS(IShellLinkImpl, iface);
983 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
985 *ppvObj = NULL;
987 if(IsEqualIID(riid, &IID_IUnknown) ||
988 IsEqualIID(riid, &IID_IShellLinkA))
990 *ppvObj = This;
992 else if(IsEqualIID(riid, &IID_IShellLinkW))
994 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
996 else if(IsEqualIID(riid, &IID_IPersistFile))
998 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
1000 else if(IsEqualIID(riid, &IID_IPersistStream))
1002 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
1005 if(*ppvObj)
1007 IUnknown_AddRef((IUnknown*)(*ppvObj));
1008 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
1009 return S_OK;
1011 TRACE("-- Interface: E_NOINTERFACE\n");
1012 return E_NOINTERFACE;
1014 /******************************************************************************
1015 * IShellLinkA_AddRef
1017 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
1019 ICOM_THIS(IShellLinkImpl, iface);
1021 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1023 shell32_ObjCount++;
1024 return ++(This->ref);
1026 /******************************************************************************
1027 * IShellLinkA_Release
1029 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
1031 ICOM_THIS(IShellLinkImpl, iface);
1033 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1035 shell32_ObjCount--;
1036 if (!--(This->ref))
1037 { TRACE("-- destroying IShellLink(%p)\n",This);
1039 if (This->sIcoPath)
1040 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1042 if (This->sArgs)
1043 HeapFree(GetProcessHeap(), 0, This->sArgs);
1045 if (This->sWorkDir)
1046 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1048 if (This->sDescription)
1049 HeapFree(GetProcessHeap(), 0, This->sDescription);
1051 if (This->sPath)
1052 HeapFree(GetProcessHeap(),0,This->sPath);
1054 if (This->pPidl)
1055 SHFree(This->pPidl);
1057 if (This->lpFileStream)
1058 IStream_Release(This->lpFileStream);
1060 This->iIcoNdx = 0;
1062 HeapFree(GetProcessHeap(),0,This);
1063 return 0;
1065 return This->ref;
1068 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1070 ICOM_THIS(IShellLinkImpl, iface);
1072 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",This, pszFile, cchMaxPath, pfd, fFlags, debugstr_a(This->sPath));
1074 if (This->sPath)
1075 lstrcpynA(pszFile,This->sPath, cchMaxPath);
1076 else
1077 return E_FAIL;
1079 return NOERROR;
1081 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1083 ICOM_THIS(IShellLinkImpl, iface);
1085 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1087 *ppidl = ILClone(This->pPidl);
1088 return NOERROR;
1090 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1092 ICOM_THIS(IShellLinkImpl, iface);
1094 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1096 if (This->pPidl)
1097 SHFree(This->pPidl);
1098 This->pPidl = ILClone (pidl);
1099 return NOERROR;
1101 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1103 ICOM_THIS(IShellLinkImpl, iface);
1105 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1106 lstrcpynA(pszName,"Description, FIXME",cchMaxName);
1107 return NOERROR;
1109 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1111 ICOM_THIS(IShellLinkImpl, iface);
1113 TRACE("(%p)->(pName=%s)\n", This, pszName);
1115 if (This->sDescription)
1116 HeapFree(GetProcessHeap(), 0, This->sDescription);
1117 if (!(This->sDescription = heap_strdup(pszName)))
1118 return E_OUTOFMEMORY;
1120 return NOERROR;
1122 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1124 ICOM_THIS(IShellLinkImpl, iface);
1126 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1128 lstrcpynA( pszDir, This->sWorkDir ? This->sWorkDir : "", cchMaxPath );
1130 return NOERROR;
1132 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1134 ICOM_THIS(IShellLinkImpl, iface);
1136 TRACE("(%p)->(dir=%s)\n",This, pszDir);
1138 if (This->sWorkDir)
1139 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1140 if (!(This->sWorkDir = heap_strdup(pszDir)))
1141 return E_OUTOFMEMORY;
1143 return NOERROR;
1145 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1147 ICOM_THIS(IShellLinkImpl, iface);
1149 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1151 lstrcpynA( pszArgs, This->sArgs ? This->sArgs : "", cchMaxPath );
1153 return NOERROR;
1155 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1157 ICOM_THIS(IShellLinkImpl, iface);
1159 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1161 if (This->sArgs)
1162 HeapFree(GetProcessHeap(), 0, This->sArgs);
1163 if (!(This->sArgs = heap_strdup(pszArgs)))
1164 return E_OUTOFMEMORY;
1166 return NOERROR;
1168 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1170 ICOM_THIS(IShellLinkImpl, iface);
1172 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1174 *pwHotkey = This->wHotKey;
1176 return NOERROR;
1178 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1180 ICOM_THIS(IShellLinkImpl, iface);
1182 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1184 This->wHotKey = wHotkey;
1186 return NOERROR;
1188 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1190 ICOM_THIS(IShellLinkImpl, iface);
1192 FIXME("(%p)->(%p)\n",This, piShowCmd);
1193 *piShowCmd=0;
1194 return NOERROR;
1196 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1198 ICOM_THIS(IShellLinkImpl, iface);
1200 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1201 return NOERROR;
1203 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1205 ICOM_THIS(IShellLinkImpl, iface);
1207 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1209 lstrcpynA( pszIconPath, This->sIcoPath ? This->sIcoPath : "", cchIconPath );
1210 *piIcon = This->iIcoNdx;
1212 return NOERROR;
1214 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1216 ICOM_THIS(IShellLinkImpl, iface);
1218 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1220 if (This->sIcoPath)
1221 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1222 if (!(This->sIcoPath = heap_strdup(pszIconPath)))
1223 return E_OUTOFMEMORY;
1224 This->iIcoNdx = iIcon;
1226 return NOERROR;
1228 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1230 ICOM_THIS(IShellLinkImpl, iface);
1232 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1233 return NOERROR;
1235 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1237 ICOM_THIS(IShellLinkImpl, iface);
1239 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1240 return NOERROR;
1242 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1244 ICOM_THIS(IShellLinkImpl, iface);
1246 TRACE("(%p)->(path=%s)\n",This, pszFile);
1248 if (This->sPath)
1249 HeapFree(GetProcessHeap(), 0, This->sPath);
1250 if (!(This->sPath = heap_strdup(pszFile)))
1251 return E_OUTOFMEMORY;
1253 return NOERROR;
1256 /**************************************************************************
1257 * IShellLink Implementation
1260 static ICOM_VTABLE(IShellLinkA) slvt =
1262 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1263 IShellLinkA_fnQueryInterface,
1264 IShellLinkA_fnAddRef,
1265 IShellLinkA_fnRelease,
1266 IShellLinkA_fnGetPath,
1267 IShellLinkA_fnGetIDList,
1268 IShellLinkA_fnSetIDList,
1269 IShellLinkA_fnGetDescription,
1270 IShellLinkA_fnSetDescription,
1271 IShellLinkA_fnGetWorkingDirectory,
1272 IShellLinkA_fnSetWorkingDirectory,
1273 IShellLinkA_fnGetArguments,
1274 IShellLinkA_fnSetArguments,
1275 IShellLinkA_fnGetHotkey,
1276 IShellLinkA_fnSetHotkey,
1277 IShellLinkA_fnGetShowCmd,
1278 IShellLinkA_fnSetShowCmd,
1279 IShellLinkA_fnGetIconLocation,
1280 IShellLinkA_fnSetIconLocation,
1281 IShellLinkA_fnSetRelativePath,
1282 IShellLinkA_fnResolve,
1283 IShellLinkA_fnSetPath
1287 /**************************************************************************
1288 * IShellLinkW_fnQueryInterface
1290 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1291 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1293 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1295 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1298 /******************************************************************************
1299 * IShellLinkW_fnAddRef
1301 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1303 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1305 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1307 return IShellLinkA_AddRef((IShellLinkA*)This);
1309 /******************************************************************************
1310 * IShellLinkW_fnRelease
1313 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1315 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1317 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1319 return IShellLinkA_Release((IShellLinkA*)This);
1322 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1324 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1326 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1327 MultiByteToWideChar( CP_ACP, 0, "c:\\foo.bar", -1, pszFile, cchMaxPath );
1328 return NOERROR;
1331 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1333 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1335 FIXME("(%p)->(ppidl=%p)\n",This, ppidl);
1336 *ppidl = _ILCreateDesktop();
1337 return NOERROR;
1340 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1342 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1344 FIXME("(%p)->(pidl=%p)\n",This, pidl);
1345 return NOERROR;
1348 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1350 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1352 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1353 MultiByteToWideChar( CP_ACP, 0, "Description, FIXME", -1, pszName, cchMaxName );
1354 return NOERROR;
1357 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1359 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1361 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1363 if (This->sDescription)
1364 HeapFree(GetProcessHeap(), 0, This->sDescription);
1365 if (!(This->sDescription = HEAP_strdupWtoA(GetProcessHeap(), 0, pszName)))
1366 return E_OUTOFMEMORY;
1368 return NOERROR;
1371 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1373 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1375 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1377 MultiByteToWideChar( CP_ACP, 0, This->sWorkDir ? This->sWorkDir : "", -1, pszDir, cchMaxPath );
1379 return NOERROR;
1382 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1384 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1386 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1388 if (This->sWorkDir)
1389 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1390 if (!(This->sWorkDir = HEAP_strdupWtoA(GetProcessHeap(), 0, pszDir)))
1391 return E_OUTOFMEMORY;
1393 return NOERROR;
1396 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1398 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1400 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1402 MultiByteToWideChar( CP_ACP, 0, This->sArgs ? This->sArgs : "", -1, pszArgs, cchMaxPath );
1404 return NOERROR;
1407 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1409 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1411 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1413 if (This->sArgs)
1414 HeapFree(GetProcessHeap(), 0, This->sArgs);
1415 if (!(This->sArgs = HEAP_strdupWtoA(GetProcessHeap(), 0, pszArgs)))
1416 return E_OUTOFMEMORY;
1418 return NOERROR;
1421 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1423 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1425 FIXME("(%p)->(%p)\n",This, pwHotkey);
1426 *pwHotkey=0x0;
1427 return NOERROR;
1430 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1432 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1434 FIXME("(%p)->(hotkey=%x)\n",This, wHotkey);
1435 return NOERROR;
1438 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1440 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1442 FIXME("(%p)->(%p)\n",This, piShowCmd);
1443 *piShowCmd=0;
1444 return NOERROR;
1447 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1449 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1451 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1452 return NOERROR;
1455 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1457 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1459 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1461 MultiByteToWideChar( CP_ACP, 0, This->sIcoPath ? This->sIcoPath : "", -1, pszIconPath, cchIconPath );
1462 *piIcon = This->iIcoNdx;
1464 return NOERROR;
1467 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1469 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1471 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1473 if (This->sIcoPath)
1474 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1475 if (!(This->sIcoPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszIconPath)))
1476 return E_OUTOFMEMORY;
1477 This->iIcoNdx = iIcon;
1479 return NOERROR;
1482 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1484 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1486 FIXME("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1487 return NOERROR;
1490 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1492 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1494 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1495 return NOERROR;
1498 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1500 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1502 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1504 if (This->sPath)
1505 HeapFree(GetProcessHeap(), 0, This->sPath);
1506 if (!(This->sPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszFile)))
1507 return E_OUTOFMEMORY;
1509 return NOERROR;
1512 /**************************************************************************
1513 * IShellLinkW Implementation
1516 static ICOM_VTABLE(IShellLinkW) slvtw =
1518 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1519 IShellLinkW_fnQueryInterface,
1520 IShellLinkW_fnAddRef,
1521 IShellLinkW_fnRelease,
1522 IShellLinkW_fnGetPath,
1523 IShellLinkW_fnGetIDList,
1524 IShellLinkW_fnSetIDList,
1525 IShellLinkW_fnGetDescription,
1526 IShellLinkW_fnSetDescription,
1527 IShellLinkW_fnGetWorkingDirectory,
1528 IShellLinkW_fnSetWorkingDirectory,
1529 IShellLinkW_fnGetArguments,
1530 IShellLinkW_fnSetArguments,
1531 IShellLinkW_fnGetHotkey,
1532 IShellLinkW_fnSetHotkey,
1533 IShellLinkW_fnGetShowCmd,
1534 IShellLinkW_fnSetShowCmd,
1535 IShellLinkW_fnGetIconLocation,
1536 IShellLinkW_fnSetIconLocation,
1537 IShellLinkW_fnSetRelativePath,
1538 IShellLinkW_fnResolve,
1539 IShellLinkW_fnSetPath