- added version messages
[wine] / dlls / shell32 / shell32_main.c
1 /*
2  *                              Shell basics
3  *
4  *  1998 Marcus Meissner
5  *  1998 Juergen Schmied (jsch)  *  <juergen.schmied@metronet.de>
6  */
7 #include <stdlib.h>
8 #include <string.h>
9
10 #include "wine/winuser16.h"
11 #include "winerror.h"
12 #include "heap.h"
13 #include "resource.h"
14 #include "dlgs.h"
15 #include "ldt.h"
16 #include "sysmetrics.h"
17 #include "debugtools.h"
18 #include "winreg.h"
19 #include "authors.h"
20 #include "winversion.h"
21
22 #include "shellapi.h"
23 #include "pidl.h"
24
25 #include "shlobj.h"
26 #include "shell32_main.h"
27 #include "shlguid.h"
28 #include "wine/undocshell.h"
29 #include "shpolicy.h"
30
31 DECLARE_DEBUG_CHANNEL(exec)
32 DECLARE_DEBUG_CHANNEL(shell)
33
34 #define MORE_DEBUG 1
35 /*************************************************************************
36  * CommandLineToArgvW                   [SHELL32.7]
37  */
38 LPWSTR* WINAPI CommandLineToArgvW(LPWSTR cmdline,LPDWORD numargs)
39 {       LPWSTR  *argv,s,t;
40         int     i;
41         TRACE_(shell)("\n");
42
43         /* to get writeable copy */
44         cmdline = HEAP_strdupW( GetProcessHeap(), 0, cmdline);
45         s=cmdline;i=0;
46         while (*s)
47         { /* space */
48           if (*s==0x0020) 
49           { i++;
50             s++;
51             while (*s && *s==0x0020)
52               s++;
53             continue;
54           }
55           s++;
56         }
57         argv=(LPWSTR*)HeapAlloc( GetProcessHeap(), 0, sizeof(LPWSTR)*(i+1) );
58         s=t=cmdline;
59         i=0;
60         while (*s)
61         { if (*s==0x0020)
62           { *s=0;
63             argv[i++]=HEAP_strdupW( GetProcessHeap(), 0, t );
64             *s=0x0020;
65             while (*s && *s==0x0020)
66               s++;
67             if (*s)
68               t=s+1;
69             else
70               t=s;
71             continue;
72           }
73           s++;
74         }
75         if (*t)
76           argv[i++]=(LPWSTR)HEAP_strdupW( GetProcessHeap(), 0, t );
77
78         HeapFree( GetProcessHeap(), 0, cmdline );
79         argv[i]=NULL;
80         *numargs=i;
81         return argv;
82 }
83
84 /*************************************************************************
85  * Control_RunDLL                       [SHELL32.12]
86  *
87  * Wild speculation in the following!
88  *
89  * http://premium.microsoft.com/msdn/library/techart/msdn193.htm
90  */
91
92 void WINAPI Control_RunDLL( HWND hwnd, LPCVOID code, LPCSTR cmd, DWORD arg4 )
93 {
94     FIXME_(shell)("(0x%08x, %p, %s, 0x%08lx): stub\n", hwnd, code,
95           debugstr_a(cmd), arg4);
96 }
97
98 /*************************************************************************
99  * SHGetFileInfoA                       [SHELL32.254]
100  */
101
102 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
103                               SHFILEINFOA *psfi, UINT sizeofpsfi,
104                               UINT flags )
105 {
106         char szLoaction[MAX_PATH];
107         int iIndex;
108         DWORD ret = TRUE, dwAttributes = 0;
109         IShellFolder * psfParent = NULL;
110         IExtractIcon * pei = NULL;
111         LPITEMIDLIST    pidlLast, pidl = NULL;
112         HRESULT hr = S_OK;
113
114         TRACE_(shell)("(%s,0x%lx,%p,0x%x,0x%x)\n", 
115           (flags & SHGFI_PIDL)? "pidl" : path, dwFileAttributes, psfi, sizeofpsfi, flags);
116
117 #ifdef MORE_DEBUG
118         ZeroMemory(psfi, sizeof(SHFILEINFOA));
119 #endif
120         if ((flags & SHGFI_USEFILEATTRIBUTES) && (flags & (SHGFI_ATTRIBUTES|SHGFI_EXETYPE|SHGFI_PIDL)))
121           return FALSE;
122         
123         /* translate the path into a pidl only when SHGFI_USEFILEATTRIBUTES in not specified 
124            the pidl functions fail on not existing file names */
125         if (flags & SHGFI_PIDL)
126         {
127           pidl = (LPCITEMIDLIST) path;
128           if (!pidl )
129           {
130             ERR_(shell)("pidl is null!\n");
131             return FALSE;
132           }
133         }
134         else if (!(flags & SHGFI_USEFILEATTRIBUTES))
135         {
136           hr = SHILCreateFromPathA ( path, &pidl, &dwAttributes);
137           /* note: the attributes in ISF::ParseDisplayName are not implemented */
138         }
139         
140         /* get the parent shellfolder */
141         if (pidl)
142         {
143           hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
144         }
145         
146         /* get the attributes of the child */
147         if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
148         {
149           if (!(flags & SHGFI_ATTR_SPECIFIED))
150           {
151             psfi->dwAttributes = 0xffffffff;
152           }
153           IShellFolder_GetAttributesOf(psfParent, 1 , &pidlLast, &(psfi->dwAttributes));
154         }
155
156         /* get the displayname */
157         if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
158         { 
159           if (flags & SHGFI_USEFILEATTRIBUTES)
160           {
161             strcpy (psfi->szDisplayName, PathFindFilenameA(path));
162           }
163           else
164           {
165             STRRET str;
166             hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
167             StrRetToStrNA (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
168           }
169         }
170
171         /* get the type name */
172         if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
173         {
174           _ILGetFileType(pidlLast, psfi->szTypeName, 80);
175         }
176
177         /* ### icons ###*/
178         if (flags & SHGFI_LINKOVERLAY)
179           FIXME_(shell)("set icon to link, stub\n");
180
181         if (flags & SHGFI_OPENICON)
182           FIXME_(shell)("set to open icon, stub\n");
183
184         if (flags & SHGFI_SELECTED)
185           FIXME_(shell)("set icon to selected, stub\n");
186
187         if (flags & SHGFI_SHELLICONSIZE)
188           FIXME_(shell)("set icon to shell size, stub\n");
189
190         /* get the iconlocation */
191         if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
192         {
193           UINT uDummy,uFlags;
194           hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, &pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
195
196           if (SUCCEEDED(hr))
197           {
198             hr = IExtractIconA_GetIconLocation(pei, 0, szLoaction, MAX_PATH, &iIndex, &uFlags);
199             /* fixme what to do with the index? */
200
201             if(uFlags != GIL_NOTFILENAME)
202               strcpy (psfi->szDisplayName, szLoaction);
203             else
204               ret = FALSE;
205               
206             IExtractIconA_Release(pei);
207           }
208         }
209
210         /* get icon index (or load icon)*/
211         if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
212         {
213           if (flags & SHGFI_USEFILEATTRIBUTES)
214           {
215             char sTemp [MAX_PATH];
216             char * szExt;
217             DWORD dwNr=0;
218
219             lstrcpynA(sTemp, path, MAX_PATH);
220             szExt = (LPSTR) PathFindExtensionA(sTemp);
221             if( szExt && HCR_MapTypeToValue(szExt, sTemp, MAX_PATH, TRUE)
222               && HCR_GetDefaultIcon(sTemp, sTemp, MAX_PATH, &dwNr))
223             {
224               if (!strcmp("%1",sTemp))            /* icon is in the file */
225               {
226                 strcpy(sTemp, path);
227               }
228               /* FIXME: if sTemp contains a valid filename, get the icon 
229                  from there, index is in dwNr
230               */
231               psfi->iIcon = 2;
232             }
233             else                                  /* default icon */
234             {
235               psfi->iIcon = 0;
236             }          
237           }
238           else
239           {
240             if (!(PidlToSicIndex(psfParent, pidlLast, (flags && SHGFI_LARGEICON), &(psfi->iIcon))))
241             {
242               ret = FALSE;
243             }
244           }
245           if (ret) 
246           {
247             ret = (DWORD) ((flags && SHGFI_LARGEICON) ? ShellBigIconList : ShellSmallIconList);
248           }
249         }
250
251         /* icon handle */
252         if (SUCCEEDED(hr) && (flags & SHGFI_ICON))
253           psfi->hIcon = pImageList_GetIcon((flags && SHGFI_LARGEICON) ? ShellBigIconList:ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
254
255
256         if (flags & SHGFI_EXETYPE)
257           FIXME_(shell)("type of executable, stub\n");
258
259         if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
260           FIXME_(shell)("unknown attribute!\n");
261
262         if (psfParent)
263           IShellFolder_Release(psfParent);
264
265         if (hr != S_OK)
266           ret = FALSE;
267
268 #ifdef MORE_DEBUG
269         TRACE_(shell) ("icon=0x%08x index=0x%08x attr=0x%08lx name=%s type=%s\n", 
270                 psfi->hIcon, psfi->iIcon, psfi->dwAttributes, psfi->szDisplayName, psfi->szTypeName);
271 #endif
272         return ret;
273 }
274
275 /*************************************************************************
276  * SHGetFileInfoW                       [SHELL32.255]
277  */
278
279 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
280                               SHFILEINFOW *psfi, UINT sizeofpsfi,
281                               UINT flags )
282 {       FIXME_(shell)("(%s,0x%lx,%p,0x%x,0x%x)\n",
283               debugstr_w(path),dwFileAttributes,psfi,sizeofpsfi,flags);
284         return 0;
285 }
286
287 /*************************************************************************
288  * ExtractIconA                         [SHELL32.133]
289  */
290 HICON WINAPI ExtractIconA( HINSTANCE hInstance, LPCSTR lpszExeFileName,
291         UINT nIconIndex )
292 {   HGLOBAL16 handle = InternalExtractIcon16(hInstance,lpszExeFileName,nIconIndex, 1);
293     TRACE_(shell)("\n");
294     if( handle )
295     {
296         HICON16* ptr = (HICON16*)GlobalLock16(handle);
297         HICON16  hIcon = *ptr;
298
299         GlobalFree16(handle);
300         return hIcon;
301     }
302     return 0;
303 }
304
305 /*************************************************************************
306  * ExtractIconW                         [SHELL32.180]
307  */
308 HICON WINAPI ExtractIconW( HINSTANCE hInstance, LPCWSTR lpszExeFileName,
309         UINT nIconIndex )
310 { LPSTR  exefn;
311   HICON  ret;
312   TRACE_(shell)("\n");
313
314   exefn = HEAP_strdupWtoA(GetProcessHeap(),0,lpszExeFileName);
315   ret = ExtractIconA(hInstance,exefn,nIconIndex);
316
317         HeapFree(GetProcessHeap(),0,exefn);
318         return ret;
319 }
320
321 /*************************************************************************
322  * FindExecutableA                      [SHELL32.184]
323  */
324 HINSTANCE WINAPI FindExecutableA( LPCSTR lpFile, LPCSTR lpDirectory,
325                                       LPSTR lpResult )
326 { HINSTANCE retval=31;    /* default - 'No association was found' */
327     char old_dir[1024];
328
329   TRACE_(shell)("File %s, Dir %s\n", 
330                  (lpFile != NULL?lpFile:"-"), 
331                  (lpDirectory != NULL?lpDirectory:"-"));
332
333     lpResult[0]='\0'; /* Start off with an empty return string */
334
335     /* trap NULL parameters on entry */
336     if (( lpFile == NULL ) || ( lpResult == NULL ))
337   { /* FIXME - should throw a warning, perhaps! */
338         return 2; /* File not found. Close enough, I guess. */
339     }
340
341     if (lpDirectory)
342   { GetCurrentDirectoryA( sizeof(old_dir), old_dir );
343         SetCurrentDirectoryA( lpDirectory );
344     }
345
346     retval = SHELL_FindExecutable( lpFile, "open", lpResult );
347
348   TRACE_(shell)("returning %s\n", lpResult);
349   if (lpDirectory)
350     SetCurrentDirectoryA( old_dir );
351     return retval;
352 }
353
354 /*************************************************************************
355  * FindExecutableW                      [SHELL32.219]
356  */
357 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory,
358                                      LPWSTR lpResult)
359 {
360   FIXME_(shell)("(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
361   return 31;    /* default - 'No association was found' */
362 }
363
364 typedef struct
365 { LPCSTR  szApp;
366     LPCSTR  szOtherStuff;
367     HICON hIcon;
368 } ABOUT_INFO;
369
370 #define         IDC_STATIC_TEXT         100
371 #define         IDC_LISTBOX             99
372 #define         IDC_WINE_TEXT           98
373
374 #define         DROP_FIELD_TOP          (-15)
375 #define         DROP_FIELD_HEIGHT       15
376
377 extern HICON hIconTitleFont;
378
379 static BOOL __get_dropline( HWND hWnd, LPRECT lprect )
380 { HWND hWndCtl = GetDlgItem(hWnd, IDC_WINE_TEXT);
381     if( hWndCtl )
382   { GetWindowRect( hWndCtl, lprect );
383         MapWindowPoints( 0, hWnd, (LPPOINT)lprect, 2 );
384         lprect->bottom = (lprect->top += DROP_FIELD_TOP);
385         return TRUE;
386     }
387     return FALSE;
388 }
389
390 /*************************************************************************
391  * SHAppBarMessage32                    [SHELL32.207]
392  */
393 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
394 {
395         FIXME_(shell)("(0x%08lx,%p hwnd=0x%08x): stub\n", msg, data, data->hWnd);
396
397         switch (msg)
398         { case ABM_GETSTATE:
399                 return ABS_ALWAYSONTOP | ABS_AUTOHIDE;
400           case ABM_GETTASKBARPOS:
401                 /* fake a taskbar on the bottom of the desktop */
402                 { RECT rec;
403                   GetWindowRect(GetDesktopWindow(), &rec);
404                   rec.left = 0;
405                   rec.top = rec.bottom - 2;
406                 }
407                 return TRUE;
408           case ABM_ACTIVATE:
409           case ABM_GETAUTOHIDEBAR:
410           case ABM_NEW:
411           case ABM_QUERYPOS:
412           case ABM_REMOVE:
413           case ABM_SETAUTOHIDEBAR:
414           case ABM_SETPOS:
415           case ABM_WINDOWPOSCHANGED:
416                 return FALSE;
417         }
418         return 0;
419 }
420
421 /*************************************************************************
422  * SHHelpShortcuts_RunDLL               [SHELL32.224]
423  *
424  */
425 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
426 { FIXME_(exec)("(%lx, %lx, %lx, %lx) empty stub!\n",
427         dwArg1, dwArg2, dwArg3, dwArg4);
428
429   return 0;
430 }
431
432 /*************************************************************************
433  * SHLoadInProc                         [SHELL32.225]
434  *
435  */
436
437 DWORD WINAPI SHLoadInProc (DWORD dwArg1)
438 { FIXME_(shell)("(%lx) empty stub!\n", dwArg1);
439     return 0;
440 }
441
442 /*************************************************************************
443  * ShellExecuteA                        [SHELL32.245]
444  */
445 HINSTANCE WINAPI ShellExecuteA( HWND hWnd, LPCSTR lpOperation,
446                                     LPCSTR lpFile, LPCSTR lpParameters,
447                                     LPCSTR lpDirectory, INT iShowCmd )
448 {   TRACE_(shell)("\n");
449     return ShellExecute16( hWnd, lpOperation, lpFile, lpParameters,
450                            lpDirectory, iShowCmd );
451 }
452
453 /*************************************************************************
454  * ShellExecuteW                        [SHELL32.294]
455  * from shellapi.h
456  * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, 
457  * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);   
458  */
459 HINSTANCE WINAPI 
460 ShellExecuteW(
461        HWND hwnd, 
462        LPCWSTR lpOperation, 
463        LPCWSTR lpFile, 
464        LPCWSTR lpParameters, 
465        LPCWSTR lpDirectory, 
466        INT nShowCmd) {
467
468        FIXME_(shell)(": stub\n");
469        return 0;
470 }
471
472 /*************************************************************************
473  * AboutDlgProc32                       (internal)
474  */
475 BOOL WINAPI AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
476                               LPARAM lParam )
477 {   HWND hWndCtl;
478     char Template[512], AppTitle[512];
479
480     TRACE_(shell)("\n");
481
482     switch(msg)
483     { case WM_INITDIALOG:
484       { ABOUT_INFO *info = (ABOUT_INFO *)lParam;
485             if (info)
486         { const char* const *pstr = SHELL_People;
487                 SendDlgItemMessageA(hWnd, stc1, STM_SETICON,info->hIcon, 0);
488                 GetWindowTextA( hWnd, Template, sizeof(Template) );
489                 sprintf( AppTitle, Template, info->szApp );
490                 SetWindowTextA( hWnd, AppTitle );
491                 SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT),
492                                   info->szOtherStuff );
493                 hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
494                 SendMessageA( hWndCtl, WM_SETREDRAW, 0, 0 );
495                 SendMessageA( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
496                 while (*pstr)
497           { SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)*pstr );
498                     pstr++;
499                 }
500                 SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
501             }
502         }
503         return 1;
504
505     case WM_PAINT:
506       { RECT rect;
507             PAINTSTRUCT ps;
508             HDC hDC = BeginPaint( hWnd, &ps );
509
510             if( __get_dropline( hWnd, &rect ) ) {
511                 SelectObject( hDC, GetStockObject( BLACK_PEN ) );
512                 MoveToEx( hDC, rect.left, rect.top, NULL );
513                 LineTo( hDC, rect.right, rect.bottom );
514             }
515             EndPaint( hWnd, &ps );
516         }
517         break;
518
519     case WM_LBTRACKPOINT:
520         hWndCtl = GetDlgItem(hWnd, IDC_LISTBOX);
521         if( (INT16)GetKeyState16( VK_CONTROL ) < 0 )
522       { if( DragDetect( hWndCtl, *((LPPOINT)&lParam) ) )
523         { INT idx = SendMessageA( hWndCtl, LB_GETCURSEL, 0, 0 );
524                 if( idx != -1 )
525           { INT length = SendMessageA( hWndCtl, LB_GETTEXTLEN, (WPARAM)idx, 0 );
526                     HGLOBAL16 hMemObj = GlobalAlloc16( GMEM_MOVEABLE, length + 1 );
527                     char* pstr = (char*)GlobalLock16( hMemObj );
528
529                     if( pstr )
530             { HCURSOR16 hCursor = LoadCursor16( 0, MAKEINTRESOURCE16(OCR_DRAGOBJECT) );
531                         SendMessageA( hWndCtl, LB_GETTEXT, (WPARAM)idx, (LPARAM)pstr );
532                         SendMessageA( hWndCtl, LB_DELETESTRING, (WPARAM)idx, 0 );
533                         UpdateWindow( hWndCtl );
534                         if( !DragObject16((HWND16)hWnd, (HWND16)hWnd, DRAGOBJ_DATA, 0, (WORD)hMemObj, hCursor) )
535                             SendMessageA( hWndCtl, LB_ADDSTRING, (WPARAM)-1, (LPARAM)pstr );
536                     }
537             if( hMemObj )
538               GlobalFree16( hMemObj );
539                 }
540             }
541         }
542         break;
543
544     case WM_QUERYDROPOBJECT:
545         if( wParam == 0 )
546       { LPDRAGINFO lpDragInfo = (LPDRAGINFO)PTR_SEG_TO_LIN((SEGPTR)lParam);
547             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
548         { RECT rect;
549                 if( __get_dropline( hWnd, &rect ) )
550           { POINT pt;
551             pt.x=lpDragInfo->pt.x;
552             pt.x=lpDragInfo->pt.y;
553                     rect.bottom += DROP_FIELD_HEIGHT;
554                     if( PtInRect( &rect, pt ) )
555             { SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
556                         return TRUE;
557                     }
558                 }
559             }
560         }
561         break;
562
563     case WM_DROPOBJECT:
564         if( wParam == hWnd )
565       { LPDRAGINFO lpDragInfo = (LPDRAGINFO)PTR_SEG_TO_LIN((SEGPTR)lParam);
566             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
567         { char* pstr = (char*)GlobalLock16( (HGLOBAL16)(lpDragInfo->hList) );
568                 if( pstr )
569           { static char __appendix_str[] = " with";
570
571                     hWndCtl = GetDlgItem( hWnd, IDC_WINE_TEXT );
572                     SendMessageA( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
573                     if( !strncmp( Template, "WINE", 4 ) )
574                         SetWindowTextA( GetDlgItem(hWnd, IDC_STATIC_TEXT), Template );
575                     else
576           { char* pch = Template + strlen(Template) - strlen(__appendix_str);
577                         *pch = '\0';
578                         SendMessageA( GetDlgItem(hWnd, IDC_LISTBOX), LB_ADDSTRING, 
579                                         (WPARAM)-1, (LPARAM)Template );
580                     }
581
582                     strcpy( Template, pstr );
583                     strcat( Template, __appendix_str );
584                     SetWindowTextA( hWndCtl, Template );
585                     SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
586                     return TRUE;
587                 }
588             }
589         }
590         break;
591
592     case WM_COMMAND:
593         if (wParam == IDOK)
594     {  EndDialog(hWnd, TRUE);
595             return TRUE;
596         }
597         break;
598     case WM_CLOSE:
599       EndDialog(hWnd, TRUE);
600       break;
601     }
602
603     return 0;
604 }
605
606
607 /*************************************************************************
608  * ShellAboutA                          [SHELL32.243]
609  */
610 BOOL WINAPI ShellAboutA( HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
611                              HICON hIcon )
612 {   ABOUT_INFO info;
613     HRSRC hRes;
614     LPVOID template;
615     TRACE_(shell)("\n");
616
617     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
618         return FALSE;
619     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
620         return FALSE;
621
622     info.szApp        = szApp;
623     info.szOtherStuff = szOtherStuff;
624     info.hIcon        = hIcon;
625     if (!hIcon) info.hIcon = LoadIcon16( 0, MAKEINTRESOURCE16(OIC_WINEICON) );
626     return DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
627                                       template, hWnd, AboutDlgProc, (LPARAM)&info );
628 }
629
630
631 /*************************************************************************
632  * ShellAboutW                          [SHELL32.244]
633  */
634 BOOL WINAPI ShellAboutW( HWND hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
635                              HICON hIcon )
636 {   BOOL ret;
637     ABOUT_INFO info;
638     HRSRC hRes;
639     LPVOID template;
640
641     TRACE_(shell)("\n");
642     
643     if(!(hRes = FindResourceA(shell32_hInstance, "SHELL_ABOUT_MSGBOX", RT_DIALOGA)))
644         return FALSE;
645     if(!(template = (LPVOID)LoadResource(shell32_hInstance, hRes)))
646         return FALSE;
647
648     info.szApp        = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
649     info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
650     info.hIcon        = hIcon;
651     if (!hIcon) info.hIcon = LoadIcon16( 0, MAKEINTRESOURCE16(OIC_WINEICON) );
652     ret = DialogBoxIndirectParamA( GetWindowLongA( hWnd, GWL_HINSTANCE ),
653                                    template, hWnd, AboutDlgProc, (LPARAM)&info );
654     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
655     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
656     return ret;
657 }
658
659 /*************************************************************************
660  * Shell_NotifyIcon                     [SHELL32.296]
661  *      FIXME
662  *      This function is supposed to deal with the systray.
663  *      Any ideas on how this is to be implimented?
664  */
665 BOOL WINAPI Shell_NotifyIcon(   DWORD dwMessage, PNOTIFYICONDATAA pnid )
666 {   FIXME_(shell)("Taskbar Notification Area functionality not implemented !\n");
667     return TRUE; /* pretend success */
668 }
669
670 /*************************************************************************
671  * Shell_NotifyIcon                     [SHELL32.297]
672  *      FIXME
673  *      This function is supposed to deal with the systray.
674  *      Any ideas on how this is to be implimented?
675  */
676 BOOL WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATAA pnid )
677 {   FIXME_(shell)("Taskbar Notification Area functionality not implemented !\n");
678     return TRUE; /* pretend success */
679 }
680
681 /*************************************************************************
682  * FreeIconList
683  */
684 void WINAPI FreeIconList( DWORD dw )
685 { FIXME_(shell)("(%lx): stub\n",dw);
686 }
687
688 /***********************************************************************
689  * DllGetVersion [COMCTL32.25]
690  *
691  * Retrieves version information of the 'SHELL32.DLL'
692  *
693  * PARAMS
694  *     pdvi [O] pointer to version information structure.
695  *
696  * RETURNS
697  *     Success: S_OK
698  *     Failure: E_INVALIDARG
699  *
700  * NOTES
701  *     Returns version of a shell32.dll from IE4.01 SP1.
702  */
703
704 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
705 {
706         if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) 
707         { WARN_(shell)("wrong DLLVERSIONINFO size from app");
708           return E_INVALIDARG;
709         }
710
711         pdvi->dwMajorVersion = 4;
712         pdvi->dwMinorVersion = 72;
713         pdvi->dwBuildNumber = 3110;
714         pdvi->dwPlatformID = 1;
715
716         TRACE_(shell)("%lu.%lu.%lu.%lu\n",
717            pdvi->dwMajorVersion, pdvi->dwMinorVersion,
718            pdvi->dwBuildNumber, pdvi->dwPlatformID);
719
720         return S_OK;
721 }
722 /*************************************************************************
723  * global variables of the shell32.dll
724  * all are once per process
725  *
726  */
727 void    (WINAPI* pDLLInitComctl)(LPVOID);
728 INT     (WINAPI* pImageList_AddIcon) (HIMAGELIST himl, HICON hIcon);
729 INT     (WINAPI* pImageList_ReplaceIcon) (HIMAGELIST, INT, HICON);
730 HIMAGELIST (WINAPI * pImageList_Create) (INT,INT,UINT,INT,INT);
731 BOOL    (WINAPI* pImageList_Draw) (HIMAGELIST himl, int i, HDC hdcDest, int x, int y, UINT fStyle);
732 HICON   (WINAPI * pImageList_GetIcon) (HIMAGELIST, INT, UINT);
733 INT     (WINAPI* pImageList_GetImageCount)(HIMAGELIST);
734 COLORREF (WINAPI *pImageList_SetBkColor)(HIMAGELIST, COLORREF);
735
736 LPVOID  (WINAPI* pCOMCTL32_Alloc) (INT);  
737 BOOL    (WINAPI* pCOMCTL32_Free) (LPVOID);  
738
739 HDPA    (WINAPI* pDPA_Create) (INT);  
740 INT     (WINAPI* pDPA_InsertPtr) (const HDPA, INT, LPVOID); 
741 BOOL    (WINAPI* pDPA_Sort) (const HDPA, PFNDPACOMPARE, LPARAM); 
742 LPVOID  (WINAPI* pDPA_GetPtr) (const HDPA, INT);   
743 BOOL    (WINAPI* pDPA_Destroy) (const HDPA); 
744 INT     (WINAPI *pDPA_Search) (const HDPA, LPVOID, INT, PFNDPACOMPARE, LPARAM, UINT);
745 LPVOID  (WINAPI *pDPA_DeletePtr) (const HDPA hdpa, INT i);
746
747 /* user32 */
748 HICON (WINAPI *pLookupIconIdFromDirectoryEx)(LPBYTE dir, BOOL bIcon, INT width, INT height, UINT cFlag);
749 HICON (WINAPI *pCreateIconFromResourceEx)(LPBYTE bits,UINT cbSize, BOOL bIcon, DWORD dwVersion, INT width, INT height,UINT cFlag);
750
751 /* ole2 */
752 HRESULT (WINAPI* pOleInitialize)(LPVOID reserved);
753 void (WINAPI* pOleUninitialize)(void);
754 HRESULT (WINAPI* pDoDragDrop)(IDataObject* pDataObject, IDropSource * pDropSource, DWORD dwOKEffect, DWORD *pdwEffect);
755 HRESULT (WINAPI* pRegisterDragDrop)(HWND hwnd, IDropTarget* pDropTarget);
756 HRESULT (WINAPI* pRevokeDragDrop)(HWND hwnd);
757
758 static HINSTANCE        hComctl32;
759 static HINSTANCE        hOle32;
760 static INT              shell32_RefCount = 0;
761
762 INT             shell32_ObjCount = 0;
763 HINSTANCE       shell32_hInstance; 
764 HIMAGELIST      ShellSmallIconList = 0;
765 HIMAGELIST      ShellBigIconList = 0;
766
767 /*************************************************************************
768  * SHELL32 LibMain
769  *
770  * NOTES
771  *  calling oleinitialize here breaks sone apps.
772  */
773
774 BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
775 {
776         HMODULE hUser32;
777
778         TRACE_(shell)("0x%x 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
779
780         switch (fdwReason)
781         {
782           case DLL_PROCESS_ATTACH:
783             shell32_RefCount++;
784             if (shell32_hInstance)
785             {
786               ERR_(shell)("shell32.dll instantiated twice in one address space!\n"); 
787             }
788             else
789             {
790               /* we only want to call this the first time shell32 is instantiated */
791               SHInitRestricted(NULL, NULL);
792             }
793
794             shell32_hInstance = hinstDLL;
795
796             hComctl32 = LoadLibraryA("COMCTL32.DLL");   
797             hOle32 = LoadLibraryA("OLE32.DLL");
798             hUser32 = GetModuleHandleA("USER32");
799
800             if (!hComctl32 || !hUser32 || !hOle32)
801             {
802               ERR_(shell)("P A N I C SHELL32 loading failed\n");
803               return FALSE;
804             }
805
806             /* comctl32 */
807             pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
808             pImageList_Create=(void*)GetProcAddress(hComctl32,"ImageList_Create");
809             pImageList_AddIcon=(void*)GetProcAddress(hComctl32,"ImageList_AddIcon");
810             pImageList_ReplaceIcon=(void*)GetProcAddress(hComctl32,"ImageList_ReplaceIcon");
811             pImageList_GetIcon=(void*)GetProcAddress(hComctl32,"ImageList_GetIcon");
812             pImageList_GetImageCount=(void*)GetProcAddress(hComctl32,"ImageList_GetImageCount");
813             pImageList_Draw=(void*)GetProcAddress(hComctl32,"ImageList_Draw");
814             pImageList_SetBkColor=(void*)GetProcAddress(hComctl32,"ImageList_SetBkColor");
815             pCOMCTL32_Alloc=(void*)GetProcAddress(hComctl32, (LPCSTR)71L);
816             pCOMCTL32_Free=(void*)GetProcAddress(hComctl32, (LPCSTR)73L);
817             pDPA_Create=(void*)GetProcAddress(hComctl32, (LPCSTR)328L);
818             pDPA_Destroy=(void*)GetProcAddress(hComctl32, (LPCSTR)329L);
819             pDPA_GetPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)332L);
820             pDPA_InsertPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)334L);
821             pDPA_DeletePtr=(void*)GetProcAddress(hComctl32, (LPCSTR)336L);
822             pDPA_Sort=(void*)GetProcAddress(hComctl32, (LPCSTR)338L);
823             pDPA_Search=(void*)GetProcAddress(hComctl32, (LPCSTR)339L);
824             /* user32 */
825             pLookupIconIdFromDirectoryEx=(void*)GetProcAddress(hUser32,"LookupIconIdFromDirectoryEx");
826             pCreateIconFromResourceEx=(void*)GetProcAddress(hUser32,"CreateIconFromResourceEx");
827             /* ole2 */
828             pOleInitialize=(void*)GetProcAddress(hOle32,"OleInitialize");
829             pOleUninitialize=(void*)GetProcAddress(hOle32,"OleUninitialize");
830             pDoDragDrop=(void*)GetProcAddress(hOle32,"DoDragDrop");
831             pRegisterDragDrop=(void*)GetProcAddress(hOle32,"RegisterDragDrop");
832             pRevokeDragDrop=(void*)GetProcAddress(hOle32,"RevokeDragDrop");
833
834             /* initialize the common controls */
835             if (pDLLInitComctl)
836             {
837               pDLLInitComctl(NULL);
838             }
839
840             SIC_Initialize();
841
842             break;
843
844           case DLL_THREAD_ATTACH:
845             shell32_RefCount++;
846             break;
847
848           case DLL_THREAD_DETACH:
849             shell32_RefCount--;
850             break;
851
852           case DLL_PROCESS_DETACH:
853             shell32_RefCount--;
854
855             if ( !shell32_RefCount )
856             { 
857               shell32_hInstance = 0;
858
859               if (pdesktopfolder) 
860               {
861                 IShellFolder_Release(pdesktopfolder);
862                 pdesktopfolder = NULL;
863               }
864
865               SIC_Destroy();
866
867               /* this one is here to check if AddRef/Release is balanced */
868               if (shell32_ObjCount)
869               {
870                 WARN_(shell)("leaving with %u objects left (memory leak)\n", shell32_ObjCount);
871               }
872             }
873
874             FreeLibrary(hOle32);
875             FreeLibrary(hComctl32);
876
877             TRACE_(shell)("refcount=%u objcount=%u \n", shell32_RefCount, shell32_ObjCount);
878             break;
879         }
880         return TRUE;
881 }
882
883 /*************************************************************************
884  * DllInstall         [SHELL32.202]
885  *
886  * PARAMETERS
887  *   
888  *    BOOL bInstall - TRUE for install, FALSE for uninstall
889  *    LPCWSTR pszCmdLine - command line (unused by shell32?)
890  */
891
892 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
893 {
894    FIXME_(shell)("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
895
896    return S_OK;         /* indicate success */
897 }