3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
15 #include "debugtools.h"
21 #include "wine/winestring.h"
22 #include "wine/undocshell.h"
23 #include "bitmaps/wine.xpm"
27 #include "shell32_main.h"
32 DEFAULT_DEBUG_CHANNEL(shell);
34 /* link file formats */
38 /* flag1: lnk elements: simple link has 0x0B */
46 #define MAXIMIZED 0x03
47 #define MINIMIZED 0x07
49 typedef struct _LINK_HEADER
50 { DWORD MagicStr; /* 0x00 'L','\0','\0','\0' */
51 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
52 DWORD Flag1; /* 0x14 describes elements following */
53 DWORD Flag2; /* 0x18 */
54 FILETIME Time1; /* 0x1c */
55 FILETIME Time2; /* 0x24 */
56 FILETIME Time3; /* 0x2c */
57 DWORD Unknown1; /* 0x34 */
58 DWORD Unknown2; /* 0x38 icon number */
59 DWORD fStartup; /* 0x3c startup type */
60 DWORD wHotKey; /* 0x40 hotkey */
61 DWORD Unknown5; /* 0x44 */
62 DWORD Unknown6; /* 0x48 */
63 USHORT PidlSize; /* 0x4c */
64 ITEMIDLIST Pidl; /* 0x4e */
65 } LINK_HEADER, * PLINK_HEADER;
67 #define LINK_HEADER_SIZE (sizeof(LINK_HEADER)-sizeof(ITEMIDLIST))
86 GRPICONDIRENTRY idEntries[1];
112 static ICOM_VTABLE(IShellLinkA) slvt;
113 static ICOM_VTABLE(IShellLinkW) slvtw;
114 static ICOM_VTABLE(IPersistFile) pfvt;
115 static ICOM_VTABLE(IPersistStream) psvt;
117 /* IShellLink Implementation */
121 ICOM_VFIELD(IShellLinkA);
124 ICOM_VTABLE(IShellLinkW)* lpvtblw;
125 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
126 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
128 /* internal stream of the IPersistFile interface */
129 IStream* lpFileStream;
131 /* data structures according to the informations in the lnk */
146 #define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
147 #define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset);
149 #define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
150 #define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
152 #define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
153 #define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset);
154 #define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset);
156 /**************************************************************************
157 * IPersistFile_QueryInterface
159 static HRESULT WINAPI IPersistFile_fnQueryInterface(
164 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
166 TRACE("(%p)\n",This);
168 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
171 /******************************************************************************
172 * IPersistFile_AddRef
174 static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
176 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
178 TRACE("(%p)->(count=%lu)\n",This,This->ref);
180 return IShellLinkA_AddRef((IShellLinkA*)This);
182 /******************************************************************************
183 * IPersistFile_Release
185 static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
187 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
189 TRACE("(%p)->(count=%lu)\n",This,This->ref);
191 return IShellLinkA_Release((IShellLinkA*)This);
194 static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
196 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
197 FIXME("(%p)\n",This);
200 static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
202 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
203 FIXME("(%p)\n",This);
206 static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
208 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
209 _IPersistStream_From_ICOM_THIS(IPersistStream, This)
211 LPSTR sFile = HEAP_strdupWtoA ( GetProcessHeap(), 0, pszFileName);
212 HRESULT hRet = E_FAIL;
214 TRACE("(%p, %s)\n",This, sFile);
217 if (This->lpFileStream)
218 IStream_Release(This->lpFileStream);
220 if SUCCEEDED(CreateStreamOnFile(sFile, &(This->lpFileStream)))
222 if SUCCEEDED (IPersistStream_Load(StreamThis, This->lpFileStream))
232 /* Icon extraction routines
234 * FIXME: should use PrivateExtractIcons and friends
235 * FIXME: should not use stdio
238 static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName)
248 BOOL aColorUsed[256] = {0};
252 if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8)))
255 if (!(fXPMFile = fopen(szXPMFileName, "w")))
258 nHeight = pIcon->bmiHeader.biHeight / 2;
259 nXORWidthBytes = 4 * ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount / 32)
260 + ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount % 32) > 0));
261 nANDWidthBytes = 4 * ((pIcon->bmiHeader.biWidth / 32)
262 + ((pIcon->bmiHeader.biWidth % 32) > 0));
263 b8BitColors = pIcon->bmiHeader.biBitCount == 8;
264 nColors = pIcon->bmiHeader.biClrUsed ? pIcon->bmiHeader.biClrUsed
265 : 1 << pIcon->bmiHeader.biBitCount;
266 pXOR = (BYTE*) pIcon + sizeof (BITMAPINFOHEADER) + (nColors * sizeof (RGBQUAD));
267 pAND = pXOR + nHeight * nXORWidthBytes;
269 #define MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
270 #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)
272 for (i = 0; i < nHeight; i++)
273 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
274 if (!aColorUsed[COLOR(j,i)] && !MASK(j,i))
276 aColorUsed[COLOR(j,i)] = TRUE;
280 if (fprintf(fXPMFile, "/* XPM */\nstatic char *icon[] = {\n") <= 0)
282 if (fprintf(fXPMFile, "\"%d %d %d %d\",\n",
283 (int) pIcon->bmiHeader.biWidth, nHeight, nColorsUsed + 1, 2) <=0)
286 for (i = 0; i < nColors; i++)
288 if (fprintf(fXPMFile, "\"%.2X c #%.2X%.2X%.2X\",\n", i, pIcon->bmiColors[i].rgbRed,
289 pIcon->bmiColors[i].rgbGreen, pIcon->bmiColors[i].rgbBlue) <= 0)
291 if (fprintf(fXPMFile, "\" c None\"") <= 0)
294 for (i = 0; i < nHeight; i++)
296 if (fprintf(fXPMFile, ",\n\"") <= 0)
298 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
302 if (fprintf(fXPMFile, " ") <= 0)
306 if (fprintf(fXPMFile, "%.2X", COLOR(j,i)) <= 0)
309 if (fprintf(fXPMFile, "\"") <= 0)
312 if (fprintf(fXPMFile, "};\n") <= 0)
323 unlink( szXPMFileName );
327 static BOOL CALLBACK EnumResNameProc(HANDLE hModule, const char *lpszType, char *lpszName, LONG lParam)
329 *(HRSRC *) lParam = FindResourceA(hModule, lpszName, RT_GROUP_ICONA);
333 static int ExtractFromEXEDLL(const char *szFileName, int nIndex, const char *szXPMFileName)
339 GRPICONDIR *pIconDir;
344 if (!(hModule = LoadLibraryExA(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE)))
348 hResInfo = FindResourceA(hModule, MAKEINTRESOURCEA(nIndex), RT_GROUP_ICONA);
350 if (EnumResourceNamesA(hModule, RT_GROUP_ICONA, &EnumResNameProc, (LONG) &hResInfo))
356 if (!(hResData = LoadResource(hModule, hResInfo)))
358 if (!(pIconDir = LockResource(hResData)))
361 for (i = 0; i < pIconDir->idCount; i++)
362 if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax)
364 lpName = MAKEINTRESOURCEA(pIconDir->idEntries[i].nID);
365 nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
368 FreeResource(hResData);
370 if (!(hResInfo = FindResourceA(hModule, lpName, RT_ICONA)))
372 if (!(hResData = LoadResource(hModule, hResInfo)))
374 if (!(pIcon = LockResource(hResData)))
377 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
380 FreeResource(hResData);
381 FreeLibrary(hModule);
386 FreeResource(hResData);
388 FreeLibrary(hModule);
393 static int ExtractFromICO(const char *szFileName, const char *szXPMFileName)
397 ICONDIRENTRY *pIconDirEntry;
403 if (!(fICOFile = fopen(szFileName, "r")))
406 if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
408 if ((iconDir.idReserved != 0) || (iconDir.idType != 1))
411 if ((pIconDirEntry = malloc(iconDir.idCount * sizeof (ICONDIRENTRY))) == NULL)
413 if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
416 for (i = 0; i < iconDir.idCount; i++)
417 if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
420 nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
422 if ((pIcon = malloc(pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
424 if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
426 if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
429 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
448 /* get the Unix file name for a given path, allocating the string */
449 inline static char *get_unix_file_name( const char *dos )
453 if (!DOSFS_GetFullName( dos, FALSE, &path )) return NULL;
454 return HEAP_strdupA( GetProcessHeap(), 0, path.long_name );
457 static BOOL create_default_icon( const char *filename )
462 if (!(fXPM = fopen(filename, "w"))) return FALSE;
463 fprintf(fXPM, "/* XPM */\nstatic char * icon[] = {");
464 for (i = 0; i < sizeof(wine_xpm)/sizeof(wine_xpm[0]); i++)
465 fprintf( fXPM, "\n\"%s\",", wine_xpm[i]);
466 fprintf( fXPM, "};\n" );
471 /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
472 static char *extract_icon( const char *path, int index )
474 char *filename = HEAP_strdupA( GetProcessHeap(), 0, tmpnam(NULL) );
475 if (ExtractFromEXEDLL( path, index, filename )) return filename;
476 if (ExtractFromICO( path, filename )) return filename;
477 if (create_default_icon( filename )) return filename;
478 HeapFree( GetProcessHeap(), 0, filename );
483 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
485 HRESULT ret = NOERROR;
487 char buffer[MAX_PATH], buff2[MAX_PATH];
488 char *filename, *link_name, *p;
489 char *shell_link_app = NULL;
490 char *icon_name = NULL;
491 char *path_name = NULL;
492 char *work_dir = NULL;
495 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
497 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
499 if (!pszFileName || !This->sPath)
500 return ERROR_UNKNOWN;
502 /* check for .exe extension */
503 if (!(p = strrchr( This->sPath, '.' ))) return NOERROR;
504 if (strchr( p, '\\' ) || strchr( p, '/' )) return NOERROR;
505 if (strcasecmp( p, ".exe" )) return NOERROR;
507 /* check if ShellLinker configured */
508 PROFILE_GetWineIniString( "wine", "ShellLinker", "", buffer, sizeof(buffer) );
509 if (!*buffer) return NOERROR;
510 shell_link_app = HEAP_strdupA( GetProcessHeap(), 0, buffer );
512 if (!WideCharToMultiByte( CP_ACP, 0, pszFileName, -1, buffer, sizeof(buffer), NULL, NULL))
513 return ERROR_UNKNOWN;
514 GetFullPathNameA( buffer, sizeof(buff2), buff2, NULL );
515 filename = HEAP_strdupA( GetProcessHeap(), 0, buff2 );
517 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTUP, FALSE ))
519 /* ignore startup for now */
520 if (!strncasecmp( filename, buffer, strlen(buffer) )) goto done;
522 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_DESKTOPDIRECTORY, FALSE ))
524 if (!strncasecmp( filename, buffer, strlen(buffer) ))
526 link_name = filename + strlen(buffer);
531 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTMENU, FALSE ))
533 if (!strncasecmp( filename, buffer, strlen(buffer) ))
535 link_name = filename + strlen(buffer);
543 /* make link name a Unix name */
544 for (p = link_name; *p; p++) if (*p == '\\') *p = '/';
545 /* strip leading slashes */
546 while (*link_name == '/') link_name++;
547 /* remove extension */
548 if ((p = strrchr( link_name, '.' ))) *p = 0;
550 /* convert app path name */
551 path_name = get_unix_file_name( This->sPath );
553 /* convert app working dir */
554 if (This->sWorkDir) work_dir = get_unix_file_name( This->sWorkDir );
556 /* extract the icon */
557 if (!(icon_name = extract_icon( This->sIcoPath ? This->sIcoPath : This->sPath,
558 This->iIcoNdx ))) goto done;
560 TRACE("linker app='%s' link='%s' mode=%s path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
561 shell_link_app, link_name, bDesktop ? "desktop" : "menu", path_name,
562 This->sArgs ? This->sArgs : "", icon_name, work_dir ? work_dir : "",
563 This->sDescription ? This->sDescription : "" );
565 if ((pid = fork()) == -1) goto done;
570 argv[pos++] = shell_link_app;
571 argv[pos++] = "--link";
572 argv[pos++] = link_name;
573 argv[pos++] = "--path";
574 argv[pos++] = path_name;
575 argv[pos++] = bDesktop ? "--desktop" : "--menu";
578 argv[pos++] = "--args";
579 argv[pos++] = This->sArgs;
583 argv[pos++] = "--icon";
584 argv[pos++] = icon_name;
588 argv[pos++] = "--workdir";
589 argv[pos++] = This->sWorkDir;
591 if (This->sDescription)
593 argv[pos++] = "--descr";
594 argv[pos++] = This->sDescription;
597 execvp( shell_link_app, argv );
601 while (waitpid( pid, &status, 0 ) == -1)
609 if (status) ret = E_ACCESSDENIED;
612 if (icon_name) unlink( icon_name );
613 HeapFree( GetProcessHeap(), 0, shell_link_app );
614 HeapFree( GetProcessHeap(), 0, filename );
615 HeapFree( GetProcessHeap(), 0, icon_name );
616 HeapFree( GetProcessHeap(), 0, path_name );
617 HeapFree( GetProcessHeap(), 0, work_dir );
621 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
623 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
624 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
627 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
629 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
630 FIXME("(%p)\n",This);
634 static ICOM_VTABLE(IPersistFile) pfvt =
636 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
637 IPersistFile_fnQueryInterface,
638 IPersistFile_fnAddRef,
639 IPersistFile_fnRelease,
640 IPersistFile_fnGetClassID,
641 IPersistFile_fnIsDirty,
644 IPersistFile_fnSaveCompleted,
645 IPersistFile_fnGetCurFile
648 /************************************************************************
649 * IPersistStream_QueryInterface
651 static HRESULT WINAPI IPersistStream_fnQueryInterface(
652 IPersistStream* iface,
656 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
658 TRACE("(%p)\n",This);
660 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
663 /************************************************************************
664 * IPersistStream_Release
666 static ULONG WINAPI IPersistStream_fnRelease(
667 IPersistStream* iface)
669 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
671 TRACE("(%p)\n",This);
673 return IShellLinkA_Release((IShellLinkA*)This);
676 /************************************************************************
677 * IPersistStream_AddRef
679 static ULONG WINAPI IPersistStream_fnAddRef(
680 IPersistStream* iface)
682 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
684 TRACE("(%p)\n",This);
686 return IShellLinkA_AddRef((IShellLinkA*)This);
689 /************************************************************************
690 * IPersistStream_GetClassID
693 static HRESULT WINAPI IPersistStream_fnGetClassID(
694 IPersistStream* iface,
697 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
699 TRACE("(%p)\n", This);
704 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
709 /************************************************************************
710 * IPersistStream_IsDirty (IPersistStream)
712 static HRESULT WINAPI IPersistStream_fnIsDirty(
713 IPersistStream* iface)
715 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
717 TRACE("(%p)\n", This);
721 /************************************************************************
722 * IPersistStream_Load (IPersistStream)
725 static HRESULT WINAPI IPersistStream_fnLoad(
726 IPersistStream* iface,
727 IStream* pLoadStream)
729 PLINK_HEADER lpLinkHeader = HeapAlloc(GetProcessHeap(), 0, LINK_HEADER_SIZE);
732 char sTemp[MAX_PATH];
734 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
736 TRACE("(%p)(%p)\n", This, pLoadStream);
740 return STG_E_INVALIDPOINTER;
743 IStream_AddRef (pLoadStream);
746 if (SUCCEEDED(IStream_Read(pLoadStream, lpLinkHeader, LINK_HEADER_SIZE, &dwBytesRead)))
748 if ((lpLinkHeader->MagicStr == 0x0000004CL) && IsEqualIID(&lpLinkHeader->MagicGuid, &CLSID_ShellLink))
750 lpLinkHeader = HeapReAlloc(GetProcessHeap(), 0, lpLinkHeader, LINK_HEADER_SIZE+lpLinkHeader->PidlSize);
753 if (SUCCEEDED(IStream_Read(pLoadStream, &(lpLinkHeader->Pidl), lpLinkHeader->PidlSize, &dwBytesRead)))
755 if (pcheck (&lpLinkHeader->Pidl))
757 This->pPidl = ILClone (&lpLinkHeader->Pidl);
759 SHGetPathFromIDListA(&lpLinkHeader->Pidl, sTemp);
760 This->sPath = HEAP_strdupA ( GetProcessHeap(), 0, sTemp);
762 This->wHotKey = lpLinkHeader->wHotKey;
763 FileTimeToSystemTime (&lpLinkHeader->Time1, &This->time1);
764 FileTimeToSystemTime (&lpLinkHeader->Time2, &This->time2);
765 FileTimeToSystemTime (&lpLinkHeader->Time3, &This->time3);
767 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
768 TRACE("-- time1: %s\n", sTemp);
769 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
770 TRACE("-- time1: %s\n", sTemp);
771 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
772 TRACE("-- time1: %s\n", sTemp);
781 WARN("stream contains no link!\n");
786 IStream_Release (pLoadStream);
790 HeapFree(GetProcessHeap(), 0, lpLinkHeader);
795 /************************************************************************
796 * IPersistStream_Save (IPersistStream)
798 static HRESULT WINAPI IPersistStream_fnSave(
799 IPersistStream* iface,
803 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
805 TRACE("(%p) %p %x\n", This, pOutStream, fClearDirty);
810 /************************************************************************
811 * IPersistStream_GetSizeMax (IPersistStream)
813 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
814 IPersistStream* iface,
815 ULARGE_INTEGER* pcbSize)
817 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
819 TRACE("(%p)\n", This);
824 static ICOM_VTABLE(IPersistStream) psvt =
826 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
827 IPersistStream_fnQueryInterface,
828 IPersistStream_fnAddRef,
829 IPersistStream_fnRelease,
830 IPersistStream_fnGetClassID,
831 IPersistStream_fnIsDirty,
832 IPersistStream_fnLoad,
833 IPersistStream_fnSave,
834 IPersistStream_fnGetSizeMax
837 /**************************************************************************
838 * IShellLink_Constructor
840 IShellLinkA * IShellLink_Constructor(BOOL bUnicode)
841 { IShellLinkImpl * sl;
843 sl = (IShellLinkImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IShellLinkImpl));
845 ICOM_VTBL(sl) = &slvt;
846 sl->lpvtblw = &slvtw;
847 sl->lpvtblPersistFile = &pfvt;
848 sl->lpvtblPersistStream = &psvt;
850 TRACE("(%p)->()\n",sl);
852 return bUnicode ? (IShellLinkA *) &(sl->lpvtblw) : (IShellLinkA *)sl;
855 /**************************************************************************
856 * IShellLinkA_QueryInterface
858 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
860 ICOM_THIS(IShellLinkImpl, iface);
862 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
866 if(IsEqualIID(riid, &IID_IUnknown) ||
867 IsEqualIID(riid, &IID_IShellLinkA))
871 else if(IsEqualIID(riid, &IID_IShellLinkW))
873 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
875 else if(IsEqualIID(riid, &IID_IPersistFile))
877 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
879 else if(IsEqualIID(riid, &IID_IPersistStream))
881 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
886 IUnknown_AddRef((IUnknown*)(*ppvObj));
887 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
890 TRACE("-- Interface: E_NOINTERFACE\n");
891 return E_NOINTERFACE;
893 /******************************************************************************
896 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
898 ICOM_THIS(IShellLinkImpl, iface);
900 TRACE("(%p)->(count=%lu)\n",This,This->ref);
903 return ++(This->ref);
905 /******************************************************************************
906 * IShellLinkA_Release
908 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
910 ICOM_THIS(IShellLinkImpl, iface);
912 TRACE("(%p)->(count=%lu)\n",This,This->ref);
916 { TRACE("-- destroying IShellLink(%p)\n",This);
919 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
922 HeapFree(GetProcessHeap(), 0, This->sArgs);
925 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
927 if (This->sDescription)
928 HeapFree(GetProcessHeap(), 0, This->sDescription);
931 HeapFree(GetProcessHeap(),0,This->sPath);
936 if (This->lpFileStream)
937 IStream_Release(This->lpFileStream);
941 HeapFree(GetProcessHeap(),0,This);
947 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
949 ICOM_THIS(IShellLinkImpl, iface);
951 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",This, pszFile, cchMaxPath, pfd, fFlags, debugstr_a(This->sPath));
954 lstrcpynA(pszFile,This->sPath, cchMaxPath);
960 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
962 ICOM_THIS(IShellLinkImpl, iface);
964 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
966 *ppidl = ILClone(This->pPidl);
969 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
971 ICOM_THIS(IShellLinkImpl, iface);
973 TRACE("(%p)->(pidl=%p)\n",This, pidl);
977 This->pPidl = ILClone (pidl);
980 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
982 ICOM_THIS(IShellLinkImpl, iface);
984 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
985 lstrcpynA(pszName,"Description, FIXME",cchMaxName);
988 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
990 ICOM_THIS(IShellLinkImpl, iface);
992 TRACE("(%p)->(pName=%s)\n", This, pszName);
994 if (This->sDescription)
995 HeapFree(GetProcessHeap(), 0, This->sDescription);
996 if (!(This->sDescription = HEAP_strdupA(GetProcessHeap(), 0, pszName)))
997 return E_OUTOFMEMORY;
1001 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1003 ICOM_THIS(IShellLinkImpl, iface);
1005 FIXME("(%p)->()\n",This);
1006 lstrcpynA(pszDir,"c:\\", cchMaxPath);
1009 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1011 ICOM_THIS(IShellLinkImpl, iface);
1013 TRACE("(%p)->(dir=%s)\n",This, pszDir);
1016 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1017 if (!(This->sWorkDir = HEAP_strdupA(GetProcessHeap(), 0, pszDir)))
1018 return E_OUTOFMEMORY;
1022 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1024 ICOM_THIS(IShellLinkImpl, iface);
1026 FIXME("(%p)->(%p len=%u)\n",This, pszArgs, cchMaxPath);
1027 lstrcpynA(pszArgs, "", cchMaxPath);
1030 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1032 ICOM_THIS(IShellLinkImpl, iface);
1034 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1037 HeapFree(GetProcessHeap(), 0, This->sArgs);
1038 if (!(This->sArgs = HEAP_strdupA(GetProcessHeap(), 0, pszArgs)))
1039 return E_OUTOFMEMORY;
1043 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1045 ICOM_THIS(IShellLinkImpl, iface);
1047 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1049 *pwHotkey = This->wHotKey;
1053 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1055 ICOM_THIS(IShellLinkImpl, iface);
1057 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1059 This->wHotKey = wHotkey;
1063 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1065 ICOM_THIS(IShellLinkImpl, iface);
1067 FIXME("(%p)->(%p)\n",This, piShowCmd);
1071 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1073 ICOM_THIS(IShellLinkImpl, iface);
1075 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1078 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1080 ICOM_THIS(IShellLinkImpl, iface);
1082 FIXME("(%p)->(%p len=%u iicon=%p)\n",This, pszIconPath, cchIconPath, piIcon);
1083 lstrcpynA(pszIconPath,"shell32.dll",cchIconPath);
1087 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1089 ICOM_THIS(IShellLinkImpl, iface);
1091 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1094 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1095 if (!(This->sIcoPath = HEAP_strdupA(GetProcessHeap(), 0, pszIconPath)))
1096 return E_OUTOFMEMORY;
1097 This->iIcoNdx = iIcon;
1101 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1103 ICOM_THIS(IShellLinkImpl, iface);
1105 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1108 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1110 ICOM_THIS(IShellLinkImpl, iface);
1112 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1115 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1117 ICOM_THIS(IShellLinkImpl, iface);
1119 TRACE("(%p)->(path=%s)\n",This, pszFile);
1122 HeapFree(GetProcessHeap(), 0, This->sPath);
1123 if (!(This->sPath = HEAP_strdupA(GetProcessHeap(), 0, pszFile)))
1124 return E_OUTOFMEMORY;
1129 /**************************************************************************
1130 * IShellLink Implementation
1133 static ICOM_VTABLE(IShellLinkA) slvt =
1135 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1136 IShellLinkA_fnQueryInterface,
1137 IShellLinkA_fnAddRef,
1138 IShellLinkA_fnRelease,
1139 IShellLinkA_fnGetPath,
1140 IShellLinkA_fnGetIDList,
1141 IShellLinkA_fnSetIDList,
1142 IShellLinkA_fnGetDescription,
1143 IShellLinkA_fnSetDescription,
1144 IShellLinkA_fnGetWorkingDirectory,
1145 IShellLinkA_fnSetWorkingDirectory,
1146 IShellLinkA_fnGetArguments,
1147 IShellLinkA_fnSetArguments,
1148 IShellLinkA_fnGetHotkey,
1149 IShellLinkA_fnSetHotkey,
1150 IShellLinkA_fnGetShowCmd,
1151 IShellLinkA_fnSetShowCmd,
1152 IShellLinkA_fnGetIconLocation,
1153 IShellLinkA_fnSetIconLocation,
1154 IShellLinkA_fnSetRelativePath,
1155 IShellLinkA_fnResolve,
1156 IShellLinkA_fnSetPath
1160 /**************************************************************************
1161 * IShellLinkW_fnQueryInterface
1163 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1164 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1166 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1168 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1171 /******************************************************************************
1172 * IShellLinkW_fnAddRef
1174 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1176 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1178 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1180 return IShellLinkA_AddRef((IShellLinkA*)This);
1182 /******************************************************************************
1183 * IShellLinkW_fnRelease
1186 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1188 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1190 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1192 return IShellLinkA_Release((IShellLinkA*)This);
1195 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1197 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1199 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1200 lstrcpynAtoW(pszFile,"c:\\foo.bar", cchMaxPath);
1204 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1206 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1208 FIXME("(%p)->(ppidl=%p)\n",This, ppidl);
1209 *ppidl = _ILCreateDesktop();
1213 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1215 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1217 FIXME("(%p)->(pidl=%p)\n",This, pidl);
1221 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1223 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1225 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1226 lstrcpynAtoW(pszName,"Description, FIXME",cchMaxName);
1230 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1232 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1234 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1236 if (This->sDescription)
1237 HeapFree(GetProcessHeap(), 0, This->sDescription);
1238 if (!(This->sDescription = HEAP_strdupWtoA(GetProcessHeap(), 0, pszName)))
1239 return E_OUTOFMEMORY;
1244 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1246 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1248 FIXME("(%p)->()\n",This);
1249 lstrcpynAtoW(pszDir,"c:\\", cchMaxPath);
1253 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1255 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1257 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1260 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1261 if (!(This->sWorkDir = HEAP_strdupWtoA(GetProcessHeap(), 0, pszDir)))
1262 return E_OUTOFMEMORY;
1267 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1269 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1271 FIXME("(%p)->(%p len=%u)\n",This, pszArgs, cchMaxPath);
1272 lstrcpynAtoW(pszArgs, "", cchMaxPath);
1276 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1278 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1280 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1283 HeapFree(GetProcessHeap(), 0, This->sArgs);
1284 if (!(This->sArgs = HEAP_strdupWtoA(GetProcessHeap(), 0, pszArgs)))
1285 return E_OUTOFMEMORY;
1290 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1292 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1294 FIXME("(%p)->(%p)\n",This, pwHotkey);
1299 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1301 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1303 FIXME("(%p)->(hotkey=%x)\n",This, wHotkey);
1307 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1309 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1311 FIXME("(%p)->(%p)\n",This, piShowCmd);
1316 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1318 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1320 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1324 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1326 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1328 FIXME("(%p)->(%p len=%u iicon=%p)\n",This, pszIconPath, cchIconPath, piIcon);
1329 lstrcpynAtoW(pszIconPath,"shell32.dll",cchIconPath);
1334 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1336 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1338 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1341 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1342 if (!(This->sIcoPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszIconPath)))
1343 return E_OUTOFMEMORY;
1344 This->iIcoNdx = iIcon;
1349 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1351 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1353 FIXME("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1357 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1359 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1361 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1365 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1367 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1369 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1372 HeapFree(GetProcessHeap(), 0, This->sPath);
1373 if (!(This->sPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszFile)))
1374 return E_OUTOFMEMORY;
1379 /**************************************************************************
1380 * IShellLinkW Implementation
1383 static ICOM_VTABLE(IShellLinkW) slvtw =
1385 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1386 IShellLinkW_fnQueryInterface,
1387 IShellLinkW_fnAddRef,
1388 IShellLinkW_fnRelease,
1389 IShellLinkW_fnGetPath,
1390 IShellLinkW_fnGetIDList,
1391 IShellLinkW_fnSetIDList,
1392 IShellLinkW_fnGetDescription,
1393 IShellLinkW_fnSetDescription,
1394 IShellLinkW_fnGetWorkingDirectory,
1395 IShellLinkW_fnSetWorkingDirectory,
1396 IShellLinkW_fnGetArguments,
1397 IShellLinkW_fnSetArguments,
1398 IShellLinkW_fnGetHotkey,
1399 IShellLinkW_fnSetHotkey,
1400 IShellLinkW_fnGetShowCmd,
1401 IShellLinkW_fnSetShowCmd,
1402 IShellLinkW_fnGetIconLocation,
1403 IShellLinkW_fnSetIconLocation,
1404 IShellLinkW_fnSetRelativePath,
1405 IShellLinkW_fnResolve,
1406 IShellLinkW_fnSetPath