shell32: Register 'LocalizedString' values for shellfolder classes.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
37 #include "shellapi.h"
38 #include "objbase.h"
39 #include "shlguid.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "shlobj.h"
43 #include "shell32_main.h"
44 #include "undocshell.h"
45 #include "pidl.h"
46 #include "shlwapi.h"
47 #include "commdlg.h"
48
49 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 WINE_DECLARE_DEBUG_CHANNEL(pidl);
51
52 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
53 /*        !!! it is in both here and comctl32undoc.c      !!! */
54 typedef struct tagCREATEMRULIST
55 {
56     DWORD  cbSize;        /* size of struct */
57     DWORD  nMaxItems;     /* max no. of items in list */
58     DWORD  dwFlags;       /* see below */
59     HKEY   hKey;          /* root reg. key under which list is saved */
60     LPCSTR lpszSubKey;    /* reg. subkey */
61     PROC   lpfnCompare;   /* item compare proc */
62 } CREATEMRULISTA, *LPCREATEMRULISTA;
63
64 /* dwFlags */
65 #define MRUF_STRING_LIST  0 /* list will contain strings */
66 #define MRUF_BINARY_LIST  1 /* list will contain binary data */
67 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
68
69 extern HANDLE WINAPI CreateMRUListA(LPCREATEMRULISTA lpcml);
70 extern DWORD  WINAPI FreeMRUList(HANDLE hMRUList);
71 extern INT    WINAPI AddMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData);
72 extern INT    WINAPI FindMRUData(HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
73 extern INT    WINAPI EnumMRUListA(HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
74
75
76 /* Get a function pointer from a DLL handle */
77 #define GET_FUNC(func, module, name, fail) \
78   do { \
79     if (!func) { \
80       if (!SHELL32_h##module && !(SHELL32_h##module = LoadLibraryA(#module ".dll"))) return fail; \
81       func = (void*)GetProcAddress(SHELL32_h##module, name); \
82       if (!func) return fail; \
83     } \
84   } while (0)
85
86 /* Function pointers for GET_FUNC macro */
87 static HMODULE SHELL32_hshlwapi=NULL;
88 static HANDLE (WINAPI *pSHAllocShared)(LPCVOID,DWORD,DWORD);
89 static LPVOID (WINAPI *pSHLockShared)(HANDLE,DWORD);
90 static BOOL   (WINAPI *pSHUnlockShared)(LPVOID);
91 static BOOL   (WINAPI *pSHFreeShared)(HANDLE,DWORD);
92
93
94 /*************************************************************************
95  * ParseFieldA                                  [internal]
96  *
97  * copies a field from a ',' delimited string
98  *
99  * first field is nField = 1
100  */
101 DWORD WINAPI ParseFieldA(
102         LPCSTR src,
103         DWORD nField,
104         LPSTR dst,
105         DWORD len)
106 {
107         WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src),nField,dst,len);
108
109         if (!src || !src[0] || !dst || !len)
110           return 0;
111
112         /* skip n fields delimited by ',' */
113         while (nField > 1)
114         {
115           if (*src=='\0') return FALSE;
116           if (*(src++)==',') nField--;
117         }
118
119         /* copy part till the next ',' to dst */
120         while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
121
122         /* finalize the string */
123         *dst=0x0;
124
125         return TRUE;
126 }
127
128 /*************************************************************************
129  * ParseFieldW                  [internal]
130  *
131  * copies a field from a ',' delimited string
132  *
133  * first field is nField = 1
134  */
135 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
136 {
137         WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n", debugstr_w(src), nField, dst, len);
138
139         if (!src || !src[0] || !dst || !len)
140           return 0;
141
142         /* skip n fields delimited by ',' */
143         while (nField > 1)
144         {
145           if (*src == 0x0) return FALSE;
146           if (*src++ == ',') nField--;
147         }
148
149         /* copy part till the next ',' to dst */
150         while ( *src != 0x0 && *src != ',' && (len--)>0 ) *(dst++) = *(src++);
151
152         /* finalize the string */
153         *dst = 0x0;
154
155         return TRUE;
156 }
157
158 /*************************************************************************
159  * ParseField                   [SHELL32.58]
160  */
161 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
162 {
163         if (SHELL_OsIsUnicode())
164           return ParseFieldW(src, nField, dst, len);
165         return ParseFieldA(src, nField, dst, len);
166 }
167
168 /*************************************************************************
169  * GetFileNameFromBrowse                        [SHELL32.63]
170  *
171  */
172 BOOL WINAPI GetFileNameFromBrowse(
173         HWND hwndOwner,
174         LPSTR lpstrFile,
175         DWORD nMaxFile,
176         LPCSTR lpstrInitialDir,
177         LPCSTR lpstrDefExt,
178         LPCSTR lpstrFilter,
179         LPCSTR lpstrTitle)
180 {
181     HMODULE hmodule;
182     FARPROC pGetOpenFileNameA;
183     OPENFILENAMEA ofn;
184     BOOL ret;
185
186     TRACE("%p, %s, %ld, %s, %s, %s, %s)\n",
187           hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
188           lpstrFilter, lpstrTitle);
189
190     hmodule = LoadLibraryA("comdlg32.dll");
191     if(!hmodule) return FALSE;
192     pGetOpenFileNameA = GetProcAddress(hmodule, "GetOpenFileNameA");
193     if(!pGetOpenFileNameA)
194     {
195         FreeLibrary(hmodule);
196         return FALSE;
197     }
198
199     memset(&ofn, 0, sizeof(ofn));
200
201     ofn.lStructSize = sizeof(ofn);
202     ofn.hwndOwner = hwndOwner;
203     ofn.lpstrFilter = lpstrFilter;
204     ofn.lpstrFile = lpstrFile;
205     ofn.nMaxFile = nMaxFile;
206     ofn.lpstrInitialDir = lpstrInitialDir;
207     ofn.lpstrTitle = lpstrTitle;
208     ofn.lpstrDefExt = lpstrDefExt;
209     ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
210     ret = pGetOpenFileNameA(&ofn);
211
212     FreeLibrary(hmodule);
213     return ret;
214 }
215
216 /*************************************************************************
217  * SHGetSetSettings                             [SHELL32.68]
218  */
219 VOID WINAPI SHGetSetSettings(LPSHELLSTATE lpss, DWORD dwMask, BOOL bSet)
220 {
221   if(bSet)
222   {
223     FIXME("%p 0x%08lx TRUE\n", lpss, dwMask);
224   }
225   else
226   {
227     SHGetSettings((LPSHELLFLAGSTATE)lpss,dwMask);
228   }
229 }
230
231 /*************************************************************************
232  * SHGetSettings                                [SHELL32.@]
233  *
234  * NOTES
235  *  the registry path are for win98 (tested)
236  *  and possibly are the same in nt40
237  *
238  */
239 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
240 {
241         HKEY    hKey;
242         DWORD   dwData;
243         DWORD   dwDataSize = sizeof (DWORD);
244
245         TRACE("(%p 0x%08lx)\n",lpsfs,dwMask);
246
247         if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
248                                  0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
249           return;
250
251         if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
252           lpsfs->fShowExtensions  = ((dwData == 0) ?  0 : 1);
253
254         if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
255           lpsfs->fShowInfoTip  = ((dwData == 0) ?  0 : 1);
256
257         if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
258           lpsfs->fDontPrettyPath  = ((dwData == 0) ?  0 : 1);
259
260         if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
261           lpsfs->fHideIcons  = ((dwData == 0) ?  0 : 1);
262
263         if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
264           lpsfs->fMapNetDrvBtn  = ((dwData == 0) ?  0 : 1);
265
266         if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
267           lpsfs->fShowAttribCol  = ((dwData == 0) ?  0 : 1);
268
269         if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
270         { if (dwData == 0)
271           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 0;
272             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 0;
273           }
274           else if (dwData == 1)
275           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 1;
276             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 0;
277           }
278           else if (dwData == 2)
279           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 0;
280             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 1;
281           }
282         }
283         RegCloseKey (hKey);
284
285         TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
286 }
287
288 /*************************************************************************
289  * SHShellFolderView_Message                    [SHELL32.73]
290  *
291  * Send a message to an explorer cabinet window.
292  *
293  * PARAMS
294  *  hwndCabinet [I] The window containing the shellview to communicate with
295  *  dwMessage   [I] The SFVM message to send
296  *  dwParam     [I] Message parameter
297  *
298  * RETURNS
299  *  fixme.
300  *
301  * NOTES
302  *  Message SFVM_REARRANGE = 1
303  *
304  *    This message gets sent when a column gets clicked to instruct the
305  *    shell view to re-sort the item list. dwParam identifies the column
306  *    that was clicked.
307  */
308 LRESULT WINAPI SHShellFolderView_Message(
309         HWND hwndCabinet,
310         UINT uMessage,
311         LPARAM lParam)
312 {
313         FIXME("%p %08x %08lx stub\n",hwndCabinet, uMessage, lParam);
314         return 0;
315 }
316
317 /*************************************************************************
318  * RegisterShellHook                            [SHELL32.181]
319  *
320  * Register a shell hook.
321  *
322  * PARAMS
323  *      hwnd   [I]  Window handle
324  *      dwType [I]  Type of hook.
325  *
326  * NOTES
327  *     Exported by ordinal
328  */
329 BOOL WINAPI RegisterShellHook(
330         HWND hWnd,
331         DWORD dwType)
332 {
333         FIXME("(%p,0x%08lx):stub.\n",hWnd, dwType);
334         return TRUE;
335 }
336
337 /*************************************************************************
338  * ShellMessageBoxW                             [SHELL32.182]
339  *
340  * See ShellMessageBoxA.
341  */
342 int WINAPIV ShellMessageBoxW(
343         HINSTANCE hInstance,
344         HWND hWnd,
345         LPCWSTR lpText,
346         LPCWSTR lpCaption,
347         UINT uType,
348         ...)
349 {
350         WCHAR   szText[100],szTitle[100];
351         LPCWSTR pszText = szText, pszTitle = szTitle, pszTemp;
352         va_list args;
353         int     ret;
354
355         va_start(args, uType);
356         /* wvsprintfA(buf,fmt, args); */
357
358         TRACE("(%p,%p,%p,%p,%08x)\n",
359             hInstance,hWnd,lpText,lpCaption,uType);
360
361         if (IS_INTRESOURCE(lpCaption))
362           LoadStringW(hInstance, LOWORD(lpCaption), szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
363         else
364           pszTitle = lpCaption;
365
366         if (IS_INTRESOURCE(lpText))
367           LoadStringW(hInstance, LOWORD(lpText), szText, sizeof(szText)/sizeof(szText[0]));
368         else
369           pszText = lpText;
370
371         FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
372                        pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
373
374         va_end(args);
375
376         ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
377         LocalFree((HLOCAL)pszTemp);
378         return ret;
379 }
380
381 /*************************************************************************
382  * ShellMessageBoxA                             [SHELL32.183]
383  *
384  * Format and output an error message.
385  *
386  * PARAMS
387  *  hInstance [I] Instance handle of message creator
388  *  hWnd      [I] Window handle of message creator
389  *  lpText    [I] Resource Id of title or LPSTR
390  *  lpCaption [I] Resource Id of title or LPSTR
391  *  uType     [I] Type of error message
392  *
393  * RETURNS
394  *  A return value from MessageBoxA().
395  *
396  * NOTES
397  *     Exported by ordinal
398  */
399 int WINAPIV ShellMessageBoxA(
400         HINSTANCE hInstance,
401         HWND hWnd,
402         LPCSTR lpText,
403         LPCSTR lpCaption,
404         UINT uType,
405         ...)
406 {
407         char    szText[100],szTitle[100];
408         LPCSTR  pszText = szText, pszTitle = szTitle, pszTemp;
409         va_list args;
410         int     ret;
411
412         va_start(args, uType);
413         /* wvsprintfA(buf,fmt, args); */
414
415         TRACE("(%p,%p,%p,%p,%08x)\n",
416             hInstance,hWnd,lpText,lpCaption,uType);
417
418         if (IS_INTRESOURCE(lpCaption))
419           LoadStringA(hInstance, LOWORD(lpCaption), szTitle, sizeof(szTitle));
420         else
421           pszTitle = lpCaption;
422
423         if (IS_INTRESOURCE(lpText))
424           LoadStringA(hInstance, LOWORD(lpText), szText, sizeof(szText));
425         else
426           pszText = lpText;
427
428         FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
429                        pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
430
431         va_end(args);
432
433         ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
434         LocalFree((HLOCAL)pszTemp);
435         return ret;
436 }
437
438 /*************************************************************************
439  * SHRegisterDragDrop                           [SHELL32.86]
440  *
441  * NOTES
442  *     exported by ordinal
443  */
444 HRESULT WINAPI SHRegisterDragDrop(
445         HWND hWnd,
446         LPDROPTARGET pDropTarget)
447 {
448         FIXME("(%p,%p):stub.\n", hWnd, pDropTarget);
449         return RegisterDragDrop(hWnd, pDropTarget);
450 }
451
452 /*************************************************************************
453  * SHRevokeDragDrop                             [SHELL32.87]
454  *
455  * NOTES
456  *     exported by ordinal
457  */
458 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
459 {
460     FIXME("(%p):stub.\n",hWnd);
461     return RevokeDragDrop(hWnd);
462 }
463
464 /*************************************************************************
465  * SHDoDragDrop                                 [SHELL32.88]
466  *
467  * NOTES
468  *     exported by ordinal
469  */
470 HRESULT WINAPI SHDoDragDrop(
471         HWND hWnd,
472         LPDATAOBJECT lpDataObject,
473         LPDROPSOURCE lpDropSource,
474         DWORD dwOKEffect,
475         LPDWORD pdwEffect)
476 {
477     FIXME("(%p %p %p 0x%08lx %p):stub.\n",
478     hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
479         return DoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
480 }
481
482 /*************************************************************************
483  * ArrangeWindows                               [SHELL32.184]
484  *
485  */
486 WORD WINAPI ArrangeWindows(
487         HWND hwndParent,
488         DWORD dwReserved,
489         LPCRECT lpRect,
490         WORD cKids,
491         CONST HWND * lpKids)
492 {
493     FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
494            hwndParent, dwReserved, lpRect, cKids, lpKids);
495     return 0;
496 }
497
498 /*************************************************************************
499  * SignalFileOpen                               [SHELL32.103]
500  *
501  * NOTES
502  *     exported by ordinal
503  */
504 DWORD WINAPI
505 SignalFileOpen (DWORD dwParam1)
506 {
507     FIXME("(0x%08lx):stub.\n", dwParam1);
508
509     return 0;
510 }
511
512 /*************************************************************************
513  * SHADD_get_policy - helper function for SHAddToRecentDocs
514  *
515  * PARAMETERS
516  *   policy    [IN]  policy name (null termed string) to find
517  *   type      [OUT] ptr to DWORD to receive type
518  *   buffer    [OUT] ptr to area to hold data retrieved
519  *   len       [IN/OUT] ptr to DWORD holding size of buffer and getting
520  *                      length filled
521  *
522  * RETURNS
523  *   result of the SHQueryValueEx call
524  */
525 static INT SHADD_get_policy(LPSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
526 {
527     HKEY Policy_basekey;
528     INT ret;
529
530     /* Get the key for the policies location in the registry
531      */
532     if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
533                       "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
534                       0, KEY_READ, &Policy_basekey)) {
535
536         if (RegOpenKeyExA(HKEY_CURRENT_USER,
537                           "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
538                           0, KEY_READ, &Policy_basekey)) {
539             TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
540                   policy);
541             *len = 0;
542             return ERROR_FILE_NOT_FOUND;
543         }
544     }
545
546     /* Retrieve the data if it exists
547      */
548     ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
549     RegCloseKey(Policy_basekey);
550     return ret;
551 }
552
553
554 /*************************************************************************
555  * SHADD_compare_mru - helper function for SHAddToRecentDocs
556  *
557  * PARAMETERS
558  *   data1     [IN] data being looked for
559  *   data2     [IN] data in MRU
560  *   cbdata    [IN] length from FindMRUData call (not used)
561  *
562  * RETURNS
563  *   position within MRU list that data was added.
564  */
565 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
566 {
567     return lstrcmpiA(data1, data2);
568 }
569
570 /*************************************************************************
571  * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
572  *
573  * PARAMETERS
574  *   mruhandle    [IN] handle for created MRU list
575  *   doc_name     [IN] null termed pure doc name
576  *   new_lnk_name [IN] null termed path and file name for .lnk file
577  *   buffer       [IN/OUT] 2048 byte area to construct MRU data
578  *   len          [OUT] ptr to int to receive space used in buffer
579  *
580  * RETURNS
581  *   position within MRU list that data was added.
582  */
583 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
584                                      LPSTR buffer, INT *len)
585 {
586     LPSTR ptr;
587     INT wlen;
588
589     /*FIXME: Document:
590      *  RecentDocs MRU data structure seems to be:
591      *    +0h   document file name w/ terminating 0h
592      *    +nh   short int w/ size of remaining
593      *    +n+2h 02h 30h, or 01h 30h, or 00h 30h  -  unknown
594      *    +n+4h 10 bytes zeros  -   unknown
595      *    +n+eh shortcut file name w/ terminating 0h
596      *    +n+e+nh 3 zero bytes  -  unknown
597      */
598
599     /* Create the MRU data structure for "RecentDocs"
600          */
601     ptr = buffer;
602     lstrcpyA(ptr, doc_name);
603     ptr += (lstrlenA(buffer) + 1);
604     wlen= lstrlenA(new_lnk_name) + 1 + 12;
605     *((short int*)ptr) = wlen;
606     ptr += 2;   /* step past the length */
607     *(ptr++) = 0x30;  /* unknown reason */
608     *(ptr++) = 0;     /* unknown, but can be 0x00, 0x01, 0x02 */
609     memset(ptr, 0, 10);
610     ptr += 10;
611     lstrcpyA(ptr, new_lnk_name);
612     ptr += (lstrlenA(new_lnk_name) + 1);
613     memset(ptr, 0, 3);
614     ptr += 3;
615     *len = ptr - buffer;
616
617     /* Add the new entry into the MRU list
618      */
619     return AddMRUData(mruhandle, (LPCVOID)buffer, *len);
620 }
621
622 /*************************************************************************
623  * SHAddToRecentDocs                            [SHELL32.@]
624  *
625  * Modify (add/clear) Shell's list of recently used documents.
626  *
627  * PARAMETERS
628  *   uFlags  [IN] SHARD_PATHA, SHARD_PATHW or SHARD_PIDL
629  *   pv      [IN] string or pidl, NULL clears the list
630  *
631  * NOTES
632  *     exported by name
633  *
634  * FIXME
635  *  convert to unicode
636  */
637 void WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
638 {
639 /* If list is a string list lpfnCompare has the following prototype
640  * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
641  * for binary lists the prototype is
642  * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
643  * where cbData is the no. of bytes to compare.
644  * Need to check what return value means identical - 0?
645  */
646
647
648     UINT olderrormode;
649     HKEY HCUbasekey;
650     CHAR doc_name[MAX_PATH];
651     CHAR link_dir[MAX_PATH];
652     CHAR new_lnk_filepath[MAX_PATH];
653     CHAR new_lnk_name[MAX_PATH];
654     IMalloc *ppM;
655     LPITEMIDLIST pidl;
656     HWND hwnd = 0;       /* FIXME:  get real window handle */
657     INT ret;
658     DWORD data[64], datalen, type;
659
660     TRACE("%04x %p\n", uFlags, pv);
661
662     /*FIXME: Document:
663      *  RecentDocs MRU data structure seems to be:
664      *    +0h   document file name w/ terminating 0h
665      *    +nh   short int w/ size of remaining
666      *    +n+2h 02h 30h, or 01h 30h, or 00h 30h  -  unknown
667      *    +n+4h 10 bytes zeros  -   unknown
668      *    +n+eh shortcut file name w/ terminating 0h
669      *    +n+e+nh 3 zero bytes  -  unknown
670      */
671
672     /* See if we need to do anything.
673      */
674     datalen = 64;
675     ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
676     if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
677         ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
678         return;
679     }
680     if (ret == ERROR_SUCCESS) {
681         if (!( (type == REG_DWORD) ||
682                ((type == REG_BINARY) && (datalen == 4)) )) {
683             ERR("Error policy data for \"NoRecentDocsHistory\" not formatted correctly, type=%ld, len=%ld\n",
684                 type, datalen);
685             return;
686         }
687
688         TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
689         /* now test the actual policy value */
690         if ( data[0] != 0)
691             return;
692     }
693
694     /* Open key to where the necessary info is
695      */
696     /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
697      *        and the close should be done during the _DETACH. The resulting
698      *        key is stored in the DLL global data.
699      */
700     if (RegCreateKeyExA(HKEY_CURRENT_USER,
701                         "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
702                         0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
703         ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
704         return;
705     }
706
707     /* Get path to user's "Recent" directory
708      */
709     if(SUCCEEDED(SHGetMalloc(&ppM))) {
710         if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
711                                                  &pidl))) {
712             SHGetPathFromIDListA(pidl, link_dir);
713             IMalloc_Free(ppM, pidl);
714         }
715         else {
716             /* serious issues */
717             link_dir[0] = 0;
718             ERR("serious issues 1\n");
719         }
720         IMalloc_Release(ppM);
721     }
722     else {
723         /* serious issues */
724         link_dir[0] = 0;
725         ERR("serious issues 2\n");
726     }
727     TRACE("Users Recent dir %s\n", link_dir);
728
729     /* If no input, then go clear the lists */
730     if (!pv) {
731         /* clear user's Recent dir
732          */
733
734         /* FIXME: delete all files in "link_dir"
735          *
736          * while( more files ) {
737          *    lstrcpyA(old_lnk_name, link_dir);
738          *    PathAppendA(old_lnk_name, filenam);
739          *    DeleteFileA(old_lnk_name);
740          * }
741          */
742         FIXME("should delete all files in %s\\\n", link_dir);
743
744         /* clear MRU list
745          */
746         /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
747          *  HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
748          *  and naturally it fails w/ rc=2. It should do it against
749          *  HKEY_CURRENT_USER which is where it is stored, and where
750          *  the MRU routines expect it!!!!
751          */
752         RegDeleteKeyA(HCUbasekey, "RecentDocs");
753         RegCloseKey(HCUbasekey);
754         return;
755     }
756
757     /* Have data to add, the jobs to be done:
758      *   1. Add document to MRU list in registry "HKCU\Software\
759      *      Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
760      *   2. Add shortcut to document in the user's Recent directory
761      *      (CSIDL_RECENT).
762      *   3. Add shortcut to Start menu's Documents submenu.
763      */
764
765     /* Get the pure document name from the input
766      */
767     switch (uFlags)
768     {
769     case SHARD_PIDL:
770         SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
771         break;
772
773     case SHARD_PATHA:
774         lstrcpynA(doc_name, (LPCSTR)pv, MAX_PATH);
775         break;
776
777     case SHARD_PATHW:
778         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pv, -1, doc_name, MAX_PATH, NULL, NULL);
779         break;
780
781     default:
782         FIXME("Unsupported flags: %u\n", uFlags);
783         return;
784     }
785
786     TRACE("full document name %s\n", debugstr_a(doc_name));
787     PathStripPathA(doc_name);
788     TRACE("stripped document name %s\n", debugstr_a(doc_name));
789
790
791     /* ***  JOB 1: Update registry for ...\Explorer\RecentDocs list  *** */
792
793     {  /* on input needs:
794         *      doc_name    -  pure file-spec, no path
795         *      link_dir    -  path to the user's Recent directory
796         *      HCUbasekey  -  key of ...Windows\CurrentVersion\Explorer" node
797         * creates:
798         *      new_lnk_name-  pure file-spec, no path for new .lnk file
799         *      new_lnk_filepath
800         *                  -  path and file name of new .lnk file
801         */
802         CREATEMRULISTA mymru;
803         HANDLE mruhandle;
804         INT len, pos, bufused, err;
805         INT i;
806         DWORD attr;
807         CHAR buffer[2048];
808         CHAR *ptr;
809         CHAR old_lnk_name[MAX_PATH];
810         short int slen;
811
812         mymru.cbSize = sizeof(CREATEMRULISTA);
813         mymru.nMaxItems = 15;
814         mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
815         mymru.hKey = HCUbasekey;
816         mymru.lpszSubKey = "RecentDocs";
817         mymru.lpfnCompare = &SHADD_compare_mru;
818         mruhandle = CreateMRUListA(&mymru);
819         if (!mruhandle) {
820             /* MRU failed */
821             ERR("MRU processing failed, handle zero\n");
822             RegCloseKey(HCUbasekey);
823             return;
824         }
825         len = lstrlenA(doc_name);
826         pos = FindMRUData(mruhandle, doc_name, len, 0);
827
828         /* Now get the MRU entry that will be replaced
829          * and delete the .lnk file for it
830          */
831         if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
832                                     buffer, 2048)) != -1) {
833             ptr = buffer;
834             ptr += (lstrlenA(buffer) + 1);
835             slen = *((short int*)ptr);
836             ptr += 2;  /* skip the length area */
837             if (bufused >= slen + (ptr-buffer)) {
838                 /* buffer size looks good */
839                 ptr += 12; /* get to string */
840                 len = bufused - (ptr-buffer);  /* get length of buf remaining */
841                 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
842                     /* appears to be good string */
843                     lstrcpyA(old_lnk_name, link_dir);
844                     PathAppendA(old_lnk_name, ptr);
845                     if (!DeleteFileA(old_lnk_name)) {
846                         if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) {
847                             if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
848                                 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
849                                     old_lnk_name, err, attr);
850                             }
851                             else {
852                                 TRACE("old .lnk file %s did not exist\n",
853                                       old_lnk_name);
854                             }
855                         }
856                         else {
857                             ERR("Delete for %s failed, attr=%08lx\n",
858                                 old_lnk_name, attr);
859                         }
860                     }
861                     else {
862                         TRACE("deleted old .lnk file %s\n", old_lnk_name);
863                     }
864                 }
865             }
866         }
867
868         /* Create usable .lnk file name for the "Recent" directory
869          */
870         wsprintfA(new_lnk_name, "%s.lnk", doc_name);
871         lstrcpyA(new_lnk_filepath, link_dir);
872         PathAppendA(new_lnk_filepath, new_lnk_name);
873         i = 1;
874         olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
875         while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
876             i++;
877             wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
878             lstrcpyA(new_lnk_filepath, link_dir);
879             PathAppendA(new_lnk_filepath, new_lnk_name);
880         }
881         SetErrorMode(olderrormode);
882         TRACE("new shortcut will be %s\n", new_lnk_filepath);
883
884         /* Now add the new MRU entry and data
885          */
886         pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
887                                         buffer, &len);
888         FreeMRUList(mruhandle);
889         TRACE("Updated MRU list, new doc is position %d\n", pos);
890     }
891
892     /* ***  JOB 2: Create shortcut in user's "Recent" directory  *** */
893
894     {  /* on input needs:
895         *      doc_name    -  pure file-spec, no path
896         *      new_lnk_filepath
897         *                  -  path and file name of new .lnk file
898         *      uFlags[in]  -  flags on call to SHAddToRecentDocs
899         *      pv[in]      -  document path/pidl on call to SHAddToRecentDocs
900         */
901         IShellLinkA *psl = NULL;
902         IPersistFile *pPf = NULL;
903         HRESULT hres;
904         CHAR desc[MAX_PATH];
905         WCHAR widelink[MAX_PATH];
906
907         CoInitialize(0);
908
909         hres = CoCreateInstance( &CLSID_ShellLink,
910                                  NULL,
911                                  CLSCTX_INPROC_SERVER,
912                                  &IID_IShellLinkA,
913                                  (LPVOID )&psl);
914         if(SUCCEEDED(hres)) {
915
916             hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
917                                              (LPVOID *)&pPf);
918             if(FAILED(hres)) {
919                 /* bombed */
920                 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
921                 goto fail;
922             }
923
924             /* Set the document path or pidl */
925             if (uFlags == SHARD_PIDL) {
926                 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
927             } else {
928                 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
929             }
930             if(FAILED(hres)) {
931                 /* bombed */
932                 ERR("failed Set{IDList|Path} %08lx\n", hres);
933                 goto fail;
934             }
935
936             lstrcpyA(desc, "Shortcut to ");
937             lstrcatA(desc, doc_name);
938             hres = IShellLinkA_SetDescription(psl, desc);
939             if(FAILED(hres)) {
940                 /* bombed */
941                 ERR("failed SetDescription %08lx\n", hres);
942                 goto fail;
943             }
944
945             MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
946                                 widelink, MAX_PATH);
947             /* create the short cut */
948             hres = IPersistFile_Save(pPf, widelink, TRUE);
949             if(FAILED(hres)) {
950                 /* bombed */
951                 ERR("failed IPersistFile::Save %08lx\n", hres);
952                 IPersistFile_Release(pPf);
953                 IShellLinkA_Release(psl);
954                 goto fail;
955             }
956             hres = IPersistFile_SaveCompleted(pPf, widelink);
957             IPersistFile_Release(pPf);
958             IShellLinkA_Release(psl);
959             TRACE("shortcut %s has been created, result=%08lx\n",
960                   new_lnk_filepath, hres);
961         }
962         else {
963             ERR("CoCreateInstance failed, hres=%08lx\n", hres);
964         }
965     }
966
967  fail:
968     CoUninitialize();
969
970     /* all done */
971     RegCloseKey(HCUbasekey);
972     return;
973 }
974
975 /*************************************************************************
976  * SHCreateShellFolderViewEx                    [SHELL32.174]
977  *
978  * Create a new instance of the default Shell folder view object.
979  *
980  * RETURNS
981  *  Success: S_OK
982  *  Failure: error value
983  *
984  * NOTES
985  *  see IShellFolder::CreateViewObject
986  */
987 HRESULT WINAPI SHCreateShellFolderViewEx(
988         LPCSFV psvcbi,    /* [in] shelltemplate struct */
989         IShellView **ppv) /* [out] IShellView pointer */
990 {
991         IShellView * psf;
992         HRESULT hRes;
993
994         TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=%p\n",
995           psvcbi->pshf, psvcbi->pidl, psvcbi->pfnCallback,
996           psvcbi->fvm, psvcbi->psvOuter);
997
998         psf = IShellView_Constructor(psvcbi->pshf);
999
1000         if (!psf)
1001           return E_OUTOFMEMORY;
1002
1003         IShellView_AddRef(psf);
1004         hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
1005         IShellView_Release(psf);
1006
1007         return hRes;
1008 }
1009 /*************************************************************************
1010  *  SHWinHelp                                   [SHELL32.127]
1011  *
1012  */
1013 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
1014 {       FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
1015         return 0;
1016 }
1017 /*************************************************************************
1018  *  SHRunControlPanel [SHELL32.161]
1019  *
1020  */
1021 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
1022 {       FIXME("0x%08lx 0x%08lx stub\n",x,z);
1023         return 0;
1024 }
1025
1026 static LPUNKNOWN SHELL32_IExplorerInterface=0;
1027 /*************************************************************************
1028  * SHSetInstanceExplorer                        [SHELL32.176]
1029  *
1030  * NOTES
1031  *  Sets the interface
1032  */
1033 VOID WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
1034 {       TRACE("%p\n", lpUnknown);
1035         SHELL32_IExplorerInterface = lpUnknown;
1036 }
1037 /*************************************************************************
1038  * SHGetInstanceExplorer                        [SHELL32.@]
1039  *
1040  * NOTES
1041  *  gets the interface pointer of the explorer and a reference
1042  */
1043 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
1044 {       TRACE("%p\n", lpUnknown);
1045
1046         *lpUnknown = SHELL32_IExplorerInterface;
1047
1048         if (!SHELL32_IExplorerInterface)
1049           return E_FAIL;
1050
1051         IUnknown_AddRef(SHELL32_IExplorerInterface);
1052         return NOERROR;
1053 }
1054 /*************************************************************************
1055  * SHFreeUnusedLibraries                        [SHELL32.123]
1056  *
1057  * NOTES
1058  *  exported by name
1059  */
1060 void WINAPI SHFreeUnusedLibraries (void)
1061 {
1062         FIXME("stub\n");
1063 }
1064 /*************************************************************************
1065  * DAD_AutoScroll                               [SHELL32.129]
1066  *
1067  */
1068 BOOL WINAPI DAD_AutoScroll(HWND hwnd, AUTO_SCROLL_DATA *samples, LPPOINT pt)
1069 {
1070     FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1071     return 0;
1072 }
1073 /*************************************************************************
1074  * DAD_DragEnter                                [SHELL32.130]
1075  *
1076  */
1077 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1078 {
1079     FIXME("hwnd = %p\n",hwnd);
1080     return FALSE;
1081 }
1082 /*************************************************************************
1083  * DAD_DragEnterEx                              [SHELL32.131]
1084  *
1085  */
1086 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1087 {
1088     FIXME("hwnd = %p (%ld,%ld)\n",hwnd,p.x,p.y);
1089     return FALSE;
1090 }
1091 /*************************************************************************
1092  * DAD_DragMove                         [SHELL32.134]
1093  *
1094  */
1095 BOOL WINAPI DAD_DragMove(POINT p)
1096 {
1097     FIXME("(%ld,%ld)\n",p.x,p.y);
1098     return FALSE;
1099 }
1100 /*************************************************************************
1101  * DAD_DragLeave                                [SHELL32.132]
1102  *
1103  */
1104 BOOL WINAPI DAD_DragLeave(VOID)
1105 {
1106     FIXME("\n");
1107     return FALSE;
1108 }
1109 /*************************************************************************
1110  * DAD_SetDragImage                             [SHELL32.136]
1111  *
1112  * NOTES
1113  *  exported by name
1114  */
1115 BOOL WINAPI DAD_SetDragImage(
1116         HIMAGELIST himlTrack,
1117         LPPOINT lppt)
1118 {
1119         FIXME("%p %p stub\n",himlTrack, lppt);
1120   return 0;
1121 }
1122 /*************************************************************************
1123  * DAD_ShowDragImage                            [SHELL32.137]
1124  *
1125  * NOTES
1126  *  exported by name
1127  */
1128 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1129 {
1130         FIXME("0x%08x stub\n",bShow);
1131         return 0;
1132 }
1133
1134 static const WCHAR szwCabLocation[] = {
1135   'S','o','f','t','w','a','r','e','\\',
1136   'M','i','c','r','o','s','o','f','t','\\',
1137   'W','i','n','d','o','w','s','\\',
1138   'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1139   'E','x','p','l','o','r','e','r','\\',
1140   'C','a','b','i','n','e','t','S','t','a','t','e',0
1141 };
1142
1143 static const WCHAR szwSettings[] = { 'S','e','t','t','i','n','g','s',0 };
1144
1145 /*************************************************************************
1146  * ReadCabinetState                             [SHELL32.651] NT 4.0
1147  *
1148  */
1149 BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
1150 {
1151         HKEY hkey = 0;
1152         DWORD type, r;
1153
1154         TRACE("%p %d\n", cs, length);
1155
1156         if( (cs == NULL) || (length < (int)sizeof(*cs))  )
1157                 return FALSE;
1158
1159         r = RegOpenKeyW( HKEY_CURRENT_USER, szwCabLocation, &hkey );
1160         if( r == ERROR_SUCCESS )
1161         {
1162                 type = REG_BINARY;
1163                 r = RegQueryValueExW( hkey, szwSettings, 
1164                         NULL, &type, (LPBYTE)cs, (LPDWORD)&length );
1165                 RegCloseKey( hkey );
1166                         
1167         }
1168
1169         /* if we can't read from the registry, create default values */
1170         if ( (r != ERROR_SUCCESS) || (cs->cLength < sizeof(*cs)) ||
1171                 (cs->cLength != length) )
1172         {
1173                 ERR("Initializing shell cabinet settings\n");
1174                 memset(cs, 0, sizeof(*cs));
1175                 cs->cLength          = sizeof(*cs);
1176                 cs->nVersion         = 2;
1177                 cs->fFullPathTitle   = FALSE;
1178                 cs->fSaveLocalView   = TRUE;
1179                 cs->fNotShell        = FALSE;
1180                 cs->fSimpleDefault   = TRUE;
1181                 cs->fDontShowDescBar = FALSE;
1182                 cs->fNewWindowMode   = FALSE;
1183                 cs->fShowCompColor   = FALSE;
1184                 cs->fDontPrettyNames = FALSE;
1185                 cs->fAdminsCreateCommonGroups = TRUE;
1186                 cs->fMenuEnumFilter  = 96;
1187         }
1188         
1189         return TRUE;
1190 }
1191
1192 /*************************************************************************
1193  * WriteCabinetState                            [SHELL32.652] NT 4.0
1194  *
1195  */
1196 BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
1197 {
1198         DWORD r;
1199         HKEY hkey = 0;
1200
1201         TRACE("%p\n",cs);
1202
1203         if( cs == NULL )
1204                 return FALSE;
1205
1206         r = RegCreateKeyExW( HKEY_CURRENT_USER, szwCabLocation, 0,
1207                  NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
1208         if( r == ERROR_SUCCESS )
1209         {
1210                 r = RegSetValueExW( hkey, szwSettings, 0, 
1211                         REG_BINARY, (LPBYTE) cs, cs->cLength);
1212
1213                 RegCloseKey( hkey );
1214         }
1215
1216         return (r==ERROR_SUCCESS);
1217 }
1218
1219 /*************************************************************************
1220  * FileIconInit                                 [SHELL32.660]
1221  *
1222  */
1223 BOOL WINAPI FileIconInit(BOOL bFullInit)
1224 {       FIXME("(%s)\n", bFullInit ? "true" : "false");
1225         return 0;
1226 }
1227 /*************************************************************************
1228  * IsUserAdmin                                  [SHELL32.680] NT 4.0
1229  *
1230  */
1231 HRESULT WINAPI IsUserAdmin(void)
1232 {       FIXME("stub\n");
1233         return TRUE;
1234 }
1235
1236 /*************************************************************************
1237  * SHAllocShared                                [SHELL32.520]
1238  *
1239  * See shlwapi.SHAllocShared
1240  */
1241 HANDLE WINAPI SHAllocShared(LPVOID lpvData, DWORD dwSize, DWORD dwProcId)
1242 {
1243     GET_FUNC(pSHAllocShared, shlwapi, (char*)7, NULL);
1244     return pSHAllocShared(lpvData, dwSize, dwProcId);
1245 }
1246
1247 /*************************************************************************
1248  * SHLockShared                                 [SHELL32.521]
1249  *
1250  * See shlwapi.SHLockShared
1251  */
1252 LPVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
1253 {
1254     GET_FUNC(pSHLockShared, shlwapi, (char*)8, NULL);
1255     return pSHLockShared(hShared, dwProcId);
1256 }
1257
1258 /*************************************************************************
1259  * SHUnlockShared                               [SHELL32.522]
1260  *
1261  * See shlwapi.SHUnlockShared
1262  */
1263 BOOL WINAPI SHUnlockShared(LPVOID lpView)
1264 {
1265     GET_FUNC(pSHUnlockShared, shlwapi, (char*)9, FALSE);
1266     return pSHUnlockShared(lpView);
1267 }
1268
1269 /*************************************************************************
1270  * SHFreeShared                                 [SHELL32.523]
1271  *
1272  * See shlwapi.SHFreeShared
1273  */
1274 BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
1275 {
1276     GET_FUNC(pSHFreeShared, shlwapi, (char*)10, FALSE);
1277     return pSHFreeShared(hShared, dwProcId);
1278 }
1279
1280 /*************************************************************************
1281  * SetAppStartingCursor                         [SHELL32.99]
1282  */
1283 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1284 {       FIXME("hwnd=%p 0x%04lx stub\n",u,v );
1285         return 0;
1286 }
1287 /*************************************************************************
1288  * SHLoadOLE                                    [SHELL32.151]
1289  *
1290  */
1291 HRESULT WINAPI SHLoadOLE(LPARAM lParam)
1292 {       FIXME("0x%04lx stub\n",lParam);
1293         return S_OK;
1294 }
1295 /*************************************************************************
1296  * DriveType                                    [SHELL32.64]
1297  *
1298  */
1299 HRESULT WINAPI DriveType(DWORD u)
1300 {       FIXME("0x%04lx stub\n",u);
1301         return 0;
1302 }
1303 /*************************************************************************
1304  * SHAbortInvokeCommand                         [SHELL32.198]
1305  *
1306  */
1307 HRESULT WINAPI SHAbortInvokeCommand(void)
1308 {       FIXME("stub\n");
1309         return 1;
1310 }
1311 /*************************************************************************
1312  * SHOutOfMemoryMessageBox                      [SHELL32.126]
1313  *
1314  */
1315 int WINAPI SHOutOfMemoryMessageBox(
1316         HWND hwndOwner,
1317         LPCSTR lpCaption,
1318         UINT uType)
1319 {
1320         FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1321         return 0;
1322 }
1323 /*************************************************************************
1324  * SHFlushClipboard                             [SHELL32.121]
1325  *
1326  */
1327 HRESULT WINAPI SHFlushClipboard(void)
1328 {       FIXME("stub\n");
1329         return 1;
1330 }
1331
1332 /*************************************************************************
1333  * SHWaitForFileToOpen                          [SHELL32.97]
1334  *
1335  */
1336 BOOL WINAPI SHWaitForFileToOpen(
1337         LPCITEMIDLIST pidl,
1338         DWORD dwFlags,
1339         DWORD dwTimeout)
1340 {
1341         FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1342         return 0;
1343 }
1344
1345 /************************************************************************
1346  *      @                               [SHELL32.654]
1347  *
1348  * NOTES
1349  *  first parameter seems to be a pointer (same as passed to WriteCabinetState)
1350  *  second one could be a size (0x0c). The size is the same as the structure saved to
1351  *  HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1352  *  I'm (js) guessing: this one is just ReadCabinetState ;-)
1353  */
1354 HRESULT WINAPI shell32_654 (CABINETSTATE *cs, int length)
1355 {
1356         TRACE("%p %d\n",cs,length);
1357         return ReadCabinetState(cs,length);
1358 }
1359
1360 /************************************************************************
1361  *      RLBuildListOfPaths                      [SHELL32.146]
1362  *
1363  * NOTES
1364  *   builds a DPA
1365  */
1366 DWORD WINAPI RLBuildListOfPaths (void)
1367 {       FIXME("stub\n");
1368         return 0;
1369 }
1370 /************************************************************************
1371  *      SHValidateUNC                           [SHELL32.173]
1372  *
1373  */
1374 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1375 {
1376         FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1377         return 0;
1378 }
1379
1380 /************************************************************************
1381  *      DoEnvironmentSubstA                     [SHELL32.@]
1382  *
1383  * Replace %KEYWORD% in the str with the value of variable KEYWORD
1384  * from environment. If it is not found the %KEYWORD% is left
1385  * intact. If the buffer is too small, str is not modified.
1386  *
1387  * PARAMS
1388  *  pszString  [I] '\0' terminated string with %keyword%.
1389  *             [O] '\0' terminated string with %keyword% substituted.
1390  *  cchString  [I] size of str.
1391  *
1392  * RETURNS
1393  *     cchString length in the HIWORD;
1394  *     TRUE in LOWORD if subst was successful and FALSE in other case
1395  */
1396 DWORD WINAPI DoEnvironmentSubstA(LPSTR pszString, UINT cchString)
1397 {
1398     LPSTR dst;
1399     BOOL res = FALSE;
1400     FIXME("(%s, %d) stub\n", debugstr_a(pszString), cchString);
1401     if (pszString == NULL) /* Really return 0? */
1402         return 0;
1403     if ((dst = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(CHAR))))
1404     {
1405         DWORD num = ExpandEnvironmentStringsA(pszString, dst, cchString);
1406         if (num && num < cchString) /* dest buffer is too small */
1407         {
1408             res = TRUE;
1409             memcpy(pszString, dst, num);
1410         }
1411         HeapFree(GetProcessHeap(), 0, dst);
1412     }
1413     return MAKELONG(res,cchString); /* Always cchString? */
1414 }
1415
1416 /************************************************************************
1417  *      DoEnvironmentSubstW                     [SHELL32.@]
1418  *
1419  * See DoEnvironmentSubstA.  
1420  */
1421 DWORD WINAPI DoEnvironmentSubstW(LPWSTR pszString, UINT cchString)
1422 {
1423         FIXME("(%s, %d): stub\n", debugstr_w(pszString), cchString);
1424         return MAKELONG(FALSE,cchString);
1425 }
1426
1427 /************************************************************************
1428  *      DoEnvironmentSubst                      [SHELL32.53]
1429  *
1430  * See DoEnvironmentSubstA.  
1431  */
1432 DWORD WINAPI DoEnvironmentSubstAW(LPVOID x, UINT y)
1433 {
1434     if (SHELL_OsIsUnicode())
1435         return DoEnvironmentSubstW(x, y);
1436     return DoEnvironmentSubstA(x, y);
1437 }
1438
1439 /*************************************************************************
1440  *      @                             [SHELL32.243]
1441  *
1442  * Win98+ by-ordinal routine.  In Win98 this routine returns zero and
1443  * does nothing else.  Possibly this does something in NT or SHELL32 5.0?
1444  *
1445  */
1446
1447 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1448 {
1449   return FALSE;
1450 }
1451
1452 /*************************************************************************
1453  *      @       [SHELL32.714]
1454  */
1455 DWORD WINAPI SHELL32_714(LPVOID x)
1456 {
1457         FIXME("(%s)stub\n", debugstr_w(x));
1458         return 0;
1459 }
1460
1461 /*************************************************************************
1462  *      SHAddFromPropSheetExtArray      [SHELL32.167]
1463  */
1464 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1465 {
1466         FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1467         return 0;
1468 }
1469
1470 /*************************************************************************
1471  *      SHCreatePropSheetExtArray       [SHELL32.168]
1472  */
1473 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1474 {
1475         FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1476         return 0;
1477 }
1478
1479 /*************************************************************************
1480  *      SHReplaceFromPropSheetExtArray  [SHELL32.170]
1481  */
1482 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1483 {
1484         FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1485         return 0;
1486 }
1487
1488 /*************************************************************************
1489  *      SHDestroyPropSheetExtArray      [SHELL32.169]
1490  */
1491 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1492 {
1493         FIXME("(%08lx)stub\n", a);
1494         return 0;
1495 }
1496
1497 /*************************************************************************
1498  *      CIDLData_CreateFromIDArray      [SHELL32.83]
1499  *
1500  *  Create IDataObject from PIDLs??
1501  */
1502 HRESULT WINAPI CIDLData_CreateFromIDArray(
1503         LPCITEMIDLIST pidlFolder,
1504         DWORD cpidlFiles,
1505         LPCITEMIDLIST *lppidlFiles,
1506         LPDATAOBJECT *ppdataObject)
1507 {
1508     UINT i;
1509     HWND hwnd = 0;   /*FIXME: who should be hwnd of owner? set to desktop */
1510
1511     TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1512     if (TRACE_ON(pidl))
1513     {
1514         pdump (pidlFolder);
1515         for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1516     }
1517     *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1518                                              lppidlFiles, cpidlFiles);
1519     if (*ppdataObject) return S_OK;
1520     return E_OUTOFMEMORY;
1521 }
1522
1523 /*************************************************************************
1524  * SHCreateStdEnumFmtEtc                        [SHELL32.74]
1525  *
1526  * NOTES
1527  *
1528  */
1529 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1530         DWORD cFormats,
1531         const FORMATETC *lpFormats,
1532         LPENUMFORMATETC *ppenumFormatetc)
1533 {
1534         IEnumFORMATETC *pef;
1535         HRESULT hRes;
1536         TRACE("cf=%ld fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1537
1538         pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1539         if (!pef)
1540           return E_OUTOFMEMORY;
1541
1542         IEnumFORMATETC_AddRef(pef);
1543         hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1544         IEnumFORMATETC_Release(pef);
1545
1546         return hRes;
1547 }
1548
1549
1550 /*************************************************************************
1551  *              SHELL32_256 (SHELL32.256)
1552  */
1553 HRESULT WINAPI SHELL32_256(LPDWORD lpdw0, LPDWORD lpdw1)
1554 {
1555     HRESULT ret = S_OK;
1556
1557     FIXME("stub %p 0x%08lx %p\n", lpdw0, lpdw0 ? *lpdw0 : 0, lpdw1);
1558
1559     if (!lpdw0 || *lpdw0 != 0x10)
1560         ret = E_INVALIDARG;
1561     else
1562     {
1563         LPVOID lpdata = 0;/*LocalAlloc(LMEM_ZEROINIT, 0x4E4);*/
1564
1565         if (!lpdata)
1566             ret = E_OUTOFMEMORY;
1567         else
1568         {
1569             /* Initialize and return unknown lpdata structure */
1570         }
1571     }
1572
1573     return ret;
1574 }
1575
1576 /*************************************************************************
1577  *              SHFindFiles (SHELL32.90)
1578  */
1579 BOOL WINAPI SHFindFiles( LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlSaveFile )
1580 {
1581     FIXME("%p %p\n", pidlFolder, pidlSaveFile );
1582     return FALSE;
1583 }
1584
1585 /*************************************************************************
1586  *              SHUpdateImageW (SHELL32.192)
1587  *
1588  * Notifies the shell that an icon in the system image list has been changed.
1589  *
1590  * PARAMS
1591  *  pszHashItem [I] Path to file that contains the icon.
1592  *  iIndex      [I] Zero-based index of the icon in the file.
1593  *  uFlags      [I] Flags determining the icon attributes. See notes.
1594  *  iImageIndex [I] Index of the icon in the system image list.
1595  *
1596  * RETURNS
1597  *  Nothing
1598  *
1599  * NOTES
1600  *  uFlags can be one or more of the following flags:
1601  *  GIL_NOTFILENAME - pszHashItem is not a file name.
1602  *  GIL_SIMULATEDOC - Create a document icon using the specified icon.
1603  */
1604 void WINAPI SHUpdateImageW(LPCWSTR pszHashItem, int iIndex, UINT uFlags, int iImageIndex)
1605 {
1606     FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_w(pszHashItem), iIndex, uFlags, iImageIndex);
1607 }
1608
1609 /*************************************************************************
1610  *              SHUpdateImageA (SHELL32.191)
1611  *
1612  * See SHUpdateImageW.
1613  */
1614 VOID WINAPI SHUpdateImageA(LPCSTR pszHashItem, INT iIndex, UINT uFlags, INT iImageIndex)
1615 {
1616     FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_a(pszHashItem), iIndex, uFlags, iImageIndex);
1617 }
1618
1619 INT WINAPI SHHandleUpdateImage(LPCITEMIDLIST pidlExtra)
1620 {
1621     FIXME("%p - stub\n", pidlExtra);
1622
1623     return -1;
1624 }
1625
1626 BOOL WINAPI SHObjectProperties(HWND hwnd, DWORD dwType, LPCWSTR szObject, LPCWSTR szPage)
1627 {
1628     FIXME("%p, 0x%08lx, %s, %s - stub\n", hwnd, dwType, debugstr_w(szObject), debugstr_w(szPage));
1629
1630     return TRUE;
1631 }
1632
1633 BOOL WINAPI SHGetNewLinkInfoA(LPCSTR pszLinkTo, LPCSTR pszDir, LPSTR pszName, BOOL *pfMustCopy,
1634                               UINT uFlags)
1635 {
1636     FIXME("%s, %s, %p, %p, 0x%08x - stub\n", debugstr_a(pszLinkTo), debugstr_a(pszDir),
1637           pszName, pfMustCopy, uFlags);
1638
1639     return FALSE;
1640 }
1641
1642 BOOL WINAPI SHGetNewLinkInfoW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName, BOOL *pfMustCopy,
1643                               UINT uFlags)
1644 {
1645     FIXME("%s, %s, %p, %p, 0x%08x - stub\n", debugstr_w(pszLinkTo), debugstr_w(pszDir),
1646           pszName, pfMustCopy, uFlags);
1647
1648     return FALSE;
1649 }
1650
1651 HRESULT WINAPI SHStartNetConnectionDialog(HWND hwnd, LPCSTR pszRemoteName, DWORD dwType)
1652 {
1653     FIXME("%p, %s, 0x%08lx - stub\n", hwnd, debugstr_a(pszRemoteName), dwType);
1654
1655     return S_OK;
1656 }
1657
1658 HRESULT WINAPI SHEmptyRecycleBinA(HWND hwnd, LPCSTR pszRootPath, DWORD dwFlags)
1659 {
1660     FIXME("%p, %s, 0x%08lx - stub\n", hwnd, debugstr_a(pszRootPath), dwFlags);
1661
1662     return S_OK;
1663 }
1664
1665 HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags)
1666 {
1667     FIXME("%p, %s, 0x%08lx - stub\n", hwnd, debugstr_w(pszRootPath), dwFlags);
1668
1669     return S_OK;
1670 }
1671
1672 DWORD WINAPI SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options)
1673 {
1674     FIXME("%p, 0x%08x, 0x%08x, 0x%08x - stub\n", hwnd, drive, fmtID, options);
1675
1676     return SHFMT_NOFORMAT;
1677 }
1678
1679 HRESULT WINAPI SHQueryRecycleBinA(LPCSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
1680 {
1681     FIXME("%s, %p - stub\n", debugstr_a(pszRootPath), pSHQueryRBInfo);
1682
1683     pSHQueryRBInfo->i64Size = 0;
1684     pSHQueryRBInfo->i64NumItems = 0;
1685
1686     return S_OK;
1687 }
1688
1689 HRESULT WINAPI SHQueryRecycleBinW(LPCWSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
1690 {
1691     FIXME("%s, %p - stub\n", debugstr_w(pszRootPath), pSHQueryRBInfo);
1692
1693     pSHQueryRBInfo->i64Size = 0;
1694     pSHQueryRBInfo->i64NumItems = 0;
1695
1696     return S_OK;
1697 }