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
29 #include "wine/test.h"
31 #include "shell32_test.h"
33 #ifndef SLDF_HAS_LOGO3ID
34 # define SLDF_HAS_LOGO3ID 0x00000800 /* not available in the Vista SDK */
37 static void (WINAPI *pILFree)(LPITEMIDLIST);
38 static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
39 static HRESULT (WINAPI *pSHILCreateFromPath)(LPCWSTR, LPITEMIDLIST *,DWORD*);
40 static HRESULT (WINAPI *pSHDefExtractIconA)(LPCSTR, int, UINT, HICON*, HICON*, UINT);
41 static HRESULT (WINAPI *pSHGetStockIconInfo)(SHSTOCKICONID, UINT, SHSTOCKICONINFO *);
42 static DWORD (WINAPI *pGetLongPathNameA)(LPCSTR, LPSTR, DWORD);
43 static DWORD (WINAPI *pGetShortPathNameA)(LPCSTR, LPSTR, DWORD);
45 static const GUID _IID_IShellLinkDataList = {
46 0x45e2b4ae, 0xb1c3, 0x11d0,
47 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
50 static const WCHAR notafile[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
53 /* For some reason SHILCreateFromPath does not work on Win98 and
54 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
55 * get what we want on all platforms.
57 static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID);
59 static LPITEMIDLIST path_to_pidl(const char* path)
63 if (!pSHSimpleIDListFromPathAW)
65 HMODULE hdll=GetModuleHandleA("shell32.dll");
66 pSHSimpleIDListFromPathAW=(void*)GetProcAddress(hdll, (char*)162);
67 if (!pSHSimpleIDListFromPathAW)
68 win_skip("SHSimpleIDListFromPathAW not found in shell32.dll\n");
72 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
73 if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
74 pidl=pSHSimpleIDListFromPathAW(path);
82 len=MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
83 pathW=HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
84 MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, len);
86 r=pSHILCreateFromPath(pathW, &pidl, NULL);
87 ok(r == S_OK, "SHILCreateFromPath failed (0x%08x)\n", r);
88 HeapFree(GetProcessHeap(), 0, pathW);
95 * Test manipulation of an IShellLink's properties.
98 static void test_get_set(void)
102 IShellLinkW *slW = NULL;
103 char mypath[MAX_PATH];
104 char buffer[INFOTIPSIZE];
105 LPITEMIDLIST pidl, tmp_pidl;
110 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
111 &IID_IShellLinkA, (LPVOID*)&sl);
112 ok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
116 /* Test Getting / Setting the description */
117 strcpy(buffer,"garbage");
118 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
119 ok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
120 ok(*buffer=='\0', "GetDescription returned '%s'\n", buffer);
122 str="Some description";
123 r = IShellLinkA_SetDescription(sl, str);
124 ok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
126 strcpy(buffer,"garbage");
127 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
128 ok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
129 ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer);
131 r = IShellLinkA_SetDescription(sl, NULL);
132 ok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
134 strcpy(buffer,"garbage");
135 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
136 ok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
137 ok(*buffer=='\0' || broken(lstrcmp(buffer,str)==0), "GetDescription returned '%s'\n", buffer); /* NT4 */
140 /* Test Getting / Setting the work directory */
141 strcpy(buffer,"garbage");
142 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
143 ok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
144 ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
146 str="c:\\nonexistent\\directory";
147 r = IShellLinkA_SetWorkingDirectory(sl, str);
148 ok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r);
150 strcpy(buffer,"garbage");
151 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
152 ok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
153 ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
155 /* Test Getting / Setting the path */
156 strcpy(buffer,"garbage");
157 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
158 todo_wine ok(r == S_FALSE || broken(r == S_OK) /* NT4/W2K */, "GetPath failed (0x%08x)\n", r);
159 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
161 CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
162 &IID_IShellLinkW, (LPVOID*)&slW);
163 if (!slW /* Win9x */ || !pGetLongPathNameA /* NT4 */)
164 skip("SetPath with NULL parameter crashes on Win9x and some NT4\n");
167 IShellLinkW_Release(slW);
168 r = IShellLinkA_SetPath(sl, NULL);
169 ok(r==E_INVALIDARG ||
170 broken(r==S_OK), /* Some Win95 and NT4 */
171 "SetPath returned wrong error (0x%08x)\n", r);
174 r = IShellLinkA_SetPath(sl, "");
175 ok(r==S_OK, "SetPath failed (0x%08x)\n", r);
177 strcpy(buffer,"garbage");
178 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
179 todo_wine ok(r == S_FALSE, "GetPath failed (0x%08x)\n", r);
180 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
182 /* Win98 returns S_FALSE, but WinXP returns S_OK */
183 str="c:\\nonexistent\\file";
184 r = IShellLinkA_SetPath(sl, str);
185 ok(r==S_FALSE || r==S_OK, "SetPath failed (0x%08x)\n", r);
187 strcpy(buffer,"garbage");
188 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
189 ok(r == S_OK, "GetPath failed (0x%08x)\n", r);
190 ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer);
192 /* Get some real path to play with */
193 GetWindowsDirectoryA( mypath, sizeof(mypath)-12 );
194 strcat(mypath, "\\regedit.exe");
196 /* Test the interaction of SetPath and SetIDList */
198 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
199 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
204 strcpy(buffer,"garbage");
205 ret = SHGetPathFromIDListA(tmp_pidl, buffer);
206 ok(ret, "SHGetPathFromIDListA failed\n");
208 ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
212 pidl=path_to_pidl(mypath);
213 ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
217 LPITEMIDLIST second_pidl;
219 r = IShellLinkA_SetIDList(sl, pidl);
220 ok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
223 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
224 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
225 ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
226 "GetIDList returned an incorrect pidl\n");
228 r = IShellLinkA_GetIDList(sl, &second_pidl);
229 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
230 ok(second_pidl && pILIsEqual(pidl, second_pidl),
231 "GetIDList returned an incorrect pidl\n");
232 ok(second_pidl != tmp_pidl, "pidls are the same\n");
234 pILFree(second_pidl);
238 strcpy(buffer,"garbage");
239 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
240 ok(r == S_OK, "GetPath failed (0x%08x)\n", r);
242 ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
246 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
247 r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
248 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
250 strcpy(buffer,"garbage");
251 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
252 ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
253 ok(!lstrcmp(buffer, "C:\\nonexistent\\file") ||
254 broken(!lstrcmp(buffer, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
255 "case doesn't match\n");
257 r = IShellLinkA_SetPath(sl, "\"c:\\foo");
258 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
260 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
261 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
263 r = IShellLinkA_SetPath(sl, "c:\\foo\"");
264 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
266 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
267 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
269 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
270 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
272 /* Test Getting / Setting the arguments */
273 strcpy(buffer,"garbage");
274 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
275 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
276 ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
278 str="param1 \"spaced param2\"";
279 r = IShellLinkA_SetArguments(sl, str);
280 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
282 strcpy(buffer,"garbage");
283 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
284 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
285 ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
287 strcpy(buffer,"garbage");
288 r = IShellLinkA_SetArguments(sl, NULL);
289 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
290 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
291 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
292 ok(!buffer[0] || lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
294 strcpy(buffer,"garbage");
295 r = IShellLinkA_SetArguments(sl, "");
296 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
297 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
298 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
299 ok(!buffer[0], "GetArguments returned '%s'\n", buffer);
301 /* Test Getting / Setting showcmd */
303 r = IShellLinkA_GetShowCmd(sl, &i);
304 ok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
305 ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
307 r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
308 ok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
311 r = IShellLinkA_GetShowCmd(sl, &i);
312 ok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
313 ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
315 /* Test Getting / Setting the icon */
317 strcpy(buffer,"garbage");
318 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
319 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
320 ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
321 ok(i==0, "GetIconLocation returned %d\n", i);
323 str="c:\\nonexistent\\file";
324 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
325 ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
328 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
329 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
330 ok(lstrcmpi(buffer,str)==0, "GetIconLocation returned '%s'\n", buffer);
331 ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
333 /* Test Getting / Setting the hot key */
335 r = IShellLinkA_GetHotkey(sl, &w);
336 ok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
337 ok(w==0, "GetHotkey returned %d\n", w);
339 r = IShellLinkA_SetHotkey(sl, 0x5678);
340 ok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
343 r = IShellLinkA_GetHotkey(sl, &w);
344 ok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
345 ok(w==0x5678, "GetHotkey returned %d'\n", w);
347 IShellLinkA_Release(sl);
352 * Test saving and loading .lnk files
355 #define lok ok_(__FILE__, line)
356 #define lok_todo_4(todo_flag,a,b,c,d) \
357 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
358 else todo_wine lok((a), (b), (c), (d));
359 #define lok_todo_2(todo_flag,a,b) \
360 if ((todo & todo_flag) == 0) lok((a), (b)); \
361 else todo_wine lok((a), (b));
362 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
364 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
370 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
371 &IID_IShellLinkA, (LPVOID*)&sl);
372 lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
376 if (desc->description)
378 r = IShellLinkA_SetDescription(sl, desc->description);
379 lok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
383 r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
384 lok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r);
388 r = IShellLinkA_SetPath(sl, desc->path);
389 lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
393 r = IShellLinkA_SetIDList(sl, desc->pidl);
394 lok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
398 r = IShellLinkA_SetArguments(sl, desc->arguments);
399 lok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
403 r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
404 lok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
408 r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
409 lok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
413 r = IShellLinkA_SetHotkey(sl, desc->hotkey);
414 lok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
417 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (void**)&pf);
418 lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
426 IPersistFile_GetCurFile(pf, NULL);
429 /* test GetCurFile before ::Save */
430 str = (LPWSTR)0xdeadbeef;
431 r = IPersistFile_GetCurFile(pf, &str);
433 broken(r == S_OK), /* shell32 < 5.0 */
435 lok(str == NULL, "got %p\n", str);
437 r = IPersistFile_Save(pf, path, TRUE);
441 lok(r == S_OK, "save failed (0x%08x)\n", r);
446 lok(r == S_OK, "save failed (0x%08x)\n", r);
449 /* test GetCurFile after ::Save */
450 r = IPersistFile_GetCurFile(pf, &str);
451 lok(r == S_OK, "got 0x%08x\n", r);
453 broken(str == NULL), /* shell32 < 5.0 */
454 "Didn't expect NULL\n");
459 lok(!winetest_strcmpW(path, str), "Expected %s, got %s\n",
460 wine_dbgstr_w(path), wine_dbgstr_w(str));
462 SHGetMalloc(&pmalloc);
463 IMalloc_Free(pmalloc, str);
466 win_skip("GetCurFile fails on shell32 < 5.0\n");
468 IPersistFile_Release(pf);
471 IShellLinkA_Release(sl);
474 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int todo)
479 char buffer[INFOTIPSIZE];
482 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
483 &IID_IShellLinkA, (LPVOID*)&sl);
484 lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
488 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
489 lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
492 IShellLinkA_Release(sl);
496 /* test GetCurFile before ::Load */
497 str = (LPWSTR)0xdeadbeef;
498 r = IPersistFile_GetCurFile(pf, &str);
500 broken(r == S_OK), /* shell32 < 5.0 */
502 lok(str == NULL, "got %p\n", str);
504 r = IPersistFile_Load(pf, path, STGM_READ);
505 lok(r == S_OK, "load failed (0x%08x)\n", r);
507 /* test GetCurFile after ::Save */
508 r = IPersistFile_GetCurFile(pf, &str);
509 lok(r == S_OK, "got 0x%08x\n", r);
511 broken(str == NULL), /* shell32 < 5.0 */
512 "Didn't expect NULL\n");
517 lok(!winetest_strcmpW(path, str), "Expected %s, got %s\n",
518 wine_dbgstr_w(path), wine_dbgstr_w(str));
520 SHGetMalloc(&pmalloc);
521 IMalloc_Free(pmalloc, str);
524 win_skip("GetCurFile fails on shell32 < 5.0\n");
526 IPersistFile_Release(pf);
529 IShellLinkA_Release(sl);
533 if (desc->description)
535 strcpy(buffer,"garbage");
536 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
537 lok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
538 lok_todo_4(0x1, lstrcmp(buffer, desc->description)==0,
539 "GetDescription returned '%s' instead of '%s'\n",
540 buffer, desc->description);
544 strcpy(buffer,"garbage");
545 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
546 lok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
547 lok_todo_4(0x2, lstrcmpi(buffer, desc->workdir)==0,
548 "GetWorkingDirectory returned '%s' instead of '%s'\n",
549 buffer, desc->workdir);
553 strcpy(buffer,"garbage");
554 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
555 lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
556 lok_todo_4(0x4, lstrcmpi(buffer, desc->path)==0,
557 "GetPath returned '%s' instead of '%s'\n",
562 LPITEMIDLIST pidl=NULL;
563 r = IShellLinkA_GetIDList(sl, &pidl);
564 lok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
565 lok_todo_2(0x8, pILIsEqual(pidl, desc->pidl),
566 "GetIDList returned an incorrect pidl\n");
571 r = IShellLinkA_GetShowCmd(sl, &i);
572 lok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
573 lok_todo_4(0x10, i==desc->showcmd,
574 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
580 strcpy(buffer,"garbage");
581 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
582 lok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
583 lok_todo_4(0x20, lstrcmpi(buffer, desc->icon)==0,
584 "GetIconLocation returned '%s' instead of '%s'\n",
586 lok_todo_4(0x20, i==desc->icon_id,
587 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
593 r = IShellLinkA_GetHotkey(sl, &i);
594 lok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
595 lok_todo_4(0x40, i==desc->hotkey,
596 "GetHotkey returned 0x%04x instead of 0x%04x\n",
600 IShellLinkA_Release(sl);
603 static void test_load_save(void)
605 WCHAR lnkfile[MAX_PATH];
606 char lnkfileA[MAX_PATH];
607 static const char lnkfileA_name[] = "\\test.lnk";
610 char mypath[MAX_PATH];
611 char mydir[MAX_PATH];
612 char realpath[MAX_PATH];
617 if (!pGetLongPathNameA)
619 win_skip("GetLongPathNameA is not available\n");
623 /* Don't used a fixed path for the test.lnk file */
624 GetTempPathA(MAX_PATH, lnkfileA);
625 lstrcatA(lnkfileA, lnkfileA_name);
626 MultiByteToWideChar(CP_ACP, 0, lnkfileA, -1, lnkfile, MAX_PATH);
628 /* Save an empty .lnk file */
629 memset(&desc, 0, sizeof(desc));
630 create_lnk(lnkfile, &desc, 0);
632 /* It should come back as a bunch of empty strings */
638 check_lnk(lnkfile, &desc, 0x0);
640 /* Point a .lnk file to nonexistent files */
642 desc.workdir="c:\\Nonexitent\\work\\directory";
643 desc.path="c:\\nonexistent\\path";
647 desc.icon="c:\\nonexistent\\icon\\file";
650 create_lnk(lnkfile, &desc, 0);
651 check_lnk(lnkfile, &desc, 0x0);
653 r=GetModuleFileName(NULL, mypath, sizeof(mypath));
654 ok(r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
655 strcpy(mydir, mypath);
656 p=strrchr(mydir, '\\');
660 /* IShellLink returns path in long form */
661 if (!pGetLongPathNameA(mypath, realpath, MAX_PATH)) strcpy( realpath, mypath );
663 /* Overwrite the existing lnk file and point it to existing files */
664 desc.description="test 2";
668 desc.arguments="/option1 /option2 \"Some string\"";
669 desc.showcmd=SW_SHOWNORMAL;
673 create_lnk(lnkfile, &desc, 0);
674 check_lnk(lnkfile, &desc, 0x0);
676 /* Test omitting .exe from an absolute path */
677 p=strrchr(realpath, '.');
681 desc.description="absolute path without .exe";
685 desc.arguments="/option1 /option2 \"Some string\"";
686 desc.showcmd=SW_SHOWNORMAL;
690 create_lnk(lnkfile, &desc, 0);
691 strcat(realpath, ".exe");
692 check_lnk(lnkfile, &desc, 0x4);
694 /* Overwrite the existing lnk file and test link to a command on the path */
695 desc.description="command on path";
697 desc.path="rundll32.exe";
699 desc.arguments="/option1 /option2 \"Some string\"";
700 desc.showcmd=SW_SHOWNORMAL;
704 create_lnk(lnkfile, &desc, 0);
705 /* Check that link is created to proper location */
706 SearchPathA( NULL, desc.path, NULL, MAX_PATH, realpath, NULL);
708 check_lnk(lnkfile, &desc, 0x0);
710 /* Test omitting .exe from a command on the path */
711 desc.description="command on path without .exe";
713 desc.path="rundll32";
715 desc.arguments="/option1 /option2 \"Some string\"";
716 desc.showcmd=SW_SHOWNORMAL;
720 create_lnk(lnkfile, &desc, 0);
721 /* Check that link is created to proper location */
722 SearchPathA( NULL, "rundll32", NULL, MAX_PATH, realpath, NULL);
724 check_lnk(lnkfile, &desc, 0x4);
726 /* Create a temporary non-executable file */
727 r=GetTempPath(sizeof(mypath), mypath);
728 ok(r<sizeof(mypath), "GetTempPath failed (%d), err %d\n", r, GetLastError());
729 r=pGetLongPathNameA(mypath, mydir, sizeof(mydir));
730 ok(r<sizeof(mydir), "GetLongPathName failed (%d), err %d\n", r, GetLastError());
731 p=strrchr(mydir, '\\');
735 strcpy(mypath, mydir);
736 strcat(mypath, "\\test.txt");
737 hf = CreateFile(mypath, GENERIC_WRITE, 0, NULL,
738 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
741 /* Overwrite the existing lnk file and test link to an existing non-executable file */
742 desc.description="non-executable file";
747 desc.showcmd=SW_SHOWNORMAL;
751 create_lnk(lnkfile, &desc, 0);
752 check_lnk(lnkfile, &desc, 0x0);
754 r=pGetShortPathNameA(mydir, mypath, sizeof(mypath));
755 ok(r<sizeof(mypath), "GetShortPathName failed (%d), err %d\n", r, GetLastError());
757 strcpy(realpath, mypath);
758 strcat(realpath, "\\test.txt");
759 strcat(mypath, "\\\\test.txt");
761 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
762 desc.description="non-executable file";
767 desc.showcmd=SW_SHOWNORMAL;
771 create_lnk(lnkfile, &desc, 0);
773 check_lnk(lnkfile, &desc, 0x0);
775 r = DeleteFileA(mypath);
776 ok(r, "failed to delete file %s (%d)\n", mypath, GetLastError());
778 /* Create a temporary .bat file */
779 strcpy(mypath, mydir);
780 strcat(mypath, "\\test.bat");
781 hf = CreateFile(mypath, GENERIC_WRITE, 0, NULL,
782 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
785 strcpy(realpath, mypath);
787 p=strrchr(mypath, '.');
791 /* Try linking to the .bat file without the extension */
792 desc.description="batch file";
797 desc.showcmd=SW_SHOWNORMAL;
801 create_lnk(lnkfile, &desc, 0);
802 desc.path = realpath;
803 check_lnk(lnkfile, &desc, 0x4);
805 r = DeleteFileA(realpath);
806 ok(r, "failed to delete file %s (%d)\n", realpath, GetLastError());
808 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
809 * represented as a path.
812 /* DeleteFileW is not implemented on Win9x */
813 r=DeleteFileA(lnkfileA);
814 ok(r, "failed to delete link '%s' (%d)\n", lnkfileA, GetLastError());
817 static void test_datalink(void)
819 static const WCHAR lnk[] = {
820 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
821 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
822 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
823 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
824 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
825 '1','-',']',':',':',0 };
826 static const WCHAR comp[] = {
827 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
828 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
829 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
830 IShellLinkDataList *dl = NULL;
831 IShellLinkW *sl = NULL;
834 EXP_DARWIN_LINK *dar;
836 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
837 &IID_IShellLinkW, (LPVOID*)&sl );
839 broken(r == E_NOINTERFACE), /* Win9x */
840 "CoCreateInstance failed (0x%08x)\n", r);
843 win_skip("no shelllink\n");
847 r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
849 broken(r == E_NOINTERFACE), /* NT4 */
850 "IShellLinkW_QueryInterface failed (0x%08x)\n", r);
854 win_skip("no datalink interface\n");
855 IShellLinkW_Release( sl );
860 r = IShellLinkDataList_GetFlags( dl, &flags );
861 ok( r == S_OK, "GetFlags failed\n");
862 ok( flags == 0, "GetFlags returned wrong flags\n");
865 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
866 ok( r == E_FAIL, "CopyDataBlock failed\n");
867 ok( dar == NULL, "should be null\n");
869 if (!pGetLongPathNameA /* NT4 */)
870 skip("SetPath with NULL parameter crashes on NT4\n");
873 r = IShellLinkW_SetPath(sl, NULL);
874 ok(r == E_INVALIDARG, "SetPath returned wrong error (0x%08x)\n", r);
877 r = IShellLinkW_SetPath(sl, lnk);
878 ok(r == S_OK, "SetPath failed\n");
882 /* the following crashes */
883 IShellLinkDataList_GetFlags( dl, NULL );
887 r = IShellLinkDataList_GetFlags( dl, &flags );
888 ok( r == S_OK, "GetFlags failed\n");
889 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
890 ok( (flags & (~ SLDF_HAS_LOGO3ID)) == SLDF_HAS_DARWINID,
891 "GetFlags returned wrong flags\n");
894 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
895 ok( r == S_OK, "CopyDataBlock failed\n");
897 ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
898 ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
902 IShellLinkDataList_Release( dl );
903 IShellLinkW_Release( sl );
906 static void test_shdefextracticon(void)
908 HICON hiconlarge=NULL, hiconsmall=NULL;
911 if (!pSHDefExtractIconA)
913 win_skip("SHDefExtractIconA is unavailable\n");
917 res = pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge, &hiconsmall, MAKELONG(16,24));
918 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
919 ok(hiconlarge != NULL, "got null hiconlarge\n");
920 ok(hiconsmall != NULL, "got null hiconsmall\n");
921 DestroyIcon(hiconlarge);
922 DestroyIcon(hiconsmall);
925 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, &hiconsmall, MAKELONG(16,24));
926 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
927 ok(hiconsmall != NULL, "got null hiconsmall\n");
928 DestroyIcon(hiconsmall);
930 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, NULL, MAKELONG(16,24));
931 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
934 static void test_GetIconLocation(void)
938 char buffer[INFOTIPSIZE], mypath[MAX_PATH];
943 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
944 &IID_IShellLinkA, (LPVOID*)&sl);
945 ok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
950 strcpy(buffer, "garbage");
951 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
952 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
953 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
954 ok(i == 0, "GetIconLocation returned %d\n", i);
956 str = "c:\\some\\path";
957 r = IShellLinkA_SetPath(sl, str);
958 ok(r == S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
961 strcpy(buffer, "garbage");
962 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
963 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
964 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
965 ok(i == 0, "GetIconLocation returned %d\n", i);
967 GetWindowsDirectoryA(mypath, sizeof(mypath) - 12);
968 strcat(mypath, "\\regedit.exe");
969 pidl = path_to_pidl(mypath);
970 r = IShellLinkA_SetIDList(sl, pidl);
971 ok(r == S_OK, "SetPath failed (0x%08x)\n", r);
975 strcpy(buffer, "garbage");
976 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
977 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
978 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
979 ok(i == 0, "GetIconLocation returned %d\n", i);
981 str = "c:\\nonexistent\\file";
982 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
983 ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
986 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
987 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
988 ok(lstrcmpi(buffer,str) == 0, "GetIconLocation returned '%s'\n", buffer);
989 ok(i == 0xbabecafe, "GetIconLocation returned %d'\n", i);
991 IShellLinkA_Release(sl);
994 static void test_SHGetStockIconInfo(void)
996 BYTE buffer[sizeof(SHSTOCKICONINFO) + 16];
997 SHSTOCKICONINFO *sii = (SHSTOCKICONINFO *) buffer;
1002 /* not present before vista */
1003 if (!pSHGetStockIconInfo)
1005 win_skip("SHGetStockIconInfo not available\n");
1009 /* negative values are handled */
1010 memset(buffer, '#', sizeof(buffer));
1011 sii->cbSize = sizeof(SHSTOCKICONINFO);
1012 hr = pSHGetStockIconInfo(-1, SHGSI_ICONLOCATION, sii);
1013 ok(hr == E_INVALIDARG, "-1: got 0x%x (expected E_INVALIDARG)\n", hr);
1015 /* max. id for vista is 140 (no definition exists for this value) */
1016 for (i = 0; i <= 140; i++)
1018 memset(buffer, '#', sizeof(buffer));
1019 sii->cbSize = sizeof(SHSTOCKICONINFO);
1020 hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii);
1023 "%3d: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x (expected S_OK)\n",
1024 i, hr, sii->iSysImageIndex, sii->iIcon);
1026 if ((hr == S_OK) && (winetest_debug > 1))
1027 trace("%3d: got iSysImageIndex %3d, iIcon %3d and %s\n", i, sii->iSysImageIndex,
1028 sii->iIcon, wine_dbgstr_w(sii->szPath));
1031 /* there are more icons since win7 */
1032 memset(buffer, '#', sizeof(buffer));
1033 sii->cbSize = sizeof(SHSTOCKICONINFO);
1034 hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii);
1035 atleast_win7 = (!hr);
1037 for (; i < (SIID_MAX_ICONS + 25) ; i++)
1039 memset(buffer, '#', sizeof(buffer));
1040 sii->cbSize = sizeof(SHSTOCKICONINFO);
1041 hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii);
1043 if (atleast_win7 && (i == (SIID_MAX_ICONS - 1)) && broken(hr == E_INVALIDARG))
1045 /* off by one windows bug: there are SIID_MAX_ICONS icons from 0 upto
1046 SIID_MAX_ICONS-1 on win8, but the last one is missing on win7 */
1047 trace("%3d: got E_INVALIDARG (windows bug: off by one)\n", i);
1049 else if (atleast_win7 && (i < (SIID_MAX_ICONS)))
1052 "%3d: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x (expected S_OK)\n",
1053 i, hr, sii->iSysImageIndex, sii->iIcon);
1055 if ((hr == S_OK) && (winetest_debug > 1))
1056 trace("%3d: got iSysImageIndex %3d, iIcon %3d and %s\n", i, sii->iSysImageIndex,
1057 sii->iIcon, wine_dbgstr_w(sii->szPath));
1060 ok(hr == E_INVALIDARG, "%3d: got 0x%x (expected E_INVALIDARG)\n", i, hr);
1063 /* test more returned SHSTOCKICONINFO elements without extra flags */
1064 memset(buffer, '#', sizeof(buffer));
1065 sii->cbSize = sizeof(SHSTOCKICONINFO);
1066 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1067 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1068 ok(!sii->hIcon, "got %p (expected NULL)\n", sii->hIcon);
1069 ok(sii->iSysImageIndex == -1, "got %d (expected -1)\n", sii->iSysImageIndex);
1071 /* the exact size is required of the struct */
1072 memset(buffer, '#', sizeof(buffer));
1073 sii->cbSize = sizeof(SHSTOCKICONINFO) + 2;
1074 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1075 ok(hr == E_INVALIDARG, "+2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon);
1077 memset(buffer, '#', sizeof(buffer));
1078 sii->cbSize = sizeof(SHSTOCKICONINFO) + 1;
1079 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1080 ok(hr == E_INVALIDARG, "+1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon);
1082 memset(buffer, '#', sizeof(buffer));
1083 sii->cbSize = sizeof(SHSTOCKICONINFO) - 1;
1084 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1085 ok(hr == E_INVALIDARG, "-1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon);
1087 memset(buffer, '#', sizeof(buffer));
1088 sii->cbSize = sizeof(SHSTOCKICONINFO) - 2;
1089 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1090 ok(hr == E_INVALIDARG, "-2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon);
1092 /* there is a NULL check for the struct */
1093 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, NULL);
1094 ok(hr == E_INVALIDARG, "NULL: got 0x%x\n", hr);
1097 START_TEST(shelllink)
1100 HMODULE hmod = GetModuleHandleA("shell32.dll");
1101 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
1103 pILFree = (void *)GetProcAddress(hmod, (LPSTR)155);
1104 pILIsEqual = (void *)GetProcAddress(hmod, (LPSTR)21);
1105 pSHILCreateFromPath = (void *)GetProcAddress(hmod, (LPSTR)28);
1106 pSHDefExtractIconA = (void *)GetProcAddress(hmod, "SHDefExtractIconA");
1107 pSHGetStockIconInfo = (void *)GetProcAddress(hmod, "SHGetStockIconInfo");
1108 pGetLongPathNameA = (void *)GetProcAddress(hkernel32, "GetLongPathNameA");
1109 pGetShortPathNameA = (void *)GetProcAddress(hkernel32, "GetShortPathNameA");
1111 r = CoInitialize(NULL);
1112 ok(r == S_OK, "CoInitialize failed (0x%08x)\n", r);
1119 test_shdefextracticon();
1120 test_GetIconLocation();
1121 test_SHGetStockIconInfo();