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);
51 static DWORD (WINAPI *pGetShortPathNameA)(LPCSTR, LPSTR, DWORD);
53 static const GUID _IID_IShellLinkDataList = {
54 0x45e2b4ae, 0xb1c3, 0x11d0,
55 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
58 static const WCHAR notafile[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
61 /* For some reason SHILCreateFromPath does not work on Win98 and
62 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
63 * get what we want on all platforms.
65 static LPITEMIDLIST (WINAPI *pSHSimpleIDListFromPathAW)(LPCVOID);
67 static LPITEMIDLIST path_to_pidl(const char* path)
71 if (!pSHSimpleIDListFromPathAW)
73 HMODULE hdll=GetModuleHandleA("shell32.dll");
74 pSHSimpleIDListFromPathAW=(void*)GetProcAddress(hdll, (char*)162);
75 if (!pSHSimpleIDListFromPathAW)
76 win_skip("SHSimpleIDListFromPathAW not found in shell32.dll\n");
80 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
81 if (pSHSimpleIDListFromPathAW && (GetVersion() & 0x80000000))
82 pidl=pSHSimpleIDListFromPathAW(path);
90 len=MultiByteToWideChar(CP_ACP, 0, path, -1, NULL, 0);
91 pathW=HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
92 MultiByteToWideChar(CP_ACP, 0, path, -1, pathW, len);
94 r=pSHILCreateFromPath(pathW, &pidl, NULL);
95 ok(SUCCEEDED(r), "SHILCreateFromPath failed (0x%08x)\n", r);
96 HeapFree(GetProcessHeap(), 0, pathW);
103 * Test manipulation of an IShellLink's properties.
106 static void test_get_set(void)
110 char mypath[MAX_PATH];
111 char buffer[INFOTIPSIZE];
112 LPITEMIDLIST pidl, tmp_pidl;
117 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
118 &IID_IShellLinkA, (LPVOID*)&sl);
119 ok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
123 /* Test Getting / Setting the description */
124 strcpy(buffer,"garbage");
125 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
126 ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
127 ok(*buffer=='\0', "GetDescription returned '%s'\n", buffer);
129 str="Some description";
130 r = IShellLinkA_SetDescription(sl, str);
131 ok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
133 strcpy(buffer,"garbage");
134 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
135 ok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
136 ok(lstrcmp(buffer,str)==0, "GetDescription returned '%s'\n", buffer);
138 /* Test Getting / Setting the work directory */
139 strcpy(buffer,"garbage");
140 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
141 ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
142 ok(*buffer=='\0', "GetWorkingDirectory returned '%s'\n", buffer);
144 str="c:\\nonexistent\\directory";
145 r = IShellLinkA_SetWorkingDirectory(sl, str);
146 ok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
148 strcpy(buffer,"garbage");
149 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
150 ok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
151 ok(lstrcmpi(buffer,str)==0, "GetWorkingDirectory returned '%s'\n", buffer);
153 /* Test Getting / Setting the path */
154 strcpy(buffer,"garbage");
155 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
156 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
157 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
159 r = IShellLinkA_SetPath(sl, "");
160 ok(r==S_OK, "SetPath failed (0x%08x)\n", r);
162 strcpy(buffer,"garbage");
163 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
164 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
165 ok(*buffer=='\0', "GetPath returned '%s'\n", buffer);
167 /* Win98 returns S_FALSE, but WinXP returns S_OK */
168 str="c:\\nonexistent\\file";
169 r = IShellLinkA_SetPath(sl, str);
170 ok(r==S_FALSE || r==S_OK, "SetPath failed (0x%08x)\n", r);
172 strcpy(buffer,"garbage");
173 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
174 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
175 ok(lstrcmpi(buffer,str)==0, "GetPath returned '%s'\n", buffer);
177 /* Get some real path to play with */
178 GetWindowsDirectoryA( mypath, sizeof(mypath)-12 );
179 strcat(mypath, "\\regedit.exe");
181 /* Test the interaction of SetPath and SetIDList */
183 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
184 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
189 strcpy(buffer,"garbage");
190 ret = SHGetPathFromIDListA(tmp_pidl, buffer);
192 ok(ret, "SHGetPathFromIDListA failed\n");
195 ok(lstrcmpi(buffer,str)==0, "GetIDList returned '%s'\n", buffer);
198 pidl=path_to_pidl(mypath);
199 ok(pidl!=NULL, "path_to_pidl returned a NULL pidl\n");
203 r = IShellLinkA_SetIDList(sl, pidl);
204 ok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
207 r = IShellLinkA_GetIDList(sl, &tmp_pidl);
208 ok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
209 ok(tmp_pidl && pILIsEqual(pidl, tmp_pidl),
210 "GetIDList returned an incorrect pidl\n");
212 /* tmp_pidl is owned by IShellLink so we don't free it */
215 strcpy(buffer,"garbage");
216 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
217 ok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
219 ok(lstrcmpi(buffer, mypath)==0, "GetPath returned '%s'\n", buffer);
223 /* test path with quotes (IShellLinkA_SetPath returns S_FALSE on W2K and below and S_OK on XP and above */
224 r = IShellLinkA_SetPath(sl, "\"c:\\nonexistent\\file\"");
225 ok(r==S_FALSE || r == S_OK, "SetPath failed (0x%08x)\n", r);
227 strcpy(buffer,"garbage");
228 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
229 ok(r==S_OK, "GetPath failed (0x%08x)\n", r);
230 ok(!lstrcmp(buffer, "C:\\nonexistent\\file") ||
231 broken(!lstrcmp(buffer, "C:\\\"c:\\nonexistent\\file\"")), /* NT4 */
232 "case doesn't match\n");
234 r = IShellLinkA_SetPath(sl, "\"c:\\foo");
235 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
237 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo");
238 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
240 r = IShellLinkA_SetPath(sl, "c:\\foo\"");
241 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
243 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"");
244 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
246 r = IShellLinkA_SetPath(sl, "\"\"c:\\foo\"\"");
247 ok(r==S_FALSE || r == S_OK || r == E_INVALIDARG /* Vista */, "SetPath failed (0x%08x)\n", r);
249 /* Test Getting / Setting the arguments */
250 strcpy(buffer,"garbage");
251 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
252 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
253 ok(*buffer=='\0', "GetArguments returned '%s'\n", buffer);
255 str="param1 \"spaced param2\"";
256 r = IShellLinkA_SetArguments(sl, str);
257 ok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
259 strcpy(buffer,"garbage");
260 r = IShellLinkA_GetArguments(sl, buffer, sizeof(buffer));
261 ok(SUCCEEDED(r), "GetArguments failed (0x%08x)\n", r);
262 ok(lstrcmp(buffer,str)==0, "GetArguments returned '%s'\n", buffer);
264 /* Test Getting / Setting showcmd */
266 r = IShellLinkA_GetShowCmd(sl, &i);
267 ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
268 ok(i==SW_SHOWNORMAL, "GetShowCmd returned %d\n", i);
270 r = IShellLinkA_SetShowCmd(sl, SW_SHOWMAXIMIZED);
271 ok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
274 r = IShellLinkA_GetShowCmd(sl, &i);
275 ok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
276 ok(i==SW_SHOWMAXIMIZED, "GetShowCmd returned %d'\n", i);
278 /* Test Getting / Setting the icon */
280 strcpy(buffer,"garbage");
281 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
283 ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
285 ok(*buffer=='\0', "GetIconLocation returned '%s'\n", buffer);
286 ok(i==0, "GetIconLocation returned %d\n", i);
288 str="c:\\nonexistent\\file";
289 r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
290 ok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
293 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
294 ok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
295 ok(lstrcmpi(buffer,str)==0, "GetIconLocation returned '%s'\n", buffer);
296 ok(i==0xbabecafe, "GetIconLocation returned %d'\n", i);
298 /* Test Getting / Setting the hot key */
300 r = IShellLinkA_GetHotkey(sl, &w);
301 ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
302 ok(w==0, "GetHotkey returned %d\n", w);
304 r = IShellLinkA_SetHotkey(sl, 0x5678);
305 ok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
308 r = IShellLinkA_GetHotkey(sl, &w);
309 ok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
310 ok(w==0x5678, "GetHotkey returned %d'\n", w);
312 IShellLinkA_Release(sl);
317 * Test saving and loading .lnk files
320 #define lok ok_(__FILE__, line)
321 #define lok_todo_4(todo_flag,a,b,c,d) \
322 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
323 else todo_wine lok((a), (b), (c), (d));
324 #define lok_todo_2(todo_flag,a,b) \
325 if ((todo & todo_flag) == 0) lok((a), (b)); \
326 else todo_wine lok((a), (b));
327 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
329 void create_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int save_fails)
335 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
336 &IID_IShellLinkA, (LPVOID*)&sl);
337 lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
341 if (desc->description)
343 r = IShellLinkA_SetDescription(sl, desc->description);
344 lok(SUCCEEDED(r), "SetDescription failed (0x%08x)\n", r);
348 r = IShellLinkA_SetWorkingDirectory(sl, desc->workdir);
349 lok(SUCCEEDED(r), "SetWorkingDirectory failed (0x%08x)\n", r);
353 r = IShellLinkA_SetPath(sl, desc->path);
354 lok(SUCCEEDED(r), "SetPath failed (0x%08x)\n", r);
358 r = IShellLinkA_SetIDList(sl, desc->pidl);
359 lok(SUCCEEDED(r), "SetIDList failed (0x%08x)\n", r);
363 r = IShellLinkA_SetArguments(sl, desc->arguments);
364 lok(SUCCEEDED(r), "SetArguments failed (0x%08x)\n", r);
368 r = IShellLinkA_SetShowCmd(sl, desc->showcmd);
369 lok(SUCCEEDED(r), "SetShowCmd failed (0x%08x)\n", r);
373 r = IShellLinkA_SetIconLocation(sl, desc->icon, desc->icon_id);
374 lok(SUCCEEDED(r), "SetIconLocation failed (0x%08x)\n", r);
378 r = IShellLinkA_SetHotkey(sl, desc->hotkey);
379 lok(SUCCEEDED(r), "SetHotkey failed (0x%08x)\n", r);
382 r = IShellLinkW_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
383 lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
386 r = IPersistFile_Save(pf, path, TRUE);
390 lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
395 lok(SUCCEEDED(r), "save failed (0x%08x)\n", r);
397 IPersistFile_Release(pf);
400 IShellLinkA_Release(sl);
403 static void check_lnk_(int line, const WCHAR* path, lnk_desc_t* desc, int todo)
408 char buffer[INFOTIPSIZE];
410 r = CoCreateInstance(&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
411 &IID_IShellLinkA, (LPVOID*)&sl);
412 lok(SUCCEEDED(r), "no IID_IShellLinkA (0x%08x)\n", r);
416 r = IShellLinkA_QueryInterface(sl, &IID_IPersistFile, (LPVOID*)&pf);
417 lok(SUCCEEDED(r), "no IID_IPersistFile (0x%08x)\n", r);
420 IShellLinkA_Release(sl);
424 r = IPersistFile_Load(pf, path, STGM_READ);
425 lok(SUCCEEDED(r), "load failed (0x%08x)\n", r);
426 IPersistFile_Release(pf);
429 IShellLinkA_Release(sl);
433 if (desc->description)
435 strcpy(buffer,"garbage");
436 r = IShellLinkA_GetDescription(sl, buffer, sizeof(buffer));
437 lok(SUCCEEDED(r), "GetDescription failed (0x%08x)\n", r);
438 lok_todo_4(0x1, lstrcmp(buffer, desc->description)==0,
439 "GetDescription returned '%s' instead of '%s'\n",
440 buffer, desc->description);
444 strcpy(buffer,"garbage");
445 r = IShellLinkA_GetWorkingDirectory(sl, buffer, sizeof(buffer));
446 lok(SUCCEEDED(r), "GetWorkingDirectory failed (0x%08x)\n", r);
447 lok_todo_4(0x2, lstrcmpi(buffer, desc->workdir)==0,
448 "GetWorkingDirectory returned '%s' instead of '%s'\n",
449 buffer, desc->workdir);
453 strcpy(buffer,"garbage");
454 r = IShellLinkA_GetPath(sl, buffer, sizeof(buffer), NULL, SLGP_RAWPATH);
455 lok(SUCCEEDED(r), "GetPath failed (0x%08x)\n", r);
456 lok_todo_4(0x4, lstrcmpi(buffer, desc->path)==0,
457 "GetPath returned '%s' instead of '%s'\n",
462 LPITEMIDLIST pidl=NULL;
463 r = IShellLinkA_GetIDList(sl, &pidl);
464 lok(SUCCEEDED(r), "GetIDList failed (0x%08x)\n", r);
465 lok_todo_2(0x8, pILIsEqual(pidl, desc->pidl),
466 "GetIDList returned an incorrect pidl\n");
471 r = IShellLinkA_GetShowCmd(sl, &i);
472 lok(SUCCEEDED(r), "GetShowCmd failed (0x%08x)\n", r);
473 lok_todo_4(0x10, i==desc->showcmd,
474 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
480 strcpy(buffer,"garbage");
481 r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
482 lok(SUCCEEDED(r), "GetIconLocation failed (0x%08x)\n", r);
483 lok_todo_4(0x20, lstrcmpi(buffer, desc->icon)==0,
484 "GetIconLocation returned '%s' instead of '%s'\n",
486 lok_todo_4(0x20, i==desc->icon_id,
487 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
493 r = IShellLinkA_GetHotkey(sl, &i);
494 lok(SUCCEEDED(r), "GetHotkey failed (0x%08x)\n", r);
495 lok_todo_4(0x40, i==desc->hotkey,
496 "GetHotkey returned 0x%04x instead of 0x%04x\n",
500 IShellLinkA_Release(sl);
503 static void test_load_save(void)
505 WCHAR lnkfile[MAX_PATH];
506 char lnkfileA[MAX_PATH];
507 static const char lnkfileA_name[] = "\\test.lnk";
510 char mypath[MAX_PATH];
511 char mydir[MAX_PATH];
512 char realpath[MAX_PATH];
517 if (!pGetLongPathNameA)
519 win_skip("GetLongPathNameA is not available\n");
523 /* Don't used a fixed path for the test.lnk file */
524 GetTempPathA(MAX_PATH, lnkfileA);
525 lstrcatA(lnkfileA, lnkfileA_name);
526 MultiByteToWideChar(CP_ACP, 0, lnkfileA, -1, lnkfile, MAX_PATH);
528 /* Save an empty .lnk file */
529 memset(&desc, 0, sizeof(desc));
530 create_lnk(lnkfile, &desc, 0);
532 /* It should come back as a bunch of empty strings */
538 check_lnk(lnkfile, &desc, 0x0);
540 /* Point a .lnk file to nonexistent files */
542 desc.workdir="c:\\Nonexitent\\work\\directory";
543 desc.path="c:\\nonexistent\\path";
547 desc.icon="c:\\nonexistent\\icon\\file";
550 create_lnk(lnkfile, &desc, 0);
551 check_lnk(lnkfile, &desc, 0x0);
553 r=GetModuleFileName(NULL, mypath, sizeof(mypath));
554 ok(r<sizeof(mypath), "GetModuleFileName failed (%d)\n", r);
555 strcpy(mydir, mypath);
556 p=strrchr(mydir, '\\');
560 /* IShellLink returns path in long form */
561 if (!pGetLongPathNameA(mypath, realpath, MAX_PATH)) strcpy( realpath, mypath );
563 /* Overwrite the existing lnk file and point it to existing files */
564 desc.description="test 2";
568 desc.arguments="/option1 /option2 \"Some string\"";
569 desc.showcmd=SW_SHOWNORMAL;
573 create_lnk(lnkfile, &desc, 0);
574 check_lnk(lnkfile, &desc, 0x0);
576 /* Overwrite the existing lnk file and test link to a command on the path */
577 desc.description="command on path";
579 desc.path="rundll32.exe";
581 desc.arguments="/option1 /option2 \"Some string\"";
582 desc.showcmd=SW_SHOWNORMAL;
586 create_lnk(lnkfile, &desc, 0);
587 /* Check that link is created to proper location */
588 SearchPathA( NULL, desc.path, NULL, MAX_PATH, realpath, NULL);
590 check_lnk(lnkfile, &desc, 0x0);
592 /* Create a temporary non-executable file */
593 r=GetTempPath(sizeof(mypath), mypath);
594 ok(r<sizeof(mypath), "GetTempPath failed (%d), err %d\n", r, GetLastError());
595 r=pGetLongPathNameA(mypath, mydir, sizeof(mydir));
596 ok(r<sizeof(mydir), "GetLongPathName failed (%d), err %d\n", r, GetLastError());
597 p=strrchr(mydir, '\\');
601 strcpy(mypath, mydir);
602 strcat(mypath, "\\test.txt");
603 hf = CreateFile(mypath, GENERIC_WRITE, 0, NULL,
604 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
607 /* Overwrite the existing lnk file and test link to an existing non-executable file */
608 desc.description="non-executable file";
613 desc.showcmd=SW_SHOWNORMAL;
617 create_lnk(lnkfile, &desc, 0);
618 check_lnk(lnkfile, &desc, 0x0);
620 r=pGetShortPathNameA(mydir, mypath, sizeof(mypath));
621 strcpy(realpath, mypath);
622 strcat(realpath, "\\test.txt");
623 strcat(mypath, "\\\\test.txt");
625 /* Overwrite the existing lnk file and test link to a short path with double backslashes */
626 desc.description="non-executable file";
631 desc.showcmd=SW_SHOWNORMAL;
635 create_lnk(lnkfile, &desc, 0);
637 check_lnk(lnkfile, &desc, 0x0);
639 r = DeleteFileA(mypath);
640 ok(r, "failed to delete file %s (%d)\n", mypath, GetLastError());
642 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
643 * represented as a path.
646 /* DeleteFileW is not implemented on Win9x */
647 r=DeleteFileA(lnkfileA);
648 ok(r, "failed to delete link '%s' (%d)\n", lnkfileA, GetLastError());
651 static void test_datalink(void)
653 static const WCHAR lnk[] = {
654 ':',':','{','9','d','b','1','1','8','6','e','-','4','0','d','f','-','1',
655 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
656 '8','6','3','}',':','2','6',',','!','!','g','x','s','f','(','N','g',']',
657 'q','F','`','H','{','L','s','A','C','C','E','S','S','F','i','l','e','s',
658 '>','p','l','T',']','j','I','{','j','f','(','=','1','&','L','[','-','8',
659 '1','-',']',':',':',0 };
660 static const WCHAR comp[] = {
661 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
662 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
663 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
664 IShellLinkDataList *dl = NULL;
665 IShellLinkW *sl = NULL;
668 EXP_DARWIN_LINK *dar;
670 r = CoCreateInstance( &CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
671 &IID_IShellLinkW, (LPVOID*)&sl );
673 broken(r == E_NOINTERFACE), /* Win9x */
674 "CoCreateInstance failed (0x%08x)\n", r);
677 win_skip("no shelllink\n");
681 r = IShellLinkW_QueryInterface( sl, &_IID_IShellLinkDataList, (LPVOID*) &dl );
683 broken(r == E_NOINTERFACE), /* NT4 */
684 "IShellLinkW_QueryInterface failed (0x%08x)\n", r);
688 win_skip("no datalink interface\n");
689 IShellLinkW_Release( sl );
694 r = IShellLinkDataList_GetFlags( dl, &flags );
695 ok( r == S_OK, "GetFlags failed\n");
696 ok( flags == 0, "GetFlags returned wrong flags\n");
699 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
700 ok( r == E_FAIL, "CopyDataBlock failed\n");
701 ok( dar == NULL, "should be null\n");
703 r = IShellLinkW_SetPath(sl, lnk);
704 ok(r == S_OK, "set path failed\n");
707 * The following crashes:
708 * r = IShellLinkDataList_GetFlags( dl, NULL );
712 r = IShellLinkDataList_GetFlags( dl, &flags );
713 ok( r == S_OK, "GetFlags failed\n");
714 /* SLDF_HAS_LOGO3ID is no longer supported on Vista+, filter it out */
715 ok( (flags & (~ SLDF_HAS_LOGO3ID)) == SLDF_HAS_DARWINID,
716 "GetFlags returned wrong flags\n");
719 r = IShellLinkDataList_CopyDataBlock( dl, EXP_DARWIN_ID_SIG, (LPVOID*) &dar );
720 ok( r == S_OK, "CopyDataBlock failed\n");
722 ok( dar && ((DATABLOCK_HEADER*)dar)->dwSignature == EXP_DARWIN_ID_SIG, "signature wrong\n");
723 ok( dar && 0==lstrcmpW(dar->szwDarwinID, comp ), "signature wrong\n");
727 IUnknown_Release( dl );
728 IShellLinkW_Release( sl );
731 static void test_shdefextracticon(void)
733 HICON hiconlarge=NULL, hiconsmall=NULL;
736 if (!pSHDefExtractIconA)
738 win_skip("SHDefExtractIconA is unavailable\n");
742 res = pSHDefExtractIconA("shell32.dll", 0, 0, &hiconlarge, &hiconsmall, MAKELONG(16,24));
743 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
744 ok(hiconlarge != NULL, "got null hiconlarge\n");
745 ok(hiconsmall != NULL, "got null hiconsmall\n");
746 DestroyIcon(hiconlarge);
747 DestroyIcon(hiconsmall);
750 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, &hiconsmall, MAKELONG(16,24));
751 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
752 ok(hiconsmall != NULL, "got null hiconsmall\n");
753 DestroyIcon(hiconsmall);
755 res = pSHDefExtractIconA("shell32.dll", 0, 0, NULL, NULL, MAKELONG(16,24));
756 ok(SUCCEEDED(res), "SHDefExtractIconA failed, res=%x\n", res);
759 START_TEST(shelllink)
762 HMODULE hmod = GetModuleHandleA("shell32.dll");
763 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
765 pILFree = (fnILFree) GetProcAddress(hmod, (LPSTR)155);
766 pILIsEqual = (fnILIsEqual) GetProcAddress(hmod, (LPSTR)21);
767 pSHILCreateFromPath = (fnSHILCreateFromPath) GetProcAddress(hmod, (LPSTR)28);
768 pSHDefExtractIconA = (fnSHDefExtractIconA) GetProcAddress(hmod, "SHDefExtractIconA");
770 pGetLongPathNameA = (void *)GetProcAddress(hkernel32, "GetLongPathNameA");
771 pGetShortPathNameA = (void *)GetProcAddress(hkernel32, "GetShortPathNameA");
773 r = CoInitialize(NULL);
774 ok(SUCCEEDED(r), "CoInitialize failed (0x%08x)\n", r);
781 test_shdefextracticon();