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 filesytem path or a LPITEMIDLIST (shell
21 * namespace) path for a given folder (CSIDL value).
31 #include "wine/test.h"
33 #include "shell32_test.h"
36 typedef void (WINAPI
*fnILFree
)(LPITEMIDLIST
);
37 typedef BOOL (WINAPI
*fnILIsEqual
)(LPCITEMIDLIST
, LPCITEMIDLIST
);
38 typedef HRESULT (WINAPI
*fnSHILCreateFromPath
)(LPCWSTR
, LPITEMIDLIST
*,DWORD
*);
40 static fnILFree pILFree
;
41 static fnILIsEqual pILIsEqual
;
42 static fnSHILCreateFromPath pSHILCreateFromPath
;
44 static DWORD (WINAPI
*pGetLongPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
46 static const GUID _IID_IShellLinkDataList
= {
47 0x45e2b4ae, 0xb1c3, 0x11d0,
48 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
51 static const WCHAR lnkfile
[]= { 'C',':','\\','t','e','s','t','.','l','n','k',0 };
52 static const WCHAR notafile
[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
55 /* For some reason SHILCreateFromPath does not work on Win98 and
56 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
57 * get what we want on all platforms.
59 static LPITEMIDLIST (WINAPI
*pSHSimpleIDListFromPathAW
)(LPCVOID
);
61 static LPITEMIDLIST
path_to_pidl(const char* path
)
65 if (!pSHSimpleIDListFromPathAW
)
67 HMODULE hdll
=GetModuleHandleA("shell32.dll");
68 pSHSimpleIDListFromPathAW
=(void*)GetProcAddress(hdll
, (char*)162);
69 if (!pSHSimpleIDListFromPathAW
)
70 trace("SHSimpleIDListFromPathAW not found in shell32.dll\n");
74 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
75 if (pSHSimpleIDListFromPathAW
&& (GetVersion() & 0x80000000))
76 pidl
=pSHSimpleIDListFromPathAW(path
);
84 len
=MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
85 pathW
=HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
86 MultiByteToWideChar(CP_ACP
, 0, path
, -1, pathW
, len
);
88 r
=pSHILCreateFromPath(pathW
, &pidl
, NULL
);
90 ok(SUCCEEDED(r
), "SHILCreateFromPath failed (0x%08x)\n", r
);
92 HeapFree(GetProcessHeap(), 0, pathW
);
99 * Test manipulation of an IShellLink's properties.
102 static void test_get_set(void)
106 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(SUCCEEDED(r
), "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(SUCCEEDED(r
), "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(SUCCEEDED(r
), "SetDescription failed (0x%08x)\n", r
);
129 strcpy(buffer
,"garbage");
130 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
131 ok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
132 ok(lstrcmp(buffer
,str
)==0, "GetDescription returned '%s'\n", buffer
);
134 /* Test Getting / Setting the work directory */
135 strcpy(buffer
,"garbage");
136 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
137 ok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
138 ok(*buffer
=='\0', "GetWorkingDirectory returned '%s'\n", buffer
);
140 str
="c:\\nonexistent\\directory";
141 r
= IShellLinkA_SetWorkingDirectory(sl
, str
);
142 ok(SUCCEEDED(r
), "SetWorkingDirectory failed (0x%08x)\n", r
);
144 strcpy(buffer
,"garbage");
145 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
146 ok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
147 ok(lstrcmpi(buffer
,str
)==0, "GetWorkingDirectory returned '%s'\n", buffer
);
149 /* Test Getting / Setting the path */
150 strcpy(buffer
,"garbage");
151 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
152 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
153 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
155 r
= IShellLinkA_SetPath(sl
, "");
156 ok(r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
158 strcpy(buffer
,"garbage");
159 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
160 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
161 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
163 /* Win98 returns S_FALSE, but WinXP returns S_OK */
164 str
="c:\\nonexistent\\file";
165 r
= IShellLinkA_SetPath(sl
, str
);
166 ok(r
==S_FALSE
|| r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
168 strcpy(buffer
,"garbage");
169 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
170 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
171 ok(lstrcmpi(buffer
,str
)==0, "GetPath returned '%s'\n", buffer
);
173 /* Get some a real path to play with */
174 r
=GetModuleFileName(NULL
, mypath
, sizeof(mypath
));
175 ok(r
>=0 && r
<sizeof(mypath
), "GetModuleFileName failed (%d)\n", r
);
177 /* Test the interaction of SetPath and SetIDList */
179 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
180 ok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
183 strcpy(buffer
,"garbage");
184 r
=SHGetPathFromIDListA(tmp_pidl
, buffer
);
186 ok(r
, "SHGetPathFromIDListA failed\n");
189 ok(lstrcmpi(buffer
,str
)==0, "GetIDList returned '%s'\n", buffer
);
192 pidl
=path_to_pidl(mypath
);
194 ok(pidl
!=NULL
, "path_to_pidl returned a NULL pidl\n");
199 r
= IShellLinkA_SetIDList(sl
, pidl
);
200 ok(SUCCEEDED(r
), "SetIDList failed (0x%08x)\n", r
);
203 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
204 ok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
205 ok(tmp_pidl
&& pILIsEqual(pidl
, tmp_pidl
),
206 "GetIDList returned an incorrect pidl\n");
208 /* tmp_pidl is owned by IShellLink so we don't free it */
211 strcpy(buffer
,"garbage");
212 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
213 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
214 ok(lstrcmpi(buffer
, mypath
)==0, "GetPath returned '%s'\n", buffer
);
217 /* test path with quotes (Win98 IShellLinkA_SetPath returns S_FALSE, WinXP returns S_OK) */
218 r
= IShellLinkA_SetPath(sl
, "\"c:\\nonexistent\\file\"");
219 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
221 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
222 ok(r
==S_OK
, "GetPath failed (0x%08x)\n", r
);
223 ok(!lstrcmp(buffer
, "C:\\nonexistent\\file"), "case doesn't match\n");
225 r
= IShellLinkA_SetPath(sl
, "\"c:\\foo");
226 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
228 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo");
229 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
231 r
= IShellLinkA_SetPath(sl
, "c:\\foo\"");
232 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
234 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"");
235 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
237 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo\"\"");
238 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
240 /* Test Getting / Setting the arguments */
241 strcpy(buffer
,"garbage");
242 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
243 ok(SUCCEEDED(r
), "GetArguments failed (0x%08x)\n", r
);
244 ok(*buffer
=='\0', "GetArguments returned '%s'\n", buffer
);
246 str
="param1 \"spaced param2\"";
247 r
= IShellLinkA_SetArguments(sl
, str
);
248 ok(SUCCEEDED(r
), "SetArguments failed (0x%08x)\n", r
);
250 strcpy(buffer
,"garbage");
251 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
252 ok(SUCCEEDED(r
), "GetArguments failed (0x%08x)\n", r
);
253 ok(lstrcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
255 /* Test Getting / Setting showcmd */
257 r
= IShellLinkA_GetShowCmd(sl
, &i
);
258 ok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
259 ok(i
==SW_SHOWNORMAL
, "GetShowCmd returned %d\n", i
);
261 r
= IShellLinkA_SetShowCmd(sl
, SW_SHOWMAXIMIZED
);
262 ok(SUCCEEDED(r
), "SetShowCmd failed (0x%08x)\n", r
);
265 r
= IShellLinkA_GetShowCmd(sl
, &i
);
266 ok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
267 ok(i
==SW_SHOWMAXIMIZED
, "GetShowCmd returned %d'\n", i
);
269 /* Test Getting / Setting the icon */
271 strcpy(buffer
,"garbage");
272 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
274 ok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
276 ok(*buffer
=='\0', "GetIconLocation returned '%s'\n", buffer
);
277 ok(i
==0, "GetIconLocation returned %d\n", i
);
279 str
="c:\\nonexistent\\file";
280 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
281 ok(SUCCEEDED(r
), "SetIconLocation failed (0x%08x)\n", r
);
284 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
285 ok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
286 ok(lstrcmpi(buffer
,str
)==0, "GetIconLocation returned '%s'\n", buffer
);
287 ok(i
==0xbabecafe, "GetIconLocation returned %d'\n", i
);
289 /* Test Getting / Setting the hot key */
291 r
= IShellLinkA_GetHotkey(sl
, &w
);
292 ok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
293 ok(w
==0, "GetHotkey returned %d\n", w
);
295 r
= IShellLinkA_SetHotkey(sl
, 0x5678);
296 ok(SUCCEEDED(r
), "SetHotkey failed (0x%08x)\n", r
);
299 r
= IShellLinkA_GetHotkey(sl
, &w
);
300 ok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
301 ok(w
==0x5678, "GetHotkey returned %d'\n", w
);
303 IShellLinkA_Release(sl
);
308 * Test saving and loading .lnk files
311 #define lok ok_(__FILE__, line)
312 #define lok_todo_4(todo_flag,a,b,c,d) \
313 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
314 else todo_wine lok((a), (b), (c), (d));
315 #define lok_todo_2(todo_flag,a,b) \
316 if ((todo & todo_flag) == 0) lok((a), (b)); \
317 else todo_wine lok((a), (b));
318 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
320 void create_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int save_fails
)
326 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
327 &IID_IShellLinkA
, (LPVOID
*)&sl
);
328 lok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
332 if (desc
->description
)
334 r
= IShellLinkA_SetDescription(sl
, desc
->description
);
335 lok(SUCCEEDED(r
), "SetDescription failed (0x%08x)\n", r
);
339 r
= IShellLinkA_SetWorkingDirectory(sl
, desc
->workdir
);
340 lok(SUCCEEDED(r
), "SetWorkingDirectory failed (0x%08x)\n", r
);
344 r
= IShellLinkA_SetPath(sl
, desc
->path
);
345 lok(SUCCEEDED(r
), "SetPath failed (0x%08x)\n", r
);
349 r
= IShellLinkA_SetIDList(sl
, desc
->pidl
);
350 lok(SUCCEEDED(r
), "SetIDList failed (0x%08x)\n", r
);
354 r
= IShellLinkA_SetArguments(sl
, desc
->arguments
);
355 lok(SUCCEEDED(r
), "SetArguments failed (0x%08x)\n", r
);
359 r
= IShellLinkA_SetShowCmd(sl
, desc
->showcmd
);
360 lok(SUCCEEDED(r
), "SetShowCmd failed (0x%08x)\n", r
);
364 r
= IShellLinkA_SetIconLocation(sl
, desc
->icon
, desc
->icon_id
);
365 lok(SUCCEEDED(r
), "SetIconLocation failed (0x%08x)\n", r
);
369 r
= IShellLinkA_SetHotkey(sl
, desc
->hotkey
);
370 lok(SUCCEEDED(r
), "SetHotkey failed (0x%08x)\n", r
);
373 r
= IShellLinkW_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
374 lok(SUCCEEDED(r
), "no IID_IPersistFile (0x%08x)\n", r
);
377 r
= IPersistFile_Save(pf
, path
, TRUE
);
381 lok(SUCCEEDED(r
), "save failed (0x%08x)\n", r
);
386 lok(SUCCEEDED(r
), "save failed (0x%08x)\n", r
);
388 IPersistFile_Release(pf
);
391 IShellLinkA_Release(sl
);
394 static void check_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int todo
)
399 char buffer
[INFOTIPSIZE
];
401 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
402 &IID_IShellLinkA
, (LPVOID
*)&sl
);
403 lok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
407 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
408 lok(SUCCEEDED(r
), "no IID_IPersistFile (0x%08x)\n", r
);
411 IShellLinkA_Release(sl
);
415 r
= IPersistFile_Load(pf
, path
, STGM_READ
);
416 lok(SUCCEEDED(r
), "load failed (0x%08x)\n", r
);
417 IPersistFile_Release(pf
);
420 IShellLinkA_Release(sl
);
424 if (desc
->description
)
426 strcpy(buffer
,"garbage");
427 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
428 lok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
429 lok_todo_4(0x1, lstrcmp(buffer
, desc
->description
)==0,
430 "GetDescription returned '%s' instead of '%s'\n",
431 buffer
, desc
->description
);
435 strcpy(buffer
,"garbage");
436 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
437 lok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
438 lok_todo_4(0x2, lstrcmpi(buffer
, desc
->workdir
)==0,
439 "GetWorkingDirectory returned '%s' instead of '%s'\n",
440 buffer
, desc
->workdir
);
444 strcpy(buffer
,"garbage");
445 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
446 lok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
447 lok_todo_4(0x4, lstrcmpi(buffer
, desc
->path
)==0,
448 "GetPath returned '%s' instead of '%s'\n",
453 LPITEMIDLIST pidl
=NULL
;
454 r
= IShellLinkA_GetIDList(sl
, &pidl
);
455 lok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
456 lok_todo_2(0x8, pILIsEqual(pidl
, desc
->pidl
),
457 "GetIDList returned an incorrect pidl\n");
462 r
= IShellLinkA_GetShowCmd(sl
, &i
);
463 lok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
464 lok_todo_4(0x10, i
==desc
->showcmd
,
465 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
471 strcpy(buffer
,"garbage");
472 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
473 lok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
474 lok_todo_4(0x20, lstrcmpi(buffer
, desc
->icon
)==0,
475 "GetIconLocation returned '%s' instead of '%s'\n",
477 lok_todo_4(0x20, i
==desc
->icon_id
,
478 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
484 r
= IShellLinkA_GetHotkey(sl
, &i
);
485 lok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
486 lok_todo_4(0x40, i
==desc
->hotkey
,
487 "GetHotkey returned 0x%04x instead of 0x%04x\n",
491 IShellLinkA_Release(sl
);
494 static void test_load_save(void)
497 char mypath
[MAX_PATH
];
498 char mydir
[MAX_PATH
];
499 char realpath
[MAX_PATH
];
504 /* Save an empty .lnk file */
505 memset(&desc
, 0, sizeof(desc
));
506 create_lnk(lnkfile
, &desc
, 0);
508 /* It should come back as a bunch of empty strings */
514 check_lnk(lnkfile
, &desc
, 0x0);
516 /* Point a .lnk file to nonexistent files */
518 desc
.workdir
="c:\\Nonexitent\\work\\directory";
519 desc
.path
="c:\\nonexistent\\path";
523 desc
.icon
="c:\\nonexistent\\icon\\file";
526 create_lnk(lnkfile
, &desc
, 0);
527 check_lnk(lnkfile
, &desc
, 0x0);
529 r
=GetModuleFileName(NULL
, mypath
, sizeof(mypath
));
530 ok(r
<sizeof(mypath
), "GetModuleFileName failed (%d)\n", r
);
531 strcpy(mydir
, mypath
);
532 p
=strrchr(mydir
, '\\');
536 /* Overwrite the existing lnk file and point it to existing files */
537 desc
.description
="test 2";
541 desc
.arguments
="/option1 /option2 \"Some string\"";
542 desc
.showcmd
=SW_SHOWNORMAL
;
546 create_lnk(lnkfile
, &desc
, 0);
547 check_lnk(lnkfile
, &desc
, 0x0);
549 /* Overwrite the existing lnk file and test link to a command on the path */
550 desc
.description
="command on path";
552 desc
.path
="rundll32.exe";
554 desc
.arguments
="/option1 /option2 \"Some string\"";
555 desc
.showcmd
=SW_SHOWNORMAL
;
559 create_lnk(lnkfile
, &desc
, 0);
560 /* Check that link is created to proper location */
561 SearchPathA( NULL
, desc
.path
, NULL
, MAX_PATH
, realpath
, NULL
);
563 check_lnk(lnkfile
, &desc
, 0x0);
565 /* Create a temporary non-executable file */
566 r
=GetTempPath(sizeof(mypath
), mypath
);
567 ok(r
<sizeof(mypath
), "GetTempPath failed (%d), err %d\n", r
, GetLastError());
568 if (!pGetLongPathNameA
)
570 skip("GetLongPathNameA is not available\n");
573 r
=pGetLongPathNameA(mypath
, mydir
, sizeof(mydir
));
574 ok(r
<sizeof(mydir
), "GetLongPathName failed (%d), err %d\n", r
, GetLastError());
575 p
=strrchr(mydir
, '\\');
579 strcpy(mypath
, mydir
);
580 strcat(mypath
, "\\test.txt");
581 hf
= CreateFile(mypath
, GENERIC_WRITE
, 0, NULL
,
582 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
585 /* Overwrite the existing lnk file and test link to an existing non-executable file */
586 desc
.description
="non-executable file";
591 desc
.showcmd
=SW_SHOWNORMAL
;
595 create_lnk(lnkfile
, &desc
, 0);
596 check_lnk(lnkfile
, &desc
, 0x0);
598 r
= DeleteFileA(mypath
);
599 ok(r
, "failed to delete file %s (%d)\n", mypath
, GetLastError());
601 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
602 * represented as a path.
606 /* DeleteFileW is not implemented on Win9x */
607 r
=DeleteFileA("c:\\test.lnk");
608 ok(r
, "failed to delete link (%d)\n", GetLastError());
611 static void test_datalink(void)
613 static const WCHAR lnk
[] = {
614 ':',':','{','9','d','b','1','1','8','6','f','-','4','0','d','f','-','1',
615 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
616 '8','6','3','}',':','{','0','0','0','1','0','4','0','9','-','7','8','E',
617 '1','-','1','1','D','2','-','B','6','0','F','-','0','0','6','0','9','7',
618 'C','9','9','8','E','7','}',':',':','{','9','d','b','1','1','8','6','e',
619 '-','4','0','d','f','-','1','1','d','1','-','a','a','8','c','-','0','0',
620 'c','0','4','f','b','6','7','8','6','3','}',':','2','6',',','!','!','g',
621 'x','s','f','(','N','g',']','q','F','`','H','{','L','s','A','C','C','E',
622 'S','S','F','i','l','e','s','>','p','l','T',']','j','I','{','j','f','(',
623 '=','1','&','L','[','-','8','1','-',']',':',':',0 };
624 static const WCHAR comp
[] = {
625 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
626 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
627 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
628 IShellLinkDataList
*dl
= NULL
;
629 IShellLinkW
*sl
= NULL
;
632 EXP_DARWIN_LINK
*dar
;
634 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
635 &IID_IShellLinkW
, (LPVOID
*)&sl
);
636 ok( r
== S_OK
|| r
== E_NOINTERFACE
, "CoCreateInstance failed (0x%08x)\n", r
);
639 skip("no shelllink\n");
643 r
= IShellLinkW_QueryInterface( sl
, &_IID_IShellLinkDataList
, (LPVOID
*) &dl
);
644 ok(r
== S_OK
, "IShellLinkW_QueryInterface failed (0x%08x)\n", r
);
648 skip("no datalink interface\n");
653 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
654 ok( r
== S_OK
, "GetFlags failed\n");
655 ok( flags
== 0, "GetFlags returned wrong flags\n");
658 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
659 ok( r
== E_FAIL
, "CopyDataBlock failed\n");
660 ok( dar
== NULL
, "should be null\n");
662 r
= IShellLinkW_SetPath(sl
, lnk
);
663 ok(r
== S_OK
, "set path failed\n");
666 * The following crashes:
667 * r = IShellLinkDataList_GetFlags( dl, NULL );
671 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
672 ok( r
== S_OK
, "GetFlags failed\n");
673 ok( flags
== (SLDF_HAS_DARWINID
|SLDF_HAS_LOGO3ID
),
674 "GetFlags returned wrong flags\n");
677 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
678 ok( r
== S_OK
, "CopyDataBlock failed\n");
680 ok( dar
&& ((DATABLOCK_HEADER
*)dar
)->dwSignature
== EXP_DARWIN_ID_SIG
, "signature wrong\n");
681 ok( dar
&& 0==lstrcmpW(dar
->szwDarwinID
, comp
), "signature wrong\n");
685 IUnknown_Release( dl
);
686 IShellLinkW_Release( sl
);
689 START_TEST(shelllink
)
692 HMODULE hmod
= GetModuleHandleA("shell32.dll");
693 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
695 pILFree
= (fnILFree
) GetProcAddress(hmod
, (LPSTR
)155);
696 pILIsEqual
= (fnILIsEqual
) GetProcAddress(hmod
, (LPSTR
)21);
697 pSHILCreateFromPath
= (fnSHILCreateFromPath
) GetProcAddress(hmod
, (LPSTR
)28);
699 pGetLongPathNameA
= (void *)GetProcAddress(hkernel32
, "GetLongPathNameA");
701 r
= CoInitialize(NULL
);
702 ok(SUCCEEDED(r
), "CoInitialize failed (0x%08x)\n", r
);