crypt32: Test decoding a big CRL.
[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
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  * Probably equivalent to RegisterDragDrop but under Windows 9x it could use the
442  * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
443  * for details
444  *
445  * NOTES
446  *     exported by ordinal
447  *
448  * SEE ALSO
449  *     RegisterDragDrop, SHLoadOLE
450  */
451 HRESULT WINAPI SHRegisterDragDrop(
452         HWND hWnd,
453         LPDROPTARGET pDropTarget)
454 {
455         FIXME("(%p,%p):stub.\n", hWnd, pDropTarget);
456         return RegisterDragDrop(hWnd, pDropTarget);
457 }
458
459 /*************************************************************************
460  * SHRevokeDragDrop                             [SHELL32.87]
461  *
462  * Probably equivalent to RevokeDragDrop but under Windows 9x it could use the
463  * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
464  * for details
465  *
466  * NOTES
467  *     exported by ordinal
468  *
469  * SEE ALSO
470  *     RevokeDragDrop, SHLoadOLE
471  */
472 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
473 {
474     FIXME("(%p):stub.\n",hWnd);
475     return RevokeDragDrop(hWnd);
476 }
477
478 /*************************************************************************
479  * SHDoDragDrop                                 [SHELL32.88]
480  *
481  * Probably equivalent to DoDragDrop but under Windows 9x it could use the
482  * shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
483  * for details
484  *
485  * NOTES
486  *     exported by ordinal
487  *
488  * SEE ALSO
489  *     DoDragDrop, SHLoadOLE
490  */
491 HRESULT WINAPI SHDoDragDrop(
492         HWND hWnd,
493         LPDATAOBJECT lpDataObject,
494         LPDROPSOURCE lpDropSource,
495         DWORD dwOKEffect,
496         LPDWORD pdwEffect)
497 {
498     FIXME("(%p %p %p 0x%08lx %p):stub.\n",
499     hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
500         return DoDragDrop(lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
501 }
502
503 /*************************************************************************
504  * ArrangeWindows                               [SHELL32.184]
505  *
506  */
507 WORD WINAPI ArrangeWindows(
508         HWND hwndParent,
509         DWORD dwReserved,
510         LPCRECT lpRect,
511         WORD cKids,
512         CONST HWND * lpKids)
513 {
514     FIXME("(%p 0x%08lx %p 0x%04x %p):stub.\n",
515            hwndParent, dwReserved, lpRect, cKids, lpKids);
516     return 0;
517 }
518
519 /*************************************************************************
520  * SignalFileOpen                               [SHELL32.103]
521  *
522  * NOTES
523  *     exported by ordinal
524  */
525 DWORD WINAPI
526 SignalFileOpen (DWORD dwParam1)
527 {
528     FIXME("(0x%08lx):stub.\n", dwParam1);
529
530     return 0;
531 }
532
533 /*************************************************************************
534  * SHADD_get_policy - helper function for SHAddToRecentDocs
535  *
536  * PARAMETERS
537  *   policy    [IN]  policy name (null termed string) to find
538  *   type      [OUT] ptr to DWORD to receive type
539  *   buffer    [OUT] ptr to area to hold data retrieved
540  *   len       [IN/OUT] ptr to DWORD holding size of buffer and getting
541  *                      length filled
542  *
543  * RETURNS
544  *   result of the SHQueryValueEx call
545  */
546 static INT SHADD_get_policy(LPCSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
547 {
548     HKEY Policy_basekey;
549     INT ret;
550
551     /* Get the key for the policies location in the registry
552      */
553     if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
554                       "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
555                       0, KEY_READ, &Policy_basekey)) {
556
557         if (RegOpenKeyExA(HKEY_CURRENT_USER,
558                           "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
559                           0, KEY_READ, &Policy_basekey)) {
560             TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
561                   policy);
562             *len = 0;
563             return ERROR_FILE_NOT_FOUND;
564         }
565     }
566
567     /* Retrieve the data if it exists
568      */
569     ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
570     RegCloseKey(Policy_basekey);
571     return ret;
572 }
573
574
575 /*************************************************************************
576  * SHADD_compare_mru - helper function for SHAddToRecentDocs
577  *
578  * PARAMETERS
579  *   data1     [IN] data being looked for
580  *   data2     [IN] data in MRU
581  *   cbdata    [IN] length from FindMRUData call (not used)
582  *
583  * RETURNS
584  *   position within MRU list that data was added.
585  */
586 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
587 {
588     return lstrcmpiA(data1, data2);
589 }
590
591 /*************************************************************************
592  * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
593  *
594  * PARAMETERS
595  *   mruhandle    [IN] handle for created MRU list
596  *   doc_name     [IN] null termed pure doc name
597  *   new_lnk_name [IN] null termed path and file name for .lnk file
598  *   buffer       [IN/OUT] 2048 byte area to construct MRU data
599  *   len          [OUT] ptr to int to receive space used in buffer
600  *
601  * RETURNS
602  *   position within MRU list that data was added.
603  */
604 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
605                                      LPSTR buffer, INT *len)
606 {
607     LPSTR ptr;
608     INT wlen;
609
610     /*FIXME: Document:
611      *  RecentDocs MRU data structure seems to be:
612      *    +0h   document file name w/ terminating 0h
613      *    +nh   short int w/ size of remaining
614      *    +n+2h 02h 30h, or 01h 30h, or 00h 30h  -  unknown
615      *    +n+4h 10 bytes zeros  -   unknown
616      *    +n+eh shortcut file name w/ terminating 0h
617      *    +n+e+nh 3 zero bytes  -  unknown
618      */
619
620     /* Create the MRU data structure for "RecentDocs"
621          */
622     ptr = buffer;
623     lstrcpyA(ptr, doc_name);
624     ptr += (lstrlenA(buffer) + 1);
625     wlen= lstrlenA(new_lnk_name) + 1 + 12;
626     *((short int*)ptr) = wlen;
627     ptr += 2;   /* step past the length */
628     *(ptr++) = 0x30;  /* unknown reason */
629     *(ptr++) = 0;     /* unknown, but can be 0x00, 0x01, 0x02 */
630     memset(ptr, 0, 10);
631     ptr += 10;
632     lstrcpyA(ptr, new_lnk_name);
633     ptr += (lstrlenA(new_lnk_name) + 1);
634     memset(ptr, 0, 3);
635     ptr += 3;
636     *len = ptr - buffer;
637
638     /* Add the new entry into the MRU list
639      */
640     return AddMRUData(mruhandle, (LPCVOID)buffer, *len);
641 }
642
643 /*************************************************************************
644  * SHAddToRecentDocs                            [SHELL32.@]
645  *
646  * Modify (add/clear) Shell's list of recently used documents.
647  *
648  * PARAMETERS
649  *   uFlags  [IN] SHARD_PATHA, SHARD_PATHW or SHARD_PIDL
650  *   pv      [IN] string or pidl, NULL clears the list
651  *
652  * NOTES
653  *     exported by name
654  *
655  * FIXME
656  *  convert to unicode
657  */
658 void WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
659 {
660 /* If list is a string list lpfnCompare has the following prototype
661  * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
662  * for binary lists the prototype is
663  * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
664  * where cbData is the no. of bytes to compare.
665  * Need to check what return value means identical - 0?
666  */
667
668
669     UINT olderrormode;
670     HKEY HCUbasekey;
671     CHAR doc_name[MAX_PATH];
672     CHAR link_dir[MAX_PATH];
673     CHAR new_lnk_filepath[MAX_PATH];
674     CHAR new_lnk_name[MAX_PATH];
675     IMalloc *ppM;
676     LPITEMIDLIST pidl;
677     HWND hwnd = 0;       /* FIXME:  get real window handle */
678     INT ret;
679     DWORD data[64], datalen, type;
680
681     TRACE("%04x %p\n", uFlags, pv);
682
683     /*FIXME: Document:
684      *  RecentDocs MRU data structure seems to be:
685      *    +0h   document file name w/ terminating 0h
686      *    +nh   short int w/ size of remaining
687      *    +n+2h 02h 30h, or 01h 30h, or 00h 30h  -  unknown
688      *    +n+4h 10 bytes zeros  -   unknown
689      *    +n+eh shortcut file name w/ terminating 0h
690      *    +n+e+nh 3 zero bytes  -  unknown
691      */
692
693     /* See if we need to do anything.
694      */
695     datalen = 64;
696     ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
697     if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
698         ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
699         return;
700     }
701     if (ret == ERROR_SUCCESS) {
702         if (!( (type == REG_DWORD) ||
703                ((type == REG_BINARY) && (datalen == 4)) )) {
704             ERR("Error policy data for \"NoRecentDocsHistory\" not formatted correctly, type=%ld, len=%ld\n",
705                 type, datalen);
706             return;
707         }
708
709         TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
710         /* now test the actual policy value */
711         if ( data[0] != 0)
712             return;
713     }
714
715     /* Open key to where the necessary info is
716      */
717     /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
718      *        and the close should be done during the _DETACH. The resulting
719      *        key is stored in the DLL global data.
720      */
721     if (RegCreateKeyExA(HKEY_CURRENT_USER,
722                         "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
723                         0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
724         ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
725         return;
726     }
727
728     /* Get path to user's "Recent" directory
729      */
730     if(SUCCEEDED(SHGetMalloc(&ppM))) {
731         if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
732                                                  &pidl))) {
733             SHGetPathFromIDListA(pidl, link_dir);
734             IMalloc_Free(ppM, pidl);
735         }
736         else {
737             /* serious issues */
738             link_dir[0] = 0;
739             ERR("serious issues 1\n");
740         }
741         IMalloc_Release(ppM);
742     }
743     else {
744         /* serious issues */
745         link_dir[0] = 0;
746         ERR("serious issues 2\n");
747     }
748     TRACE("Users Recent dir %s\n", link_dir);
749
750     /* If no input, then go clear the lists */
751     if (!pv) {
752         /* clear user's Recent dir
753          */
754
755         /* FIXME: delete all files in "link_dir"
756          *
757          * while( more files ) {
758          *    lstrcpyA(old_lnk_name, link_dir);
759          *    PathAppendA(old_lnk_name, filenam);
760          *    DeleteFileA(old_lnk_name);
761          * }
762          */
763         FIXME("should delete all files in %s\\\n", link_dir);
764
765         /* clear MRU list
766          */
767         /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
768          *  HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
769          *  and naturally it fails w/ rc=2. It should do it against
770          *  HKEY_CURRENT_USER which is where it is stored, and where
771          *  the MRU routines expect it!!!!
772          */
773         RegDeleteKeyA(HCUbasekey, "RecentDocs");
774         RegCloseKey(HCUbasekey);
775         return;
776     }
777
778     /* Have data to add, the jobs to be done:
779      *   1. Add document to MRU list in registry "HKCU\Software\
780      *      Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
781      *   2. Add shortcut to document in the user's Recent directory
782      *      (CSIDL_RECENT).
783      *   3. Add shortcut to Start menu's Documents submenu.
784      */
785
786     /* Get the pure document name from the input
787      */
788     switch (uFlags)
789     {
790     case SHARD_PIDL:
791         SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
792         break;
793
794     case SHARD_PATHA:
795         lstrcpynA(doc_name, (LPCSTR)pv, MAX_PATH);
796         break;
797
798     case SHARD_PATHW:
799         WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pv, -1, doc_name, MAX_PATH, NULL, NULL);
800         break;
801
802     default:
803         FIXME("Unsupported flags: %u\n", uFlags);
804         return;
805     }
806
807     TRACE("full document name %s\n", debugstr_a(doc_name));
808     PathStripPathA(doc_name);
809     TRACE("stripped document name %s\n", debugstr_a(doc_name));
810
811
812     /* ***  JOB 1: Update registry for ...\Explorer\RecentDocs list  *** */
813
814     {  /* on input needs:
815         *      doc_name    -  pure file-spec, no path
816         *      link_dir    -  path to the user's Recent directory
817         *      HCUbasekey  -  key of ...Windows\CurrentVersion\Explorer" node
818         * creates:
819         *      new_lnk_name-  pure file-spec, no path for new .lnk file
820         *      new_lnk_filepath
821         *                  -  path and file name of new .lnk file
822         */
823         CREATEMRULISTA mymru;
824         HANDLE mruhandle;
825         INT len, pos, bufused, err;
826         INT i;
827         DWORD attr;
828         CHAR buffer[2048];
829         CHAR *ptr;
830         CHAR old_lnk_name[MAX_PATH];
831         short int slen;
832
833         mymru.cbSize = sizeof(CREATEMRULISTA);
834         mymru.nMaxItems = 15;
835         mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
836         mymru.hKey = HCUbasekey;
837         mymru.lpszSubKey = "RecentDocs";
838         mymru.lpfnCompare = &SHADD_compare_mru;
839         mruhandle = CreateMRUListA(&mymru);
840         if (!mruhandle) {
841             /* MRU failed */
842             ERR("MRU processing failed, handle zero\n");
843             RegCloseKey(HCUbasekey);
844             return;
845         }
846         len = lstrlenA(doc_name);
847         pos = FindMRUData(mruhandle, doc_name, len, 0);
848
849         /* Now get the MRU entry that will be replaced
850          * and delete the .lnk file for it
851          */
852         if ((bufused = EnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
853                                     buffer, 2048)) != -1) {
854             ptr = buffer;
855             ptr += (lstrlenA(buffer) + 1);
856             slen = *((short int*)ptr);
857             ptr += 2;  /* skip the length area */
858             if (bufused >= slen + (ptr-buffer)) {
859                 /* buffer size looks good */
860                 ptr += 12; /* get to string */
861                 len = bufused - (ptr-buffer);  /* get length of buf remaining */
862                 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
863                     /* appears to be good string */
864                     lstrcpyA(old_lnk_name, link_dir);
865                     PathAppendA(old_lnk_name, ptr);
866                     if (!DeleteFileA(old_lnk_name)) {
867                         if ((attr = GetFileAttributesA(old_lnk_name)) == INVALID_FILE_ATTRIBUTES) {
868                             if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
869                                 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
870                                     old_lnk_name, err, attr);
871                             }
872                             else {
873                                 TRACE("old .lnk file %s did not exist\n",
874                                       old_lnk_name);
875                             }
876                         }
877                         else {
878                             ERR("Delete for %s failed, attr=%08lx\n",
879                                 old_lnk_name, attr);
880                         }
881                     }
882                     else {
883                         TRACE("deleted old .lnk file %s\n", old_lnk_name);
884                     }
885                 }
886             }
887         }
888
889         /* Create usable .lnk file name for the "Recent" directory
890          */
891         wsprintfA(new_lnk_name, "%s.lnk", doc_name);
892         lstrcpyA(new_lnk_filepath, link_dir);
893         PathAppendA(new_lnk_filepath, new_lnk_name);
894         i = 1;
895         olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
896         while (GetFileAttributesA(new_lnk_filepath) != INVALID_FILE_ATTRIBUTES) {
897             i++;
898             wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
899             lstrcpyA(new_lnk_filepath, link_dir);
900             PathAppendA(new_lnk_filepath, new_lnk_name);
901         }
902         SetErrorMode(olderrormode);
903         TRACE("new shortcut will be %s\n", new_lnk_filepath);
904
905         /* Now add the new MRU entry and data
906          */
907         pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
908                                         buffer, &len);
909         FreeMRUList(mruhandle);
910         TRACE("Updated MRU list, new doc is position %d\n", pos);
911     }
912
913     /* ***  JOB 2: Create shortcut in user's "Recent" directory  *** */
914
915     {  /* on input needs:
916         *      doc_name    -  pure file-spec, no path
917         *      new_lnk_filepath
918         *                  -  path and file name of new .lnk file
919         *      uFlags[in]  -  flags on call to SHAddToRecentDocs
920         *      pv[in]      -  document path/pidl on call to SHAddToRecentDocs
921         */
922         IShellLinkA *psl = NULL;
923         IPersistFile *pPf = NULL;
924         HRESULT hres;
925         CHAR desc[MAX_PATH];
926         WCHAR widelink[MAX_PATH];
927
928         CoInitialize(0);
929
930         hres = CoCreateInstance( &CLSID_ShellLink,
931                                  NULL,
932                                  CLSCTX_INPROC_SERVER,
933                                  &IID_IShellLinkA,
934                                  (LPVOID )&psl);
935         if(SUCCEEDED(hres)) {
936
937             hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
938                                              (LPVOID *)&pPf);
939             if(FAILED(hres)) {
940                 /* bombed */
941                 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
942                 goto fail;
943             }
944
945             /* Set the document path or pidl */
946             if (uFlags == SHARD_PIDL) {
947                 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
948             } else {
949                 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
950             }
951             if(FAILED(hres)) {
952                 /* bombed */
953                 ERR("failed Set{IDList|Path} %08lx\n", hres);
954                 goto fail;
955             }
956
957             lstrcpyA(desc, "Shortcut to ");
958             lstrcatA(desc, doc_name);
959             hres = IShellLinkA_SetDescription(psl, desc);
960             if(FAILED(hres)) {
961                 /* bombed */
962                 ERR("failed SetDescription %08lx\n", hres);
963                 goto fail;
964             }
965
966             MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
967                                 widelink, MAX_PATH);
968             /* create the short cut */
969             hres = IPersistFile_Save(pPf, widelink, TRUE);
970             if(FAILED(hres)) {
971                 /* bombed */
972                 ERR("failed IPersistFile::Save %08lx\n", hres);
973                 IPersistFile_Release(pPf);
974                 IShellLinkA_Release(psl);
975                 goto fail;
976             }
977             hres = IPersistFile_SaveCompleted(pPf, widelink);
978             IPersistFile_Release(pPf);
979             IShellLinkA_Release(psl);
980             TRACE("shortcut %s has been created, result=%08lx\n",
981                   new_lnk_filepath, hres);
982         }
983         else {
984             ERR("CoCreateInstance failed, hres=%08lx\n", hres);
985         }
986     }
987
988  fail:
989     CoUninitialize();
990
991     /* all done */
992     RegCloseKey(HCUbasekey);
993     return;
994 }
995
996 /*************************************************************************
997  * SHCreateShellFolderViewEx                    [SHELL32.174]
998  *
999  * Create a new instance of the default Shell folder view object.
1000  *
1001  * RETURNS
1002  *  Success: S_OK
1003  *  Failure: error value
1004  *
1005  * NOTES
1006  *  see IShellFolder::CreateViewObject
1007  */
1008 HRESULT WINAPI SHCreateShellFolderViewEx(
1009         LPCSFV psvcbi,    /* [in] shelltemplate struct */
1010         IShellView **ppv) /* [out] IShellView pointer */
1011 {
1012         IShellView * psf;
1013         HRESULT hRes;
1014
1015         TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=%p\n",
1016           psvcbi->pshf, psvcbi->pidl, psvcbi->pfnCallback,
1017           psvcbi->fvm, psvcbi->psvOuter);
1018
1019         psf = IShellView_Constructor(psvcbi->pshf);
1020
1021         if (!psf)
1022           return E_OUTOFMEMORY;
1023
1024         IShellView_AddRef(psf);
1025         hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
1026         IShellView_Release(psf);
1027
1028         return hRes;
1029 }
1030 /*************************************************************************
1031  *  SHWinHelp                                   [SHELL32.127]
1032  *
1033  */
1034 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
1035 {       FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
1036         return 0;
1037 }
1038 /*************************************************************************
1039  *  SHRunControlPanel [SHELL32.161]
1040  *
1041  */
1042 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
1043 {       FIXME("0x%08lx 0x%08lx stub\n",x,z);
1044         return 0;
1045 }
1046
1047 static LPUNKNOWN SHELL32_IExplorerInterface=0;
1048 /*************************************************************************
1049  * SHSetInstanceExplorer                        [SHELL32.176]
1050  *
1051  * NOTES
1052  *  Sets the interface
1053  */
1054 VOID WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
1055 {       TRACE("%p\n", lpUnknown);
1056         SHELL32_IExplorerInterface = lpUnknown;
1057 }
1058 /*************************************************************************
1059  * SHGetInstanceExplorer                        [SHELL32.@]
1060  *
1061  * NOTES
1062  *  gets the interface pointer of the explorer and a reference
1063  */
1064 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
1065 {       TRACE("%p\n", lpUnknown);
1066
1067         *lpUnknown = SHELL32_IExplorerInterface;
1068
1069         if (!SHELL32_IExplorerInterface)
1070           return E_FAIL;
1071
1072         IUnknown_AddRef(SHELL32_IExplorerInterface);
1073         return NOERROR;
1074 }
1075 /*************************************************************************
1076  * SHFreeUnusedLibraries                        [SHELL32.123]
1077  *
1078  * Probably equivalent to CoFreeUnusedLibraries but under Windows 9x it could use
1079  * the shell32 built-in "mini-COM" without the need to load ole32.dll - see SHLoadOLE
1080  * for details
1081  *
1082  * NOTES
1083  *     exported by ordinal
1084  *
1085  * SEE ALSO
1086  *     CoFreeUnusedLibraries, SHLoadOLE
1087  */
1088 void WINAPI SHFreeUnusedLibraries (void)
1089 {
1090         FIXME("stub\n");
1091         CoFreeUnusedLibraries();
1092 }
1093 /*************************************************************************
1094  * DAD_AutoScroll                               [SHELL32.129]
1095  *
1096  */
1097 BOOL WINAPI DAD_AutoScroll(HWND hwnd, AUTO_SCROLL_DATA *samples, LPPOINT pt)
1098 {
1099     FIXME("hwnd = %p %p %p\n",hwnd,samples,pt);
1100     return 0;
1101 }
1102 /*************************************************************************
1103  * DAD_DragEnter                                [SHELL32.130]
1104  *
1105  */
1106 BOOL WINAPI DAD_DragEnter(HWND hwnd)
1107 {
1108     FIXME("hwnd = %p\n",hwnd);
1109     return FALSE;
1110 }
1111 /*************************************************************************
1112  * DAD_DragEnterEx                              [SHELL32.131]
1113  *
1114  */
1115 BOOL WINAPI DAD_DragEnterEx(HWND hwnd, POINT p)
1116 {
1117     FIXME("hwnd = %p (%ld,%ld)\n",hwnd,p.x,p.y);
1118     return FALSE;
1119 }
1120 /*************************************************************************
1121  * DAD_DragMove                         [SHELL32.134]
1122  *
1123  */
1124 BOOL WINAPI DAD_DragMove(POINT p)
1125 {
1126     FIXME("(%ld,%ld)\n",p.x,p.y);
1127     return FALSE;
1128 }
1129 /*************************************************************************
1130  * DAD_DragLeave                                [SHELL32.132]
1131  *
1132  */
1133 BOOL WINAPI DAD_DragLeave(VOID)
1134 {
1135     FIXME("\n");
1136     return FALSE;
1137 }
1138 /*************************************************************************
1139  * DAD_SetDragImage                             [SHELL32.136]
1140  *
1141  * NOTES
1142  *  exported by name
1143  */
1144 BOOL WINAPI DAD_SetDragImage(
1145         HIMAGELIST himlTrack,
1146         LPPOINT lppt)
1147 {
1148         FIXME("%p %p stub\n",himlTrack, lppt);
1149   return 0;
1150 }
1151 /*************************************************************************
1152  * DAD_ShowDragImage                            [SHELL32.137]
1153  *
1154  * NOTES
1155  *  exported by name
1156  */
1157 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1158 {
1159         FIXME("0x%08x stub\n",bShow);
1160         return 0;
1161 }
1162
1163 static const WCHAR szwCabLocation[] = {
1164   'S','o','f','t','w','a','r','e','\\',
1165   'M','i','c','r','o','s','o','f','t','\\',
1166   'W','i','n','d','o','w','s','\\',
1167   'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
1168   'E','x','p','l','o','r','e','r','\\',
1169   'C','a','b','i','n','e','t','S','t','a','t','e',0
1170 };
1171
1172 static const WCHAR szwSettings[] = { 'S','e','t','t','i','n','g','s',0 };
1173
1174 /*************************************************************************
1175  * ReadCabinetState                             [SHELL32.651] NT 4.0
1176  *
1177  */
1178 BOOL WINAPI ReadCabinetState(CABINETSTATE *cs, int length)
1179 {
1180         HKEY hkey = 0;
1181         DWORD type, r;
1182
1183         TRACE("%p %d\n", cs, length);
1184
1185         if( (cs == NULL) || (length < (int)sizeof(*cs))  )
1186                 return FALSE;
1187
1188         r = RegOpenKeyW( HKEY_CURRENT_USER, szwCabLocation, &hkey );
1189         if( r == ERROR_SUCCESS )
1190         {
1191                 type = REG_BINARY;
1192                 r = RegQueryValueExW( hkey, szwSettings, 
1193                         NULL, &type, (LPBYTE)cs, (LPDWORD)&length );
1194                 RegCloseKey( hkey );
1195                         
1196         }
1197
1198         /* if we can't read from the registry, create default values */
1199         if ( (r != ERROR_SUCCESS) || (cs->cLength < sizeof(*cs)) ||
1200                 (cs->cLength != length) )
1201         {
1202                 ERR("Initializing shell cabinet settings\n");
1203                 memset(cs, 0, sizeof(*cs));
1204                 cs->cLength          = sizeof(*cs);
1205                 cs->nVersion         = 2;
1206                 cs->fFullPathTitle   = FALSE;
1207                 cs->fSaveLocalView   = TRUE;
1208                 cs->fNotShell        = FALSE;
1209                 cs->fSimpleDefault   = TRUE;
1210                 cs->fDontShowDescBar = FALSE;
1211                 cs->fNewWindowMode   = FALSE;
1212                 cs->fShowCompColor   = FALSE;
1213                 cs->fDontPrettyNames = FALSE;
1214                 cs->fAdminsCreateCommonGroups = TRUE;
1215                 cs->fMenuEnumFilter  = 96;
1216         }
1217         
1218         return TRUE;
1219 }
1220
1221 /*************************************************************************
1222  * WriteCabinetState                            [SHELL32.652] NT 4.0
1223  *
1224  */
1225 BOOL WINAPI WriteCabinetState(CABINETSTATE *cs)
1226 {
1227         DWORD r;
1228         HKEY hkey = 0;
1229
1230         TRACE("%p\n",cs);
1231
1232         if( cs == NULL )
1233                 return FALSE;
1234
1235         r = RegCreateKeyExW( HKEY_CURRENT_USER, szwCabLocation, 0,
1236                  NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
1237         if( r == ERROR_SUCCESS )
1238         {
1239                 r = RegSetValueExW( hkey, szwSettings, 0, 
1240                         REG_BINARY, (LPBYTE) cs, cs->cLength);
1241
1242                 RegCloseKey( hkey );
1243         }
1244
1245         return (r==ERROR_SUCCESS);
1246 }
1247
1248 /*************************************************************************
1249  * FileIconInit                                 [SHELL32.660]
1250  *
1251  */
1252 BOOL WINAPI FileIconInit(BOOL bFullInit)
1253 {       FIXME("(%s)\n", bFullInit ? "true" : "false");
1254         return 0;
1255 }
1256 /*************************************************************************
1257  * IsUserAdmin                                  [SHELL32.680] NT 4.0
1258  *
1259  */
1260 HRESULT WINAPI IsUserAdmin(void)
1261 {       FIXME("stub\n");
1262         return TRUE;
1263 }
1264
1265 /*************************************************************************
1266  * SHAllocShared                                [SHELL32.520]
1267  *
1268  * See shlwapi.SHAllocShared
1269  */
1270 HANDLE WINAPI SHAllocShared(LPVOID lpvData, DWORD dwSize, DWORD dwProcId)
1271 {
1272     GET_FUNC(pSHAllocShared, shlwapi, (char*)7, NULL);
1273     return pSHAllocShared(lpvData, dwSize, dwProcId);
1274 }
1275
1276 /*************************************************************************
1277  * SHLockShared                                 [SHELL32.521]
1278  *
1279  * See shlwapi.SHLockShared
1280  */
1281 LPVOID WINAPI SHLockShared(HANDLE hShared, DWORD dwProcId)
1282 {
1283     GET_FUNC(pSHLockShared, shlwapi, (char*)8, NULL);
1284     return pSHLockShared(hShared, dwProcId);
1285 }
1286
1287 /*************************************************************************
1288  * SHUnlockShared                               [SHELL32.522]
1289  *
1290  * See shlwapi.SHUnlockShared
1291  */
1292 BOOL WINAPI SHUnlockShared(LPVOID lpView)
1293 {
1294     GET_FUNC(pSHUnlockShared, shlwapi, (char*)9, FALSE);
1295     return pSHUnlockShared(lpView);
1296 }
1297
1298 /*************************************************************************
1299  * SHFreeShared                                 [SHELL32.523]
1300  *
1301  * See shlwapi.SHFreeShared
1302  */
1303 BOOL WINAPI SHFreeShared(HANDLE hShared, DWORD dwProcId)
1304 {
1305     GET_FUNC(pSHFreeShared, shlwapi, (char*)10, FALSE);
1306     return pSHFreeShared(hShared, dwProcId);
1307 }
1308
1309 /*************************************************************************
1310  * SetAppStartingCursor                         [SHELL32.99]
1311  */
1312 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1313 {       FIXME("hwnd=%p 0x%04lx stub\n",u,v );
1314         return 0;
1315 }
1316
1317 /*************************************************************************
1318  * SHLoadOLE                                    [SHELL32.151]
1319  *
1320  * To reduce the memory usage of Windows 95 it's shell32 contained an
1321  * internal implementation of a part of COM (see e.g. SHGetMalloc, SHCoCreateInstance,
1322  * SHRegisterDragDrop etc.) that allowed to use in-process STA objects without
1323  * the need to load OLE32.DLL. If OLE32.DLL was already loaded, the SH* function
1324  * would just call the Co* functions.
1325  *
1326  * The SHLoadOLE was called when OLE32.DLL was being loaded to transfer all the
1327  * informations from the shell32 "mini-COM" to ole32.dll.
1328  *
1329  * See http://blogs.msdn.com/oldnewthing/archive/2004/07/05/173226.aspx for a
1330  * detailed description.
1331  *
1332  * Under wine ole32.dll is always loaded as it is imported by shlwapi.dll which is
1333  * imported by shell32 and no "mini-COM" is used (except for the "LoadWithoutCOM"
1334  * hack in SHCoCreateInstance)
1335  */
1336 HRESULT WINAPI SHLoadOLE(LPARAM lParam)
1337 {       FIXME("0x%04lx stub\n",lParam);
1338         return S_OK;
1339 }
1340 /*************************************************************************
1341  * DriveType                                    [SHELL32.64]
1342  *
1343  */
1344 HRESULT WINAPI DriveType(DWORD u)
1345 {       FIXME("0x%04lx stub\n",u);
1346         return 0;
1347 }
1348 /*************************************************************************
1349  * InvalidateDriveType                  [SHELL32.65]
1350  *
1351  */
1352 int WINAPI InvalidateDriveType(int u)
1353 {       FIXME("0x%08x stub\n",u);
1354         return 0;
1355 }
1356 /*************************************************************************
1357  * SHAbortInvokeCommand                         [SHELL32.198]
1358  *
1359  */
1360 HRESULT WINAPI SHAbortInvokeCommand(void)
1361 {       FIXME("stub\n");
1362         return 1;
1363 }
1364 /*************************************************************************
1365  * SHOutOfMemoryMessageBox                      [SHELL32.126]
1366  *
1367  */
1368 int WINAPI SHOutOfMemoryMessageBox(
1369         HWND hwndOwner,
1370         LPCSTR lpCaption,
1371         UINT uType)
1372 {
1373         FIXME("%p %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1374         return 0;
1375 }
1376 /*************************************************************************
1377  * SHFlushClipboard                             [SHELL32.121]
1378  *
1379  */
1380 HRESULT WINAPI SHFlushClipboard(void)
1381 {       FIXME("stub\n");
1382         return 1;
1383 }
1384
1385 /*************************************************************************
1386  * SHWaitForFileToOpen                          [SHELL32.97]
1387  *
1388  */
1389 BOOL WINAPI SHWaitForFileToOpen(
1390         LPCITEMIDLIST pidl,
1391         DWORD dwFlags,
1392         DWORD dwTimeout)
1393 {
1394         FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1395         return 0;
1396 }
1397
1398 /************************************************************************
1399  *      @                               [SHELL32.654]
1400  *
1401  * NOTES
1402  *  first parameter seems to be a pointer (same as passed to WriteCabinetState)
1403  *  second one could be a size (0x0c). The size is the same as the structure saved to
1404  *  HCU\Software\Microsoft\Windows\CurrentVersion\Explorer\CabinetState
1405  *  I'm (js) guessing: this one is just ReadCabinetState ;-)
1406  */
1407 HRESULT WINAPI shell32_654 (CABINETSTATE *cs, int length)
1408 {
1409         TRACE("%p %d\n",cs,length);
1410         return ReadCabinetState(cs,length);
1411 }
1412
1413 /************************************************************************
1414  *      RLBuildListOfPaths                      [SHELL32.146]
1415  *
1416  * NOTES
1417  *   builds a DPA
1418  */
1419 DWORD WINAPI RLBuildListOfPaths (void)
1420 {       FIXME("stub\n");
1421         return 0;
1422 }
1423 /************************************************************************
1424  *      SHValidateUNC                           [SHELL32.173]
1425  *
1426  */
1427 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1428 {
1429         FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1430         return 0;
1431 }
1432
1433 /************************************************************************
1434  *      DoEnvironmentSubstA                     [SHELL32.@]
1435  *
1436  * Replace %KEYWORD% in the str with the value of variable KEYWORD
1437  * from environment. If it is not found the %KEYWORD% is left
1438  * intact. If the buffer is too small, str is not modified.
1439  *
1440  * PARAMS
1441  *  pszString  [I] '\0' terminated string with %keyword%.
1442  *             [O] '\0' terminated string with %keyword% substituted.
1443  *  cchString  [I] size of str.
1444  *
1445  * RETURNS
1446  *     cchString length in the HIWORD;
1447  *     TRUE in LOWORD if subst was successful and FALSE in other case
1448  */
1449 DWORD WINAPI DoEnvironmentSubstA(LPSTR pszString, UINT cchString)
1450 {
1451     LPSTR dst;
1452     BOOL res = FALSE;
1453     FIXME("(%s, %d) stub\n", debugstr_a(pszString), cchString);
1454     if (pszString == NULL) /* Really return 0? */
1455         return 0;
1456     if ((dst = HeapAlloc(GetProcessHeap(), 0, cchString * sizeof(CHAR))))
1457     {
1458         DWORD num = ExpandEnvironmentStringsA(pszString, dst, cchString);
1459         if (num && num < cchString) /* dest buffer is too small */
1460         {
1461             res = TRUE;
1462             memcpy(pszString, dst, num);
1463         }
1464         HeapFree(GetProcessHeap(), 0, dst);
1465     }
1466     return MAKELONG(res,cchString); /* Always cchString? */
1467 }
1468
1469 /************************************************************************
1470  *      DoEnvironmentSubstW                     [SHELL32.@]
1471  *
1472  * See DoEnvironmentSubstA.  
1473  */
1474 DWORD WINAPI DoEnvironmentSubstW(LPWSTR pszString, UINT cchString)
1475 {
1476         FIXME("(%s, %d): stub\n", debugstr_w(pszString), cchString);
1477         return MAKELONG(FALSE,cchString);
1478 }
1479
1480 /************************************************************************
1481  *      DoEnvironmentSubst                      [SHELL32.53]
1482  *
1483  * See DoEnvironmentSubstA.  
1484  */
1485 DWORD WINAPI DoEnvironmentSubstAW(LPVOID x, UINT y)
1486 {
1487     if (SHELL_OsIsUnicode())
1488         return DoEnvironmentSubstW(x, y);
1489     return DoEnvironmentSubstA(x, y);
1490 }
1491
1492 /*************************************************************************
1493  *      @                             [SHELL32.243]
1494  *
1495  * Win98+ by-ordinal routine.  In Win98 this routine returns zero and
1496  * does nothing else.  Possibly this does something in NT or SHELL32 5.0?
1497  *
1498  */
1499
1500 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1501 {
1502   return FALSE;
1503 }
1504
1505 /*************************************************************************
1506  *      @       [SHELL32.714]
1507  */
1508 DWORD WINAPI SHELL32_714(LPVOID x)
1509 {
1510         FIXME("(%s)stub\n", debugstr_w(x));
1511         return 0;
1512 }
1513
1514 /*************************************************************************
1515  *      SHAddFromPropSheetExtArray      [SHELL32.167]
1516  */
1517 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1518 {
1519         FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1520         return 0;
1521 }
1522
1523 /*************************************************************************
1524  *      SHCreatePropSheetExtArray       [SHELL32.168]
1525  */
1526 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1527 {
1528         FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1529         return 0;
1530 }
1531
1532 /*************************************************************************
1533  *      SHReplaceFromPropSheetExtArray  [SHELL32.170]
1534  */
1535 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1536 {
1537         FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1538         return 0;
1539 }
1540
1541 /*************************************************************************
1542  *      SHDestroyPropSheetExtArray      [SHELL32.169]
1543  */
1544 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1545 {
1546         FIXME("(%08lx)stub\n", a);
1547         return 0;
1548 }
1549
1550 /*************************************************************************
1551  *      CIDLData_CreateFromIDArray      [SHELL32.83]
1552  *
1553  *  Create IDataObject from PIDLs??
1554  */
1555 HRESULT WINAPI CIDLData_CreateFromIDArray(
1556         LPCITEMIDLIST pidlFolder,
1557         DWORD cpidlFiles,
1558         LPCITEMIDLIST *lppidlFiles,
1559         LPDATAOBJECT *ppdataObject)
1560 {
1561     UINT i;
1562     HWND hwnd = 0;   /*FIXME: who should be hwnd of owner? set to desktop */
1563
1564     TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1565     if (TRACE_ON(pidl))
1566     {
1567         pdump (pidlFolder);
1568         for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1569     }
1570     *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1571                                              lppidlFiles, cpidlFiles);
1572     if (*ppdataObject) return S_OK;
1573     return E_OUTOFMEMORY;
1574 }
1575
1576 /*************************************************************************
1577  * SHCreateStdEnumFmtEtc                        [SHELL32.74]
1578  *
1579  * NOTES
1580  *
1581  */
1582 HRESULT WINAPI SHCreateStdEnumFmtEtc(
1583         DWORD cFormats,
1584         const FORMATETC *lpFormats,
1585         LPENUMFORMATETC *ppenumFormatetc)
1586 {
1587         IEnumFORMATETC *pef;
1588         HRESULT hRes;
1589         TRACE("cf=%ld fe=%p pef=%p\n", cFormats, lpFormats, ppenumFormatetc);
1590
1591         pef = IEnumFORMATETC_Constructor(cFormats, lpFormats);
1592         if (!pef)
1593           return E_OUTOFMEMORY;
1594
1595         IEnumFORMATETC_AddRef(pef);
1596         hRes = IEnumFORMATETC_QueryInterface(pef, &IID_IEnumFORMATETC, (LPVOID*)ppenumFormatetc);
1597         IEnumFORMATETC_Release(pef);
1598
1599         return hRes;
1600 }
1601
1602
1603 /*************************************************************************
1604  *              SHELL32_256 (SHELL32.256)
1605  */
1606 HRESULT WINAPI SHELL32_256(LPDWORD lpdw0, LPDWORD lpdw1)
1607 {
1608     HRESULT ret = S_OK;
1609
1610     FIXME("stub %p 0x%08lx %p\n", lpdw0, lpdw0 ? *lpdw0 : 0, lpdw1);
1611
1612     if (!lpdw0 || *lpdw0 != 0x10)
1613         ret = E_INVALIDARG;
1614     else
1615     {
1616         LPVOID lpdata = 0;/*LocalAlloc(LMEM_ZEROINIT, 0x4E4);*/
1617
1618         if (!lpdata)
1619             ret = E_OUTOFMEMORY;
1620         else
1621         {
1622             /* Initialize and return unknown lpdata structure */
1623         }
1624     }
1625
1626     return ret;
1627 }
1628
1629 /*************************************************************************
1630  *              SHFindFiles (SHELL32.90)
1631  */
1632 BOOL WINAPI SHFindFiles( LPCITEMIDLIST pidlFolder, LPCITEMIDLIST pidlSaveFile )
1633 {
1634     FIXME("%p %p\n", pidlFolder, pidlSaveFile );
1635     return FALSE;
1636 }
1637
1638 /*************************************************************************
1639  *              SHUpdateImageW (SHELL32.192)
1640  *
1641  * Notifies the shell that an icon in the system image list has been changed.
1642  *
1643  * PARAMS
1644  *  pszHashItem [I] Path to file that contains the icon.
1645  *  iIndex      [I] Zero-based index of the icon in the file.
1646  *  uFlags      [I] Flags determining the icon attributes. See notes.
1647  *  iImageIndex [I] Index of the icon in the system image list.
1648  *
1649  * RETURNS
1650  *  Nothing
1651  *
1652  * NOTES
1653  *  uFlags can be one or more of the following flags:
1654  *  GIL_NOTFILENAME - pszHashItem is not a file name.
1655  *  GIL_SIMULATEDOC - Create a document icon using the specified icon.
1656  */
1657 void WINAPI SHUpdateImageW(LPCWSTR pszHashItem, int iIndex, UINT uFlags, int iImageIndex)
1658 {
1659     FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_w(pszHashItem), iIndex, uFlags, iImageIndex);
1660 }
1661
1662 /*************************************************************************
1663  *              SHUpdateImageA (SHELL32.191)
1664  *
1665  * See SHUpdateImageW.
1666  */
1667 VOID WINAPI SHUpdateImageA(LPCSTR pszHashItem, INT iIndex, UINT uFlags, INT iImageIndex)
1668 {
1669     FIXME("%s, %d, 0x%x, %d - stub\n", debugstr_a(pszHashItem), iIndex, uFlags, iImageIndex);
1670 }
1671
1672 INT WINAPI SHHandleUpdateImage(LPCITEMIDLIST pidlExtra)
1673 {
1674     FIXME("%p - stub\n", pidlExtra);
1675
1676     return -1;
1677 }
1678
1679 BOOL WINAPI SHObjectProperties(HWND hwnd, DWORD dwType, LPCWSTR szObject, LPCWSTR szPage)
1680 {
1681     FIXME("%p, 0x%08lx, %s, %s - stub\n", hwnd, dwType, debugstr_w(szObject), debugstr_w(szPage));
1682
1683     return TRUE;
1684 }
1685
1686 BOOL WINAPI SHGetNewLinkInfoA(LPCSTR pszLinkTo, LPCSTR pszDir, LPSTR pszName, BOOL *pfMustCopy,
1687                               UINT uFlags)
1688 {
1689     FIXME("%s, %s, %p, %p, 0x%08x - stub\n", debugstr_a(pszLinkTo), debugstr_a(pszDir),
1690           pszName, pfMustCopy, uFlags);
1691
1692     return FALSE;
1693 }
1694
1695 BOOL WINAPI SHGetNewLinkInfoW(LPCWSTR pszLinkTo, LPCWSTR pszDir, LPWSTR pszName, BOOL *pfMustCopy,
1696                               UINT uFlags)
1697 {
1698     FIXME("%s, %s, %p, %p, 0x%08x - stub\n", debugstr_w(pszLinkTo), debugstr_w(pszDir),
1699           pszName, pfMustCopy, uFlags);
1700
1701     return FALSE;
1702 }
1703
1704 HRESULT WINAPI SHStartNetConnectionDialog(HWND hwnd, LPCSTR pszRemoteName, DWORD dwType)
1705 {
1706     FIXME("%p, %s, 0x%08lx - stub\n", hwnd, debugstr_a(pszRemoteName), dwType);
1707
1708     return S_OK;
1709 }
1710
1711 HRESULT WINAPI SHEmptyRecycleBinA(HWND hwnd, LPCSTR pszRootPath, DWORD dwFlags)
1712 {
1713     FIXME("%p, %s, 0x%08lx - stub\n", hwnd, debugstr_a(pszRootPath), dwFlags);
1714
1715     return S_OK;
1716 }
1717
1718 HRESULT WINAPI SHEmptyRecycleBinW(HWND hwnd, LPCWSTR pszRootPath, DWORD dwFlags)
1719 {
1720     FIXME("%p, %s, 0x%08lx - stub\n", hwnd, debugstr_w(pszRootPath), dwFlags);
1721
1722     return S_OK;
1723 }
1724
1725 DWORD WINAPI SHFormatDrive(HWND hwnd, UINT drive, UINT fmtID, UINT options)
1726 {
1727     FIXME("%p, 0x%08x, 0x%08x, 0x%08x - stub\n", hwnd, drive, fmtID, options);
1728
1729     return SHFMT_NOFORMAT;
1730 }
1731
1732 HRESULT WINAPI SHQueryRecycleBinA(LPCSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
1733 {
1734     FIXME("%s, %p - stub\n", debugstr_a(pszRootPath), pSHQueryRBInfo);
1735
1736     pSHQueryRBInfo->i64Size = 0;
1737     pSHQueryRBInfo->i64NumItems = 0;
1738
1739     return S_OK;
1740 }
1741
1742 HRESULT WINAPI SHQueryRecycleBinW(LPCWSTR pszRootPath, LPSHQUERYRBINFO pSHQueryRBInfo)
1743 {
1744     FIXME("%s, %p - stub\n", debugstr_w(pszRootPath), pSHQueryRBInfo);
1745
1746     pSHQueryRBInfo->i64Size = 0;
1747     pSHQueryRBInfo->i64NumItems = 0;
1748
1749     return S_OK;
1750 }
1751
1752 /*************************************************************************
1753  *              SHSetLocalizedName (SHELL32.@)
1754  */
1755 HRESULT WINAPI SHSetLocalizedName(LPWSTR pszPath, LPCWSTR pszResModule, int idsRes)
1756 {
1757     FIXME("%p, %s, %d - stub\n", pszPath, debugstr_w(pszResModule), idsRes);
1758
1759     return S_OK;
1760 }