Tests should not use wine/unicode.h.
[wine/multimedia.git] / dlls / shell32 / tests / shlfolder.c
blob7a79ab652c14acd691e9041f9274ee0bca920462
1 /*
2 * Unit test of the IShellFolder functions.
4 * Copyright 2004 Vitaliy Margolen
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wtypes.h"
29 #include "shellapi.h"
32 #include "shlguid.h"
33 #include "shlobj.h"
34 #include "shobjidl.h"
35 #include "shlwapi.h"
36 #include "ocidl.h"
37 #include "oleauto.h"
39 #include "wine/test.h"
42 static IMalloc *ppM;
44 static HRESULT (WINAPI *pSHBindToParent)(LPCITEMIDLIST, REFIID, LPVOID*, LPCITEMIDLIST*);
45 static BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL);
46 static HRESULT (WINAPI *pStrRetToBufW)(STRRET*,LPCITEMIDLIST,LPWSTR,UINT);
47 static LPITEMIDLIST (WINAPI *pILFindLastID)(LPCITEMIDLIST);
49 static void init_function_pointers(void)
51 HMODULE hmod;
52 HRESULT hr;
54 hmod = GetModuleHandleA("shell32.dll");
55 if(hmod)
57 pSHBindToParent = (void*)GetProcAddress(hmod, "SHBindToParent");
58 pSHGetSpecialFolderPathW = (void*)GetProcAddress(hmod, "SHGetSpecialFolderPathW");
59 pILFindLastID = (void *)GetProcAddress(hmod, (LPCSTR)16);
63 hmod = GetModuleHandleA("shlwapi.dll");
64 if(hmod)
66 pStrRetToBufW = (void*)GetProcAddress(hmod, "StrRetToBufW");
69 hr = SHGetMalloc(&ppM);
70 ok(hr == S_OK, "SHGetMalloc failed %08lx\n", hr);
73 static void test_ParseDisplayName(void)
75 HRESULT hr;
76 IShellFolder *IDesktopFolder;
77 static const char *cNonExistDir1A = "c:\\nonexist_subdir";
78 static const char *cNonExistDir2A = "c:\\\\nonexist_subdir";
79 DWORD res;
80 WCHAR cTestDirW [MAX_PATH] = {0};
81 ITEMIDLIST *newPIDL;
82 BOOL bRes;
84 hr = SHGetDesktopFolder(&IDesktopFolder);
85 if(hr != S_OK) return;
87 res = GetFileAttributesA(cNonExistDir1A);
88 if(res != INVALID_FILE_ATTRIBUTES) return;
90 MultiByteToWideChar(CP_ACP, 0, cNonExistDir1A, -1, cTestDirW, MAX_PATH);
91 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
92 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
93 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL),
94 "ParseDisplayName returned %08lx, expected 80070002 or E_FAIL\n", hr);
96 res = GetFileAttributesA(cNonExistDir2A);
97 if(res != INVALID_FILE_ATTRIBUTES) return;
99 MultiByteToWideChar(CP_ACP, 0, cNonExistDir2A, -1, cTestDirW, MAX_PATH);
100 hr = IShellFolder_ParseDisplayName(IDesktopFolder,
101 NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
102 ok((hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) || (hr == E_FAIL) || (hr == E_INVALIDARG),
103 "ParseDisplayName returned %08lx, expected 80070002, E_FAIL or E_INVALIDARG\n", hr);
105 /* I thought that perhaps the DesktopFolder's ParseDisplayName would recognize the
106 * path corresponding to CSIDL_PERSONAL and return a CLSID_MyDocuments PIDL. Turns
107 * out it doesn't. The magic seems to happen in the file dialogs, then. */
108 if (!pSHGetSpecialFolderPathW || !pILFindLastID) goto finished;
110 bRes = pSHGetSpecialFolderPathW(NULL, cTestDirW, CSIDL_PERSONAL, FALSE);
111 ok(bRes, "SHGetSpecialFolderPath(CSIDL_PERSONAL) failed! %ld\n", GetLastError());
112 if (!bRes) goto finished;
114 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cTestDirW, NULL, &newPIDL, 0);
115 ok(SUCCEEDED(hr), "DesktopFolder->ParseDisplayName failed. hr = %08lx.\n", hr);
116 if (FAILED(hr)) goto finished;
118 ok(pILFindLastID(newPIDL)->mkid.abID[0] == 0x31, "Last pidl should be of type "
119 "PT_FOLDER, but is: %02x\n", pILFindLastID(newPIDL)->mkid.abID[0]);
120 IMalloc_Free(ppM, newPIDL);
122 finished:
123 IShellFolder_Release(IDesktopFolder);
126 /* creates a file with the specified name for tests */
127 static void CreateTestFile(const CHAR *name)
129 HANDLE file;
130 DWORD written;
132 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
133 if (file != INVALID_HANDLE_VALUE)
135 WriteFile(file, name, strlen(name), &written, NULL);
136 WriteFile(file, "\n", strlen("\n"), &written, NULL);
137 CloseHandle(file);
142 /* initializes the tests */
143 static void CreateFilesFolders(void)
145 CreateDirectoryA(".\\testdir", NULL);
146 CreateDirectoryA(".\\testdir\\test.txt", NULL);
147 CreateTestFile (".\\testdir\\test1.txt ");
148 CreateTestFile (".\\testdir\\test2.txt ");
149 CreateTestFile (".\\testdir\\test3.txt ");
150 CreateDirectoryA(".\\testdir\\testdir2 ", NULL);
151 CreateDirectoryA(".\\testdir\\testdir2\\subdir", NULL);
154 /* cleans after tests */
155 static void Cleanup(void)
157 DeleteFileA(".\\testdir\\test1.txt");
158 DeleteFileA(".\\testdir\\test2.txt");
159 DeleteFileA(".\\testdir\\test3.txt");
160 RemoveDirectoryA(".\\testdir\\test.txt");
161 RemoveDirectoryA(".\\testdir\\testdir2\\subdir");
162 RemoveDirectoryA(".\\testdir\\testdir2");
163 RemoveDirectoryA(".\\testdir");
167 /* perform test */
168 static void test_EnumObjects(IShellFolder *iFolder)
170 IEnumIDList *iEnumList;
171 LPITEMIDLIST newPIDL, idlArr[10];
172 ULONG NumPIDLs;
173 int i=0, j;
174 HRESULT hr;
176 static const WORD iResults [5][5] =
178 { 0,-1,-1,-1,-1},
179 { 1, 0,-1,-1,-1},
180 { 1, 1, 0,-1,-1},
181 { 1, 1, 1, 0,-1},
182 { 1, 1, 1, 1, 0}
185 #define SFGAO_testfor SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR | SFGAO_CAPABILITYMASK
186 /* Don't test for SFGAO_HASSUBFOLDER since we return real state and native cached */
187 static const ULONG attrs[5] =
189 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
190 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM | SFGAO_FOLDER | SFGAO_FILESYSANCESTOR,
191 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
192 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
193 SFGAO_CAPABILITYMASK | SFGAO_FILESYSTEM,
196 hr = IShellFolder_EnumObjects(iFolder, NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
197 ok(hr == S_OK, "EnumObjects failed %08lx\n", hr);
199 /* This is to show that, contrary to what is said on MSDN, on IEnumIDList::Next,
200 * the filesystem shellfolders return S_OK even if less than 'celt' items are
201 * returned (in contrast to S_FALSE). We have to do it in a loop since WinXP
202 * only ever returns a single entry per call. */
203 while (IEnumIDList_Next(iEnumList, 10-i, &idlArr[i], &NumPIDLs) == S_OK)
204 i += NumPIDLs;
205 ok (i == 5, "i: %d\n", i);
207 hr = IEnumIDList_Release(iEnumList);
208 ok(hr == S_OK, "IEnumIDList_Release failed %08lx\n", hr);
210 /* Sort them first in case of wrong order from system */
211 for (i=0;i<5;i++) for (j=0;j<5;j++)
212 if ((SHORT)IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]) < 0)
214 newPIDL = idlArr[i];
215 idlArr[i] = idlArr[j];
216 idlArr[j] = newPIDL;
219 for (i=0;i<5;i++) for (j=0;j<5;j++)
221 hr = IShellFolder_CompareIDs(iFolder, 0, idlArr[i], idlArr[j]);
222 ok(hr == iResults[i][j], "Got %lx expected [%d]-[%d]=%x\n", hr, i, j, iResults[i][j]);
226 for (i = 0; i < 5; i++)
228 SFGAOF flags;
229 /* Native returns all flags no matter what we ask for */
230 flags = SFGAO_CANCOPY;
231 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
232 flags &= SFGAO_testfor;
233 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
234 ok(flags == (attrs[i]), "GetAttributesOf[%i] got %08lx, expected %08lx\n", i, flags, attrs[i]);
236 flags = SFGAO_testfor;
237 hr = IShellFolder_GetAttributesOf(iFolder, 1, (LPCITEMIDLIST*)(idlArr + i), &flags);
238 flags &= SFGAO_testfor;
239 ok(hr == S_OK, "GetAttributesOf returns %08lx\n", hr);
240 ok(flags == attrs[i], "GetAttributesOf[%i] got %08lx, expected %08lx\n", i, flags, attrs[i]);
243 for (i=0;i<5;i++)
244 IMalloc_Free(ppM, idlArr[i]);
247 static void test_BindToObject(void)
249 HRESULT hr;
250 UINT cChars;
251 IShellFolder *psfDesktop, *psfChild, *psfMyComputer, *psfSystemDir;
252 SHITEMID emptyitem = { 0, { 0 } };
253 LPITEMIDLIST pidlMyComputer, pidlSystemDir, pidlEmpty = (LPITEMIDLIST)&emptyitem;
254 WCHAR wszSystemDir[MAX_PATH];
255 char szSystemDir[MAX_PATH];
256 WCHAR wszMyComputer[] = {
257 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
258 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
260 /* The following tests shows that BindToObject should fail with E_INVALIDARG if called
261 * with an empty pidl. This is tested for Desktop, MyComputer and the FS ShellFolder
263 hr = SHGetDesktopFolder(&psfDesktop);
264 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
265 if (FAILED(hr)) return;
267 hr = IShellFolder_BindToObject(psfDesktop, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
268 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
270 hr = IShellFolder_BindToObject(psfDesktop, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
271 ok (hr == E_INVALIDARG, "Desktop's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
273 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
274 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
275 if (FAILED(hr)) {
276 IShellFolder_Release(psfDesktop);
277 return;
280 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
281 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
282 IShellFolder_Release(psfDesktop);
283 IMalloc_Free(ppM, pidlMyComputer);
284 if (FAILED(hr)) return;
286 hr = IShellFolder_BindToObject(psfMyComputer, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
287 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
289 #if 0
290 /* this call segfaults on 98SE */
291 hr = IShellFolder_BindToObject(psfMyComputer, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
292 ok (hr == E_INVALIDARG, "MyComputers's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
293 #endif
295 cChars = GetSystemDirectoryA(szSystemDir, MAX_PATH);
296 ok (cChars > 0 && cChars < MAX_PATH, "GetSystemDirectoryA failed! LastError: %08lx\n", GetLastError());
297 if (cChars == 0 || cChars >= MAX_PATH) {
298 IShellFolder_Release(psfMyComputer);
299 return;
301 MultiByteToWideChar(CP_ACP, 0, szSystemDir, -1, wszSystemDir, MAX_PATH);
303 hr = IShellFolder_ParseDisplayName(psfMyComputer, NULL, NULL, wszSystemDir, NULL, &pidlSystemDir, NULL);
304 ok (SUCCEEDED(hr), "MyComputers's ParseDisplayName failed to parse the SystemDirectory! hr = %08lx\n", hr);
305 if (FAILED(hr)) {
306 IShellFolder_Release(psfMyComputer);
307 return;
310 hr = IShellFolder_BindToObject(psfMyComputer, pidlSystemDir, NULL, &IID_IShellFolder, (LPVOID*)&psfSystemDir);
311 ok (SUCCEEDED(hr), "MyComputer failed to bind to a FileSystem ShellFolder! hr = %08lx\n", hr);
312 IShellFolder_Release(psfMyComputer);
313 IMalloc_Free(ppM, pidlSystemDir);
314 if (FAILED(hr)) return;
316 hr = IShellFolder_BindToObject(psfSystemDir, pidlEmpty, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
317 ok (hr == E_INVALIDARG,
318 "FileSystem ShellFolder's BindToObject should fail, when called with empty pidl! hr = %08lx\n", hr);
320 #if 0
321 /* this call segfaults on 98SE */
322 hr = IShellFolder_BindToObject(psfSystemDir, NULL, NULL, &IID_IShellFolder, (LPVOID*)&psfChild);
323 ok (hr == E_INVALIDARG,
324 "FileSystem ShellFolder's BindToObject should fail, when called with NULL pidl! hr = %08lx\n", hr);
325 #endif
327 IShellFolder_Release(psfSystemDir);
330 static void test_GetDisplayName(void)
332 BOOL result;
333 HRESULT hr;
334 HANDLE hTestFile;
335 WCHAR wszTestFile[MAX_PATH], wszTestFile2[MAX_PATH], wszTestDir[MAX_PATH];
336 char szTestFile[MAX_PATH], szTestDir[MAX_PATH];
337 STRRET strret;
338 LPSHELLFOLDER psfDesktop, psfPersonal;
339 IUnknown *psfFile;
340 SHITEMID emptyitem = { 0, { 0 } };
341 LPITEMIDLIST pidlTestFile, pidlEmpty = (LPITEMIDLIST)&emptyitem;
342 LPCITEMIDLIST pidlLast;
343 static const WCHAR wszFileName[] = { 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
344 static const WCHAR wszDirName[] = { 'w','i','n','e','t','e','s','t',0 };
346 /* I'm trying to figure if there is a functional difference between calling
347 * SHGetPathFromIDList and calling GetDisplayNameOf(SHGDN_FORPARSING) after
348 * binding to the shellfolder. One thing I thought of was that perhaps
349 * SHGetPathFromIDList would be able to get the path to a file, which does
350 * not exist anymore, while the other method would'nt. It turns out there's
351 * no functional difference in this respect.
354 if(!pSHGetSpecialFolderPathW) return;
356 /* First creating a directory in MyDocuments and a file in this directory. */
357 result = pSHGetSpecialFolderPathW(NULL, wszTestDir, CSIDL_PERSONAL, FALSE);
358 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
359 if (!result) return;
361 PathAddBackslashW(wszTestDir);
362 lstrcatW(wszTestDir, wszDirName);
363 WideCharToMultiByte(CP_ACP, 0, wszTestDir, -1, szTestDir, MAX_PATH, 0, 0);
364 result = CreateDirectoryA(szTestDir, NULL);
365 ok(result, "CreateDirectoryA failed! Last error: %08lx\n", GetLastError());
366 if (!result) return;
368 lstrcpyW(wszTestFile, wszTestDir);
369 PathAddBackslashW(wszTestFile);
370 lstrcatW(wszTestFile, wszFileName);
371 WideCharToMultiByte(CP_ACP, 0, wszTestFile, -1, szTestFile, MAX_PATH, 0, 0);
373 hTestFile = CreateFileA(szTestFile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
374 ok((hTestFile != INVALID_HANDLE_VALUE), "CreateFileA failed! Last error: %08lx\n", GetLastError());
375 if (hTestFile == INVALID_HANDLE_VALUE) return;
376 CloseHandle(hTestFile);
378 /* Getting an itemidlist for the file. */
379 hr = SHGetDesktopFolder(&psfDesktop);
380 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
381 if (FAILED(hr)) return;
383 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
384 ok(SUCCEEDED(hr), "Desktop->ParseDisplayName failed! hr = %08lx\n", hr);
385 if (FAILED(hr)) {
386 IShellFolder_Release(psfDesktop);
387 return;
390 /* WinXP stores the filenames as both ANSI and UNICODE in the pidls */
391 pidlLast = pILFindLastID(pidlTestFile);
392 ok(pidlLast->mkid.cb >=76, "Expected pidl length of at least 76, got %d.\n", pidlLast->mkid.cb);
393 if (pidlLast->mkid.cb >= 76) {
394 ok(!lstrcmpW((WCHAR*)&pidlLast->mkid.abID[46], wszFileName),
395 "WinXP stores the filename as a wchar-string at this position!\n");
398 /* It seems as if we cannot bind to regular files on windows, but only directories.
400 hr = IShellFolder_BindToObject(psfDesktop, pidlTestFile, NULL, &IID_IUnknown, (VOID**)&psfFile);
401 todo_wine { ok (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "hr = %08lx\n", hr); }
402 if (SUCCEEDED(hr)) {
403 IShellFolder_Release(psfFile);
406 /* Some tests for IShellFolder::SetNameOf */
407 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
408 ok(SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
409 if (SUCCEEDED(hr)) {
410 /* It's ok to use this fixed path. Call will fail anyway. */
411 WCHAR wszAbsoluteFilename[] = { 'C',':','\\','w','i','n','e','t','e','s','t', 0 };
412 LPITEMIDLIST pidlNew;
414 /* The pidl returned through the last parameter of SetNameOf is a simple one. */
415 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlLast, wszDirName, SHGDN_NORMAL, &pidlNew);
416 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08lx\n", hr);
417 ok (((LPITEMIDLIST)((LPBYTE)pidlNew+pidlNew->mkid.cb))->mkid.cb == 0,
418 "pidl returned from SetNameOf should be simple!\n");
420 /* Passing an absolute path to SetNameOf fails. The HRESULT code indicates that SetNameOf
421 * is implemented on top of SHFileOperation in WinXP. */
422 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszAbsoluteFilename,
423 SHGDN_FORPARSING, NULL);
424 ok (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED), "SetNameOf succeeded! hr = %08lx\n", hr);
426 /* Rename the file back to it's original name. SetNameOf ignores the fact, that the
427 * SHGDN flags specify an absolute path. */
428 hr = IShellFolder_SetNameOf(psfPersonal, NULL, pidlNew, wszFileName, SHGDN_FORPARSING, NULL);
429 ok (SUCCEEDED(hr), "SetNameOf failed! hr = %08lx\n", hr);
431 ILFree(pidlNew);
432 IShellFolder_Release(psfPersonal);
435 /* Deleting the file and the directory */
436 DeleteFileA(szTestFile);
437 RemoveDirectoryA(szTestDir);
439 /* SHGetPathFromIDListW still works, although the file is not present anymore. */
440 result = SHGetPathFromIDListW(pidlTestFile, wszTestFile2);
441 ok (result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
442 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "SHGetPathFromIDListW returns incorrect path!\n");
444 if(!pSHBindToParent) return;
446 /* SHBindToParent fails, if called with a NULL PIDL. */
447 hr = pSHBindToParent(NULL, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
448 ok (FAILED(hr), "SHBindToParent(NULL) should fail!\n");
450 /* But it succeeds with an empty PIDL. */
451 hr = pSHBindToParent(pidlEmpty, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
452 ok (SUCCEEDED(hr), "SHBindToParent(empty PIDL) should succeed! hr = %08lx\n", hr);
453 ok (pidlLast == pidlEmpty, "The last element of an empty PIDL should be the PIDL itself!\n");
454 if (SUCCEEDED(hr))
455 IShellFolder_Release(psfPersonal);
457 /* Binding to the folder and querying the display name of the file also works. */
458 hr = pSHBindToParent(pidlTestFile, &IID_IShellFolder, (VOID**)&psfPersonal, &pidlLast);
459 ok (SUCCEEDED(hr), "SHBindToParent failed! hr = %08lx\n", hr);
460 if (FAILED(hr)) {
461 IShellFolder_Release(psfDesktop);
462 return;
465 /* This test shows that Windows doesn't allocate a new pidlLast, but returns a pointer into
466 * pidlTestFile (In accordance with MSDN). */
467 ok (pILFindLastID(pidlTestFile) == pidlLast,
468 "SHBindToParent doesn't return the last id of the pidl param!\n");
470 hr = IShellFolder_GetDisplayNameOf(psfPersonal, pidlLast, SHGDN_FORPARSING, &strret);
471 ok (SUCCEEDED(hr), "Personal->GetDisplayNameOf failed! hr = %08lx\n", hr);
472 if (FAILED(hr)) {
473 IShellFolder_Release(psfDesktop);
474 IShellFolder_Release(psfPersonal);
475 return;
478 if (pStrRetToBufW)
480 hr = pStrRetToBufW(&strret, pidlLast, wszTestFile2, MAX_PATH);
481 ok (SUCCEEDED(hr), "StrRetToBufW failed! hr = %08lx\n", hr);
482 ok (!lstrcmpiW(wszTestFile, wszTestFile2), "GetDisplayNameOf returns incorrect path!\n");
485 IShellFolder_Release(psfDesktop);
486 IShellFolder_Release(psfPersonal);
489 static void test_CallForAttributes(void)
491 HKEY hKey;
492 LONG lResult;
493 HRESULT hr;
494 DWORD dwSize;
495 LPSHELLFOLDER psfDesktop;
496 LPITEMIDLIST pidlMyDocuments;
497 DWORD dwAttributes, dwCallForAttributes, dwOrigAttributes, dwOrigCallForAttributes;
498 static const WCHAR wszAttributes[] = { 'A','t','t','r','i','b','u','t','e','s',0 };
499 static const WCHAR wszCallForAttributes[] = {
500 'C','a','l','l','F','o','r','A','t','t','r','i','b','u','t','e','s',0 };
501 static const WCHAR wszMyDocumentsKey[] = {
502 'C','L','S','I','D','\\','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-',
503 '1','1','D','0','-','9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',
504 '\\','S','h','e','l','l','F','o','l','d','e','r',0 };
505 WCHAR wszMyDocuments[] = {
506 ':',':','{','4','5','0','D','8','F','B','A','-','A','D','2','5','-','1','1','D','0','-',
507 '9','8','A','8','-','0','8','0','0','3','6','1','B','1','1','0','3','}',0 };
509 /* For the root of a namespace extension, the attributes are not queried by binding
510 * to the object and calling GetAttributesOf. Instead, the attributes are read from
511 * the registry value HKCR/CLSID/{...}/ShellFolder/Attributes. This is documented on MSDN.
513 * The MyDocuments shellfolder on WinXP has a HKCR/CLSID/{...}/ShellFolder/CallForAttributes
514 * value. It seems that if the folder is queried for one of the flags set in CallForAttributes,
515 * the shell does bind to the folder object and calls GetAttributesOf. This is not documented
516 * on MSDN. This test is meant to document the observed behaviour on WinXP SP2.
518 hr = SHGetDesktopFolder(&psfDesktop);
519 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
520 if (FAILED(hr)) return;
522 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyDocuments, NULL,
523 &pidlMyDocuments, NULL);
524 ok (SUCCEEDED(hr),
525 "Desktop's ParseDisplayName failed to parse MyDocuments's CLSID! hr = %08lx\n", hr);
526 if (FAILED(hr)) {
527 IShellFolder_Release(psfDesktop);
528 return;
531 dwAttributes = 0xffffffff;
532 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
533 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
534 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
536 /* We need the following setup (as observed on WinXP SP2), for the tests to make sense. */
537 ok (dwAttributes & SFGAO_FILESYSTEM, "SFGAO_FILESYSTEM attribute is not set for MyDocuments!\n");
538 ok (!(dwAttributes & SFGAO_ISSLOW), "SFGAO_ISSLOW attribute is set for MyDocuments!\n");
539 ok (!(dwAttributes & SFGAO_GHOSTED), "SFGAO_GHOSTED attribute is set for MyDocuments!\n");
541 /* We don't have the MyDocuments shellfolder in wine yet, and thus we don't have the registry
542 * key. So the test will return at this point, if run on wine.
544 lResult = RegOpenKeyExW(HKEY_CLASSES_ROOT, wszMyDocumentsKey, 0, KEY_WRITE|KEY_READ, &hKey);
545 ok (lResult == ERROR_SUCCESS, "RegOpenKeyEx failed! result: %08lx\n", lResult);
546 if (lResult != ERROR_SUCCESS) {
547 IMalloc_Free(ppM, pidlMyDocuments);
548 IShellFolder_Release(psfDesktop);
549 return;
552 /* Query MyDocuments' Attributes value, to be able to restore it later. */
553 dwSize = sizeof(DWORD);
554 lResult = RegQueryValueExW(hKey, wszAttributes, NULL, NULL, (LPBYTE)&dwOrigAttributes, &dwSize);
555 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
556 if (lResult != ERROR_SUCCESS) {
557 RegCloseKey(hKey);
558 IMalloc_Free(ppM, pidlMyDocuments);
559 IShellFolder_Release(psfDesktop);
560 return;
563 /* Query MyDocuments' CallForAttributes value, to be able to restore it later. */
564 dwSize = sizeof(DWORD);
565 lResult = RegQueryValueExW(hKey, wszCallForAttributes, NULL, NULL,
566 (LPBYTE)&dwOrigCallForAttributes, &dwSize);
567 ok (lResult == ERROR_SUCCESS, "RegQueryValueEx failed! result: %08lx\n", lResult);
568 if (lResult != ERROR_SUCCESS) {
569 RegCloseKey(hKey);
570 IMalloc_Free(ppM, pidlMyDocuments);
571 IShellFolder_Release(psfDesktop);
572 return;
575 /* Define via the Attributes value that MyDocuments attributes are SFGAO_ISSLOW and
576 * SFGAO_GHOSTED and that MyDocuments should be called for the SFGAO_ISSLOW and
577 * SFGAO_FILESYSTEM attributes. */
578 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED;
579 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwAttributes, sizeof(DWORD));
580 dwCallForAttributes = SFGAO_ISSLOW|SFGAO_FILESYSTEM;
581 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
582 (LPBYTE)&dwCallForAttributes, sizeof(DWORD));
584 /* Although it is not set in CallForAttributes, the SFGAO_GHOSTED flag is reset by
585 * GetAttributesOf. It seems that once there is a single attribute queried, for which
586 * CallForAttributes is set, all flags are taken from the GetAttributesOf call and
587 * the flags in Attributes are ignored.
589 dwAttributes = SFGAO_ISSLOW|SFGAO_GHOSTED|SFGAO_FILESYSTEM;
590 hr = IShellFolder_GetAttributesOf(psfDesktop, 1,
591 (LPCITEMIDLIST*)&pidlMyDocuments, &dwAttributes);
592 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyDocuments) failed! hr = %08lx\n", hr);
593 if (SUCCEEDED(hr))
594 ok (dwAttributes == SFGAO_FILESYSTEM,
595 "Desktop->GetAttributes(MyDocuments) returned unexpected attributes: %08lx\n",
596 dwAttributes);
598 /* Restore MyDocuments' original Attributes and CallForAttributes registry values */
599 RegSetValueExW(hKey, wszAttributes, 0, REG_DWORD, (LPBYTE)&dwOrigAttributes, sizeof(DWORD));
600 RegSetValueExW(hKey, wszCallForAttributes, 0, REG_DWORD,
601 (LPBYTE)&dwOrigCallForAttributes, sizeof(DWORD));
602 RegCloseKey(hKey);
603 IMalloc_Free(ppM, pidlMyDocuments);
604 IShellFolder_Release(psfDesktop);
607 static void test_GetAttributesOf(void)
609 HRESULT hr;
610 LPSHELLFOLDER psfDesktop, psfMyComputer;
611 SHITEMID emptyitem = { 0, { 0 } };
612 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
613 LPITEMIDLIST pidlMyComputer;
614 DWORD dwFlags;
615 static const DWORD dwDesktopFlags = /* As observed on WinXP SP2 */
616 SFGAO_STORAGE | SFGAO_HASPROPSHEET | SFGAO_STORAGEANCESTOR |
617 SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_HASSUBFOLDER;
618 static const DWORD dwMyComputerFlags = /* As observed on WinXP SP2 */
619 SFGAO_CANRENAME | SFGAO_CANDELETE | SFGAO_HASPROPSHEET |
620 SFGAO_DROPTARGET | SFGAO_FILESYSANCESTOR | SFGAO_FOLDER | SFGAO_HASSUBFOLDER;
621 WCHAR wszMyComputer[] = {
622 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
623 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
624 char cCurrDirA [MAX_PATH] = {0};
625 WCHAR cCurrDirW [MAX_PATH];
626 static const WCHAR cTestDirW[] = {'t','e','s','t','d','i','r',0};
627 static const WCHAR cBackSlash[] = {'\\',0};
628 IShellFolder *IDesktopFolder, *testIShellFolder;
629 ITEMIDLIST *newPIDL;
630 int len;
632 hr = SHGetDesktopFolder(&psfDesktop);
633 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
634 if (FAILED(hr)) return;
636 /* The Desktop attributes can be queried with a single empty itemidlist, .. */
637 dwFlags = 0xffffffff;
638 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, &pidlEmpty, &dwFlags);
639 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(empty pidl) failed! hr = %08lx\n", hr);
640 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
641 dwFlags, dwDesktopFlags);
643 /* .. or with no itemidlist at all. */
644 dwFlags = 0xffffffff;
645 hr = IShellFolder_GetAttributesOf(psfDesktop, 0, NULL, &dwFlags);
646 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
647 ok (dwFlags == dwDesktopFlags, "Wrong Desktop attributes: %08lx, expected: %08lx\n",
648 dwFlags, dwDesktopFlags);
650 /* Testing the attributes of the MyComputer shellfolder */
651 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
652 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
653 if (FAILED(hr)) {
654 IShellFolder_Release(psfDesktop);
655 return;
658 /* WinXP SP2 sets the SFGAO_CANLINK flag, when MyComputer is queried via the Desktop
659 * folder object. It doesn't do this, if MyComputer is queried directly (see below).
660 * SFGAO_CANLINK is the same as DROPEFFECT_LINK, which MSDN says means: "Drag source
661 * should create a link to the original data". You can't create links on MyComputer on
662 * Windows, so this flag shouldn't be set. Seems like a bug in Windows. As long as nobody
663 * depends on this bug, we probably shouldn't imitate it.
665 dwFlags = 0xffffffff;
666 hr = IShellFolder_GetAttributesOf(psfDesktop, 1, (LPCITEMIDLIST*)&pidlMyComputer, &dwFlags);
667 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf(MyComputer) failed! hr = %08lx\n", hr);
668 ok ((dwFlags & ~(DWORD)SFGAO_CANLINK) == dwMyComputerFlags,
669 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags);
671 hr = IShellFolder_BindToObject(psfDesktop, pidlMyComputer, NULL, &IID_IShellFolder, (LPVOID*)&psfMyComputer);
672 ok (SUCCEEDED(hr), "Desktop failed to bind to MyComputer object! hr = %08lx\n", hr);
673 IShellFolder_Release(psfDesktop);
674 IMalloc_Free(ppM, pidlMyComputer);
675 if (FAILED(hr)) return;
677 hr = IShellFolder_GetAttributesOf(psfMyComputer, 1, &pidlEmpty, &dwFlags);
678 todo_wine {ok (hr == E_INVALIDARG, "MyComputer->GetAttributesOf(emtpy pidl) should fail! hr = %08lx\n", hr); }
680 dwFlags = 0xffffffff;
681 hr = IShellFolder_GetAttributesOf(psfMyComputer, 0, NULL, &dwFlags);
682 ok (SUCCEEDED(hr), "MyComputer->GetAttributesOf(NULL) failed! hr = %08lx\n", hr);
683 todo_wine { ok (dwFlags == dwMyComputerFlags,
684 "Wrong MyComputer attributes: %08lx, expected: %08lx\n", dwFlags, dwMyComputerFlags); }
686 IShellFolder_Release(psfMyComputer);
688 /* create test directory */
689 CreateFilesFolders();
691 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
692 len = lstrlenA(cCurrDirA);
694 if (len == 0) {
695 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
696 return;
698 if(cCurrDirA[len-1] == '\\')
699 cCurrDirA[len-1] = 0;
701 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
703 hr = SHGetDesktopFolder(&IDesktopFolder);
704 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
706 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
707 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
709 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
710 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
712 IMalloc_Free(ppM, newPIDL);
714 /* get relative PIDL */
715 hr = IShellFolder_ParseDisplayName(testIShellFolder, NULL, NULL, (LPWSTR)cTestDirW, NULL, &newPIDL, 0);
716 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
718 /* test the shell attributes of the test directory using the relative PIDL */
719 dwFlags = SFGAO_FOLDER;
720 hr = IShellFolder_GetAttributesOf(testIShellFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
721 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08lx\n", hr);
722 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for relative PIDL: %08lx\n", dwFlags);
724 /* free memory */
725 IMalloc_Free(ppM, newPIDL);
727 /* append testdirectory name to path */
728 lstrcatW(cCurrDirW, cBackSlash);
729 lstrcatW(cCurrDirW, cTestDirW);
731 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
732 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
734 /* test the shell attributes of the test directory using the absolute PIDL */
735 dwFlags = SFGAO_FOLDER;
736 hr = IShellFolder_GetAttributesOf(IDesktopFolder, 1, (LPCITEMIDLIST*)&newPIDL, &dwFlags);
737 ok (SUCCEEDED(hr), "Desktop->GetAttributesOf() failed! hr = %08lx\n", hr);
738 ok ((dwFlags&SFGAO_FOLDER), "Wrong directory attribute for absolute PIDL: %08lx\n", dwFlags);
740 /* free memory */
741 IMalloc_Free(ppM, newPIDL);
743 IShellFolder_Release(testIShellFolder);
745 Cleanup();
747 IShellFolder_Release(IDesktopFolder);
750 static void test_SHGetPathFromIDList(void)
752 SHITEMID emptyitem = { 0, { 0 } };
753 LPCITEMIDLIST pidlEmpty = (LPCITEMIDLIST)&emptyitem;
754 LPITEMIDLIST pidlMyComputer;
755 WCHAR wszPath[MAX_PATH], wszDesktop[MAX_PATH];
756 BOOL result;
757 HRESULT hr;
758 LPSHELLFOLDER psfDesktop;
759 WCHAR wszMyComputer[] = {
760 ':',':','{','2','0','D','0','4','F','E','0','-','3','A','E','A','-','1','0','6','9','-',
761 'A','2','D','8','-','0','8','0','0','2','B','3','0','3','0','9','D','}',0 };
762 WCHAR wszFileName[MAX_PATH];
763 LPITEMIDLIST pidlTestFile;
764 HANDLE hTestFile;
765 STRRET strret;
766 static WCHAR wszTestFile[] = {
767 'w','i','n','e','t','e','s','t','.','f','o','o',0 };
768 HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *);
769 HMODULE hShell32;
770 LPITEMIDLIST pidlPrograms;
772 if(!pSHGetSpecialFolderPathW) return;
774 /* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
775 result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
776 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError());
777 if (!result) return;
779 result = SHGetPathFromIDListW(pidlEmpty, wszPath);
780 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
781 if (!result) return;
782 ok(!lstrcmpiW(wszDesktop, wszPath), "SHGetPathFromIDList didn't return desktop path for empty pidl!\n");
784 /* MyComputer does not map to a filesystem path. SHGetPathFromIDList should fail. */
785 hr = SHGetDesktopFolder(&psfDesktop);
786 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
787 if (FAILED(hr)) return;
789 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszMyComputer, NULL, &pidlMyComputer, NULL);
790 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse MyComputer's CLSID! hr = %08lx\n", hr);
791 if (FAILED(hr)) {
792 IShellFolder_Release(psfDesktop);
793 return;
796 SetLastError(0xdeadbeef);
797 result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
798 ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
799 ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError());
800 if (result) {
801 IShellFolder_Release(psfDesktop);
802 return;
805 IMalloc_Free(ppM, pidlMyComputer);
807 result = pSHGetSpecialFolderPathW(NULL, wszFileName, CSIDL_DESKTOPDIRECTORY, FALSE);
808 ok(result, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
809 if (!result) {
810 IShellFolder_Release(psfDesktop);
811 return;
813 PathAddBackslashW(wszFileName);
814 lstrcatW(wszFileName, wszTestFile);
815 hTestFile = CreateFileW(wszFileName, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
816 ok(hTestFile != INVALID_HANDLE_VALUE, "CreateFileW failed! Last error: %08lx\n", GetLastError());
817 if (hTestFile == INVALID_HANDLE_VALUE) {
818 IShellFolder_Release(psfDesktop);
819 return;
821 CloseHandle(hTestFile);
823 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszTestFile, NULL, &pidlTestFile, NULL);
824 ok (SUCCEEDED(hr), "Desktop's ParseDisplayName failed to parse filename hr = %08lx\n", hr);
825 if (FAILED(hr)) {
826 IShellFolder_Release(psfDesktop);
827 DeleteFileW(wszFileName);
828 IMalloc_Free(ppM, pidlTestFile);
829 return;
832 /* This test is to show that the Desktop shellfolder prepends the CSIDL_DESKTOPDIRECTORY
833 * path for files placed on the desktop, if called with SHGDN_FORPARSING. */
834 hr = IShellFolder_GetDisplayNameOf(psfDesktop, pidlTestFile, SHGDN_FORPARSING, &strret);
835 ok (SUCCEEDED(hr), "Desktop's GetDisplayNamfOf failed! hr = %08lx\n", hr);
836 IShellFolder_Release(psfDesktop);
837 DeleteFileW(wszFileName);
838 if (FAILED(hr)) {
839 IMalloc_Free(ppM, pidlTestFile);
840 return;
842 if (pStrRetToBufW)
844 pStrRetToBufW(&strret, pidlTestFile, wszPath, MAX_PATH);
845 ok(0 == lstrcmpW(wszFileName, wszPath),
846 "Desktop->GetDisplayNameOf(pidlTestFile, SHGDN_FORPARSING) "
847 "returned incorrect path for file placed on desktop\n");
850 result = SHGetPathFromIDListW(pidlTestFile, wszPath);
851 ok(result, "SHGetPathFromIDListW failed! Last error: %08lx\n", GetLastError());
852 IMalloc_Free(ppM, pidlTestFile);
853 if (!result) return;
854 ok(0 == lstrcmpW(wszFileName, wszPath), "SHGetPathFromIDListW returned incorrect path for file placed on desktop\n");
857 /* Test if we can get the path from the start menu "program files" PIDL. */
858 hShell32 = GetModuleHandleA("shell32");
859 pSHGetSpecialFolderLocation = (void *)GetProcAddress(hShell32, "SHGetSpecialFolderLocation");
861 hr = pSHGetSpecialFolderLocation(NULL, CSIDL_PROGRAM_FILES, &pidlPrograms);
862 ok(SUCCEEDED(hr), "SHGetFolderLocation failed: 0x%08lx\n", hr);
864 SetLastError(0xdeadbeef);
865 result = SHGetPathFromIDListW(pidlPrograms, wszPath);
866 IMalloc_Free(ppM, pidlPrograms);
867 ok(result, "SHGetPathFromIDList failed\n");
870 static void test_EnumObjects_and_CompareIDs(void)
872 ITEMIDLIST *newPIDL;
873 IShellFolder *IDesktopFolder, *testIShellFolder;
874 char cCurrDirA [MAX_PATH] = {0};
875 WCHAR cCurrDirW [MAX_PATH];
876 static const WCHAR cTestDirW[] = {'\\','t','e','s','t','d','i','r',0};
877 int len;
878 HRESULT hr;
880 GetCurrentDirectoryA(MAX_PATH, cCurrDirA);
881 len = lstrlenA(cCurrDirA);
883 if(len == 0) {
884 trace("GetCurrentDirectoryA returned empty string. Skipping test_EnumObjects_and_CompareIDs\n");
885 return;
887 if(cCurrDirA[len-1] == '\\')
888 cCurrDirA[len-1] = 0;
890 MultiByteToWideChar(CP_ACP, 0, cCurrDirA, -1, cCurrDirW, MAX_PATH);
891 lstrcatW(cCurrDirW, cTestDirW);
893 hr = SHGetDesktopFolder(&IDesktopFolder);
894 ok(hr == S_OK, "SHGetDesktopfolder failed %08lx\n", hr);
896 CreateFilesFolders();
898 hr = IShellFolder_ParseDisplayName(IDesktopFolder, NULL, NULL, cCurrDirW, NULL, &newPIDL, 0);
899 ok(hr == S_OK, "ParseDisplayName failed %08lx\n", hr);
901 hr = IShellFolder_BindToObject(IDesktopFolder, newPIDL, NULL, (REFIID)&IID_IShellFolder, (LPVOID *)&testIShellFolder);
902 ok(hr == S_OK, "BindToObject failed %08lx\n", hr);
904 test_EnumObjects(testIShellFolder);
906 IShellFolder_Release(testIShellFolder);
908 Cleanup();
910 IMalloc_Free(ppM, newPIDL);
912 IShellFolder_Release(IDesktopFolder);
915 /* A simple implementation of an IPropertyBag, which returns fixed values for
916 * 'Target' and 'Attributes' properties.
918 static HRESULT WINAPI InitPropertyBag_IPropertyBag_QueryInterface(IPropertyBag *iface, REFIID riid,
919 void **ppvObject)
921 if (!ppvObject)
922 return E_INVALIDARG;
924 if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IPropertyBag, riid)) {
925 *ppvObject = iface;
926 } else {
927 ok (FALSE, "InitPropertyBag asked for unknown interface!\n");
928 return E_NOINTERFACE;
931 IPropertyBag_AddRef(iface);
932 return S_OK;
935 static ULONG WINAPI InitPropertyBag_IPropertyBag_AddRef(IPropertyBag *iface) {
936 return 2;
939 static ULONG WINAPI InitPropertyBag_IPropertyBag_Release(IPropertyBag *iface) {
940 return 1;
943 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Read(IPropertyBag *iface, LPCOLESTR pszPropName,
944 VARIANT *pVar, IErrorLog *pErrorLog)
946 static const WCHAR wszTargetSpecialFolder[] = {
947 'T','a','r','g','e','t','S','p','e','c','i','a','l','F','o','l','d','e','r',0 };
948 static const WCHAR wszTarget[] = {
949 'T','a','r','g','e','t',0 };
950 static const WCHAR wszAttributes[] = {
951 'A','t','t','r','i','b','u','t','e','s',0 };
952 static const WCHAR wszResolveLinkFlags[] = {
953 'R','e','s','o','l','v','e','L','i','n','k','F','l','a','g','s',0 };
955 if (!lstrcmpW(pszPropName, wszTargetSpecialFolder)) {
956 ok(V_VT(pVar) == VT_I4, "Wrong variant type for 'TargetSpecialFolder' property!\n");
957 return E_INVALIDARG;
960 if (!lstrcmpW(pszPropName, wszResolveLinkFlags))
962 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'ResolveLinkFlags' property!\n");
963 return E_INVALIDARG;
966 if (!lstrcmpW(pszPropName, wszTarget)) {
967 WCHAR wszPath[MAX_PATH];
968 BOOL result;
970 ok(V_VT(pVar) == VT_BSTR, "Wrong variant type for 'Target' property!\n");
971 if (V_VT(pVar) != VT_BSTR) return E_INVALIDARG;
973 result = pSHGetSpecialFolderPathW(NULL, wszPath, CSIDL_DESKTOPDIRECTORY, FALSE);
974 ok(result, "SHGetSpecialFolderPathW(DESKTOPDIRECTORY) failed! x%08lx\n", GetLastError());
975 if (!result) return E_INVALIDARG;
977 V_BSTR(pVar) = SysAllocString(wszPath);
978 return S_OK;
981 if (!lstrcmpW(pszPropName, wszAttributes)) {
982 ok(V_VT(pVar) == VT_UI4, "Wrong variant type for 'Attributes' property!\n");
983 if (V_VT(pVar) != VT_UI4) return E_INVALIDARG;
984 V_UI4(pVar) = SFGAO_FOLDER|SFGAO_HASSUBFOLDER|SFGAO_FILESYSANCESTOR|
985 SFGAO_CANRENAME|SFGAO_FILESYSTEM;
986 return S_OK;
989 ok(FALSE, "PropertyBag was asked for unknown property (vt=%d)!\n", V_VT(pVar));
990 return E_INVALIDARG;
993 static HRESULT WINAPI InitPropertyBag_IPropertyBag_Write(IPropertyBag *iface, LPCOLESTR pszPropName,
994 VARIANT *pVar)
996 ok(FALSE, "Unexpected call to IPropertyBag_Write\n");
997 return E_NOTIMPL;
1000 static const IPropertyBagVtbl InitPropertyBag_IPropertyBagVtbl = {
1001 InitPropertyBag_IPropertyBag_QueryInterface,
1002 InitPropertyBag_IPropertyBag_AddRef,
1003 InitPropertyBag_IPropertyBag_Release,
1004 InitPropertyBag_IPropertyBag_Read,
1005 InitPropertyBag_IPropertyBag_Write
1008 struct IPropertyBag InitPropertyBag = {
1009 &InitPropertyBag_IPropertyBagVtbl
1012 void test_FolderShortcut(void) {
1013 IPersistPropertyBag *pPersistPropertyBag;
1014 IShellFolder *pShellFolder, *pDesktopFolder;
1015 IPersistFolder3 *pPersistFolder3;
1016 HRESULT hr;
1017 STRRET strret;
1018 WCHAR wszDesktopPath[MAX_PATH], wszBuffer[MAX_PATH];
1019 BOOL result;
1020 CLSID clsid;
1021 LPITEMIDLIST pidlCurrentFolder, pidlWineTestFolder, pidlSubFolder;
1022 HKEY hShellExtKey;
1023 WCHAR wszWineTestFolder[] = {
1024 ':',':','{','9','B','3','5','2','E','B','F','-','2','7','6','5','-','4','5','C','1','-',
1025 'B','4','C','6','-','8','5','C','C','7','F','7','A','B','C','6','4','}',0 };
1026 WCHAR wszShellExtKey[] = { 'S','o','f','t','w','a','r','e','\\',
1027 'M','i','c','r','o','s','o','f','t','\\','W','i','n','d','o','w','s','\\',
1028 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1029 'E','x','p','l','o','r','e','r','\\','D','e','s','k','t','o','p','\\',
1030 'N','a','m','e','S','p','a','c','e','\\',
1031 '{','9','b','3','5','2','e','b','f','-','2','7','6','5','-','4','5','c','1','-',
1032 'b','4','c','6','-','8','5','c','c','7','f','7','a','b','c','6','4','}',0 };
1034 WCHAR wszSomeSubFolder[] = { 'S','u','b','F','o','l','d','e','r', 0};
1035 static const GUID CLSID_UnixDosFolder =
1036 {0x9d20aae8, 0x0625, 0x44b0, {0x9c, 0xa7, 0x71, 0x88, 0x9c, 0x22, 0x54, 0xd9}};
1038 if (!pSHGetSpecialFolderPathW || !pStrRetToBufW) return;
1040 /* These tests basically show, that CLSID_FolderShortcuts are initialized
1041 * via their IPersistPropertyBag interface. And that the target folder
1042 * is taken from the IPropertyBag's 'Target' property.
1044 hr = CoCreateInstance(&CLSID_FolderShortcut, NULL, CLSCTX_INPROC_SERVER,
1045 &IID_IPersistPropertyBag, (LPVOID*)&pPersistPropertyBag);
1046 ok (SUCCEEDED(hr), "CoCreateInstance failed! hr = 0x%08lx\n", hr);
1047 if (FAILED(hr)) return;
1049 hr = IPersistPropertyBag_Load(pPersistPropertyBag, &InitPropertyBag, NULL);
1050 ok(SUCCEEDED(hr), "IPersistPropertyBag_Load failed! hr = %08lx\n", hr);
1051 if (FAILED(hr)) {
1052 IPersistPropertyBag_Release(pPersistPropertyBag);
1053 return;
1056 hr = IPersistPropertyBag_QueryInterface(pPersistPropertyBag, &IID_IShellFolder,
1057 (LPVOID*)&pShellFolder);
1058 IPersistPropertyBag_Release(pPersistPropertyBag);
1059 ok(SUCCEEDED(hr), "IPersistPropertyBag_QueryInterface(IShellFolder) failed! hr = %08lx\n", hr);
1060 if (FAILED(hr)) return;
1062 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1063 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08lx\n", hr);
1064 if (FAILED(hr)) {
1065 IShellFolder_Release(pShellFolder);
1066 return;
1069 result = pSHGetSpecialFolderPathW(NULL, wszDesktopPath, CSIDL_DESKTOPDIRECTORY, FALSE);
1070 ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOPDIRECTORY) failed! 0x%08lx\n", GetLastError());
1071 if (!result) return;
1073 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1074 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1076 hr = IShellFolder_QueryInterface(pShellFolder, &IID_IPersistFolder3, (LPVOID*)&pPersistFolder3);
1077 IShellFolder_Release(pShellFolder);
1078 ok(SUCCEEDED(hr), "IShellFolder_QueryInterface(IID_IPersistFolder3 failed! hr = 0x%08lx\n", hr);
1079 if (FAILED(hr)) return;
1081 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1082 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08lx\n", hr);
1083 ok(IsEqualCLSID(&clsid, &CLSID_FolderShortcut), "Unexpected CLSID!\n");
1085 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1086 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08lx\n", hr);
1087 ok(!pidlCurrentFolder, "IPersistFolder3_GetCurFolder should return a NULL pidl!\n");
1089 /* For FolderShortcut objects, the Initialize method initialized the folder's position in the
1090 * shell namespace. The target folder, read from the property bag above, remains untouched.
1091 * The following tests show this: The itemidlist for some imaginary shellfolder object
1092 * is created and the FolderShortcut is initialized with it. GetCurFolder now returns this
1093 * itemidlist, but GetDisplayNameOf still returns the path from above.
1095 hr = SHGetDesktopFolder(&pDesktopFolder);
1096 ok (SUCCEEDED(hr), "SHGetDesktopFolder failed! hr = %08lx\n", hr);
1097 if (FAILED(hr)) return;
1099 /* Temporarily register WineTestFolder as a shell namespace extension at the Desktop.
1100 * Otherwise ParseDisplayName fails on WinXP with E_INVALIDARG */
1101 RegCreateKeyW(HKEY_CURRENT_USER, wszShellExtKey, &hShellExtKey);
1102 RegCloseKey(hShellExtKey);
1103 hr = IShellFolder_ParseDisplayName(pDesktopFolder, NULL, NULL, wszWineTestFolder, NULL,
1104 &pidlWineTestFolder, NULL);
1105 RegDeleteKeyW(HKEY_CURRENT_USER, wszShellExtKey);
1106 IShellFolder_Release(pDesktopFolder);
1107 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08lx\n", hr);
1108 if (FAILED(hr)) return;
1110 hr = IPersistFolder3_Initialize(pPersistFolder3, pidlWineTestFolder);
1111 ok (SUCCEEDED(hr), "IPersistFolder3::Initialize failed! hr = %08lx\n", hr);
1112 if (FAILED(hr)) {
1113 IPersistFolder3_Release(pPersistFolder3);
1114 ILFree(pidlWineTestFolder);
1115 return;
1118 hr = IPersistFolder3_GetCurFolder(pPersistFolder3, &pidlCurrentFolder);
1119 ok(SUCCEEDED(hr), "IPersistFolder3_GetCurFolder failed! hr=0x%08lx\n", hr);
1120 ok(ILIsEqual(pidlCurrentFolder, pidlWineTestFolder),
1121 "IPersistFolder3_GetCurFolder should return pidlWineTestFolder!\n");
1122 ILFree(pidlCurrentFolder);
1123 ILFree(pidlWineTestFolder);
1125 hr = IPersistFolder3_QueryInterface(pPersistFolder3, &IID_IShellFolder, (LPVOID*)&pShellFolder);
1126 IPersistFolder3_Release(pPersistFolder3);
1127 ok(SUCCEEDED(hr), "IPersistFolder3_QueryInterface(IShellFolder) failed! hr = %08lx\n", hr);
1128 if (FAILED(hr)) return;
1130 hr = IShellFolder_GetDisplayNameOf(pShellFolder, NULL, SHGDN_FORPARSING, &strret);
1131 ok(SUCCEEDED(hr), "IShellFolder_GetDisplayNameOf(NULL) failed! hr = %08lx\n", hr);
1132 if (FAILED(hr)) {
1133 IShellFolder_Release(pShellFolder);
1134 return;
1137 pStrRetToBufW(&strret, NULL, wszBuffer, MAX_PATH);
1138 ok(!lstrcmpiW(wszDesktopPath, wszBuffer), "FolderShortcut returned incorrect folder!\n");
1140 /* Next few lines are meant to show that children of FolderShortcuts are not FolderShortcuts,
1141 * but ShellFSFolders. */
1142 PathAddBackslashW(wszDesktopPath);
1143 lstrcatW(wszDesktopPath, wszSomeSubFolder);
1144 if (!CreateDirectoryW(wszDesktopPath, NULL)) {
1145 IShellFolder_Release(pShellFolder);
1146 return;
1149 hr = IShellFolder_ParseDisplayName(pShellFolder, NULL, NULL, wszSomeSubFolder, NULL,
1150 &pidlSubFolder, NULL);
1151 RemoveDirectoryW(wszDesktopPath);
1152 ok (SUCCEEDED(hr), "IShellFolder::ParseDisplayName failed! hr = %08lx\n", hr);
1153 if (FAILED(hr)) {
1154 IShellFolder_Release(pShellFolder);
1155 return;
1158 hr = IShellFolder_BindToObject(pShellFolder, pidlSubFolder, NULL, &IID_IPersistFolder3,
1159 (LPVOID*)&pPersistFolder3);
1160 IShellFolder_Release(pShellFolder);
1161 ILFree(pidlSubFolder);
1162 ok (SUCCEEDED(hr), "IShellFolder::BindToObject failed! hr = %08lx\n", hr);
1163 if (FAILED(hr))
1164 return;
1166 /* On windows, we expect CLSID_ShellFSFolder. On wine we relax this constraint
1167 * a little bit and also allow CLSID_UnixDosFolder. */
1168 hr = IPersistFolder3_GetClassID(pPersistFolder3, &clsid);
1169 ok(SUCCEEDED(hr), "IPersistFolder3_GetClassID failed! hr=0x%08lx\n", hr);
1170 ok(IsEqualCLSID(&clsid, &CLSID_ShellFSFolder) || IsEqualCLSID(&clsid, &CLSID_UnixDosFolder),
1171 "IPersistFolder3::GetClassID returned unexpected CLSID!\n");
1173 IPersistFolder3_Release(pPersistFolder3);
1176 #include "pshpack1.h"
1177 struct FileStructA {
1178 BYTE type;
1179 BYTE dummy;
1180 DWORD dwFileSize;
1181 WORD uFileDate; /* In our current implementation this is */
1182 WORD uFileTime; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastWriteTime) */
1183 WORD uFileAttribs;
1184 CHAR szName[1];
1187 struct FileStructW {
1188 WORD cbLen; /* Length of this element. */
1189 BYTE abFooBar1[6]; /* Beyond any recognition. */
1190 WORD uDate; /* FileTimeToDosDate(WIN32_FIND_DATA->ftCreationTime)? */
1191 WORD uTime; /* (this is currently speculation) */
1192 WORD uDate2; /* FileTimeToDosDate(WIN32_FIND_DATA->ftLastAccessTime)? */
1193 WORD uTime2; /* (this is currently speculation) */
1194 BYTE abFooBar2[4]; /* Beyond any recognition. */
1195 WCHAR wszName[1]; /* The long filename in unicode. */
1196 /* Just for documentation: Right after the unicode string: */
1197 WORD cbOffset; /* FileStructW's offset from the beginning of the SHITMEID.
1198 * SHITEMID->cb == uOffset + cbLen */
1200 #include "poppack.h"
1202 void test_ITEMIDLIST_format(void) {
1203 WCHAR wszPersonal[MAX_PATH];
1204 LPSHELLFOLDER psfDesktop, psfPersonal;
1205 LPITEMIDLIST pidlPersonal, pidlFile;
1206 HANDLE hFile;
1207 HRESULT hr;
1208 BOOL bResult;
1209 WCHAR wszFile[3][17] = { { 'e','v','e','n','_',0 }, { 'o','d','d','_',0 },
1210 { 'l','o','n','g','e','r','_','t','h','a','n','.','8','_','3',0 } };
1211 int i;
1213 if(!pSHGetSpecialFolderPathW) return;
1215 bResult = pSHGetSpecialFolderPathW(NULL, wszPersonal, CSIDL_PERSONAL, FALSE);
1216 ok(bResult, "SHGetSpecialFolderPathW failed! Last error: %08lx\n", GetLastError());
1217 if (!bResult) return;
1219 bResult = SetCurrentDirectoryW(wszPersonal);
1220 ok(bResult, "SetCurrentDirectory failed! Last error: %ld\n", GetLastError());
1221 if (!bResult) return;
1223 hr = SHGetDesktopFolder(&psfDesktop);
1224 ok(SUCCEEDED(hr), "SHGetDesktopFolder failed! hr: %08lx\n", hr);
1225 if (FAILED(hr)) return;
1227 hr = IShellFolder_ParseDisplayName(psfDesktop, NULL, NULL, wszPersonal, NULL, &pidlPersonal, NULL);
1228 ok(SUCCEEDED(hr), "psfDesktop->ParseDisplayName failed! hr = %08lx\n", hr);
1229 if (FAILED(hr)) {
1230 IShellFolder_Release(psfDesktop);
1231 return;
1234 hr = IShellFolder_BindToObject(psfDesktop, pidlPersonal, NULL, &IID_IShellFolder,
1235 (LPVOID*)&psfPersonal);
1236 IShellFolder_Release(psfDesktop);
1237 ILFree(pidlPersonal);
1238 ok(SUCCEEDED(hr), "psfDesktop->BindToObject failed! hr = %08lx\n", hr);
1239 if (FAILED(hr)) return;
1241 for (i=0; i<3; i++) {
1242 CHAR szFile[MAX_PATH];
1243 struct FileStructA *pFileStructA;
1244 WORD cbOffset;
1246 WideCharToMultiByte(CP_ACP, 0, wszFile[i], -1, szFile, MAX_PATH, NULL, NULL);
1248 hFile = CreateFileW(wszFile[i], GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_FLAG_WRITE_THROUGH, NULL);
1249 ok(hFile != INVALID_HANDLE_VALUE, "CreateFile failed! (%ld)\n", GetLastError());
1250 if (hFile == INVALID_HANDLE_VALUE) {
1251 IShellFolder_Release(psfPersonal);
1252 return;
1254 CloseHandle(hFile);
1256 hr = IShellFolder_ParseDisplayName(psfPersonal, NULL, NULL, wszFile[i], NULL, &pidlFile, NULL);
1257 DeleteFileW(wszFile[i]);
1258 ok(SUCCEEDED(hr), "psfPersonal->ParseDisplayName failed! hr: %08lx\n", hr);
1259 if (FAILED(hr)) {
1260 IShellFolder_Release(psfPersonal);
1261 return;
1264 pFileStructA = (struct FileStructA *)pidlFile->mkid.abID;
1265 ok(pFileStructA->type == 0x32, "PIDLTYPE should be 0x32!\n");
1266 ok(pFileStructA->dummy == 0x00, "Dummy Byte should be 0x00!\n");
1267 ok(pFileStructA->dwFileSize == 0, "Filesize should be zero!\n");
1269 if (i < 2) /* First two file names are already in valid 8.3 format */
1270 ok(!strcmp(szFile, (CHAR*)&pidlFile->mkid.abID[12]), "Wrong file name!\n");
1271 else
1272 /* WinXP stores a derived 8.3 dos name (LONGER~1.8_3) here. We probably
1273 * can't implement this correctly, since unix filesystems don't support
1274 * this nasty short/long filename stuff. So we'll probably stay with our
1275 * current habbit of storing the long filename here, which seems to work
1276 * just fine. */
1277 todo_wine { ok(pidlFile->mkid.abID[18] == '~', "Should be derived 8.3 name!\n"); }
1279 if (i == 0) /* First file name has an even number of chars. No need for alignment. */
1280 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] != '\0',
1281 "Alignment byte, where there shouldn't be!\n");
1283 if (i == 1) /* Second file name has an uneven number of chars => alignment byte */
1284 ok(pidlFile->mkid.abID[12 + strlen(szFile) + 1] == '\0',
1285 "There should be an alignment byte, but isn't!\n");
1287 /* The offset of the FileStructW member is stored as a WORD at the end of the pidl. */
1288 cbOffset = *(WORD*)(((LPBYTE)pidlFile)+pidlFile->mkid.cb-sizeof(WORD));
1289 ok (cbOffset >= sizeof(struct FileStructA) &&
1290 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW),
1291 "Wrong offset value (%d) stored at the end of the PIDL\n", cbOffset);
1293 if (cbOffset >= sizeof(struct FileStructA) &&
1294 cbOffset <= pidlFile->mkid.cb - sizeof(struct FileStructW))
1296 struct FileStructW *pFileStructW = (struct FileStructW *)(((LPBYTE)pidlFile)+cbOffset);
1298 ok(pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen,
1299 "FileStructW's offset and length should add up to the PIDL's length!\n");
1301 if (pidlFile->mkid.cb == cbOffset + pFileStructW->cbLen) {
1302 /* Since we just created the file, time of creation,
1303 * time of last access and time of last write access just be the same.
1304 * These tests seem to fail sometimes (on WinXP), if the test is run again shortly
1305 * after the first run. I do remember something with NTFS keeping the creation time
1306 * if a file is deleted and then created again within a couple of seconds or so.
1307 * Might be the reason. */
1308 ok (pFileStructA->uFileDate == pFileStructW->uDate &&
1309 pFileStructA->uFileTime == pFileStructW->uTime,
1310 "Last write time should match creation time!\n");
1312 ok (pFileStructA->uFileDate == pFileStructW->uDate2 &&
1313 pFileStructA->uFileTime == pFileStructW->uTime2,
1314 "Last write time should match last access time!\n");
1316 ok (!lstrcmpW(wszFile[i], pFileStructW->wszName),
1317 "The filename should be stored in unicode at this position!\n");
1321 ILFree(pidlFile);
1325 START_TEST(shlfolder)
1327 init_function_pointers();
1328 /* if OleInitialize doesn't get called, ParseDisplayName returns
1329 CO_E_NOTINITIALIZED for malformed directory names on win2k. */
1330 OleInitialize(NULL);
1332 test_ParseDisplayName();
1333 test_BindToObject();
1334 test_EnumObjects_and_CompareIDs();
1335 test_GetDisplayName();
1336 test_GetAttributesOf();
1337 test_SHGetPathFromIDList();
1338 test_CallForAttributes();
1339 test_FolderShortcut();
1340 test_ITEMIDLIST_format();
1342 OleUninitialize();