3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
14 #ifdef HAVE_SYS_WAIT_H
15 # include <sys/wait.h>
17 #include "debugtools.h"
24 #include "wine/undocshell.h"
25 #include "bitmaps/wine.xpm"
29 #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)))
346 TRACE("LoadLibraryExA (%s) failed, error %ld\n", szFileName, GetLastError());
352 hResInfo = FindResourceA(hModule, MAKEINTRESOURCEA(nIndex), RT_GROUP_ICONA);
353 TRACE("FindResourceA (%s) called, return 0x%x, error %ld\n", szFileName, hResInfo, GetLastError());
356 if (EnumResourceNamesA(hModule, RT_GROUP_ICONA, &EnumResNameProc, (LONG) &hResInfo))
358 TRACE("EnumResourceNamesA failed, error %ld\n", GetLastError());
364 TRACE("ExtractFromEXEDLL failed, error %ld\n", GetLastError());
368 if (!(hResData = LoadResource(hModule, hResInfo)))
370 TRACE("LoadResource failed, error %ld\n", GetLastError());
373 if (!(pIconDir = LockResource(hResData)))
375 TRACE("LockResource failed, error %ld\n", GetLastError());
379 for (i = 0; i < pIconDir->idCount; i++)
380 if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax)
382 lpName = MAKEINTRESOURCEA(pIconDir->idEntries[i].nID);
383 nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
386 FreeResource(hResData);
388 if (!(hResInfo = FindResourceA(hModule, lpName, RT_ICONA)))
390 TRACE("Second FindResourceA failed, error %ld\n", GetLastError());
393 if (!(hResData = LoadResource(hModule, hResInfo)))
395 TRACE("Second LoadResource failed, error %ld\n", GetLastError());
398 if (!(pIcon = LockResource(hResData)))
400 TRACE("Second LockResource failed, error %ld\n", GetLastError());
404 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
406 TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
410 FreeResource(hResData);
411 FreeLibrary(hModule);
416 FreeResource(hResData);
418 FreeLibrary(hModule);
423 static int ExtractFromICO(const char *szFileName, const char *szXPMFileName)
427 ICONDIRENTRY *pIconDirEntry;
433 if (!(fICOFile = fopen(szFileName, "r")))
436 if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
438 if ((iconDir.idReserved != 0) || (iconDir.idType != 1))
441 if ((pIconDirEntry = malloc(iconDir.idCount * sizeof (ICONDIRENTRY))) == NULL)
443 if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
446 for (i = 0; i < iconDir.idCount; i++)
447 if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
450 nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
452 if ((pIcon = malloc(pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
454 if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
456 if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
459 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
478 /* get the Unix file name for a given path, allocating the string */
479 inline static char *get_unix_file_name( const char *dos )
481 char buffer[MAX_PATH];
483 if (!wine_get_unix_file_name( dos, buffer, sizeof(buffer) )) return NULL;
484 return HEAP_strdupA( GetProcessHeap(), 0, buffer );
487 static BOOL create_default_icon( const char *filename )
492 if (!(fXPM = fopen(filename, "w"))) return FALSE;
493 fprintf(fXPM, "/* XPM */\nstatic char * icon[] = {");
494 for (i = 0; i < sizeof(wine_xpm)/sizeof(wine_xpm[0]); i++)
495 fprintf( fXPM, "\n\"%s\",", wine_xpm[i]);
496 fprintf( fXPM, "};\n" );
501 /* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
502 static char *extract_icon( const char *path, int index )
504 char *filename = HEAP_strdupA( GetProcessHeap(), 0, tmpnam(NULL) );
505 if (ExtractFromEXEDLL( path, index, filename )) return filename;
506 if (ExtractFromICO( path, filename )) return filename;
507 if (create_default_icon( filename )) return filename;
508 HeapFree( GetProcessHeap(), 0, filename );
513 static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
515 HRESULT ret = NOERROR;
517 char buffer[MAX_PATH], buff2[MAX_PATH];
518 char *filename, *link_name, *p;
519 char *shell_link_app = NULL;
520 char *icon_name = NULL;
521 char *path_name = NULL;
522 char *work_dir = NULL;
526 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
528 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
530 if (!pszFileName || !This->sPath)
531 return ERROR_UNKNOWN;
533 /* check for .exe extension */
534 if (!(p = strrchr( This->sPath, '.' ))) return NOERROR;
535 if (strchr( p, '\\' ) || strchr( p, '/' )) return NOERROR;
536 if (strcasecmp( p, ".exe" )) return NOERROR;
538 /* check if ShellLinker configured */
540 if (!RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine",
541 0, KEY_ALL_ACCESS, &hkey ))
543 DWORD type, count = sizeof(buffer);
544 if (RegQueryValueExA( hkey, "ShellLinker", 0, &type, buffer, &count )) buffer[0] = 0;
547 if (!*buffer) return NOERROR;
548 shell_link_app = HEAP_strdupA( GetProcessHeap(), 0, buffer );
550 if (!WideCharToMultiByte( CP_ACP, 0, pszFileName, -1, buffer, sizeof(buffer), NULL, NULL))
551 return ERROR_UNKNOWN;
552 GetFullPathNameA( buffer, sizeof(buff2), buff2, NULL );
553 filename = HEAP_strdupA( GetProcessHeap(), 0, buff2 );
555 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTUP, FALSE ))
557 /* ignore startup for now */
558 if (!strncasecmp( filename, buffer, strlen(buffer) )) goto done;
560 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_DESKTOPDIRECTORY, FALSE ))
562 if (!strncasecmp( filename, buffer, strlen(buffer) ))
564 link_name = filename + strlen(buffer);
569 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTMENU, FALSE ))
571 if (!strncasecmp( filename, buffer, strlen(buffer) ))
573 link_name = filename + strlen(buffer);
581 /* make link name a Unix name */
582 for (p = link_name; *p; p++) if (*p == '\\') *p = '/';
583 /* strip leading slashes */
584 while (*link_name == '/') link_name++;
585 /* remove extension */
586 if ((p = strrchr( link_name, '.' ))) *p = 0;
588 /* convert app path name */
589 path_name = get_unix_file_name( This->sPath );
591 /* convert app working dir */
592 if (This->sWorkDir) work_dir = get_unix_file_name( This->sWorkDir );
594 /* extract the icon */
595 if (!(icon_name = extract_icon( This->sIcoPath && strlen(This->sIcoPath) ?
596 This->sIcoPath : This->sPath,
597 This->iIcoNdx ))) goto done;
600 TRACE("linker app='%s' link='%s' mode=%s path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
601 shell_link_app, link_name, bDesktop ? "desktop" : "menu", path_name,
602 This->sArgs ? This->sArgs : "", icon_name, work_dir ? work_dir : "",
603 This->sDescription ? This->sDescription : "" );
605 if ((pid = fork()) == -1) goto done;
610 argv[pos++] = shell_link_app;
611 argv[pos++] = "--link";
612 argv[pos++] = link_name;
613 argv[pos++] = "--path";
614 argv[pos++] = path_name;
615 argv[pos++] = bDesktop ? "--desktop" : "--menu";
616 if (This->sArgs && strlen(This->sArgs))
618 argv[pos++] = "--args";
619 argv[pos++] = This->sArgs;
623 argv[pos++] = "--icon";
624 argv[pos++] = icon_name;
626 if (This->sWorkDir && strlen(This->sWorkDir))
628 argv[pos++] = "--workdir";
629 argv[pos++] = This->sWorkDir;
631 if (This->sDescription && strlen(This->sDescription))
633 argv[pos++] = "--descr";
634 argv[pos++] = This->sDescription;
637 execvp( shell_link_app, argv );
641 while (waitpid( pid, &status, 0 ) == -1)
649 if (status) ret = E_ACCESSDENIED;
652 if (icon_name) unlink( icon_name );
653 HeapFree( GetProcessHeap(), 0, shell_link_app );
654 HeapFree( GetProcessHeap(), 0, filename );
655 HeapFree( GetProcessHeap(), 0, icon_name );
656 HeapFree( GetProcessHeap(), 0, path_name );
657 HeapFree( GetProcessHeap(), 0, work_dir );
661 static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
663 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
664 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
667 static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
669 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
670 FIXME("(%p)\n",This);
674 static ICOM_VTABLE(IPersistFile) pfvt =
676 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
677 IPersistFile_fnQueryInterface,
678 IPersistFile_fnAddRef,
679 IPersistFile_fnRelease,
680 IPersistFile_fnGetClassID,
681 IPersistFile_fnIsDirty,
684 IPersistFile_fnSaveCompleted,
685 IPersistFile_fnGetCurFile
688 /************************************************************************
689 * IPersistStream_QueryInterface
691 static HRESULT WINAPI IPersistStream_fnQueryInterface(
692 IPersistStream* iface,
696 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
698 TRACE("(%p)\n",This);
700 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
703 /************************************************************************
704 * IPersistStream_Release
706 static ULONG WINAPI IPersistStream_fnRelease(
707 IPersistStream* iface)
709 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
711 TRACE("(%p)\n",This);
713 return IShellLinkA_Release((IShellLinkA*)This);
716 /************************************************************************
717 * IPersistStream_AddRef
719 static ULONG WINAPI IPersistStream_fnAddRef(
720 IPersistStream* iface)
722 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
724 TRACE("(%p)\n",This);
726 return IShellLinkA_AddRef((IShellLinkA*)This);
729 /************************************************************************
730 * IPersistStream_GetClassID
733 static HRESULT WINAPI IPersistStream_fnGetClassID(
734 IPersistStream* iface,
737 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
739 TRACE("(%p)\n", This);
744 /* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
749 /************************************************************************
750 * IPersistStream_IsDirty (IPersistStream)
752 static HRESULT WINAPI IPersistStream_fnIsDirty(
753 IPersistStream* iface)
755 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
757 TRACE("(%p)\n", This);
761 /************************************************************************
762 * IPersistStream_Load (IPersistStream)
765 static HRESULT WINAPI IPersistStream_fnLoad(
766 IPersistStream* iface,
767 IStream* pLoadStream)
769 PLINK_HEADER lpLinkHeader = HeapAlloc(GetProcessHeap(), 0, LINK_HEADER_SIZE);
772 char sTemp[MAX_PATH];
774 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
776 TRACE("(%p)(%p)\n", This, pLoadStream);
780 return STG_E_INVALIDPOINTER;
783 IStream_AddRef (pLoadStream);
786 if (SUCCEEDED(IStream_Read(pLoadStream, lpLinkHeader, LINK_HEADER_SIZE, &dwBytesRead)))
788 if ((lpLinkHeader->MagicStr == 0x0000004CL) && IsEqualIID(&lpLinkHeader->MagicGuid, &CLSID_ShellLink))
790 lpLinkHeader = HeapReAlloc(GetProcessHeap(), 0, lpLinkHeader, LINK_HEADER_SIZE+lpLinkHeader->PidlSize);
793 if (SUCCEEDED(IStream_Read(pLoadStream, &(lpLinkHeader->Pidl), lpLinkHeader->PidlSize, &dwBytesRead)))
795 if (pcheck (&lpLinkHeader->Pidl))
797 This->pPidl = ILClone (&lpLinkHeader->Pidl);
799 SHGetPathFromIDListA(&lpLinkHeader->Pidl, sTemp);
800 This->sPath = HEAP_strdupA ( GetProcessHeap(), 0, sTemp);
802 This->wHotKey = lpLinkHeader->wHotKey;
803 FileTimeToSystemTime (&lpLinkHeader->Time1, &This->time1);
804 FileTimeToSystemTime (&lpLinkHeader->Time2, &This->time2);
805 FileTimeToSystemTime (&lpLinkHeader->Time3, &This->time3);
807 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
808 TRACE("-- time1: %s\n", sTemp);
809 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
810 TRACE("-- time1: %s\n", sTemp);
811 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
812 TRACE("-- time1: %s\n", sTemp);
821 WARN("stream contains no link!\n");
826 IStream_Release (pLoadStream);
830 HeapFree(GetProcessHeap(), 0, lpLinkHeader);
835 /************************************************************************
836 * IPersistStream_Save (IPersistStream)
838 static HRESULT WINAPI IPersistStream_fnSave(
839 IPersistStream* iface,
843 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
845 TRACE("(%p) %p %x\n", This, pOutStream, fClearDirty);
850 /************************************************************************
851 * IPersistStream_GetSizeMax (IPersistStream)
853 static HRESULT WINAPI IPersistStream_fnGetSizeMax(
854 IPersistStream* iface,
855 ULARGE_INTEGER* pcbSize)
857 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
859 TRACE("(%p)\n", This);
864 static ICOM_VTABLE(IPersistStream) psvt =
866 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
867 IPersistStream_fnQueryInterface,
868 IPersistStream_fnAddRef,
869 IPersistStream_fnRelease,
870 IPersistStream_fnGetClassID,
871 IPersistStream_fnIsDirty,
872 IPersistStream_fnLoad,
873 IPersistStream_fnSave,
874 IPersistStream_fnGetSizeMax
877 /**************************************************************************
878 * IShellLink_Constructor
880 IShellLinkA * IShellLink_Constructor(BOOL bUnicode)
881 { IShellLinkImpl * sl;
883 sl = (IShellLinkImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IShellLinkImpl));
885 ICOM_VTBL(sl) = &slvt;
886 sl->lpvtblw = &slvtw;
887 sl->lpvtblPersistFile = &pfvt;
888 sl->lpvtblPersistStream = &psvt;
890 TRACE("(%p)->()\n",sl);
892 return bUnicode ? (IShellLinkA *) &(sl->lpvtblw) : (IShellLinkA *)sl;
895 /**************************************************************************
896 * IShellLinkA_QueryInterface
898 static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
900 ICOM_THIS(IShellLinkImpl, iface);
902 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
906 if(IsEqualIID(riid, &IID_IUnknown) ||
907 IsEqualIID(riid, &IID_IShellLinkA))
911 else if(IsEqualIID(riid, &IID_IShellLinkW))
913 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
915 else if(IsEqualIID(riid, &IID_IPersistFile))
917 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
919 else if(IsEqualIID(riid, &IID_IPersistStream))
921 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
926 IUnknown_AddRef((IUnknown*)(*ppvObj));
927 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
930 TRACE("-- Interface: E_NOINTERFACE\n");
931 return E_NOINTERFACE;
933 /******************************************************************************
936 static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
938 ICOM_THIS(IShellLinkImpl, iface);
940 TRACE("(%p)->(count=%lu)\n",This,This->ref);
943 return ++(This->ref);
945 /******************************************************************************
946 * IShellLinkA_Release
948 static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
950 ICOM_THIS(IShellLinkImpl, iface);
952 TRACE("(%p)->(count=%lu)\n",This,This->ref);
956 { TRACE("-- destroying IShellLink(%p)\n",This);
959 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
962 HeapFree(GetProcessHeap(), 0, This->sArgs);
965 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
967 if (This->sDescription)
968 HeapFree(GetProcessHeap(), 0, This->sDescription);
971 HeapFree(GetProcessHeap(),0,This->sPath);
976 if (This->lpFileStream)
977 IStream_Release(This->lpFileStream);
981 HeapFree(GetProcessHeap(),0,This);
987 static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
989 ICOM_THIS(IShellLinkImpl, iface);
991 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",This, pszFile, cchMaxPath, pfd, fFlags, debugstr_a(This->sPath));
994 lstrcpynA(pszFile,This->sPath, cchMaxPath);
1000 static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1002 ICOM_THIS(IShellLinkImpl, iface);
1004 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1006 *ppidl = ILClone(This->pPidl);
1009 static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1011 ICOM_THIS(IShellLinkImpl, iface);
1013 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1016 SHFree(This->pPidl);
1017 This->pPidl = ILClone (pidl);
1020 static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1022 ICOM_THIS(IShellLinkImpl, iface);
1024 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1025 lstrcpynA(pszName,"Description, FIXME",cchMaxName);
1028 static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1030 ICOM_THIS(IShellLinkImpl, iface);
1032 TRACE("(%p)->(pName=%s)\n", This, pszName);
1034 if (This->sDescription)
1035 HeapFree(GetProcessHeap(), 0, This->sDescription);
1036 if (!(This->sDescription = HEAP_strdupA(GetProcessHeap(), 0, pszName)))
1037 return E_OUTOFMEMORY;
1041 static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1043 ICOM_THIS(IShellLinkImpl, iface);
1045 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1047 lstrcpynA( pszDir, This->sWorkDir ? This->sWorkDir : "", cchMaxPath );
1051 static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1053 ICOM_THIS(IShellLinkImpl, iface);
1055 TRACE("(%p)->(dir=%s)\n",This, pszDir);
1058 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1059 if (!(This->sWorkDir = HEAP_strdupA(GetProcessHeap(), 0, pszDir)))
1060 return E_OUTOFMEMORY;
1064 static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1066 ICOM_THIS(IShellLinkImpl, iface);
1068 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1070 lstrcpynA( pszArgs, This->sArgs ? This->sArgs : "", cchMaxPath );
1074 static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1076 ICOM_THIS(IShellLinkImpl, iface);
1078 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1081 HeapFree(GetProcessHeap(), 0, This->sArgs);
1082 if (!(This->sArgs = HEAP_strdupA(GetProcessHeap(), 0, pszArgs)))
1083 return E_OUTOFMEMORY;
1087 static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1089 ICOM_THIS(IShellLinkImpl, iface);
1091 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1093 *pwHotkey = This->wHotKey;
1097 static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1099 ICOM_THIS(IShellLinkImpl, iface);
1101 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1103 This->wHotKey = wHotkey;
1107 static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1109 ICOM_THIS(IShellLinkImpl, iface);
1111 FIXME("(%p)->(%p)\n",This, piShowCmd);
1115 static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1117 ICOM_THIS(IShellLinkImpl, iface);
1119 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1122 static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1124 ICOM_THIS(IShellLinkImpl, iface);
1126 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1128 lstrcpynA( pszIconPath, This->sIcoPath ? This->sIcoPath : "", cchIconPath );
1129 *piIcon = This->iIcoNdx;
1133 static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1135 ICOM_THIS(IShellLinkImpl, iface);
1137 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1140 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1141 if (!(This->sIcoPath = HEAP_strdupA(GetProcessHeap(), 0, pszIconPath)))
1142 return E_OUTOFMEMORY;
1143 This->iIcoNdx = iIcon;
1147 static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1149 ICOM_THIS(IShellLinkImpl, iface);
1151 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1154 static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1156 ICOM_THIS(IShellLinkImpl, iface);
1158 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1161 static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1163 ICOM_THIS(IShellLinkImpl, iface);
1165 TRACE("(%p)->(path=%s)\n",This, pszFile);
1168 HeapFree(GetProcessHeap(), 0, This->sPath);
1169 if (!(This->sPath = HEAP_strdupA(GetProcessHeap(), 0, pszFile)))
1170 return E_OUTOFMEMORY;
1175 /**************************************************************************
1176 * IShellLink Implementation
1179 static ICOM_VTABLE(IShellLinkA) slvt =
1181 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1182 IShellLinkA_fnQueryInterface,
1183 IShellLinkA_fnAddRef,
1184 IShellLinkA_fnRelease,
1185 IShellLinkA_fnGetPath,
1186 IShellLinkA_fnGetIDList,
1187 IShellLinkA_fnSetIDList,
1188 IShellLinkA_fnGetDescription,
1189 IShellLinkA_fnSetDescription,
1190 IShellLinkA_fnGetWorkingDirectory,
1191 IShellLinkA_fnSetWorkingDirectory,
1192 IShellLinkA_fnGetArguments,
1193 IShellLinkA_fnSetArguments,
1194 IShellLinkA_fnGetHotkey,
1195 IShellLinkA_fnSetHotkey,
1196 IShellLinkA_fnGetShowCmd,
1197 IShellLinkA_fnSetShowCmd,
1198 IShellLinkA_fnGetIconLocation,
1199 IShellLinkA_fnSetIconLocation,
1200 IShellLinkA_fnSetRelativePath,
1201 IShellLinkA_fnResolve,
1202 IShellLinkA_fnSetPath
1206 /**************************************************************************
1207 * IShellLinkW_fnQueryInterface
1209 static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1210 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1212 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1214 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1217 /******************************************************************************
1218 * IShellLinkW_fnAddRef
1220 static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1222 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1224 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1226 return IShellLinkA_AddRef((IShellLinkA*)This);
1228 /******************************************************************************
1229 * IShellLinkW_fnRelease
1232 static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1234 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1236 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1238 return IShellLinkA_Release((IShellLinkA*)This);
1241 static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1243 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1245 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1246 MultiByteToWideChar( CP_ACP, 0, "c:\\foo.bar", -1, pszFile, cchMaxPath );
1250 static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1252 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1254 FIXME("(%p)->(ppidl=%p)\n",This, ppidl);
1255 *ppidl = _ILCreateDesktop();
1259 static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1261 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1263 FIXME("(%p)->(pidl=%p)\n",This, pidl);
1267 static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1269 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1271 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1272 MultiByteToWideChar( CP_ACP, 0, "Description, FIXME", -1, pszName, cchMaxName );
1276 static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1278 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1280 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1282 if (This->sDescription)
1283 HeapFree(GetProcessHeap(), 0, This->sDescription);
1284 if (!(This->sDescription = HEAP_strdupWtoA(GetProcessHeap(), 0, pszName)))
1285 return E_OUTOFMEMORY;
1290 static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1292 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1294 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1296 MultiByteToWideChar( CP_ACP, 0, This->sWorkDir ? This->sWorkDir : "", -1, pszDir, cchMaxPath );
1301 static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1303 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1305 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1308 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1309 if (!(This->sWorkDir = HEAP_strdupWtoA(GetProcessHeap(), 0, pszDir)))
1310 return E_OUTOFMEMORY;
1315 static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1317 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1319 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1321 MultiByteToWideChar( CP_ACP, 0, This->sArgs ? This->sArgs : "", -1, pszArgs, cchMaxPath );
1326 static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1328 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1330 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1333 HeapFree(GetProcessHeap(), 0, This->sArgs);
1334 if (!(This->sArgs = HEAP_strdupWtoA(GetProcessHeap(), 0, pszArgs)))
1335 return E_OUTOFMEMORY;
1340 static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1342 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1344 FIXME("(%p)->(%p)\n",This, pwHotkey);
1349 static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1351 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1353 FIXME("(%p)->(hotkey=%x)\n",This, wHotkey);
1357 static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1359 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1361 FIXME("(%p)->(%p)\n",This, piShowCmd);
1366 static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1368 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1370 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1374 static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1376 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1378 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1380 MultiByteToWideChar( CP_ACP, 0, This->sIcoPath ? This->sIcoPath : "", -1, pszIconPath, cchIconPath );
1381 *piIcon = This->iIcoNdx;
1386 static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1388 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1390 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1393 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1394 if (!(This->sIcoPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszIconPath)))
1395 return E_OUTOFMEMORY;
1396 This->iIcoNdx = iIcon;
1401 static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1403 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1405 FIXME("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1409 static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1411 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1413 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1417 static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1419 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1421 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1424 HeapFree(GetProcessHeap(), 0, This->sPath);
1425 if (!(This->sPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszFile)))
1426 return E_OUTOFMEMORY;
1431 /**************************************************************************
1432 * IShellLinkW Implementation
1435 static ICOM_VTABLE(IShellLinkW) slvtw =
1437 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1438 IShellLinkW_fnQueryInterface,
1439 IShellLinkW_fnAddRef,
1440 IShellLinkW_fnRelease,
1441 IShellLinkW_fnGetPath,
1442 IShellLinkW_fnGetIDList,
1443 IShellLinkW_fnSetIDList,
1444 IShellLinkW_fnGetDescription,
1445 IShellLinkW_fnSetDescription,
1446 IShellLinkW_fnGetWorkingDirectory,
1447 IShellLinkW_fnSetWorkingDirectory,
1448 IShellLinkW_fnGetArguments,
1449 IShellLinkW_fnSetArguments,
1450 IShellLinkW_fnGetHotkey,
1451 IShellLinkW_fnSetHotkey,
1452 IShellLinkW_fnGetShowCmd,
1453 IShellLinkW_fnSetShowCmd,
1454 IShellLinkW_fnGetIconLocation,
1455 IShellLinkW_fnSetIconLocation,
1456 IShellLinkW_fnSetRelativePath,
1457 IShellLinkW_fnResolve,
1458 IShellLinkW_fnSetPath