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 #ifndef SLDF_HAS_LOGO3ID
36 # define SLDF_HAS_LOGO3ID 0x00000800 /* not available in the Vista SDK */
39 static void (WINAPI
*pILFree
)(LPITEMIDLIST
);
40 static BOOL (WINAPI
*pILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
);
41 static HRESULT (WINAPI
*pSHILCreateFromPath
)(LPCWSTR
, LPITEMIDLIST
*,DWORD
*);
42 static HRESULT (WINAPI
*pSHGetFolderLocation
)(HWND
,INT
,HANDLE
,DWORD
,PIDLIST_ABSOLUTE
*);
43 static HRESULT (WINAPI
*pSHDefExtractIconA
)(LPCSTR
, int, UINT
, HICON
*, HICON
*, UINT
);
44 static HRESULT (WINAPI
*pSHGetStockIconInfo
)(SHSTOCKICONID
, UINT
, SHSTOCKICONINFO
*);
45 static DWORD (WINAPI
*pGetLongPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
46 static DWORD (WINAPI
*pGetShortPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
47 static UINT (WINAPI
*pSHExtractIconsW
)(LPCWSTR
, int, int, int, HICON
*, UINT
*, UINT
, UINT
);
48 static BOOL (WINAPI
*pIsProcessDPIAware
)(void);
50 static const GUID _IID_IShellLinkDataList
= {
51 0x45e2b4ae, 0xb1c3, 0x11d0,
52 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
56 /* For some reason SHILCreateFromPath does not work on Win98 and
57 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
58 * get what we want on all platforms.
60 static LPITEMIDLIST (WINAPI
*pSHSimpleIDListFromPathAW
)(LPCVOID
);
62 static LPITEMIDLIST
path_to_pidl(const char* path
)
66 if (!pSHSimpleIDListFromPathAW
)
68 HMODULE hdll
=GetModuleHandleA("shell32.dll");
69 pSHSimpleIDListFromPathAW
=(void*)GetProcAddress(hdll
, (char*)162);
70 if (!pSHSimpleIDListFromPathAW
)
71 win_skip("SHSimpleIDListFromPathAW not found in shell32.dll\n");
75 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
76 if (pSHSimpleIDListFromPathAW
&& (GetVersion() & 0x80000000))
77 pidl
=pSHSimpleIDListFromPathAW(path
);
85 len
=MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
86 pathW
=HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
87 MultiByteToWideChar(CP_ACP
, 0, path
, -1, pathW
, len
);
89 r
=pSHILCreateFromPath(pathW
, &pidl
, NULL
);
90 ok(r
== S_OK
, "SHILCreateFromPath failed (0x%08x)\n", r
);
91 HeapFree(GetProcessHeap(), 0, pathW
);
98 * Test manipulation of an IShellLink's properties.
101 static void test_get_set(void)
105 IShellLinkW
*slW
= NULL
;
106 char mypath
[MAX_PATH
];
107 char buffer
[INFOTIPSIZE
];
108 WIN32_FIND_DATAA finddata
;
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 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 strcpy(buffer
,"garbage");
165 memset(&finddata
, 0xaa, sizeof(finddata
));
166 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), &finddata
, SLGP_RAWPATH
);
167 ok(r
== S_FALSE
|| broken(r
== S_OK
) /* NT4/W2K */, "GetPath failed (0x%08x)\n", r
);
168 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
169 ok(finddata
.dwFileAttributes
== 0, "unexpected attributes %x\n", finddata
.dwFileAttributes
);
170 ok(finddata
.cFileName
[0] == 0, "unexpected filename '%s'\n", finddata
.cFileName
);
172 CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
173 &IID_IShellLinkW
, (LPVOID
*)&slW
);
174 if (!slW
/* Win9x */ || !pGetLongPathNameA
/* NT4 */)
175 skip("SetPath with NULL parameter crashes on Win9x and some NT4\n");
178 IShellLinkW_Release(slW
);
179 r
= IShellLinkA_SetPath(sl
, NULL
);
180 ok(r
==E_INVALIDARG
||
181 broken(r
==S_OK
), /* Some Win95 and NT4 */
182 "SetPath returned wrong error (0x%08x)\n", r
);
185 r
= IShellLinkA_SetPath(sl
, "");
186 ok(r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
188 strcpy(buffer
,"garbage");
189 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
190 ok(r
== S_FALSE
, "GetPath failed (0x%08x)\n", r
);
191 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
193 /* Win98 returns S_FALSE, but WinXP returns S_OK */
194 str
="c:\\nonexistent\\file";
195 r
= IShellLinkA_SetPath(sl
, str
);
196 ok(r
==S_FALSE
|| r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
198 strcpy(buffer
,"garbage");
199 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
200 ok(r
== S_OK
, "GetPath failed (0x%08x)\n", r
);
201 ok(lstrcmpiA(buffer
,str
)==0, "GetPath returned '%s'\n", buffer
);
203 strcpy(buffer
,"garbage");
204 memset(&finddata
, 0xaa, sizeof(finddata
));
205 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), &finddata
, SLGP_RAWPATH
);
206 ok(r
== S_OK
, "GetPath failed (0x%08x)\n", r
);
207 ok(lstrcmpiA(buffer
,str
)==0, "GetPath returned '%s'\n", buffer
);
208 ok(finddata
.dwFileAttributes
== 0, "unexpected attributes %x\n", finddata
.dwFileAttributes
);
209 ok(lstrcmpiA(finddata
.cFileName
, "file") == 0, "unexpected filename '%s'\n", finddata
.cFileName
);
211 /* Get some real path to play with */
212 GetWindowsDirectoryA( mypath
, sizeof(mypath
)-12 );
213 strcat(mypath
, "\\regedit.exe");
215 /* Test the interaction of SetPath and SetIDList */
217 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
218 ok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
223 strcpy(buffer
,"garbage");
224 ret
= SHGetPathFromIDListA(tmp_pidl
, buffer
);
225 ok(ret
, "SHGetPathFromIDListA failed\n");
227 ok(lstrcmpiA(buffer
,str
)==0, "GetIDList returned '%s'\n", buffer
);
231 pidl
=path_to_pidl(mypath
);
232 ok(pidl
!=NULL
, "path_to_pidl returned a NULL pidl\n");
236 LPITEMIDLIST second_pidl
;
238 r
= IShellLinkA_SetIDList(sl
, pidl
);
239 ok(r
== S_OK
, "SetIDList failed (0x%08x)\n", r
);
242 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
243 ok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
244 ok(tmp_pidl
&& pILIsEqual(pidl
, tmp_pidl
),
245 "GetIDList returned an incorrect pidl\n");
247 r
= IShellLinkA_GetIDList(sl
, &second_pidl
);
248 ok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
249 ok(second_pidl
&& pILIsEqual(pidl
, second_pidl
),
250 "GetIDList returned an incorrect pidl\n");
251 ok(second_pidl
!= tmp_pidl
, "pidls are the same\n");
253 pILFree(second_pidl
);
257 strcpy(buffer
,"garbage");
258 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
259 ok(r
== S_OK
, "GetPath failed (0x%08x)\n", r
);
260 ok(lstrcmpiA(buffer
, mypath
)==0, "GetPath returned '%s'\n", buffer
);
262 strcpy(buffer
,"garbage");
263 memset(&finddata
, 0xaa, sizeof(finddata
));
264 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), &finddata
, SLGP_RAWPATH
);
265 ok(r
== S_OK
, "GetPath failed (0x%08x)\n", r
);
266 ok(lstrcmpiA(buffer
, mypath
)==0, "GetPath returned '%s'\n", buffer
);
267 ok(finddata
.dwFileAttributes
!= 0, "unexpected attributes %x\n", finddata
.dwFileAttributes
);
268 ok(lstrcmpiA(finddata
.cFileName
, "regedit.exe") == 0, "unexpected filename '%s'\n", finddata
.cFileName
);
271 if (pSHGetFolderLocation
)
273 LPITEMIDLIST pidl_controls
;
275 r
= pSHGetFolderLocation(NULL
, CSIDL_CONTROLS
, NULL
, 0, &pidl_controls
);
276 ok(r
== S_OK
, "SHGetFolderLocation failed (0x%08x)\n", r
);
278 r
= IShellLinkA_SetIDList(sl
, pidl_controls
);
279 ok(r
== S_OK
, "SetIDList failed (0x%08x)\n", r
);
281 strcpy(buffer
,"garbage");
282 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
283 ok(r
== S_FALSE
, "GetPath failed (0x%08x)\n", r
);
284 ok(buffer
[0] == 0, "GetPath returned '%s'\n", buffer
);
286 strcpy(buffer
,"garbage");
287 memset(&finddata
, 0xaa, sizeof(finddata
));
288 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), &finddata
, SLGP_RAWPATH
);
289 ok(r
== S_FALSE
, "GetPath failed (0x%08x)\n", r
);
290 ok(buffer
[0] == 0, "GetPath returned '%s'\n", buffer
);
291 ok(finddata
.dwFileAttributes
== 0, "unexpected attributes %x\n", finddata
.dwFileAttributes
);
292 ok(finddata
.cFileName
[0] == 0, "unexpected filename '%s'\n", finddata
.cFileName
);
294 pILFree(pidl_controls
);
297 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
298 r
= IShellLinkA_SetPath(sl
, "\"c:\\nonexistent\\file\"");
299 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
301 strcpy(buffer
,"garbage");
302 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
303 ok(r
==S_OK
, "GetPath failed (0x%08x)\n", r
);
304 todo_wine
ok(!strcmp(buffer
, "C:\\nonexistent\\file") ||
305 broken(!strcmp(buffer
, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
306 "case doesn't match\n");
308 r
= IShellLinkA_SetPath(sl
, "\"c:\\foo");
309 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
311 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo");
312 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
314 r
= IShellLinkA_SetPath(sl
, "c:\\foo\"");
315 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
317 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"");
318 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
320 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"\"");
321 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
323 /* Test Getting / Setting the arguments */
324 strcpy(buffer
,"garbage");
325 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
326 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
327 ok(*buffer
=='\0', "GetArguments returned '%s'\n", buffer
);
329 str
="param1 \"spaced param2\"";
330 r
= IShellLinkA_SetArguments(sl
, str
);
331 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
333 strcpy(buffer
,"garbage");
334 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
335 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
336 ok(strcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
338 strcpy(buffer
,"garbage");
339 r
= IShellLinkA_SetArguments(sl
, NULL
);
340 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
341 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
342 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
343 ok(!buffer
[0] || strcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
345 strcpy(buffer
,"garbage");
346 r
= IShellLinkA_SetArguments(sl
, "");
347 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
348 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
349 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
350 ok(!buffer
[0], "GetArguments returned '%s'\n", buffer
);
352 /* Test Getting / Setting showcmd */
354 r
= IShellLinkA_GetShowCmd(sl
, &i
);
355 ok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
356 ok(i
==SW_SHOWNORMAL
, "GetShowCmd returned %d\n", i
);
358 r
= IShellLinkA_SetShowCmd(sl
, SW_SHOWMAXIMIZED
);
359 ok(r
== S_OK
, "SetShowCmd failed (0x%08x)\n", r
);
362 r
= IShellLinkA_GetShowCmd(sl
, &i
);
363 ok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
364 ok(i
==SW_SHOWMAXIMIZED
, "GetShowCmd returned %d'\n", i
);
366 /* Test Getting / Setting the icon */
368 strcpy(buffer
,"garbage");
369 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
370 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
371 ok(*buffer
=='\0', "GetIconLocation returned '%s'\n", buffer
);
372 ok(i
==0, "GetIconLocation returned %d\n", i
);
374 str
="c:\\nonexistent\\file";
375 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
376 ok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
379 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
380 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
381 ok(lstrcmpiA(buffer
,str
)==0, "GetIconLocation returned '%s'\n", buffer
);
382 ok(i
==0xbabecafe, "GetIconLocation returned %d'\n", i
);
384 /* Test Getting / Setting the hot key */
386 r
= IShellLinkA_GetHotkey(sl
, &w
);
387 ok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
388 ok(w
==0, "GetHotkey returned %d\n", w
);
390 r
= IShellLinkA_SetHotkey(sl
, 0x5678);
391 ok(r
== S_OK
, "SetHotkey failed (0x%08x)\n", r
);
394 r
= IShellLinkA_GetHotkey(sl
, &w
);
395 ok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
396 ok(w
==0x5678, "GetHotkey returned %d'\n", w
);
398 IShellLinkA_Release(sl
);
403 * Test saving and loading .lnk files
406 #define lok ok_(__FILE__, line)
407 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
409 void create_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int save_fails
)
415 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
416 &IID_IShellLinkA
, (LPVOID
*)&sl
);
417 lok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
421 if (desc
->description
)
423 r
= IShellLinkA_SetDescription(sl
, desc
->description
);
424 lok(r
== S_OK
, "SetDescription failed (0x%08x)\n", r
);
428 r
= IShellLinkA_SetWorkingDirectory(sl
, desc
->workdir
);
429 lok(r
== S_OK
, "SetWorkingDirectory failed (0x%08x)\n", r
);
433 r
= IShellLinkA_SetPath(sl
, desc
->path
);
434 lok(SUCCEEDED(r
), "SetPath failed (0x%08x)\n", r
);
438 r
= IShellLinkA_SetIDList(sl
, desc
->pidl
);
439 lok(r
== S_OK
, "SetIDList failed (0x%08x)\n", r
);
443 r
= IShellLinkA_SetArguments(sl
, desc
->arguments
);
444 lok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
448 r
= IShellLinkA_SetShowCmd(sl
, desc
->showcmd
);
449 lok(r
== S_OK
, "SetShowCmd failed (0x%08x)\n", r
);
453 r
= IShellLinkA_SetIconLocation(sl
, desc
->icon
, desc
->icon_id
);
454 lok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
458 r
= IShellLinkA_SetHotkey(sl
, desc
->hotkey
);
459 lok(r
== S_OK
, "SetHotkey failed (0x%08x)\n", r
);
462 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (void**)&pf
);
463 lok(r
== S_OK
, "no IID_IPersistFile (0x%08x)\n", r
);
471 IPersistFile_GetCurFile(pf
, NULL
);
474 /* test GetCurFile before ::Save */
475 str
= (LPWSTR
)0xdeadbeef;
476 r
= IPersistFile_GetCurFile(pf
, &str
);
478 broken(r
== S_OK
), /* shell32 < 5.0 */
480 lok(str
== NULL
, "got %p\n", str
);
482 r
= IPersistFile_Save(pf
, path
, TRUE
);
483 todo_wine_if (save_fails
)
484 lok(r
== S_OK
, "save failed (0x%08x)\n", r
);
486 /* test GetCurFile after ::Save */
487 r
= IPersistFile_GetCurFile(pf
, &str
);
488 lok(r
== S_OK
, "got 0x%08x\n", r
);
490 broken(str
== NULL
), /* shell32 < 5.0 */
491 "Didn't expect NULL\n");
496 lok(!winetest_strcmpW(path
, str
), "Expected %s, got %s\n",
497 wine_dbgstr_w(path
), wine_dbgstr_w(str
));
499 SHGetMalloc(&pmalloc
);
500 IMalloc_Free(pmalloc
, str
);
503 win_skip("GetCurFile fails on shell32 < 5.0\n");
505 IPersistFile_Release(pf
);
508 IShellLinkA_Release(sl
);
511 static void check_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int todo
)
516 char buffer
[INFOTIPSIZE
];
519 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
520 &IID_IShellLinkA
, (LPVOID
*)&sl
);
521 lok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
525 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
526 lok(r
== S_OK
, "no IID_IPersistFile (0x%08x)\n", r
);
529 IShellLinkA_Release(sl
);
533 /* test GetCurFile before ::Load */
534 str
= (LPWSTR
)0xdeadbeef;
535 r
= IPersistFile_GetCurFile(pf
, &str
);
537 broken(r
== S_OK
), /* shell32 < 5.0 */
539 lok(str
== NULL
, "got %p\n", str
);
541 r
= IPersistFile_Load(pf
, path
, STGM_READ
);
542 lok(r
== S_OK
, "load failed (0x%08x)\n", r
);
544 /* test GetCurFile after ::Save */
545 r
= IPersistFile_GetCurFile(pf
, &str
);
546 lok(r
== S_OK
, "got 0x%08x\n", r
);
548 broken(str
== NULL
), /* shell32 < 5.0 */
549 "Didn't expect NULL\n");
554 lok(!winetest_strcmpW(path
, str
), "Expected %s, got %s\n",
555 wine_dbgstr_w(path
), wine_dbgstr_w(str
));
557 SHGetMalloc(&pmalloc
);
558 IMalloc_Free(pmalloc
, str
);
561 win_skip("GetCurFile fails on shell32 < 5.0\n");
563 IPersistFile_Release(pf
);
566 IShellLinkA_Release(sl
);
570 if (desc
->description
)
572 strcpy(buffer
,"garbage");
573 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
574 lok(r
== S_OK
, "GetDescription failed (0x%08x)\n", r
);
575 todo_wine_if ((todo
& 0x1) != 0)
576 lok(strcmp(buffer
, desc
->description
)==0, "GetDescription returned '%s' instead of '%s'\n",
577 buffer
, desc
->description
);
581 strcpy(buffer
,"garbage");
582 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
583 lok(r
== S_OK
, "GetWorkingDirectory failed (0x%08x)\n", r
);
584 todo_wine_if ((todo
& 0x2) != 0)
585 lok(lstrcmpiA(buffer
, desc
->workdir
)==0, "GetWorkingDirectory returned '%s' instead of '%s'\n",
586 buffer
, desc
->workdir
);
590 strcpy(buffer
,"garbage");
591 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
592 lok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
593 todo_wine_if ((todo
& 0x4) != 0)
594 lok(lstrcmpiA(buffer
, desc
->path
)==0, "GetPath returned '%s' instead of '%s'\n",
599 LPITEMIDLIST pidl
=NULL
;
600 r
= IShellLinkA_GetIDList(sl
, &pidl
);
601 lok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
602 todo_wine_if ((todo
& 0x8) != 0)
603 lok(pILIsEqual(pidl
, desc
->pidl
), "GetIDList returned an incorrect pidl\n");
608 r
= IShellLinkA_GetShowCmd(sl
, &i
);
609 lok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
610 todo_wine_if ((todo
& 0x10) != 0)
611 lok(i
==desc
->showcmd
, "GetShowCmd returned 0x%0x instead of 0x%0x\n",
617 strcpy(buffer
,"garbage");
618 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
619 lok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
620 todo_wine_if ((todo
& 0x20) != 0) {
621 lok(lstrcmpiA(buffer
, desc
->icon
)==0, "GetIconLocation returned '%s' instead of '%s'\n",
623 lok(i
==desc
->icon_id
, "GetIconLocation returned 0x%0x instead of 0x%0x\n",
630 r
= IShellLinkA_GetHotkey(sl
, &i
);
631 lok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
632 todo_wine_if ((todo
& 0x40) != 0)
633 lok(i
==desc
->hotkey
, "GetHotkey returned 0x%04x instead of 0x%04x\n",
637 IShellLinkA_Release(sl
);
640 static void test_load_save(void)
642 WCHAR lnkfile
[MAX_PATH
];
643 char lnkfileA
[MAX_PATH
];
644 static const char lnkfileA_name
[] = "\\test.lnk";
647 char mypath
[MAX_PATH
];
648 char mydir
[MAX_PATH
];
649 char realpath
[MAX_PATH
];
654 if (!pGetLongPathNameA
)
656 win_skip("GetLongPathNameA is not available\n");
660 /* Don't used a fixed path for the test.lnk file */
661 GetTempPathA(MAX_PATH
, lnkfileA
);
662 lstrcatA(lnkfileA
, lnkfileA_name
);
663 MultiByteToWideChar(CP_ACP
, 0, lnkfileA
, -1, lnkfile
, MAX_PATH
);
665 /* Save an empty .lnk file */
666 memset(&desc
, 0, sizeof(desc
));
667 create_lnk(lnkfile
, &desc
, 0);
669 /* It should come back as a bunch of empty strings */
675 check_lnk(lnkfile
, &desc
, 0x0);
677 /* Point a .lnk file to nonexistent files */
679 desc
.workdir
="c:\\Nonexitent\\work\\directory";
680 desc
.path
="c:\\nonexistent\\path";
684 desc
.icon
="c:\\nonexistent\\icon\\file";
687 create_lnk(lnkfile
, &desc
, 0);
688 check_lnk(lnkfile
, &desc
, 0x0);
690 r
=GetModuleFileNameA(NULL
, mypath
, sizeof(mypath
));
691 ok(r
<sizeof(mypath
), "GetModuleFileName failed (%d)\n", r
);
692 strcpy(mydir
, mypath
);
693 p
=strrchr(mydir
, '\\');
697 /* IShellLink returns path in long form */
698 if (!pGetLongPathNameA(mypath
, realpath
, MAX_PATH
)) strcpy( realpath
, mypath
);
700 /* Overwrite the existing lnk file and point it to existing files */
701 desc
.description
="test 2";
705 desc
.arguments
="/option1 /option2 \"Some string\"";
706 desc
.showcmd
=SW_SHOWNORMAL
;
710 create_lnk(lnkfile
, &desc
, 0);
711 check_lnk(lnkfile
, &desc
, 0x0);
713 /* Test omitting .exe from an absolute path */
714 p
=strrchr(realpath
, '.');
718 desc
.description
="absolute path without .exe";
722 desc
.arguments
="/option1 /option2 \"Some string\"";
723 desc
.showcmd
=SW_SHOWNORMAL
;
727 create_lnk(lnkfile
, &desc
, 0);
728 strcat(realpath
, ".exe");
729 check_lnk(lnkfile
, &desc
, 0x4);
731 /* Overwrite the existing lnk file and test link to a command on the path */
732 desc
.description
="command on path";
734 desc
.path
="rundll32.exe";
736 desc
.arguments
="/option1 /option2 \"Some string\"";
737 desc
.showcmd
=SW_SHOWNORMAL
;
741 create_lnk(lnkfile
, &desc
, 0);
742 /* Check that link is created to proper location */
743 SearchPathA( NULL
, desc
.path
, NULL
, MAX_PATH
, realpath
, NULL
);
745 check_lnk(lnkfile
, &desc
, 0x0);
747 /* Test omitting .exe from a command on the path */
748 desc
.description
="command on path without .exe";
750 desc
.path
="rundll32";
752 desc
.arguments
="/option1 /option2 \"Some string\"";
753 desc
.showcmd
=SW_SHOWNORMAL
;
757 create_lnk(lnkfile
, &desc
, 0);
758 /* Check that link is created to proper location */
759 SearchPathA( NULL
, "rundll32", NULL
, MAX_PATH
, realpath
, NULL
);
761 check_lnk(lnkfile
, &desc
, 0x4);
763 /* Create a temporary non-executable file */
764 r
=GetTempPathA(sizeof(mypath
), mypath
);
765 ok(r
<sizeof(mypath
), "GetTempPath failed (%d), err %d\n", r
, GetLastError());
766 r
=pGetLongPathNameA(mypath
, mydir
, sizeof(mydir
));
767 ok(r
<sizeof(mydir
), "GetLongPathName failed (%d), err %d\n", r
, GetLastError());
768 p
=strrchr(mydir
, '\\');
772 strcpy(mypath
, mydir
);
773 strcat(mypath
, "\\test.txt");
774 hf
= CreateFileA(mypath
, GENERIC_WRITE
, 0, NULL
,
775 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
778 /* Overwrite the existing lnk file and test link to an existing non-executable file */
779 desc
.description
="non-executable file";
784 desc
.showcmd
=SW_SHOWNORMAL
;
788 create_lnk(lnkfile
, &desc
, 0);
789 check_lnk(lnkfile
, &desc
, 0x0);
791 r
=pGetShortPathNameA(mydir
, mypath
, sizeof(mypath
));
792 ok(r
<sizeof(mypath
), "GetShortPathName failed (%d), err %d\n", r
, GetLastError());
794 strcpy(realpath
, mypath
);
795 strcat(realpath
, "\\test.txt");
796 strcat(mypath
, "\\\\test.txt");
798 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
799 desc
.description
="non-executable file";
804 desc
.showcmd
=SW_SHOWNORMAL
;
808 create_lnk(lnkfile
, &desc
, 0);
810 check_lnk(lnkfile
, &desc
, 0x0);
812 r
= DeleteFileA(mypath
);
813 ok(r
, "failed to delete file %s (%d)\n", mypath
, GetLastError());
815 /* Create a temporary .bat file */
816 strcpy(mypath
, mydir
);
817 strcat(mypath
, "\\test.bat");
818 hf
= CreateFileA(mypath
, GENERIC_WRITE
, 0, NULL
,
819 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
822 strcpy(realpath
, mypath
);
824 p
=strrchr(mypath
, '.');
828 /* Try linking to the .bat file without the extension */
829 desc
.description
="batch file";
834 desc
.showcmd
=SW_SHOWNORMAL
;
838 create_lnk(lnkfile
, &desc
, 0);
839 desc
.path
= realpath
;
840 check_lnk(lnkfile
, &desc
, 0x4);
842 r
= DeleteFileA(realpath
);
843 ok(r
, "failed to delete file %s (%d)\n", realpath
, GetLastError());
845 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
846 * represented as a path.
849 /* DeleteFileW is not implemented on Win9x */
850 r
=DeleteFileA(lnkfileA
);
851 ok(r
, "failed to delete link '%s' (%d)\n", lnkfileA
, GetLastError());
854 static void test_datalink(void)
856 static const WCHAR lnk
[] = {
857 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
858 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
859 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
860 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
861 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
862 '1','-',']',':',':',0 };
863 static const WCHAR comp
[] = {
864 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
865 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
866 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
867 IShellLinkDataList
*dl
= NULL
;
868 IShellLinkW
*sl
= NULL
;
871 EXP_DARWIN_LINK
*dar
;
873 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
874 &IID_IShellLinkW
, (LPVOID
*)&sl
);
876 broken(r
== E_NOINTERFACE
), /* Win9x */
877 "CoCreateInstance failed (0x%08x)\n", r
);
880 win_skip("no shelllink\n");
884 r
= IShellLinkW_QueryInterface( sl
, &_IID_IShellLinkDataList
, (LPVOID
*) &dl
);
886 broken(r
== E_NOINTERFACE
), /* NT4 */
887 "IShellLinkW_QueryInterface failed (0x%08x)\n", r
);
891 win_skip("no datalink interface\n");
892 IShellLinkW_Release( sl
);
897 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
898 ok( r
== S_OK
, "GetFlags failed\n");
899 ok( flags
== 0, "GetFlags returned wrong flags\n");
902 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
903 ok( r
== E_FAIL
, "CopyDataBlock failed\n");
904 ok( dar
== NULL
, "should be null\n");
906 if (!pGetLongPathNameA
/* NT4 */)
907 skip("SetPath with NULL parameter crashes on NT4\n");
910 r
= IShellLinkW_SetPath(sl
, NULL
);
911 ok(r
== E_INVALIDARG
, "SetPath returned wrong error (0x%08x)\n", r
);
914 r
= IShellLinkW_SetPath(sl
, lnk
);
915 ok(r
== S_OK
, "SetPath failed\n");
919 /* the following crashes */
920 IShellLinkDataList_GetFlags( dl
, NULL
);
924 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
925 ok( r
== S_OK
, "GetFlags failed\n");
926 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
927 ok( (flags
& (~ SLDF_HAS_LOGO3ID
)) == SLDF_HAS_DARWINID
,
928 "GetFlags returned wrong flags\n");
931 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
932 ok( r
== S_OK
, "CopyDataBlock failed\n");
934 ok( dar
&& ((DATABLOCK_HEADER
*)dar
)->dwSignature
== EXP_DARWIN_ID_SIG
, "signature wrong\n");
935 ok( dar
&& 0==lstrcmpW(dar
->szwDarwinID
, comp
), "signature wrong\n");
939 IShellLinkDataList_Release( dl
);
940 IShellLinkW_Release( sl
);
943 static void test_shdefextracticon(void)
945 HICON hiconlarge
=NULL
, hiconsmall
=NULL
;
948 if (!pSHDefExtractIconA
)
950 win_skip("SHDefExtractIconA is unavailable\n");
954 res
= pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge
, &hiconsmall
, MAKELONG(16,24));
955 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
956 ok(hiconlarge
!= NULL
, "got null hiconlarge\n");
957 ok(hiconsmall
!= NULL
, "got null hiconsmall\n");
958 DestroyIcon(hiconlarge
);
959 DestroyIcon(hiconsmall
);
962 res
= pSHDefExtractIconA("shell32.dll", 0, 0, NULL
, &hiconsmall
, MAKELONG(16,24));
963 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
964 ok(hiconsmall
!= NULL
, "got null hiconsmall\n");
965 DestroyIcon(hiconsmall
);
967 res
= pSHDefExtractIconA("shell32.dll", 0, 0, NULL
, NULL
, MAKELONG(16,24));
968 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
971 static void test_GetIconLocation(void)
975 char buffer
[INFOTIPSIZE
], mypath
[MAX_PATH
];
980 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
981 &IID_IShellLinkA
, (LPVOID
*)&sl
);
982 ok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
987 strcpy(buffer
, "garbage");
988 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
989 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
990 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
991 ok(i
== 0, "GetIconLocation returned %d\n", i
);
993 str
= "c:\\some\\path";
994 r
= IShellLinkA_SetPath(sl
, str
);
995 ok(r
== S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
998 strcpy(buffer
, "garbage");
999 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
1000 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
1001 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
1002 ok(i
== 0, "GetIconLocation returned %d\n", i
);
1004 GetWindowsDirectoryA(mypath
, sizeof(mypath
) - 12);
1005 strcat(mypath
, "\\regedit.exe");
1006 pidl
= path_to_pidl(mypath
);
1007 r
= IShellLinkA_SetIDList(sl
, pidl
);
1008 ok(r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
1012 strcpy(buffer
, "garbage");
1013 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
1014 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
1015 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
1016 ok(i
== 0, "GetIconLocation returned %d\n", i
);
1018 str
= "c:\\nonexistent\\file";
1019 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
1020 ok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
1023 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
1024 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
1025 ok(lstrcmpiA(buffer
,str
) == 0, "GetIconLocation returned '%s'\n", buffer
);
1026 ok(i
== 0xbabecafe, "GetIconLocation returned %d'\n", i
);
1028 IShellLinkA_Release(sl
);
1031 static void test_SHGetStockIconInfo(void)
1033 BYTE buffer
[sizeof(SHSTOCKICONINFO
) + 16];
1034 SHSTOCKICONINFO
*sii
= (SHSTOCKICONINFO
*) buffer
;
1038 /* not present before vista */
1039 if (!pSHGetStockIconInfo
)
1041 win_skip("SHGetStockIconInfo not available\n");
1045 /* negative values are handled */
1046 memset(buffer
, '#', sizeof(buffer
));
1047 sii
->cbSize
= sizeof(SHSTOCKICONINFO
);
1048 hr
= pSHGetStockIconInfo(SIID_INVALID
, SHGSI_ICONLOCATION
, sii
);
1049 ok(hr
== E_INVALIDARG
, "-1: got 0x%x (expected E_INVALIDARG)\n", hr
);
1051 /* max. id for vista is 140 (no definition exists for this value) */
1052 for (i
= SIID_DOCNOASSOC
; i
<= SIID_CLUSTEREDDRIVE
; i
++)
1054 memset(buffer
, '#', sizeof(buffer
));
1055 sii
->cbSize
= sizeof(SHSTOCKICONINFO
);
1056 hr
= pSHGetStockIconInfo(i
, SHGSI_ICONLOCATION
, sii
);
1059 "%3d: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x (expected S_OK)\n",
1060 i
, hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1062 if ((hr
== S_OK
) && (winetest_debug
> 1))
1063 trace("%3d: got iSysImageIndex %3d, iIcon %3d and %s\n", i
, sii
->iSysImageIndex
,
1064 sii
->iIcon
, wine_dbgstr_w(sii
->szPath
));
1067 /* test invalid icons indices that are invalid for all platforms */
1068 for (i
= SIID_MAX_ICONS
; i
< (SIID_MAX_ICONS
+ 25) ; i
++)
1070 memset(buffer
, '#', sizeof(buffer
));
1071 sii
->cbSize
= sizeof(SHSTOCKICONINFO
);
1072 hr
= pSHGetStockIconInfo(i
, SHGSI_ICONLOCATION
, sii
);
1073 ok(hr
== E_INVALIDARG
, "%3d: got 0x%x (expected E_INVALIDARG)\n", i
, hr
);
1075 ok(sii
->iSysImageIndex
== -1, "%d: got iSysImageIndex %d\n", i
, sii
->iSysImageIndex
);
1076 ok(sii
->iIcon
== -1, "%d: got iIcon %d\n", i
, sii
->iIcon
);
1080 /* test more returned SHSTOCKICONINFO elements without extra flags */
1081 memset(buffer
, '#', sizeof(buffer
));
1082 sii
->cbSize
= sizeof(SHSTOCKICONINFO
);
1083 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1084 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
1085 ok(!sii
->hIcon
, "got %p (expected NULL)\n", sii
->hIcon
);
1086 ok(sii
->iSysImageIndex
== -1, "got %d (expected -1)\n", sii
->iSysImageIndex
);
1088 /* the exact size is required of the struct */
1089 memset(buffer
, '#', sizeof(buffer
));
1090 sii
->cbSize
= sizeof(SHSTOCKICONINFO
) + 2;
1091 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1092 ok(hr
== E_INVALIDARG
, "+2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1094 memset(buffer
, '#', sizeof(buffer
));
1095 sii
->cbSize
= sizeof(SHSTOCKICONINFO
) + 1;
1096 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1097 ok(hr
== E_INVALIDARG
, "+1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1099 memset(buffer
, '#', sizeof(buffer
));
1100 sii
->cbSize
= sizeof(SHSTOCKICONINFO
) - 1;
1101 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1102 ok(hr
== E_INVALIDARG
, "-1: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1104 memset(buffer
, '#', sizeof(buffer
));
1105 sii
->cbSize
= sizeof(SHSTOCKICONINFO
) - 2;
1106 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, sii
);
1107 ok(hr
== E_INVALIDARG
, "-2: got 0x%x, iSysImageIndex: 0x%x, iIcon: 0x%x\n", hr
, sii
->iSysImageIndex
, sii
->iIcon
);
1109 /* there is a NULL check for the struct */
1110 hr
= pSHGetStockIconInfo(SIID_FOLDER
, SHGSI_ICONLOCATION
, NULL
);
1111 ok(hr
== E_INVALIDARG
, "NULL: got 0x%x\n", hr
);
1114 static void test_SHExtractIcons(void)
1116 static const WCHAR notepadW
[] = {'n','o','t','e','p','a','d','.','e','x','e',0};
1117 static const WCHAR shell32W
[] = {'s','h','e','l','l','3','2','.','d','l','l',0};
1118 static const WCHAR emptyW
[] = {0};
1123 if (!pSHExtractIconsW
)
1125 win_skip("SHExtractIconsW not available\n");
1129 ret
= pSHExtractIconsW(emptyW
, 0, 16, 16, icons
, ids
, 1, 0);
1130 ok(ret
== ~0u, "got %u\n", ret
);
1132 ret
= pSHExtractIconsW(notepadW
, 0, 16, 16, NULL
, NULL
, 1, 0);
1133 ok(ret
== 1 || broken(ret
== 2) /* win2k */, "got %u\n", ret
);
1135 icons
[0] = (HICON
)0xdeadbeef;
1136 ret
= pSHExtractIconsW(notepadW
, 0, 16, 16, icons
, NULL
, 1, 0);
1137 ok(ret
== 1, "got %u\n", ret
);
1138 ok(icons
[0] != (HICON
)0xdeadbeef, "icon not set\n");
1139 DestroyIcon(icons
[0]);
1141 icons
[0] = (HICON
)0xdeadbeef;
1142 ids
[0] = 0xdeadbeef;
1143 ret
= pSHExtractIconsW(notepadW
, 0, 16, 16, icons
, ids
, 1, 0);
1144 ok(ret
== 1, "got %u\n", ret
);
1145 ok(icons
[0] != (HICON
)0xdeadbeef, "icon not set\n");
1146 ok(ids
[0] != 0xdeadbeef, "id not set\n");
1147 DestroyIcon(icons
[0]);
1149 ret
= pSHExtractIconsW(shell32W
, 0, 16, 16, NULL
, NULL
, 0, 0);
1150 ret2
= pSHExtractIconsW(shell32W
, 4, MAKELONG(32,16), MAKELONG(32,16), NULL
, NULL
, 256, 0);
1151 ok(ret
&& ret
== ret2
,
1152 "icon count should be independent of requested icon sizes and base icon index\n");
1154 ret
= pSHExtractIconsW(shell32W
, 0, 16, 16, icons
, ids
, 0, 0);
1155 ok(ret
== ~0u || !ret
/* < vista */, "got %u\n", ret
);
1157 ret
= pSHExtractIconsW(shell32W
, 0, 16, 16, icons
, ids
, 3, 0);
1158 ok(ret
== 3, "got %u\n", ret
);
1159 for (i
= 0; i
< ret
; i
++) DestroyIcon(icons
[i
]);
1161 /* count must be a multiple of two when getting two sizes */
1162 ret
= pSHExtractIconsW(shell32W
, 0, MAKELONG(16,32), MAKELONG(16,32), icons
, ids
, 3, 0);
1163 ok(!ret
/* vista */ || ret
== 4, "got %u\n", ret
);
1164 for (i
= 0; i
< ret
; i
++) DestroyIcon(icons
[i
]);
1166 ret
= pSHExtractIconsW(shell32W
, 0, MAKELONG(16,32), MAKELONG(16,32), icons
, ids
, 4, 0);
1167 ok(ret
== 4, "got %u\n", ret
);
1168 for (i
= 0; i
< ret
; i
++) DestroyIcon(icons
[i
]);
1171 static void test_propertystore(void)
1178 hr
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
1179 &IID_IShellLinkA
, (void**)&linkA
);
1180 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1182 hr
= IShellLinkA_QueryInterface(linkA
, &IID_IShellLinkW
, (void**)&linkW
);
1183 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1185 hr
= IShellLinkA_QueryInterface(linkA
, &IID_IPropertyStore
, (void**)&ps
);
1187 IPropertyStoreCache
*pscache
;
1189 IPropertyStore_Release(ps
);
1191 hr
= IShellLinkW_QueryInterface(linkW
, &IID_IPropertyStore
, (void**)&ps
);
1192 ok(hr
== S_OK
, "got 0x%08x\n", hr
);
1194 hr
= IPropertyStore_QueryInterface(ps
, &IID_IPropertyStoreCache
, (void**)&pscache
);
1195 ok(hr
== E_NOINTERFACE
, "got 0x%08x\n", hr
);
1197 IPropertyStore_Release(ps
);
1200 win_skip("IShellLink doesn't support IPropertyStore.\n");
1202 IShellLinkA_Release(linkA
);
1203 IShellLinkW_Release(linkW
);
1206 static void test_ExtractIcon(void)
1208 static const WCHAR nameW
[] = {'\\','e','x','t','r','a','c','t','i','c','o','n','_','t','e','s','t','.','t','x','t',0};
1209 static const WCHAR shell32W
[] = {'s','h','e','l','l','3','2','.','d','l','l',0};
1210 WCHAR pathW
[MAX_PATH
];
1211 HICON hicon
, hicon2
;
1212 char path
[MAX_PATH
];
1218 /* specified instance handle */
1219 hicon
= ExtractIconA(GetModuleHandleA("shell32.dll"), NULL
, 0);
1221 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1222 hicon2
= ExtractIconA(GetModuleHandleA("shell32.dll"), "shell32.dll", -1);
1223 ok(hicon2
!= NULL
, "Got icon %p\n", hicon2
);
1225 /* existing index */
1226 hicon
= ExtractIconA(NULL
, "shell32.dll", 0);
1227 ok(hicon
!= NULL
&& HandleToLong(hicon
) != -1, "Got icon %p\n", hicon
);
1230 /* returns number of resources */
1231 hicon
= ExtractIconA(NULL
, "shell32.dll", -1);
1232 ok(HandleToLong(hicon
) > 1 && hicon
== hicon2
, "Got icon %p\n", hicon
);
1234 /* invalid index, valid dll name */
1235 hicon
= ExtractIconA(NULL
, "shell32.dll", 3000);
1236 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1238 /* Create a temporary non-executable file */
1239 GetTempPathA(sizeof(path
), path
);
1240 strcat(path
, "\\extracticon_test.txt");
1241 file
= CreateFileA(path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1242 ok(file
!= INVALID_HANDLE_VALUE
, "Failed to create a test file\n");
1245 hicon
= ExtractIconA(NULL
, path
, 0);
1247 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1249 hicon
= ExtractIconA(NULL
, path
, -1);
1250 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1252 hicon
= ExtractIconA(NULL
, path
, 1);
1254 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1256 r
= DeleteFileA(path
);
1257 ok(r
, "failed to delete file %s (%d)\n", path
, GetLastError());
1259 /* same for W variant */
1262 /* specified instance handle, crashes on XP, 2k3 */
1263 hicon
= ExtractIconW(GetModuleHandleA("shell32.dll"), NULL
, 0);
1264 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1266 hicon2
= ExtractIconW(GetModuleHandleA("shell32.dll"), shell32W
, -1);
1267 ok(hicon2
!= NULL
, "Got icon %p\n", hicon2
);
1269 /* existing index */
1270 hicon
= ExtractIconW(NULL
, shell32W
, 0);
1271 ok(hicon
!= NULL
&& HandleToLong(hicon
) != -1, "Got icon %p\n", hicon
);
1272 GetIconInfo(hicon
, &info
);
1273 GetObjectW(info
.hbmColor
, sizeof(bm
), &bm
);
1274 ok(bm
.bmWidth
== GetSystemMetrics(SM_CXICON
), "got %d\n", bm
.bmWidth
);
1275 ok(bm
.bmHeight
== GetSystemMetrics(SM_CYICON
), "got %d\n", bm
.bmHeight
);
1278 /* returns number of resources */
1279 hicon
= ExtractIconW(NULL
, shell32W
, -1);
1280 ok(HandleToLong(hicon
) > 1 && hicon
== hicon2
, "Got icon %p\n", hicon
);
1282 /* invalid index, valid dll name */
1283 hicon
= ExtractIconW(NULL
, shell32W
, 3000);
1284 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1286 /* Create a temporary non-executable file */
1287 GetTempPathW(sizeof(pathW
)/sizeof(pathW
[0]), pathW
);
1288 lstrcatW(pathW
, nameW
);
1289 file
= CreateFileW(pathW
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1290 ok(file
!= INVALID_HANDLE_VALUE
, "Failed to create a test file\n");
1293 hicon
= ExtractIconW(NULL
, pathW
, 0);
1295 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1297 hicon
= ExtractIconW(NULL
, pathW
, -1);
1298 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1300 hicon
= ExtractIconW(NULL
, pathW
, 1);
1302 ok(hicon
== NULL
, "Got icon %p\n", hicon
);
1304 r
= DeleteFileW(pathW
);
1305 ok(r
, "failed to delete file %s (%d)\n", path
, GetLastError());
1308 static void test_ExtractAssociatedIcon(void)
1310 char pathA
[MAX_PATH
];
1317 hicon
= ExtractAssociatedIconA(NULL
, pathA
, &index
);
1319 ok(hicon
!= NULL
, "Got icon %p\n", hicon
);
1320 ok(!*pathA
, "Unexpected path %s\n", pathA
);
1321 ok(index
== 0, "Unexpected index %u\n", index
);
1327 strcpy(pathA
, "shell32.dll");
1328 hicon
= ExtractAssociatedIconA(NULL
, pathA
, &index
);
1329 ok(hicon
!= NULL
, "Got icon %p\n", hicon
);
1330 ok(!strcmp(pathA
, "shell32.dll"), "Unexpected path %s\n", pathA
);
1331 ok(index
== 0, "Unexpected index %u\n", index
);
1334 /* valid dll name, invalid index */
1336 strcpy(pathA
, "user32.dll");
1337 hicon
= ExtractAssociatedIconA(NULL
, pathA
, &index
);
1338 CharLowerBuffA(pathA
, strlen(pathA
));
1340 ok(hicon
!= NULL
, "Got icon %p\n", hicon
);
1341 ok(!!strstr(pathA
, "shell32.dll"), "Unexpected path %s\n", pathA
);
1343 ok(index
!= 5000, "Unexpected index %u\n", index
);
1346 /* associated icon */
1348 strcpy(pathA
, "dummy.exe");
1349 hicon
= ExtractAssociatedIconA(NULL
, pathA
, &index
);
1350 CharLowerBuffA(pathA
, strlen(pathA
));
1352 ok(hicon
!= NULL
, "Got icon %p\n", hicon
);
1353 ok(!!strstr(pathA
, "shell32.dll"), "Unexpected path %s\n", pathA
);
1355 ok(index
!= 0xcaca, "Unexpected index %u\n", index
);
1359 static int get_shell_icon_size(void)
1362 DWORD value
= 32, size
= sizeof(buf
), type
;
1365 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Control Panel\\Desktop\\WindowMetrics", &key
))
1367 if (!RegQueryValueExA( key
, "Shell Icon Size", NULL
, &type
, (BYTE
*)buf
, &size
) && type
== REG_SZ
)
1368 value
= atoi( buf
);
1374 static void test_SHGetImageList(void)
1377 IImageList
*list
, *list2
;
1380 ULONG start_refs
, refs
;
1381 int i
, width
, height
, expect
;
1382 BOOL dpi_aware
= pIsProcessDPIAware
&& pIsProcessDPIAware();
1384 hr
= SHGetImageList( SHIL_LARGE
, &IID_IImageList
, (void **)&list
);
1385 ok( hr
== S_OK
, "got %08x\n", hr
);
1386 start_refs
= IImageList_AddRef( list
);
1387 IImageList_Release( list
);
1389 hr
= SHGetImageList( SHIL_LARGE
, &IID_IImageList
, (void **)&list2
);
1390 ok( hr
== S_OK
, "got %08x\n", hr
);
1391 ok( list
== list2
, "lists differ\n" );
1392 refs
= IImageList_AddRef( list
);
1393 IImageList_Release( list
);
1394 ok( refs
== start_refs
+ 1, "got %d, start_refs %d\n", refs
, start_refs
);
1395 IImageList_Release( list2
);
1397 hr
= SHGetImageList( SHIL_SMALL
, &IID_IImageList
, (void **)&list2
);
1398 ok( hr
== S_OK
, "got %08x\n", hr
);
1400 ret
= Shell_GetImageLists( &lg
, &sm
);
1401 ok( ret
, "got %d\n", ret
);
1402 ok( lg
== (HIMAGELIST
)list
, "mismatch\n" );
1403 ok( sm
== (HIMAGELIST
)list2
, "mismatch\n" );
1405 /* Shell_GetImageLists doesn't take a reference */
1406 refs
= IImageList_AddRef( list
);
1407 IImageList_Release( list
);
1408 ok( refs
== start_refs
, "got %d, start_refs %d\n", refs
, start_refs
);
1410 IImageList_Release( list2
);
1411 IImageList_Release( list
);
1413 /* Test the icon sizes */
1414 for (i
= 0; i
<= SHIL_LAST
; i
++)
1416 hr
= SHGetImageList( i
, &IID_IImageList
, (void **)&list
);
1417 todo_wine_if(i
== SHIL_EXTRALARGE
|| i
== SHIL_JUMBO
)
1419 broken( i
== SHIL_JUMBO
&& hr
== E_INVALIDARG
), /* XP and 2003 */
1420 "%d: got %08x\n", i
, hr
);
1421 if (FAILED(hr
)) continue;
1422 IImageList_GetIconSize( list
, &width
, &height
);
1426 if (dpi_aware
) expect
= GetSystemMetrics( SM_CXICON
);
1427 else expect
= get_shell_icon_size();
1430 if (dpi_aware
) expect
= GetSystemMetrics( SM_CXICON
) / 2;
1431 else expect
= GetSystemMetrics( SM_CXSMICON
);
1433 case SHIL_EXTRALARGE
:
1434 expect
= (GetSystemMetrics( SM_CXICON
) * 3) / 2;
1437 expect
= GetSystemMetrics( SM_CXSMICON
);
1443 todo_wine_if(i
== SHIL_SYSSMALL
&& dpi_aware
&& expect
!= GetSystemMetrics( SM_CXICON
) / 2)
1445 ok( width
== expect
, "%d: got %d expect %d\n", i
, width
, expect
);
1446 ok( height
== expect
, "%d: got %d expect %d\n", i
, height
, expect
);
1448 IImageList_Release( list
);
1452 START_TEST(shelllink
)
1455 HMODULE hmod
= GetModuleHandleA("shell32.dll");
1456 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
1457 HMODULE huser32
= GetModuleHandleA("user32.dll");
1459 pILFree
= (void *)GetProcAddress(hmod
, (LPSTR
)155);
1460 pILIsEqual
= (void *)GetProcAddress(hmod
, (LPSTR
)21);
1461 pSHILCreateFromPath
= (void *)GetProcAddress(hmod
, (LPSTR
)28);
1462 pSHGetFolderLocation
= (void *)GetProcAddress(hmod
, "SHGetFolderLocation");
1463 pSHDefExtractIconA
= (void *)GetProcAddress(hmod
, "SHDefExtractIconA");
1464 pSHGetStockIconInfo
= (void *)GetProcAddress(hmod
, "SHGetStockIconInfo");
1465 pGetLongPathNameA
= (void *)GetProcAddress(hkernel32
, "GetLongPathNameA");
1466 pGetShortPathNameA
= (void *)GetProcAddress(hkernel32
, "GetShortPathNameA");
1467 pSHExtractIconsW
= (void *)GetProcAddress(hmod
, "SHExtractIconsW");
1468 pIsProcessDPIAware
= (void *)GetProcAddress(huser32
, "IsProcessDPIAware");
1470 r
= CoInitialize(NULL
);
1471 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
1478 test_shdefextracticon();
1479 test_GetIconLocation();
1480 test_SHGetStockIconInfo();
1481 test_SHExtractIcons();
1482 test_propertystore();
1484 test_ExtractAssociatedIcon();
1485 test_SHGetImageList();