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