netstat: Initial implementation.
[wine] / dlls / shell32 / shellord.c
1 /*
2  * The parameters of many functions changes between different OS versions
3  * (NT uses Unicode strings, 95 uses ASCII strings)
4  *
5  * Copyright 1997 Marcus Meissner
6  *           1998 Jürgen Schmied
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21  */
22 #include "config.h"
23
24 #include <string.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27
28 #define COBJMACROS
29
30 #include "winerror.h"
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winreg.h"
34 #include "wine/debug.h"
35 #include "winnls.h"
36 #include "winternl.h"
37
38 #include "shellapi.h"
39 #include "objbase.h"
40 #include "shlguid.h"
41 #include "wingdi.h"
42 #include "winuser.h"
43 #include "shlobj.h"
44 #include "shell32_main.h"
45 #include "undocshell.h"
46 #include "pidl.h"
47 #include "shlwapi.h"
48 #include "commdlg.h"
49 #include "commoncontrols.h"
50
51 WINE_DEFAULT_DEBUG_CHANNEL(shell);
52 WINE_DECLARE_DEBUG_CHANNEL(pidl);
53
54 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
55 /*        !!! it is in both here and comctl32undoc.c      !!! */
56 typedef struct tagCREATEMRULIST
57 {
58     DWORD  cbSize;        /* size of struct */
59     DWORD  nMaxItems;     /* max no. of items in list */
60     DWORD  dwFlags;       /* see below */
61     HKEY   hKey;          /* root reg. key under which list is saved */
62     LPCSTR lpszSubKey;    /* reg. subkey */
63     int (CALLBACK *lpfnCompare)(LPCVOID, LPCVOID, DWORD); /* item compare proc */
64 } CREATEMRULISTA, *LPCREATEMRULISTA;
65
66 /* dwFlags */
67 #define MRUF_STRING_LIST  0 /* list will contain strings */
68 #define MRUF_BINARY_LIST  1 /* list will contain binary data */
69 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
70
71 extern HANDLE WINAPI CreateMRUListA(LPCREATEMRULISTA lpcml);
72 extern DWORD  WINAPI FreeMRUList(HANDLE hMRUList);
73 extern INT    WINAPI AddMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData);
74 extern INT    WINAPI FindMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
75 extern INT    WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
76
77
78 /* Get a function pointer from a DLL handle */
79 #define GET_FUNC(func, module, name, fail) \
80   do { \
81     if (!func) { \
82       if (!SHELL32_h##module && !(SHELL32_h##module = LoadLibraryA(#module ".dll"))) return fail; \
83       func = (void*)GetProcAddress(SHELL32_h##module, name); \
84       if (!func) return fail; \
85     } \
86   } while (0)
87
88 /* Function pointers for GET_FUNC macro */
89 static HMODULE SHELL32_hshlwapi=NULL;
90 static HANDLE (WINAPI *pSHAllocShared)(LPCVOID,DWORD,DWORD);
91 static LPVOID (WINAPI *pSHLockShared)(HANDLE,DWORD);
92 static BOOL   (WINAPI *pSHUnlockShared)(LPVOID);
93 static BOOL   (WINAPI *pSHFreeShared)(HANDLE,DWORD);
94
95
96 /*************************************************************************
97  * ParseFieldA                                  [internal]
98  *
99  * copies a field from a ',' delimited string
100  *
101  * first field is nField = 1
102  */
103 DWORD WINAPI ParseFieldA(
104         LPCSTR src,
105         DWORD nField,
106         LPSTR dst,
107         DWORD len)
108 {
109         WARN("(%s,0x%08x,%p,%d) semi-stub.\n",debugstr_a(src),nField,dst,len);
110
111         if (!src || !src[0] || !dst || !len)
112           return 0;
113
114         /* skip n fields delimited by ',' */
115         while (nField > 1)
116         {
117           if (*src=='\0') return FALSE;
118           if (*(src++)==',') nField--;
119         }
120
121         /* copy part till the next ',' to dst */
122         while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
123
124         /* finalize the string */
125         *dst=0x0;
126
127         return TRUE;
128 }
129
130 /*************************************************************************
131  * ParseFieldW                  [internal]
132  *
133  * copies a field from a ',' delimited string
134  *
135  * first field is nField = 1
136  */
137 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
138 {
139         WARN("(%s,0x%08x,%p,%d) semi-stub.\n", debugstr_w(src), nField, dst, len);
140
141         if (!src || !src[0] || !dst || !len)
142           return 0;
143
144         /* skip n fields delimited by ',' */
145         while (nField > 1)
146         {
147           if (*src == 0x0) return FALSE;
148           if (*src++ == ',') nField--;
149         }
150
151         /* copy part till the next ',' to dst */
152         while ( *src != 0x0 && *src != ',' && (len--)>0 ) *(dst++) = *(src++);
153
154         /* finalize the string */
155         *dst = 0x0;
156
157         return TRUE;
158 }
159
160 /*************************************************************************
161  * ParseField                   [SHELL32.58]
162  */
163 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
164 {
165         if (SHELL_OsIsUnicode())
166           return ParseFieldW(src, nField, dst, len);
167         return ParseFieldA(src, nField, dst, len);
168 }
169
170 /*************************************************************************
171  * GetFileNameFromBrowseA                       [internal]
172  */
173 static BOOL GetFileNameFromBrowseA(
174         HWND hwndOwner,
175         LPSTR lpstrFile,
176         DWORD nMaxFile,
177         LPCSTR lpstrInitialDir,
178         LPCSTR lpstrDefExt,
179         LPCSTR lpstrFilter,
180         LPCSTR lpstrTitle)
181 {
182     HMODULE hmodule;
183     BOOL (WINAPI *pGetOpenFileNameA)(LPOPENFILENAMEA);
184     OPENFILENAMEA ofn;
185     BOOL ret;
186
187     TRACE("%p, %s, %d, %s, %s, %s, %s)\n",
188           hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
189           lpstrFilter, lpstrTitle);
190
191     hmodule = LoadLibraryA("comdlg32.dll");
192     if(!hmodule) return FALSE;
193     pGetOpenFileNameA = (void *)GetProcAddress(hmodule, "GetOpenFileNameA");
194     if(!pGetOpenFileNameA)
195     {
196         FreeLibrary(hmodule);
197         return FALSE;
198     }
199
200     memset(&ofn, 0, sizeof(ofn));
201
202     ofn.lStructSize = sizeof(ofn);
203     ofn.hwndOwner = hwndOwner;
204     ofn.lpstrFilter = lpstrFilter;
205     ofn.lpstrFile = lpstrFile;
206     ofn.nMaxFile = nMaxFile;
207     ofn.lpstrInitialDir = lpstrInitialDir;
208     ofn.lpstrTitle = lpstrTitle;
209     ofn.lpstrDefExt = lpstrDefExt;
210     ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
211     ret = pGetOpenFileNameA(&ofn);
212
213     FreeLibrary(hmodule);
214     return ret;
215 }
216
217 /*************************************************************************
218  * GetFileNameFromBrowseW                       [internal]
219  */
220 static BOOL GetFileNameFromBrowseW(
221         HWND hwndOwner,
222         LPWSTR lpstrFile,
223         DWORD nMaxFile,
224         LPCWSTR lpstrInitialDir,
225         LPCWSTR lpstrDefExt,
226         LPCWSTR lpstrFilter,
227         LPCWSTR lpstrTitle)
228 {
229     HMODULE hmodule;
230     BOOL (WINAPI *pGetOpenFileNameW)(LPOPENFILENAMEW);
231     OPENFILENAMEW ofn;
232     BOOL ret;
233
234     TRACE("%p, %s, %d, %s, %s, %s, %s)\n",
235           hwndOwner, debugstr_w(lpstrFile), nMaxFile, debugstr_w(lpstrInitialDir), debugstr_w(lpstrDefExt),
236           debugstr_w(lpstrFilter), debugstr_w(lpstrTitle));
237
238     hmodule = LoadLibraryA("comdlg32.dll");
239     if(!hmodule) return FALSE;
240     pGetOpenFileNameW = (void *)GetProcAddress(hmodule, "GetOpenFileNameW");
241     if(!pGetOpenFileNameW)
242     {
243         FreeLibrary(hmodule);
244         return FALSE;
245     }
246
247     memset(&ofn, 0, sizeof(ofn));
248
249     ofn.lStructSize = sizeof(ofn);
250     ofn.hwndOwner = hwndOwner;
251     ofn.lpstrFilter = lpstrFilter;
252     ofn.lpstrFile = lpstrFile;
253     ofn.nMaxFile = nMaxFile;
254     ofn.lpstrInitialDir = lpstrInitialDir;
255     ofn.lpstrTitle = lpstrTitle;
256     ofn.lpstrDefExt = lpstrDefExt;
257     ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
258     ret = pGetOpenFileNameW(&ofn);
259
260     FreeLibrary(hmodule);
261     return ret;
262 }
263
264 /*************************************************************************
265  * GetFileNameFromBrowse                        [SHELL32.63]
266  *
267  */
268 BOOL WINAPI GetFileNameFromBrowseAW(
269         HWND hwndOwner,
270         LPVOID lpstrFile,
271         DWORD nMaxFile,
272         LPCVOID lpstrInitialDir,
273         LPCVOID lpstrDefExt,
274         LPCVOID lpstrFilter,
275         LPCVOID lpstrTitle)
276 {
277     if (SHELL_OsIsUnicode())
278         return GetFileNameFromBrowseW(hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt, lpstrFilter, lpstrTitle);
279
280     return GetFileNameFromBrowseA(hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt, lpstrFilter, lpstrTitle);
281 }
282
283 /*************************************************************************
284  * SHGetSetSettings                             [SHELL32.68]
285  */
286 VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
287 {
288   if(bSet)
289   {
290     FIXME("%p 0x%08x TRUE\n", lpss, dwMask);
291   }
292   else
293   {
294     SHGetSettings((LPSHELLFLAGSTATE)lpss,dwMask);
295   }
296 }
297
298 /*************************************************************************
299  * SHGetSettings                                [SHELL32.@]
300  *
301  * NOTES
302  *  the registry path are for win98 (tested)
303  *  and possibly are the same in nt40
304  *
305  */
306 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
307 {
308         HKEY    hKey;
309         DWORD   dwData;
310         DWORD   dwDataSize = sizeof (DWORD);
311
312         TRACE("(%p 0x%08x)\n",lpsfs,dwMask);
313
314         if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
315                                  0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
316           return;
317
318         if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
319           lpsfs->fShowExtensions  = ((dwData == 0) ?  0 : 1);
320
321         if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
322           lpsfs->fShowInfoTip  = ((dwData == 0) ?  0 : 1);
323
324         if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
325           lpsfs->fDontPrettyPath  = ((dwData == 0) ?  0 : 1);
326
327         if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
328           lpsfs->fHideIcons  = ((dwData == 0) ?  0 : 1);
329
330         if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
331           lpsfs->fMapNetDrvBtn  = ((dwData == 0) ?  0 : 1);
332
333         if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
334           lpsfs->fShowAttribCol  = ((dwData == 0) ?  0 : 1);
335
336         if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
337         { if (dwData == 0)
338           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 0;
339             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 0;
340           }
341           else if (dwData == 1)
342           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 1;
343             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 0;
344           }
345           else if (dwData == 2)
346           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 0;
347             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 1;
348           }
349         }
350         RegCloseKey (hKey);
351
352         TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
353 }
354
355 /*************************************************************************
356  * SHShellFolderView_Message                    [SHELL32.73]
357  *
358  * Send a message to an explorer cabinet window.
359  *
360  * PARAMS
361  *  hwndCabinet [I] The window containing the shellview to communicate with
362  *  dwMessage   [I] The SFVM message to send
363  *  dwParam     [I] Message parameter
364  *
365  * RETURNS
366  *  fixme.
367  *
368  * NOTES
369  *  Message SFVM_REARRANGE = 1
370  *
371  *    This message gets sent when a column gets clicked to instruct the
372  *    shell view to re-sort the item list. dwParam identifies the column
373  *    that was clicked.
374  */
375 LRESULT WINAPI SHShellFolderView_Message(
376         HWND hwndCabinet,
377         UINT uMessage,
378         LPARAM lParam)
379 {
380         FIXME("%p %08x %08lx stub\n",hwndCabinet, uMessage, lParam);
381         return 0;
382 }
383
384 /*************************************************************************
385  * RegisterShellHook                            [SHELL32.181]
386  *
387  * Register a shell hook.
388  *
389  * PARAMS
390  *      hwnd   [I]  Window handle
391  *      dwType [I]  Type of hook.
392  *
393  * NOTES
394  *     Exported by ordinal
395  */
396 BOOL WINAPI RegisterShellHook(
397         HWND hWnd,
398         DWORD dwType)
399 {
400         FIXME("(%p,0x%08x):stub.\n",hWnd, dwType);
401         return TRUE;
402 }
403
404 /*************************************************************************
405  * ShellMessageBoxW                             [SHELL32.182]
406  *
407  * See ShellMessageBoxA.
408  *
409  * NOTE:
410  * shlwapi.ShellMessageBoxWrapW is a duplicate of shell32.ShellMessageBoxW
411  * because we can't forward to it in the .spec file since it's exported by
412  * ordinal. If you change the implementation here please update the code in
413  * shlwapi as well.
414  */
415 int WINAPIV ShellMessageBoxW(
416         HINSTANCE hInstance,
417         HWND hWnd,
418         LPCWSTR lpText,
419         LPCWSTR lpCaption,
420         UINT uType,
421         ...)
422 {
423         WCHAR   szText[100],szTitle[100];
424         LPCWSTR pszText = szText, pszTitle = szTitle;
425         LPWSTR  pszTemp;
426         __ms_va_list args;
427         int     ret;
428
429         __ms_va_start(args, uType);
430         /* wvsprintfA(buf,fmt, args); */
431
432         TRACE("(%p,%p,%p,%p,%08x)\n",
433             hInstance,hWnd,lpText,lpCaption,uType);
434
435         if (IS_INTRESOURCE(lpCaption))
436           LoadStringW(hInstance, LOWORD(lpCaption), szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
437         else
438           pszTitle = lpCaption;
439
440         if (IS_INTRESOURCE(lpText))
441           LoadStringW(hInstance, LOWORD(lpText), szText, sizeof(szText)/sizeof(szText[0]));
442         else
443           pszText = lpText;
444
445         FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
446                        pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
447
448         __ms_va_end(args);
449
450         ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
451         LocalFree(pszTemp);
452         return ret;
453 }
454
455 /*************************************************************************
456  * ShellMessageBoxA                             [SHELL32.183]
457  *
458  * Format and output an error message.
459  *
460  * PARAMS
461  *  hInstance [I] Instance handle of message creator
462  *  hWnd      [I] Window handle of message creator
463  *  lpText    [I] Resource Id of title or LPSTR
464  *  lpCaption [I] Resource Id of title or LPSTR
465  *  uType     [I] Type of error message
466  *
467  * RETURNS
468  *  A return value from MessageBoxA().
469  *
470  * NOTES
471  *     Exported by ordinal
472  */
473 int WINAPIV ShellMessageBoxA(
474         HINSTANCE hInstance,
475         HWND hWnd,
476         LPCSTR lpText,
477         LPCSTR lpCaption,
478         UINT uType,
479         ...)
480 {
481         char    szText[100],szTitle[100];
482         LPCSTR  pszText = szText, pszTitle = szTitle;
483         LPSTR   pszTemp;
484         __ms_va_list args;
485         int     ret;
486
487         __ms_va_start(args, uType);
488         /* wvsprintfA(buf,fmt, args); */
489
490         TRACE("(%p,%p,%p,%p,%08x)\n",
491             hInstance,hWnd,lpText,lpCaption,uType);
492
493         if (IS_INTRESOURCE(lpCaption))
494           LoadStringA(hInstance, LOWORD(lpCaption), szTitle, sizeof(szTitle));
495         else
496           pszTitle = lpCaption;
497
498         if (IS_INTRESOURCE(lpText))
499           LoadStringA(hInstance, LOWORD(lpText), szText, sizeof(szText));
500         else
501           pszText = lpText;
502
503         FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
504                        pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
505
506         __ms_va_end(args);
507
508         ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
509         LocalFree(pszTemp);
510         return ret;
511 }
512
513 /*************************************************************************
514  * SHRegisterDragDrop                           [SHELL32.86]
515  *
516  * Probably equivalent to RegisterDragDrop but under Windows 95 it could use the
517  * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
518  * for details. Under Windows 98 this function initializes the true OLE when called
519  * the first time, on XP always returns E_OUTOFMEMORY and it got removed from Vista.
520  *
521  * We follow Windows 98 behaviour.
522  *
523  * NOTES
524  *     exported by ordinal
525  *
526  * SEE ALSO
527  *     RegisterDragDrop, SHLoadOLE
528  */
529 HRESULT WINAPI SHRegisterDragDrop(
530         HWND hWnd,
531         LPDROPTARGET pDropTarget)
532 {
533         static BOOL ole_initialized = FALSE;
534         HRESULT hr;
535
536         TRACE("(%p,%p)\n", hWnd, pDropTarget);
537
538         if (!ole_initialized)
539         {
540             hr = OleInitialize(NULL);
541             if (FAILED(hr))
542                 return hr;
543             ole_initialized = TRUE;
544         }
545         return RegisterDragDrop(hWnd, pDropTarget);
546 }
547
548 /*************************************************************************
549  * SHRevokeDragDrop                             [SHELL32.87]
550  *
551  * Probably equivalent to RevokeDragDrop but under Windows 95 it could use the
552  * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
553  * for details. Function removed from Windows Vista.
554  *
555  * We call ole32 RevokeDragDrop which seems to work even if OleInitialize was
556  * not called.
557  *
558  * NOTES
559  *     exported by ordinal
560  *
561  * SEE ALSO
562  *     RevokeDragDrop, SHLoadOLE
563  */
564 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
565 {
566     TRACE("(%p)\n", hWnd);
567     return RevokeDragDrop(hWnd);
568 }
569
570 /*************************************************************************
571  * SHDoDragDrop                                 [SHELL32.88]
572  *
573  * Probably equivalent to DoDragDrop but under Windows 9x it could use the
574  * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
575  * for details
576  *
577  * NOTES
578  *     exported by ordinal
579  *
580  * SEE ALSO
581  *     DoDragDrop, SHLoadOLE
582  */
583 HRESULT WINAPI SHDoDragDrop(
584         HWND hWnd,
585         LPDATAOBJECT lpDataObject,
586         LPDROPSOURCE lpDropSource,
587         DWORD dwOKEffect,
588         LPDWORD pdwEffect)
589 {
590     FIXME("(%p %p %p 0x%08x %p):stub.\n",
591     hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
592         return DoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
593 }
594
595 /*************************************************************************
596  * ArrangeWindows                               [SHELL32.184]
597  *
598  */
599 WORD WINAPI ArrangeWindows(
600         HWND hwndParent,
601         DWORD dwReserved,
602         LPCRECT lpRect,
603         WORD cKids,
604         CONST HWND * lpKids)
605 {
606     FIXME("(%p 0x%08x %p 0x%04x %p):stub.\n",
607            hwndParent, dwReserved, lpRect, cKids, lpKids);
608     return 0;
609 }
610
611 /*************************************************************************
612  * SignalFileOpen                               [SHELL32.103]
613  *
614  * NOTES
615  *     exported by ordinal
616  */
617 BOOL WINAPI
618 SignalFileOpen (PCIDLIST_ABSOLUTE pidl)
619 {
620     FIXME("(%p):stub.\n", pidl);
621
622     return FALSE;
623 }
624
625 /*************************************************************************
626  * SHADD_get_policy - helper function for SHAddToRecentDocs
627  *
628  * PARAMETERS
629  *   policy    [IN]  policy name (null termed string) to find
630  *   type      [OUT] ptr to DWORD to receive type
631  *   buffer    [OUT] ptr to area to hold data retrieved
632  *   len       [IN/OUT] ptr to DWORD holding size of buffer and getting
633  *                      length filled
634  *
635  * RETURNS
636  *   result of the SHQueryValueEx call
637  */
638 static INT SHADD_get_policy(LPCSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
639 {
640     HKEY Policy_basekey;
641     INT ret;
642
643     /* Get the key for the policies location in the registry
644      */
645     if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
646                       "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
647                       0, KEY_READ, &Policy_basekey)) {
648
649         if (RegOpenKeyExA(HKEY_CURRENT_USER,
650                           "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
651                           0, KEY_READ, &Policy_basekey)) {
652             TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
653                   policy);
654             *len = 0;
655             return ERROR_FILE_NOT_FOUND;
656         }
657     }
658
659     /* Retrieve the data if it exists
660      */
661     ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
662     RegCloseKey(Policy_basekey);
663     return ret;
664 }
665
666
667 /*************************************************************************
668  * SHADD_compare_mru - helper function for SHAddToRecentDocs
669  *
670  * PARAMETERS
671  *   data1     [IN] data being looked for
672  *   data2     [IN] data in MRU
673  *   cbdata    [IN] length from FindMRUData call (not used)
674  *
675  * RETURNS
676  *   position within MRU list that data was added.
677  */
678 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
679 {
680     return lstrcmpiA(data1, data2);
681 }
682
683 /*************************************************************************
684  * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
685  *
686  * PARAMETERS
687  *   mruhandle    [IN] handle for created MRU list
688  *   doc_name     [IN] null termed pure doc name
689  *   new_lnk_name [IN] null termed path and file name for .lnk file
690  *   buffer       [IN/OUT] 2048 byte area to construct MRU data
691  *   len          [OUT] ptr to int to receive space used in buffer
692  *
693  * RETURNS
694  *   position within MRU list that data was added.
695  */
696 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPCSTR doc_name, LPCSTR new_lnk_name,
697                                      LPSTR buffer, INT *len)
698 {
699     LPSTR ptr;
700     INT wlen;
701
702     /*FIXME: Document:
703      *  RecentDocs MRU data structure seems to be:
704      *    +0h   document file name w/ terminating 0h
705      *    +nh   short int w/ size of remaining
706      *    +n+2h 02h 30h, or 01h 30h, or 00h 30h  -  unknown
707      *    +n+4h 10 bytes zeros  -   unknown
708      *    +n+eh shortcut file name w/ terminating 0h
709      *    +n+e+nh 3 zero bytes  -  unknown
710      */
711
712     /* Create the MRU data structure for "RecentDocs"
713          */
714     ptr = buffer;
715     lstrcpyA(ptr, doc_name);
716     ptr += (lstrlenA(buffer) + 1);
717     wlen= lstrlenA(new_lnk_name) + 1 + 12;
718     *((short int*)ptr) = wlen;
719     ptr += 2;   /* step past the length */
720     *(ptr++) = 0x30;  /* unknown reason */
721     *(ptr++) = 0;     /* unknown, but can be 0x00, 0x01, 0x02 */
722     memset(ptr, 0, 10);
723     ptr += 10;
724     lstrcpyA(ptr, new_lnk_name);
725     ptr += (lstrlenA(new_lnk_name) + 1);
726     memset(ptr, 0, 3);
727     ptr += 3;
728     *len = ptr - buffer;
729
730     /* Add the new entry into the MRU list
731      */
732     return AddMRUData(mruhandle, buffer, *len);
733 }
734
735 /*************************************************************************
736  * SHAddToRecentDocs                            [SHELL32.@]
737  *
738  * Modify (add/clear) Shell's list of recently used documents.
739  *
740  * PARAMETERS
741  *   uFlags  [IN] SHARD_PATHA, SHARD_PATHW or SHARD_PIDL
742  *   pv      [IN] string or pidl, NULL clears the list
743  *
744  * NOTES
745  *     exported by name
746  *
747  * FIXME
748  *  convert to unicode
749  */
750 void WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
751 {
752 /* If list is a string list lpfnCompare has the following prototype
753  * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
754  * for binary lists the prototype is
755  * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
756  * where cbData is the no. of bytes to compare.
757  * Need to check what return value means identical - 0?
758  */
759
760
761     UINT olderrormode;
762     HKEY HCUbasekey;
763     CHAR doc_name[MAX_PATH];
764     CHAR link_dir[MAX_PATH];
765     CHAR new_lnk_filepath[MAX_PATH];
766     CHAR new_lnk_name[MAX_PATH];
767     IMalloc *ppM;
768     LPITEMIDLIST pidl;
769     HWND hwnd = 0;       /* FIXME:  get real window handle */
770     INT ret;
771     DWORD data[64], datalen, type;
772
773     TRACE("%04x %p\n", uFlags, pv);
774
775     /*FIXME: Document:
776      *  RecentDocs MRU data structure seems to be:
777      *    +0h   document file name w/ terminating 0h
778      *    +nh   short int w/ size of remaining
779      *    +n+2h 02h 30h, or 01h 30h, or 00h 30h  -  unknown
780      *    +n+4h 10 bytes zeros  -   unknown
781      *    +n+eh shortcut file name w/ terminating 0h
782      *    +n+e+nh 3 zero bytes  -  unknown
783      */
784
785     /* See if we need to do anything.
786      */
787     datalen = 64;
788     ret=SHADD_get_policy( "NoRecentDocsHistory", &type, data, &datalen);
789     if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
790         ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
791         return;
792     }
793     if (ret == ERROR_SUCCESS) {
794         if (!( (type == REG_DWORD) ||
795                ((type == REG_BINARY) && (datalen == 4)) )) {
796             ERR("Error policy data for \"NoRecentDocsHistory\" not formatted correctly, type=%d, len=%d\n",
797                 type, datalen);
798             return;
799         }
800
801         TRACE("policy value for NoRecentDocsHistory = %08x\n", data[0]);
802         /* now test the actual policy value */
803         if ( data[0] != 0)
804             return;
805     }
806
807     /* Open key to where the necessary info is
808      */
809     /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
810      *        and the close should be done during the _DETACH. The resulting
811      *        key is stored in the DLL global data.
812      */
813     if (RegCreateKeyExA(HKEY_CURRENT_USER,
814                         "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
815                         0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
816         ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
817         return;
818     }
819
820     /* Get path to user's "Recent" directory
821      */
822     if(SUCCEEDED(SHGetMalloc(&ppM))) {
823         if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
824                                                  &pidl))) {
825             SHGetPathFromIDListA(pidl, link_dir);
826             IMalloc_Free(ppM, pidl);
827         }
828         else {
829             /* serious issues */
830             link_dir[0] = 0;
831             ERR("serious issues 1\n");
832         }
833         IMalloc_Release(ppM);
834     }
835     else {
836         /* serious issues */
837         link_dir[0] = 0;
838         ERR("serious issues 2\n");
839     }
840     TRACE("Users Recent dir %s\n", link_dir);
841
842     /* If no input, then go clear the lists */
843     if (!pv) {
844         /* clear user's Recent dir
845          */
846
847         /* FIXME: delete all files in "link_dir"
848          *
849          * while( more files ) {
850          *    lstrcpyA(old_lnk_name, link_dir);
851          *    PathAppendA(old_lnk_name, filenam);
852          *    DeleteFileA(old_lnk_name);
853          * }
854          */
855         FIXME("should delete all files in %s\\\n", link_dir);
856
857         /* clear MRU list
858          */
859         /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
860          *  HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
861          *  and naturally it fails w/ rc=2. It should do it against
862          *  HKEY_CURRENT_USER which is where it is stored, and where
863          *  the MRU routines expect it!!!!
864          */
865         RegDeleteKeyA(HCUbasekey, "RecentDocs");
866         RegCloseKey(HCUbasekey);
867         return;
868     }
869
870     /* Have data to add, the jobs to be done:
871      *   1. Add document to MRU list in registry "HKCU\Software\
872      *      Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
873      *   2. Add shortcut to document in the user's Recent directory
874      *      (CSIDL_RECENT).
875      *   3. Add shortcut to Start menu's Documents submenu.
876      */
877
878     /* Get the pure document name from the input
879      */
880     switch (uFlags)
881     {
882     case SHARD_PIDL:
883         SHGetPathFromIDListA(pv, doc_name);
884         break;
885
886     case SHARD_PATHA:
887         lstrcpynA(doc_name, pv, MAX_PATH);
888         break;
889
890     case SHARD_PATHW:
891         WideCharToMultiByte(CP_ACP, 0, pv, -1, doc_name, MAX_PATH, NULL, NULL);
892         break;
893
894     default:
895         FIXME("Unsupported flags: %u\n", uFlags);
896         return;
897     }
898
899     TRACE("full document name %s\n", debugstr_a(doc_name));
900     PathStripPathA(doc_name);
901     TRACE("stripped document name %s\n", debugstr_a(doc_name));
902
903
904     /* ***  JOB 1: Update registry for ...\Explorer\RecentDocs list  *** */
905
906     {  /* on input needs:
907         *      doc_name    -  pure file-spec, no path
908         *      link_dir    -  path to the user's Recent directory
909         *      HCUbasekey  -  key of ...Windows\CurrentVersion\Explorer" node
910         * creates:
911         *      new_lnk_name-  pure file-spec, no path for new .lnk file
912         *      new_lnk_filepath
913         *                  -  path and file name of new .lnk file
914         */
915         CREATEMRULISTA mymru;
916         HANDLE mruhandle;
917         INT len, pos, bufused, err;
918         INT i;
919         DWORD attr;
920         CHAR buffer[2048];
921         CHAR *ptr;
922         CHAR old_lnk_name[MAX_PATH];
923         short int slen;
924
925         mymru.cbSize = sizeof(CREATEMRULISTA);
926         mymru.nMaxItems = 15;
927         mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
928         mymru.hKey = HCUbasekey;
929         mymru.lpszSubKey = "RecentDocs";
930         mymru.lpfnCompare = SHADD_compare_mru;
931         mruhandle = CreateMRUListA(&mymru);
932         if (!mruhandle) {
933             /* MRU failed */
934             ERR("MRU processing failed, handle zero\n");
935             RegCloseKey(HCUbasekey);
936             return;
937         }
938         len = lstrlenA(doc_name);
939         pos = FindMRUData(mruhandle, doc_name, len, 0);
940
941         /* Now get the MRU entry that will be replaced
942          * and delete the .lnk file for it
943          */
944         if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
945                                     buffer, 2048)) != -1) {
946             ptr = buffer;
947             ptr += (lstrlenA(buffer) + 1);
948             slen = *((short int*)ptr);
949             ptr += 2;  /* skip the length area */
950             if (bufused >= slen + (ptr-buffer)) {
951                 /* buffer size looks good */
952                 ptr += 12; /* get to string */
953                 len = bufused - (ptr-buffer);  /* get length of buf remaining */
954                 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
955                     /* appears to be good string */
956                     lstrcpyA(old_lnk_name, link_dir);
957                     PathAppendA(old_lnk_name, ptr);
958                     if (!DeleteFileA(old_lnk_name)) {
959                         if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) {
960                             if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
961                                 ERR("Delete for %s failed, err=%d, attr=%08x\n",
962                                     old_lnk_name, err, attr);
963                             }
964                             else {
965                                 TRACE("old .lnk file %s did not exist\n",
966                                       old_lnk_name);
967                             }
968                         }
969                         else {
970                             ERR("Delete for %s failed, attr=%08x\n",
971                                 old_lnk_name, attr);
972                         }
973                     }
974                     else {
975                         TRACE("deleted old .lnk file %s\n", old_lnk_name);
976                     }
977                 }
978             }
979         }
980
981         /* Create usable .lnk file name for the "Recent" directory
982          */
983         wsprintfA(new_lnk_name, "%s.lnk", doc_name);
984         lstrcpyA(new_lnk_filepath, link_dir);
985         PathAppendA(new_lnk_filepath, new_lnk_name);
986         i = 1;
987         olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
988         while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
989             i++;
990             wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
991             lstrcpyA(new_lnk_filepath, link_dir);
992             PathAppendA(new_lnk_filepath, new_lnk_name);
993         }
994         SetErrorMode(olderrormode);
995         TRACE("new shortcut will be %s\n", new_lnk_filepath);
996
997         /* Now add the new MRU entry and data
998          */
999         pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
1000                                         buffer, &len);
1001         FreeMRUList(mruhandle);
1002         TRACE("Updated MRU list, new doc is position %d\n", pos);
1003     }
1004
1005     /* ***  JOB 2: Create shortcut in user's "Recent" directory  *** */
1006
1007     {  /* on input needs:
1008         *      doc_name    -  pure file-spec, no path
1009         *      new_lnk_filepath
1010         *                  -  path and file name of new .lnk file
1011         *      uFlags[in]  -  flags on call to SHAddToRecentDocs
1012         *      pv[in]      -  document path/pidl on call to SHAddToRecentDocs
1013         */
1014         IShellLinkA *psl = NULL;
1015         IPersistFile *pPf = NULL;
1016         HRESULT hres;
1017         CHAR desc[MAX_PATH];
1018         WCHAR widelink[MAX_PATH];
1019
1020         CoInitialize(0);
1021
1022         hres = CoCreateInstance( &CLSID_ShellLink,
1023                                  NULL,
1024                                  CLSCTX_INPROC_SERVER,
1025                                  &IID_IShellLinkA,
1026                                  (LPVOID )&psl);
1027         if(SUCCEEDED(hres)) {
1028
1029             hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
1030                                              (LPVOID *)&pPf);
1031             if(FAILED(hres)) {
1032                 /* bombed */
1033                 ERR("failed QueryInterface for IPersistFile %08x\n", hres);
1034                 goto fail;
1035             }
1036
1037             /* Set the document path or pidl */
1038             if (uFlags == SHARD_PIDL) {
1039                 hres = IShellLinkA_SetIDList(psl, pv);
1040             } else {
1041                 hres = IShellLinkA_SetPath(psl, pv);
1042             }
1043             if(FAILED(hres)) {
1044                 /* bombed */
1045                 ERR("failed Set{IDList|Path} %08x\n", hres);
1046                 goto fail;
1047             }
1048
1049             lstrcpyA(desc, "Shortcut to ");
1050             lstrcatA(desc, doc_name);
1051             hres = IShellLinkA_SetDescription(psl, desc);
1052             if(FAILED(hres)) {
1053                 /* bombed */
1054                 ERR("failed SetDescription %08x\n", hres);
1055                 goto fail;
1056             }
1057
1058             MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
1059                                 widelink, MAX_PATH);
1060             /* create the short cut */
1061             hres = IPersistFile_Save(pPf, widelink, TRUE);
1062             if(FAILED(hres)) {
1063                 /* bombed */
1064                 ERR("failed IPersistFile::Save %08x\n", hres);
1065                 IPersistFile_Release(pPf);
1066                 IShellLinkA_Release(psl);
1067                 goto fail;
1068             }
1069             hres = IPersistFile_SaveCompleted(pPf, widelink);
1070             IPersistFile_Release(pPf);
1071             IShellLinkA_Release(psl);
1072             TRACE("shortcut %s has been created, result=%08x\n",
1073                   new_lnk_filepath, hres);
1074         }
1075         else {
1076             ERR("CoCreateInstance failed, hres=%08x\n", hres);
1077         }
1078     }
1079
1080  fail:
1081     CoUninitialize();
1082
1083     /* all done */
1084     RegCloseKey(HCUbasekey);
1085     return;
1086 }
1087
1088 /*************************************************************************
1089  * SHCreateShellFolderViewEx                    [SHELL32.174]
1090  *
1091  * Create a new instance of the default Shell folder view object.
1092  *
1093  * RETURNS
1094  *  Success: S_OK
1095  *  Failure: error value
1096  *
1097  * NOTES
1098  *  see IShellFolder::CreateViewObject
1099  */
1100 HRESULT WINAPI SHCreateShellFolderViewEx(
1101         LPCSFV psvcbi,    /* [in] shelltemplate struct */
1102         IShellView **ppv) /* [out] IShellView pointer */
1103 {
1104         IShellView * psf;
1105         HRESULT hRes;
1106
1107         TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=%p\n",
1108           psvcbi->pshf, psvcbi->pidl, psvcbi->pfnCallback,
1109           psvcbi->fvm, psvcbi->psvOuter);
1110
1111         psf = IShellView_Constructor(psvcbi->pshf);
1112
1113         if (!psf)
1114           return E_OUTOFMEMORY;
1115
1116         IShellView_AddRef(psf);
1117         hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
1118         IShellView_Release(psf);
1119
1120         return hRes;
1121 }
1122 /*************************************************************************
1123  *  SHWinHelp                                   [SHELL32.127]
1124  *
1125  */
1126 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
1127 {       FIXME("0x%08x 0x%08x 0x%08x 0x%08x stub\n",v,w,x,z);
1128         return 0;
1129 }
1130 /*************************************************************************
1131  *  SHRunControlPanel [SHELL32.161]
1132  *
1133  */
1134 BOOL WINAPI SHRunControlPanel (LPCWSTR commandLine, HWND parent)
1135 {
1136         FIXME("(%s, %p): stub\n", debugstr_w(commandLine), parent);
1137         return FALSE;
1138 }
1139
1140 static LPUNKNOWN SHELL32_IExplorerInterface=0;
1141 /*************************************************************************
1142  * SHSetInstanceExplorer                        [SHELL32.176]
1143  *
1144  * NOTES
1145  *  Sets the interface
1146  */
1147 VOID WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
1148 {       TRACE("%p\n", lpUnknown);
1149         SHELL32_IExplorerInterface = lpUnknown;
1150 }
1151 /*************************************************************************
1152  * SHGetInstanceExplorer                        [SHELL32.@]
1153  *
1154  * NOTES
1155  *  gets the interface pointer of the explorer and a reference
1156  */
1157 HRESULT WINAPI SHGetInstanceExplorer (IUnknown **lpUnknown)
1158 {       TRACE("%p\n", lpUnknown);
1159
1160         *lpUnknown = SHELL32_IExplorerInterface;
1161
1162         if (!SHELL32_IExplorerInterface)
1163           return E_FAIL;
1164
1165         IUnknown_AddRef(SHELL32_IExplorerInterface);
1166         return S_OK;
1167 }
1168 /*************************************************************************
1169  * SHFreeUnusedLibraries                        [SHELL32.123]
1170  *
1171  * Probably equivalent to CoFreeUnusedLibraries but under Windows 9x it could use
1172  * the shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
1173  * for details
1174  *
1175  * NOTES
1176  *     exported by ordinal
1177  *
1178  * SEE ALSO
1179  *     CoFreeUnusedLibraries, SHLoadOLE
1180  */
1181 void WINAPI SHFreeUnusedLibraries (void)
1182 {
1183         FIXME("stub\n");
1184         CoFreeUnusedLibraries();
1185 }
1186 /*************************************************************************
1187  * DAD_AutoScroll                               [SHELL32.129]
1188  *
1189  */
1190 BOOL WINAPI DAD_AutoScroll(HWND hwnd, AUTO_SCROLL_DATA *samples, LPPOINT pt)
1191 {
1192     FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1193     return 0;
1194 }
1195 /*************************************************************************
1196  * DAD_DragEnter                                [SHELL32.130]
1197  *
1198  */
1199 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1200 {
1201     FIXME("hwnd = %p\n",hwnd);
1202     return FALSE;
1203 }
1204 /*************************************************************************
1205  * DAD_DragEnterEx                              [SHELL32.131]
1206  *
1207  */
1208 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1209 {
1210     FIXME("hwnd = %p (%d,%d)\n",hwnd,p.x,p.y);
1211     return FALSE;
1212 }
1213 /*************************************************************************
1214  * DAD_DragMove                         [SHELL32.134]
1215  *
1216  */
1217 BOOL WINAPI DAD_DragMove(POINT p)
1218 {
1219     FIXME("(%d,%d)\n",p.x,p.y);
1220     return FALSE;
1221 }
1222 /*************************************************************************
1223  * DAD_DragLeave                                [SHELL32.132]
1224  *
1225  */
1226 BOOL WINAPI DAD_DragLeave(VOID)
1227 {
1228     FIXME("\n");
1229     return FALSE;
1230 }
1231 /*************************************************************************
1232  * DAD_SetDragImage                             [SHELL32.136]
1233  *
1234  * NOTES
1235  *  exported by name
1236  */
1237 BOOL WINAPI DAD_SetDragImage(
1238         HIMAGELIST himlTrack,
1239         LPPOINT lppt)
1240 {
1241         FIXME("%p %p stub\n",himlTrack, lppt);
1242   return 0;
1243 }
1244 /*************************************************************************
1245  * DAD_ShowDragImage                            [SHELL32.137]
1246  *
1247  * NOTES
1248  *  exported by name
1249  */
1250 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1251 {
1252         FIXME("0x%08x stub\n",bShow);
1253         return 0;
1254 }
1255
1256 static const WCHAR szwCabLocation[] = {
1257   'S','o','f','t','w','a','r','e','\\',
1258   'M','i','c','r','o','s','o','f','t','\\',
1259   'W','i','n','d','o','w','s','\\',
1260   'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1261   'E','x','p','l','o','r','e','r','\\',
1262   'C','a','b','i','n','e','t','S','t','a','t','e',0
1263 };
1264
1265 static const WCHAR szwSettings[] = { 'S','e','t','t','i','n','g','s',0 };
1266
1267 /*************************************************************************
1268  * ReadCabinetState                             [SHELL32.651] NT 4.0
1269  *
1270  */
1271 BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
1272 {
1273         HKEY hkey = 0;
1274         DWORD type, r;
1275
1276         TRACE("%p %d\n", cs, length);
1277
1278         if( (cs == NULL) || (length < (int)sizeof(*cs))  )
1279                 return FALSE;
1280
1281         r = RegOpenKeyW( HKEY_CURRENT_USER, szwCabLocation, &hkey );
1282         if( r == ERROR_SUCCESS )
1283         {
1284                 type = REG_BINARY;
1285                 r = RegQueryValueExW( hkey, szwSettings, 
1286                         NULL, &type, (LPBYTE)cs, (LPDWORD)&length );
1287                 RegCloseKey( hkey );
1288                         
1289         }
1290
1291         /* if we can't read from the registry, create default values */
1292         if ( (r != ERROR_SUCCESS) || (cs->cLength < sizeof(*cs)) ||
1293                 (cs->cLength != length) )
1294         {
1295                 ERR("Initializing shell cabinet settings\n");
1296                 memset(cs, 0, sizeof(*cs));
1297                 cs->cLength          = sizeof(*cs);
1298                 cs->nVersion         = 2;
1299                 cs->fFullPathTitle   = FALSE;
1300                 cs->fSaveLocalView   = TRUE;
1301                 cs->fNotShell        = FALSE;
1302                 cs->fSimpleDefault   = TRUE;
1303                 cs->fDontShowDescBar = FALSE;
1304                 cs->fNewWindowMode   = FALSE;
1305                 cs->fShowCompColor   = FALSE;
1306                 cs->fDontPrettyNames = FALSE;
1307                 cs->fAdminsCreateCommonGroups = TRUE;
1308                 cs->fMenuEnumFilter  = 96;
1309         }
1310         
1311         return TRUE;
1312 }
1313
1314 /*************************************************************************
1315  * WriteCabinetState                            [SHELL32.652] NT 4.0
1316  *
1317  */
1318 BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
1319 {
1320         DWORD r;
1321         HKEY hkey = 0;
1322
1323         TRACE("%p\n",cs);
1324
1325         if( cs == NULL )
1326                 return FALSE;
1327
1328         r = RegCreateKeyExW( HKEY_CURRENT_USER, szwCabLocation, 0,
1329                  NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
1330         if( r == ERROR_SUCCESS )
1331         {
1332                 r = RegSetValueExW( hkey, szwSettings, 0, 
1333                         REG_BINARY, (LPBYTE) cs, cs->cLength);
1334
1335                 RegCloseKey( hkey );
1336         }
1337
1338         return (r==ERROR_SUCCESS);
1339 }
1340
1341 /*************************************************************************
1342  * FileIconInit                                 [SHELL32.660]
1343  *
1344  */
1345 BOOL WINAPI FileIconInit(BOOL bFullInit)
1346 {       FIXME("(%s)\n", bFullInit ? "true" : "false");
1347         return 0;
1348 }
1349
1350 /*************************************************************************
1351  * IsUserAnAdmin    [SHELL32.680] NT 4.0
1352  *
1353  * Checks whether the current user is a member of the Administrators group.
1354  *
1355  * PARAMS
1356  *     None
1357  *
1358  * RETURNS
1359  *     Success: TRUE
1360  *     Failure: FALSE
1361  */
1362 BOOL WINAPI IsUserAnAdmin(VOID)
1363 {
1364     SID_IDENTIFIER_AUTHORITY Authority = {SECURITY_NT_AUTHORITY};
1365     HANDLE hToken;
1366     DWORD dwSize;
1367     PTOKEN_GROUPS lpGroups;
1368     PSID lpSid;
1369     DWORD i;
1370     BOOL bResult = FALSE;
1371
1372     TRACE("\n");
1373     if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
1374     {
1375         return FALSE;
1376     }
1377
1378     if (!GetTokenInformation(hToken, TokenGroups, NULL, 0, &dwSize))
1379     {
1380         if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
1381         {
1382             CloseHandle(hToken);
1383             return FALSE;
1384         }
1385     }
1386
1387     lpGroups = HeapAlloc(GetProcessHeap(), 0, dwSize);
1388     if (lpGroups == NULL)
1389     {
1390         CloseHandle(hToken);
1391         return FALSE;
1392     }
1393
1394     if (!GetTokenInformation(hToken, TokenGroups, lpGroups, dwSize, &dwSize))
1395     {
1396         HeapFree(GetProcessHeap(), 0, lpGroups);
1397         CloseHandle(hToken);
1398         return FALSE;
1399     }
1400
1401     CloseHandle(hToken);
1402     if (!AllocateAndInitializeSid(&Authority, 2, SECURITY_BUILTIN_DOMAIN_RID,
1403                                   DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0,
1404                                   &lpSid))
1405     {
1406         HeapFree(GetProcessHeap(), 0, lpGroups);
1407         return FALSE;
1408     }
1409
1410     for (i = 0; i < lpGroups->GroupCount; i++)
1411     {
1412         if (EqualSid(lpSid, lpGroups->Groups[i].Sid))
1413         {
1414             bResult = TRUE;
1415             break;
1416         }
1417     }
1418
1419     FreeSid(lpSid);
1420     HeapFree(GetProcessHeap(), 0, lpGroups);
1421     return bResult;
1422 }
1423
1424 /*************************************************************************
1425  * SHAllocShared                                [SHELL32.520]
1426  *
1427  * See shlwapi.SHAllocShared
1428  */
1429 HANDLE WINAPI SHAllocShared(LPVOID lpvData, DWORD dwSize, DWORD dwProcId)
1430 {
1431     GET_FUNC(pSHAllocShared, shlwapi, (char*)7, NULL);
1432     return pSHAllocShared(lpvData, dwSize, dwProcId);
1433 }
1434
1435 /*************************************************************************
1436  * SHLockShared                                 [SHELL32.521]
1437  *
1438  * See shlwapi.SHLockShared
1439  */
1440 LPVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
1441 {
1442     GET_FUNC(pSHLockShared, shlwapi, (char*)8, NULL);
1443     return pSHLockShared(hShared, dwProcId);
1444 }
1445
1446 /*************************************************************************
1447  * SHUnlockShared                               [SHELL32.522]
1448  *
1449  * See shlwapi.SHUnlockShared
1450  */
1451 BOOL WINAPI SHUnlockShared(LPVOID lpView)
1452 {
1453     GET_FUNC(pSHUnlockShared, shlwapi, (char*)9, FALSE);
1454     return pSHUnlockShared(lpView);
1455 }
1456
1457 /*************************************************************************
1458  * SHFreeShared                                 [SHELL32.523]
1459  *
1460  * See shlwapi.SHFreeShared
1461  */
1462 BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
1463 {
1464     GET_FUNC(pSHFreeShared, shlwapi, (char*)10, FALSE);
1465     return pSHFreeShared(hShared, dwProcId);
1466 }
1467
1468 /*************************************************************************
1469  * SetAppStartingCursor                         [SHELL32.99]
1470  */
1471 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1472 {       FIXME("hwnd=%p 0x%04x stub\n",u,v );
1473         return 0;
1474 }
1475
1476 /*************************************************************************
1477  * SHLoadOLE                                    [SHELL32.151]
1478  *
1479  * To reduce the memory usage of Windows 95, its shell32 contained an
1480  * internal implementation of a part of COM (see e.g. SHGetMalloc, SHCoCreateInstance,
1481  * SHRegisterDragDrop etc.) that allowed to use in-process STA objects without
1482  * the need to load OLE32.DLL. If OLE32.DLL was already loaded, the SH* function
1483  * would just call the Co* functions.
1484  *
1485  * The SHLoadOLE was called when OLE32.DLL was being loaded to transfer all the
1486  * information from the shell32 "mini-COM" to ole32.dll.
1487  *
1488  * See http://blogs.msdn.com/oldnewthing/archive/2004/07/05/173226.aspx for a
1489  * detailed description.
1490  *
1491  * Under wine ole32.dll is always loaded as it is imported by shlwapi.dll which is
1492  * imported by shell32 and no "mini-COM" is used (except for the "LoadWithoutCOM"
1493  * hack in SHCoCreateInstance)
1494  */
1495 HRESULT WINAPI SHLoadOLE(LPARAM lParam)
1496 {       FIXME("0x%08lx stub\n",lParam);
1497         return S_OK;
1498 }
1499 /*************************************************************************
1500  * DriveType                                    [SHELL32.64]
1501  *
1502  */
1503 int WINAPI DriveType(int u)
1504 {       FIXME("0x%04x stub\n",u);
1505         return 0;
1506 }
1507 /*************************************************************************
1508  * InvalidateDriveType                  [SHELL32.65]
1509  *
1510  */
1511 int WINAPI InvalidateDriveType(int u)
1512 {       FIXME("0x%08x stub\n",u);
1513         return 0;
1514 }
1515 /*************************************************************************
1516  * SHAbortInvokeCommand                         [SHELL32.198]
1517  *
1518  */
1519 HRESULT WINAPI SHAbortInvokeCommand(void)
1520 {       FIXME("stub\n");
1521         return 1;
1522 }
1523 /*************************************************************************
1524  * SHOutOfMemoryMessageBox                      [SHELL32.126]
1525  *
1526  */
1527 int WINAPI SHOutOfMemoryMessageBox(
1528         HWND hwndOwner,
1529         LPCSTR lpCaption,
1530         UINT uType)
1531 {
1532         FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1533         return 0;
1534 }
1535 /*************************************************************************
1536  * SHFlushClipboard                             [SHELL32.121]
1537  *
1538  */
1539 HRESULT WINAPI SHFlushClipboard(void)
1540 {       FIXME("stub\n");
1541         return 1;
1542 }
1543
1544 /*************************************************************************
1545  * SHWaitForFileToOpen                          [SHELL32.97]
1546  *
1547  */
1548 BOOL WINAPI SHWaitForFileToOpen(
1549         LPCITEMIDLIST pidl,
1550         DWORD dwFlags,
1551         DWORD dwTimeout)
1552 {
1553         FIXME("%p 0x%08x 0x%08x stub\n", pidl, dwFlags, dwTimeout);
1554         return 0;
1555 }
1556
1557 /************************************************************************
1558  *      @                               [SHELL32.654]
1559  *
1560  * NOTES
1561  *  first parameter seems to be a pointer (same as passed to WriteCabinetState)
1562  *  second one could be a size (0x0c). The size is the same as the structure saved to
1563  *  HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1564  *  I'm (js) guessing: this one is just ReadCabinetState ;-)
1565  */
1566 HRESULT WINAPI shell32_654 (CABINETSTATE *cs, int length)
1567 {
1568         TRACE("%p %d\n",cs,length);
1569         return ReadCabinetState(cs,length);
1570 }
1571
1572 /************************************************************************
1573  *      RLBuildListOfPaths                      [SHELL32.146]
1574  *
1575  * NOTES
1576  *   builds a DPA
1577  */
1578 DWORD WINAPI RLBuildListOfPaths (void)
1579 {       FIXME("stub\n");
1580         return 0;
1581 }
1582 /************************************************************************
1583  *      SHValidateUNC                           [SHELL32.173]
1584  *
1585  */
1586 BOOL WINAPI SHValidateUNC (HWND hwndOwner, PWSTR pszFile, UINT fConnect)
1587 {
1588         FIXME("(%p, %s, 0x%08x): stub\n", hwndOwner, debugstr_w(pszFile), fConnect);
1589         return FALSE;
1590 }
1591
1592 /************************************************************************
1593  * DoEnvironmentSubstA [SHELL32.@]
1594  *
1595  * See DoEnvironmentSubstW.
1596  */
1597 DWORD WINAPI DoEnvironmentSubstA(LPSTR pszString, UINT cchString)
1598 {
1599     LPSTR dst;
1600     BOOL res = FALSE;
1601     DWORD len = cchString;
1602
1603     TRACE("(%s, %d)\n", debugstr_a(pszString), cchString);
1604
1605     if ((dst = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(CHAR))))
1606     {
1607         len = ExpandEnvironmentStringsA(pszString, dst, cchString);
1608         /* len includes the terminating 0 */
1609         if (len && len < cchString)
1610         {
1611             res = TRUE;
1612             memcpy(pszString, dst, len);
1613         }
1614         else
1615             len = cchString;
1616
1617         HeapFree(GetProcessHeap(), 0, dst);
1618     }
1619     return MAKELONG(len, res);
1620 }
1621
1622 /************************************************************************
1623  * DoEnvironmentSubstW [SHELL32.@]
1624  *
1625  * Replace all %KEYWORD% in the string with the value of the named
1626  * environment variable. If the buffer is too small, the string is not modified.
1627  *
1628  * PARAMS
1629  *  pszString  [I] '\0' terminated string with %keyword%.
1630  *             [O] '\0' terminated string with %keyword% substituted.
1631  *  cchString  [I] size of str.
1632  *
1633  * RETURNS
1634  *  Success:  The string in the buffer is updated
1635  *            HIWORD: TRUE
1636  *            LOWORD: characters used in the buffer, including space for the terminating 0
1637  *  Failure:  buffer too small. The string is not modified.
1638  *            HIWORD: FALSE
1639  *            LOWORD: provided size of the buffer in characters
1640  */
1641 DWORD WINAPI DoEnvironmentSubstW(LPWSTR pszString, UINT cchString)
1642 {
1643     LPWSTR dst;
1644     BOOL res = FALSE;
1645     DWORD len = cchString;
1646
1647     TRACE("(%s, %d)\n", debugstr_w(pszString), cchString);
1648
1649     if ((cchString < MAXLONG) && (dst = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(WCHAR))))
1650     {
1651         len = ExpandEnvironmentStringsW(pszString, dst, cchString);
1652         /* len includes the terminating 0 */
1653         if (len && len <= cchString)
1654         {
1655             res = TRUE;
1656             memcpy(pszString, dst, len * sizeof(WCHAR));
1657         }
1658         else
1659             len = cchString;
1660
1661         HeapFree(GetProcessHeap(), 0, dst);
1662     }
1663     return MAKELONG(len, res);
1664 }
1665
1666 /************************************************************************
1667  *      DoEnvironmentSubst                      [SHELL32.53]
1668  *
1669  * See DoEnvironmentSubstA.  
1670  */
1671 DWORD WINAPI DoEnvironmentSubstAW(LPVOID x, UINT y)
1672 {
1673     if (SHELL_OsIsUnicode())
1674         return DoEnvironmentSubstW(x, y);
1675     return DoEnvironmentSubstA(x, y);
1676 }
1677
1678 /*************************************************************************
1679  *      @                             [SHELL32.243]
1680  *
1681  * Win98+ by-ordinal routine.  In Win98 this routine returns zero and
1682  * does nothing else.  Possibly this does something in NT or SHELL32 5.0?
1683  *
1684  */
1685
1686 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1687 {
1688   return FALSE;
1689 }
1690
1691 /*************************************************************************
1692  *      GUIDFromStringW   [SHELL32.704]
1693  */
1694 BOOL WINAPI GUIDFromStringW(LPCWSTR str, LPGUID guid)
1695 {
1696     UNICODE_STRING guid_str;
1697
1698     RtlInitUnicodeString(&guid_str, str);
1699     return !RtlGUIDFromString(&guid_str, guid);
1700 }
1701
1702 /*************************************************************************
1703  *      @       [SHELL32.714]
1704  */
1705 DWORD WINAPI SHELL32_714(LPVOID x)
1706 {
1707         FIXME("(%s)stub\n", debugstr_w(x));
1708         return 0;
1709 }
1710
1711 typedef struct _PSXA
1712 {
1713     UINT uiCount;
1714     UINT uiAllocated;
1715     IShellPropSheetExt *pspsx[1];
1716 } PSXA, *PPSXA;
1717
1718 typedef struct _PSXA_CALL
1719 {
1720     LPFNADDPROPSHEETPAGE lpfnAddReplaceWith;
1721     LPARAM lParam;
1722     BOOL bCalled;
1723     BOOL bMultiple;
1724     UINT uiCount;
1725 } PSXA_CALL, *PPSXA_CALL;
1726
1727 static BOOL CALLBACK PsxaCall(HPROPSHEETPAGE hpage, LPARAM lParam)
1728 {
1729     PPSXA_CALL Call = (PPSXA_CALL)lParam;
1730
1731     if (Call != NULL)
1732     {
1733         if ((Call->bMultiple || !Call->bCalled) &&
1734             Call->lpfnAddReplaceWith(hpage, Call->lParam))
1735         {
1736             Call->bCalled = TRUE;
1737             Call->uiCount++;
1738             return TRUE;
1739         }
1740     }
1741
1742     return FALSE;
1743 }
1744
1745 /*************************************************************************
1746  *      SHAddFromPropSheetExtArray      [SHELL32.167]
1747  */
1748 UINT WINAPI SHAddFromPropSheetExtArray(HPSXA hpsxa, LPFNADDPROPSHEETPAGE lpfnAddPage, LPARAM lParam)
1749 {
1750     PSXA_CALL Call;
1751     UINT i;
1752     PPSXA psxa = (PPSXA)hpsxa;
1753
1754     TRACE("(%p,%p,%08lx)\n", hpsxa, lpfnAddPage, lParam);
1755
1756     if (psxa)
1757     {
1758         ZeroMemory(&Call, sizeof(Call));
1759         Call.lpfnAddReplaceWith = lpfnAddPage;
1760         Call.lParam = lParam;
1761         Call.bMultiple = TRUE;
1762
1763         /* Call the AddPage method of all registered IShellPropSheetExt interfaces */
1764         for (i = 0; i != psxa->uiCount; i++)
1765         {
1766             psxa->pspsx[i]->lpVtbl->AddPages(psxa->pspsx[i], PsxaCall, (LPARAM)&Call);
1767         }
1768
1769         return Call.uiCount;
1770     }
1771
1772     return 0;
1773 }
1774
1775 /*************************************************************************
1776  *      SHCreatePropSheetExtArray       [SHELL32.168]
1777  */
1778 HPSXA WINAPI SHCreatePropSheetExtArray(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface)
1779 {
1780     return SHCreatePropSheetExtArrayEx(hKey, pszSubKey, max_iface, NULL);
1781 }
1782
1783 /*************************************************************************
1784  *      SHCreatePropSheetExtArrayEx     [SHELL32.194]
1785  */
1786 HPSXA WINAPI SHCreatePropSheetExtArrayEx(HKEY hKey, LPCWSTR pszSubKey, UINT max_iface, LPDATAOBJECT pDataObj)
1787 {
1788     static const WCHAR szPropSheetSubKey[] = {'s','h','e','l','l','e','x','\\','P','r','o','p','e','r','t','y','S','h','e','e','t','H','a','n','d','l','e','r','s',0};
1789     WCHAR szHandler[64];
1790     DWORD dwHandlerLen;
1791     WCHAR szClsidHandler[39];
1792     DWORD dwClsidSize;
1793     CLSID clsid;
1794     LONG lRet;
1795     DWORD dwIndex;
1796     IShellExtInit *psxi;
1797     IShellPropSheetExt *pspsx;
1798     HKEY hkBase, hkPropSheetHandlers;
1799     PPSXA psxa = NULL;
1800
1801     TRACE("(%p,%s,%u)\n", hKey, debugstr_w(pszSubKey), max_iface);
1802
1803     if (max_iface == 0)
1804         return NULL;
1805
1806     /* Open the registry key */
1807     lRet = RegOpenKeyW(hKey, pszSubKey, &hkBase);
1808     if (lRet != ERROR_SUCCESS)
1809         return NULL;
1810
1811     lRet = RegOpenKeyExW(hkBase, szPropSheetSubKey, 0, KEY_ENUMERATE_SUB_KEYS, &hkPropSheetHandlers);
1812     RegCloseKey(hkBase);
1813     if (lRet == ERROR_SUCCESS)
1814     {
1815         /* Create and initialize the Property Sheet Extensions Array */
1816         psxa = LocalAlloc(LMEM_FIXED, FIELD_OFFSET(PSXA, pspsx[max_iface]));
1817         if (psxa)
1818         {
1819             ZeroMemory(psxa, FIELD_OFFSET(PSXA, pspsx[max_iface]));
1820             psxa->uiAllocated = max_iface;
1821
1822             /* Enumerate all subkeys and attempt to load the shell extensions */
1823             dwIndex = 0;
1824             do
1825             {
1826                 dwHandlerLen = sizeof(szHandler) / sizeof(szHandler[0]);
1827                 lRet = RegEnumKeyExW(hkPropSheetHandlers, dwIndex++, szHandler, &dwHandlerLen, NULL, NULL, NULL, NULL);
1828                 if (lRet != ERROR_SUCCESS)
1829                 {
1830                     if (lRet == ERROR_MORE_DATA)
1831                         continue;
1832
1833                     if (lRet == ERROR_NO_MORE_ITEMS)
1834                         lRet = ERROR_SUCCESS;
1835                     break;
1836                 }
1837
1838                 /* The CLSID is stored either in the key itself or in its default value. */
1839                 if (FAILED(lRet = SHCLSIDFromStringW(szHandler, &clsid)))
1840                 {
1841                     dwClsidSize = sizeof(szClsidHandler);
1842                     if (SHGetValueW(hkPropSheetHandlers, szHandler, NULL, NULL, szClsidHandler, &dwClsidSize) == ERROR_SUCCESS)
1843                     {
1844                         /* Force a NULL-termination and convert the string */
1845                         szClsidHandler[(sizeof(szClsidHandler) / sizeof(szClsidHandler[0])) - 1] = 0;
1846                         lRet = SHCLSIDFromStringW(szClsidHandler, &clsid);
1847                     }
1848                 }
1849
1850                 if (SUCCEEDED(lRet))
1851                 {
1852                     /* Attempt to get an IShellPropSheetExt and an IShellExtInit instance.
1853                        Only if both interfaces are supported it's a real shell extension.
1854                        Then call IShellExtInit's Initialize method. */
1855                     if (SUCCEEDED(CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER/* | CLSCTX_NO_CODE_DOWNLOAD */, &IID_IShellPropSheetExt, (LPVOID *)&pspsx)))
1856                     {
1857                         if (SUCCEEDED(pspsx->lpVtbl->QueryInterface(pspsx, &IID_IShellExtInit, (PVOID *)&psxi)))
1858                         {
1859                             if (SUCCEEDED(psxi->lpVtbl->Initialize(psxi, NULL, pDataObj, hKey)))
1860                             {
1861                                 /* Add the IShellPropSheetExt instance to the array */
1862                                 psxa->pspsx[psxa->uiCount++] = pspsx;
1863                             }
1864                             else
1865                             {
1866                                 psxi->lpVtbl->Release(psxi);
1867                                 pspsx->lpVtbl->Release(pspsx);
1868                             }
1869                         }
1870                         else
1871                             pspsx->lpVtbl->Release(pspsx);
1872                     }
1873                 }
1874
1875             } while (psxa->uiCount != psxa->uiAllocated);
1876         }
1877         else
1878             lRet = ERROR_NOT_ENOUGH_MEMORY;
1879
1880         RegCloseKey(hkPropSheetHandlers);
1881     }
1882
1883     if (lRet != ERROR_SUCCESS && psxa)
1884     {
1885         SHDestroyPropSheetExtArray((HPSXA)psxa);
1886         psxa = NULL;
1887     }
1888
1889     return (HPSXA)psxa;
1890 }
1891
1892 /*************************************************************************
1893  *      SHReplaceFromPropSheetExtArray  [SHELL32.170]
1894  */
1895 UINT WINAPI SHReplaceFromPropSheetExtArray(HPSXA hpsxa, UINT uPageID, LPFNADDPROPSHEETPAGE lpfnReplaceWith, LPARAM lParam)
1896 {
1897     PSXA_CALL Call;
1898     UINT i;
1899     PPSXA psxa = (PPSXA)hpsxa;
1900
1901     TRACE("(%p,%u,%p,%08lx)\n", hpsxa, uPageID, lpfnReplaceWith, lParam);
1902
1903     if (psxa)
1904     {
1905         ZeroMemory(&Call, sizeof(Call));
1906         Call.lpfnAddReplaceWith = lpfnReplaceWith;
1907         Call.lParam = lParam;
1908
1909         /* Call the ReplacePage method of all registered IShellPropSheetExt interfaces.
1910            Each shell extension is only allowed to call the callback once during the callback. */
1911         for (i = 0; i != psxa->uiCount; i++)
1912         {
1913             Call.bCalled = FALSE;
1914             psxa->pspsx[i]->lpVtbl->ReplacePage(psxa->pspsx[i], uPageID, PsxaCall, (LPARAM)&Call);
1915         }
1916
1917         return Call.uiCount;
1918     }
1919
1920     return 0;
1921 }
1922
1923 /*************************************************************************
1924  *      SHDestroyPropSheetExtArray      [SHELL32.169]
1925  */
1926 void WINAPI SHDestroyPropSheetExtArray(HPSXA hpsxa)
1927 {
1928     UINT i;
1929     PPSXA psxa = (PPSXA)hpsxa;
1930
1931     TRACE("(%p)\n", hpsxa);
1932
1933     if (psxa)
1934     {
1935         for (i = 0; i != psxa->uiCount; i++)
1936         {
1937             psxa->pspsx[i]->lpVtbl->Release(psxa->pspsx[i]);
1938         }
1939
1940         LocalFree(psxa);
1941     }
1942 }
1943
1944 /*************************************************************************
1945  *      CIDLData_CreateFromIDArray      [SHELL32.83]
1946  *
1947  *  Create IDataObject from PIDLs??
1948  */
1949 HRESULT WINAPI CIDLData_CreateFromIDArray(
1950         LPCITEMIDLIST pidlFolder,
1951         DWORD cpidlFiles,
1952         LPCITEMIDLIST *lppidlFiles,
1953         LPDATAOBJECT *ppdataObject)
1954 {
1955     UINT i;
1956     HWND hwnd = 0;   /*FIXME: who should be hwnd of owner? set to desktop */
1957
1958     TRACE("(%p, %d, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1959     if (TRACE_ON(pidl))
1960     {
1961         pdump (pidlFolder);
1962         for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1963     }
1964     *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1965                                              lppidlFiles, cpidlFiles);
1966     if (*ppdataObject) return S_OK;
1967     return E_OUTOFMEMORY;
1968 }
1969
1970 /*************************************************************************
1971  * SHCreateStdEnumFmtEtc                        [SHELL32.74]
1972  *
1973  * NOTES
1974  *
1975  */
1976 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1977         DWORD cFormats,
1978         const FORMATETC *lpFormats,
1979         LPENUMFORMATETC *ppenumFormatetc)
1980 {
1981         IEnumFORMATETC *pef;
1982         HRESULT hRes;
1983         TRACE("cf=%d fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1984
1985         pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1986         if (!pef)
1987           return E_OUTOFMEMORY;
1988
1989         IEnumFORMATETC_AddRef(pef);
1990         hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1991         IEnumFORMATETC_Release(pef);
1992
1993         return hRes;
1994 }
1995
1996 /*************************************************************************
1997  *              SHFindFiles (SHELL32.90)
1998  */
1999 BOOL WINAPI SHFindFiles( LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlSaveFile )
2000 {
2001     FIXME("%p %p\n", pidlFolder, pidlSaveFile );
2002     return FALSE;
2003 }
2004
2005 /*************************************************************************
2006  *              SHUpdateImageW (SHELL32.192)
2007  *
2008  * Notifies the shell that an icon in the system image list has been changed.
2009  *
2010  * PARAMS
2011  *  pszHashItem [I] Path to file that contains the icon.
2012  *  iIndex      [I] Zero-based index of the icon in the file.
2013  *  uFlags      [I] Flags determining the icon attributes. See notes.
2014  *  iImageIndex [I] Index of the icon in the system image list.
2015  *
2016  * RETURNS
2017  *  Nothing
2018  *
2019  * NOTES
2020  *  uFlags can be one or more of the following flags:
2021  *  GIL_NOTFILENAME - pszHashItem is not a file name.
2022  *  GIL_SIMULATEDOC - Create a document icon using the specified icon.
2023  */
2024 void WINAPI SHUpdateImageW(LPCWSTR pszHashItem, int iIndex, UINT uFlags, int iImageIndex)
2025 {
2026     FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_w(pszHashItem), iIndex, uFlags, iImageIndex);
2027 }
2028
2029 /*************************************************************************
2030  *              SHUpdateImageA (SHELL32.191)
2031  *
2032  * See SHUpdateImageW.
2033  */
2034 VOID WINAPI SHUpdateImageA(LPCSTR pszHashItem, INT iIndex, UINT uFlags, INT iImageIndex)
2035 {
2036     FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_a(pszHashItem), iIndex, uFlags, iImageIndex);
2037 }
2038
2039 INT WINAPI SHHandleUpdateImage(LPCITEMIDLIST pidlExtra)
2040 {
2041     FIXME("%p - stub\n", pidlExtra);
2042
2043     return -1;
2044 }
2045
2046 BOOL WINAPI SHObjectProperties(HWND hwnd, DWORD dwType, LPCWSTR szObject, LPCWSTR szPage)
2047 {
2048     FIXME("%p, 0x%08x, %s, %s - stub\n", hwnd, dwType, debugstr_w(szObject), debugstr_w(szPage));
2049
2050     return TRUE;
2051 }
2052
2053 BOOL WINAPI SHGetNewLinkInfoA(LPCSTR pszLinkTo, LPCSTR pszDir, LPSTR pszName, BOOL *pfMustCopy,
2054                               UINT uFlags)
2055 {
2056     WCHAR wszLinkTo[MAX_PATH];
2057     WCHAR wszDir[MAX_PATH];
2058     WCHAR wszName[MAX_PATH];
2059     BOOL res;
2060
2061     MultiByteToWideChar(CP_ACP, 0, pszLinkTo, -1, wszLinkTo, MAX_PATH);
2062     MultiByteToWideChar(CP_ACP, 0, pszDir, -1, wszDir, MAX_PATH);
2063
2064     res = SHGetNewLinkInfoW(wszLinkTo, wszDir, wszName, pfMustCopy, uFlags);
2065
2066     if (res)
2067         WideCharToMultiByte(CP_ACP, 0, wszName, -1, pszName, MAX_PATH, NULL, NULL);
2068
2069     return res;
2070 }
2071
2072 BOOL WINAPI SHGetNewLinkInfoW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName, BOOL *pfMustCopy,
2073                               UINT uFlags)
2074 {
2075     const WCHAR *basename;
2076     WCHAR *dst_basename;
2077     int i=2;
2078     static const WCHAR lnkformat[] = {'%','s','.','l','n','k',0};
2079     static const WCHAR lnkformatnum[] = {'%','s',' ','(','%','d',')','.','l','n','k',0};
2080
2081     TRACE("(%s, %s, %p, %p, 0x%08x)\n", debugstr_w(pszLinkTo), debugstr_w(pszDir),
2082           pszName, pfMustCopy, uFlags);
2083
2084     *pfMustCopy = FALSE;
2085
2086     if (uFlags & SHGNLI_PIDL)
2087     {
2088         FIXME("SHGNLI_PIDL flag unsupported\n");
2089         return FALSE;
2090     }
2091
2092     if (uFlags)
2093         FIXME("ignoring flags: 0x%08x\n", uFlags);
2094
2095     /* FIXME: should test if the file is a shortcut or DOS program */
2096     if (GetFileAttributesW(pszLinkTo) == INVALID_FILE_ATTRIBUTES)
2097         return FALSE;
2098
2099     basename = strrchrW(pszLinkTo, '\\');
2100     if (basename)
2101         basename = basename+1;
2102     else
2103         basename = pszLinkTo;
2104
2105     lstrcpynW(pszName, pszDir, MAX_PATH);
2106     if (!PathAddBackslashW(pszName))
2107         return FALSE;
2108
2109     dst_basename = pszName + strlenW(pszName);
2110
2111     snprintfW(dst_basename, pszName + MAX_PATH - dst_basename, lnkformat, basename);
2112
2113     while (GetFileAttributesW(pszName) != INVALID_FILE_ATTRIBUTES)
2114     {
2115         snprintfW(dst_basename, pszName + MAX_PATH - dst_basename, lnkformatnum, basename, i);
2116         i++;
2117     }
2118
2119     return TRUE;
2120 }
2121
2122 HRESULT WINAPI SHStartNetConnectionDialog(HWND hwnd, LPCSTR pszRemoteName, DWORD dwType)
2123 {
2124     FIXME("%p, %s, 0x%08x - stub\n", hwnd, debugstr_a(pszRemoteName), dwType);
2125
2126     return S_OK;
2127 }
2128
2129 DWORD WINAPI SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options)
2130 {
2131     FIXME("%p, 0x%08x, 0x%08x, 0x%08x - stub\n", hwnd, drive, fmtID, options);
2132
2133     return SHFMT_NOFORMAT;
2134 }
2135
2136 /*************************************************************************
2137  *              SHSetLocalizedName (SHELL32.@)
2138  */
2139 HRESULT WINAPI SHSetLocalizedName(LPWSTR pszPath, LPCWSTR pszResModule, int idsRes)
2140 {
2141     FIXME("%p, %s, %d - stub\n", pszPath, debugstr_w(pszResModule), idsRes);
2142
2143     return S_OK;
2144 }
2145
2146 /*************************************************************************
2147  *              LinkWindow_RegisterClass (SHELL32.258)
2148  */
2149 BOOL WINAPI LinkWindow_RegisterClass(void)
2150 {
2151     FIXME("()\n");
2152     return TRUE;
2153 }
2154
2155 /*************************************************************************
2156  *              LinkWindow_UnregisterClass (SHELL32.259)
2157  */
2158 BOOL WINAPI LinkWindow_UnregisterClass(void)
2159 {
2160     FIXME("()\n");
2161     return TRUE;
2162 }
2163
2164 /*************************************************************************
2165  *              SHFlushSFCache (SHELL32.526)
2166  *
2167  * Notifies the shell that a user-specified special folder location has changed.
2168  *
2169  * NOTES
2170  *   In Wine, the shell folder registry values are not cached, so this function
2171  *   has no effect.
2172  */
2173 void WINAPI SHFlushSFCache(void)
2174 {
2175 }
2176
2177 /*************************************************************************
2178  *              SHGetImageList (SHELL32.727)
2179  *
2180  * Returns a copy of a shell image list.
2181  *
2182  * NOTES
2183  *   Windows XP features 4 sizes of image list, and Vista 5. Wine currently
2184  *   only supports the traditional small and large image lists, so requests
2185  *   for the others will currently fail.
2186  */
2187 HRESULT WINAPI SHGetImageList(int iImageList, REFIID riid, void **ppv)
2188 {
2189     HIMAGELIST hLarge, hSmall;
2190     HIMAGELIST hNew;
2191     HRESULT ret = E_FAIL;
2192
2193     /* Wine currently only maintains large and small image lists */
2194     if ((iImageList != SHIL_LARGE) && (iImageList != SHIL_SMALL) && (iImageList != SHIL_SYSSMALL))
2195     {
2196         FIXME("Unsupported image list %i requested\n", iImageList);
2197         return E_FAIL;
2198     }
2199
2200     Shell_GetImageLists(&hLarge, &hSmall);
2201     hNew = ImageList_Duplicate(iImageList == SHIL_LARGE ? hLarge : hSmall);
2202
2203     /* Get the interface for the new image list */
2204     if (hNew)
2205     {
2206         ret = HIMAGELIST_QueryInterface(hNew, riid, ppv);
2207         ImageList_Destroy(hNew);
2208     }
2209
2210     return ret;
2211 }
2212
2213 /*************************************************************************
2214  * SHCreateShellFolderView                      [SHELL32.256]
2215  *
2216  * Create a new instance of the default Shell folder view object.
2217  *
2218  * RETURNS
2219  *  Success: S_OK
2220  *  Failure: error value
2221  *
2222  * NOTES
2223  *  see IShellFolder::CreateViewObject
2224  */
2225 HRESULT WINAPI SHCreateShellFolderView(const SFV_CREATE *pcsfv,
2226                         IShellView **ppsv)
2227 {
2228         IShellView * psf;
2229         HRESULT hRes;
2230
2231         TRACE("sf=%p outer=%p callback=%p\n",
2232           pcsfv->pshf, pcsfv->psvOuter, pcsfv->psfvcb);
2233
2234         psf = IShellView_Constructor(pcsfv->pshf);
2235
2236         if (!psf)
2237           return E_OUTOFMEMORY;
2238
2239         IShellView_AddRef(psf);
2240         hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppsv);
2241         IShellView_Release(psf);
2242
2243         return hRes;
2244 }