2 * Unit tests for shelllinks
4 * Copyright 2004 Mike McCormack
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * This is a test program for the SHGet{Special}Folder{Path|Location} functions
20 * of shell32, that get either a filesystem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
32 #include "wine/test.h"
34 #include "shell32_test.h"
36 #ifndef SLDF_HAS_LOGO3ID
37 # define SLDF_HAS_LOGO3ID 0x00000800 /* not available in the Vista SDK */
40 static void (WINAPI
*pILFree
)(LPITEMIDLIST
);
41 static BOOL (WINAPI
*pILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
);
42 static HRESULT (WINAPI
*pSHILCreateFromPath
)(LPCWSTR
, LPITEMIDLIST
*,DWORD
*);
43 static HRESULT (WINAPI
*pSHDefExtractIconA
)(LPCSTR
, int, UINT
, HICON
*, HICON
*, UINT
);
45 static DWORD (WINAPI
*pGetLongPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
46 static DWORD (WINAPI
*pGetShortPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
48 static const GUID _IID_IShellLinkDataList
= {
49 0x45e2b4ae, 0xb1c3, 0x11d0,
50 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
53 static const WCHAR notafile
[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
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 LPITEMIDLIST pidl
, tmp_pidl
;
113 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
114 &IID_IShellLinkA
, (LPVOID
*)&sl
);
115 ok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
119 /* Test Getting / Setting the description */
120 strcpy(buffer
,"garbage");
121 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
122 ok(r
== S_OK
, "GetDescription failed (0x%08x)\n", r
);
123 ok(*buffer
=='\0', "GetDescription returned '%s'\n", buffer
);
125 str
="Some description";
126 r
= IShellLinkA_SetDescription(sl
, str
);
127 ok(r
== S_OK
, "SetDescription failed (0x%08x)\n", r
);
129 strcpy(buffer
,"garbage");
130 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
131 ok(r
== S_OK
, "GetDescription failed (0x%08x)\n", r
);
132 ok(lstrcmp(buffer
,str
)==0, "GetDescription returned '%s'\n", buffer
);
134 r
= IShellLinkA_SetDescription(sl
, NULL
);
135 ok(r
== S_OK
, "SetDescription failed (0x%08x)\n", r
);
137 strcpy(buffer
,"garbage");
138 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
139 ok(r
== S_OK
, "GetDescription failed (0x%08x)\n", r
);
140 ok(*buffer
=='\0' || broken(lstrcmp(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(lstrcmpi(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(lstrcmpi(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(lstrcmpi(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(lstrcmpi(buffer
, mypath
)==0, "GetPath returned '%s'\n", buffer
);
249 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
250 r
= IShellLinkA_SetPath(sl
, "\"c:\\nonexistent\\file\"");
251 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
253 strcpy(buffer
,"garbage");
254 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
255 ok(r
==S_OK
, "GetPath failed (0x%08x)\n", r
);
256 ok(!lstrcmp(buffer
, "C:\\nonexistent\\file") ||
257 broken(!lstrcmp(buffer
, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
258 "case doesn't match\n");
260 r
= IShellLinkA_SetPath(sl
, "\"c:\\foo");
261 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
263 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo");
264 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
266 r
= IShellLinkA_SetPath(sl
, "c:\\foo\"");
267 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
269 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"");
270 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
272 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"\"");
273 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
275 /* Test Getting / Setting the arguments */
276 strcpy(buffer
,"garbage");
277 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
278 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
279 ok(*buffer
=='\0', "GetArguments returned '%s'\n", buffer
);
281 str
="param1 \"spaced param2\"";
282 r
= IShellLinkA_SetArguments(sl
, str
);
283 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
285 strcpy(buffer
,"garbage");
286 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
287 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
288 ok(lstrcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
290 strcpy(buffer
,"garbage");
291 r
= IShellLinkA_SetArguments(sl
, NULL
);
292 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
293 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
294 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
295 ok(!buffer
[0] || lstrcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
297 strcpy(buffer
,"garbage");
298 r
= IShellLinkA_SetArguments(sl
, "");
299 ok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
300 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
301 ok(r
== S_OK
, "GetArguments failed (0x%08x)\n", r
);
302 ok(!buffer
[0], "GetArguments returned '%s'\n", buffer
);
304 /* Test Getting / Setting showcmd */
306 r
= IShellLinkA_GetShowCmd(sl
, &i
);
307 ok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
308 ok(i
==SW_SHOWNORMAL
, "GetShowCmd returned %d\n", i
);
310 r
= IShellLinkA_SetShowCmd(sl
, SW_SHOWMAXIMIZED
);
311 ok(r
== S_OK
, "SetShowCmd failed (0x%08x)\n", r
);
314 r
= IShellLinkA_GetShowCmd(sl
, &i
);
315 ok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
316 ok(i
==SW_SHOWMAXIMIZED
, "GetShowCmd returned %d'\n", i
);
318 /* Test Getting / Setting the icon */
320 strcpy(buffer
,"garbage");
321 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
322 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
323 ok(*buffer
=='\0', "GetIconLocation returned '%s'\n", buffer
);
324 ok(i
==0, "GetIconLocation returned %d\n", i
);
326 str
="c:\\nonexistent\\file";
327 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
328 ok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
331 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
332 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
333 ok(lstrcmpi(buffer
,str
)==0, "GetIconLocation returned '%s'\n", buffer
);
334 ok(i
==0xbabecafe, "GetIconLocation returned %d'\n", i
);
336 /* Test Getting / Setting the hot key */
338 r
= IShellLinkA_GetHotkey(sl
, &w
);
339 ok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
340 ok(w
==0, "GetHotkey returned %d\n", w
);
342 r
= IShellLinkA_SetHotkey(sl
, 0x5678);
343 ok(r
== S_OK
, "SetHotkey failed (0x%08x)\n", r
);
346 r
= IShellLinkA_GetHotkey(sl
, &w
);
347 ok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
348 ok(w
==0x5678, "GetHotkey returned %d'\n", w
);
350 IShellLinkA_Release(sl
);
355 * Test saving and loading .lnk files
358 #define lok ok_(__FILE__, line)
359 #define lok_todo_4(todo_flag,a,b,c,d) \
360 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
361 else todo_wine lok((a), (b), (c), (d));
362 #define lok_todo_2(todo_flag,a,b) \
363 if ((todo & todo_flag) == 0) lok((a), (b)); \
364 else todo_wine lok((a), (b));
365 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
367 void create_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int save_fails
)
373 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
374 &IID_IShellLinkA
, (LPVOID
*)&sl
);
375 lok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
379 if (desc
->description
)
381 r
= IShellLinkA_SetDescription(sl
, desc
->description
);
382 lok(r
== S_OK
, "SetDescription failed (0x%08x)\n", r
);
386 r
= IShellLinkA_SetWorkingDirectory(sl
, desc
->workdir
);
387 lok(r
== S_OK
, "SetWorkingDirectory failed (0x%08x)\n", r
);
391 r
= IShellLinkA_SetPath(sl
, desc
->path
);
392 lok(SUCCEEDED(r
), "SetPath failed (0x%08x)\n", r
);
396 r
= IShellLinkA_SetIDList(sl
, desc
->pidl
);
397 lok(r
== S_OK
, "SetIDList failed (0x%08x)\n", r
);
401 r
= IShellLinkA_SetArguments(sl
, desc
->arguments
);
402 lok(r
== S_OK
, "SetArguments failed (0x%08x)\n", r
);
406 r
= IShellLinkA_SetShowCmd(sl
, desc
->showcmd
);
407 lok(r
== S_OK
, "SetShowCmd failed (0x%08x)\n", r
);
411 r
= IShellLinkA_SetIconLocation(sl
, desc
->icon
, desc
->icon_id
);
412 lok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
416 r
= IShellLinkA_SetHotkey(sl
, desc
->hotkey
);
417 lok(r
== S_OK
, "SetHotkey failed (0x%08x)\n", r
);
420 r
= IShellLinkW_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
421 lok(r
== S_OK
, "no IID_IPersistFile (0x%08x)\n", r
);
429 IPersistFile_GetCurFile(pf
, NULL
);
432 /* test GetCurFile before ::Save */
433 str
= (LPWSTR
)0xdeadbeef;
434 r
= IPersistFile_GetCurFile(pf
, &str
);
436 broken(r
== S_OK
), /* shell32 < 5.0 */
438 lok(str
== NULL
, "got %p\n", str
);
440 r
= IPersistFile_Save(pf
, path
, TRUE
);
444 lok(r
== S_OK
, "save failed (0x%08x)\n", r
);
449 lok(r
== S_OK
, "save failed (0x%08x)\n", r
);
452 /* test GetCurFile after ::Save */
453 r
= IPersistFile_GetCurFile(pf
, &str
);
454 lok(r
== S_OK
, "got 0x%08x\n", r
);
456 broken(str
== NULL
), /* shell32 < 5.0 */
457 "Didn't expect NULL\n");
462 lok(!winetest_strcmpW(path
, str
), "Expected %s, got %s\n",
463 wine_dbgstr_w(path
), wine_dbgstr_w(str
));
465 SHGetMalloc(&pmalloc
);
466 IMalloc_Free(pmalloc
, str
);
469 win_skip("GetCurFile fails on shell32 < 5.0\n");
471 IPersistFile_Release(pf
);
474 IShellLinkA_Release(sl
);
477 static void check_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int todo
)
482 char buffer
[INFOTIPSIZE
];
485 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
486 &IID_IShellLinkA
, (LPVOID
*)&sl
);
487 lok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
491 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
492 lok(r
== S_OK
, "no IID_IPersistFile (0x%08x)\n", r
);
495 IShellLinkA_Release(sl
);
499 /* test GetCurFile before ::Load */
500 str
= (LPWSTR
)0xdeadbeef;
501 r
= IPersistFile_GetCurFile(pf
, &str
);
503 broken(r
== S_OK
), /* shell32 < 5.0 */
505 lok(str
== NULL
, "got %p\n", str
);
507 r
= IPersistFile_Load(pf
, path
, STGM_READ
);
508 lok(r
== S_OK
, "load failed (0x%08x)\n", r
);
510 /* test GetCurFile after ::Save */
511 r
= IPersistFile_GetCurFile(pf
, &str
);
512 lok(r
== S_OK
, "got 0x%08x\n", r
);
514 broken(str
== NULL
), /* shell32 < 5.0 */
515 "Didn't expect NULL\n");
520 lok(!winetest_strcmpW(path
, str
), "Expected %s, got %s\n",
521 wine_dbgstr_w(path
), wine_dbgstr_w(str
));
523 SHGetMalloc(&pmalloc
);
524 IMalloc_Free(pmalloc
, str
);
527 win_skip("GetCurFile fails on shell32 < 5.0\n");
529 IPersistFile_Release(pf
);
532 IShellLinkA_Release(sl
);
536 if (desc
->description
)
538 strcpy(buffer
,"garbage");
539 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
540 lok(r
== S_OK
, "GetDescription failed (0x%08x)\n", r
);
541 lok_todo_4(0x1, lstrcmp(buffer
, desc
->description
)==0,
542 "GetDescription returned '%s' instead of '%s'\n",
543 buffer
, desc
->description
);
547 strcpy(buffer
,"garbage");
548 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
549 lok(r
== S_OK
, "GetWorkingDirectory failed (0x%08x)\n", r
);
550 lok_todo_4(0x2, lstrcmpi(buffer
, desc
->workdir
)==0,
551 "GetWorkingDirectory returned '%s' instead of '%s'\n",
552 buffer
, desc
->workdir
);
556 strcpy(buffer
,"garbage");
557 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
558 lok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
559 lok_todo_4(0x4, lstrcmpi(buffer
, desc
->path
)==0,
560 "GetPath returned '%s' instead of '%s'\n",
565 LPITEMIDLIST pidl
=NULL
;
566 r
= IShellLinkA_GetIDList(sl
, &pidl
);
567 lok(r
== S_OK
, "GetIDList failed (0x%08x)\n", r
);
568 lok_todo_2(0x8, pILIsEqual(pidl
, desc
->pidl
),
569 "GetIDList returned an incorrect pidl\n");
574 r
= IShellLinkA_GetShowCmd(sl
, &i
);
575 lok(r
== S_OK
, "GetShowCmd failed (0x%08x)\n", r
);
576 lok_todo_4(0x10, i
==desc
->showcmd
,
577 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
583 strcpy(buffer
,"garbage");
584 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
585 lok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
586 lok_todo_4(0x20, lstrcmpi(buffer
, desc
->icon
)==0,
587 "GetIconLocation returned '%s' instead of '%s'\n",
589 lok_todo_4(0x20, i
==desc
->icon_id
,
590 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
596 r
= IShellLinkA_GetHotkey(sl
, &i
);
597 lok(r
== S_OK
, "GetHotkey failed (0x%08x)\n", r
);
598 lok_todo_4(0x40, i
==desc
->hotkey
,
599 "GetHotkey returned 0x%04x instead of 0x%04x\n",
603 IShellLinkA_Release(sl
);
606 static void test_load_save(void)
608 WCHAR lnkfile
[MAX_PATH
];
609 char lnkfileA
[MAX_PATH
];
610 static const char lnkfileA_name
[] = "\\test.lnk";
613 char mypath
[MAX_PATH
];
614 char mydir
[MAX_PATH
];
615 char realpath
[MAX_PATH
];
620 if (!pGetLongPathNameA
)
622 win_skip("GetLongPathNameA is not available\n");
626 /* Don't used a fixed path for the test.lnk file */
627 GetTempPathA(MAX_PATH
, lnkfileA
);
628 lstrcatA(lnkfileA
, lnkfileA_name
);
629 MultiByteToWideChar(CP_ACP
, 0, lnkfileA
, -1, lnkfile
, MAX_PATH
);
631 /* Save an empty .lnk file */
632 memset(&desc
, 0, sizeof(desc
));
633 create_lnk(lnkfile
, &desc
, 0);
635 /* It should come back as a bunch of empty strings */
641 check_lnk(lnkfile
, &desc
, 0x0);
643 /* Point a .lnk file to nonexistent files */
645 desc
.workdir
="c:\\Nonexitent\\work\\directory";
646 desc
.path
="c:\\nonexistent\\path";
650 desc
.icon
="c:\\nonexistent\\icon\\file";
653 create_lnk(lnkfile
, &desc
, 0);
654 check_lnk(lnkfile
, &desc
, 0x0);
656 r
=GetModuleFileName(NULL
, mypath
, sizeof(mypath
));
657 ok(r
<sizeof(mypath
), "GetModuleFileName failed (%d)\n", r
);
658 strcpy(mydir
, mypath
);
659 p
=strrchr(mydir
, '\\');
663 /* IShellLink returns path in long form */
664 if (!pGetLongPathNameA(mypath
, realpath
, MAX_PATH
)) strcpy( realpath
, mypath
);
666 /* Overwrite the existing lnk file and point it to existing files */
667 desc
.description
="test 2";
671 desc
.arguments
="/option1 /option2 \"Some string\"";
672 desc
.showcmd
=SW_SHOWNORMAL
;
676 create_lnk(lnkfile
, &desc
, 0);
677 check_lnk(lnkfile
, &desc
, 0x0);
679 /* Test omitting .exe from an absolute path */
680 p
=strrchr(realpath
, '.');
684 desc
.description
="absolute path without .exe";
688 desc
.arguments
="/option1 /option2 \"Some string\"";
689 desc
.showcmd
=SW_SHOWNORMAL
;
693 create_lnk(lnkfile
, &desc
, 0);
694 strcat(realpath
, ".exe");
695 check_lnk(lnkfile
, &desc
, 0x4);
697 /* Overwrite the existing lnk file and test link to a command on the path */
698 desc
.description
="command on path";
700 desc
.path
="rundll32.exe";
702 desc
.arguments
="/option1 /option2 \"Some string\"";
703 desc
.showcmd
=SW_SHOWNORMAL
;
707 create_lnk(lnkfile
, &desc
, 0);
708 /* Check that link is created to proper location */
709 SearchPathA( NULL
, desc
.path
, NULL
, MAX_PATH
, realpath
, NULL
);
711 check_lnk(lnkfile
, &desc
, 0x0);
713 /* Test omitting .exe from a command on the path */
714 desc
.description
="command on path without .exe";
716 desc
.path
="rundll32";
718 desc
.arguments
="/option1 /option2 \"Some string\"";
719 desc
.showcmd
=SW_SHOWNORMAL
;
723 create_lnk(lnkfile
, &desc
, 0);
724 /* Check that link is created to proper location */
725 SearchPathA( NULL
, "rundll32", NULL
, MAX_PATH
, realpath
, NULL
);
727 check_lnk(lnkfile
, &desc
, 0x4);
729 /* Create a temporary non-executable file */
730 r
=GetTempPath(sizeof(mypath
), mypath
);
731 ok(r
<sizeof(mypath
), "GetTempPath failed (%d), err %d\n", r
, GetLastError());
732 r
=pGetLongPathNameA(mypath
, mydir
, sizeof(mydir
));
733 ok(r
<sizeof(mydir
), "GetLongPathName failed (%d), err %d\n", r
, GetLastError());
734 p
=strrchr(mydir
, '\\');
738 strcpy(mypath
, mydir
);
739 strcat(mypath
, "\\test.txt");
740 hf
= CreateFile(mypath
, GENERIC_WRITE
, 0, NULL
,
741 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
744 /* Overwrite the existing lnk file and test link to an existing non-executable file */
745 desc
.description
="non-executable file";
750 desc
.showcmd
=SW_SHOWNORMAL
;
754 create_lnk(lnkfile
, &desc
, 0);
755 check_lnk(lnkfile
, &desc
, 0x0);
757 r
=pGetShortPathNameA(mydir
, mypath
, sizeof(mypath
));
758 ok(r
<sizeof(mypath
), "GetShortPathName failed (%d), err %d\n", r
, GetLastError());
760 strcpy(realpath
, mypath
);
761 strcat(realpath
, "\\test.txt");
762 strcat(mypath
, "\\\\test.txt");
764 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
765 desc
.description
="non-executable file";
770 desc
.showcmd
=SW_SHOWNORMAL
;
774 create_lnk(lnkfile
, &desc
, 0);
776 check_lnk(lnkfile
, &desc
, 0x0);
778 r
= DeleteFileA(mypath
);
779 ok(r
, "failed to delete file %s (%d)\n", mypath
, GetLastError());
781 /* Create a temporary .bat file */
782 strcpy(mypath
, mydir
);
783 strcat(mypath
, "\\test.bat");
784 hf
= CreateFile(mypath
, GENERIC_WRITE
, 0, NULL
,
785 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
788 strcpy(realpath
, mypath
);
790 p
=strrchr(mypath
, '.');
794 /* Try linking to the .bat file without the extension */
795 desc
.description
="batch file";
800 desc
.showcmd
=SW_SHOWNORMAL
;
804 create_lnk(lnkfile
, &desc
, 0);
805 desc
.path
= realpath
;
806 check_lnk(lnkfile
, &desc
, 0x4);
808 r
= DeleteFileA(realpath
);
809 ok(r
, "failed to delete file %s (%d)\n", realpath
, GetLastError());
811 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
812 * represented as a path.
815 /* DeleteFileW is not implemented on Win9x */
816 r
=DeleteFileA(lnkfileA
);
817 ok(r
, "failed to delete link '%s' (%d)\n", lnkfileA
, GetLastError());
820 static void test_datalink(void)
822 static const WCHAR lnk
[] = {
823 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
824 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
825 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
826 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
827 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
828 '1','-',']',':',':',0 };
829 static const WCHAR comp
[] = {
830 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
831 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
832 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
833 IShellLinkDataList
*dl
= NULL
;
834 IShellLinkW
*sl
= NULL
;
837 EXP_DARWIN_LINK
*dar
;
839 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
840 &IID_IShellLinkW
, (LPVOID
*)&sl
);
842 broken(r
== E_NOINTERFACE
), /* Win9x */
843 "CoCreateInstance failed (0x%08x)\n", r
);
846 win_skip("no shelllink\n");
850 r
= IShellLinkW_QueryInterface( sl
, &_IID_IShellLinkDataList
, (LPVOID
*) &dl
);
852 broken(r
== E_NOINTERFACE
), /* NT4 */
853 "IShellLinkW_QueryInterface failed (0x%08x)\n", r
);
857 win_skip("no datalink interface\n");
858 IShellLinkW_Release( sl
);
863 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
864 ok( r
== S_OK
, "GetFlags failed\n");
865 ok( flags
== 0, "GetFlags returned wrong flags\n");
868 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
869 ok( r
== E_FAIL
, "CopyDataBlock failed\n");
870 ok( dar
== NULL
, "should be null\n");
872 if (!pGetLongPathNameA
/* NT4 */)
873 skip("SetPath with NULL parameter crashes on NT4\n");
876 r
= IShellLinkW_SetPath(sl
, NULL
);
877 ok(r
== E_INVALIDARG
, "SetPath returned wrong error (0x%08x)\n", r
);
880 r
= IShellLinkW_SetPath(sl
, lnk
);
881 ok(r
== S_OK
, "SetPath failed\n");
885 /* the following crashes */
886 IShellLinkDataList_GetFlags( dl
, NULL
);
890 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
891 ok( r
== S_OK
, "GetFlags failed\n");
892 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
893 ok( (flags
& (~ SLDF_HAS_LOGO3ID
)) == SLDF_HAS_DARWINID
,
894 "GetFlags returned wrong flags\n");
897 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
898 ok( r
== S_OK
, "CopyDataBlock failed\n");
900 ok( dar
&& ((DATABLOCK_HEADER
*)dar
)->dwSignature
== EXP_DARWIN_ID_SIG
, "signature wrong\n");
901 ok( dar
&& 0==lstrcmpW(dar
->szwDarwinID
, comp
), "signature wrong\n");
905 IUnknown_Release( dl
);
906 IShellLinkW_Release( sl
);
909 static void test_shdefextracticon(void)
911 HICON hiconlarge
=NULL
, hiconsmall
=NULL
;
914 if (!pSHDefExtractIconA
)
916 win_skip("SHDefExtractIconA is unavailable\n");
920 res
= pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge
, &hiconsmall
, MAKELONG(16,24));
921 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
922 ok(hiconlarge
!= NULL
, "got null hiconlarge\n");
923 ok(hiconsmall
!= NULL
, "got null hiconsmall\n");
924 DestroyIcon(hiconlarge
);
925 DestroyIcon(hiconsmall
);
928 res
= pSHDefExtractIconA("shell32.dll", 0, 0, NULL
, &hiconsmall
, MAKELONG(16,24));
929 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
930 ok(hiconsmall
!= NULL
, "got null hiconsmall\n");
931 DestroyIcon(hiconsmall
);
933 res
= pSHDefExtractIconA("shell32.dll", 0, 0, NULL
, NULL
, MAKELONG(16,24));
934 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
937 static void test_GetIconLocation(void)
941 char buffer
[INFOTIPSIZE
], mypath
[MAX_PATH
];
946 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
947 &IID_IShellLinkA
, (LPVOID
*)&sl
);
948 ok(r
== S_OK
, "no IID_IShellLinkA (0x%08x)\n", r
);
953 strcpy(buffer
, "garbage");
954 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
955 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
956 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
957 ok(i
== 0, "GetIconLocation returned %d\n", i
);
959 str
= "c:\\some\\path";
960 r
= IShellLinkA_SetPath(sl
, str
);
961 ok(r
== S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
964 strcpy(buffer
, "garbage");
965 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
966 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
967 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
968 ok(i
== 0, "GetIconLocation returned %d\n", i
);
970 GetWindowsDirectoryA(mypath
, sizeof(mypath
) - 12);
971 strcat(mypath
, "\\regedit.exe");
972 pidl
= path_to_pidl(mypath
);
973 r
= IShellLinkA_SetIDList(sl
, pidl
);
974 ok(r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
978 strcpy(buffer
, "garbage");
979 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
980 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
981 ok(*buffer
== '\0', "GetIconLocation returned '%s'\n", buffer
);
982 ok(i
== 0, "GetIconLocation returned %d\n", i
);
984 str
= "c:\\nonexistent\\file";
985 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
986 ok(r
== S_OK
, "SetIconLocation failed (0x%08x)\n", r
);
989 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
990 ok(r
== S_OK
, "GetIconLocation failed (0x%08x)\n", r
);
991 ok(lstrcmpi(buffer
,str
) == 0, "GetIconLocation returned '%s'\n", buffer
);
992 ok(i
== 0xbabecafe, "GetIconLocation returned %d'\n", i
);
994 IShellLinkA_Release(sl
);
997 START_TEST(shelllink
)
1000 HMODULE hmod
= GetModuleHandleA("shell32.dll");
1001 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
1003 pILFree
= (void *)GetProcAddress(hmod
, (LPSTR
)155);
1004 pILIsEqual
= (void *)GetProcAddress(hmod
, (LPSTR
)21);
1005 pSHILCreateFromPath
= (void *)GetProcAddress(hmod
, (LPSTR
)28);
1006 pSHDefExtractIconA
= (void *)GetProcAddress(hmod
, "SHDefExtractIconA");
1008 pGetLongPathNameA
= (void *)GetProcAddress(hkernel32
, "GetLongPathNameA");
1009 pGetShortPathNameA
= (void *)GetProcAddress(hkernel32
, "GetShortPathNameA");
1011 r
= CoInitialize(NULL
);
1012 ok(r
== S_OK
, "CoInitialize failed (0x%08x)\n", r
);
1019 test_shdefextracticon();
1020 test_GetIconLocation();