shell32/tests: Test icon ids that are invalid on all systems.
[wine/multimedia.git] / dlls / shell32 / tests / shelllink.c
blob41fac4842e88eafef19a365b01dfe59b56ff2ef9
1 /*
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
22 #define COBJMACROS
24 #include "initguid.h"
25 #include "windows.h"
26 #include "shlguid.h"
27 #include "shobjidl.h"
28 #include "shlobj.h"
29 #include "shellapi.h"
30 #include "wine/test.h"
32 #include "shell32_test.h"
34 #ifndef SLDF_HAS_LOGO3ID
35 # define SLDF_HAS_LOGO3ID 0x00000800 /* not available in the Vista SDK */
36 #endif
38 static void (WINAPI *pILFree)(LPITEMIDLIST);
39 static BOOL (WINAPI *pILIsEqual)(LPCITEMIDLIST, LPCITEMIDLIST);
40 static HRESULT (WINAPI *pSHILCreateFromPath)(LPCWSTR, LPITEMIDLIST *,DWORD*);
41 static HRESULT (WINAPI *pSHDefExtractIconA)(LPCSTR, int, UINT, HICON*, HICON*, UINT);
42 static HRESULT (WINAPI *pSHGetStockIconInfo)(SHSTOCKICONID, UINT, SHSTOCKICONINFO *);
43 static DWORD (WINAPI *pGetLongPathNameA)(LPCSTR, LPSTR, DWORD);
44 static DWORD (WINAPI *pGetShortPathNameA)(LPCSTR, LPSTR, DWORD);
45 static UINT (WINAPI *pSHExtractIconsW)(LPCWSTR, int, int, int, HICON *, UINT *, UINT, UINT);
47 static const GUID _IID_IShellLinkDataList = {
48 0x45e2b4ae, 0xb1c3, 0x11d0,
49 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
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)
61 LPITEMIDLIST pidl;
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");
71 pidl=NULL;
72 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
73 if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
74 pidl=pSHSimpleIDListFromPathAW(path);
76 if (!pidl)
78 WCHAR* pathW;
79 HRESULT r;
80 int len;
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);
90 return pidl;
95 * Test manipulation of an IShellLink's properties.
98 static void test_get_set(void)
100 HRESULT r;
101 IShellLinkA *sl;
102 IShellLinkW *slW = NULL;
103 char mypath[MAX_PATH];
104 char buffer[INFOTIPSIZE];
105 LPITEMIDLIST pidl, tmp_pidl;
106 const char * str;
107 int i;
108 WORD w;
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);
113 if (r != S_OK)
114 return;
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(strcmp(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(strcmp(buffer,str)==0), "GetDescription returned '%s'\n", buffer); /* NT4 */
139 /* Test Getting / Setting the work directory */
140 strcpy(buffer,"garbage");
141 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
142 ok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
143 ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
145 str="c:\\nonexistent\\directory";
146 r = IShellLinkA_SetWorkingDirectory(sl, str);
147 ok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r);
149 strcpy(buffer,"garbage");
150 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
151 ok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
152 ok(lstrcmpiA(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
154 /* Test Getting / Setting the path */
155 strcpy(buffer,"garbage");
156 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
157 todo_wine ok(r == S_FALSE || broken(r == S_OK) /* NT4/W2K */, "GetPath failed (0x%08x)\n", r);
158 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
160 CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
161 &IID_IShellLinkW, (LPVOID*)&slW);
162 if (!slW /* Win9x */ || !pGetLongPathNameA /* NT4 */)
163 skip("SetPath with NULL parameter crashes on Win9x and some NT4\n");
164 else
166 IShellLinkW_Release(slW);
167 r = IShellLinkA_SetPath(sl, NULL);
168 ok(r==E_INVALIDARG ||
169 broken(r==S_OK), /* Some Win95 and NT4 */
170 "SetPath returned wrong error (0x%08x)\n", r);
173 r = IShellLinkA_SetPath(sl, "");
174 ok(r==S_OK, "SetPath failed (0x%08x)\n", r);
176 strcpy(buffer,"garbage");
177 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
178 todo_wine ok(r == S_FALSE, "GetPath failed (0x%08x)\n", r);
179 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
181 /* Win98 returns S_FALSE, but WinXP returns S_OK */
182 str="c:\\nonexistent\\file";
183 r = IShellLinkA_SetPath(sl, str);
184 ok(r==S_FALSE || r==S_OK, "SetPath failed (0x%08x)\n", r);
186 strcpy(buffer,"garbage");
187 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
188 ok(r == S_OK, "GetPath failed (0x%08x)\n", r);
189 ok(lstrcmpiA(buffer,str)==0, "GetPath returned '%s'\n", buffer);
191 /* Get some real path to play with */
192 GetWindowsDirectoryA( mypath, sizeof(mypath)-12 );
193 strcat(mypath, "\\regedit.exe");
195 /* Test the interaction of SetPath and SetIDList */
196 tmp_pidl=NULL;
197 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
198 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
199 if (r == S_OK)
201 BOOL ret;
203 strcpy(buffer,"garbage");
204 ret = SHGetPathFromIDListA(tmp_pidl, buffer);
205 ok(ret, "SHGetPathFromIDListA failed\n");
206 if (ret)
207 ok(lstrcmpiA(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
208 pILFree(tmp_pidl);
211 pidl=path_to_pidl(mypath);
212 ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
214 if (pidl)
216 LPITEMIDLIST second_pidl;
218 r = IShellLinkA_SetIDList(sl, pidl);
219 ok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
221 tmp_pidl=NULL;
222 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
223 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
224 ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
225 "GetIDList returned an incorrect pidl\n");
227 r = IShellLinkA_GetIDList(sl, &second_pidl);
228 ok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
229 ok(second_pidl && pILIsEqual(pidl, second_pidl),
230 "GetIDList returned an incorrect pidl\n");
231 ok(second_pidl != tmp_pidl, "pidls are the same\n");
233 pILFree(second_pidl);
234 pILFree(tmp_pidl);
235 pILFree(pidl);
237 strcpy(buffer,"garbage");
238 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
239 ok(r == S_OK, "GetPath failed (0x%08x)\n", r);
240 todo_wine
241 ok(lstrcmpiA(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
244 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
245 r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
246 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
248 strcpy(buffer,"garbage");
249 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
250 ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
251 ok(!strcmp(buffer, "C:\\nonexistent\\file") ||
252 broken(!strcmp(buffer, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
253 "case doesn't match\n");
255 r = IShellLinkA_SetPath(sl, "\"c:\\foo");
256 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
258 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
259 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
261 r = IShellLinkA_SetPath(sl, "c:\\foo\"");
262 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
264 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
265 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
267 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
268 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
270 /* Test Getting / Setting the arguments */
271 strcpy(buffer,"garbage");
272 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
273 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
274 ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
276 str="param1 \"spaced param2\"";
277 r = IShellLinkA_SetArguments(sl, str);
278 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
280 strcpy(buffer,"garbage");
281 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
282 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
283 ok(strcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
285 strcpy(buffer,"garbage");
286 r = IShellLinkA_SetArguments(sl, NULL);
287 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
288 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
289 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
290 ok(!buffer[0] || strcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
292 strcpy(buffer,"garbage");
293 r = IShellLinkA_SetArguments(sl, "");
294 ok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
295 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
296 ok(r == S_OK, "GetArguments failed (0x%08x)\n", r);
297 ok(!buffer[0], "GetArguments returned '%s'\n", buffer);
299 /* Test Getting / Setting showcmd */
300 i=0xdeadbeef;
301 r = IShellLinkA_GetShowCmd(sl, &i);
302 ok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
303 ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
305 r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
306 ok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
308 i=0xdeadbeef;
309 r = IShellLinkA_GetShowCmd(sl, &i);
310 ok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
311 ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
313 /* Test Getting / Setting the icon */
314 i=0xdeadbeef;
315 strcpy(buffer,"garbage");
316 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
317 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
318 ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
319 ok(i==0, "GetIconLocation returned %d\n", i);
321 str="c:\\nonexistent\\file";
322 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
323 ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
325 i=0xdeadbeef;
326 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
327 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
328 ok(lstrcmpiA(buffer,str)==0, "GetIconLocation returned '%s'\n", buffer);
329 ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
331 /* Test Getting / Setting the hot key */
332 w=0xbeef;
333 r = IShellLinkA_GetHotkey(sl, &w);
334 ok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
335 ok(w==0, "GetHotkey returned %d\n", w);
337 r = IShellLinkA_SetHotkey(sl, 0x5678);
338 ok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
340 w=0xbeef;
341 r = IShellLinkA_GetHotkey(sl, &w);
342 ok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
343 ok(w==0x5678, "GetHotkey returned %d'\n", w);
345 IShellLinkA_Release(sl);
350 * Test saving and loading .lnk files
353 #define lok ok_(__FILE__, line)
354 #define lok_todo_4(todo_flag,a,b,c,d) \
355 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
356 else todo_wine lok((a), (b), (c), (d));
357 #define lok_todo_2(todo_flag,a,b) \
358 if ((todo & todo_flag) == 0) lok((a), (b)); \
359 else todo_wine lok((a), (b));
360 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
362 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
364 HRESULT r;
365 IShellLinkA *sl;
366 IPersistFile *pf;
368 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
369 &IID_IShellLinkA, (LPVOID*)&sl);
370 lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
371 if (r != S_OK)
372 return;
374 if (desc->description)
376 r = IShellLinkA_SetDescription(sl, desc->description);
377 lok(r == S_OK, "SetDescription failed (0x%08x)\n", r);
379 if (desc->workdir)
381 r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
382 lok(r == S_OK, "SetWorkingDirectory failed (0x%08x)\n", r);
384 if (desc->path)
386 r = IShellLinkA_SetPath(sl, desc->path);
387 lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
389 if (desc->pidl)
391 r = IShellLinkA_SetIDList(sl, desc->pidl);
392 lok(r == S_OK, "SetIDList failed (0x%08x)\n", r);
394 if (desc->arguments)
396 r = IShellLinkA_SetArguments(sl, desc->arguments);
397 lok(r == S_OK, "SetArguments failed (0x%08x)\n", r);
399 if (desc->showcmd)
401 r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
402 lok(r == S_OK, "SetShowCmd failed (0x%08x)\n", r);
404 if (desc->icon)
406 r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
407 lok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
409 if (desc->hotkey)
411 r = IShellLinkA_SetHotkey(sl, desc->hotkey);
412 lok(r == S_OK, "SetHotkey failed (0x%08x)\n", r);
415 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (void**)&pf);
416 lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
417 if (r == S_OK)
419 LPOLESTR str;
421 if (0)
423 /* crashes on XP */
424 IPersistFile_GetCurFile(pf, NULL);
427 /* test GetCurFile before ::Save */
428 str = (LPWSTR)0xdeadbeef;
429 r = IPersistFile_GetCurFile(pf, &str);
430 lok(r == S_FALSE ||
431 broken(r == S_OK), /* shell32 < 5.0 */
432 "got 0x%08x\n", r);
433 lok(str == NULL, "got %p\n", str);
435 r = IPersistFile_Save(pf, path, TRUE);
436 if (save_fails)
438 todo_wine {
439 lok(r == S_OK, "save failed (0x%08x)\n", r);
442 else
444 lok(r == S_OK, "save failed (0x%08x)\n", r);
447 /* test GetCurFile after ::Save */
448 r = IPersistFile_GetCurFile(pf, &str);
449 lok(r == S_OK, "got 0x%08x\n", r);
450 lok(str != NULL ||
451 broken(str == NULL), /* shell32 < 5.0 */
452 "Didn't expect NULL\n");
453 if (str != NULL)
455 IMalloc *pmalloc;
457 lok(!winetest_strcmpW(path, str), "Expected %s, got %s\n",
458 wine_dbgstr_w(path), wine_dbgstr_w(str));
460 SHGetMalloc(&pmalloc);
461 IMalloc_Free(pmalloc, str);
463 else
464 win_skip("GetCurFile fails on shell32 < 5.0\n");
466 IPersistFile_Release(pf);
469 IShellLinkA_Release(sl);
472 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int todo)
474 HRESULT r;
475 IShellLinkA *sl;
476 IPersistFile *pf;
477 char buffer[INFOTIPSIZE];
478 LPOLESTR str;
480 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
481 &IID_IShellLinkA, (LPVOID*)&sl);
482 lok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
483 if (r != S_OK)
484 return;
486 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
487 lok(r == S_OK, "no IID_IPersistFile (0x%08x)\n", r);
488 if (r != S_OK)
490 IShellLinkA_Release(sl);
491 return;
494 /* test GetCurFile before ::Load */
495 str = (LPWSTR)0xdeadbeef;
496 r = IPersistFile_GetCurFile(pf, &str);
497 lok(r == S_FALSE ||
498 broken(r == S_OK), /* shell32 < 5.0 */
499 "got 0x%08x\n", r);
500 lok(str == NULL, "got %p\n", str);
502 r = IPersistFile_Load(pf, path, STGM_READ);
503 lok(r == S_OK, "load failed (0x%08x)\n", r);
505 /* test GetCurFile after ::Save */
506 r = IPersistFile_GetCurFile(pf, &str);
507 lok(r == S_OK, "got 0x%08x\n", r);
508 lok(str != NULL ||
509 broken(str == NULL), /* shell32 < 5.0 */
510 "Didn't expect NULL\n");
511 if (str != NULL)
513 IMalloc *pmalloc;
515 lok(!winetest_strcmpW(path, str), "Expected %s, got %s\n",
516 wine_dbgstr_w(path), wine_dbgstr_w(str));
518 SHGetMalloc(&pmalloc);
519 IMalloc_Free(pmalloc, str);
521 else
522 win_skip("GetCurFile fails on shell32 < 5.0\n");
524 IPersistFile_Release(pf);
525 if (r != S_OK)
527 IShellLinkA_Release(sl);
528 return;
531 if (desc->description)
533 strcpy(buffer,"garbage");
534 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
535 lok(r == S_OK, "GetDescription failed (0x%08x)\n", r);
536 lok_todo_4(0x1, strcmp(buffer, desc->description)==0,
537 "GetDescription returned '%s' instead of '%s'\n",
538 buffer, desc->description);
540 if (desc->workdir)
542 strcpy(buffer,"garbage");
543 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
544 lok(r == S_OK, "GetWorkingDirectory failed (0x%08x)\n", r);
545 lok_todo_4(0x2, lstrcmpiA(buffer, desc->workdir)==0,
546 "GetWorkingDirectory returned '%s' instead of '%s'\n",
547 buffer, desc->workdir);
549 if (desc->path)
551 strcpy(buffer,"garbage");
552 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
553 lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
554 lok_todo_4(0x4, lstrcmpiA(buffer, desc->path)==0,
555 "GetPath returned '%s' instead of '%s'\n",
556 buffer, desc->path);
558 if (desc->pidl)
560 LPITEMIDLIST pidl=NULL;
561 r = IShellLinkA_GetIDList(sl, &pidl);
562 lok(r == S_OK, "GetIDList failed (0x%08x)\n", r);
563 lok_todo_2(0x8, pILIsEqual(pidl, desc->pidl),
564 "GetIDList returned an incorrect pidl\n");
566 if (desc->showcmd)
568 int i=0xdeadbeef;
569 r = IShellLinkA_GetShowCmd(sl, &i);
570 lok(r == S_OK, "GetShowCmd failed (0x%08x)\n", r);
571 lok_todo_4(0x10, i==desc->showcmd,
572 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
573 i, desc->showcmd);
575 if (desc->icon)
577 int i=0xdeadbeef;
578 strcpy(buffer,"garbage");
579 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
580 lok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
581 lok_todo_4(0x20, lstrcmpiA(buffer, desc->icon)==0,
582 "GetIconLocation returned '%s' instead of '%s'\n",
583 buffer, desc->icon);
584 lok_todo_4(0x20, i==desc->icon_id,
585 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
586 i, desc->icon_id);
588 if (desc->hotkey)
590 WORD i=0xbeef;
591 r = IShellLinkA_GetHotkey(sl, &i);
592 lok(r == S_OK, "GetHotkey failed (0x%08x)\n", r);
593 lok_todo_4(0x40, i==desc->hotkey,
594 "GetHotkey returned 0x%04x instead of 0x%04x\n",
595 i, desc->hotkey);
598 IShellLinkA_Release(sl);
601 static void test_load_save(void)
603 WCHAR lnkfile[MAX_PATH];
604 char lnkfileA[MAX_PATH];
605 static const char lnkfileA_name[] = "\\test.lnk";
607 lnk_desc_t desc;
608 char mypath[MAX_PATH];
609 char mydir[MAX_PATH];
610 char realpath[MAX_PATH];
611 char* p;
612 HANDLE hf;
613 DWORD r;
615 if (!pGetLongPathNameA)
617 win_skip("GetLongPathNameA is not available\n");
618 return;
621 /* Don't used a fixed path for the test.lnk file */
622 GetTempPathA(MAX_PATH, lnkfileA);
623 lstrcatA(lnkfileA, lnkfileA_name);
624 MultiByteToWideChar(CP_ACP, 0, lnkfileA, -1, lnkfile, MAX_PATH);
626 /* Save an empty .lnk file */
627 memset(&desc, 0, sizeof(desc));
628 create_lnk(lnkfile, &desc, 0);
630 /* It should come back as a bunch of empty strings */
631 desc.description="";
632 desc.workdir="";
633 desc.path="";
634 desc.arguments="";
635 desc.icon="";
636 check_lnk(lnkfile, &desc, 0x0);
638 /* Point a .lnk file to nonexistent files */
639 desc.description="";
640 desc.workdir="c:\\Nonexitent\\work\\directory";
641 desc.path="c:\\nonexistent\\path";
642 desc.pidl=NULL;
643 desc.arguments="";
644 desc.showcmd=0;
645 desc.icon="c:\\nonexistent\\icon\\file";
646 desc.icon_id=1234;
647 desc.hotkey=0;
648 create_lnk(lnkfile, &desc, 0);
649 check_lnk(lnkfile, &desc, 0x0);
651 r=GetModuleFileNameA(NULL, mypath, sizeof(mypath));
652 ok(r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
653 strcpy(mydir, mypath);
654 p=strrchr(mydir, '\\');
655 if (p)
656 *p='\0';
658 /* IShellLink returns path in long form */
659 if (!pGetLongPathNameA(mypath, realpath, MAX_PATH)) strcpy( realpath, mypath );
661 /* Overwrite the existing lnk file and point it to existing files */
662 desc.description="test 2";
663 desc.workdir=mydir;
664 desc.path=realpath;
665 desc.pidl=NULL;
666 desc.arguments="/option1 /option2 \"Some string\"";
667 desc.showcmd=SW_SHOWNORMAL;
668 desc.icon=mypath;
669 desc.icon_id=0;
670 desc.hotkey=0x1234;
671 create_lnk(lnkfile, &desc, 0);
672 check_lnk(lnkfile, &desc, 0x0);
674 /* Test omitting .exe from an absolute path */
675 p=strrchr(realpath, '.');
676 if (p)
677 *p='\0';
679 desc.description="absolute path without .exe";
680 desc.workdir=mydir;
681 desc.path=realpath;
682 desc.pidl=NULL;
683 desc.arguments="/option1 /option2 \"Some string\"";
684 desc.showcmd=SW_SHOWNORMAL;
685 desc.icon=mypath;
686 desc.icon_id=0;
687 desc.hotkey=0x1234;
688 create_lnk(lnkfile, &desc, 0);
689 strcat(realpath, ".exe");
690 check_lnk(lnkfile, &desc, 0x4);
692 /* Overwrite the existing lnk file and test link to a command on the path */
693 desc.description="command on path";
694 desc.workdir=mypath;
695 desc.path="rundll32.exe";
696 desc.pidl=NULL;
697 desc.arguments="/option1 /option2 \"Some string\"";
698 desc.showcmd=SW_SHOWNORMAL;
699 desc.icon=mypath;
700 desc.icon_id=0;
701 desc.hotkey=0x1234;
702 create_lnk(lnkfile, &desc, 0);
703 /* Check that link is created to proper location */
704 SearchPathA( NULL, desc.path, NULL, MAX_PATH, realpath, NULL);
705 desc.path=realpath;
706 check_lnk(lnkfile, &desc, 0x0);
708 /* Test omitting .exe from a command on the path */
709 desc.description="command on path without .exe";
710 desc.workdir=mypath;
711 desc.path="rundll32";
712 desc.pidl=NULL;
713 desc.arguments="/option1 /option2 \"Some string\"";
714 desc.showcmd=SW_SHOWNORMAL;
715 desc.icon=mypath;
716 desc.icon_id=0;
717 desc.hotkey=0x1234;
718 create_lnk(lnkfile, &desc, 0);
719 /* Check that link is created to proper location */
720 SearchPathA( NULL, "rundll32", NULL, MAX_PATH, realpath, NULL);
721 desc.path=realpath;
722 check_lnk(lnkfile, &desc, 0x4);
724 /* Create a temporary non-executable file */
725 r=GetTempPathA(sizeof(mypath), mypath);
726 ok(r<sizeof(mypath), "GetTempPath failed (%d), err %d\n", r, GetLastError());
727 r=pGetLongPathNameA(mypath, mydir, sizeof(mydir));
728 ok(r<sizeof(mydir), "GetLongPathName failed (%d), err %d\n", r, GetLastError());
729 p=strrchr(mydir, '\\');
730 if (p)
731 *p='\0';
733 strcpy(mypath, mydir);
734 strcat(mypath, "\\test.txt");
735 hf = CreateFileA(mypath, GENERIC_WRITE, 0, NULL,
736 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
737 CloseHandle(hf);
739 /* Overwrite the existing lnk file and test link to an existing non-executable file */
740 desc.description="non-executable file";
741 desc.workdir=mydir;
742 desc.path=mypath;
743 desc.pidl=NULL;
744 desc.arguments="";
745 desc.showcmd=SW_SHOWNORMAL;
746 desc.icon=mypath;
747 desc.icon_id=0;
748 desc.hotkey=0x1234;
749 create_lnk(lnkfile, &desc, 0);
750 check_lnk(lnkfile, &desc, 0x0);
752 r=pGetShortPathNameA(mydir, mypath, sizeof(mypath));
753 ok(r<sizeof(mypath), "GetShortPathName failed (%d), err %d\n", r, GetLastError());
755 strcpy(realpath, mypath);
756 strcat(realpath, "\\test.txt");
757 strcat(mypath, "\\\\test.txt");
759 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
760 desc.description="non-executable file";
761 desc.workdir=mydir;
762 desc.path=mypath;
763 desc.pidl=NULL;
764 desc.arguments="";
765 desc.showcmd=SW_SHOWNORMAL;
766 desc.icon=mypath;
767 desc.icon_id=0;
768 desc.hotkey=0x1234;
769 create_lnk(lnkfile, &desc, 0);
770 desc.path=realpath;
771 check_lnk(lnkfile, &desc, 0x0);
773 r = DeleteFileA(mypath);
774 ok(r, "failed to delete file %s (%d)\n", mypath, GetLastError());
776 /* Create a temporary .bat file */
777 strcpy(mypath, mydir);
778 strcat(mypath, "\\test.bat");
779 hf = CreateFileA(mypath, GENERIC_WRITE, 0, NULL,
780 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
781 CloseHandle(hf);
783 strcpy(realpath, mypath);
785 p=strrchr(mypath, '.');
786 if (p)
787 *p='\0';
789 /* Try linking to the .bat file without the extension */
790 desc.description="batch file";
791 desc.workdir=mydir;
792 desc.path=mypath;
793 desc.pidl=NULL;
794 desc.arguments="";
795 desc.showcmd=SW_SHOWNORMAL;
796 desc.icon=mypath;
797 desc.icon_id=0;
798 desc.hotkey=0x1234;
799 create_lnk(lnkfile, &desc, 0);
800 desc.path = realpath;
801 check_lnk(lnkfile, &desc, 0x4);
803 r = DeleteFileA(realpath);
804 ok(r, "failed to delete file %s (%d)\n", realpath, GetLastError());
806 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
807 * represented as a path.
810 /* DeleteFileW is not implemented on Win9x */
811 r=DeleteFileA(lnkfileA);
812 ok(r, "failed to delete link '%s' (%d)\n", lnkfileA, GetLastError());
815 static void test_datalink(void)
817 static const WCHAR lnk[] = {
818 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
819 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
820 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
821 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
822 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
823 '1','-',']',':',':',0 };
824 static const WCHAR comp[] = {
825 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
826 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
827 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
828 IShellLinkDataList *dl = NULL;
829 IShellLinkW *sl = NULL;
830 HRESULT r;
831 DWORD flags = 0;
832 EXP_DARWIN_LINK *dar;
834 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
835 &IID_IShellLinkW, (LPVOID*)&sl );
836 ok( r == S_OK ||
837 broken(r == E_NOINTERFACE), /* Win9x */
838 "CoCreateInstance failed (0x%08x)\n", r);
839 if (!sl)
841 win_skip("no shelllink\n");
842 return;
845 r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
846 ok( r == S_OK ||
847 broken(r == E_NOINTERFACE), /* NT4 */
848 "IShellLinkW_QueryInterface failed (0x%08x)\n", r);
850 if (!dl)
852 win_skip("no datalink interface\n");
853 IShellLinkW_Release( sl );
854 return;
857 flags = 0;
858 r = IShellLinkDataList_GetFlags( dl, &flags );
859 ok( r == S_OK, "GetFlags failed\n");
860 ok( flags == 0, "GetFlags returned wrong flags\n");
862 dar = (void*)-1;
863 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
864 ok( r == E_FAIL, "CopyDataBlock failed\n");
865 ok( dar == NULL, "should be null\n");
867 if (!pGetLongPathNameA /* NT4 */)
868 skip("SetPath with NULL parameter crashes on NT4\n");
869 else
871 r = IShellLinkW_SetPath(sl, NULL);
872 ok(r == E_INVALIDARG, "SetPath returned wrong error (0x%08x)\n", r);
875 r = IShellLinkW_SetPath(sl, lnk);
876 ok(r == S_OK, "SetPath failed\n");
878 if (0)
880 /* the following crashes */
881 IShellLinkDataList_GetFlags( dl, NULL );
884 flags = 0;
885 r = IShellLinkDataList_GetFlags( dl, &flags );
886 ok( r == S_OK, "GetFlags failed\n");
887 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
888 ok( (flags & (~ SLDF_HAS_LOGO3ID)) == SLDF_HAS_DARWINID,
889 "GetFlags returned wrong flags\n");
891 dar = NULL;
892 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
893 ok( r == S_OK, "CopyDataBlock failed\n");
895 ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
896 ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
898 LocalFree( dar );
900 IShellLinkDataList_Release( dl );
901 IShellLinkW_Release( sl );
904 static void test_shdefextracticon(void)
906 HICON hiconlarge=NULL, hiconsmall=NULL;
907 HRESULT res;
909 if (!pSHDefExtractIconA)
911 win_skip("SHDefExtractIconA is unavailable\n");
912 return;
915 res = pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge, &hiconsmall, MAKELONG(16,24));
916 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
917 ok(hiconlarge != NULL, "got null hiconlarge\n");
918 ok(hiconsmall != NULL, "got null hiconsmall\n");
919 DestroyIcon(hiconlarge);
920 DestroyIcon(hiconsmall);
922 hiconsmall = NULL;
923 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, &hiconsmall, MAKELONG(16,24));
924 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
925 ok(hiconsmall != NULL, "got null hiconsmall\n");
926 DestroyIcon(hiconsmall);
928 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, NULL, MAKELONG(16,24));
929 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
932 static void test_GetIconLocation(void)
934 IShellLinkA *sl;
935 const char *str;
936 char buffer[INFOTIPSIZE], mypath[MAX_PATH];
937 int i;
938 HRESULT r;
939 LPITEMIDLIST pidl;
941 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
942 &IID_IShellLinkA, (LPVOID*)&sl);
943 ok(r == S_OK, "no IID_IShellLinkA (0x%08x)\n", r);
944 if(r != S_OK)
945 return;
947 i = 0xdeadbeef;
948 strcpy(buffer, "garbage");
949 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
950 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
951 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
952 ok(i == 0, "GetIconLocation returned %d\n", i);
954 str = "c:\\some\\path";
955 r = IShellLinkA_SetPath(sl, str);
956 ok(r == S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
958 i = 0xdeadbeef;
959 strcpy(buffer, "garbage");
960 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
961 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
962 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
963 ok(i == 0, "GetIconLocation returned %d\n", i);
965 GetWindowsDirectoryA(mypath, sizeof(mypath) - 12);
966 strcat(mypath, "\\regedit.exe");
967 pidl = path_to_pidl(mypath);
968 r = IShellLinkA_SetIDList(sl, pidl);
969 ok(r == S_OK, "SetPath failed (0x%08x)\n", r);
970 pILFree(pidl);
972 i = 0xdeadbeef;
973 strcpy(buffer, "garbage");
974 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
975 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
976 ok(*buffer == '\0', "GetIconLocation returned '%s'\n", buffer);
977 ok(i == 0, "GetIconLocation returned %d\n", i);
979 str = "c:\\nonexistent\\file";
980 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
981 ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
983 i = 0xdeadbeef;
984 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
985 ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
986 ok(lstrcmpiA(buffer,str) == 0, "GetIconLocation returned '%s'\n", buffer);
987 ok(i == 0xbabecafe, "GetIconLocation returned %d'\n", i);
989 IShellLinkA_Release(sl);
992 static void test_SHGetStockIconInfo(void)
994 BYTE buffer[sizeof(SHSTOCKICONINFO) + 16];
995 SHSTOCKICONINFO *sii = (SHSTOCKICONINFO *) buffer;
996 HRESULT hr;
997 INT i;
999 /* not present before vista */
1000 if (!pSHGetStockIconInfo)
1002 win_skip("SHGetStockIconInfo not available\n");
1003 return;
1006 /* negative values are handled */
1007 memset(buffer, '#', sizeof(buffer));
1008 sii->cbSize = sizeof(SHSTOCKICONINFO);
1009 hr = pSHGetStockIconInfo(SIID_INVALID, SHGSI_ICONLOCATION, sii);
1010 ok(hr == E_INVALIDARG, "-1: got 0x%x (expected E_INVALIDARG)\n", hr);
1012 /* max. id for vista is 140 (no definition exists for this value) */
1013 for (i = SIID_DOCNOASSOC; i <= SIID_CLUSTEREDDRIVE; i++)
1015 memset(buffer, '#', sizeof(buffer));
1016 sii->cbSize = sizeof(SHSTOCKICONINFO);
1017 hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii);
1019 ok(hr == S_OK,
1020 "%3d: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x (expected S_OK)\n",
1021 i, hr, sii->iSysImageIndex, sii->iIcon);
1023 if ((hr == S_OK) && (winetest_debug > 1))
1024 trace("%3d: got iSysImageIndex %3d, iIcon %3d and %s\n", i, sii->iSysImageIndex,
1025 sii->iIcon, wine_dbgstr_w(sii->szPath));
1028 /* test invalid icons indices that are invalid for all platforms */
1029 for (i = SIID_MAX_ICONS; i < (SIID_MAX_ICONS + 25) ; i++)
1031 memset(buffer, '#', sizeof(buffer));
1032 sii->cbSize = sizeof(SHSTOCKICONINFO);
1033 hr = pSHGetStockIconInfo(i, SHGSI_ICONLOCATION, sii);
1034 ok(hr == E_INVALIDARG, "%3d: got 0x%x (expected E_INVALIDARG)\n", i, hr);
1035 todo_wine {
1036 ok(sii->iSysImageIndex == -1, "%d: got iSysImageIndex %d\n", i, sii->iSysImageIndex);
1037 ok(sii->iIcon == -1, "%d: got iIcon %d\n", i, sii->iIcon);
1041 /* test more returned SHSTOCKICONINFO elements without extra flags */
1042 memset(buffer, '#', sizeof(buffer));
1043 sii->cbSize = sizeof(SHSTOCKICONINFO);
1044 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1045 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1046 ok(!sii->hIcon, "got %p (expected NULL)\n", sii->hIcon);
1047 ok(sii->iSysImageIndex == -1, "got %d (expected -1)\n", sii->iSysImageIndex);
1049 /* the exact size is required of the struct */
1050 memset(buffer, '#', sizeof(buffer));
1051 sii->cbSize = sizeof(SHSTOCKICONINFO) + 2;
1052 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1053 ok(hr == E_INVALIDARG, "+2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon);
1055 memset(buffer, '#', sizeof(buffer));
1056 sii->cbSize = sizeof(SHSTOCKICONINFO) + 1;
1057 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1058 ok(hr == E_INVALIDARG, "+1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon);
1060 memset(buffer, '#', sizeof(buffer));
1061 sii->cbSize = sizeof(SHSTOCKICONINFO) - 1;
1062 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1063 ok(hr == E_INVALIDARG, "-1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon);
1065 memset(buffer, '#', sizeof(buffer));
1066 sii->cbSize = sizeof(SHSTOCKICONINFO) - 2;
1067 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, sii);
1068 ok(hr == E_INVALIDARG, "-2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr, sii->iSysImageIndex, sii->iIcon);
1070 /* there is a NULL check for the struct */
1071 hr = pSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICONLOCATION, NULL);
1072 ok(hr == E_INVALIDARG, "NULL: got 0x%x\n", hr);
1075 static void test_SHExtractIcons(void)
1077 static const WCHAR notepadW[] = {'n','o','t','e','p','a','d','.','e','x','e',0};
1078 static const WCHAR shell32W[] = {'s','h','e','l','l','3','2','.','d','l','l',0};
1079 static const WCHAR emptyW[] = {0};
1080 UINT ret, ret2;
1081 HICON icons[256];
1082 UINT ids[256], i;
1084 if (!pSHExtractIconsW)
1086 win_skip("SHExtractIconsW not available\n");
1087 return;
1090 ret = pSHExtractIconsW(emptyW, 0, 16, 16, icons, ids, 1, 0);
1091 ok(ret == ~0u, "got %u\n", ret);
1093 ret = pSHExtractIconsW(notepadW, 0, 16, 16, NULL, NULL, 1, 0);
1094 ok(ret == 1 || broken(ret == 2) /* win2k */, "got %u\n", ret);
1096 icons[0] = (HICON)0xdeadbeef;
1097 ret = pSHExtractIconsW(notepadW, 0, 16, 16, icons, NULL, 1, 0);
1098 ok(ret == 1, "got %u\n", ret);
1099 ok(icons[0] != (HICON)0xdeadbeef, "icon not set\n");
1100 DestroyIcon(icons[0]);
1102 icons[0] = (HICON)0xdeadbeef;
1103 ids[0] = 0xdeadbeef;
1104 ret = pSHExtractIconsW(notepadW, 0, 16, 16, icons, ids, 1, 0);
1105 ok(ret == 1, "got %u\n", ret);
1106 ok(icons[0] != (HICON)0xdeadbeef, "icon not set\n");
1107 ok(ids[0] != 0xdeadbeef, "id not set\n");
1108 DestroyIcon(icons[0]);
1110 ret = pSHExtractIconsW(shell32W, 0, 16, 16, NULL, NULL, 0, 0);
1111 ret2 = pSHExtractIconsW(shell32W, 4, MAKELONG(32,16), MAKELONG(32,16), NULL, NULL, 256, 0);
1112 ok(ret && ret == ret2,
1113 "icon count should be independent of requested icon sizes and base icon index\n");
1115 ret = pSHExtractIconsW(shell32W, 0, 16, 16, icons, ids, 0, 0);
1116 ok(ret == ~0u || !ret /* < vista */, "got %u\n", ret);
1118 ret = pSHExtractIconsW(shell32W, 0, 16, 16, icons, ids, 3, 0);
1119 ok(ret == 3, "got %u\n", ret);
1120 for (i = 0; i < ret; i++) DestroyIcon(icons[i]);
1122 /* count must be a multiple of two when getting two sizes */
1123 ret = pSHExtractIconsW(shell32W, 0, MAKELONG(16,32), MAKELONG(16,32), icons, ids, 3, 0);
1124 ok(!ret /* vista */ || ret == 4, "got %u\n", ret);
1125 for (i = 0; i < ret; i++) DestroyIcon(icons[i]);
1127 ret = pSHExtractIconsW(shell32W, 0, MAKELONG(16,32), MAKELONG(16,32), icons, ids, 4, 0);
1128 ok(ret == 4, "got %u\n", ret);
1129 for (i = 0; i < ret; i++) DestroyIcon(icons[i]);
1132 static void test_propertystore(void)
1134 IShellLinkA *linkA;
1135 IShellLinkW *linkW;
1136 IPropertyStore *ps;
1137 HRESULT hr;
1139 hr = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
1140 &IID_IShellLinkA, (void**)&linkA);
1141 ok(hr == S_OK, "got 0x%08x\n", hr);
1143 hr = IShellLinkA_QueryInterface(linkA, &IID_IShellLinkW, (void**)&linkW);
1144 ok(hr == S_OK, "got 0x%08x\n", hr);
1146 hr = IShellLinkA_QueryInterface(linkA, &IID_IPropertyStore, (void**)&ps);
1147 if (hr == S_OK) {
1148 IPropertyStoreCache *pscache;
1150 IPropertyStore_Release(ps);
1152 hr = IShellLinkW_QueryInterface(linkW, &IID_IPropertyStore, (void**)&ps);
1153 ok(hr == S_OK, "got 0x%08x\n", hr);
1155 hr = IPropertyStore_QueryInterface(ps, &IID_IPropertyStoreCache, (void**)&pscache);
1156 ok(hr == E_NOINTERFACE, "got 0x%08x\n", hr);
1158 IPropertyStore_Release(ps);
1160 else
1161 win_skip("IShellLink doesn't support IPropertyStore.\n");
1163 IShellLinkA_Release(linkA);
1164 IShellLinkW_Release(linkW);
1167 START_TEST(shelllink)
1169 HRESULT r;
1170 HMODULE hmod = GetModuleHandleA("shell32.dll");
1171 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
1173 pILFree = (void *)GetProcAddress(hmod, (LPSTR)155);
1174 pILIsEqual = (void *)GetProcAddress(hmod, (LPSTR)21);
1175 pSHILCreateFromPath = (void *)GetProcAddress(hmod, (LPSTR)28);
1176 pSHDefExtractIconA = (void *)GetProcAddress(hmod, "SHDefExtractIconA");
1177 pSHGetStockIconInfo = (void *)GetProcAddress(hmod, "SHGetStockIconInfo");
1178 pGetLongPathNameA = (void *)GetProcAddress(hkernel32, "GetLongPathNameA");
1179 pGetShortPathNameA = (void *)GetProcAddress(hkernel32, "GetShortPathNameA");
1180 pSHExtractIconsW = (void *)GetProcAddress(hmod, "SHExtractIconsW");
1182 r = CoInitialize(NULL);
1183 ok(r == S_OK, "CoInitialize failed (0x%08x)\n", r);
1184 if (r != S_OK)
1185 return;
1187 test_get_set();
1188 test_load_save();
1189 test_datalink();
1190 test_shdefextracticon();
1191 test_GetIconLocation();
1192 test_SHGetStockIconInfo();
1193 test_SHExtractIcons();
1194 test_propertystore();
1196 CoUninitialize();