Fix buffer length calculation in InitializeGenericSF().
[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 <string.h>
23 #include <stdio.h>
24 #include "winerror.h"
25 #include "winreg.h"
26 #include "wine/debug.h"
27 #include "winnls.h"
28 #include "heap.h"
29
30 #include "wine/obj_base.h"
31 #include "shellapi.h"
32 #include "shlguid.h"
33 #include "shlobj.h"
34 #include "shell32_main.h"
35 #include "undocshell.h"
36 #include "pidl.h"
37 #include "shlwapi.h"
38 #include "commdlg.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 WINE_DECLARE_DEBUG_CHANNEL(pidl);
42
43 /*************************************************************************
44  * ParseFieldA                                  [internal]
45  *
46  * copies a field from a ',' delimited string
47  *
48  * first field is nField = 1
49  */
50 DWORD WINAPI ParseFieldA(
51         LPCSTR src,
52         DWORD nField,
53         LPSTR dst,
54         DWORD len)
55 {
56         WARN("(%s,0x%08lx,%p,%ld) semi-stub.\n",debugstr_a(src),nField,dst,len);
57
58         if (!src || !src[0] || !dst || !len)
59           return 0;
60
61         /* skip n fields delimited by ',' */
62         while (nField > 1)
63         {
64           if (*src=='\0') return FALSE;
65           if (*(src++)==',') nField--;
66         }
67
68         /* copy part till the next ',' to dst */
69         while ( *src!='\0' && *src!=',' && (len--)>0 ) *(dst++)=*(src++);
70
71         /* finalize the string */
72         *dst=0x0;
73
74         return TRUE;
75 }
76
77 /*************************************************************************
78  * ParseFieldW                  [internal]
79  *
80  * copies a field from a ',' delimited string
81  *
82  * first field is nField = 1
83  */
84 DWORD WINAPI ParseFieldW(LPCWSTR src, DWORD nField, LPWSTR dst, DWORD len)
85 {
86         FIXME("(%s,0x%08lx,%p,%ld) stub\n",
87           debugstr_w(src), nField, dst, len);
88         return FALSE;
89 }
90
91 /*************************************************************************
92  * ParseField                   [SHELL32.58]
93  */
94 DWORD WINAPI ParseFieldAW(LPCVOID src, DWORD nField, LPVOID dst, DWORD len)
95 {
96         if (SHELL_OsIsUnicode())
97           return ParseFieldW(src, nField, dst, len);
98         return ParseFieldA(src, nField, dst, len);
99 }
100
101 /*************************************************************************
102  * GetFileNameFromBrowse                        [SHELL32.63]
103  *
104  */
105 BOOL WINAPI GetFileNameFromBrowse(
106         HWND hwndOwner,
107         LPSTR lpstrFile,
108         DWORD nMaxFile,
109         LPCSTR lpstrInitialDir,
110         LPCSTR lpstrDefExt,
111         LPCSTR lpstrFilter,
112         LPCSTR lpstrTitle)
113 {
114     HMODULE hmodule;
115     FARPROC pGetOpenFileNameA;
116     OPENFILENAMEA ofn;
117     BOOL ret;
118
119     TRACE("%04x, %s, %ld, %s, %s, %s, %s)\n",
120           hwndOwner, lpstrFile, nMaxFile, lpstrInitialDir, lpstrDefExt,
121           lpstrFilter, lpstrTitle);
122
123     hmodule = LoadLibraryA("comdlg32.dll");
124     if(!hmodule) return FALSE;
125     pGetOpenFileNameA = GetProcAddress(hmodule, "GetOpenFileNameA");
126     if(!pGetOpenFileNameA)
127     {
128         FreeLibrary(hmodule);
129         return FALSE;
130     }
131
132     memset(&ofn, 0, sizeof(ofn));
133
134     ofn.lStructSize = sizeof(ofn);
135     ofn.hwndOwner = hwndOwner;
136     ofn.lpstrFilter = lpstrFilter;
137     ofn.lpstrFile = lpstrFile;
138     ofn.nMaxFile = nMaxFile;
139     ofn.lpstrInitialDir = lpstrInitialDir;
140     ofn.lpstrTitle = lpstrTitle;
141     ofn.lpstrDefExt = lpstrDefExt;
142     ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
143     ret = pGetOpenFileNameA(&ofn);
144
145     FreeLibrary(hmodule);
146     return ret;
147 }
148
149 /*************************************************************************
150  * SHGetSetSettings                             [SHELL32.68]
151  */
152 VOID WINAPI SHGetSetSettings(DWORD x, DWORD y, DWORD z)
153 {
154         FIXME("0x%08lx 0x%08lx 0x%08lx\n", x, y, z);
155 }
156
157 /*************************************************************************
158  * SHGetSettings                                [SHELL32.@]
159  *
160  * NOTES
161  *  the registry path are for win98 (tested)
162  *  and possibly are the same in nt40
163  *
164  */
165 VOID WINAPI SHGetSettings(LPSHELLFLAGSTATE lpsfs, DWORD dwMask)
166 {
167         HKEY    hKey;
168         DWORD   dwData;
169         DWORD   dwDataSize = sizeof (DWORD);
170
171         TRACE("(%p 0x%08lx)\n",lpsfs,dwMask);
172
173         if (RegCreateKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
174                                  0, 0, 0, KEY_ALL_ACCESS, 0, &hKey, 0))
175           return;
176
177         if ( (SSF_SHOWEXTENSIONS & dwMask) && !RegQueryValueExA(hKey, "HideFileExt", 0, 0, (LPBYTE)&dwData, &dwDataSize))
178           lpsfs->fShowExtensions  = ((dwData == 0) ?  0 : 1);
179
180         if ( (SSF_SHOWINFOTIP & dwMask) && !RegQueryValueExA(hKey, "ShowInfoTip", 0, 0, (LPBYTE)&dwData, &dwDataSize))
181           lpsfs->fShowInfoTip  = ((dwData == 0) ?  0 : 1);
182
183         if ( (SSF_DONTPRETTYPATH & dwMask) && !RegQueryValueExA(hKey, "DontPrettyPath", 0, 0, (LPBYTE)&dwData, &dwDataSize))
184           lpsfs->fDontPrettyPath  = ((dwData == 0) ?  0 : 1);
185
186         if ( (SSF_HIDEICONS & dwMask) && !RegQueryValueExA(hKey, "HideIcons", 0, 0, (LPBYTE)&dwData, &dwDataSize))
187           lpsfs->fHideIcons  = ((dwData == 0) ?  0 : 1);
188
189         if ( (SSF_MAPNETDRVBUTTON & dwMask) && !RegQueryValueExA(hKey, "MapNetDrvBtn", 0, 0, (LPBYTE)&dwData, &dwDataSize))
190           lpsfs->fMapNetDrvBtn  = ((dwData == 0) ?  0 : 1);
191
192         if ( (SSF_SHOWATTRIBCOL & dwMask) && !RegQueryValueExA(hKey, "ShowAttribCol", 0, 0, (LPBYTE)&dwData, &dwDataSize))
193           lpsfs->fShowAttribCol  = ((dwData == 0) ?  0 : 1);
194
195         if (((SSF_SHOWALLOBJECTS | SSF_SHOWSYSFILES) & dwMask) && !RegQueryValueExA(hKey, "Hidden", 0, 0, (LPBYTE)&dwData, &dwDataSize))
196         { if (dwData == 0)
197           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 0;
198             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 0;
199           }
200           else if (dwData == 1)
201           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 1;
202             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 0;
203           }
204           else if (dwData == 2)
205           { if (SSF_SHOWALLOBJECTS & dwMask)    lpsfs->fShowAllObjects  = 0;
206             if (SSF_SHOWSYSFILES & dwMask)      lpsfs->fShowSysFiles  = 1;
207           }
208         }
209         RegCloseKey (hKey);
210
211         TRACE("-- 0x%04x\n", *(WORD*)lpsfs);
212 }
213
214 /*************************************************************************
215  * SHShellFolderView_Message                    [SHELL32.73]
216  *
217  * PARAMETERS
218  *  hwndCabinet defines the explorer cabinet window that contains the
219  *              shellview you need to communicate with
220  *  uMsg        identifying the SFVM enum to perform
221  *  lParam
222  *
223  * NOTES
224  *  Message SFVM_REARRANGE = 1
225  *    This message gets sent when a column gets clicked to instruct the
226  *    shell view to re-sort the item list. lParam identifies the column
227  *    that was clicked.
228  */
229 int WINAPI SHShellFolderView_Message(
230         HWND hwndCabinet,
231         DWORD dwMessage,
232         DWORD dwParam)
233 {
234         FIXME("%04x %08lx %08lx stub\n",hwndCabinet, dwMessage, dwParam);
235         return 0;
236 }
237
238 /*************************************************************************
239  * RegisterShellHook                            [SHELL32.181]
240  *
241  * PARAMS
242  *      hwnd [I]  window handle
243  *      y    [I]  flag ????
244  *
245  * NOTES
246  *     exported by ordinal
247  */
248 BOOL WINAPI RegisterShellHook(
249         HWND hWnd,
250         DWORD dwType)
251 {
252         FIXME("(0x%08x,0x%08lx):stub.\n",hWnd, dwType);
253         return TRUE;
254 }
255 /*************************************************************************
256  * ShellMessageBoxW                             [SHELL32.182]
257  *
258  * Format and output errormessage.
259  *
260  * idText       resource ID of title or LPSTR
261  * idTitle      resource ID of title or LPSTR
262  *
263  * NOTES
264  *     exported by ordinal
265  */
266 int WINAPIV ShellMessageBoxW(
267         HINSTANCE hInstance,
268         HWND hWnd,
269         LPCWSTR lpText,
270         LPCWSTR lpCaption,
271         UINT uType,
272         ...)
273 {
274         WCHAR   szText[100],szTitle[100];
275         LPCWSTR pszText = szText, pszTitle = szTitle, pszTemp;
276         va_list args;
277         int     ret;
278
279         va_start(args, uType);
280         /* wvsprintfA(buf,fmt, args); */
281
282         TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
283         (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
284
285         if (!HIWORD(lpCaption))
286           LoadStringW(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle)/sizeof(szTitle[0]));
287         else
288           pszTitle = lpCaption;
289
290         if (!HIWORD(lpText))
291           LoadStringW(hInstance, (DWORD)lpText, szText, sizeof(szText)/sizeof(szText[0]));
292         else
293           pszText = lpText;
294
295         FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
296                        pszText, 0, 0, (LPWSTR)&pszTemp, 0, &args);
297
298         va_end(args);
299
300         ret = MessageBoxW(hWnd,pszTemp,pszTitle,uType);
301         LocalFree((HLOCAL)pszTemp);
302         return ret;
303 }
304
305 /*************************************************************************
306  * ShellMessageBoxA                             [SHELL32.183]
307  */
308 int WINAPIV ShellMessageBoxA(
309         HINSTANCE hInstance,
310         HWND hWnd,
311         LPCSTR lpText,
312         LPCSTR lpCaption,
313         UINT uType,
314         ...)
315 {
316         char    szText[100],szTitle[100];
317         LPCSTR  pszText = szText, pszTitle = szTitle, pszTemp;
318         va_list args;
319         int     ret;
320
321         va_start(args, uType);
322         /* wvsprintfA(buf,fmt, args); */
323
324         TRACE("(%08lx,%08lx,%p,%p,%08x)\n",
325         (DWORD)hInstance,(DWORD)hWnd,lpText,lpCaption,uType);
326
327         if (!HIWORD(lpCaption))
328           LoadStringA(hInstance, (DWORD)lpCaption, szTitle, sizeof(szTitle));
329         else
330           pszTitle = lpCaption;
331
332         if (!HIWORD(lpText))
333           LoadStringA(hInstance, (DWORD)lpText, szText, sizeof(szText));
334         else
335           pszText = lpText;
336
337         FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING,
338                        pszText, 0, 0, (LPSTR)&pszTemp, 0, &args);
339
340         va_end(args);
341
342         ret = MessageBoxA(hWnd,pszTemp,pszTitle,uType);
343         LocalFree((HLOCAL)pszTemp);
344         return ret;
345 }
346
347 /*************************************************************************
348  * SHRegisterDragDrop                           [SHELL32.86]
349  *
350  * NOTES
351  *     exported by ordinal
352  */
353 HRESULT WINAPI SHRegisterDragDrop(
354         HWND hWnd,
355         LPDROPTARGET pDropTarget)
356 {
357         FIXME("(0x%08x,%p):stub.\n", hWnd, pDropTarget);
358         if (GetShellOle()) return pRegisterDragDrop(hWnd, pDropTarget);
359         return 0;
360 }
361
362 /*************************************************************************
363  * SHRevokeDragDrop                             [SHELL32.87]
364  *
365  * NOTES
366  *     exported by ordinal
367  */
368 HRESULT WINAPI SHRevokeDragDrop(HWND hWnd)
369 {
370     FIXME("(0x%08x):stub.\n",hWnd);
371     return 0;
372 }
373
374 /*************************************************************************
375  * SHDoDragDrop                                 [SHELL32.88]
376  *
377  * NOTES
378  *     exported by ordinal
379  */
380 HRESULT WINAPI SHDoDragDrop(
381         HWND hWnd,
382         LPDATAOBJECT lpDataObject,
383         LPDROPSOURCE lpDropSource,
384         DWORD dwOKEffect,
385         LPDWORD pdwEffect)
386 {
387     FIXME("(0x%04x %p %p 0x%08lx %p):stub.\n",
388     hWnd, lpDataObject, lpDropSource, dwOKEffect, pdwEffect);
389     return 0;
390 }
391
392 /*************************************************************************
393  * ArrangeWindows                               [SHELL32.184]
394  *
395  */
396 WORD WINAPI ArrangeWindows(
397         HWND hwndParent,
398         DWORD dwReserved,
399         LPCRECT lpRect,
400         WORD cKids,
401         CONST HWND * lpKids)
402 {
403     FIXME("(0x%08x 0x%08lx %p 0x%04x %p):stub.\n",
404            hwndParent, dwReserved, lpRect, cKids, lpKids);
405     return 0;
406 }
407
408 /*************************************************************************
409  * SignalFileOpen                               [SHELL32.103]
410  *
411  * NOTES
412  *     exported by ordinal
413  */
414 DWORD WINAPI
415 SignalFileOpen (DWORD dwParam1)
416 {
417     FIXME("(0x%08lx):stub.\n", dwParam1);
418
419     return 0;
420 }
421
422 /*************************************************************************
423  * SHADD_get_policy - helper function for SHAddToRecentDocs
424  *
425  * PARAMETERS
426  *   policy    [IN]  policy name (null termed string) to find
427  *   type      [OUT] ptr to DWORD to receive type
428  *   buffer    [OUT] ptr to area to hold data retrieved
429  *   len       [IN/OUT] ptr to DWORD holding size of buffer and getting
430  *                      length filled
431  *
432  * RETURNS
433  *   result of the SHQueryValueEx call
434  */
435 static INT SHADD_get_policy(LPSTR policy, LPDWORD type, LPVOID buffer, LPDWORD len)
436 {
437     HKEY Policy_basekey;
438     INT ret;
439
440     /* Get the key for the policies location in the registry
441      */
442     if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
443                       "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
444                       0, KEY_READ, &Policy_basekey)) {
445
446         if (RegOpenKeyExA(HKEY_CURRENT_USER,
447                           "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
448                           0, KEY_READ, &Policy_basekey)) {
449             TRACE("No Explorer Policies location exists. Policy wanted=%s\n",
450                   policy);
451             *len = 0;
452             return ERROR_FILE_NOT_FOUND;
453         }
454     }
455
456     /* Retrieve the data if it exists
457      */
458     ret = SHQueryValueExA(Policy_basekey, policy, 0, type, buffer, len);
459     RegCloseKey(Policy_basekey);
460     return ret;
461 }
462
463
464 /*************************************************************************
465  * SHADD_compare_mru - helper function for SHAddToRecentDocs
466  *
467  * PARAMETERS
468  *   data1     [IN] data being looked for
469  *   data2     [IN] data in MRU
470  *   cbdata    [IN] length from FindMRUData call (not used)
471  *
472  * RETURNS
473  *   position within MRU list that data was added.
474  */
475 static INT CALLBACK SHADD_compare_mru(LPCVOID data1, LPCVOID data2, DWORD cbData)
476 {
477     return lstrcmpiA(data1, data2);
478 }
479
480 /*************************************************************************
481  * SHADD_create_add_mru_data - helper function for SHAddToRecentDocs
482  *
483  * PARAMETERS
484  *   mruhandle    [IN] handle for created MRU list
485  *   doc_name     [IN] null termed pure doc name
486  *   new_lnk_name [IN] null termed path and file name for .lnk file
487  *   buffer       [IN/OUT] 2048 byte area to consturct MRU data
488  *   len          [OUT] ptr to int to receive space used in buffer
489  *
490  * RETURNS
491  *   position within MRU list that data was added.
492  */
493 static INT SHADD_create_add_mru_data(HANDLE mruhandle, LPSTR doc_name, LPSTR new_lnk_name,
494                                      LPSTR buffer, INT *len)
495 {
496     LPSTR ptr;
497     INT wlen;
498
499     /*FIXME: Document:
500      *  RecentDocs MRU data structure seems to be:
501      *    +0h   document file name w/ terminating 0h
502      *    +nh   short int w/ size of remaining
503      *    +n+2h 02h 30h, or 01h 30h, or 00h 30h  -  unknown
504      *    +n+4h 10 bytes zeros  -   unknown
505      *    +n+eh shortcut file name w/ terminating 0h
506      *    +n+e+nh 3 zero bytes  -  unknown
507      */
508
509     /* Create the MRU data structure for "RecentDocs"
510          */
511     ptr = buffer;
512     lstrcpyA(ptr, doc_name);
513     ptr += (lstrlenA(buffer) + 1);
514     wlen= lstrlenA(new_lnk_name) + 1 + 12;
515     *((short int*)ptr) = wlen;
516     ptr += 2;   /* step past the length */
517     *(ptr++) = 0x30;  /* unknown reason */
518     *(ptr++) = 0;     /* unknown, but can be 0x00, 0x01, 0x02 */
519     memset(ptr, 0, 10);
520     ptr += 10;
521     lstrcpyA(ptr, new_lnk_name);
522     ptr += (lstrlenA(new_lnk_name) + 1);
523     memset(ptr, 0, 3);
524     ptr += 3;
525     *len = ptr - buffer;
526
527     /* Add the new entry into the MRU list
528      */
529     return pAddMRUData(mruhandle, (LPCVOID)buffer, *len);
530 }
531
532 /*************************************************************************
533  * SHAddToRecentDocs                            [SHELL32.@]
534  *
535  * PARAMETERS
536  *   uFlags  [IN] SHARD_PATH or SHARD_PIDL
537  *   pv      [IN] string or pidl, NULL clears the list
538  *
539  * NOTES
540  *     exported by name
541  *
542  * FIXME: ?? MSDN shows this as a VOID
543  */
544 DWORD WINAPI SHAddToRecentDocs (UINT uFlags,LPCVOID pv)
545 {
546
547 /* FIXME: !!! move CREATEMRULIST and flags to header file !!! */
548 /*        !!! it is in both here and comctl32undoc.c      !!! */
549 typedef struct tagCREATEMRULIST
550 {
551     DWORD  cbSize;        /* size of struct */
552     DWORD  nMaxItems;     /* max no. of items in list */
553     DWORD  dwFlags;       /* see below */
554     HKEY   hKey;          /* root reg. key under which list is saved */
555     LPCSTR lpszSubKey;    /* reg. subkey */
556     PROC   lpfnCompare;   /* item compare proc */
557 } CREATEMRULIST, *LPCREATEMRULIST;
558
559 /* dwFlags */
560 #define MRUF_STRING_LIST  0 /* list will contain strings */
561 #define MRUF_BINARY_LIST  1 /* list will contain binary data */
562 #define MRUF_DELAYED_SAVE 2 /* only save list order to reg. is FreeMRUList */
563
564 /* If list is a string list lpfnCompare has the following prototype
565  * int CALLBACK MRUCompareString(LPCSTR s1, LPCSTR s2)
566  * for binary lists the prototype is
567  * int CALLBACK MRUCompareBinary(LPCVOID data1, LPCVOID data2, DWORD cbData)
568  * where cbData is the no. of bytes to compare.
569  * Need to check what return value means identical - 0?
570  */
571
572
573     UINT olderrormode;
574     HKEY HCUbasekey;
575     CHAR doc_name[MAX_PATH];
576     CHAR link_dir[MAX_PATH];
577     CHAR new_lnk_filepath[MAX_PATH];
578     CHAR new_lnk_name[MAX_PATH];
579     IMalloc *ppM;
580     LPITEMIDLIST pidl;
581     HWND hwnd = 0;       /* FIXME:  get real window handle */
582     INT ret;
583     DWORD data[64], datalen, type;
584
585     /*FIXME: Document:
586      *  RecentDocs MRU data structure seems to be:
587      *    +0h   document file name w/ terminating 0h
588      *    +nh   short int w/ size of remaining
589      *    +n+2h 02h 30h, or 01h 30h, or 00h 30h  -  unknown
590      *    +n+4h 10 bytes zeros  -   unknown
591      *    +n+eh shortcut file name w/ terminating 0h
592      *    +n+e+nh 3 zero bytes  -  unknown
593      */
594
595     /* See if we need to do anything.
596      */
597     datalen = 64;
598     ret=SHADD_get_policy( "NoRecentDocsHistory", &type, &data, &datalen);
599     if ((ret > 0) && (ret != ERROR_FILE_NOT_FOUND)) {
600         ERR("Error %d getting policy \"NoRecentDocsHistory\"\n", ret);
601         return 0;
602     }
603     if (ret == ERROR_SUCCESS) {
604         if (!( (type == REG_DWORD) ||
605                ((type == REG_BINARY) && (datalen == 4)) )) {
606             ERR("Error policy data for \"NoRecentDocsHistory\" not formated correctly, type=%ld, len=%ld\n",
607                 type, datalen);
608             return 0;
609         }
610
611         TRACE("policy value for NoRecentDocsHistory = %08lx\n", data[0]);
612         /* now test the actual policy value */
613         if ( data[0] != 0)
614             return 0;
615     }
616
617     /* Open key to where the necessary info is
618      */
619     /* FIXME: This should be done during DLL PROCESS_ATTACH (or THREAD_ATTACH)
620      *        and the close should be done during the _DETACH. The resulting
621      *        key is stored in the DLL global data.
622      */
623     if (RegCreateKeyExA(HKEY_CURRENT_USER,
624                         "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer",
625                         0, 0, 0, KEY_READ, 0, &HCUbasekey, 0)) {
626         ERR("Failed to create 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer'\n");
627         return 0;
628     }
629
630     /* Get path to user's "Recent" directory
631      */
632     if(SUCCEEDED(SHGetMalloc(&ppM))) {
633         if (SUCCEEDED(SHGetSpecialFolderLocation(hwnd, CSIDL_RECENT,
634                                                  &pidl))) {
635             SHGetPathFromIDListA(pidl, link_dir);
636             IMalloc_Free(ppM, pidl);
637         }
638         else {
639             /* serious issues */
640             link_dir[0] = 0;
641             ERR("serious issues 1\n");
642         }
643         IMalloc_Release(ppM);
644     }
645     else {
646         /* serious issues */
647         link_dir[0] = 0;
648         ERR("serious issues 2\n");
649     }
650     TRACE("Users Recent dir %s\n", link_dir);
651
652     /* If no input, then go clear the lists */
653     if (!pv) {
654         /* clear user's Recent dir
655          */
656
657         /* FIXME: delete all files in "link_dir"
658          *
659          * while( more files ) {
660          *    lstrcpyA(old_lnk_name, link_dir);
661          *    PathAppendA(old_lnk_name, filenam);
662          *    DeleteFileA(old_lnk_name);
663          * }
664          */
665         FIXME("should delete all files in %s\\ \n", link_dir);
666
667         /* clear MRU list
668          */
669         /* MS Bug ?? v4.72.3612.1700 of shell32 does the delete against
670          *  HKEY_LOCAL_MACHINE version of ...CurrentVersion\Explorer
671          *  and naturally it fails w/ rc=2. It should do it against
672          *  HKEY_CURRENT_USER which is where it is stored, and where
673          *  the MRU routines expect it!!!!
674          */
675         RegDeleteKeyA(HCUbasekey, "RecentDocs");
676         RegCloseKey(HCUbasekey);
677         return 0;
678     }
679
680     /* Have data to add, the jobs to be done:
681      *   1. Add document to MRU list in registry "HKCU\Software\
682      *      Microsoft\Windows\CurrentVersion\Explorer\RecentDocs".
683      *   2. Add shortcut to document in the user's Recent directory
684      *      (CSIDL_RECENT).
685      *   3. Add shortcut to Start menu's Documents submenu.
686      */
687
688     /* Get the pure document name from the input
689      */
690     if (uFlags & SHARD_PIDL) {
691         SHGetPathFromIDListA((LPCITEMIDLIST) pv, doc_name);
692     }
693     else {
694         lstrcpyA(doc_name, (LPSTR) pv);
695     }
696     TRACE("full document name %s\n", doc_name);
697     PathStripPathA(doc_name);
698     TRACE("stripped document name %s\n", doc_name);
699
700
701     /* ***  JOB 1: Update registry for ...\Explorer\RecentDocs list  *** */
702
703     {  /* on input needs:
704         *      doc_name    -  pure file-spec, no path
705         *      link_dir    -  path to the user's Recent directory
706         *      HCUbasekey  -  key of ...Windows\CurrentVersion\Explorer" node
707         * creates:
708         *      new_lnk_name-  pure file-spec, no path for new .lnk file
709         *      new_lnk_filepath
710         *                  -  path and file name of new .lnk file
711         */
712         CREATEMRULIST mymru;
713         HANDLE mruhandle;
714         INT len, pos, bufused, err;
715         INT i;
716         DWORD attr;
717         CHAR buffer[2048];
718         CHAR *ptr;
719         CHAR old_lnk_name[MAX_PATH];
720         short int slen;
721
722         mymru.cbSize = sizeof(CREATEMRULIST);
723         mymru.nMaxItems = 15;
724         mymru.dwFlags = MRUF_BINARY_LIST | MRUF_DELAYED_SAVE;
725         mymru.hKey = HCUbasekey;
726         mymru.lpszSubKey = "RecentDocs";
727         mymru.lpfnCompare = &SHADD_compare_mru;
728         mruhandle = pCreateMRUListA(&mymru);
729         if (!mruhandle) {
730             /* MRU failed */
731             ERR("MRU processing failed, handle zero\n");
732             RegCloseKey(HCUbasekey);
733             return 0;
734         }
735         len = lstrlenA(doc_name);
736         pos = pFindMRUData(mruhandle, doc_name, len, 0);
737
738         /* Now get the MRU entry that will be replaced
739          * and delete the .lnk file for it
740          */
741         if ((bufused = pEnumMRUListA(mruhandle, (pos == -1) ? 14 : pos,
742                                      buffer, 2048)) != -1) {
743             ptr = buffer;
744             ptr += (lstrlenA(buffer) + 1);
745             slen = *((short int*)ptr);
746             ptr += 2;  /* skip the length area */
747             if (bufused >= slen + (ptr-buffer)) {
748                 /* buffer size looks good */
749                 ptr += 12; /* get to string */
750                 len = bufused - (ptr-buffer);  /* get length of buf remaining */
751                 if ((lstrlenA(ptr) > 0) && (lstrlenA(ptr) <= len-1)) {
752                     /* appears to be good string */
753                     lstrcpyA(old_lnk_name, link_dir);
754                     PathAppendA(old_lnk_name, ptr);
755                     if (!DeleteFileA(old_lnk_name)) {
756                         if ((attr = GetFileAttributesA(old_lnk_name)) == -1) {
757                             if ((err = GetLastError()) != ERROR_FILE_NOT_FOUND) {
758                                 ERR("Delete for %s failed, err=%d, attr=%08lx\n",
759                                     old_lnk_name, err, attr);
760                             }
761                             else {
762                                 TRACE("old .lnk file %s did not exist\n",
763                                       old_lnk_name);
764                             }
765                         }
766                         else {
767                             ERR("Delete for %s failed, attr=%08lx\n",
768                                 old_lnk_name, attr);
769                         }
770                     }
771                     else {
772                         TRACE("deleted old .lnk file %s\n", old_lnk_name);
773                     }
774                 }
775             }
776         }
777
778         /* Create usable .lnk file name for the "Recent" directory
779          */
780         wsprintfA(new_lnk_name, "%s.lnk", doc_name);
781         lstrcpyA(new_lnk_filepath, link_dir);
782         PathAppendA(new_lnk_filepath, new_lnk_name);
783         i = 1;
784         olderrormode = SetErrorMode(SEM_FAILCRITICALERRORS);
785         while (GetFileAttributesA(new_lnk_filepath) != -1) {
786             i++;
787             wsprintfA(new_lnk_name, "%s (%u).lnk", doc_name, i);
788             lstrcpyA(new_lnk_filepath, link_dir);
789             PathAppendA(new_lnk_filepath, new_lnk_name);
790         }
791         SetErrorMode(olderrormode);
792         TRACE("new shortcut will be %s\n", new_lnk_filepath);
793
794         /* Now add the new MRU entry and data
795          */
796         pos = SHADD_create_add_mru_data(mruhandle, doc_name, new_lnk_name,
797                                         buffer, &len);
798         pFreeMRUListA(mruhandle);
799         TRACE("Updated MRU list, new doc is position %d\n", pos);
800     }
801
802     /* ***  JOB 2: Create shortcut in user's "Recent" directory  *** */
803
804     {  /* on input needs:
805         *      doc_name    -  pure file-spec, no path
806         *      new_lnk_filepath
807         *                  -  path and file name of new .lnk file
808         *      uFlags[in]  -  flags on call to SHAddToRecentDocs
809         *      pv[in]      -  document path/pidl on call to SHAddToRecentDocs
810         */
811         IShellLinkA *psl = NULL;
812         IPersistFile *pPf = NULL;
813         HRESULT hres;
814         CHAR desc[MAX_PATH];
815         WCHAR widelink[MAX_PATH];
816
817         CoInitialize(0);
818
819         hres = CoCreateInstance( &CLSID_ShellLink,
820                                  NULL,
821                                  CLSCTX_INPROC_SERVER,
822                                  &IID_IShellLinkA,
823                                  (LPVOID )&psl);
824         if(SUCCEEDED(hres)) {
825
826             hres = IShellLinkA_QueryInterface(psl, &IID_IPersistFile,
827                                              (LPVOID *)&pPf);
828             if(FAILED(hres)) {
829                 /* bombed */
830                 ERR("failed QueryInterface for IPersistFile %08lx\n", hres);
831                 goto fail;
832             }
833
834             /* Set the document path or pidl */
835             if (uFlags & SHARD_PIDL) {
836                 hres = IShellLinkA_SetIDList(psl, (LPCITEMIDLIST) pv);
837             } else {
838                 hres = IShellLinkA_SetPath(psl, (LPCSTR) pv);
839             }
840             if(FAILED(hres)) {
841                 /* bombed */
842                 ERR("failed Set{IDList|Path} %08lx\n", hres);
843                 goto fail;
844             }
845
846             lstrcpyA(desc, "Shortcut to ");
847             lstrcatA(desc, doc_name);
848             hres = IShellLinkA_SetDescription(psl, desc);
849             if(FAILED(hres)) {
850                 /* bombed */
851                 ERR("failed SetDescription %08lx\n", hres);
852                 goto fail;
853             }
854
855             MultiByteToWideChar(CP_ACP, 0, new_lnk_filepath, -1,
856                                 widelink, MAX_PATH);
857             /* create the short cut */
858             hres = IPersistFile_Save(pPf, widelink, TRUE);
859             if(FAILED(hres)) {
860                 /* bombed */
861                 ERR("failed IPersistFile::Save %08lx\n", hres);
862                 IPersistFile_Release(pPf);
863                 IShellLinkA_Release(psl);
864                 goto fail;
865             }
866             hres = IPersistFile_SaveCompleted(pPf, widelink);
867             IPersistFile_Release(pPf);
868             IShellLinkA_Release(psl);
869             TRACE("shortcut %s has been created, result=%08lx\n",
870                   new_lnk_filepath, hres);
871         }
872         else {
873             ERR("CoCreateInstance failed, hres=%08lx\n", hres);
874         }
875     }
876
877  fail:
878     CoUninitialize();
879
880     /* all done */
881     RegCloseKey(HCUbasekey);
882     return 0;
883 }
884
885 /*************************************************************************
886  * SHCreateShellFolderViewEx                    [SHELL32.174]
887  *
888  * NOTES
889  *  see IShellFolder::CreateViewObject
890  */
891 HRESULT WINAPI SHCreateShellFolderViewEx(
892         LPCSHELLFOLDERVIEWINFO psvcbi, /* [in] shelltemplate struct */
893         LPSHELLVIEW* ppv)              /* [out] IShellView pointer */
894 {
895         IShellView * psf;
896         HRESULT hRes;
897
898         TRACE("sf=%p pidl=%p cb=%p mode=0x%08x parm=0x%08lx\n",
899           psvcbi->pshf, psvcbi->pidlFolder, psvcbi->lpfnCallback,
900           psvcbi->uViewMode, psvcbi->dwUser);
901
902         psf = IShellView_Constructor(psvcbi->pshf);
903
904         if (!psf)
905           return E_OUTOFMEMORY;
906
907         IShellView_AddRef(psf);
908         hRes = IShellView_QueryInterface(psf, &IID_IShellView, (LPVOID *)ppv);
909         IShellView_Release(psf);
910
911         return hRes;
912 }
913 /*************************************************************************
914  *  SHWinHelp                                   [SHELL32.127]
915  *
916  */
917 HRESULT WINAPI SHWinHelp (DWORD v, DWORD w, DWORD x, DWORD z)
918 {       FIXME("0x%08lx 0x%08lx 0x%08lx 0x%08lx stub\n",v,w,x,z);
919         return 0;
920 }
921 /*************************************************************************
922  *  SHRunControlPanel [SHELL32.161]
923  *
924  */
925 HRESULT WINAPI SHRunControlPanel (DWORD x, DWORD z)
926 {       FIXME("0x%08lx 0x%08lx stub\n",x,z);
927         return 0;
928 }
929 /*************************************************************************
930  * ShellExecuteEx                               [SHELL32.291]
931  *
932  */
933 BOOL WINAPI ShellExecuteExAW (LPVOID sei)
934 {       if (SHELL_OsIsUnicode())
935           return ShellExecuteExW (sei);
936         return ShellExecuteExA (sei);
937 }
938 /*************************************************************************
939  * ShellExecuteExA                              [SHELL32.292]
940  *
941  * placeholder in the commandline:
942  *      %1 file
943  *      %2 printer
944  *      %3 driver
945  *      %4 port
946  *      %I adress of a global item ID (explorer switch /idlist)
947  *      %L ??? path/url/current file ???
948  *      %S ???
949  *      %* all following parameters (see batfile)
950  */
951 BOOL WINAPI ShellExecuteExA (LPSHELLEXECUTEINFOA sei)
952 {       CHAR szApplicationName[MAX_PATH],szCommandline[MAX_PATH],szPidl[20];
953         LPSTR pos;
954         int gap, len;
955         STARTUPINFOA  startup;
956         PROCESS_INFORMATION info;
957
958         WARN("mask=0x%08lx hwnd=0x%04x verb=%s file=%s parm=%s dir=%s show=0x%08x class=%s incomplete\n",
959              sei->fMask, sei->hwnd, debugstr_a(sei->lpVerb),
960              debugstr_a(sei->lpFile), debugstr_a(sei->lpParameters),
961              debugstr_a(sei->lpDirectory), sei->nShow,
962              (sei->fMask & SEE_MASK_CLASSNAME) ? debugstr_a(sei->lpClass) : "not used");
963
964         ZeroMemory(szApplicationName,MAX_PATH);
965         if (sei->lpFile)
966           strcpy(szApplicationName, sei->lpFile);
967
968         ZeroMemory(szCommandline,MAX_PATH);
969         if (sei->lpParameters)
970           strcpy(szCommandline, sei->lpParameters);
971
972         if (sei->fMask & (SEE_MASK_CLASSKEY | SEE_MASK_INVOKEIDLIST | SEE_MASK_ICON | SEE_MASK_HOTKEY |
973                           SEE_MASK_CONNECTNETDRV | SEE_MASK_FLAG_DDEWAIT |
974                           SEE_MASK_DOENVSUBST | SEE_MASK_FLAG_NO_UI | SEE_MASK_UNICODE |
975                           SEE_MASK_NO_CONSOLE | SEE_MASK_ASYNCOK | SEE_MASK_HMONITOR ))
976         {
977           FIXME("flags ignored: 0x%08lx\n", sei->fMask);
978         }
979
980         /* launch a document by fileclass like 'Wordpad.Document.1' */
981         if (sei->fMask & SEE_MASK_CLASSNAME)
982         {
983           /* FIXME: szCommandline should not be of a fixed size. Plus MAX_PATH is way too short! */
984           /* the commandline contains 'c:\Path\wordpad.exe "%1"' */
985           HCR_GetExecuteCommand(sei->lpClass, (sei->lpVerb) ? sei->lpVerb : "open", szCommandline, sizeof(szCommandline));
986           /* FIXME: get the extension of lpFile, check if it fits to the lpClass */
987           TRACE("SEE_MASK_CLASSNAME->'%s'\n", szCommandline);
988         }
989
990         /* process the IDList */
991         if ( (sei->fMask & SEE_MASK_INVOKEIDLIST) == SEE_MASK_INVOKEIDLIST) /*0x0c*/
992         {
993           SHGetPathFromIDListA (sei->lpIDList,szApplicationName);
994           TRACE("-- idlist=%p (%s)\n", sei->lpIDList, szApplicationName);
995         }
996         else
997         {
998           if (sei->fMask & SEE_MASK_IDLIST )
999           {
1000             pos = strstr(szCommandline, "%I");
1001             if (pos)
1002             {
1003               LPVOID pv;
1004               HGLOBAL hmem = SHAllocShared ( sei->lpIDList, ILGetSize(sei->lpIDList), 0);
1005               pv = SHLockShared(hmem,0);
1006               sprintf(szPidl,":%p",pv );
1007               SHUnlockShared(pv);
1008
1009               gap = strlen(szPidl);
1010               len = strlen(pos)-2;
1011               memmove(pos+gap,pos+2,len);
1012               memcpy(pos,szPidl,gap);
1013
1014             }
1015           }
1016         }
1017
1018         TRACE("execute:'%s','%s'\n",szApplicationName, szCommandline);
1019
1020         if (szCommandline[0]) {
1021           strcat(szApplicationName, " ");
1022           strcat(szApplicationName, szCommandline);
1023         }
1024
1025         ZeroMemory(&startup,sizeof(STARTUPINFOA));
1026         startup.cb = sizeof(STARTUPINFOA);
1027
1028         if (! CreateProcessA(NULL, szApplicationName,
1029                          NULL, NULL, FALSE, 0,
1030                          NULL, sei->lpDirectory,
1031                          &startup, &info))
1032         {
1033         BOOL failed = TRUE;
1034
1035         if ((!sei->lpVerb)||(!strcasecmp(sei->lpVerb,"open")))
1036         {
1037             LPSTR   ext = PathFindExtensionA(szApplicationName);
1038             CHAR    key[1023];
1039             CHAR    buffer[1023];
1040             CHAR    cmdline[1023];
1041             DWORD   size;
1042
1043             sprintf(key,"Software\\Classes\\%s",ext);
1044             size = 1023;
1045             if (!RegQueryValueA(HKEY_LOCAL_MACHINE,key,buffer,&size))
1046             {
1047                 sprintf(key,"Software\\Classes\\%s\\shell\\%s\\command", buffer,
1048                     (sei->lpVerb)?sei->lpVerb:"open");
1049                 size = 1023;
1050                 if (!RegQueryValueA(HKEY_LOCAL_MACHINE,key,buffer,&size))
1051                 {
1052                     sprintf(cmdline,"%s \"%s\"",buffer,szApplicationName);
1053                     if (CreateProcessA(NULL,cmdline,  NULL, NULL, FALSE, 0,
1054                                    NULL, sei->lpDirectory, &startup, &info))
1055                         failed = FALSE;
1056                 }
1057             }
1058         }
1059
1060         if (failed)
1061         {
1062             sei->hInstApp = GetLastError();
1063             return FALSE;
1064         }
1065         }
1066
1067         sei->hInstApp = 33;
1068
1069         if(sei->fMask & SEE_MASK_NOCLOSEPROCESS)
1070           sei->hProcess = info.hProcess;
1071         else
1072           CloseHandle( info.hProcess );
1073         CloseHandle( info.hThread );
1074         return TRUE;
1075 }
1076 /*************************************************************************
1077  * ShellExecuteExW                              [SHELL32.293]
1078  *
1079  */
1080 BOOL WINAPI ShellExecuteExW (LPSHELLEXECUTEINFOW sei)
1081 {       SHELLEXECUTEINFOA seiA;
1082         DWORD ret;
1083
1084         TRACE("%p\n", sei);
1085
1086         memcpy(&seiA, sei, sizeof(SHELLEXECUTEINFOA));
1087
1088         if (sei->lpVerb)
1089           seiA.lpVerb = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpVerb);
1090
1091         if (sei->lpFile)
1092           seiA.lpFile = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpFile);
1093
1094         if (sei->lpParameters)
1095           seiA.lpParameters = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpParameters);
1096
1097         if (sei->lpDirectory)
1098           seiA.lpDirectory = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpDirectory);
1099
1100         if ((sei->fMask & SEE_MASK_CLASSNAME) && sei->lpClass)
1101           seiA.lpClass = HEAP_strdupWtoA( GetProcessHeap(), 0, sei->lpClass);
1102         else
1103           seiA.lpClass = NULL;
1104
1105         ret = ShellExecuteExA(&seiA);
1106
1107         if (seiA.lpVerb)        HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpVerb );
1108         if (seiA.lpFile)        HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpFile );
1109         if (seiA.lpParameters)  HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpParameters );
1110         if (seiA.lpDirectory)   HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpDirectory );
1111         if (seiA.lpClass)       HeapFree( GetProcessHeap(), 0, (LPSTR) seiA.lpClass );
1112
1113         return ret;
1114 }
1115
1116 static LPUNKNOWN SHELL32_IExplorerInterface=0;
1117 /*************************************************************************
1118  * SHSetInstanceExplorer                        [SHELL32.176]
1119  *
1120  * NOTES
1121  *  Sets the interface
1122  */
1123 HRESULT WINAPI SHSetInstanceExplorer (LPUNKNOWN lpUnknown)
1124 {       TRACE("%p\n", lpUnknown);
1125         SHELL32_IExplorerInterface = lpUnknown;
1126         return (HRESULT) lpUnknown;
1127 }
1128 /*************************************************************************
1129  * SHGetInstanceExplorer                        [SHELL32.@]
1130  *
1131  * NOTES
1132  *  gets the interface pointer of the explorer and a reference
1133  */
1134 HRESULT WINAPI SHGetInstanceExplorer (LPUNKNOWN * lpUnknown)
1135 {       TRACE("%p\n", lpUnknown);
1136
1137         *lpUnknown = SHELL32_IExplorerInterface;
1138
1139         if (!SHELL32_IExplorerInterface)
1140           return E_FAIL;
1141
1142         IUnknown_AddRef(SHELL32_IExplorerInterface);
1143         return NOERROR;
1144 }
1145 /*************************************************************************
1146  * SHFreeUnusedLibraries                        [SHELL32.123]
1147  *
1148  * NOTES
1149  *  exported by name
1150  */
1151 void WINAPI SHFreeUnusedLibraries (void)
1152 {
1153         FIXME("stub\n");
1154 }
1155 /*************************************************************************
1156  * DAD_SetDragImage                             [SHELL32.136]
1157  *
1158  * NOTES
1159  *  exported by name
1160  */
1161 BOOL WINAPI DAD_SetDragImage(
1162         HIMAGELIST himlTrack,
1163         LPPOINT lppt)
1164 {
1165         FIXME("%p %p stub\n",himlTrack, lppt);
1166   return 0;
1167 }
1168 /*************************************************************************
1169  * DAD_ShowDragImage                            [SHELL32.137]
1170  *
1171  * NOTES
1172  *  exported by name
1173  */
1174 BOOL WINAPI DAD_ShowDragImage(BOOL bShow)
1175 {
1176         FIXME("0x%08x stub\n",bShow);
1177         return 0;
1178 }
1179 /*************************************************************************
1180  * ReadCabinetState                             [SHELL32.651] NT 4.0
1181  *
1182  */
1183 HRESULT WINAPI ReadCabinetState(DWORD u, DWORD v)
1184 {       FIXME("0x%04lx 0x%04lx stub\n",u,v);
1185         return 0;
1186 }
1187 /*************************************************************************
1188  * WriteCabinetState                            [SHELL32.652] NT 4.0
1189  *
1190  */
1191 HRESULT WINAPI WriteCabinetState(DWORD u)
1192 {       FIXME("0x%04lx stub\n",u);
1193         return 0;
1194 }
1195 /*************************************************************************
1196  * FileIconInit                                 [SHELL32.660]
1197  *
1198  */
1199 BOOL WINAPI FileIconInit(BOOL bFullInit)
1200 {       FIXME("(%s)\n", bFullInit ? "true" : "false");
1201         return 0;
1202 }
1203 /*************************************************************************
1204  * IsUserAdmin                                  [SHELL32.680] NT 4.0
1205  *
1206  */
1207 HRESULT WINAPI IsUserAdmin(void)
1208 {       FIXME("stub\n");
1209         return TRUE;
1210 }
1211
1212 /*************************************************************************
1213  * SHAllocShared                                [SHELL32.520]
1214  *
1215  * NOTES
1216  *  parameter1 is return value from HeapAlloc
1217  *  parameter2 is equal to the size allocated with HeapAlloc
1218  *  parameter3 is return value from GetCurrentProcessId
1219  *
1220  *  the return value is posted as lParam with 0x402 (WM_USER+2) to somewhere
1221  *  WM_USER+2 could be the undocumented CWM_SETPATH
1222  *  the allocated memory contains a pidl
1223  */
1224 HGLOBAL WINAPI SHAllocShared(LPVOID psrc, DWORD size, DWORD procID)
1225 {       HGLOBAL hmem;
1226         LPVOID pmem;
1227
1228         TRACE("ptr=%p size=0x%04lx procID=0x%04lx\n",psrc,size,procID);
1229         hmem = GlobalAlloc(GMEM_FIXED, size);
1230         if (!hmem)
1231           return 0;
1232
1233         pmem =  GlobalLock (hmem);
1234
1235         if (! pmem)
1236           return 0;
1237
1238         memcpy (pmem, psrc, size);
1239         GlobalUnlock(hmem);
1240         return hmem;
1241 }
1242 /*************************************************************************
1243  * SHLockShared                                 [SHELL32.521]
1244  *
1245  * NOTES
1246  *  parameter1 is return value from SHAllocShared
1247  *  parameter2 is return value from GetCurrentProcessId
1248  *  the receiver of (WM_USER+2) tries to lock the HANDLE (?)
1249  *  the return value seems to be a memory address
1250  */
1251 LPVOID WINAPI SHLockShared(HANDLE hmem, DWORD procID)
1252 {       TRACE("handle=0x%04x procID=0x%04lx\n",hmem,procID);
1253         return GlobalLock(hmem);
1254 }
1255 /*************************************************************************
1256  * SHUnlockShared                               [SHELL32.522]
1257  *
1258  * NOTES
1259  *  parameter1 is return value from SHLockShared
1260  */
1261 BOOL WINAPI SHUnlockShared(LPVOID pv)
1262 {
1263         TRACE("%p\n",pv);
1264         return GlobalUnlock((HANDLE)pv);
1265 }
1266 /*************************************************************************
1267  * SHFreeShared                                 [SHELL32.523]
1268  *
1269  * NOTES
1270  *  parameter1 is return value from SHAllocShared
1271  *  parameter2 is return value from GetCurrentProcessId
1272  */
1273 BOOL WINAPI SHFreeShared(
1274         HANDLE hMem,
1275         DWORD pid)
1276 {
1277         TRACE("handle=0x%04x 0x%04lx\n",hMem,pid);
1278         return GlobalFree(hMem);
1279 }
1280
1281 /*************************************************************************
1282  * SetAppStartingCursor                         [SHELL32.99]
1283  */
1284 HRESULT WINAPI SetAppStartingCursor(HWND u, DWORD v)
1285 {       FIXME("hwnd=0x%04x 0x%04lx stub\n",u,v );
1286         return 0;
1287 }
1288 /*************************************************************************
1289  * SHLoadOLE                                    [SHELL32.151]
1290  *
1291  */
1292 HRESULT WINAPI SHLoadOLE(DWORD u)
1293 {       FIXME("0x%04lx stub\n",u);
1294         return S_OK;
1295 }
1296 /*************************************************************************
1297  * DriveType                                    [SHELL32.64]
1298  *
1299  */
1300 HRESULT WINAPI DriveType(DWORD u)
1301 {       FIXME("0x%04lx stub\n",u);
1302         return 0;
1303 }
1304 /*************************************************************************
1305  * SHAbortInvokeCommand                         [SHELL32.198]
1306  *
1307  */
1308 HRESULT WINAPI SHAbortInvokeCommand(void)
1309 {       FIXME("stub\n");
1310         return 1;
1311 }
1312 /*************************************************************************
1313  * SHOutOfMemoryMessageBox                      [SHELL32.126]
1314  *
1315  */
1316 int WINAPI SHOutOfMemoryMessageBox(
1317         HWND hwndOwner,
1318         LPCSTR lpCaption,
1319         UINT uType)
1320 {
1321         FIXME("0x%04x %s 0x%08x stub\n",hwndOwner, lpCaption, uType);
1322         return 0;
1323 }
1324 /*************************************************************************
1325  * SHFlushClipboard                             [SHELL32.121]
1326  *
1327  */
1328 HRESULT WINAPI SHFlushClipboard(void)
1329 {       FIXME("stub\n");
1330         return 1;
1331 }
1332
1333 /*************************************************************************
1334  * SHWaitForFileToOpen                          [SHELL32.97]
1335  *
1336  */
1337 BOOL WINAPI SHWaitForFileToOpen(
1338         LPCITEMIDLIST pidl,
1339         DWORD dwFlags,
1340         DWORD dwTimeout)
1341 {
1342         FIXME("%p 0x%08lx 0x%08lx stub\n", pidl, dwFlags, dwTimeout);
1343         return 0;
1344 }
1345
1346 /************************************************************************
1347  *      @                               [SHELL32.654]
1348  *
1349  * NOTES: 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 (DWORD x, DWORD y)
1355 {       FIXME("0x%08lx 0x%08lx stub\n",x,y);
1356         return 0;
1357 }
1358
1359 /************************************************************************
1360  *      RLBuildListOfPaths                      [SHELL32.146]
1361  *
1362  * NOTES
1363  *   builds a DPA
1364  */
1365 DWORD WINAPI RLBuildListOfPaths (void)
1366 {       FIXME("stub\n");
1367         return 0;
1368 }
1369 /************************************************************************
1370  *      SHValidateUNC                           [SHELL32.173]
1371  *
1372  */
1373 HRESULT WINAPI SHValidateUNC (DWORD x, DWORD y, DWORD z)
1374 {
1375         FIXME("0x%08lx 0x%08lx 0x%08lx stub\n",x,y,z);
1376         return 0;
1377 }
1378
1379 /************************************************************************
1380  *      DoEnvironmentSubstA                     [SHELL32.@]
1381  *
1382  */
1383 HRESULT WINAPI DoEnvironmentSubstA(LPSTR x, LPSTR y)
1384 {
1385         FIXME("(%s, %s) stub\n", debugstr_a(x), debugstr_a(y));
1386         return 0;
1387 }
1388
1389 /************************************************************************
1390  *      DoEnvironmentSubstW                     [SHELL32.@]
1391  *
1392  */
1393 HRESULT WINAPI DoEnvironmentSubstW(LPWSTR x, LPWSTR y)
1394 {
1395         FIXME("(%s, %s): stub\n", debugstr_w(x), debugstr_w(y));
1396         return 0;
1397 }
1398
1399 /************************************************************************
1400  *      DoEnvironmentSubst                      [SHELL32.53]
1401  *
1402  */
1403 HRESULT WINAPI DoEnvironmentSubstAW(LPVOID x, LPVOID y)
1404 {
1405         if (SHELL_OsIsUnicode())
1406           return DoEnvironmentSubstW(x, y);
1407         return DoEnvironmentSubstA(x, y);
1408 }
1409
1410 /*************************************************************************
1411  *      @                             [SHELL32.243]
1412  *
1413  * Win98+ by-ordinal routine.  In Win98 this routine returns zero and
1414  * does nothing else.  Possibly this does something in NT or SHELL32 5.0?
1415  *
1416  */
1417
1418 BOOL WINAPI shell32_243(DWORD a, DWORD b)
1419 {
1420   return FALSE;
1421 }
1422
1423 /*************************************************************************
1424  *      @       [SHELL32.714]
1425  */
1426 DWORD WINAPI SHELL32_714(LPVOID x)
1427 {
1428         FIXME("(%s)stub\n", debugstr_w(x));
1429         return 0;
1430 }
1431
1432 /*************************************************************************
1433  *      SHAddFromPropSheetExtArray      [SHELL32.167]
1434  */
1435 DWORD WINAPI SHAddFromPropSheetExtArray(DWORD a, DWORD b, DWORD c)
1436 {
1437         FIXME("(%08lx,%08lx,%08lx)stub\n", a, b, c);
1438         return 0;
1439 }
1440
1441 /*************************************************************************
1442  *      SHCreatePropSheetExtArray       [SHELL32.168]
1443  */
1444 DWORD WINAPI SHCreatePropSheetExtArray(DWORD a, LPCSTR b, DWORD c)
1445 {
1446         FIXME("(%08lx,%s,%08lx)stub\n", a, debugstr_a(b), c);
1447         return 0;
1448 }
1449
1450 /*************************************************************************
1451  *      SHReplaceFromPropSheetExtArray  [SHELL32.170]
1452  */
1453 DWORD WINAPI SHReplaceFromPropSheetExtArray(DWORD a, DWORD b, DWORD c, DWORD d)
1454 {
1455         FIXME("(%08lx,%08lx,%08lx,%08lx)stub\n", a, b, c, d);
1456         return 0;
1457 }
1458
1459 /*************************************************************************
1460  *      SHDestroyPropSheetExtArray      [SHELL32.169]
1461  */
1462 DWORD WINAPI SHDestroyPropSheetExtArray(DWORD a)
1463 {
1464         FIXME("(%08lx)stub\n", a);
1465         return 0;
1466 }
1467
1468 /*************************************************************************
1469  *      CIDLData_CreateFromIDArray      [SHELL32.83]
1470  *
1471  *  Create IDataObject from PIDLs??
1472  */
1473 HRESULT WINAPI CIDLData_CreateFromIDArray(
1474         LPCITEMIDLIST pidlFolder,
1475         DWORD cpidlFiles,
1476         LPCITEMIDLIST *lppidlFiles,
1477         LPDATAOBJECT *ppdataObject)
1478 {
1479     INT i;
1480     HWND hwnd = 0;   /*FIXME: who should be hwnd of owner? set to desktop */
1481
1482     TRACE("(%p, %ld, %p, %p)\n", pidlFolder, cpidlFiles, lppidlFiles, ppdataObject);
1483     if (TRACE_ON(pidl))
1484     {
1485         pdump (pidlFolder);
1486         for (i=0; i<cpidlFiles; i++) pdump (lppidlFiles[i]);
1487     }
1488     *ppdataObject = IDataObject_Constructor( hwnd, pidlFolder,
1489                                              lppidlFiles, cpidlFiles);
1490     if (*ppdataObject) return S_OK;
1491     return E_OUTOFMEMORY;
1492 }