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
30 #include "commoncontrols.h"
31 #include "wine/test.h"
33 #include "shell32_test.h"
35 #include <reactos/undocshell.h>
37 #ifndef SLDF_HAS_LOGO3ID
38 # define SLDF_HAS_LOGO3ID 0x00000800 /* not available in the Vista SDK */
41 static void (WINAPI
*pILFree
)(LPITEMIDLIST
);
42 static BOOL (WINAPI
*pILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
);
43 static HRESULT (WINAPI
*pSHILCreateFromPath
)(LPCWSTR
, LPITEMIDLIST
*,DWORD
*);
44 static HRESULT (WINAPI
*pSHDefExtractIconA
)(LPCSTR
, int, UINT
, HICON
*, HICON
*, UINT
);
45 static HRESULT (WINAPI
*pSHGetStockIconInfo
)(SHSTOCKICONID
, UINT
, SHSTOCKICONINFO
*);
46 static DWORD (WINAPI
*pGetLongPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
47 static DWORD (WINAPI
*pGetShortPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
48 static UINT (WINAPI
*pSHExtractIconsW
)(LPCWSTR
, int, int, int, HICON
*, UINT
*, UINT
, UINT
);
49 static BOOL (WINAPI
*pIsProcessDPIAware
)(void);
51 static const GUID _IID_IShellLinkDataList
= {
52 0x45e2b4ae, 0xb1c3, 0x11d0,
53 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
57 /* For some reason SHILCreateFromPath does not work on Win98 and
58 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
59 * get what we want on all platforms.
61 static LPITEMIDLIST (WINAPI
*pSHSimpleIDListFromPathAW
)(LPCVOID
);
63 static LPITEMIDLIST
path_to_pidl(const char* path
)
67 if (!pSHSimpleIDListFromPathAW
)
69 HMODULE hdll
=GetModuleHandleA("shell32.dll");
70 pSHSimpleIDListFromPathAW
=(void*)GetProcAddress(hdll
, (char*)162);
71 if (!pSHSimpleIDListFromPathAW
)
72 win_skip("SHSimpleIDListFromPathAW not found in shell32.dll\n");
76 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
77 if (pSHSimpleIDListFromPathAW
&& (GetVersion() & 0x80000000))
78 pidl
=pSHSimpleIDListFromPathAW(path
);
86 len
=MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
87 pathW
=HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
88 MultiByteToWideChar(CP_ACP
, 0, path
, -1, pathW
, len
);
90 r
=pSHILCreateFromPath(pathW
, &pidl
, NULL
);
91 ok(r
== S_OK
, "SHILCreateFromPath failed (0x%08x)\n", r
);
92 HeapFree(GetProcessHeap(), 0, pathW
);
99 * Test manipulation of an IShellLink's properties.
102 static void test_get_set(void)
106 IShellLinkW
*slW
= NULL
;
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(r
== S_OK
, "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(r
== S_OK
, "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(r
== S_OK
, "SetDescription failed (0x%08x)\n", r
);
130 strcpy(buffer
,"garbage");
131 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
132 ok(r
== S_OK
, "GetDescription failed (0x%08x)\n", r
);
133 ok(strcmp(buffer
,str
)==0, "GetDescription returned '%s'\n", buffer
);
135 r
= IShellLinkA_SetDescription(sl
, NULL
);
136 ok(r
== S_OK
, "SetDescription failed (0x%08x)\n", r
);
138 strcpy(buffer
,"garbage");
139 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
140 ok(r
== S_OK
, "GetDescription failed (0x%08x)\n", r
);
141 ok(*buffer
=='\0' || broken(strcmp(buffer
,str
)==0), "GetDescription returned '%s'\n", buffer
); /* NT4 */
143 /* Test Getting / Setting the work directory */
144 strcpy(buffer
,"garbage");
145 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
146 ok(r
== S_OK
, "GetWorkingDirectory failed (0x%08x)\n", r
);
147 ok(*buffer
=='\0', "GetWorkingDirectory returned '%s'\n", buffer
);
149 str
="c:\\nonexistent\\directory";
150 r
= IShellLinkA_SetWorkingDirectory(sl
, str
);
151 ok(r
== S_OK
, "SetWorkingDirectory failed (0x%08x)\n", r
);
153 strcpy(buffer
,"garbage");
154 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
155 ok(r
== S_OK
, "GetWorkingDirectory failed (0x%08x)\n", r
);
156 ok(lstrcmpiA(buffer
,str
)==0, "GetWorkingDirectory returned '%s'\n", buffer
);
158 /* Test Getting / Setting the path */
159 strcpy(buffer
,"garbage");
160 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
161 todo_wine
ok(r
== S_FALSE
|| broken(r
== S_OK
) /* NT4/W2K */, "GetPath failed (0x%08x)\n", r
);
162 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
164 CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
165 &IID_IShellLinkW
, (LPVOID
*)&slW
);
166 if (!slW
/* Win9x */ || !pGetLongPathNameA
/* NT4 */)
167 skip("SetPath with NULL parameter crashes on Win9x and some NT4\n");
170 IShellLinkW_Release(slW
);
171 r
= IShellLinkA_SetPath(sl
, NULL
);
172 ok(r
==E_INVALIDARG
||
173 broken(r
==S_OK
), /* Some Win95 and NT4 */
174 "SetPath returned wrong error (0x%08x)\n", r
);
177 r
= IShellLinkA_SetPath(sl
, "");
178 ok(r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
180 strcpy(buffer
,"garbage");
181 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
182 todo_wine
ok(r
== S_FALSE
, "GetPath failed (0x%08x)\n", r
);
183 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
185 /* Win98 returns S_FALSE, but WinXP returns S_OK */
186 str
="c:\\nonexistent\\file";
187 r
= IShellLinkA_SetPath(sl
, str
);
188 ok(r
==S_FALSE
|| r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
190 strcpy(buffer
,"garbage");
191 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
192 ok(r
== S_OK
, "GetPath failed (0x%08x)\n", r
);
193 ok(lstrcmpiA(buffer
,str
)==0, "GetPath returned '%s'\n", buffer
);
195 /* Get some real path to play with */
196 GetWindowsDirectoryA( mypath
, sizeof(mypath
)-12 );
197 strcat(mypath
, "\\regedit.exe");
199 /* Test the interaction of SetPath and SetIDList */
201 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
202 ok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
207 strcpy(buffer
,"garbage");
208 ret
= SHGetPathFromIDListA(tmp_pidl
, buffer
);
209 ok(ret
, "SHGetPathFromIDListA failed\n");
211 ok(lstrcmpiA(buffer
,str
)==0, "GetIDList returned '%s'\n", buffer
);
215 pidl
=path_to_pidl(mypath
);
216 ok(pidl
!=NULL
, "path_to_pidl returned a NULL pidl\n");
220 LPITEMIDLIST second_pidl
;
222 r
= IShellLinkA_SetIDList(sl
, pidl
);
223 ok(r
== S_OK
, "SetIDList failed (0x%08x)\n", r
);
226 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
227 ok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
228 ok(tmp_pidl
&& pILIsEqual(pidl
, tmp_pidl
),
229 "GetIDList returned an incorrect pidl\n");
231 r
= IShellLinkA_GetIDList(sl
, &second_pidl
);
232 ok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
233 ok(second_pidl
&& pILIsEqual(pidl
, second_pidl
),
234 "GetIDList returned an incorrect pidl\n");
235 ok(second_pidl
!= tmp_pidl
, "pidls are the same\n");
237 pILFree(second_pidl
);
241 strcpy(buffer
,"garbage");
242 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
243 ok(r
== S_OK
, "GetPath failed (0x%08x)\n", r
);
245 ok(lstrcmpiA(buffer
, mypath
)==0, "GetPath returned '%s'\n", buffer
);
248 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
249 r
= IShellLinkA_SetPath(sl
, "\"c:\\nonexistent\\file\"");
250 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
252 strcpy(buffer
,"garbage");
253 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
254 ok(r
==S_OK
, "GetPath failed (0x%08x)\n", r
);
255 todo_wine
ok(!strcmp(buffer
, "C:\\nonexistent\\file") ||
256 broken(!strcmp(buffer
, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
257 "case doesn't match\n");
259 r
= IShellLinkA_SetPath(sl
, "\"c:\\foo");
260 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
262 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo");
263 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
265 r
= IShellLinkA_SetPath(sl
, "c:\\foo\"");
266 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
268 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"");
269 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
271 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"\"");
272 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
274 /* Test Getting / Setting the arguments */
275 strcpy(buffer
,"garbage");
276 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
277 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
278 ok(*buffer
=='\0', "GetArguments returned '%s'\n", buffer
);
280 str
="param1 \"spaced param2\"";
281 r
= IShellLinkA_SetArguments(sl
, str
);
282 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
284 strcpy(buffer
,"garbage");
285 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
286 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
287 ok(strcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
289 strcpy(buffer
,"garbage");
290 r
= IShellLinkA_SetArguments(sl
, NULL
);
291 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
292 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
293 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
294 ok(!buffer
[0] || strcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
296 strcpy(buffer
,"garbage");
297 r
= IShellLinkA_SetArguments(sl
, "");
298 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
299 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
300 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
301 ok(!buffer
[0], "GetArguments returned '%s'\n", buffer
);
303 /* Test Getting / Setting showcmd */
305 r
= IShellLinkA_GetShowCmd(sl
, &i
);
306 ok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
307 ok(i
==SW_SHOWNORMAL
, "GetShowCmd returned %d\n", i
);
309 r
= IShellLinkA_SetShowCmd(sl
, SW_SHOWMAXIMIZED
);
310 ok(r
== S_OK
, "SetShowCmd failed (0x%08x)\n", r
);
313 r
= IShellLinkA_GetShowCmd(sl
, &i
);
314 ok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
315 ok(i
==SW_SHOWMAXIMIZED
, "GetShowCmd returned %d'\n", i
);
317 /* Test Getting / Setting the icon */
319 strcpy(buffer
,"garbage");
320 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
321 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
322 ok(*buffer
=='\0', "GetIconLocation returned '%s'\n", buffer
);
323 ok(i
==0, "GetIconLocation returned %d\n", i
);
325 str
="c:\\nonexistent\\file";
326 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
327 ok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
330 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
331 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
332 ok(lstrcmpiA(buffer
,str
)==0, "GetIconLocation returned '%s'\n", buffer
);
333 ok(i
==0xbabecafe, "GetIconLocation returned %d'\n", i
);
335 /* Test Getting / Setting the hot key */
337 r
= IShellLinkA_GetHotkey(sl
, &w
);
338 ok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
339 ok(w
==0, "GetHotkey returned %d\n", w
);
341 r
= IShellLinkA_SetHotkey(sl
, 0x5678);
342 ok(r
== S_OK
, "SetHotkey failed (0x%08x)\n", r
);
345 r
= IShellLinkA_GetHotkey(sl
, &w
);
346 ok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
347 ok(w
==0x5678, "GetHotkey returned %d'\n", w
);
349 IShellLinkA_Release(sl
);
354 * Test saving and loading .lnk files
357 #define lok ok_(__FILE__, line)
358 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
360 void create_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int save_fails
)
366 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
367 &IID_IShellLinkA
, (LPVOID
*)&sl
);
368 lok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
372 if (desc
->description
)
374 r
= IShellLinkA_SetDescription(sl
, desc
->description
);
375 lok(r
== S_OK
, "SetDescription failed (0x%08x)\n", r
);
379 r
= IShellLinkA_SetWorkingDirectory(sl
, desc
->workdir
);
380 lok(r
== S_OK
, "SetWorkingDirectory failed (0x%08x)\n", r
);
384 r
= IShellLinkA_SetPath(sl
, desc
->path
);
385 lok(SUCCEEDED(r
), "SetPath failed (0x%08x)\n", r
);
389 r
= IShellLinkA_SetIDList(sl
, desc
->pidl
);
390 lok(r
== S_OK
, "SetIDList failed (0x%08x)\n", r
);
394 r
= IShellLinkA_SetArguments(sl
, desc
->arguments
);
395 lok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
399 r
= IShellLinkA_SetShowCmd(sl
, desc
->showcmd
);
400 lok(r
== S_OK
, "SetShowCmd failed (0x%08x)\n", r
);
404 r
= IShellLinkA_SetIconLocation(sl
, desc
->icon
, desc
->icon_id
);
405 lok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
409 r
= IShellLinkA_SetHotkey(sl
, desc
->hotkey
);
410 lok(r
== S_OK
, "SetHotkey failed (0x%08x)\n", r
);
413 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (void**)&pf
);
414 lok(r
== S_OK
, "no IID_IPersistFile (0x%08x)\n", r
);
422 IPersistFile_GetCurFile(pf
, NULL
);
425 /* test GetCurFile before ::Save */
426 str
= (LPWSTR
)0xdeadbeef;
427 r
= IPersistFile_GetCurFile(pf
, &str
);
429 broken(r
== S_OK
), /* shell32 < 5.0 */
431 lok(str
== NULL
, "got %p\n", str
);
433 r
= IPersistFile_Save(pf
, path
, TRUE
);
434 todo_wine_if (save_fails
)
435 lok(r
== S_OK
, "save failed (0x%08x)\n", r
);
437 /* test GetCurFile after ::Save */
438 r
= IPersistFile_GetCurFile(pf
, &str
);
439 lok(r
== S_OK
, "got 0x%08x\n", r
);
441 broken(str
== NULL
), /* shell32 < 5.0 */
442 "Didn't expect NULL\n");
447 lok(!winetest_strcmpW(path
, str
), "Expected %s, got %s\n",
448 wine_dbgstr_w(path
), wine_dbgstr_w(str
));
450 SHGetMalloc(&pmalloc
);
451 IMalloc_Free(pmalloc
, str
);
454 win_skip("GetCurFile fails on shell32 < 5.0\n");
456 IPersistFile_Release(pf
);
459 IShellLinkA_Release(sl
);
462 static void check_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int todo
)
467 char buffer
[INFOTIPSIZE
];
470 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
471 &IID_IShellLinkA
, (LPVOID
*)&sl
);
472 lok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
476 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
477 lok(r
== S_OK
, "no IID_IPersistFile (0x%08x)\n", r
);
480 IShellLinkA_Release(sl
);
484 /* test GetCurFile before ::Load */
485 str
= (LPWSTR
)0xdeadbeef;
486 r
= IPersistFile_GetCurFile(pf
, &str
);
488 broken(r
== S_OK
), /* shell32 < 5.0 */
490 lok(str
== NULL
, "got %p\n", str
);
492 r
= IPersistFile_Load(pf
, path
, STGM_READ
);
493 lok(r
== S_OK
, "load failed (0x%08x)\n", r
);
495 /* test GetCurFile after ::Save */
496 r
= IPersistFile_GetCurFile(pf
, &str
);
497 lok(r
== S_OK
, "got 0x%08x\n", r
);
499 broken(str
== NULL
), /* shell32 < 5.0 */
500 "Didn't expect NULL\n");
505 lok(!winetest_strcmpW(path
, str
), "Expected %s, got %s\n",
506 wine_dbgstr_w(path
), wine_dbgstr_w(str
));
508 SHGetMalloc(&pmalloc
);
509 IMalloc_Free(pmalloc
, str
);
512 win_skip("GetCurFile fails on shell32 < 5.0\n");
514 IPersistFile_Release(pf
);
517 IShellLinkA_Release(sl
);
521 if (desc
->description
)
523 strcpy(buffer
,"garbage");
524 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
525 lok(r
== S_OK
, "GetDescription failed (0x%08x)\n", r
);
526 todo_wine_if ((todo
& 0x1) != 0)
527 lok(strcmp(buffer
, desc
->description
)==0, "GetDescription returned '%s' instead of '%s'\n",
528 buffer
, desc
->description
);
532 strcpy(buffer
,"garbage");
533 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
534 lok(r
== S_OK
, "GetWorkingDirectory failed (0x%08x)\n", r
);
535 todo_wine_if ((todo
& 0x2) != 0)
536 lok(lstrcmpiA(buffer
, desc
->workdir
)==0, "GetWorkingDirectory returned '%s' instead of '%s'\n",
537 buffer
, desc
->workdir
);
541 strcpy(buffer
,"garbage");
542 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
543 lok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
544 todo_wine_if ((todo
& 0x4) != 0)
545 lok(lstrcmpiA(buffer
, desc
->path
)==0, "GetPath returned '%s' instead of '%s'\n",
550 LPITEMIDLIST pidl
=NULL
;
551 r
= IShellLinkA_GetIDList(sl
, &pidl
);
552 lok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
553 todo_wine_if ((todo
& 0x8) != 0)
554 lok(pILIsEqual(pidl
, desc
->pidl
), "GetIDList returned an incorrect pidl\n");
559 r
= IShellLinkA_GetShowCmd(sl
, &i
);
560 lok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
561 todo_wine_if ((todo
& 0x10) != 0)
562 lok(i
==desc
->showcmd
, "GetShowCmd returned 0x%0x instead of 0x%0x\n",
568 strcpy(buffer
,"garbage");
569 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
570 lok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
571 todo_wine_if ((todo
& 0x20) != 0) {
572 lok(lstrcmpiA(buffer
, desc
->icon
)==0, "GetIconLocation returned '%s' instead of '%s'\n",
574 lok(i
==desc
->icon_id
, "GetIconLocation returned 0x%0x instead of 0x%0x\n",
581 r
= IShellLinkA_GetHotkey(sl
, &i
);
582 lok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
583 todo_wine_if ((todo
& 0x40) != 0)
584 lok(i
==desc
->hotkey
, "GetHotkey returned 0x%04x instead of 0x%04x\n",
588 IShellLinkA_Release(sl
);
591 static void test_load_save(void)
593 WCHAR lnkfile
[MAX_PATH
];
594 char lnkfileA
[MAX_PATH
];
595 static const char lnkfileA_name
[] = "\\test.lnk";
598 char mypath
[MAX_PATH
];
599 char mydir
[MAX_PATH
];
600 char realpath
[MAX_PATH
];
605 if (!pGetLongPathNameA
)
607 win_skip("GetLongPathNameA is not available\n");
611 /* Don't used a fixed path for the test.lnk file */
612 GetTempPathA(MAX_PATH
, lnkfileA
);
613 lstrcatA(lnkfileA
, lnkfileA_name
);
614 MultiByteToWideChar(CP_ACP
, 0, lnkfileA
, -1, lnkfile
, MAX_PATH
);
616 /* Save an empty .lnk file */
617 memset(&desc
, 0, sizeof(desc
));
618 create_lnk(lnkfile
, &desc
, 0);
620 /* It should come back as a bunch of empty strings */
626 check_lnk(lnkfile
, &desc
, 0x0);
628 /* Point a .lnk file to nonexistent files */
630 desc
.workdir
="c:\\Nonexitent\\work\\directory";
631 desc
.path
="c:\\nonexistent\\path";
635 desc
.icon
="c:\\nonexistent\\icon\\file";
638 create_lnk(lnkfile
, &desc
, 0);
639 check_lnk(lnkfile
, &desc
, 0x0);
641 r
=GetModuleFileNameA(NULL
, mypath
, sizeof(mypath
));
642 ok(r
<sizeof(mypath
), "GetModuleFileName failed (%d)\n", r
);
643 strcpy(mydir
, mypath
);
644 p
=strrchr(mydir
, '\\');
648 /* IShellLink returns path in long form */
649 if (!pGetLongPathNameA(mypath
, realpath
, MAX_PATH
)) strcpy( realpath
, mypath
);
651 /* Overwrite the existing lnk file and point it to existing files */
652 desc
.description
="test 2";
656 desc
.arguments
="/option1 /option2 \"Some string\"";
657 desc
.showcmd
=SW_SHOWNORMAL
;
661 create_lnk(lnkfile
, &desc
, 0);
662 check_lnk(lnkfile
, &desc
, 0x0);
664 /* Test omitting .exe from an absolute path */
665 p
=strrchr(realpath
, '.');
669 desc
.description
="absolute path without .exe";
673 desc
.arguments
="/option1 /option2 \"Some string\"";
674 desc
.showcmd
=SW_SHOWNORMAL
;
678 create_lnk(lnkfile
, &desc
, 0);
679 strcat(realpath
, ".exe");
680 check_lnk(lnkfile
, &desc
, 0x4);
682 /* Overwrite the existing lnk file and test link to a command on the path */
683 desc
.description
="command on path";
685 desc
.path
="rundll32.exe";
687 desc
.arguments
="/option1 /option2 \"Some string\"";
688 desc
.showcmd
=SW_SHOWNORMAL
;
692 create_lnk(lnkfile
, &desc
, 0);
693 /* Check that link is created to proper location */
694 SearchPathA( NULL
, desc
.path
, NULL
, MAX_PATH
, realpath
, NULL
);
696 check_lnk(lnkfile
, &desc
, 0x0);
698 /* Test omitting .exe from a command on the path */
699 desc
.description
="command on path without .exe";
701 desc
.path
="rundll32";
703 desc
.arguments
="/option1 /option2 \"Some string\"";
704 desc
.showcmd
=SW_SHOWNORMAL
;
708 create_lnk(lnkfile
, &desc
, 0);
709 /* Check that link is created to proper location */
710 SearchPathA( NULL
, "rundll32", NULL
, MAX_PATH
, realpath
, NULL
);
712 check_lnk(lnkfile
, &desc
, 0x4);
714 /* Create a temporary non-executable file */
715 r
=GetTempPathA(sizeof(mypath
), mypath
);
716 ok(r
<sizeof(mypath
), "GetTempPath failed (%d), err %d\n", r
, GetLastError());
717 r
=pGetLongPathNameA(mypath
, mydir
, sizeof(mydir
));
718 ok(r
<sizeof(mydir
), "GetLongPathName failed (%d), err %d\n", r
, GetLastError());
719 p
=strrchr(mydir
, '\\');
723 strcpy(mypath
, mydir
);
724 strcat(mypath
, "\\test.txt");
725 hf
= CreateFileA(mypath
, GENERIC_WRITE
, 0, NULL
,
726 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
729 /* Overwrite the existing lnk file and test link to an existing non-executable file */
730 desc
.description
="non-executable file";
735 desc
.showcmd
=SW_SHOWNORMAL
;
739 create_lnk(lnkfile
, &desc
, 0);
740 check_lnk(lnkfile
, &desc
, 0x0);
742 r
=pGetShortPathNameA(mydir
, mypath
, sizeof(mypath
));
743 ok(r
<sizeof(mypath
), "GetShortPathName failed (%d), err %d\n", r
, GetLastError());
745 strcpy(realpath
, mypath
);
746 strcat(realpath
, "\\test.txt");
747 strcat(mypath
, "\\\\test.txt");
749 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
750 desc
.description
="non-executable file";
755 desc
.showcmd
=SW_SHOWNORMAL
;
759 create_lnk(lnkfile
, &desc
, 0);
761 check_lnk(lnkfile
, &desc
, 0x0);
763 r
= DeleteFileA(mypath
);
764 ok(r
, "failed to delete file %s (%d)\n", mypath
, GetLastError());
766 /* Create a temporary .bat file */
767 strcpy(mypath
, mydir
);
768 strcat(mypath
, "\\test.bat");
769 hf
= CreateFileA(mypath
, GENERIC_WRITE
, 0, NULL
,
770 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
773 strcpy(realpath
, mypath
);
775 p
=strrchr(mypath
, '.');
779 /* Try linking to the .bat file without the extension */
780 desc
.description
="batch file";
785 desc
.showcmd
=SW_SHOWNORMAL
;
789 create_lnk(lnkfile
, &desc
, 0);
790 desc
.path
= realpath
;
791 check_lnk(lnkfile
, &desc
, 0x4);
793 r
= DeleteFileA(realpath
);
794 ok(r
, "failed to delete file %s (%d)\n", realpath
, GetLastError());
796 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
797 * represented as a path.
800 /* DeleteFileW is not implemented on Win9x */
801 r
=DeleteFileA(lnkfileA
);
802 ok(r
, "failed to delete link '%s' (%d)\n", lnkfileA
, GetLastError());
805 static void test_datalink(void)
807 static const WCHAR lnk
[] = {
808 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
809 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
810 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
811 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
812 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
813 '1','-',']',':',':',0 };
814 static const WCHAR comp
[] = {
815 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
816 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
817 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
818 IShellLinkDataList
*dl
= NULL
;
819 IShellLinkW
*sl
= NULL
;
822 EXP_DARWIN_LINK
*dar
;
824 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
825 &IID_IShellLinkW
, (LPVOID
*)&sl
);
827 broken(r
== E_NOINTERFACE
), /* Win9x */
828 "CoCreateInstance failed (0x%08x)\n", r
);
831 win_skip("no shelllink\n");
835 r
= IShellLinkW_QueryInterface( sl
, &_IID_IShellLinkDataList
, (LPVOID
*) &dl
);
837 broken(r
== E_NOINTERFACE
), /* NT4 */
838 "IShellLinkW_QueryInterface failed (0x%08x)\n", r
);
842 win_skip("no datalink interface\n");
843 IShellLinkW_Release( sl
);
848 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
849 ok( r
== S_OK
, "GetFlags failed\n");
850 ok( flags
== 0, "GetFlags returned wrong flags\n");
853 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
854 ok( r
== E_FAIL
, "CopyDataBlock failed\n");
855 ok( dar
== NULL
, "should be null\n");
857 if (!pGetLongPathNameA
/* NT4 */)
858 skip("SetPath with NULL parameter crashes on NT4\n");
861 r
= IShellLinkW_SetPath(sl
, NULL
);
862 ok(r
== E_INVALIDARG
, "SetPath returned wrong error (0x%08x)\n", r
);
865 r
= IShellLinkW_SetPath(sl
, lnk
);
866 ok(r
== S_OK
, "SetPath failed\n");
870 /* the following crashes */
871 IShellLinkDataList_GetFlags( dl
, NULL
);
875 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
876 ok( r
== S_OK
, "GetFlags failed\n");
877 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
878 ok( (flags
& (~ SLDF_HAS_LOGO3ID
)) == SLDF_HAS_DARWINID
,
879 "GetFlags returned wrong flags\n");
882 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
883 ok( r
== S_OK
, "CopyDataBlock failed\n");
885 ok( dar
&& ((DATABLOCK_HEADER
*)dar
)->dwSignature
== EXP_DARWIN_ID_SIG
, "signature wrong\n");
886 ok( dar
&& 0==lstrcmpW(dar
->szwDarwinID
, comp
), "signature wrong\n");
890 IShellLinkDataList_Release( dl
);
891 IShellLinkW_Release( sl
);
894 static void test_shdefextracticon(void)
896 HICON hiconlarge
=NULL
, hiconsmall
=NULL
;
899 if (!pSHDefExtractIconA
)
901 win_skip("SHDefExtractIconA is unavailable\n");
905 res
= pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge
, &hiconsmall
, MAKELONG(16,24));
906 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
907 ok(hiconlarge
!= NULL
, "got null hiconlarge\n");
908 ok(hiconsmall
!= NULL
, "got null hiconsmall\n");
909 DestroyIcon(hiconlarge
);
910 DestroyIcon(hiconsmall
);
913 res
= pSHDefExtractIconA("shell32.dll", 0, 0, NULL
, &hiconsmall
, MAKELONG(16,24));
914 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
915 ok(hiconsmall
!= NULL
, "got null hiconsmall\n");
916 DestroyIcon(hiconsmall
);
918 res
= pSHDefExtractIconA("shell32.dll", 0, 0, NULL
, NULL
, MAKELONG(16,24));
919 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
922 static void test_GetIconLocation(void)
926 char buffer
[INFOTIPSIZE
], mypath
[MAX_PATH
];
931 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
932 &IID_IShellLinkA
, (LPVOID
*)&sl
);
933 ok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
938 strcpy(buffer
, "garbage");
939 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
940 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
941 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
942 ok(i
== 0, "GetIconLocation returned %d\n", i
);
944 str
= "c:\\some\\path";
945 r
= IShellLinkA_SetPath(sl
, str
);
946 ok(r
== S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
949 strcpy(buffer
, "garbage");
950 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
951 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
952 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
953 ok(i
== 0, "GetIconLocation returned %d\n", i
);
955 GetWindowsDirectoryA(mypath
, sizeof(mypath
) - 12);
956 strcat(mypath
, "\\regedit.exe");
957 pidl
= path_to_pidl(mypath
);
958 r
= IShellLinkA_SetIDList(sl
, pidl
);
959 ok(r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
963 strcpy(buffer
, "garbage");
964 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
965 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
966 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
967 ok(i
== 0, "GetIconLocation returned %d\n", i
);
969 str
= "c:\\nonexistent\\file";
970 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
971 ok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
974 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
975 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
976 ok(lstrcmpiA(buffer
,str
) == 0, "GetIconLocation returned '%s'\n", buffer
);
977 ok(i
== 0xbabecafe, "GetIconLocation returned %d'\n", i
);
979 IShellLinkA_Release(sl
);
982 static void test_SHGetStockIconInfo(void)
984 BYTE buffer
[sizeof(SHSTOCKICONINFO
) + 16];
985 SHSTOCKICONINFO
*sii
= (SHSTOCKICONINFO
*) buffer
;
989 /* not present before vista */
990 if (!pSHGetStockIconInfo
)
992 win_skip("SHGetStockIconInfo not available\n");
996 /* negative values are handled */
997 memset(buffer
, '#', sizeof(buffer
));
998 sii
->cbSize
= sizeof(SHSTOCKICONINFO
);
999 hr
= pSHGetStockIconInfo(SIID_INVALID
, SHGSI_ICONLOCATION
, sii
);
1000 ok(hr
== E_INVALIDARG
, "-1: got 0x%x (expected E_INVALIDARG)\n", hr
);
1002 /* max. id for vista is 140 (no definition exists for this value) */
1003 for (i
= SIID_DOCNOASSOC
; i
<= SIID_CLUSTEREDDRIVE
; i
++)
1005 memset(buffer
, '#', sizeof(buffer
));
1006 sii
->cbSize
= sizeof(SHSTOCKICONINFO
);
1007 hr
= pSHGetStockIconInfo(i
, SHGSI_ICONLOCATION
, sii
);
1010 "%3d: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x (expected S_OK)\n",
1011 i
, hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1013 if ((hr
== S_OK
) && (winetest_debug
> 1))
1014 trace("%3d: got iSysImageIndex %3d, iIcon %3d and %s\n", i
, sii
->iSysImageIndex
,
1015 sii
->iIcon
, wine_dbgstr_w(sii
->szPath
));
1018 /* test invalid icons indices that are invalid for all platforms */
1019 for (i
= SIID_MAX_ICONS
; i
< (SIID_MAX_ICONS
+ 25) ; i
++)
1021 memset(buffer
, '#', sizeof(buffer
));
1022 sii
->cbSize
= sizeof(SHSTOCKICONINFO
);
1023 hr
= pSHGetStockIconInfo(i
, SHGSI_ICONLOCATION
, sii
);
1024 ok(hr
== E_INVALIDARG
, "%3d: got 0x%x (expected E_INVALIDARG)\n", i
, hr
);
1026 ok(sii
->iSysImageIndex
== -1, "%d: got iSysImageIndex %d\n", i
, sii
->iSysImageIndex
);
1027 ok(sii
->iIcon
== -1, "%d: got iIcon %d\n", i
, sii
->iIcon
);
1031 /* test more returned SHSTOCKICONINFO elements without extra flags */
1032 memset(buffer
, '#', sizeof(buffer
));
1033 sii
->cbSize
= sizeof(SHSTOCKICONINFO
);
1034 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1035 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
1036 ok(!sii
->hIcon
, "got %p (expected NULL)\n", sii
->hIcon
);
1037 ok(sii
->iSysImageIndex
== -1, "got %d (expected -1)\n", sii
->iSysImageIndex
);
1039 /* the exact size is required of the struct */
1040 memset(buffer
, '#', sizeof(buffer
));
1041 sii
->cbSize
= sizeof(SHSTOCKICONINFO
) + 2;
1042 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1043 ok(hr
== E_INVALIDARG
, "+2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1045 memset(buffer
, '#', sizeof(buffer
));
1046 sii
->cbSize
= sizeof(SHSTOCKICONINFO
) + 1;
1047 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1048 ok(hr
== E_INVALIDARG
, "+1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1050 memset(buffer
, '#', sizeof(buffer
));
1051 sii
->cbSize
= sizeof(SHSTOCKICONINFO
) - 1;
1052 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1053 ok(hr
== E_INVALIDARG
, "-1: 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
) - 2;
1057 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1058 ok(hr
== E_INVALIDARG
, "-2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1060 /* there is a NULL check for the struct */
1061 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, NULL
);
1062 ok(hr
== E_INVALIDARG
, "NULL: got 0x%x\n", hr
);
1065 static void test_SHExtractIcons(void)
1067 static const WCHAR notepadW
[] = {'n','o','t','e','p','a','d','.','e','x','e',0};
1068 static const WCHAR shell32W
[] = {'s','h','e','l','l','3','2','.','d','l','l',0};
1069 static const WCHAR emptyW
[] = {0};
1074 if (!pSHExtractIconsW
)
1076 win_skip("SHExtractIconsW not available\n");
1080 ret
= pSHExtractIconsW(emptyW
, 0, 16, 16, icons
, ids
, 1, 0);
1081 ok(ret
== ~0u, "got %u\n", ret
);
1083 ret
= pSHExtractIconsW(notepadW
, 0, 16, 16, NULL
, NULL
, 1, 0);
1084 ok(ret
== 1 || broken(ret
== 2) /* win2k */, "got %u\n", ret
);
1086 icons
[0] = (HICON
)0xdeadbeef;
1087 ret
= pSHExtractIconsW(notepadW
, 0, 16, 16, icons
, NULL
, 1, 0);
1088 ok(ret
== 1, "got %u\n", ret
);
1089 ok(icons
[0] != (HICON
)0xdeadbeef, "icon not set\n");
1090 DestroyIcon(icons
[0]);
1092 icons
[0] = (HICON
)0xdeadbeef;
1093 ids
[0] = 0xdeadbeef;
1094 ret
= pSHExtractIconsW(notepadW
, 0, 16, 16, icons
, ids
, 1, 0);
1095 ok(ret
== 1, "got %u\n", ret
);
1096 ok(icons
[0] != (HICON
)0xdeadbeef, "icon not set\n");
1097 ok(ids
[0] != 0xdeadbeef, "id not set\n");
1098 DestroyIcon(icons
[0]);
1100 ret
= pSHExtractIconsW(shell32W
, 0, 16, 16, NULL
, NULL
, 0, 0);
1101 ret2
= pSHExtractIconsW(shell32W
, 4, MAKELONG(32,16), MAKELONG(32,16), NULL
, NULL
, 256, 0);
1102 ok(ret
&& ret
== ret2
,
1103 "icon count should be independent of requested icon sizes and base icon index\n");
1105 ret
= pSHExtractIconsW(shell32W
, 0, 16, 16, icons
, ids
, 0, 0);
1106 ok(ret
== ~0u || !ret
/* < vista */, "got %u\n", ret
);
1108 ret
= pSHExtractIconsW(shell32W
, 0, 16, 16, icons
, ids
, 3, 0);
1109 ok(ret
== 3, "got %u\n", ret
);
1110 for (i
= 0; i
< ret
; i
++) DestroyIcon(icons
[i
]);
1112 /* count must be a multiple of two when getting two sizes */
1113 ret
= pSHExtractIconsW(shell32W
, 0, MAKELONG(16,32), MAKELONG(16,32), icons
, ids
, 3, 0);
1114 ok(!ret
/* vista */ || ret
== 4, "got %u\n", ret
);
1115 for (i
= 0; i
< ret
; i
++) DestroyIcon(icons
[i
]);
1117 ret
= pSHExtractIconsW(shell32W
, 0, MAKELONG(16,32), MAKELONG(16,32), icons
, ids
, 4, 0);
1118 ok(ret
== 4, "got %u\n", ret
);
1119 for (i
= 0; i
< ret
; i
++) DestroyIcon(icons
[i
]);
1122 static void test_propertystore(void)
1129 hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
1130 &IID_IShellLinkA
, (void**)&linkA
);
1131 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1133 hr
= IShellLinkA_QueryInterface(linkA
, &IID_IShellLinkW
, (void**)&linkW
);
1134 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1136 hr
= IShellLinkA_QueryInterface(linkA
, &IID_IPropertyStore
, (void**)&ps
);
1138 IPropertyStoreCache
*pscache
;
1140 IPropertyStore_Release(ps
);
1142 hr
= IShellLinkW_QueryInterface(linkW
, &IID_IPropertyStore
, (void**)&ps
);
1143 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1145 hr
= IPropertyStore_QueryInterface(ps
, &IID_IPropertyStoreCache
, (void**)&pscache
);
1146 ok(hr
== E_NOINTERFACE
, "got 0x%08x\n", hr
);
1148 IPropertyStore_Release(ps
);
1151 win_skip("IShellLink doesn't support IPropertyStore.\n");
1153 IShellLinkA_Release(linkA
);
1154 IShellLinkW_Release(linkW
);
1157 static void test_ExtractIcon(void)
1159 static const WCHAR nameW
[] = {'\\','e','x','t','r','a','c','t','i','c','o','n','_','t','e','s','t','.','t','x','t',0};
1160 static const WCHAR shell32W
[] = {'s','h','e','l','l','3','2','.','d','l','l',0};
1161 WCHAR pathW
[MAX_PATH
];
1162 HICON hicon
, hicon2
;
1163 char path
[MAX_PATH
];
1169 /* specified instance handle */
1170 hicon
= ExtractIconA(GetModuleHandleA("shell32.dll"), NULL
, 0);
1172 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1173 hicon2
= ExtractIconA(GetModuleHandleA("shell32.dll"), "shell32.dll", -1);
1174 ok(hicon2
!= NULL
, "Got icon %p\n", hicon2
);
1176 /* existing index */
1177 hicon
= ExtractIconA(NULL
, "shell32.dll", 0);
1178 ok(hicon
!= NULL
&& HandleToLong(hicon
) != -1, "Got icon %p\n", hicon
);
1181 /* returns number of resources */
1182 hicon
= ExtractIconA(NULL
, "shell32.dll", -1);
1183 ok(HandleToLong(hicon
) > 1 && hicon
== hicon2
, "Got icon %p\n", hicon
);
1185 /* invalid index, valid dll name */
1186 hicon
= ExtractIconA(NULL
, "shell32.dll", 3000);
1187 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1189 /* Create a temporary non-executable file */
1190 GetTempPathA(sizeof(path
), path
);
1191 strcat(path
, "\\extracticon_test.txt");
1192 file
= CreateFileA(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1193 ok(file
!= INVALID_HANDLE_VALUE
, "Failed to create a test file\n");
1196 hicon
= ExtractIconA(NULL
, path
, 0);
1198 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1200 hicon
= ExtractIconA(NULL
, path
, -1);
1201 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1203 hicon
= ExtractIconA(NULL
, path
, 1);
1205 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1207 r
= DeleteFileA(path
);
1208 ok(r
, "failed to delete file %s (%d)\n", path
, GetLastError());
1210 /* same for W variant */
1213 /* specified instance handle, crashes on XP, 2k3 */
1214 hicon
= ExtractIconW(GetModuleHandleA("shell32.dll"), NULL
, 0);
1215 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1217 hicon2
= ExtractIconW(GetModuleHandleA("shell32.dll"), shell32W
, -1);
1218 ok(hicon2
!= NULL
, "Got icon %p\n", hicon2
);
1220 /* existing index */
1221 hicon
= ExtractIconW(NULL
, shell32W
, 0);
1222 ok(hicon
!= NULL
&& HandleToLong(hicon
) != -1, "Got icon %p\n", hicon
);
1223 GetIconInfo(hicon
, &info
);
1224 GetObjectW(info
.hbmColor
, sizeof(bm
), &bm
);
1225 ok(bm
.bmWidth
== GetSystemMetrics(SM_CXICON
), "got %d\n", bm
.bmWidth
);
1226 ok(bm
.bmHeight
== GetSystemMetrics(SM_CYICON
), "got %d\n", bm
.bmHeight
);
1229 /* returns number of resources */
1230 hicon
= ExtractIconW(NULL
, shell32W
, -1);
1231 ok(HandleToLong(hicon
) > 1 && hicon
== hicon2
, "Got icon %p\n", hicon
);
1233 /* invalid index, valid dll name */
1234 hicon
= ExtractIconW(NULL
, shell32W
, 3000);
1235 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1237 /* Create a temporary non-executable file */
1238 GetTempPathW(sizeof(pathW
)/sizeof(pathW
[0]), pathW
);
1239 lstrcatW(pathW
, nameW
);
1240 file
= CreateFileW(pathW
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1241 ok(file
!= INVALID_HANDLE_VALUE
, "Failed to create a test file\n");
1244 hicon
= ExtractIconW(NULL
, pathW
, 0);
1246 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1248 hicon
= ExtractIconW(NULL
, pathW
, -1);
1249 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1251 hicon
= ExtractIconW(NULL
, pathW
, 1);
1253 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1255 r
= DeleteFileW(pathW
);
1256 ok(r
, "failed to delete file %s (%d)\n", path
, GetLastError());
1259 static void test_ExtractAssociatedIcon(void)
1261 char pathA
[MAX_PATH
];
1268 hicon
= ExtractAssociatedIconA(NULL
, pathA
, &index
);
1270 ok(hicon
!= NULL
, "Got icon %p\n", hicon
);
1271 ok(!*pathA
, "Unexpected path %s\n", pathA
);
1272 ok(index
== 0, "Unexpected index %u\n", index
);
1278 strcpy(pathA
, "shell32.dll");
1279 hicon
= ExtractAssociatedIconA(NULL
, pathA
, &index
);
1280 ok(hicon
!= NULL
, "Got icon %p\n", hicon
);
1281 ok(!strcmp(pathA
, "shell32.dll"), "Unexpected path %s\n", pathA
);
1282 ok(index
== 0, "Unexpected index %u\n", index
);
1285 /* valid dll name, invalid index */
1287 strcpy(pathA
, "user32.dll");
1288 hicon
= ExtractAssociatedIconA(NULL
, pathA
, &index
);
1289 CharLowerBuffA(pathA
, strlen(pathA
));
1291 ok(hicon
!= NULL
, "Got icon %p\n", hicon
);
1292 ok(!!strstr(pathA
, "shell32.dll"), "Unexpected path %s\n", pathA
);
1294 ok(index
!= 5000, "Unexpected index %u\n", index
);
1297 /* associated icon */
1299 strcpy(pathA
, "dummy.exe");
1300 hicon
= ExtractAssociatedIconA(NULL
, pathA
, &index
);
1301 CharLowerBuffA(pathA
, strlen(pathA
));
1303 ok(hicon
!= NULL
, "Got icon %p\n", hicon
);
1304 ok(!!strstr(pathA
, "shell32.dll"), "Unexpected path %s\n", pathA
);
1306 ok(index
!= 0xcaca, "Unexpected index %u\n", index
);
1310 static int get_shell_icon_size(void)
1313 DWORD value
= 32, size
= sizeof(buf
), type
;
1316 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Control Panel\\Desktop\\WindowMetrics", &key
))
1318 if (!RegQueryValueExA( key
, "Shell Icon Size", NULL
, &type
, (BYTE
*)buf
, &size
) && type
== REG_SZ
)
1319 value
= atoi( buf
);
1325 static void test_SHGetImageList(void)
1328 IImageList
*list
, *list2
;
1331 ULONG start_refs
, refs
;
1332 int i
, width
, height
, expect
;
1333 BOOL dpi_aware
= pIsProcessDPIAware
&& pIsProcessDPIAware();
1335 hr
= SHGetImageList( SHIL_LARGE
, &IID_IImageList
, (void **)&list
);
1336 ok( hr
== S_OK
, "got %08x\n", hr
);
1337 start_refs
= IImageList_AddRef( list
);
1338 IImageList_Release( list
);
1340 hr
= SHGetImageList( SHIL_LARGE
, &IID_IImageList
, (void **)&list2
);
1341 ok( hr
== S_OK
, "got %08x\n", hr
);
1342 ok( list
== list2
, "lists differ\n" );
1343 refs
= IImageList_AddRef( list
);
1344 IImageList_Release( list
);
1345 ok( refs
== start_refs
+ 1, "got %d, start_refs %d\n", refs
, start_refs
);
1346 IImageList_Release( list2
);
1348 hr
= SHGetImageList( SHIL_SMALL
, &IID_IImageList
, (void **)&list2
);
1349 ok( hr
== S_OK
, "got %08x\n", hr
);
1351 ret
= Shell_GetImageLists( &lg
, &sm
);
1352 ok( ret
, "got %d\n", ret
);
1353 ok( lg
== (HIMAGELIST
)list
, "mismatch\n" );
1354 ok( sm
== (HIMAGELIST
)list2
, "mismatch\n" );
1356 /* Shell_GetImageLists doesn't take a reference */
1357 refs
= IImageList_AddRef( list
);
1358 IImageList_Release( list
);
1359 ok( refs
== start_refs
, "got %d, start_refs %d\n", refs
, start_refs
);
1361 IImageList_Release( list2
);
1362 IImageList_Release( list
);
1364 /* Test the icon sizes */
1365 for (i
= 0; i
<= SHIL_LAST
; i
++)
1367 hr
= SHGetImageList( i
, &IID_IImageList
, (void **)&list
);
1369 broken( i
== SHIL_JUMBO
&& hr
== E_INVALIDARG
), /* XP and 2003 */
1370 "%d: got %08x\n", i
, hr
);
1371 if (FAILED(hr
)) continue;
1372 IImageList_GetIconSize( list
, &width
, &height
);
1376 if (dpi_aware
) expect
= GetSystemMetrics( SM_CXICON
);
1377 else expect
= get_shell_icon_size();
1380 if (dpi_aware
) expect
= GetSystemMetrics( SM_CXICON
) / 2;
1381 else expect
= GetSystemMetrics( SM_CXSMICON
);
1383 case SHIL_EXTRALARGE
:
1384 expect
= (GetSystemMetrics( SM_CXICON
) * 3) / 2;
1387 expect
= GetSystemMetrics( SM_CXSMICON
);
1393 todo_wine_if(i
== SHIL_SYSSMALL
&& dpi_aware
&& expect
!= GetSystemMetrics( SM_CXICON
) / 2)
1395 ok( width
== expect
, "%d: got %d expect %d\n", i
, width
, expect
);
1396 ok( height
== expect
, "%d: got %d expect %d\n", i
, height
, expect
);
1398 IImageList_Release( list
);
1402 START_TEST(shelllink
)
1405 HMODULE hmod
= GetModuleHandleA("shell32.dll");
1406 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
1407 HMODULE huser32
= GetModuleHandleA("user32.dll");
1409 pILFree
= (void *)GetProcAddress(hmod
, (LPSTR
)155);
1410 pILIsEqual
= (void *)GetProcAddress(hmod
, (LPSTR
)21);
1411 pSHILCreateFromPath
= (void *)GetProcAddress(hmod
, (LPSTR
)28);
1412 pSHDefExtractIconA
= (void *)GetProcAddress(hmod
, "SHDefExtractIconA");
1413 pSHGetStockIconInfo
= (void *)GetProcAddress(hmod
, "SHGetStockIconInfo");
1414 pGetLongPathNameA
= (void *)GetProcAddress(hkernel32
, "GetLongPathNameA");
1415 pGetShortPathNameA
= (void *)GetProcAddress(hkernel32
, "GetShortPathNameA");
1416 pSHExtractIconsW
= (void *)GetProcAddress(hmod
, "SHExtractIconsW");
1417 pIsProcessDPIAware
= (void *)GetProcAddress(huser32
, "IsProcessDPIAware");
1419 r
= CoInitialize(NULL
);
1420 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
1427 test_shdefextracticon();
1428 test_GetIconLocation();
1429 test_SHGetStockIconInfo();
1430 test_SHExtractIcons();
1431 test_propertystore();
1433 test_ExtractAssociatedIcon();
1434 test_SHGetImageList();