source: trunk/src/shell32/shelllink.c@ 10367

Last change on this file since 10367 was 9888, checked in by sandervl, 22 years ago

Shelllink: use kernel32 file functions instead of those from the VAC crt

File size: 45.9 KB
Line 
1/*
2 *
3 * Copyright 1997 Marcus Meissner
4 * Copyright 1998 Juergen Schmied
5 *
6 */
7
8#include "config.h"
9
10#include <string.h>
11#include <sys/stat.h>
12#include <stdio.h>
13#ifndef __WIN32OS2__
14#include <unistd.h>
15#endif
16#include <errno.h>
17#ifdef HAVE_SYS_WAIT_H
18# include <sys/wait.h>
19#endif
20#include "debugtools.h"
21#include "winerror.h"
22#include "winbase.h"
23#include "winnls.h"
24#include "winreg.h"
25
26#include "shlobj.h"
27#include "undocshell.h"
28#ifdef __WIN32OS2__
29#include <winbase.h>
30#define NO_DCDATA
31#include <winuser32.h>
32#include <winres.h>
33#else
34#include "bitmaps/wine.xpm"
35#endif
36
37#include "heap.h"
38#include "pidl.h"
39#include "shell32_main.h"
40#include "shlguid.h"
41
42DEFAULT_DEBUG_CHANNEL(shell);
43
44/* link file formats */
45
46#include "pshpack1.h"
47
48/* flag1: lnk elements: simple link has 0x0B */
49#define WORKDIR 0x10
50#define ARGUMENT 0x20
51#define ICON 0x40
52#define UNC 0x80
53
54/* fStartup */
55#define NORMAL 0x01
56#define MAXIMIZED 0x03
57#define MINIMIZED 0x07
58
59typedef struct _LINK_HEADER
60{ DWORD MagicStr; /* 0x00 'L','\0','\0','\0' */
61 GUID MagicGuid; /* 0x04 is CLSID_ShellLink */
62 DWORD Flag1; /* 0x14 describes elements following */
63 DWORD Flag2; /* 0x18 */
64 FILETIME Time1; /* 0x1c */
65 FILETIME Time2; /* 0x24 */
66 FILETIME Time3; /* 0x2c */
67 DWORD Unknown1; /* 0x34 */
68 DWORD Unknown2; /* 0x38 icon number */
69 DWORD fStartup; /* 0x3c startup type */
70 DWORD wHotKey; /* 0x40 hotkey */
71 DWORD Unknown5; /* 0x44 */
72 DWORD Unknown6; /* 0x48 */
73 USHORT PidlSize; /* 0x4c */
74 ITEMIDLIST Pidl; /* 0x4e */
75} LINK_HEADER, * PLINK_HEADER;
76
77#define LINK_HEADER_SIZE (sizeof(LINK_HEADER)-sizeof(ITEMIDLIST))
78
79typedef struct
80{
81 BYTE bWidth;
82 BYTE bHeight;
83 BYTE bColorCount;
84 BYTE bReserved;
85 WORD wPlanes;
86 WORD wBitCount;
87 DWORD dwBytesInRes;
88 WORD nID;
89} GRPICONDIRENTRY;
90
91typedef struct
92{
93 WORD idReserved;
94 WORD idType;
95 WORD idCount;
96 GRPICONDIRENTRY idEntries[1];
97} GRPICONDIR;
98
99typedef struct
100{
101 BYTE bWidth;
102 BYTE bHeight;
103 BYTE bColorCount;
104 BYTE bReserved;
105 WORD wPlanes;
106 WORD wBitCount;
107 DWORD dwBytesInRes;
108 DWORD dwImageOffset;
109} ICONDIRENTRY;
110
111typedef struct
112{
113 WORD idReserved;
114 WORD idType;
115 WORD idCount;
116} ICONDIR;
117
118
119#include "poppack.h"
120
121typedef struct
122{
123 HRSRC *pResInfo;
124 int nIndex;
125} ENUMRESSTRUCT;
126
127static ICOM_VTABLE(IShellLinkA) slvt;
128static ICOM_VTABLE(IShellLinkW) slvtw;
129static ICOM_VTABLE(IPersistFile) pfvt;
130static ICOM_VTABLE(IPersistStream) psvt;
131
132/* IShellLink Implementation */
133
134typedef struct
135{
136 ICOM_VFIELD(IShellLinkA);
137 DWORD ref;
138
139 ICOM_VTABLE(IShellLinkW)* lpvtblw;
140 ICOM_VTABLE(IPersistFile)* lpvtblPersistFile;
141 ICOM_VTABLE(IPersistStream)* lpvtblPersistStream;
142
143 /* internal stream of the IPersistFile interface */
144 IStream* lpFileStream;
145
146 /* data structures according to the informations in the lnk */
147 LPSTR sPath;
148 LPITEMIDLIST pPidl;
149 WORD wHotKey;
150 SYSTEMTIME time1;
151 SYSTEMTIME time2;
152 SYSTEMTIME time3;
153
154 LPSTR sIcoPath;
155 INT iIcoNdx;
156 LPSTR sArgs;
157 LPSTR sWorkDir;
158 LPSTR sDescription;
159} IShellLinkImpl;
160
161#define _IShellLinkW_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblw)))
162#define _ICOM_THIS_From_IShellLinkW(class, name) class* This = (class*)(((char*)name)-_IShellLinkW_Offset);
163
164#define _IPersistFile_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistFile)))
165#define _ICOM_THIS_From_IPersistFile(class, name) class* This = (class*)(((char*)name)-_IPersistFile_Offset);
166
167#define _IPersistStream_Offset ((int)(&(((IShellLinkImpl*)0)->lpvtblPersistStream)))
168#define _ICOM_THIS_From_IPersistStream(class, name) class* This = (class*)(((char*)name)-_IPersistStream_Offset);
169#define _IPersistStream_From_ICOM_THIS(class, name) class* StreamThis = (class*)(((char*)name)+_IPersistStream_Offset);
170
171
172/* strdup on the process heap */
173inline static LPSTR heap_strdup( LPCSTR str )
174{
175 INT len = strlen(str) + 1;
176 LPSTR p = HeapAlloc( GetProcessHeap(), 0, len );
177 if (p) memcpy( p, str, len );
178 return p;
179}
180
181
182/**************************************************************************
183 * IPersistFile_QueryInterface
184 */
185static HRESULT WINAPI IPersistFile_fnQueryInterface(
186 IPersistFile* iface,
187 REFIID riid,
188 LPVOID *ppvObj)
189{
190 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
191
192 TRACE("(%p)\n",This);
193
194 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
195}
196
197/******************************************************************************
198 * IPersistFile_AddRef
199 */
200static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile* iface)
201{
202 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
203
204 TRACE("(%p)->(count=%lu)\n",This,This->ref);
205
206 return IShellLinkA_AddRef((IShellLinkA*)This);
207}
208/******************************************************************************
209 * IPersistFile_Release
210 */
211static ULONG WINAPI IPersistFile_fnRelease(IPersistFile* iface)
212{
213 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
214
215 TRACE("(%p)->(count=%lu)\n",This,This->ref);
216
217 return IShellLinkA_Release((IShellLinkA*)This);
218}
219
220static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile* iface, CLSID *pClassID)
221{
222 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
223 FIXME("(%p)\n",This);
224 return NOERROR;
225}
226static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile* iface)
227{
228 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
229 FIXME("(%p)\n",This);
230 return NOERROR;
231}
232static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile* iface, LPCOLESTR pszFileName, DWORD dwMode)
233{
234 HRESULT hRet = E_FAIL;
235 LPSTR sFile;
236
237 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface)
238 _IPersistStream_From_ICOM_THIS(IPersistStream, This)
239
240 sFile = HEAP_strdupWtoA ( GetProcessHeap(), 0, pszFileName);
241
242 TRACE("(%p, %s)\n",This, sFile);
243
244
245 if (This->lpFileStream)
246 IStream_Release(This->lpFileStream);
247
248 if SUCCEEDED(CreateStreamOnFile(sFile, &(This->lpFileStream)))
249 {
250 if SUCCEEDED (IPersistStream_Load(StreamThis, This->lpFileStream))
251 {
252 hRet = NOERROR;
253 }
254 }
255
256#ifdef __WIN32OS2__
257 // PH 2001-11-13 memory leak in WINE?
258 HeapFree( GetProcessHeap(), 0, sFile);
259#endif
260
261 return hRet;
262}
263
264
265#ifdef __WIN32OS2__
266static BOOL SaveIconFileAsOS2ICO(char *szFileName, char *szXPMFileName)
267{
268 HFILE fXPMFile = NULL, fICOFile = NULL;
269 void *lpOS2Icon = NULL, *lpWinIcon = NULL;
270 DWORD ressize, filesize;
271 BOOL ret = FALSE;
272
273 if (!(fICOFile = _lopen(szFileName, OF_READ)))
274 goto failure;
275 _llseek(fICOFile, 0, FILE_END);
276 filesize = _llseek(fICOFile, 0, FILE_CURRENT);
277 _llseek(fICOFile, 0, FILE_BEGIN);
278
279 lpWinIcon = malloc(filesize);
280 if(lpWinIcon == NULL) goto failure;
281 if (_lread(fICOFile, lpWinIcon, filesize) != filesize)
282 goto failure;
283
284 if (!(fXPMFile = _lcreat(szXPMFileName, OF_READWRITE)))
285 goto failure;
286
287 lpOS2Icon = ConvertIconGroupIndirect(lpWinIcon, filesize, &ressize);
288 if(lpOS2Icon) {
289 _lwrite(fXPMFile, lpOS2Icon, ressize);
290 }
291 ret = TRUE;
292
293failure:
294 if(fICOFile) _lclose(fICOFile);
295 if(fXPMFile) _lclose(fXPMFile);
296 if(lpWinIcon) free(lpWinIcon);
297 if(lpOS2Icon) free(lpOS2Icon);
298 return ret;
299}
300
301static BOOL SaveIconResAsOS2ICO(GRPICONDIR *pIconDir, HINSTANCE hInstance,
302 const char *szXPMFileName)
303{
304 FILE *fXPMFile;
305 void *lpOS2Icon;
306 DWORD ressize;
307
308 if (!(fXPMFile = fopen(szXPMFileName, "wb")))
309 return 0;
310
311 lpOS2Icon = ConvertIconGroup((void *)pIconDir, hInstance, &ressize);
312 if(lpOS2Icon) {
313 fwrite(lpOS2Icon, 1, ressize, fXPMFile);
314 free(lpOS2Icon);
315 }
316 fclose(fXPMFile);
317 return 1;
318}
319#else
320/* Icon extraction routines
321 *
322 * FIXME: should use PrivateExtractIcons and friends
323 * FIXME: should not use stdio
324 */
325
326static BOOL SaveIconResAsXPM(const BITMAPINFO *pIcon, const char *szXPMFileName)
327{
328 FILE *fXPMFile;
329 int nHeight;
330 int nXORWidthBytes;
331 int nANDWidthBytes;
332 BOOL b8BitColors;
333 int nColors;
334 BYTE *pXOR;
335 BYTE *pAND;
336 BOOL aColorUsed[256] = {0};
337 int nColorsUsed = 0;
338 int i,j;
339
340 if (!((pIcon->bmiHeader.biBitCount == 4) || (pIcon->bmiHeader.biBitCount == 8)))
341 return 0;
342
343 if (!(fXPMFile = fopen(szXPMFileName, "w")))
344 return 0;
345
346 nHeight = pIcon->bmiHeader.biHeight / 2;
347 nXORWidthBytes = 4 * ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount / 32)
348 + ((pIcon->bmiHeader.biWidth * pIcon->bmiHeader.biBitCount % 32) > 0));
349 nANDWidthBytes = 4 * ((pIcon->bmiHeader.biWidth / 32)
350 + ((pIcon->bmiHeader.biWidth % 32) > 0));
351 b8BitColors = pIcon->bmiHeader.biBitCount == 8;
352 nColors = pIcon->bmiHeader.biClrUsed ? pIcon->bmiHeader.biClrUsed
353 : 1 << pIcon->bmiHeader.biBitCount;
354 pXOR = (BYTE*) pIcon + sizeof (BITMAPINFOHEADER) + (nColors * sizeof (RGBQUAD));
355 pAND = pXOR + nHeight * nXORWidthBytes;
356
357#define MASK(x,y) (pAND[(x) / 8 + (nHeight - (y) - 1) * nANDWidthBytes] & (1 << (7 - (x) % 8)))
358#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)
359
360 for (i = 0; i < nHeight; i++)
361 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
362 if (!aColorUsed[COLOR(j,i)] && !MASK(j,i))
363 {
364 aColorUsed[COLOR(j,i)] = TRUE;
365 nColorsUsed++;
366 }
367
368 if (fprintf(fXPMFile, "/* XPM */\nstatic char *icon[] = {\n") <= 0)
369 goto error;
370 if (fprintf(fXPMFile, "\"%d %d %d %d\",\n",
371 (int) pIcon->bmiHeader.biWidth, nHeight, nColorsUsed + 1, 2) <=0)
372 goto error;
373
374 for (i = 0; i < nColors; i++)
375 if (aColorUsed[i])
376 if (fprintf(fXPMFile, "\"%.2X c #%.2X%.2X%.2X\",\n", i, pIcon->bmiColors[i].rgbRed,
377 pIcon->bmiColors[i].rgbGreen, pIcon->bmiColors[i].rgbBlue) <= 0)
378 goto error;
379 if (fprintf(fXPMFile, "\" c None\"") <= 0)
380 goto error;
381
382 for (i = 0; i < nHeight; i++)
383 {
384 if (fprintf(fXPMFile, ",\n\"") <= 0)
385 goto error;
386 for (j = 0; j < pIcon->bmiHeader.biWidth; j++)
387 {
388 if MASK(j,i)
389 {
390 if (fprintf(fXPMFile, " ") <= 0)
391 goto error;
392 }
393 else
394 if (fprintf(fXPMFile, "%.2X", COLOR(j,i)) <= 0)
395 goto error;
396 }
397 if (fprintf(fXPMFile, "\"") <= 0)
398 goto error;
399 }
400 if (fprintf(fXPMFile, "};\n") <= 0)
401 goto error;
402
403#undef MASK
404#undef COLOR
405
406 fclose(fXPMFile);
407 return 1;
408
409 error:
410 fclose(fXPMFile);
411 unlink( szXPMFileName );
412 return 0;
413}
414#endif //__WIN32OS2__
415
416static BOOL CALLBACK EnumResNameProc(HANDLE hModule, const char *lpszType, char *lpszName, LONG lParam)
417{
418 ENUMRESSTRUCT *sEnumRes = (ENUMRESSTRUCT *) lParam;
419
420 if (!sEnumRes->nIndex--)
421 {
422 *sEnumRes->pResInfo = FindResourceA(hModule, lpszName, RT_GROUP_ICONA);
423 return FALSE;
424 }
425 else
426 return TRUE;
427}
428
429
430static int ExtractFromEXEDLL(const char *szFileName, int nIndex, const char *szXPMFileName)
431{
432 HMODULE hModule;
433 HRSRC hResInfo;
434 char *lpName = NULL;
435 HGLOBAL hResData;
436 GRPICONDIR *pIconDir;
437 BITMAPINFO *pIcon;
438 ENUMRESSTRUCT sEnumRes;
439 int nMax = 0;
440 int i;
441
442 if (!(hModule = LoadLibraryExA(szFileName, 0, LOAD_LIBRARY_AS_DATAFILE)))
443 {
444 TRACE("LoadLibraryExA (%s) failed, error %ld\n", szFileName, GetLastError());
445 goto error1;
446 }
447
448 if (nIndex < 0)
449 {
450 hResInfo = FindResourceA(hModule, MAKEINTRESOURCEA(-nIndex), RT_GROUP_ICONA);
451#ifdef __WIN32OS2__
452 if(!hResInfo) {
453 hResInfo = FindResourceA(hModule, MAKEINTRESOURCEA(nIndex), RT_ICONA);
454 if(hResInfo) {
455 GRPICONDIR icondir = {0};
456 BITMAPINFO *bmi;
457
458 bmi = (BITMAPINFO *)LockResource(LoadResource(hModule, hResInfo));
459
460 icondir.idReserved = 0;
461 icondir.idType = 1;
462 icondir.idCount = 1;
463 icondir.idEntries[0].nID = nIndex;
464 icondir.idEntries[0].bHeight = bmi->bmiHeader.biHeight/2;
465 icondir.idEntries[0].bWidth = bmi->bmiHeader.biWidth;
466 icondir.idEntries[0].wBitCount = bmi->bmiHeader.biBitCount;
467
468 if(!SaveIconResAsOS2ICO(&icondir, hModule, szXPMFileName))
469 {
470 TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
471 goto error3;
472 }
473 goto done;
474 }
475 }
476#endif
477 TRACE("FindResourceA (%s) called, return 0x%x, error %ld\n", szFileName, hResInfo, GetLastError());
478 }
479 else
480 {
481 sEnumRes.pResInfo = &hResInfo;
482 sEnumRes.nIndex = nIndex;
483 if (EnumResourceNamesA(hModule, RT_GROUP_ICONA, &EnumResNameProc, (LONG) &sEnumRes))
484 {
485 TRACE("EnumResourceNamesA failed, error %ld\n", GetLastError());
486 goto error2;
487 }
488 }
489
490 if (!hResInfo)
491 {
492 TRACE("ExtractFromEXEDLL failed, error %ld\n", GetLastError());
493 goto error2;
494 }
495
496 if (!(hResData = LoadResource(hModule, hResInfo)))
497 {
498 TRACE("LoadResource failed, error %ld\n", GetLastError());
499 goto error2;
500 }
501 if (!(pIconDir = LockResource(hResData)))
502 {
503 TRACE("LockResource failed, error %ld\n", GetLastError());
504 goto error3;
505 }
506
507#ifdef __WIN32OS2__
508 if(!SaveIconResAsOS2ICO(pIconDir, hModule, szXPMFileName))
509 {
510 TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
511 goto error3;
512 }
513#else
514 for (i = 0; i < pIconDir->idCount; i++)
515 if ((pIconDir->idEntries[i].wBitCount >= nMaxBits) && (pIconDir->idEntries[i].wBitCount <= 8))
516 {
517 if (pIconDir->idEntries[i].wBitCount > nMaxBits)
518 {
519 nMaxBits = pIconDir->idEntries[i].wBitCount;
520 nMax = 0;
521 }
522 if ((pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth) > nMax)
523 {
524 lpName = MAKEINTRESOURCEA(pIconDir->idEntries[i].nID);
525 nMax = pIconDir->idEntries[i].bHeight * pIconDir->idEntries[i].bWidth;
526 }
527 }
528
529 FreeResource(hResData);
530
531 if (!(hResInfo = FindResourceA(hModule, lpName, RT_ICONA)))
532 {
533 TRACE("Second FindResourceA failed, error %ld\n", GetLastError());
534 goto error2;
535 }
536 if (!(hResData = LoadResource(hModule, hResInfo)))
537 {
538 TRACE("Second LoadResource failed, error %ld\n", GetLastError());
539 goto error2;
540 }
541 if (!(pIcon = LockResource(hResData)))
542 {
543 TRACE("Second LockResource failed, error %ld\n", GetLastError());
544 goto error3;
545 }
546
547 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
548 {
549 TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
550 goto error3;
551 }
552#endif
553
554done:
555
556 FreeResource(hResData);
557 FreeLibrary(hModule);
558
559 return 1;
560
561 error3:
562 FreeResource(hResData);
563 error2:
564 FreeLibrary(hModule);
565 error1:
566 return 0;
567}
568
569static int ExtractFromICO(const char *szFileName, const char *szXPMFileName)
570{
571#ifdef __WIN32OS2__
572 if(!SaveIconFileAsOS2ICO(szFileName, szXPMFileName))
573 {
574 TRACE("Failed saving icon as XPM, error %ld\n", GetLastError());
575 return 0;
576 }
577 return 1;
578#else
579 FILE *fICOFile;
580 ICONDIR iconDir;
581 ICONDIRENTRY *pIconDirEntry;
582 int nMax = 0;
583 int nIndex = 0;
584 void *pIcon;
585 int i;
586
587 if (!(fICOFile = fopen(szFileName, "r")))
588 goto error1;
589
590 if (fread(&iconDir, sizeof (ICONDIR), 1, fICOFile) != 1)
591 goto error2;
592 if ((iconDir.idReserved != 0) || (iconDir.idType != 1))
593 goto error2;
594
595 if ((pIconDirEntry = malloc(iconDir.idCount * sizeof (ICONDIRENTRY))) == NULL)
596 goto error2;
597 if (fread(pIconDirEntry, sizeof (ICONDIRENTRY), iconDir.idCount, fICOFile) != iconDir.idCount)
598 goto error3;
599
600 for (i = 0; i < iconDir.idCount; i++)
601 if ((pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth) > nMax)
602 {
603 nIndex = i;
604 nMax = pIconDirEntry[i].bHeight * pIconDirEntry[i].bWidth;
605 }
606 if ((pIcon = malloc(pIconDirEntry[nIndex].dwBytesInRes)) == NULL)
607 goto error3;
608 if (fseek(fICOFile, pIconDirEntry[nIndex].dwImageOffset, SEEK_SET))
609 goto error4;
610 if (fread(pIcon, pIconDirEntry[nIndex].dwBytesInRes, 1, fICOFile) != 1)
611 goto error4;
612
613 if(!SaveIconResAsXPM(pIcon, szXPMFileName))
614 goto error4;
615
616 free(pIcon);
617 free(pIconDirEntry);
618 fclose(fICOFile);
619
620 return 1;
621
622 error4:
623 free(pIcon);
624 error3:
625 free(pIconDirEntry);
626 error2:
627 fclose(fICOFile);
628 error1:
629 return 0;
630#endif
631}
632
633#ifndef __WIN32OS2__
634/* get the Unix file name for a given path, allocating the string */
635inline static char *get_unix_file_name( const char *dos )
636{
637 char buffer[MAX_PATH];
638
639 if (!wine_get_unix_file_name( dos, buffer, sizeof(buffer) )) return NULL;
640 return heap_strdup( buffer );
641}
642
643static BOOL create_default_icon( const char *filename )
644{
645 FILE *fXPM;
646 int i;
647
648 if (!(fXPM = fopen(filename, "w"))) return FALSE;
649 fprintf(fXPM, "/* XPM */\nstatic char * icon[] = {");
650 for (i = 0; i < sizeof(wine_xpm)/sizeof(wine_xpm[0]); i++)
651 fprintf( fXPM, "\n\"%s\",", wine_xpm[i]);
652 fprintf( fXPM, "};\n" );
653 fclose( fXPM );
654 return TRUE;
655}
656#endif //__WIN32OS2__
657
658/* extract an icon from an exe or icon file; helper for IPersistFile_fnSave */
659#ifdef __WIN32OS2__
660static char *extract_icon( const char *path, char *filename, int index)
661{
662 if (ExtractFromEXEDLL( path, index, filename )) return filename;
663 if (ExtractFromICO( path, filename )) return filename;
664 return NULL;
665}
666#else
667static char *extract_icon( const char *path, int index)
668{
669 char *filename = heap_strdup( tmpnam(NULL) );
670 if (ExtractFromEXEDLL( path, index, filename )) return filename;
671 if (ExtractFromICO( path, filename )) return filename;
672 if (create_default_icon( filename )) return filename;
673 HeapFree( GetProcessHeap(), 0, filename );
674 return NULL;
675}
676#endif
677
678
679static HRESULT WINAPI IPersistFile_fnSave(IPersistFile* iface, LPCOLESTR pszFileName, BOOL fRemember)
680{
681 HRESULT ret = NOERROR;
682 int pid, status;
683 char buffer[MAX_PATH], buff2[MAX_PATH];
684 char *filename, *link_name, *p;
685 char *shell_link_app = NULL;
686 char *icon_name = NULL;
687 char *path_name = NULL;
688 char *work_dir = NULL;
689 BOOL bDesktop;
690 HKEY hkey;
691#ifdef __WIN32OS2__
692 char *tmp, szAppName[MAX_PATH];
693#endif
694
695 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
696
697 TRACE("(%p)->(%s)\n",This,debugstr_w(pszFileName));
698
699 if (!pszFileName || !This->sPath)
700 return ERROR_UNKNOWN;
701
702 /* check if ShellLinker configured */
703#ifdef __WIN32OS2__
704 dprintf(("IPersistFile_fnSave %ls", pszFileName));
705 filename = link_name = NULL;
706 bDesktop = 0;
707
708 if (!WideCharToMultiByte( CP_ACP, 0, pszFileName, -1, buffer, sizeof(buffer), NULL, NULL))
709 return ERROR_UNKNOWN;
710 GetFullPathNameA( buffer, sizeof(buff2), buff2, NULL );
711 filename = HEAP_strdupA( GetProcessHeap(), 0, buff2 );
712
713 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTUP, FALSE ))
714 {
715 /* ignore startup for now */
716 if (!strncasecmp( filename, buffer, strlen(buffer) )) goto done;
717 }
718 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_DESKTOPDIRECTORY, FALSE ))
719 {
720 if (!strncasecmp( filename, buffer, strlen(buffer) ))
721 {
722 link_name = filename + strlen(buffer);
723 bDesktop = TRUE;
724 goto found;
725 }
726 }
727 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTMENU, FALSE ))
728 {
729 if (!strncasecmp( filename, buffer, strlen(buffer) ))
730 {
731 link_name = filename + strlen(buffer);
732 bDesktop = FALSE;
733 goto found;
734 }
735 }
736 goto done;
737
738 found:
739
740 icon_name = HEAP_strdupA( GetProcessHeap(), 0, filename );
741 strupr(icon_name);
742 tmp = strstr(icon_name, ".LNK");
743 if(!tmp) {
744 dprintf(("ERROR: Unexpected name %s", icon_name));
745 goto done;
746 }
747 tmp[1] = 'I';
748 tmp[2] = 'C';
749 tmp[3] = 'O';
750 /* extract the icon */
751 if (!extract_icon( This->sIcoPath && strlen(This->sIcoPath) ?
752 This->sIcoPath : This->sPath,
753 icon_name, This->iIcoNdx)) goto done;
754
755 if(SearchPathA( NULL, This->sPath, ".exe", sizeof(szAppName), szAppName, NULL) == NULL)
756 {
757 ret = E_INVALIDARG;
758 goto done;
759 }
760
761 if(OSLibWinCreateObject(szAppName, This->sArgs, This->sWorkDir, filename,
762 This->sDescription, icon_name,
763 This->iIcoNdx, bDesktop) == FALSE)
764 {
765 ret = E_ACCESSDENIED;
766 }
767
768 done:
769 if(shell_link_app) HeapFree( GetProcessHeap(), 0, shell_link_app );
770 if(filename) HeapFree( GetProcessHeap(), 0, filename );
771 if(icon_name) HeapFree( GetProcessHeap(), 0, icon_name );
772 if(path_name) HeapFree( GetProcessHeap(), 0, path_name );
773 if(work_dir) HeapFree( GetProcessHeap(), 0, work_dir );
774 return ret;
775
776#else
777
778 /* check for .exe extension */
779 if (!(p = strrchr( This->sPath, '.' ))) return NOERROR;
780 if (strchr( p, '\\' ) || strchr( p, '/' )) return NOERROR;
781 if (strcasecmp( p, ".exe" )) return NOERROR;
782
783 buffer[0] = 0;
784 if (!RegOpenKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\Wine",
785 0, KEY_ALL_ACCESS, &hkey ))
786 {
787 DWORD type, count = sizeof(buffer);
788 if (RegQueryValueExA( hkey, "ShellLinker", 0, &type, buffer, &count )) buffer[0] = 0;
789 RegCloseKey( hkey );
790 }
791 if (!*buffer) return NOERROR;
792 shell_link_app = heap_strdup( buffer );
793
794 if (!WideCharToMultiByte( CP_ACP, 0, pszFileName, -1, buffer, sizeof(buffer), NULL, NULL))
795 return ERROR_UNKNOWN;
796 GetFullPathNameA( buffer, sizeof(buff2), buff2, NULL );
797 filename = heap_strdup( buff2 );
798
799 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTUP, FALSE ))
800 {
801 /* ignore startup for now */
802 if (!strncasecmp( filename, buffer, strlen(buffer) )) goto done;
803 }
804 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_DESKTOPDIRECTORY, FALSE ))
805 {
806 if (!strncasecmp( filename, buffer, strlen(buffer) ))
807 {
808 link_name = filename + strlen(buffer);
809 bDesktop = TRUE;
810 goto found;
811 }
812 }
813 if (SHGetSpecialFolderPathA( 0, buffer, CSIDL_STARTMENU, FALSE ))
814 {
815 if (!strncasecmp( filename, buffer, strlen(buffer) ))
816 {
817 link_name = filename + strlen(buffer);
818 bDesktop = FALSE;
819 goto found;
820 }
821 }
822 goto done;
823
824 found:
825 /* make link name a Unix name */
826 for (p = link_name; *p; p++) if (*p == '\\') *p = '/';
827 /* strip leading slashes */
828 while (*link_name == '/') link_name++;
829 /* remove extension */
830 if ((p = strrchr( link_name, '.' ))) *p = 0;
831
832 /* convert app path name */
833 path_name = get_unix_file_name( This->sPath );
834
835 /* convert app working dir */
836 if (This->sWorkDir) work_dir = get_unix_file_name( This->sWorkDir );
837
838 /* extract the icon */
839 if (!(icon_name = extract_icon( This->sIcoPath && strlen(This->sIcoPath) ?
840 This->sIcoPath : This->sPath,
841 This->iIcoNdx ))) goto done;
842
843
844 TRACE("linker app='%s' link='%s' mode=%s path='%s' args='%s' icon='%s' workdir='%s' descr='%s'\n",
845 shell_link_app, link_name, bDesktop ? "desktop" : "menu", path_name,
846 This->sArgs ? This->sArgs : "", icon_name, work_dir ? work_dir : "",
847 This->sDescription ? This->sDescription : "" );
848
849 if ((pid = fork()) == -1) goto done;
850 if (!pid)
851 {
852 int pos = 0;
853 char *argv[20];
854 argv[pos++] = shell_link_app;
855 argv[pos++] = "--link";
856 argv[pos++] = link_name;
857 argv[pos++] = "--path";
858 argv[pos++] = path_name;
859 argv[pos++] = bDesktop ? "--desktop" : "--menu";
860 if (This->sArgs && strlen(This->sArgs))
861 {
862 argv[pos++] = "--args";
863 argv[pos++] = This->sArgs;
864 }
865 if (icon_name)
866 {
867 argv[pos++] = "--icon";
868 argv[pos++] = icon_name;
869 }
870 if (This->sWorkDir && strlen(This->sWorkDir))
871 {
872 argv[pos++] = "--workdir";
873 argv[pos++] = This->sWorkDir;
874 }
875 if (This->sDescription && strlen(This->sDescription))
876 {
877 argv[pos++] = "--descr";
878 argv[pos++] = This->sDescription;
879 }
880 argv[pos] = NULL;
881 execvp( shell_link_app, argv );
882 _exit(1);
883 }
884
885 while (waitpid( pid, &status, 0 ) == -1)
886 {
887 if (errno != EINTR)
888 {
889 ret = ERROR_UNKNOWN;
890 goto done;
891 }
892 }
893 if (status) ret = E_ACCESSDENIED;
894
895 done:
896 if (icon_name) unlink( icon_name );
897 HeapFree( GetProcessHeap(), 0, shell_link_app );
898 HeapFree( GetProcessHeap(), 0, filename );
899 HeapFree( GetProcessHeap(), 0, icon_name );
900 HeapFree( GetProcessHeap(), 0, path_name );
901 HeapFree( GetProcessHeap(), 0, work_dir );
902 return ret;
903#endif
904}
905
906static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile* iface, LPCOLESTR pszFileName)
907{
908 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
909 FIXME("(%p)->(%s)\n",This,debugstr_w(pszFileName));
910 return NOERROR;
911}
912static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile* iface, LPOLESTR *ppszFileName)
913{
914 _ICOM_THIS_From_IPersistFile(IShellLinkImpl, iface);
915 FIXME("(%p)\n",This);
916 return NOERROR;
917}
918
919static ICOM_VTABLE(IPersistFile) pfvt =
920{
921 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
922 IPersistFile_fnQueryInterface,
923 IPersistFile_fnAddRef,
924 IPersistFile_fnRelease,
925 IPersistFile_fnGetClassID,
926 IPersistFile_fnIsDirty,
927 IPersistFile_fnLoad,
928 IPersistFile_fnSave,
929 IPersistFile_fnSaveCompleted,
930 IPersistFile_fnGetCurFile
931};
932
933/************************************************************************
934 * IPersistStream_QueryInterface
935 */
936static HRESULT WINAPI IPersistStream_fnQueryInterface(
937 IPersistStream* iface,
938 REFIID riid,
939 VOID** ppvoid)
940{
941 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
942
943 TRACE("(%p)\n",This);
944
945 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvoid);
946}
947
948/************************************************************************
949 * IPersistStream_Release
950 */
951static ULONG WINAPI IPersistStream_fnRelease(
952 IPersistStream* iface)
953{
954 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
955
956 TRACE("(%p)\n",This);
957
958 return IShellLinkA_Release((IShellLinkA*)This);
959}
960
961/************************************************************************
962 * IPersistStream_AddRef
963 */
964static ULONG WINAPI IPersistStream_fnAddRef(
965 IPersistStream* iface)
966{
967 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
968
969 TRACE("(%p)\n",This);
970
971 return IShellLinkA_AddRef((IShellLinkA*)This);
972}
973
974/************************************************************************
975 * IPersistStream_GetClassID
976 *
977 */
978static HRESULT WINAPI IPersistStream_fnGetClassID(
979 IPersistStream* iface,
980 CLSID* pClassID)
981{
982 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
983
984 TRACE("(%p)\n", This);
985
986 if (pClassID==0)
987 return E_POINTER;
988
989/* memcpy(pClassID, &CLSID_???, sizeof(CLSID_???)); */
990
991 return S_OK;
992}
993
994/************************************************************************
995 * IPersistStream_IsDirty (IPersistStream)
996 */
997static HRESULT WINAPI IPersistStream_fnIsDirty(
998 IPersistStream* iface)
999{
1000 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
1001
1002 TRACE("(%p)\n", This);
1003
1004 return S_OK;
1005}
1006/************************************************************************
1007 * IPersistStream_Load (IPersistStream)
1008 */
1009
1010static HRESULT WINAPI IPersistStream_fnLoad(
1011 IPersistStream* iface,
1012 IStream* pLoadStream)
1013{
1014 PLINK_HEADER lpLinkHeader = HeapAlloc(GetProcessHeap(), 0, LINK_HEADER_SIZE);
1015 ULONG dwBytesRead;
1016 DWORD ret = E_FAIL;
1017 char sTemp[MAX_PATH];
1018
1019 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
1020
1021 TRACE("(%p)(%p)\n", This, pLoadStream);
1022
1023 if ( ! pLoadStream)
1024 {
1025 return STG_E_INVALIDPOINTER;
1026 }
1027
1028 IStream_AddRef (pLoadStream);
1029 if(lpLinkHeader)
1030 {
1031 if (SUCCEEDED(IStream_Read(pLoadStream, lpLinkHeader, LINK_HEADER_SIZE, &dwBytesRead)))
1032 {
1033 if ((lpLinkHeader->MagicStr == 0x0000004CL) && IsEqualIID(&lpLinkHeader->MagicGuid, &CLSID_ShellLink))
1034 {
1035 lpLinkHeader = HeapReAlloc(GetProcessHeap(), 0, lpLinkHeader, LINK_HEADER_SIZE+lpLinkHeader->PidlSize);
1036 if (lpLinkHeader)
1037 {
1038 if (SUCCEEDED(IStream_Read(pLoadStream, &(lpLinkHeader->Pidl), lpLinkHeader->PidlSize, &dwBytesRead)))
1039 {
1040 if (pcheck (&lpLinkHeader->Pidl))
1041 {
1042 This->pPidl = ILClone (&lpLinkHeader->Pidl);
1043
1044 SHGetPathFromIDListA(&lpLinkHeader->Pidl, sTemp);
1045 This->sPath = heap_strdup( sTemp );
1046 }
1047 This->wHotKey = lpLinkHeader->wHotKey;
1048 FileTimeToSystemTime (&lpLinkHeader->Time1, &This->time1);
1049 FileTimeToSystemTime (&lpLinkHeader->Time2, &This->time2);
1050 FileTimeToSystemTime (&lpLinkHeader->Time3, &This->time3);
1051#if 1
1052 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time1, NULL, sTemp, 256);
1053 TRACE("-- time1: %s\n", sTemp);
1054 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time2, NULL, sTemp, 256);
1055 TRACE("-- time1: %s\n", sTemp);
1056 GetDateFormatA(LOCALE_USER_DEFAULT,DATE_SHORTDATE,&This->time3, NULL, sTemp, 256);
1057 TRACE("-- time1: %s\n", sTemp);
1058 pdump (This->pPidl);
1059#endif
1060 ret = S_OK;
1061 }
1062 }
1063 }
1064 else
1065 {
1066 WARN("stream contains no link!\n");
1067 }
1068 }
1069 }
1070
1071 IStream_Release (pLoadStream);
1072
1073 pdump(This->pPidl);
1074
1075 HeapFree(GetProcessHeap(), 0, lpLinkHeader);
1076
1077 return ret;
1078}
1079
1080/************************************************************************
1081 * IPersistStream_Save (IPersistStream)
1082 */
1083static HRESULT WINAPI IPersistStream_fnSave(
1084 IPersistStream* iface,
1085 IStream* pOutStream,
1086 BOOL fClearDirty)
1087{
1088 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
1089
1090 TRACE("(%p) %p %x\n", This, pOutStream, fClearDirty);
1091
1092 return E_NOTIMPL;
1093}
1094
1095/************************************************************************
1096 * IPersistStream_GetSizeMax (IPersistStream)
1097 */
1098static HRESULT WINAPI IPersistStream_fnGetSizeMax(
1099 IPersistStream* iface,
1100 ULARGE_INTEGER* pcbSize)
1101{
1102 _ICOM_THIS_From_IPersistStream(IShellLinkImpl, iface);
1103
1104 TRACE("(%p)\n", This);
1105
1106 return E_NOTIMPL;
1107}
1108
1109static ICOM_VTABLE(IPersistStream) psvt =
1110{
1111 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1112 IPersistStream_fnQueryInterface,
1113 IPersistStream_fnAddRef,
1114 IPersistStream_fnRelease,
1115 IPersistStream_fnGetClassID,
1116 IPersistStream_fnIsDirty,
1117 IPersistStream_fnLoad,
1118 IPersistStream_fnSave,
1119 IPersistStream_fnGetSizeMax
1120};
1121
1122/**************************************************************************
1123 * IShellLink_Constructor
1124 */
1125IShellLinkA * IShellLink_Constructor(BOOL bUnicode)
1126{ IShellLinkImpl * sl;
1127
1128 sl = (IShellLinkImpl *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IShellLinkImpl));
1129 sl->ref = 1;
1130 ICOM_VTBL(sl) = &slvt;
1131 sl->lpvtblw = &slvtw;
1132 sl->lpvtblPersistFile = &pfvt;
1133 sl->lpvtblPersistStream = &psvt;
1134
1135 TRACE("(%p)->()\n",sl);
1136 shell32_ObjCount++;
1137 return bUnicode ? (IShellLinkA *) &(sl->lpvtblw) : (IShellLinkA *)sl;
1138}
1139
1140/**************************************************************************
1141 * IShellLinkA_QueryInterface
1142 */
1143static HRESULT WINAPI IShellLinkA_fnQueryInterface( IShellLinkA * iface, REFIID riid, LPVOID *ppvObj)
1144{
1145 ICOM_THIS(IShellLinkImpl, iface);
1146
1147 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
1148
1149 *ppvObj = NULL;
1150
1151 if(IsEqualIID(riid, &IID_IUnknown) ||
1152 IsEqualIID(riid, &IID_IShellLinkA))
1153 {
1154 *ppvObj = This;
1155 }
1156 else if(IsEqualIID(riid, &IID_IShellLinkW))
1157 {
1158 *ppvObj = (IShellLinkW *)&(This->lpvtblw);
1159 }
1160 else if(IsEqualIID(riid, &IID_IPersistFile))
1161 {
1162 *ppvObj = (IPersistFile *)&(This->lpvtblPersistFile);
1163 }
1164 else if(IsEqualIID(riid, &IID_IPersistStream))
1165 {
1166 *ppvObj = (IPersistStream *)&(This->lpvtblPersistStream);
1167 }
1168
1169 if(*ppvObj)
1170 {
1171 IUnknown_AddRef((IUnknown*)(*ppvObj));
1172 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
1173 return S_OK;
1174 }
1175 TRACE("-- Interface: E_NOINTERFACE\n");
1176 return E_NOINTERFACE;
1177}
1178/******************************************************************************
1179 * IShellLinkA_AddRef
1180 */
1181static ULONG WINAPI IShellLinkA_fnAddRef(IShellLinkA * iface)
1182{
1183 ICOM_THIS(IShellLinkImpl, iface);
1184
1185 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1186
1187 shell32_ObjCount++;
1188 return ++(This->ref);
1189}
1190/******************************************************************************
1191 * IShellLinkA_Release
1192 */
1193static ULONG WINAPI IShellLinkA_fnRelease(IShellLinkA * iface)
1194{
1195 ICOM_THIS(IShellLinkImpl, iface);
1196
1197 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1198
1199 shell32_ObjCount--;
1200 if (!--(This->ref))
1201 { TRACE("-- destroying IShellLink(%p)\n",This);
1202
1203 if (This->sIcoPath)
1204 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1205
1206 if (This->sArgs)
1207 HeapFree(GetProcessHeap(), 0, This->sArgs);
1208
1209 if (This->sWorkDir)
1210 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1211
1212 if (This->sDescription)
1213 HeapFree(GetProcessHeap(), 0, This->sDescription);
1214
1215 if (This->sPath)
1216 HeapFree(GetProcessHeap(),0,This->sPath);
1217
1218 if (This->pPidl)
1219 SHFree(This->pPidl);
1220
1221 if (This->lpFileStream)
1222 IStream_Release(This->lpFileStream);
1223
1224 This->iIcoNdx = 0;
1225
1226 HeapFree(GetProcessHeap(),0,This);
1227 return 0;
1228 }
1229 return This->ref;
1230}
1231
1232static HRESULT WINAPI IShellLinkA_fnGetPath(IShellLinkA * iface, LPSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1233{
1234 ICOM_THIS(IShellLinkImpl, iface);
1235
1236 TRACE("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)(%s)\n",This, pszFile, cchMaxPath, pfd, fFlags, debugstr_a(This->sPath));
1237
1238 if (This->sPath)
1239 lstrcpynA(pszFile,This->sPath, cchMaxPath);
1240 else
1241 return E_FAIL;
1242
1243 return NOERROR;
1244}
1245static HRESULT WINAPI IShellLinkA_fnGetIDList(IShellLinkA * iface, LPITEMIDLIST * ppidl)
1246{
1247 ICOM_THIS(IShellLinkImpl, iface);
1248
1249 TRACE("(%p)->(ppidl=%p)\n",This, ppidl);
1250
1251 *ppidl = ILClone(This->pPidl);
1252 return NOERROR;
1253}
1254static HRESULT WINAPI IShellLinkA_fnSetIDList(IShellLinkA * iface, LPCITEMIDLIST pidl)
1255{
1256 ICOM_THIS(IShellLinkImpl, iface);
1257
1258 TRACE("(%p)->(pidl=%p)\n",This, pidl);
1259
1260 if (This->pPidl)
1261 SHFree(This->pPidl);
1262 This->pPidl = ILClone (pidl);
1263 return NOERROR;
1264}
1265static HRESULT WINAPI IShellLinkA_fnGetDescription(IShellLinkA * iface, LPSTR pszName,INT cchMaxName)
1266{
1267 ICOM_THIS(IShellLinkImpl, iface);
1268
1269 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1270 lstrcpynA(pszName,"Description, FIXME",cchMaxName);
1271 return NOERROR;
1272}
1273static HRESULT WINAPI IShellLinkA_fnSetDescription(IShellLinkA * iface, LPCSTR pszName)
1274{
1275 ICOM_THIS(IShellLinkImpl, iface);
1276
1277 TRACE("(%p)->(pName=%s)\n", This, pszName);
1278
1279 if (This->sDescription)
1280 HeapFree(GetProcessHeap(), 0, This->sDescription);
1281 if (!(This->sDescription = heap_strdup(pszName)))
1282 return E_OUTOFMEMORY;
1283
1284 return NOERROR;
1285}
1286static HRESULT WINAPI IShellLinkA_fnGetWorkingDirectory(IShellLinkA * iface, LPSTR pszDir,INT cchMaxPath)
1287{
1288 ICOM_THIS(IShellLinkImpl, iface);
1289
1290 TRACE("(%p)->(%p len=%u)\n", This, pszDir, cchMaxPath);
1291
1292 lstrcpynA( pszDir, This->sWorkDir ? This->sWorkDir : "", cchMaxPath );
1293
1294 return NOERROR;
1295}
1296static HRESULT WINAPI IShellLinkA_fnSetWorkingDirectory(IShellLinkA * iface, LPCSTR pszDir)
1297{
1298 ICOM_THIS(IShellLinkImpl, iface);
1299
1300 TRACE("(%p)->(dir=%s)\n",This, pszDir);
1301
1302 if (This->sWorkDir)
1303 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1304 if (!(This->sWorkDir = heap_strdup(pszDir)))
1305 return E_OUTOFMEMORY;
1306
1307 return NOERROR;
1308}
1309static HRESULT WINAPI IShellLinkA_fnGetArguments(IShellLinkA * iface, LPSTR pszArgs,INT cchMaxPath)
1310{
1311 ICOM_THIS(IShellLinkImpl, iface);
1312
1313 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1314
1315 lstrcpynA( pszArgs, This->sArgs ? This->sArgs : "", cchMaxPath );
1316
1317 return NOERROR;
1318}
1319static HRESULT WINAPI IShellLinkA_fnSetArguments(IShellLinkA * iface, LPCSTR pszArgs)
1320{
1321 ICOM_THIS(IShellLinkImpl, iface);
1322
1323 TRACE("(%p)->(args=%s)\n",This, pszArgs);
1324
1325 if (This->sArgs)
1326 HeapFree(GetProcessHeap(), 0, This->sArgs);
1327 if (!(This->sArgs = heap_strdup(pszArgs)))
1328 return E_OUTOFMEMORY;
1329
1330 return NOERROR;
1331}
1332static HRESULT WINAPI IShellLinkA_fnGetHotkey(IShellLinkA * iface, WORD *pwHotkey)
1333{
1334 ICOM_THIS(IShellLinkImpl, iface);
1335
1336 TRACE("(%p)->(%p)(0x%08x)\n",This, pwHotkey, This->wHotKey);
1337
1338 *pwHotkey = This->wHotKey;
1339
1340 return NOERROR;
1341}
1342static HRESULT WINAPI IShellLinkA_fnSetHotkey(IShellLinkA * iface, WORD wHotkey)
1343{
1344 ICOM_THIS(IShellLinkImpl, iface);
1345
1346 TRACE("(%p)->(hotkey=%x)\n",This, wHotkey);
1347
1348 This->wHotKey = wHotkey;
1349
1350 return NOERROR;
1351}
1352static HRESULT WINAPI IShellLinkA_fnGetShowCmd(IShellLinkA * iface, INT *piShowCmd)
1353{
1354 ICOM_THIS(IShellLinkImpl, iface);
1355
1356 FIXME("(%p)->(%p)\n",This, piShowCmd);
1357 *piShowCmd=0;
1358 return NOERROR;
1359}
1360static HRESULT WINAPI IShellLinkA_fnSetShowCmd(IShellLinkA * iface, INT iShowCmd)
1361{
1362 ICOM_THIS(IShellLinkImpl, iface);
1363
1364 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1365 return NOERROR;
1366}
1367static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA * iface, LPSTR pszIconPath,INT cchIconPath,INT *piIcon)
1368{
1369 ICOM_THIS(IShellLinkImpl, iface);
1370
1371 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1372
1373 lstrcpynA( pszIconPath, This->sIcoPath ? This->sIcoPath : "", cchIconPath );
1374 *piIcon = This->iIcoNdx;
1375
1376 return NOERROR;
1377}
1378static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA * iface, LPCSTR pszIconPath,INT iIcon)
1379{
1380 ICOM_THIS(IShellLinkImpl, iface);
1381
1382 TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon);
1383
1384 if (This->sIcoPath)
1385 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1386 if (!(This->sIcoPath = heap_strdup(pszIconPath)))
1387 return E_OUTOFMEMORY;
1388 This->iIcoNdx = iIcon;
1389
1390 return NOERROR;
1391}
1392static HRESULT WINAPI IShellLinkA_fnSetRelativePath(IShellLinkA * iface, LPCSTR pszPathRel, DWORD dwReserved)
1393{
1394 ICOM_THIS(IShellLinkImpl, iface);
1395
1396 FIXME("(%p)->(path=%s %lx)\n",This, pszPathRel, dwReserved);
1397 return NOERROR;
1398}
1399static HRESULT WINAPI IShellLinkA_fnResolve(IShellLinkA * iface, HWND hwnd, DWORD fFlags)
1400{
1401 ICOM_THIS(IShellLinkImpl, iface);
1402
1403 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1404 return NOERROR;
1405}
1406static HRESULT WINAPI IShellLinkA_fnSetPath(IShellLinkA * iface, LPCSTR pszFile)
1407{
1408 ICOM_THIS(IShellLinkImpl, iface);
1409
1410 TRACE("(%p)->(path=%s)\n",This, pszFile);
1411
1412 if (This->sPath)
1413 HeapFree(GetProcessHeap(), 0, This->sPath);
1414 if (!(This->sPath = heap_strdup(pszFile)))
1415 return E_OUTOFMEMORY;
1416
1417 return NOERROR;
1418}
1419
1420/**************************************************************************
1421* IShellLink Implementation
1422*/
1423
1424static ICOM_VTABLE(IShellLinkA) slvt =
1425{
1426 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1427 IShellLinkA_fnQueryInterface,
1428 IShellLinkA_fnAddRef,
1429 IShellLinkA_fnRelease,
1430 IShellLinkA_fnGetPath,
1431 IShellLinkA_fnGetIDList,
1432 IShellLinkA_fnSetIDList,
1433 IShellLinkA_fnGetDescription,
1434 IShellLinkA_fnSetDescription,
1435 IShellLinkA_fnGetWorkingDirectory,
1436 IShellLinkA_fnSetWorkingDirectory,
1437 IShellLinkA_fnGetArguments,
1438 IShellLinkA_fnSetArguments,
1439 IShellLinkA_fnGetHotkey,
1440 IShellLinkA_fnSetHotkey,
1441 IShellLinkA_fnGetShowCmd,
1442 IShellLinkA_fnSetShowCmd,
1443 IShellLinkA_fnGetIconLocation,
1444 IShellLinkA_fnSetIconLocation,
1445 IShellLinkA_fnSetRelativePath,
1446 IShellLinkA_fnResolve,
1447 IShellLinkA_fnSetPath
1448};
1449
1450
1451/**************************************************************************
1452 * IShellLinkW_fnQueryInterface
1453 */
1454static HRESULT WINAPI IShellLinkW_fnQueryInterface(
1455 IShellLinkW * iface, REFIID riid, LPVOID *ppvObj)
1456{
1457 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1458
1459 return IShellLinkA_QueryInterface((IShellLinkA*)This, riid, ppvObj);
1460}
1461
1462/******************************************************************************
1463 * IShellLinkW_fnAddRef
1464 */
1465static ULONG WINAPI IShellLinkW_fnAddRef(IShellLinkW * iface)
1466{
1467 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1468
1469 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1470
1471 return IShellLinkA_AddRef((IShellLinkA*)This);
1472}
1473/******************************************************************************
1474 * IShellLinkW_fnRelease
1475 */
1476
1477static ULONG WINAPI IShellLinkW_fnRelease(IShellLinkW * iface)
1478{
1479 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1480
1481 TRACE("(%p)->(count=%lu)\n",This,This->ref);
1482
1483 return IShellLinkA_Release((IShellLinkA*)This);
1484}
1485
1486static HRESULT WINAPI IShellLinkW_fnGetPath(IShellLinkW * iface, LPWSTR pszFile,INT cchMaxPath, WIN32_FIND_DATAA *pfd, DWORD fFlags)
1487{
1488 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1489
1490 FIXME("(%p)->(pfile=%p len=%u find_data=%p flags=%lu)\n",This, pszFile, cchMaxPath, pfd, fFlags);
1491 MultiByteToWideChar( CP_ACP, 0, "c:\\foo.bar", -1, pszFile, cchMaxPath );
1492 return NOERROR;
1493}
1494
1495static HRESULT WINAPI IShellLinkW_fnGetIDList(IShellLinkW * iface, LPITEMIDLIST * ppidl)
1496{
1497 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1498
1499 FIXME("(%p)->(ppidl=%p)\n",This, ppidl);
1500 *ppidl = _ILCreateDesktop();
1501 return NOERROR;
1502}
1503
1504static HRESULT WINAPI IShellLinkW_fnSetIDList(IShellLinkW * iface, LPCITEMIDLIST pidl)
1505{
1506 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1507
1508 FIXME("(%p)->(pidl=%p)\n",This, pidl);
1509 return NOERROR;
1510}
1511
1512static HRESULT WINAPI IShellLinkW_fnGetDescription(IShellLinkW * iface, LPWSTR pszName,INT cchMaxName)
1513{
1514 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1515
1516 FIXME("(%p)->(%p len=%u)\n",This, pszName, cchMaxName);
1517 MultiByteToWideChar( CP_ACP, 0, "Description, FIXME", -1, pszName, cchMaxName );
1518 return NOERROR;
1519}
1520
1521static HRESULT WINAPI IShellLinkW_fnSetDescription(IShellLinkW * iface, LPCWSTR pszName)
1522{
1523 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1524
1525 TRACE("(%p)->(desc=%s)\n",This, debugstr_w(pszName));
1526
1527 if (This->sDescription)
1528 HeapFree(GetProcessHeap(), 0, This->sDescription);
1529 if (!(This->sDescription = HEAP_strdupWtoA(GetProcessHeap(), 0, pszName)))
1530 return E_OUTOFMEMORY;
1531
1532 return NOERROR;
1533}
1534
1535static HRESULT WINAPI IShellLinkW_fnGetWorkingDirectory(IShellLinkW * iface, LPWSTR pszDir,INT cchMaxPath)
1536{
1537 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1538
1539 TRACE("(%p)->(%p len %u)\n", This, pszDir, cchMaxPath);
1540
1541 MultiByteToWideChar( CP_ACP, 0, This->sWorkDir ? This->sWorkDir : "", -1, pszDir, cchMaxPath );
1542
1543 return NOERROR;
1544}
1545
1546static HRESULT WINAPI IShellLinkW_fnSetWorkingDirectory(IShellLinkW * iface, LPCWSTR pszDir)
1547{
1548 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1549
1550 TRACE("(%p)->(dir=%s)\n",This, debugstr_w(pszDir));
1551
1552 if (This->sWorkDir)
1553 HeapFree(GetProcessHeap(), 0, This->sWorkDir);
1554 if (!(This->sWorkDir = HEAP_strdupWtoA(GetProcessHeap(), 0, pszDir)))
1555 return E_OUTOFMEMORY;
1556
1557 return NOERROR;
1558}
1559
1560static HRESULT WINAPI IShellLinkW_fnGetArguments(IShellLinkW * iface, LPWSTR pszArgs,INT cchMaxPath)
1561{
1562 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1563
1564 TRACE("(%p)->(%p len=%u)\n", This, pszArgs, cchMaxPath);
1565
1566 MultiByteToWideChar( CP_ACP, 0, This->sArgs ? This->sArgs : "", -1, pszArgs, cchMaxPath );
1567
1568 return NOERROR;
1569}
1570
1571static HRESULT WINAPI IShellLinkW_fnSetArguments(IShellLinkW * iface, LPCWSTR pszArgs)
1572{
1573 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1574
1575 TRACE("(%p)->(args=%s)\n",This, debugstr_w(pszArgs));
1576
1577 if (This->sArgs)
1578 HeapFree(GetProcessHeap(), 0, This->sArgs);
1579 if (!(This->sArgs = HEAP_strdupWtoA(GetProcessHeap(), 0, pszArgs)))
1580 return E_OUTOFMEMORY;
1581
1582 return NOERROR;
1583}
1584
1585static HRESULT WINAPI IShellLinkW_fnGetHotkey(IShellLinkW * iface, WORD *pwHotkey)
1586{
1587 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1588
1589 FIXME("(%p)->(%p)\n",This, pwHotkey);
1590 *pwHotkey=0x0;
1591 return NOERROR;
1592}
1593
1594static HRESULT WINAPI IShellLinkW_fnSetHotkey(IShellLinkW * iface, WORD wHotkey)
1595{
1596 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1597
1598 FIXME("(%p)->(hotkey=%x)\n",This, wHotkey);
1599 return NOERROR;
1600}
1601
1602static HRESULT WINAPI IShellLinkW_fnGetShowCmd(IShellLinkW * iface, INT *piShowCmd)
1603{
1604 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1605
1606 FIXME("(%p)->(%p)\n",This, piShowCmd);
1607 *piShowCmd=0;
1608 return NOERROR;
1609}
1610
1611static HRESULT WINAPI IShellLinkW_fnSetShowCmd(IShellLinkW * iface, INT iShowCmd)
1612{
1613 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1614
1615 FIXME("(%p)->(showcmd=%x)\n",This, iShowCmd);
1616 return NOERROR;
1617}
1618
1619static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR pszIconPath,INT cchIconPath,INT *piIcon)
1620{
1621 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1622
1623 TRACE("(%p)->(%p len=%u iicon=%p)\n", This, pszIconPath, cchIconPath, piIcon);
1624
1625 MultiByteToWideChar( CP_ACP, 0, This->sIcoPath ? This->sIcoPath : "", -1, pszIconPath, cchIconPath );
1626 *piIcon = This->iIcoNdx;
1627
1628 return NOERROR;
1629}
1630
1631static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon)
1632{
1633 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1634
1635 TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon);
1636
1637 if (This->sIcoPath)
1638 HeapFree(GetProcessHeap(), 0, This->sIcoPath);
1639 if (!(This->sIcoPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszIconPath)))
1640 return E_OUTOFMEMORY;
1641 This->iIcoNdx = iIcon;
1642
1643 return NOERROR;
1644}
1645
1646static HRESULT WINAPI IShellLinkW_fnSetRelativePath(IShellLinkW * iface, LPCWSTR pszPathRel, DWORD dwReserved)
1647{
1648 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1649
1650 FIXME("(%p)->(path=%s %lx)\n",This, debugstr_w(pszPathRel), dwReserved);
1651 return NOERROR;
1652}
1653
1654static HRESULT WINAPI IShellLinkW_fnResolve(IShellLinkW * iface, HWND hwnd, DWORD fFlags)
1655{
1656 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1657
1658 FIXME("(%p)->(hwnd=%x flags=%lx)\n",This, hwnd, fFlags);
1659 return NOERROR;
1660}
1661
1662static HRESULT WINAPI IShellLinkW_fnSetPath(IShellLinkW * iface, LPCWSTR pszFile)
1663{
1664 _ICOM_THIS_From_IShellLinkW(IShellLinkImpl, iface);
1665
1666 TRACE("(%p)->(path=%s)\n",This, debugstr_w(pszFile));
1667
1668 if (This->sPath)
1669 HeapFree(GetProcessHeap(), 0, This->sPath);
1670 if (!(This->sPath = HEAP_strdupWtoA(GetProcessHeap(), 0, pszFile)))
1671 return E_OUTOFMEMORY;
1672
1673 return NOERROR;
1674}
1675
1676/**************************************************************************
1677* IShellLinkW Implementation
1678*/
1679
1680static ICOM_VTABLE(IShellLinkW) slvtw =
1681{
1682 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1683 IShellLinkW_fnQueryInterface,
1684 IShellLinkW_fnAddRef,
1685 IShellLinkW_fnRelease,
1686 IShellLinkW_fnGetPath,
1687 IShellLinkW_fnGetIDList,
1688 IShellLinkW_fnSetIDList,
1689 IShellLinkW_fnGetDescription,
1690 IShellLinkW_fnSetDescription,
1691 IShellLinkW_fnGetWorkingDirectory,
1692 IShellLinkW_fnSetWorkingDirectory,
1693 IShellLinkW_fnGetArguments,
1694 IShellLinkW_fnSetArguments,
1695 IShellLinkW_fnGetHotkey,
1696 IShellLinkW_fnSetHotkey,
1697 IShellLinkW_fnGetShowCmd,
1698 IShellLinkW_fnSetShowCmd,
1699 IShellLinkW_fnGetIconLocation,
1700 IShellLinkW_fnSetIconLocation,
1701 IShellLinkW_fnSetRelativePath,
1702 IShellLinkW_fnResolve,
1703 IShellLinkW_fnSetPath
1704};
1705
Note: See TracBrowser for help on using the repository browser.