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
*);
44 static fnILFree pILFree
;
45 static fnILIsEqual pILIsEqual
;
46 static fnSHILCreateFromPath pSHILCreateFromPath
;
48 static DWORD (WINAPI
*pGetLongPathNameA
)(LPCSTR
, LPSTR
, DWORD
);
50 static const GUID _IID_IShellLinkDataList
= {
51 0x45e2b4ae, 0xb1c3, 0x11d0,
52 { 0xb9, 0x2f, 0x00, 0xa0, 0xc9, 0x03, 0x12, 0xe1 }
55 static const WCHAR notafile
[]= { 'C',':','\\','n','o','n','e','x','i','s','t','e','n','t','\\','f','i','l','e',0 };
58 /* For some reason SHILCreateFromPath does not work on Win98 and
59 * SHSimpleIDListFromPathA does not work on NT4. But if we call both we
60 * get what we want on all platforms.
62 static LPITEMIDLIST (WINAPI
*pSHSimpleIDListFromPathAW
)(LPCVOID
);
64 static LPITEMIDLIST
path_to_pidl(const char* path
)
68 if (!pSHSimpleIDListFromPathAW
)
70 HMODULE hdll
=GetModuleHandleA("shell32.dll");
71 pSHSimpleIDListFromPathAW
=(void*)GetProcAddress(hdll
, (char*)162);
72 if (!pSHSimpleIDListFromPathAW
)
73 trace("SHSimpleIDListFromPathAW not found in shell32.dll\n");
77 /* pSHSimpleIDListFromPathAW maps to A on non NT platforms */
78 if (pSHSimpleIDListFromPathAW
&& (GetVersion() & 0x80000000))
79 pidl
=pSHSimpleIDListFromPathAW(path
);
87 len
=MultiByteToWideChar(CP_ACP
, 0, path
, -1, NULL
, 0);
88 pathW
=HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
89 MultiByteToWideChar(CP_ACP
, 0, path
, -1, pathW
, len
);
91 r
=pSHILCreateFromPath(pathW
, &pidl
, NULL
);
92 ok(SUCCEEDED(r
), "SHILCreateFromPath failed (0x%08x)\n", r
);
93 HeapFree(GetProcessHeap(), 0, pathW
);
100 * Test manipulation of an IShellLink's properties.
103 static void test_get_set(void)
107 char mypath
[MAX_PATH
];
108 char buffer
[INFOTIPSIZE
];
109 LPITEMIDLIST pidl
, tmp_pidl
;
114 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
115 &IID_IShellLinkA
, (LPVOID
*)&sl
);
116 ok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
120 /* Test Getting / Setting the description */
121 strcpy(buffer
,"garbage");
122 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
123 ok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
124 ok(*buffer
=='\0', "GetDescription returned '%s'\n", buffer
);
126 str
="Some description";
127 r
= IShellLinkA_SetDescription(sl
, str
);
128 ok(SUCCEEDED(r
), "SetDescription failed (0x%08x)\n", r
);
130 strcpy(buffer
,"garbage");
131 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
132 ok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
133 ok(lstrcmp(buffer
,str
)==0, "GetDescription returned '%s'\n", buffer
);
135 /* Test Getting / Setting the work directory */
136 strcpy(buffer
,"garbage");
137 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
138 ok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
139 ok(*buffer
=='\0', "GetWorkingDirectory returned '%s'\n", buffer
);
141 str
="c:\\nonexistent\\directory";
142 r
= IShellLinkA_SetWorkingDirectory(sl
, str
);
143 ok(SUCCEEDED(r
), "SetWorkingDirectory failed (0x%08x)\n", r
);
145 strcpy(buffer
,"garbage");
146 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
147 ok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
148 ok(lstrcmpi(buffer
,str
)==0, "GetWorkingDirectory returned '%s'\n", buffer
);
150 /* Test Getting / Setting the path */
151 strcpy(buffer
,"garbage");
152 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
153 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
154 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
156 r
= IShellLinkA_SetPath(sl
, "");
157 ok(r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
159 strcpy(buffer
,"garbage");
160 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
161 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
162 ok(*buffer
=='\0', "GetPath returned '%s'\n", buffer
);
164 /* Win98 returns S_FALSE, but WinXP returns S_OK */
165 str
="c:\\nonexistent\\file";
166 r
= IShellLinkA_SetPath(sl
, str
);
167 ok(r
==S_FALSE
|| r
==S_OK
, "SetPath failed (0x%08x)\n", r
);
169 strcpy(buffer
,"garbage");
170 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
171 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
172 ok(lstrcmpi(buffer
,str
)==0, "GetPath returned '%s'\n", buffer
);
174 /* Get some real path to play with */
175 GetWindowsDirectoryA( mypath
, sizeof(mypath
)-12 );
176 strcat(mypath
, "\\regedit.exe");
178 /* Test the interaction of SetPath and SetIDList */
180 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
181 ok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
186 strcpy(buffer
,"garbage");
187 ret
= SHGetPathFromIDListA(tmp_pidl
, buffer
);
189 ok(ret
, "SHGetPathFromIDListA failed\n");
192 ok(lstrcmpi(buffer
,str
)==0, "GetIDList returned '%s'\n", buffer
);
195 pidl
=path_to_pidl(mypath
);
196 ok(pidl
!=NULL
, "path_to_pidl returned a NULL pidl\n");
200 r
= IShellLinkA_SetIDList(sl
, pidl
);
201 ok(SUCCEEDED(r
), "SetIDList failed (0x%08x)\n", r
);
204 r
= IShellLinkA_GetIDList(sl
, &tmp_pidl
);
205 ok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
206 ok(tmp_pidl
&& pILIsEqual(pidl
, tmp_pidl
),
207 "GetIDList returned an incorrect pidl\n");
209 /* tmp_pidl is owned by IShellLink so we don't free it */
212 strcpy(buffer
,"garbage");
213 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
214 ok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
216 ok(lstrcmpi(buffer
, mypath
)==0, "GetPath returned '%s'\n", buffer
);
220 /* test path with quotes (Win98 IShellLinkA_SetPath returns S_FALSE, WinXP returns S_OK) */
221 r
= IShellLinkA_SetPath(sl
, "\"c:\\nonexistent\\file\"");
222 ok(r
==S_FALSE
|| r
== S_OK
, "SetPath failed (0x%08x)\n", r
);
224 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
225 ok(r
==S_OK
, "GetPath failed (0x%08x)\n", r
);
226 ok(!lstrcmp(buffer
, "C:\\nonexistent\\file"), "case doesn't match\n");
228 r
= IShellLinkA_SetPath(sl
, "\"c:\\foo");
229 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
231 r
= IShellLinkA_SetPath(sl
, "\"\"c:\\foo");
232 ok(r
==S_FALSE
|| r
== S_OK
|| r
== E_INVALIDARG
/* Vista */, "SetPath failed (0x%08x)\n", r
);
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 /* Test Getting / Setting the arguments */
244 strcpy(buffer
,"garbage");
245 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
246 ok(SUCCEEDED(r
), "GetArguments failed (0x%08x)\n", r
);
247 ok(*buffer
=='\0', "GetArguments returned '%s'\n", buffer
);
249 str
="param1 \"spaced param2\"";
250 r
= IShellLinkA_SetArguments(sl
, str
);
251 ok(SUCCEEDED(r
), "SetArguments failed (0x%08x)\n", r
);
253 strcpy(buffer
,"garbage");
254 r
= IShellLinkA_GetArguments(sl
, buffer
, sizeof(buffer
));
255 ok(SUCCEEDED(r
), "GetArguments failed (0x%08x)\n", r
);
256 ok(lstrcmp(buffer
,str
)==0, "GetArguments returned '%s'\n", buffer
);
258 /* Test Getting / Setting showcmd */
260 r
= IShellLinkA_GetShowCmd(sl
, &i
);
261 ok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
262 ok(i
==SW_SHOWNORMAL
, "GetShowCmd returned %d\n", i
);
264 r
= IShellLinkA_SetShowCmd(sl
, SW_SHOWMAXIMIZED
);
265 ok(SUCCEEDED(r
), "SetShowCmd failed (0x%08x)\n", r
);
268 r
= IShellLinkA_GetShowCmd(sl
, &i
);
269 ok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
270 ok(i
==SW_SHOWMAXIMIZED
, "GetShowCmd returned %d'\n", i
);
272 /* Test Getting / Setting the icon */
274 strcpy(buffer
,"garbage");
275 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
277 ok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
279 ok(*buffer
=='\0', "GetIconLocation returned '%s'\n", buffer
);
280 ok(i
==0, "GetIconLocation returned %d\n", i
);
282 str
="c:\\nonexistent\\file";
283 r
= IShellLinkA_SetIconLocation(sl
, str
, 0xbabecafe);
284 ok(SUCCEEDED(r
), "SetIconLocation failed (0x%08x)\n", r
);
287 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
288 ok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
289 ok(lstrcmpi(buffer
,str
)==0, "GetIconLocation returned '%s'\n", buffer
);
290 ok(i
==0xbabecafe, "GetIconLocation returned %d'\n", i
);
292 /* Test Getting / Setting the hot key */
294 r
= IShellLinkA_GetHotkey(sl
, &w
);
295 ok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
296 ok(w
==0, "GetHotkey returned %d\n", w
);
298 r
= IShellLinkA_SetHotkey(sl
, 0x5678);
299 ok(SUCCEEDED(r
), "SetHotkey failed (0x%08x)\n", r
);
302 r
= IShellLinkA_GetHotkey(sl
, &w
);
303 ok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
304 ok(w
==0x5678, "GetHotkey returned %d'\n", w
);
306 IShellLinkA_Release(sl
);
311 * Test saving and loading .lnk files
314 #define lok ok_(__FILE__, line)
315 #define lok_todo_4(todo_flag,a,b,c,d) \
316 if ((todo & todo_flag) == 0) lok((a), (b), (c), (d)); \
317 else todo_wine lok((a), (b), (c), (d));
318 #define lok_todo_2(todo_flag,a,b) \
319 if ((todo & todo_flag) == 0) lok((a), (b)); \
320 else todo_wine lok((a), (b));
321 #define check_lnk(a,b,c) check_lnk_(__LINE__, (a), (b), (c))
323 void create_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int save_fails
)
329 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
330 &IID_IShellLinkA
, (LPVOID
*)&sl
);
331 lok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
335 if (desc
->description
)
337 r
= IShellLinkA_SetDescription(sl
, desc
->description
);
338 lok(SUCCEEDED(r
), "SetDescription failed (0x%08x)\n", r
);
342 r
= IShellLinkA_SetWorkingDirectory(sl
, desc
->workdir
);
343 lok(SUCCEEDED(r
), "SetWorkingDirectory failed (0x%08x)\n", r
);
347 r
= IShellLinkA_SetPath(sl
, desc
->path
);
348 lok(SUCCEEDED(r
), "SetPath failed (0x%08x)\n", r
);
352 r
= IShellLinkA_SetIDList(sl
, desc
->pidl
);
353 lok(SUCCEEDED(r
), "SetIDList failed (0x%08x)\n", r
);
357 r
= IShellLinkA_SetArguments(sl
, desc
->arguments
);
358 lok(SUCCEEDED(r
), "SetArguments failed (0x%08x)\n", r
);
362 r
= IShellLinkA_SetShowCmd(sl
, desc
->showcmd
);
363 lok(SUCCEEDED(r
), "SetShowCmd failed (0x%08x)\n", r
);
367 r
= IShellLinkA_SetIconLocation(sl
, desc
->icon
, desc
->icon_id
);
368 lok(SUCCEEDED(r
), "SetIconLocation failed (0x%08x)\n", r
);
372 r
= IShellLinkA_SetHotkey(sl
, desc
->hotkey
);
373 lok(SUCCEEDED(r
), "SetHotkey failed (0x%08x)\n", r
);
376 r
= IShellLinkW_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
377 lok(SUCCEEDED(r
), "no IID_IPersistFile (0x%08x)\n", r
);
380 r
= IPersistFile_Save(pf
, path
, TRUE
);
384 lok(SUCCEEDED(r
), "save failed (0x%08x)\n", r
);
389 lok(SUCCEEDED(r
), "save failed (0x%08x)\n", r
);
391 IPersistFile_Release(pf
);
394 IShellLinkA_Release(sl
);
397 static void check_lnk_(int line
, const WCHAR
* path
, lnk_desc_t
* desc
, int todo
)
402 char buffer
[INFOTIPSIZE
];
404 r
= CoCreateInstance(&CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
405 &IID_IShellLinkA
, (LPVOID
*)&sl
);
406 lok(SUCCEEDED(r
), "no IID_IShellLinkA (0x%08x)\n", r
);
410 r
= IShellLinkA_QueryInterface(sl
, &IID_IPersistFile
, (LPVOID
*)&pf
);
411 lok(SUCCEEDED(r
), "no IID_IPersistFile (0x%08x)\n", r
);
414 IShellLinkA_Release(sl
);
418 r
= IPersistFile_Load(pf
, path
, STGM_READ
);
419 lok(SUCCEEDED(r
), "load failed (0x%08x)\n", r
);
420 IPersistFile_Release(pf
);
423 IShellLinkA_Release(sl
);
427 if (desc
->description
)
429 strcpy(buffer
,"garbage");
430 r
= IShellLinkA_GetDescription(sl
, buffer
, sizeof(buffer
));
431 lok(SUCCEEDED(r
), "GetDescription failed (0x%08x)\n", r
);
432 lok_todo_4(0x1, lstrcmp(buffer
, desc
->description
)==0,
433 "GetDescription returned '%s' instead of '%s'\n",
434 buffer
, desc
->description
);
438 strcpy(buffer
,"garbage");
439 r
= IShellLinkA_GetWorkingDirectory(sl
, buffer
, sizeof(buffer
));
440 lok(SUCCEEDED(r
), "GetWorkingDirectory failed (0x%08x)\n", r
);
441 lok_todo_4(0x2, lstrcmpi(buffer
, desc
->workdir
)==0,
442 "GetWorkingDirectory returned '%s' instead of '%s'\n",
443 buffer
, desc
->workdir
);
447 strcpy(buffer
,"garbage");
448 r
= IShellLinkA_GetPath(sl
, buffer
, sizeof(buffer
), NULL
, SLGP_RAWPATH
);
449 lok(SUCCEEDED(r
), "GetPath failed (0x%08x)\n", r
);
450 lok_todo_4(0x4, lstrcmpi(buffer
, desc
->path
)==0,
451 "GetPath returned '%s' instead of '%s'\n",
456 LPITEMIDLIST pidl
=NULL
;
457 r
= IShellLinkA_GetIDList(sl
, &pidl
);
458 lok(SUCCEEDED(r
), "GetIDList failed (0x%08x)\n", r
);
459 lok_todo_2(0x8, pILIsEqual(pidl
, desc
->pidl
),
460 "GetIDList returned an incorrect pidl\n");
465 r
= IShellLinkA_GetShowCmd(sl
, &i
);
466 lok(SUCCEEDED(r
), "GetShowCmd failed (0x%08x)\n", r
);
467 lok_todo_4(0x10, i
==desc
->showcmd
,
468 "GetShowCmd returned 0x%0x instead of 0x%0x\n",
474 strcpy(buffer
,"garbage");
475 r
= IShellLinkA_GetIconLocation(sl
, buffer
, sizeof(buffer
), &i
);
476 lok(SUCCEEDED(r
), "GetIconLocation failed (0x%08x)\n", r
);
477 lok_todo_4(0x20, lstrcmpi(buffer
, desc
->icon
)==0,
478 "GetIconLocation returned '%s' instead of '%s'\n",
480 lok_todo_4(0x20, i
==desc
->icon_id
,
481 "GetIconLocation returned 0x%0x instead of 0x%0x\n",
487 r
= IShellLinkA_GetHotkey(sl
, &i
);
488 lok(SUCCEEDED(r
), "GetHotkey failed (0x%08x)\n", r
);
489 lok_todo_4(0x40, i
==desc
->hotkey
,
490 "GetHotkey returned 0x%04x instead of 0x%04x\n",
494 IShellLinkA_Release(sl
);
497 static void test_load_save(void)
499 WCHAR lnkfile
[MAX_PATH
];
500 char lnkfileA
[MAX_PATH
];
501 static const char lnkfileA_name
[] = "\\test.lnk";
504 char mypath
[MAX_PATH
];
505 char mydir
[MAX_PATH
];
506 char realpath
[MAX_PATH
];
511 if (!pGetLongPathNameA
)
513 skip("GetLongPathNameA is not available\n");
517 /* Don't used a fixed path for the test.lnk file */
518 GetTempPathA(MAX_PATH
, lnkfileA
);
519 lstrcatA(lnkfileA
, lnkfileA_name
);
520 MultiByteToWideChar(CP_ACP
, 0, lnkfileA
, -1, lnkfile
, MAX_PATH
);
522 /* Save an empty .lnk file */
523 memset(&desc
, 0, sizeof(desc
));
524 create_lnk(lnkfile
, &desc
, 0);
526 /* It should come back as a bunch of empty strings */
532 check_lnk(lnkfile
, &desc
, 0x0);
534 /* Point a .lnk file to nonexistent files */
536 desc
.workdir
="c:\\Nonexitent\\work\\directory";
537 desc
.path
="c:\\nonexistent\\path";
541 desc
.icon
="c:\\nonexistent\\icon\\file";
544 create_lnk(lnkfile
, &desc
, 0);
545 check_lnk(lnkfile
, &desc
, 0x0);
547 r
=GetModuleFileName(NULL
, mypath
, sizeof(mypath
));
548 ok(r
<sizeof(mypath
), "GetModuleFileName failed (%d)\n", r
);
549 strcpy(mydir
, mypath
);
550 p
=strrchr(mydir
, '\\');
554 /* IShellLink returns path in long form */
555 if (!pGetLongPathNameA(mypath
, realpath
, MAX_PATH
)) strcpy( realpath
, mypath
);
557 /* Overwrite the existing lnk file and point it to existing files */
558 desc
.description
="test 2";
562 desc
.arguments
="/option1 /option2 \"Some string\"";
563 desc
.showcmd
=SW_SHOWNORMAL
;
567 create_lnk(lnkfile
, &desc
, 0);
568 check_lnk(lnkfile
, &desc
, 0x0);
570 /* Overwrite the existing lnk file and test link to a command on the path */
571 desc
.description
="command on path";
573 desc
.path
="rundll32.exe";
575 desc
.arguments
="/option1 /option2 \"Some string\"";
576 desc
.showcmd
=SW_SHOWNORMAL
;
580 create_lnk(lnkfile
, &desc
, 0);
581 /* Check that link is created to proper location */
582 SearchPathA( NULL
, desc
.path
, NULL
, MAX_PATH
, realpath
, NULL
);
584 check_lnk(lnkfile
, &desc
, 0x0);
586 /* Create a temporary non-executable file */
587 r
=GetTempPath(sizeof(mypath
), mypath
);
588 ok(r
<sizeof(mypath
), "GetTempPath failed (%d), err %d\n", r
, GetLastError());
589 r
=pGetLongPathNameA(mypath
, mydir
, sizeof(mydir
));
590 ok(r
<sizeof(mydir
), "GetLongPathName failed (%d), err %d\n", r
, GetLastError());
591 p
=strrchr(mydir
, '\\');
595 strcpy(mypath
, mydir
);
596 strcat(mypath
, "\\test.txt");
597 hf
= CreateFile(mypath
, GENERIC_WRITE
, 0, NULL
,
598 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
601 /* Overwrite the existing lnk file and test link to an existing non-executable file */
602 desc
.description
="non-executable file";
607 desc
.showcmd
=SW_SHOWNORMAL
;
611 create_lnk(lnkfile
, &desc
, 0);
612 check_lnk(lnkfile
, &desc
, 0x0);
614 r
= DeleteFileA(mypath
);
615 ok(r
, "failed to delete file %s (%d)\n", mypath
, GetLastError());
617 /* FIXME: Also test saving a .lnk pointing to a pidl that cannot be
618 * represented as a path.
621 /* DeleteFileW is not implemented on Win9x */
622 r
=DeleteFileA(lnkfileA
);
623 ok(r
, "failed to delete link '%s' (%d)\n", lnkfileA
, GetLastError());
626 static void test_datalink(void)
628 static const WCHAR lnk
[] = {
629 ':',':','{','9','d','b','1','1','8','6','f','-','4','0','d','f','-','1',
630 '1','d','1','-','a','a','8','c','-','0','0','c','0','4','f','b','6','7',
631 '8','6','3','}',':','{','0','0','0','1','0','4','0','9','-','7','8','E',
632 '1','-','1','1','D','2','-','B','6','0','F','-','0','0','6','0','9','7',
633 'C','9','9','8','E','7','}',':',':','{','9','d','b','1','1','8','6','e',
634 '-','4','0','d','f','-','1','1','d','1','-','a','a','8','c','-','0','0',
635 'c','0','4','f','b','6','7','8','6','3','}',':','2','6',',','!','!','g',
636 'x','s','f','(','N','g',']','q','F','`','H','{','L','s','A','C','C','E',
637 'S','S','F','i','l','e','s','>','p','l','T',']','j','I','{','j','f','(',
638 '=','1','&','L','[','-','8','1','-',']',':',':',0 };
639 static const WCHAR comp
[] = {
640 '2','6',',','!','!','g','x','s','f','(','N','g',']','q','F','`','H','{',
641 'L','s','A','C','C','E','S','S','F','i','l','e','s','>','p','l','T',']',
642 'j','I','{','j','f','(','=','1','&','L','[','-','8','1','-',']',0 };
643 IShellLinkDataList
*dl
= NULL
;
644 IShellLinkW
*sl
= NULL
;
647 EXP_DARWIN_LINK
*dar
;
649 r
= CoCreateInstance( &CLSID_ShellLink
, NULL
, CLSCTX_INPROC_SERVER
,
650 &IID_IShellLinkW
, (LPVOID
*)&sl
);
651 ok( r
== S_OK
|| r
== E_NOINTERFACE
, "CoCreateInstance failed (0x%08x)\n", r
);
654 skip("no shelllink\n");
658 r
= IShellLinkW_QueryInterface( sl
, &_IID_IShellLinkDataList
, (LPVOID
*) &dl
);
659 ok(r
== S_OK
, "IShellLinkW_QueryInterface failed (0x%08x)\n", r
);
663 skip("no datalink interface\n");
668 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
669 ok( r
== S_OK
, "GetFlags failed\n");
670 ok( flags
== 0, "GetFlags returned wrong flags\n");
673 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
674 ok( r
== E_FAIL
, "CopyDataBlock failed\n");
675 ok( dar
== NULL
, "should be null\n");
677 r
= IShellLinkW_SetPath(sl
, lnk
);
678 ok(r
== S_OK
, "set path failed\n");
681 * The following crashes:
682 * r = IShellLinkDataList_GetFlags( dl, NULL );
686 r
= IShellLinkDataList_GetFlags( dl
, &flags
);
687 ok( r
== S_OK
, "GetFlags failed\n");
688 ok( flags
== (SLDF_HAS_DARWINID
|SLDF_HAS_LOGO3ID
),
689 "GetFlags returned wrong flags\n");
692 r
= IShellLinkDataList_CopyDataBlock( dl
, EXP_DARWIN_ID_SIG
, (LPVOID
*) &dar
);
693 ok( r
== S_OK
, "CopyDataBlock failed\n");
695 ok( dar
&& ((DATABLOCK_HEADER
*)dar
)->dwSignature
== EXP_DARWIN_ID_SIG
, "signature wrong\n");
696 ok( dar
&& 0==lstrcmpW(dar
->szwDarwinID
, comp
), "signature wrong\n");
700 IUnknown_Release( dl
);
701 IShellLinkW_Release( sl
);
704 START_TEST(shelllink
)
707 HMODULE hmod
= GetModuleHandleA("shell32.dll");
708 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
710 pILFree
= (fnILFree
) GetProcAddress(hmod
, (LPSTR
)155);
711 pILIsEqual
= (fnILIsEqual
) GetProcAddress(hmod
, (LPSTR
)21);
712 pSHILCreateFromPath
= (fnSHILCreateFromPath
) GetProcAddress(hmod
, (LPSTR
)28);
714 pGetLongPathNameA
= (void *)GetProcAddress(hkernel32
, "GetLongPathNameA");
716 r
= CoInitialize(NULL
);
717 ok(SUCCEEDED(r
), "CoInitialize failed (0x%08x)\n", r
);