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