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 typedef void (WINAPI
*fnILFree
)(LPITEMIDLIST
);
41 typedef BOOL (WINAPI
*fnILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
);
42 typedef HRESULT (WINAPI
*fnSHILCreateFromPath
)(LPCWSTR
, LPITEMIDLIST
*,DWORD
*);
43 typedef HRESULT (WINAPI
*fnSHDefExtractIconA
)(LPCSTR
, int, UINT
, HICON
*, HICON
*, UINT
);
45 static fnILFree pILFree
;
46 static fnILIsEqual pILIsEqual
;
47 static fnSHILCreateFromPath pSHILCreateFromPath
;
48 static fnSHDefExtractIconA pSHDefExtractIconA
;
50 static DWORD (WINAPI
*pGetLongPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
52 static const GUID _IID_IShellLinkDataList
= {
53 0x45e2b4ae, 0xb1c3, 0x11d0,
54 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
57 static const WCHAR notafile
[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
60 /* For some reason SHILCreateFromPath does not work on Win98 and
61 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
62 * get what we want on all platforms.
64 static LPITEMIDLIST (WINAPI
*pSHSimpleIDListFromPathAW
)(LPCVOID
);
66 static LPITEMIDLIST
path_to_pidl(const char* path
)
70 if (!pSHSimpleIDListFromPathAW
)
72 HMODULE hdll
=GetModuleHandleA("shell32.dll");
73 pSHSimpleIDListFromPathAW
=(void*)GetProcAddress(hdll
, (char*)162);
74 if (!pSHSimpleIDListFromPathAW
)
75 win_skip("SHSimpleIDListFromPathAW not found in shell32.dll\n");
79 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
80 if (pSHSimpleIDListFromPathAW
&& (GetVersion() & 0x80000000))
81 pidl
=pSHSimpleIDListFromPathAW(path
);
89 len
=MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
90 pathW
=HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
91 MultiByteToWideChar(CP_ACP
, 0, path
, -1, pathW
, len
);
93 r
=pSHILCreateFromPath(pathW
, &pidl
, NULL
);
94 ok(SUCCEEDED(r
), "SHILCreateFromPath failed (0x%08x)\n", r
);
95 HeapFree(GetProcessHeap(), 0, pathW
);
102 * Test manipulation of an IShellLink's properties.
105 static void test_get_set(void)
109 char mypath
[MAX_PATH
];
110 char buffer
[INFOTIPSIZE
];
111 LPITEMIDLIST pidl
, tmp_pidl
;
116 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
117 &IID_IShellLinkA
, (LPVOID
*)&sl
);
118 ok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
122 /* Test Getting / Setting the description */
123 strcpy(buffer
,"garbage");
124 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
125 ok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
126 ok(*buffer
=='\0', "GetDescription returned '%s'\n", buffer
);
128 str
="Some description";
129 r
= IShellLinkA_SetDescription(sl
, str
);
130 ok(SUCCEEDED(r
), "SetDescription failed (0x%08x)\n", r
);
132 strcpy(buffer
,"garbage");
133 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
134 ok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
135 ok(lstrcmp(buffer
,str
)==0, "GetDescription returned '%s'\n", buffer
);
137 /* Test Getting / Setting the work directory */
138 strcpy(buffer
,"garbage");
139 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
140 ok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
141 ok(*buffer
=='\0', "GetWorkingDirectory returned '%s'\n", buffer
);
143 str
="c:\\nonexistent\\directory";
144 r
= IShellLinkA_SetWorkingDirectory(sl
, str
);
145 ok(SUCCEEDED(r
), "SetWorkingDirectory failed (0x%08x)\n", r
);
147 strcpy(buffer
,"garbage");
148 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
149 ok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
150 ok(lstrcmpi(buffer
,str
)==0, "GetWorkingDirectory returned '%s'\n", buffer
);
152 /* Test Getting / Setting the path */
153 strcpy(buffer
,"garbage");
154 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
155 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
156 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
158 r
= IShellLinkA_SetPath(sl
, "");
159 ok(r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
161 strcpy(buffer
,"garbage");
162 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
163 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
164 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
166 /* Win98 returns S_FALSE, but WinXP returns S_OK */
167 str
="c:\\nonexistent\\file";
168 r
= IShellLinkA_SetPath(sl
, str
);
169 ok(r
==S_FALSE
|| r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
171 strcpy(buffer
,"garbage");
172 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
173 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
174 ok(lstrcmpi(buffer
,str
)==0, "GetPath returned '%s'\n", buffer
);
176 /* Get some real path to play with */
177 GetWindowsDirectoryA( mypath
, sizeof(mypath
)-12 );
178 strcat(mypath
, "\\regedit.exe");
180 /* Test the interaction of SetPath and SetIDList */
182 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
183 ok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
188 strcpy(buffer
,"garbage");
189 ret
= SHGetPathFromIDListA(tmp_pidl
, buffer
);
191 ok(ret
, "SHGetPathFromIDListA failed\n");
194 ok(lstrcmpi(buffer
,str
)==0, "GetIDList returned '%s'\n", buffer
);
197 pidl
=path_to_pidl(mypath
);
198 ok(pidl
!=NULL
, "path_to_pidl returned a NULL pidl\n");
202 r
= IShellLinkA_SetIDList(sl
, pidl
);
203 ok(SUCCEEDED(r
), "SetIDList failed (0x%08x)\n", r
);
206 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
207 ok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
208 ok(tmp_pidl
&& pILIsEqual(pidl
, tmp_pidl
),
209 "GetIDList returned an incorrect pidl\n");
211 /* tmp_pidl is owned by IShellLink so we don't free it */
214 strcpy(buffer
,"garbage");
215 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
216 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
218 ok(lstrcmpi(buffer
, mypath
)==0, "GetPath returned '%s'\n", buffer
);
222 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
223 r
= IShellLinkA_SetPath(sl
, "\"c:\\nonexistent\\file\"");
224 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
226 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
227 ok(r
==S_OK
, "GetPath failed (0x%08x)\n", r
);
228 ok(!lstrcmp(buffer
, "C:\\nonexistent\\file") ||
229 broken(!lstrcmp(buffer
, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
230 "case doesn't match\n");
232 r
= IShellLinkA_SetPath(sl
, "\"c:\\foo");
233 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
235 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo");
236 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
238 r
= IShellLinkA_SetPath(sl
, "c:\\foo\"");
239 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
241 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"");
242 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
244 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"\"");
245 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
247 /* Test Getting / Setting the arguments */
248 strcpy(buffer
,"garbage");
249 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
250 ok(SUCCEEDED(r
), "GetArguments failed (0x%08x)\n", r
);
251 ok(*buffer
=='\0', "GetArguments returned '%s'\n", buffer
);
253 str
="param1 \"spaced param2\"";
254 r
= IShellLinkA_SetArguments(sl
, str
);
255 ok(SUCCEEDED(r
), "SetArguments failed (0x%08x)\n", r
);
257 strcpy(buffer
,"garbage");
258 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
259 ok(SUCCEEDED(r
), "GetArguments failed (0x%08x)\n", r
);
260 ok(lstrcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
262 /* Test Getting / Setting showcmd */
264 r
= IShellLinkA_GetShowCmd(sl
, &i
);
265 ok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
266 ok(i
==SW_SHOWNORMAL
, "GetShowCmd returned %d\n", i
);
268 r
= IShellLinkA_SetShowCmd(sl
, SW_SHOWMAXIMIZED
);
269 ok(SUCCEEDED(r
), "SetShowCmd failed (0x%08x)\n", r
);
272 r
= IShellLinkA_GetShowCmd(sl
, &i
);
273 ok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
274 ok(i
==SW_SHOWMAXIMIZED
, "GetShowCmd returned %d'\n", i
);
276 /* Test Getting / Setting the icon */
278 strcpy(buffer
,"garbage");
279 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
281 ok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
283 ok(*buffer
=='\0', "GetIconLocation returned '%s'\n", buffer
);
284 ok(i
==0, "GetIconLocation returned %d\n", i
);
286 str
="c:\\nonexistent\\file";
287 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
288 ok(SUCCEEDED(r
), "SetIconLocation failed (0x%08x)\n", r
);
291 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
292 ok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
293 ok(lstrcmpi(buffer
,str
)==0, "GetIconLocation returned '%s'\n", buffer
);
294 ok(i
==0xbabecafe, "GetIconLocation returned %d'\n", i
);
296 /* Test Getting / Setting the hot key */
298 r
= IShellLinkA_GetHotkey(sl
, &w
);
299 ok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
300 ok(w
==0, "GetHotkey returned %d\n", w
);
302 r
= IShellLinkA_SetHotkey(sl
, 0x5678);
303 ok(SUCCEEDED(r
), "SetHotkey failed (0x%08x)\n", r
);
306 r
= IShellLinkA_GetHotkey(sl
, &w
);
307 ok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
308 ok(w
==0x5678, "GetHotkey returned %d'\n", w
);
310 IShellLinkA_Release(sl
);
315 * Test saving and loading .lnk files
318 #define lok ok_(__FILE__, line)
319 #define lok_todo_4(todo_flag,a,b,c,d) \
320 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
321 else todo_wine lok((a), (b), (c), (d));
322 #define lok_todo_2(todo_flag,a,b) \
323 if ((todo & todo_flag) == 0) lok((a), (b)); \
324 else todo_wine lok((a), (b));
325 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
327 void create_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int save_fails
)
333 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
334 &IID_IShellLinkA
, (LPVOID
*)&sl
);
335 lok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
339 if (desc
->description
)
341 r
= IShellLinkA_SetDescription(sl
, desc
->description
);
342 lok(SUCCEEDED(r
), "SetDescription failed (0x%08x)\n", r
);
346 r
= IShellLinkA_SetWorkingDirectory(sl
, desc
->workdir
);
347 lok(SUCCEEDED(r
), "SetWorkingDirectory failed (0x%08x)\n", r
);
351 r
= IShellLinkA_SetPath(sl
, desc
->path
);
352 lok(SUCCEEDED(r
), "SetPath failed (0x%08x)\n", r
);
356 r
= IShellLinkA_SetIDList(sl
, desc
->pidl
);
357 lok(SUCCEEDED(r
), "SetIDList failed (0x%08x)\n", r
);
361 r
= IShellLinkA_SetArguments(sl
, desc
->arguments
);
362 lok(SUCCEEDED(r
), "SetArguments failed (0x%08x)\n", r
);
366 r
= IShellLinkA_SetShowCmd(sl
, desc
->showcmd
);
367 lok(SUCCEEDED(r
), "SetShowCmd failed (0x%08x)\n", r
);
371 r
= IShellLinkA_SetIconLocation(sl
, desc
->icon
, desc
->icon_id
);
372 lok(SUCCEEDED(r
), "SetIconLocation failed (0x%08x)\n", r
);
376 r
= IShellLinkA_SetHotkey(sl
, desc
->hotkey
);
377 lok(SUCCEEDED(r
), "SetHotkey failed (0x%08x)\n", r
);
380 r
= IShellLinkW_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
381 lok(SUCCEEDED(r
), "no IID_IPersistFile (0x%08x)\n", r
);
384 r
= IPersistFile_Save(pf
, path
, TRUE
);
388 lok(SUCCEEDED(r
), "save failed (0x%08x)\n", r
);
393 lok(SUCCEEDED(r
), "save failed (0x%08x)\n", r
);
395 IPersistFile_Release(pf
);
398 IShellLinkA_Release(sl
);
401 static void check_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int todo
)
406 char buffer
[INFOTIPSIZE
];
408 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
409 &IID_IShellLinkA
, (LPVOID
*)&sl
);
410 lok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
414 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
415 lok(SUCCEEDED(r
), "no IID_IPersistFile (0x%08x)\n", r
);
418 IShellLinkA_Release(sl
);
422 r
= IPersistFile_Load(pf
, path
, STGM_READ
);
423 lok(SUCCEEDED(r
), "load failed (0x%08x)\n", r
);
424 IPersistFile_Release(pf
);
427 IShellLinkA_Release(sl
);
431 if (desc
->description
)
433 strcpy(buffer
,"garbage");
434 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
435 lok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
436 lok_todo_4(0x1, lstrcmp(buffer
, desc
->description
)==0,
437 "GetDescription returned '%s' instead of '%s'\n",
438 buffer
, desc
->description
);
442 strcpy(buffer
,"garbage");
443 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
444 lok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
445 lok_todo_4(0x2, lstrcmpi(buffer
, desc
->workdir
)==0,
446 "GetWorkingDirectory returned '%s' instead of '%s'\n",
447 buffer
, desc
->workdir
);
451 strcpy(buffer
,"garbage");
452 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
453 lok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
454 lok_todo_4(0x4, lstrcmpi(buffer
, desc
->path
)==0,
455 "GetPath returned '%s' instead of '%s'\n",
460 LPITEMIDLIST pidl
=NULL
;
461 r
= IShellLinkA_GetIDList(sl
, &pidl
);
462 lok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
463 lok_todo_2(0x8, pILIsEqual(pidl
, desc
->pidl
),
464 "GetIDList returned an incorrect pidl\n");
469 r
= IShellLinkA_GetShowCmd(sl
, &i
);
470 lok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
471 lok_todo_4(0x10, i
==desc
->showcmd
,
472 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
478 strcpy(buffer
,"garbage");
479 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
480 lok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
481 lok_todo_4(0x20, lstrcmpi(buffer
, desc
->icon
)==0,
482 "GetIconLocation returned '%s' instead of '%s'\n",
484 lok_todo_4(0x20, i
==desc
->icon_id
,
485 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
491 r
= IShellLinkA_GetHotkey(sl
, &i
);
492 lok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
493 lok_todo_4(0x40, i
==desc
->hotkey
,
494 "GetHotkey returned 0x%04x instead of 0x%04x\n",
498 IShellLinkA_Release(sl
);
501 static void test_load_save(void)
503 WCHAR lnkfile
[MAX_PATH
];
504 char lnkfileA
[MAX_PATH
];
505 static const char lnkfileA_name
[] = "\\test.lnk";
508 char mypath
[MAX_PATH
];
509 char mydir
[MAX_PATH
];
510 char realpath
[MAX_PATH
];
515 if (!pGetLongPathNameA
)
517 win_skip("GetLongPathNameA is not available\n");
521 /* Don't used a fixed path for the test.lnk file */
522 GetTempPathA(MAX_PATH
, lnkfileA
);
523 lstrcatA(lnkfileA
, lnkfileA_name
);
524 MultiByteToWideChar(CP_ACP
, 0, lnkfileA
, -1, lnkfile
, MAX_PATH
);
526 /* Save an empty .lnk file */
527 memset(&desc
, 0, sizeof(desc
));
528 create_lnk(lnkfile
, &desc
, 0);
530 /* It should come back as a bunch of empty strings */
536 check_lnk(lnkfile
, &desc
, 0x0);
538 /* Point a .lnk file to nonexistent files */
540 desc
.workdir
="c:\\Nonexitent\\work\\directory";
541 desc
.path
="c:\\nonexistent\\path";
545 desc
.icon
="c:\\nonexistent\\icon\\file";
548 create_lnk(lnkfile
, &desc
, 0);
549 check_lnk(lnkfile
, &desc
, 0x0);
551 r
=GetModuleFileName(NULL
, mypath
, sizeof(mypath
));
552 ok(r
<sizeof(mypath
), "GetModuleFileName failed (%d)\n", r
);
553 strcpy(mydir
, mypath
);
554 p
=strrchr(mydir
, '\\');
558 /* IShellLink returns path in long form */
559 if (!pGetLongPathNameA(mypath
, realpath
, MAX_PATH
)) strcpy( realpath
, mypath
);
561 /* Overwrite the existing lnk file and point it to existing files */
562 desc
.description
="test 2";
566 desc
.arguments
="/option1 /option2 \"Some string\"";
567 desc
.showcmd
=SW_SHOWNORMAL
;
571 create_lnk(lnkfile
, &desc
, 0);
572 check_lnk(lnkfile
, &desc
, 0x0);
574 /* Overwrite the existing lnk file and test link to a command on the path */
575 desc
.description
="command on path";
577 desc
.path
="rundll32.exe";
579 desc
.arguments
="/option1 /option2 \"Some string\"";
580 desc
.showcmd
=SW_SHOWNORMAL
;
584 create_lnk(lnkfile
, &desc
, 0);
585 /* Check that link is created to proper location */
586 SearchPathA( NULL
, desc
.path
, NULL
, MAX_PATH
, realpath
, NULL
);
588 check_lnk(lnkfile
, &desc
, 0x0);
590 /* Create a temporary non-executable file */
591 r
=GetTempPath(sizeof(mypath
), mypath
);
592 ok(r
<sizeof(mypath
), "GetTempPath failed (%d), err %d\n", r
, GetLastError());
593 r
=pGetLongPathNameA(mypath
, mydir
, sizeof(mydir
));
594 ok(r
<sizeof(mydir
), "GetLongPathName failed (%d), err %d\n", r
, GetLastError());
595 p
=strrchr(mydir
, '\\');
599 strcpy(mypath
, mydir
);
600 strcat(mypath
, "\\test.txt");
601 hf
= CreateFile(mypath
, GENERIC_WRITE
, 0, NULL
,
602 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
605 /* Overwrite the existing lnk file and test link to an existing non-executable file */
606 desc
.description
="non-executable file";
611 desc
.showcmd
=SW_SHOWNORMAL
;
615 create_lnk(lnkfile
, &desc
, 0);
616 check_lnk(lnkfile
, &desc
, 0x0);
618 r
= DeleteFileA(mypath
);
619 ok(r
, "failed to delete file %s (%d)\n", mypath
, GetLastError());
621 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
622 * represented as a path.
625 /* DeleteFileW is not implemented on Win9x */
626 r
=DeleteFileA(lnkfileA
);
627 ok(r
, "failed to delete link '%s' (%d)\n", lnkfileA
, GetLastError());
630 static void test_datalink(void)
632 static const WCHAR lnk
[] = {
633 ':',':','{','9','d','b','1','1','8','6','f','-','4','0','d','f','-','1',
634 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
635 '8','6','3','}',':','{','0','0','0','1','0','4','0','9','-','7','8','E',
636 '1','-','1','1','D','2','-','B','6','0','F','-','0','0','6','0','9','7',
637 'C','9','9','8','E','7','}',':',':','{','9','d','b','1','1','8','6','e',
638 '-','4','0','d','f','-','1','1','d','1','-','a','a','8','c','-','0','0',
639 'c','0','4','f','b','6','7','8','6','3','}',':','2','6',',','!','!','g',
640 'x','s','f','(','N','g',']','q','F','`','H','{','L','s','A','C','C','E',
641 'S','S','F','i','l','e','s','>','p','l','T',']','j','I','{','j','f','(',
642 '=','1','&','L','[','-','8','1','-',']',':',':',0 };
643 static const WCHAR comp
[] = {
644 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
645 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
646 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
647 IShellLinkDataList
*dl
= NULL
;
648 IShellLinkW
*sl
= NULL
;
651 EXP_DARWIN_LINK
*dar
;
653 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
654 &IID_IShellLinkW
, (LPVOID
*)&sl
);
656 broken(r
== E_NOINTERFACE
), /* Win9x */
657 "CoCreateInstance failed (0x%08x)\n", r
);
660 win_skip("no shelllink\n");
664 r
= IShellLinkW_QueryInterface( sl
, &_IID_IShellLinkDataList
, (LPVOID
*) &dl
);
666 broken(r
== E_NOINTERFACE
), /* NT4 */
667 "IShellLinkW_QueryInterface failed (0x%08x)\n", r
);
671 win_skip("no datalink interface\n");
672 IShellLinkW_Release( sl
);
677 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
678 ok( r
== S_OK
, "GetFlags failed\n");
679 ok( flags
== 0, "GetFlags returned wrong flags\n");
682 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
683 ok( r
== E_FAIL
, "CopyDataBlock failed\n");
684 ok( dar
== NULL
, "should be null\n");
686 r
= IShellLinkW_SetPath(sl
, lnk
);
687 ok(r
== S_OK
, "set path failed\n");
690 * The following crashes:
691 * r = IShellLinkDataList_GetFlags( dl, NULL );
695 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
696 ok( r
== S_OK
, "GetFlags failed\n");
697 ok( flags
== (SLDF_HAS_DARWINID
|SLDF_HAS_LOGO3ID
),
698 "GetFlags returned wrong flags\n");
701 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
702 ok( r
== S_OK
, "CopyDataBlock failed\n");
704 ok( dar
&& ((DATABLOCK_HEADER
*)dar
)->dwSignature
== EXP_DARWIN_ID_SIG
, "signature wrong\n");
705 ok( dar
&& 0==lstrcmpW(dar
->szwDarwinID
, comp
), "signature wrong\n");
709 IUnknown_Release( dl
);
710 IShellLinkW_Release( sl
);
713 static void test_shdefextracticon(void)
715 HICON hiconlarge
=NULL
, hiconsmall
=NULL
;
718 if (!pSHDefExtractIconA
)
720 win_skip("SHDefExtractIconA is unavailable\n");
724 res
= pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge
, &hiconsmall
, MAKELONG(16,24));
725 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
726 ok(hiconlarge
!= NULL
, "got null hiconlarge\n");
727 ok(hiconsmall
!= NULL
, "got null hiconsmall\n");
728 DestroyIcon(hiconlarge
);
729 DestroyIcon(hiconsmall
);
732 res
= pSHDefExtractIconA("shell32.dll", 0, 0, NULL
, &hiconsmall
, MAKELONG(16,24));
733 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
734 ok(hiconsmall
!= NULL
, "got null hiconsmall\n");
735 DestroyIcon(hiconsmall
);
737 res
= pSHDefExtractIconA("shell32.dll", 0, 0, NULL
, NULL
, MAKELONG(16,24));
738 ok(SUCCEEDED(res
), "SHDefExtractIconA failed, res=%x\n", res
);
741 START_TEST(shelllink
)
744 HMODULE hmod
= GetModuleHandleA("shell32.dll");
745 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
747 pILFree
= (fnILFree
) GetProcAddress(hmod
, (LPSTR
)155);
748 pILIsEqual
= (fnILIsEqual
) GetProcAddress(hmod
, (LPSTR
)21);
749 pSHILCreateFromPath
= (fnSHILCreateFromPath
) GetProcAddress(hmod
, (LPSTR
)28);
750 pSHDefExtractIconA
= (fnSHDefExtractIconA
) GetProcAddress(hmod
, "SHDefExtractIconA");
752 pGetLongPathNameA
= (void *)GetProcAddress(hkernel32
, "GetLongPathNameA");
754 r
= CoInitialize(NULL
);
755 ok(SUCCEEDED(r
), "CoInitialize failed (0x%08x)\n", r
);
762 test_shdefextracticon();