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