2 * Unit tests for shelllinks
4 * Copyright 2004 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * This is a test program for the SHGet{Special}Folder{Path|Location} functions
20 * of shell32, that get either a filesystem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
32 #include "wine/test.h"
34 #include "shell32_test.h"
36 #ifndef SLDF_HAS_LOGO3ID
37 # define SLDF_HAS_LOGO3ID 0x00000800 /* not available in the Vista SDK */
40 typedef void (WINAPI
*fnILFree
)(LPITEMIDLIST
);
41 typedef BOOL (WINAPI
*fnILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
);
42 typedef HRESULT (WINAPI
*fnSHILCreateFromPath
)(LPCWSTR
, LPITEMIDLIST
*,DWORD
*);
44 static fnILFree pILFree
;
45 static fnILIsEqual pILIsEqual
;
46 static fnSHILCreateFromPath pSHILCreateFromPath
;
48 static DWORD (WINAPI
*pGetLongPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
50 static const GUID _IID_IShellLinkDataList
= {
51 0x45e2b4ae, 0xb1c3, 0x11d0,
52 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
55 static const WCHAR notafile
[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
58 /* For some reason SHILCreateFromPath does not work on Win98 and
59 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
60 * get what we want on all platforms.
62 static LPITEMIDLIST (WINAPI
*pSHSimpleIDListFromPathAW
)(LPCVOID
);
64 static LPITEMIDLIST
path_to_pidl(const char* path
)
68 if (!pSHSimpleIDListFromPathAW
)
70 HMODULE hdll
=GetModuleHandleA("shell32.dll");
71 pSHSimpleIDListFromPathAW
=(void*)GetProcAddress(hdll
, (char*)162);
72 if (!pSHSimpleIDListFromPathAW
)
73 win_skip("SHSimpleIDListFromPathAW not found in shell32.dll\n");
77 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
78 if (pSHSimpleIDListFromPathAW
&& (GetVersion() & 0x80000000))
79 pidl
=pSHSimpleIDListFromPathAW(path
);
87 len
=MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
88 pathW
=HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
89 MultiByteToWideChar(CP_ACP
, 0, path
, -1, pathW
, len
);
91 r
=pSHILCreateFromPath(pathW
, &pidl
, NULL
);
92 ok(SUCCEEDED(r
), "SHILCreateFromPath failed (0x%08x)\n", r
);
93 HeapFree(GetProcessHeap(), 0, pathW
);
100 * Test manipulation of an IShellLink's properties.
103 static void test_get_set(void)
107 char mypath
[MAX_PATH
];
108 char buffer
[INFOTIPSIZE
];
109 LPITEMIDLIST pidl
, tmp_pidl
;
114 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
115 &IID_IShellLinkA
, (LPVOID
*)&sl
);
116 ok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
120 /* Test Getting / Setting the description */
121 strcpy(buffer
,"garbage");
122 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
123 ok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
124 ok(*buffer
=='\0', "GetDescription returned '%s'\n", buffer
);
126 str
="Some description";
127 r
= IShellLinkA_SetDescription(sl
, str
);
128 ok(SUCCEEDED(r
), "SetDescription failed (0x%08x)\n", r
);
130 strcpy(buffer
,"garbage");
131 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
132 ok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
133 ok(lstrcmp(buffer
,str
)==0, "GetDescription returned '%s'\n", buffer
);
135 /* Test Getting / Setting the work directory */
136 strcpy(buffer
,"garbage");
137 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
138 ok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
139 ok(*buffer
=='\0', "GetWorkingDirectory returned '%s'\n", buffer
);
141 str
="c:\\nonexistent\\directory";
142 r
= IShellLinkA_SetWorkingDirectory(sl
, str
);
143 ok(SUCCEEDED(r
), "SetWorkingDirectory failed (0x%08x)\n", r
);
145 strcpy(buffer
,"garbage");
146 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
147 ok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
148 ok(lstrcmpi(buffer
,str
)==0, "GetWorkingDirectory returned '%s'\n", buffer
);
150 /* Test Getting / Setting the path */
151 strcpy(buffer
,"garbage");
152 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
153 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
154 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
156 r
= IShellLinkA_SetPath(sl
, "");
157 ok(r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
159 strcpy(buffer
,"garbage");
160 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
161 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
162 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
164 /* Win98 returns S_FALSE, but WinXP returns S_OK */
165 str
="c:\\nonexistent\\file";
166 r
= IShellLinkA_SetPath(sl
, str
);
167 ok(r
==S_FALSE
|| r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
169 strcpy(buffer
,"garbage");
170 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
171 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
172 ok(lstrcmpi(buffer
,str
)==0, "GetPath returned '%s'\n", buffer
);
174 /* Get some real path to play with */
175 GetWindowsDirectoryA( mypath
, sizeof(mypath
)-12 );
176 strcat(mypath
, "\\regedit.exe");
178 /* Test the interaction of SetPath and SetIDList */
180 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
181 ok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
186 strcpy(buffer
,"garbage");
187 ret
= SHGetPathFromIDListA(tmp_pidl
, buffer
);
189 ok(ret
, "SHGetPathFromIDListA failed\n");
192 ok(lstrcmpi(buffer
,str
)==0, "GetIDList returned '%s'\n", buffer
);
195 pidl
=path_to_pidl(mypath
);
196 ok(pidl
!=NULL
, "path_to_pidl returned a NULL pidl\n");
200 r
= IShellLinkA_SetIDList(sl
, pidl
);
201 ok(SUCCEEDED(r
), "SetIDList failed (0x%08x)\n", r
);
204 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
205 ok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
206 ok(tmp_pidl
&& pILIsEqual(pidl
, tmp_pidl
),
207 "GetIDList returned an incorrect pidl\n");
209 /* tmp_pidl is owned by IShellLink so we don't free it */
212 strcpy(buffer
,"garbage");
213 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
214 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
216 ok(lstrcmpi(buffer
, mypath
)==0, "GetPath returned '%s'\n", buffer
);
220 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
221 r
= IShellLinkA_SetPath(sl
, "\"c:\\nonexistent\\file\"");
222 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
224 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
225 ok(r
==S_OK
, "GetPath failed (0x%08x)\n", r
);
226 ok(!lstrcmp(buffer
, "C:\\nonexistent\\file") ||
227 broken(!lstrcmp(buffer
, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
228 "case doesn't match\n");
230 r
= IShellLinkA_SetPath(sl
, "\"c:\\foo");
231 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
233 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo");
234 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
236 r
= IShellLinkA_SetPath(sl
, "c:\\foo\"");
237 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
239 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"");
240 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
242 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"\"");
243 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
245 /* Test Getting / Setting the arguments */
246 strcpy(buffer
,"garbage");
247 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
248 ok(SUCCEEDED(r
), "GetArguments failed (0x%08x)\n", r
);
249 ok(*buffer
=='\0', "GetArguments returned '%s'\n", buffer
);
251 str
="param1 \"spaced param2\"";
252 r
= IShellLinkA_SetArguments(sl
, str
);
253 ok(SUCCEEDED(r
), "SetArguments failed (0x%08x)\n", r
);
255 strcpy(buffer
,"garbage");
256 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
257 ok(SUCCEEDED(r
), "GetArguments failed (0x%08x)\n", r
);
258 ok(lstrcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
260 /* Test Getting / Setting showcmd */
262 r
= IShellLinkA_GetShowCmd(sl
, &i
);
263 ok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
264 ok(i
==SW_SHOWNORMAL
, "GetShowCmd returned %d\n", i
);
266 r
= IShellLinkA_SetShowCmd(sl
, SW_SHOWMAXIMIZED
);
267 ok(SUCCEEDED(r
), "SetShowCmd failed (0x%08x)\n", r
);
270 r
= IShellLinkA_GetShowCmd(sl
, &i
);
271 ok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
272 ok(i
==SW_SHOWMAXIMIZED
, "GetShowCmd returned %d'\n", i
);
274 /* Test Getting / Setting the icon */
276 strcpy(buffer
,"garbage");
277 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
279 ok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
281 ok(*buffer
=='\0', "GetIconLocation returned '%s'\n", buffer
);
282 ok(i
==0, "GetIconLocation returned %d\n", i
);
284 str
="c:\\nonexistent\\file";
285 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
286 ok(SUCCEEDED(r
), "SetIconLocation failed (0x%08x)\n", r
);
289 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
290 ok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
291 ok(lstrcmpi(buffer
,str
)==0, "GetIconLocation returned '%s'\n", buffer
);
292 ok(i
==0xbabecafe, "GetIconLocation returned %d'\n", i
);
294 /* Test Getting / Setting the hot key */
296 r
= IShellLinkA_GetHotkey(sl
, &w
);
297 ok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
298 ok(w
==0, "GetHotkey returned %d\n", w
);
300 r
= IShellLinkA_SetHotkey(sl
, 0x5678);
301 ok(SUCCEEDED(r
), "SetHotkey failed (0x%08x)\n", r
);
304 r
= IShellLinkA_GetHotkey(sl
, &w
);
305 ok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
306 ok(w
==0x5678, "GetHotkey returned %d'\n", w
);
308 IShellLinkA_Release(sl
);
313 * Test saving and loading .lnk files
316 #define lok ok_(__FILE__, line)
317 #define lok_todo_4(todo_flag,a,b,c,d) \
318 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
319 else todo_wine lok((a), (b), (c), (d));
320 #define lok_todo_2(todo_flag,a,b) \
321 if ((todo & todo_flag) == 0) lok((a), (b)); \
322 else todo_wine lok((a), (b));
323 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
325 void create_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int save_fails
)
331 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
332 &IID_IShellLinkA
, (LPVOID
*)&sl
);
333 lok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
337 if (desc
->description
)
339 r
= IShellLinkA_SetDescription(sl
, desc
->description
);
340 lok(SUCCEEDED(r
), "SetDescription failed (0x%08x)\n", r
);
344 r
= IShellLinkA_SetWorkingDirectory(sl
, desc
->workdir
);
345 lok(SUCCEEDED(r
), "SetWorkingDirectory failed (0x%08x)\n", r
);
349 r
= IShellLinkA_SetPath(sl
, desc
->path
);
350 lok(SUCCEEDED(r
), "SetPath failed (0x%08x)\n", r
);
354 r
= IShellLinkA_SetIDList(sl
, desc
->pidl
);
355 lok(SUCCEEDED(r
), "SetIDList failed (0x%08x)\n", r
);
359 r
= IShellLinkA_SetArguments(sl
, desc
->arguments
);
360 lok(SUCCEEDED(r
), "SetArguments failed (0x%08x)\n", r
);
364 r
= IShellLinkA_SetShowCmd(sl
, desc
->showcmd
);
365 lok(SUCCEEDED(r
), "SetShowCmd failed (0x%08x)\n", r
);
369 r
= IShellLinkA_SetIconLocation(sl
, desc
->icon
, desc
->icon_id
);
370 lok(SUCCEEDED(r
), "SetIconLocation failed (0x%08x)\n", r
);
374 r
= IShellLinkA_SetHotkey(sl
, desc
->hotkey
);
375 lok(SUCCEEDED(r
), "SetHotkey failed (0x%08x)\n", r
);
378 r
= IShellLinkW_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
379 lok(SUCCEEDED(r
), "no IID_IPersistFile (0x%08x)\n", r
);
382 r
= IPersistFile_Save(pf
, path
, TRUE
);
386 lok(SUCCEEDED(r
), "save failed (0x%08x)\n", r
);
391 lok(SUCCEEDED(r
), "save failed (0x%08x)\n", r
);
393 IPersistFile_Release(pf
);
396 IShellLinkA_Release(sl
);
399 static void check_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int todo
)
404 char buffer
[INFOTIPSIZE
];
406 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
407 &IID_IShellLinkA
, (LPVOID
*)&sl
);
408 lok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
412 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
413 lok(SUCCEEDED(r
), "no IID_IPersistFile (0x%08x)\n", r
);
416 IShellLinkA_Release(sl
);
420 r
= IPersistFile_Load(pf
, path
, STGM_READ
);
421 lok(SUCCEEDED(r
), "load failed (0x%08x)\n", r
);
422 IPersistFile_Release(pf
);
425 IShellLinkA_Release(sl
);
429 if (desc
->description
)
431 strcpy(buffer
,"garbage");
432 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
433 lok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
434 lok_todo_4(0x1, lstrcmp(buffer
, desc
->description
)==0,
435 "GetDescription returned '%s' instead of '%s'\n",
436 buffer
, desc
->description
);
440 strcpy(buffer
,"garbage");
441 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
442 lok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
443 lok_todo_4(0x2, lstrcmpi(buffer
, desc
->workdir
)==0,
444 "GetWorkingDirectory returned '%s' instead of '%s'\n",
445 buffer
, desc
->workdir
);
449 strcpy(buffer
,"garbage");
450 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
451 lok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
452 lok_todo_4(0x4, lstrcmpi(buffer
, desc
->path
)==0,
453 "GetPath returned '%s' instead of '%s'\n",
458 LPITEMIDLIST pidl
=NULL
;
459 r
= IShellLinkA_GetIDList(sl
, &pidl
);
460 lok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
461 lok_todo_2(0x8, pILIsEqual(pidl
, desc
->pidl
),
462 "GetIDList returned an incorrect pidl\n");
467 r
= IShellLinkA_GetShowCmd(sl
, &i
);
468 lok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
469 lok_todo_4(0x10, i
==desc
->showcmd
,
470 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
476 strcpy(buffer
,"garbage");
477 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
478 lok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
479 lok_todo_4(0x20, lstrcmpi(buffer
, desc
->icon
)==0,
480 "GetIconLocation returned '%s' instead of '%s'\n",
482 lok_todo_4(0x20, i
==desc
->icon_id
,
483 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
489 r
= IShellLinkA_GetHotkey(sl
, &i
);
490 lok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
491 lok_todo_4(0x40, i
==desc
->hotkey
,
492 "GetHotkey returned 0x%04x instead of 0x%04x\n",
496 IShellLinkA_Release(sl
);
499 static void test_load_save(void)
501 WCHAR lnkfile
[MAX_PATH
];
502 char lnkfileA
[MAX_PATH
];
503 static const char lnkfileA_name
[] = "\\test.lnk";
506 char mypath
[MAX_PATH
];
507 char mydir
[MAX_PATH
];
508 char realpath
[MAX_PATH
];
513 if (!pGetLongPathNameA
)
515 skip("GetLongPathNameA is not available\n");
519 /* Don't used a fixed path for the test.lnk file */
520 GetTempPathA(MAX_PATH
, lnkfileA
);
521 lstrcatA(lnkfileA
, lnkfileA_name
);
522 MultiByteToWideChar(CP_ACP
, 0, lnkfileA
, -1, lnkfile
, MAX_PATH
);
524 /* Save an empty .lnk file */
525 memset(&desc
, 0, sizeof(desc
));
526 create_lnk(lnkfile
, &desc
, 0);
528 /* It should come back as a bunch of empty strings */
534 check_lnk(lnkfile
, &desc
, 0x0);
536 /* Point a .lnk file to nonexistent files */
538 desc
.workdir
="c:\\Nonexitent\\work\\directory";
539 desc
.path
="c:\\nonexistent\\path";
543 desc
.icon
="c:\\nonexistent\\icon\\file";
546 create_lnk(lnkfile
, &desc
, 0);
547 check_lnk(lnkfile
, &desc
, 0x0);
549 r
=GetModuleFileName(NULL
, mypath
, sizeof(mypath
));
550 ok(r
<sizeof(mypath
), "GetModuleFileName failed (%d)\n", r
);
551 strcpy(mydir
, mypath
);
552 p
=strrchr(mydir
, '\\');
556 /* IShellLink returns path in long form */
557 if (!pGetLongPathNameA(mypath
, realpath
, MAX_PATH
)) strcpy( realpath
, mypath
);
559 /* Overwrite the existing lnk file and point it to existing files */
560 desc
.description
="test 2";
564 desc
.arguments
="/option1 /option2 \"Some string\"";
565 desc
.showcmd
=SW_SHOWNORMAL
;
569 create_lnk(lnkfile
, &desc
, 0);
570 check_lnk(lnkfile
, &desc
, 0x0);
572 /* Overwrite the existing lnk file and test link to a command on the path */
573 desc
.description
="command on path";
575 desc
.path
="rundll32.exe";
577 desc
.arguments
="/option1 /option2 \"Some string\"";
578 desc
.showcmd
=SW_SHOWNORMAL
;
582 create_lnk(lnkfile
, &desc
, 0);
583 /* Check that link is created to proper location */
584 SearchPathA( NULL
, desc
.path
, NULL
, MAX_PATH
, realpath
, NULL
);
586 check_lnk(lnkfile
, &desc
, 0x0);
588 /* Create a temporary non-executable file */
589 r
=GetTempPath(sizeof(mypath
), mypath
);
590 ok(r
<sizeof(mypath
), "GetTempPath failed (%d), err %d\n", r
, GetLastError());
591 r
=pGetLongPathNameA(mypath
, mydir
, sizeof(mydir
));
592 ok(r
<sizeof(mydir
), "GetLongPathName failed (%d), err %d\n", r
, GetLastError());
593 p
=strrchr(mydir
, '\\');
597 strcpy(mypath
, mydir
);
598 strcat(mypath
, "\\test.txt");
599 hf
= CreateFile(mypath
, GENERIC_WRITE
, 0, NULL
,
600 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
603 /* Overwrite the existing lnk file and test link to an existing non-executable file */
604 desc
.description
="non-executable file";
609 desc
.showcmd
=SW_SHOWNORMAL
;
613 create_lnk(lnkfile
, &desc
, 0);
614 check_lnk(lnkfile
, &desc
, 0x0);
616 r
= DeleteFileA(mypath
);
617 ok(r
, "failed to delete file %s (%d)\n", mypath
, GetLastError());
619 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
620 * represented as a path.
623 /* DeleteFileW is not implemented on Win9x */
624 r
=DeleteFileA(lnkfileA
);
625 ok(r
, "failed to delete link '%s' (%d)\n", lnkfileA
, GetLastError());
628 static void test_datalink(void)
630 static const WCHAR lnk
[] = {
631 ':',':','{','9','d','b','1','1','8','6','f','-','4','0','d','f','-','1',
632 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
633 '8','6','3','}',':','{','0','0','0','1','0','4','0','9','-','7','8','E',
634 '1','-','1','1','D','2','-','B','6','0','F','-','0','0','6','0','9','7',
635 'C','9','9','8','E','7','}',':',':','{','9','d','b','1','1','8','6','e',
636 '-','4','0','d','f','-','1','1','d','1','-','a','a','8','c','-','0','0',
637 'c','0','4','f','b','6','7','8','6','3','}',':','2','6',',','!','!','g',
638 'x','s','f','(','N','g',']','q','F','`','H','{','L','s','A','C','C','E',
639 'S','S','F','i','l','e','s','>','p','l','T',']','j','I','{','j','f','(',
640 '=','1','&','L','[','-','8','1','-',']',':',':',0 };
641 static const WCHAR comp
[] = {
642 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
643 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
644 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
645 IShellLinkDataList
*dl
= NULL
;
646 IShellLinkW
*sl
= NULL
;
649 EXP_DARWIN_LINK
*dar
;
651 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
652 &IID_IShellLinkW
, (LPVOID
*)&sl
);
654 broken(r
== E_NOINTERFACE
), /* Win9x */
655 "CoCreateInstance failed (0x%08x)\n", r
);
658 skip("no shelllink\n");
662 r
= IShellLinkW_QueryInterface( sl
, &_IID_IShellLinkDataList
, (LPVOID
*) &dl
);
664 broken(r
== E_NOINTERFACE
), /* NT4 */
665 "IShellLinkW_QueryInterface failed (0x%08x)\n", r
);
669 skip("no datalink interface\n");
670 IShellLinkW_Release( sl
);
675 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
676 ok( r
== S_OK
, "GetFlags failed\n");
677 ok( flags
== 0, "GetFlags returned wrong flags\n");
680 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
681 ok( r
== E_FAIL
, "CopyDataBlock failed\n");
682 ok( dar
== NULL
, "should be null\n");
684 r
= IShellLinkW_SetPath(sl
, lnk
);
685 ok(r
== S_OK
, "set path failed\n");
688 * The following crashes:
689 * r = IShellLinkDataList_GetFlags( dl, NULL );
693 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
694 ok( r
== S_OK
, "GetFlags failed\n");
695 ok( flags
== (SLDF_HAS_DARWINID
|SLDF_HAS_LOGO3ID
),
696 "GetFlags returned wrong flags\n");
699 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
700 ok( r
== S_OK
, "CopyDataBlock failed\n");
702 ok( dar
&& ((DATABLOCK_HEADER
*)dar
)->dwSignature
== EXP_DARWIN_ID_SIG
, "signature wrong\n");
703 ok( dar
&& 0==lstrcmpW(dar
->szwDarwinID
, comp
), "signature wrong\n");
707 IUnknown_Release( dl
);
708 IShellLinkW_Release( sl
);
711 START_TEST(shelllink
)
714 HMODULE hmod
= GetModuleHandleA("shell32.dll");
715 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
717 pILFree
= (fnILFree
) GetProcAddress(hmod
, (LPSTR
)155);
718 pILIsEqual
= (fnILIsEqual
) GetProcAddress(hmod
, (LPSTR
)21);
719 pSHILCreateFromPath
= (fnSHILCreateFromPath
) GetProcAddress(hmod
, (LPSTR
)28);
721 pGetLongPathNameA
= (void *)GetProcAddress(hkernel32
, "GetLongPathNameA");
723 r
= CoInitialize(NULL
);
724 ok(SUCCEEDED(r
), "CoInitialize failed (0x%08x)\n", r
);