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

Last change on this file since 8048 was 8048, checked in by sandervl, 23 years ago

PH: Wine resync + OS2 integration

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