Fix snooping of 16-bit dlls being loaded at the same address.
[wine] / dlls / shell32 / shell32_main.c
1 /*
2  *                              Shell basics
3  *
4  * Copyright 1998 Marcus Meissner
5  * Copyright 1998 Juergen Schmied (jsch)  *  <juergen.schmied@metronet.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include <stdio.h>
27
28 #include "windef.h"
29 #include "winerror.h"
30 #include "winreg.h"
31 #include "dlgs.h"
32 #include "shellapi.h"
33 #include "shlobj.h"
34 #include "shlguid.h"
35 #include "shlwapi.h"
36
37 #include "undocshell.h"
38 #include "wine/winuser16.h"
39 #include "authors.h"
40 #include "heap.h"
41 #include "pidl.h"
42 #include "shell32_main.h"
43
44 #include "wine/debug.h"
45
46 WINE_DEFAULT_DEBUG_CHANNEL(shell);
47
48 #define MORE_DEBUG 1
49 /*************************************************************************
50  * CommandLineToArgvW                   [SHELL32.@]
51  *
52  * We must interpret the quotes in the command line to rebuild the argv
53  * array correctly:
54  * - arguments are separated by spaces or tabs
55  * - quotes serve as optional argument delimiters
56  *   '"a b"'   -> 'a b'
57  * - escaped quotes must be converted back to '"'
58  *   '\"'      -> '"'
59  * - an odd number of '\'s followed by '"' correspond to half that number
60  *   of '\' followed by a '"' (extension of the above)
61  *   '\\\"'    -> '\"'
62  *   '\\\\\"'  -> '\\"'
63  * - an even number of '\'s followed by a '"' correspond to half that number
64  *   of '\', plus a regular quote serving as an argument delimiter (which
65  *   means it does not appear in the result)
66  *   'a\\"b c"'   -> 'a\b c'
67  *   'a\\\\"b c"' -> 'a\\b c'
68  * - '\' that are not followed by a '"' are copied literally
69  *   'a\b'     -> 'a\b'
70  *   'a\\b'    -> 'a\\b'
71  *
72  * Note:
73  * '\t' == 0x0009
74  * ' '  == 0x0020
75  * '"'  == 0x0022
76  * '\\' == 0x005c
77  */
78 LPWSTR* WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int* numargs)
79 {
80     DWORD argc;
81     HGLOBAL hargv;
82     LPWSTR  *argv;
83     LPCWSTR cs;
84     LPWSTR arg,s,d;
85     LPWSTR cmdline;
86     int in_quotes,bcount;
87
88     if (*lpCmdline==0) {
89         /* Return the path to the executable */
90         DWORD size;
91
92         hargv=0;
93         size=16;
94         do {
95             size*=2;
96             hargv=GlobalReAlloc(hargv, size, 0);
97             argv=GlobalLock(hargv);
98         } while (GetModuleFileNameW((HMODULE)0, (LPWSTR)(argv+1), size-sizeof(LPWSTR)) == 0);
99         argv[0]=(LPWSTR)(argv+1);
100         if (numargs)
101             *numargs=2;
102
103         return argv;
104     }
105
106     /* to get a writeable copy */
107     argc=0;
108     bcount=0;
109     in_quotes=0;
110     cs=lpCmdline;
111     while (1) {
112         if (*cs==0 || ((*cs==0x0009 || *cs==0x0020) && !in_quotes)) {
113             /* space */
114             argc++;
115             /* skip the remaining spaces */
116             while (*cs==0x0009 || *cs==0x0020) {
117                 cs++;
118             }
119             if (*cs==0)
120                 break;
121             bcount=0;
122             continue;
123         } else if (*cs==0x005c) {
124             /* '\', count them */
125             bcount++;
126         } else if ((*cs==0x0022) && ((bcount & 1)==0)) {
127             /* unescaped '"' */
128             in_quotes=!in_quotes;
129             bcount=0;
130         } else {
131             /* a regular character */
132             bcount=0;
133         }
134         cs++;
135     }
136     /* Allocate in a single lump, the string array, and the strings that go with it.
137      * This way the caller can make a single GlobalFree call to free both, as per MSDN.
138      */
139     hargv=GlobalAlloc(0, argc*sizeof(LPWSTR)+(strlenW(lpCmdline)+1)*sizeof(WCHAR));
140     argv=GlobalLock(hargv);
141     if (!argv)
142         return NULL;
143     cmdline=(LPWSTR)(argv+argc);
144     strcpyW(cmdline, lpCmdline);
145
146     argc=0;
147     bcount=0;
148     in_quotes=0;
149     arg=d=s=cmdline;
150     while (*s) {
151         if ((*s==0x0009 || *s==0x0020) && !in_quotes) {
152             /* Close the argument and copy it */
153             *d=0;
154             argv[argc++]=arg;
155
156             /* skip the remaining spaces */
157             do {
158                 s++;
159             } while (*s==0x0009 || *s==0x0020);
160
161             /* Start with a new argument */
162             arg=d=s;
163             bcount=0;
164         } else if (*s==0x005c) {
165             /* '\\' */
166             *d++=*s++;
167             bcount++;
168         } else if (*s==0x0022) {
169             /* '"' */
170             if ((bcount & 1)==0) {
171                 /* Preceeded by an even number of '\', this is half that
172                  * number of '\', plus a quote which we erase.
173                  */
174                 d-=bcount/2;
175                 in_quotes=!in_quotes;
176                 s++;
177             } else {
178                 /* Preceeded by an odd number of '\', this is half that
179                  * number of '\' followed by a '"'
180                  */
181                 d=d-bcount/2-1;
182                 *d++='"';
183                 s++;
184             }
185             bcount=0;
186         } else {
187             /* a regular character */
188             *d++=*s++;
189             bcount=0;
190         }
191     }
192     if (*arg) {
193         *d='\0';
194         argv[argc]=arg;
195     }
196     if (numargs)
197         *numargs=argc;
198
199     return argv;
200 }
201
202 /*************************************************************************
203  * SHGetFileInfoA                       [SHELL32.@]
204  *
205  */
206
207 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
208                               SHFILEINFOA *psfi, UINT sizeofpsfi,
209                               UINT flags )
210 {
211         char szLoaction[MAX_PATH];
212         int iIndex;
213         DWORD ret = TRUE, dwAttributes = 0;
214         IShellFolder * psfParent = NULL;
215         IExtractIconA * pei = NULL;
216         LPITEMIDLIST    pidlLast = NULL, pidl = NULL;
217         HRESULT hr = S_OK;
218         BOOL IconNotYetLoaded=TRUE;
219
220         TRACE("(%s fattr=0x%lx sfi=%p(attr=0x%08lx) size=0x%x flags=0x%x)\n",
221           (flags & SHGFI_PIDL)? "pidl" : path, dwFileAttributes, psfi, psfi->dwAttributes, sizeofpsfi, flags);
222
223         if ((flags & SHGFI_USEFILEATTRIBUTES) && (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
224           return FALSE;
225
226         /* windows initializes this values regardless of the flags */
227         psfi->szDisplayName[0] = '\0';
228         psfi->szTypeName[0] = '\0';
229         psfi->iIcon = 0;
230
231         if (flags & SHGFI_EXETYPE) {
232           BOOL status = FALSE;
233           HANDLE hfile;
234           DWORD BinaryType;
235           IMAGE_DOS_HEADER mz_header;
236           IMAGE_NT_HEADERS nt;
237           DWORD len;
238           char magic[4];
239
240           if (flags != SHGFI_EXETYPE) return 0;
241
242           status = GetBinaryTypeA (path, &BinaryType);
243           if (!status) return 0;
244           if ((BinaryType == SCS_DOS_BINARY)
245                 || (BinaryType == SCS_PIF_BINARY)) return 0x4d5a;
246
247           hfile = CreateFileA( path, GENERIC_READ, FILE_SHARE_READ,
248                 NULL, OPEN_EXISTING, 0, 0 );
249           if ( hfile == INVALID_HANDLE_VALUE ) return 0;
250
251         /* The next section is adapted from MODULE_GetBinaryType, as we need
252          * to examine the image header to get OS and version information. We
253          * know from calling GetBinaryTypeA that the image is valid and either
254          * an NE or PE, so much error handling can be omitted.
255          * Seek to the start of the file and read the header information.
256          */
257
258           SetFilePointer( hfile, 0, NULL, SEEK_SET );
259           ReadFile( hfile, &mz_header, sizeof(mz_header), &len, NULL );
260
261          SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
262          ReadFile( hfile, magic, sizeof(magic), &len, NULL );
263          if ( *(DWORD*)magic      == IMAGE_NT_SIGNATURE )
264          {
265              SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
266              ReadFile( hfile, &nt, sizeof(nt), &len, NULL );
267               CloseHandle( hfile );
268               if (nt.OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI) {
269                  return IMAGE_NT_SIGNATURE
270                         | (nt.OptionalHeader.MajorSubsystemVersion << 24)
271                         | (nt.OptionalHeader.MinorSubsystemVersion << 16);
272               }
273               return IMAGE_NT_SIGNATURE;
274           }
275          else if ( *(WORD*)magic == IMAGE_OS2_SIGNATURE )
276          {
277              IMAGE_OS2_HEADER ne;
278              SetFilePointer( hfile, mz_header.e_lfanew, NULL, SEEK_SET );
279              ReadFile( hfile, &ne, sizeof(ne), &len, NULL );
280               CloseHandle( hfile );
281              if (ne.ne_exetyp == 2) return IMAGE_OS2_SIGNATURE
282                         | (ne.ne_expver << 16);
283               return 0;
284           }
285           CloseHandle( hfile );
286           return 0;
287       }
288
289
290         /* translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES in not specified
291            the pidl functions fail on not existing file names */
292
293         if (flags & SHGFI_PIDL) {
294             pidl = ILClone((LPCITEMIDLIST)path);
295         } else if (!(flags & SHGFI_USEFILEATTRIBUTES)) {
296             hr = SHILCreateFromPathA(path, &pidl, &dwAttributes);
297         }
298
299         /* get the parent shellfolder */
300         if (pidl) {
301             hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
302             ILFree(pidl);
303         } else {
304             ERR("pidl is null!\n");
305             return FALSE;
306         }
307
308         /* get the attributes of the child */
309         if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
310         {
311           if (!(flags & SHGFI_ATTR_SPECIFIED))
312           {
313             psfi->dwAttributes = 0xffffffff;
314           }
315           IShellFolder_GetAttributesOf(psfParent, 1 , &pidlLast, &(psfi->dwAttributes));
316         }
317
318         /* get the displayname */
319         if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
320         {
321           if (flags & SHGFI_USEFILEATTRIBUTES)
322           {
323             strcpy (psfi->szDisplayName, PathFindFileNameA(path));
324           }
325           else
326           {
327             STRRET str;
328             hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
329             StrRetToStrNA (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
330           }
331         }
332
333         /* get the type name */
334         if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
335         {
336             if (!(flags & SHGFI_USEFILEATTRIBUTES))
337                 _ILGetFileType(pidlLast, psfi->szTypeName, 80);
338             else
339             {
340                 char sTemp[64];
341                 strcpy(sTemp,PathFindExtensionA(path));
342                 if (!( HCR_MapTypeToValue(sTemp, sTemp, 64, TRUE)
343                        && HCR_MapTypeToValue(sTemp, psfi->szTypeName, 80, FALSE )))
344                 {
345                     lstrcpynA (psfi->szTypeName, sTemp, 80 - 6);
346                     strcat (psfi->szTypeName, "-file");
347                 }
348             }
349         }
350
351         /* ### icons ###*/
352         if (flags & SHGFI_LINKOVERLAY)
353           FIXME("set icon to link, stub\n");
354
355         if (flags & SHGFI_SELECTED)
356           FIXME("set icon to selected, stub\n");
357
358         if (flags & SHGFI_SHELLICONSIZE)
359           FIXME("set icon to shell size, stub\n");
360
361         /* get the iconlocation */
362         if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
363         {
364           UINT uDummy,uFlags;
365           hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, &pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
366
367           if (SUCCEEDED(hr))
368           {
369             hr = IExtractIconA_GetIconLocation(pei, (flags & SHGFI_OPENICON)? GIL_OPENICON : 0,szLoaction, MAX_PATH, &iIndex, &uFlags);
370             /* FIXME what to do with the index? */
371
372             if(uFlags != GIL_NOTFILENAME)
373               strcpy (psfi->szDisplayName, szLoaction);
374             else
375               ret = FALSE;
376
377             IExtractIconA_Release(pei);
378           }
379         }
380
381         /* get icon index (or load icon)*/
382         if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
383         {
384
385           if (flags & SHGFI_USEFILEATTRIBUTES)
386           {
387             char sTemp [MAX_PATH];
388             char * szExt;
389             DWORD dwNr=0;
390
391             lstrcpynA(sTemp, path, MAX_PATH);
392             szExt = (LPSTR) PathFindExtensionA(sTemp);
393             if( szExt && HCR_MapTypeToValue(szExt, sTemp, MAX_PATH, TRUE)
394               && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
395             {
396               if (!strcmp("%1",sTemp))            /* icon is in the file */
397               {
398                 strcpy(sTemp, path);
399               }
400               IconNotYetLoaded=FALSE;
401               psfi->iIcon = 0;
402               if (SHGFI_LARGEICON)
403                 PrivateExtractIconsA(sTemp,dwNr,GetSystemMetrics(SM_CXICON),
404                                      GetSystemMetrics(SM_CYICON),
405                                      &psfi->hIcon,0,1,0);
406               else
407                 PrivateExtractIconsA(sTemp,dwNr,GetSystemMetrics(SM_CXSMICON),
408                                      GetSystemMetrics(SM_CYSMICON),
409                                      &psfi->hIcon,0,1,0);
410             }
411             else                                  /* default icon */
412             {
413               psfi->iIcon = 0;
414             }
415           }
416           else
417           {
418             if (!(PidlToSicIndex(psfParent, pidlLast, (flags & SHGFI_LARGEICON),
419               (flags & SHGFI_OPENICON)? GIL_OPENICON : 0, &(psfi->iIcon))))
420             {
421               ret = FALSE;
422             }
423           }
424           if (ret)
425           {
426             ret = (DWORD) ((flags & SHGFI_LARGEICON) ? ShellBigIconList : ShellSmallIconList);
427           }
428         }
429
430         /* icon handle */
431         if (SUCCEEDED(hr) && (flags & SHGFI_ICON) && IconNotYetLoaded)
432           psfi->hIcon = ImageList_GetIcon((flags & SHGFI_LARGEICON) ? ShellBigIconList:ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
433
434         if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
435           FIXME("unknown attribute!\n");
436
437         if (psfParent)
438           IShellFolder_Release(psfParent);
439
440         if (hr != S_OK)
441           ret = FALSE;
442
443         if(pidlLast) SHFree(pidlLast);
444 #ifdef MORE_DEBUG
445         TRACE ("icon=0x%08x index=0x%08x attr=0x%08lx name=%s type=%s ret=0x%08lx\n",
446                 psfi->hIcon, psfi->iIcon, psfi->dwAttributes, psfi->szDisplayName, psfi->szTypeName, ret);
447 #endif
448         return ret;
449 }
450
451 /*************************************************************************
452  * SHGetFileInfoW                       [SHELL32.@]
453  */
454
455 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
456                               SHFILEINFOW *psfi, UINT sizeofpsfi,
457                               UINT flags )
458 {
459         INT len;
460         LPSTR temppath;
461         DWORD ret;
462         SHFILEINFOA temppsfi;
463
464         len = WideCharToMultiByte(CP_ACP, 0, path, -1, NULL, 0, NULL, NULL);
465         temppath = HeapAlloc(GetProcessHeap(), 0, len);
466         WideCharToMultiByte(CP_ACP, 0, path, -1, temppath, len, NULL, NULL);
467
468         WideCharToMultiByte(CP_ACP, 0, psfi->szDisplayName, -1, temppsfi.szDisplayName,
469                             sizeof(temppsfi.szDisplayName), NULL, NULL);
470         WideCharToMultiByte(CP_ACP, 0, psfi->szTypeName, -1, temppsfi.szTypeName,
471                             sizeof(temppsfi.szTypeName), NULL, NULL);
472
473         ret = SHGetFileInfoA(temppath, dwFileAttributes, &temppsfi, sizeof(temppsfi), flags);
474
475         HeapFree(GetProcessHeap(), 0, temppath);
476
477         return ret;
478 }
479
480 /*************************************************************************
481  * SHGetFileInfo                        [SHELL32.@]
482  */
483 DWORD WINAPI SHGetFileInfoAW(
484         LPCVOID path,
485         DWORD dwFileAttributes,
486         LPVOID psfi,
487         UINT sizeofpsfi,
488         UINT flags)
489 {
490         if(SHELL_OsIsUnicode())
491           return SHGetFileInfoW(path, dwFileAttributes, psfi, sizeofpsfi, flags );
492         return SHGetFileInfoA(path, dwFileAttributes, psfi, sizeofpsfi, flags );
493 }
494
495 /*************************************************************************
496  * DuplicateIcon                        [SHELL32.@]
497  */
498 HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
499 {
500     ICONINFO IconInfo;
501     HICON hDupIcon = 0;
502
503     TRACE("(%04x, %04x)\n", hInstance, hIcon);
504
505     if(GetIconInfo(hIcon, &IconInfo))
506     {
507         hDupIcon = CreateIconIndirect(&IconInfo);
508
509         /* clean up hbmMask and hbmColor */
510         DeleteObject(IconInfo.hbmMask);
511         DeleteObject(IconInfo.hbmColor);
512     }
513
514     return hDupIcon;
515 }
516
517
518 /*************************************************************************
519  * ExtractIconA                         [SHELL32.@]
520  *
521  * FIXME
522  *  if the filename is not a file return 1
523  */
524 HICON WINAPI ExtractIconA( HINSTANCE hInstance, LPCSTR lpszExeFileName,
525         UINT nIconIndex )
526 {   HGLOBAL16 handle = InternalExtractIcon16(hInstance,lpszExeFileName,nIconIndex, 1);
527     TRACE("\n");
528     if( handle )
529     {
530         HICON16* ptr = (HICON16*)GlobalLock16(handle);
531         HICON16  hIcon = *ptr;
532
533         GlobalFree16(handle);
534         return hIcon;
535     }
536     return 0;
537 }
538
539 /*************************************************************************
540  * ExtractIconW                         [SHELL32.@]
541  *
542  * FIXME: if the filename is not a file return 1
543  */
544 HICON WINAPI ExtractIconW( HINSTANCE hInstance, LPCWSTR lpszExeFileName,
545         UINT nIconIndex )
546 { LPSTR  exefn;
547   HICON  ret;
548   TRACE("\n");
549
550   exefn = HEAP_strdupWtoA(GetProcessHeap(),0,lpszExeFileName);
551   ret = ExtractIconA(hInstance,exefn,nIconIndex);
552
553         HeapFree(GetProcessHeap(),0,exefn);
554         return ret;
555 }
556
557 typedef struct
558 { LPCSTR  szApp;
559     LPCSTR  szOtherStuff;
560     HICON hIcon;
561 } ABOUT_INFO;
562
563 #define         IDC_STATIC_TEXT         100
564 #define         IDC_LISTBOX             99
565 #define         IDC_WINE_TEXT           98
566
567 #define         DROP_FIELD_TOP          (-15)
568 #define         DROP_FIELD_HEIGHT       15
569
570 static HICON hIconTitleFont;
571
572 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
573 { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
574     if( hWndCtl )
575   { GetWindowRect( hWndCtl, lprect );
576         MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
577         lprect->bottom = (lprect->top += DROP_FIELD_TOP);
578         return TRUE;
579     }
580     return FALSE;
581 }
582
583 /*************************************************************************
584  * SHAppBarMessage                      [SHELL32.@]
585  */
586 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
587 {
588         int width=data->rc.right - data->rc.left;
589         int height=data->rc.bottom - data->rc.top;
590         RECT rec=data->rc;
591         switch (msg)
592         { case ABM_GETSTATE:
593                return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
594           case ABM_GETTASKBARPOS:
595                GetWindowRect(data->hWnd, &rec);
596                data->rc=rec;
597                return TRUE;
598           case ABM_ACTIVATE:
599                SetActiveWindow(data->hWnd);
600                return TRUE;
601           case ABM_GETAUTOHIDEBAR:
602                data->hWnd=GetActiveWindow();
603                return TRUE;
604           case ABM_NEW:
605                SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
606                                         width,height,SWP_SHOWWINDOW);
607                return TRUE;
608           case ABM_QUERYPOS:
609                GetWindowRect(data->hWnd, &(data->rc));
610                return TRUE;
611           case ABM_REMOVE:
612                FIXME("ABM_REMOVE broken\n");
613                /* FIXME: this is wrong; should it be DestroyWindow instead? */
614                /*CloseHandle(data->hWnd);*/
615                return TRUE;
616           case ABM_SETAUTOHIDEBAR:
617                SetWindowPos(data->hWnd,HWND_TOP,rec.left+1000,rec.top,
618                                        width,height,SWP_SHOWWINDOW);
619                return TRUE;
620           case ABM_SETPOS:
621                data->uEdge=(ABE_RIGHT | ABE_LEFT);
622                SetWindowPos(data->hWnd,HWND_TOP,data->rc.left,data->rc.top,
623                                   width,height,SWP_SHOWWINDOW);
624                return TRUE;
625           case ABM_WINDOWPOSCHANGED:
626                SetWindowPos(data->hWnd,HWND_TOP,rec.left,rec.top,
627                                         width,height,SWP_SHOWWINDOW);
628                return TRUE;
629           }
630       return FALSE;
631 }
632
633 /*************************************************************************
634  * SHHelpShortcuts_RunDLL               [SHELL32.@]
635  *
636  */
637 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
638 { FIXME("(%lx, %lx, %lx, %lx) empty stub!\n",
639         dwArg1, dwArg2, dwArg3, dwArg4);
640
641   return 0;
642 }
643
644 /*************************************************************************
645  * SHLoadInProc                         [SHELL32.@]
646  * Create an instance of specified object class from within
647  * the shell process and release it immediately
648  */
649
650 DWORD WINAPI SHLoadInProc (REFCLSID rclsid)
651 {
652         IUnknown * pUnk = NULL;
653         TRACE("%s\n", debugstr_guid(rclsid));
654
655         CoCreateInstance(rclsid, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown,(LPVOID*)pUnk);
656         if(pUnk)
657         {
658           IUnknown_Release(pUnk);
659           return NOERROR;
660         }
661         return DISP_E_MEMBERNOTFOUND;
662 }
663
664 /*************************************************************************
665  * AboutDlgProc                 (internal)
666  */
667 BOOL WINAPI AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
668                               LPARAM lParam )
669 {   HWND hWndCtl;
670     char Template[512], AppTitle[512];
671
672     TRACE("\n");
673
674     switch(msg)
675     { case WM_INITDIALOG:
676       { ABOUT_INFO *info = (ABOUT_INFO *)lParam;
677             if (info)
678         { const char* const *pstr = SHELL_People;
679                 SendDlgItemMessageA(hWnd, stc1, STM_SETICON,info->hIcon, 0);
680                 GetWindowTextA( hWnd, Template, sizeof(Template) );
681                 sprintf( AppTitle, Template, info->szApp );
682                 SetWindowTextA( hWnd, AppTitle );
683                 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT),
684                                   info->szOtherStuff );
685                 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
686                 SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
687                 if (!hIconTitleFont)
688                 {
689                     LOGFONTA logFont;
690                     SystemParametersInfoA( SPI_GETICONTITLELOGFONT, 0, &logFont, 0 );
691                     hIconTitleFont = CreateFontIndirectA( &logFont );
692                 }
693                 SendMessageA( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
694                 while (*pstr)
695           { SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)*pstr );
696                     pstr++;
697                 }
698                 SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
699             }
700         }
701         return 1;
702
703     case WM_PAINT:
704       { RECT rect;
705             PAINTSTRUCT ps;
706             HDC hDC = BeginPaint( hWnd, &ps );
707
708             if( __get_dropline( hWnd, &rect ) ) {
709                 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
710                 MoveToEx( hDC, rect.left, rect.top, NULL );
711                 LineTo( hDC, rect.right, rect.bottom );
712             }
713             EndPaint( hWnd, &ps );
714         }
715         break;
716
717 #if 0  /* FIXME: should use DoDragDrop */
718     case WM_LBTRACKPOINT:
719         hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
720         if( (INT16)GetKeyState( VK_CONTROL ) < 0 )
721       { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
722         { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
723                 if( idx != -1 )
724           { INT length = SendMessageA( hWndCtl, LB_GETTEXTLEN, (WPARAM)idx, 0 );
725                     HGLOBAL16 hMemObj = GlobalAlloc16( GMEM_MOVEABLE, length + 1 );
726                     char* pstr = (char*)GlobalLock16( hMemObj );
727
728                     if( pstr )
729             { HCURSOR hCursor = LoadCursorA( 0, MAKEINTRESOURCEA(OCR_DRAGOBJECT) );
730                         SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
731                         SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
732                         UpdateWindow( hWndCtl );
733                         if( !DragObject16((HWND16)hWnd, (HWND16)hWnd, DRAGOBJ_DATA, 0, (WORD)hMemObj, hCursor) )
734                             SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)pstr );
735                     }
736             if( hMemObj )
737               GlobalFree16( hMemObj );
738                 }
739             }
740         }
741         break;
742 #endif
743
744     case WM_QUERYDROPOBJECT:
745         if( wParam == 0 )
746       { LPDRAGINFO16 lpDragInfo = MapSL((SEGPTR)lParam);
747             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
748         { RECT rect;
749                 if( __get_dropline( hWnd, &rect ) )
750           { POINT pt;
751             pt.x=lpDragInfo->pt.x;
752             pt.x=lpDragInfo->pt.y;
753                     rect.bottom += DROP_FIELD_HEIGHT;
754                     if( PtInRect( &rect, pt ) )
755             { SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
756                         return TRUE;
757                     }
758                 }
759             }
760         }
761         break;
762
763     case WM_DROPOBJECT:
764         if( wParam == hWnd )
765       { LPDRAGINFO16 lpDragInfo = MapSL((SEGPTR)lParam);
766             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
767         { char* pstr = (char*)GlobalLock16( (HGLOBAL16)(lpDragInfo->hList) );
768                 if( pstr )
769           { static char __appendix_str[] = " with";
770
771                     hWndCtl = GetDlgItem( hWnd, IDC_WINE_TEXT );
772                     SendMessageA( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
773                     if( !strncmp( Template, "WINE", 4 ) )
774                         SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), Template );
775                     else
776           { char* pch = Template + strlen(Template) - strlen(__appendix_str);
777                         *pch = '\0';
778                         SendMessageA( GetDlgItem(hWnd, IDC_LISTBOX), LB_ADDSTRING,
779                                         (WPARAM)-1, (LPARAM)Template );
780                     }
781
782                     strcpy( Template, pstr );
783                     strcat( Template, __appendix_str );
784                     SetWindowTextA( hWndCtl, Template );
785                     SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
786                     return TRUE;
787                 }
788             }
789         }
790         break;
791
792     case WM_COMMAND:
793         if (wParam == IDOK)
794     {  EndDialog(hWnd, TRUE);
795             return TRUE;
796         }
797         break;
798     case WM_CLOSE:
799       EndDialog(hWnd, TRUE);
800       break;
801     }
802
803     return 0;
804 }
805
806
807 /*************************************************************************
808  * ShellAboutA                          [SHELL32.288]
809  */
810 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
811                              HICON hIcon )
812 {   ABOUT_INFO info;
813     HRSRC hRes;
814     LPVOID template;
815     TRACE("\n");
816
817     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
818         return FALSE;
819     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
820         return FALSE;
821
822     info.szApp        = szApp;
823     info.szOtherStuff = szOtherStuff;
824     info.hIcon        = hIcon;
825     if (!hIcon) info.hIcon = LoadIconA( 0, IDI_WINLOGOA );
826     return DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
827                                       template, hWnd, AboutDlgProc, (LPARAM)&info );
828 }
829
830
831 /*************************************************************************
832  * ShellAboutW                          [SHELL32.289]
833  */
834 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
835                              HICON hIcon )
836 {   BOOL ret;
837     ABOUT_INFO info;
838     HRSRC hRes;
839     LPVOID template;
840
841     TRACE("\n");
842
843     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
844         return FALSE;
845     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
846         return FALSE;
847
848     info.szApp        = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
849     info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
850     info.hIcon        = hIcon;
851     if (!hIcon) info.hIcon = LoadIconA( 0, IDI_WINLOGOA );
852     ret = DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
853                                    template, hWnd, AboutDlgProc, (LPARAM)&info );
854     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
855     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
856     return ret;
857 }
858
859 /*************************************************************************
860  * FreeIconList (SHELL32.@)
861  */
862 void WINAPI FreeIconList( DWORD dw )
863 { FIXME("(%lx): stub\n",dw);
864 }
865
866 /***********************************************************************
867  * DllGetVersion [SHELL32.@]
868  *
869  * Retrieves version information of the 'SHELL32.DLL'
870  *
871  * PARAMS
872  *     pdvi [O] pointer to version information structure.
873  *
874  * RETURNS
875  *     Success: S_OK
876  *     Failure: E_INVALIDARG
877  *
878  * NOTES
879  *     Returns version of a shell32.dll from IE4.01 SP1.
880  */
881
882 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
883 {
884         if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
885         {
886           WARN("wrong DLLVERSIONINFO size from app\n");
887           return E_INVALIDARG;
888         }
889
890         pdvi->dwMajorVersion = 4;
891         pdvi->dwMinorVersion = 72;
892         pdvi->dwBuildNumber = 3110;
893         pdvi->dwPlatformID = 1;
894
895         TRACE("%lu.%lu.%lu.%lu\n",
896            pdvi->dwMajorVersion, pdvi->dwMinorVersion,
897            pdvi->dwBuildNumber, pdvi->dwPlatformID);
898
899         return S_OK;
900 }
901 /*************************************************************************
902  * global variables of the shell32.dll
903  * all are once per process
904  *
905  */
906 void    (WINAPI *pDLLInitComctl)(LPVOID);
907
908 LPVOID  (WINAPI *pCOMCTL32_Alloc) (INT);
909 BOOL    (WINAPI *pCOMCTL32_Free) (LPVOID);
910
911 HANDLE  (WINAPI *pCreateMRUListA) (LPVOID lpcml);
912 DWORD   (WINAPI *pFreeMRUListA) (HANDLE hMRUList);
913 INT     (WINAPI *pAddMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData);
914 INT     (WINAPI *pFindMRUData) (HANDLE hList, LPCVOID lpData, DWORD cbData, LPINT lpRegNum);
915 INT     (WINAPI *pEnumMRUListA) (HANDLE hList, INT nItemPos, LPVOID lpBuffer, DWORD nBufferSize);
916
917 static HINSTANCE        hComctl32;
918
919 HINSTANCE       shell32_hInstance = 0;
920 HIMAGELIST      ShellSmallIconList = 0;
921 HIMAGELIST      ShellBigIconList = 0;
922
923
924 /*************************************************************************
925  * SHELL32 LibMain
926  *
927  * NOTES
928  *  calling oleinitialize here breaks sone apps.
929  */
930
931 BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
932 {
933         TRACE("0x%x 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
934
935         switch (fdwReason)
936         {
937           case DLL_PROCESS_ATTACH:
938             shell32_hInstance = hinstDLL;
939             hComctl32 = GetModuleHandleA("COMCTL32.DLL");
940             DisableThreadLibraryCalls(shell32_hInstance);
941
942             if (!hComctl32)
943             {
944               ERR("P A N I C SHELL32 loading failed\n");
945               return FALSE;
946             }
947
948             /* comctl32 */
949             pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
950             /* initialize the common controls */
951             if (pDLLInitComctl)
952             {
953               pDLLInitComctl(NULL);
954             }
955
956             SIC_Initialize();
957             SYSTRAY_Init();
958             InitChangeNotifications();
959             SHInitRestricted(NULL, NULL);
960             break;
961
962           case DLL_THREAD_ATTACH:
963             break;
964
965           case DLL_THREAD_DETACH:
966             break;
967
968           case DLL_PROCESS_DETACH:
969               shell32_hInstance = 0;
970               SIC_Destroy();
971               FreeChangeNotifications();
972               break;
973         }
974         return TRUE;
975 }
976
977 /*************************************************************************
978  * DllInstall         [SHELL32.@]
979  *
980  * PARAMETERS
981  *
982  *    BOOL bInstall - TRUE for install, FALSE for uninstall
983  *    LPCWSTR pszCmdLine - command line (unused by shell32?)
984  */
985
986 HRESULT WINAPI SHELL32_DllInstall(BOOL bInstall, LPCWSTR cmdline)
987 {
988    FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
989
990    return S_OK;         /* indicate success */
991 }
992
993 /***********************************************************************
994  *              DllCanUnloadNow (SHELL32.@)
995  */
996 HRESULT WINAPI SHELL32_DllCanUnloadNow(void)
997 {
998     FIXME("(void): stub\n");
999
1000     return S_FALSE;
1001 }