Fixed a lot of warnings for possible problems.
[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 "windows.h"
11 #include "wine/winuser16.h"
12 #include "winerror.h"
13 #include "heap.h"
14 #include "resource.h"
15 #include "dlgs.h"
16 #include "win.h"
17 #include "sysmetrics.h"
18 #include "debug.h"
19 #include "winreg.h"
20 #include "authors.h"
21
22 #include "shell.h"
23 #include "pidl.h"
24 #include "shlobj.h"
25 #include "shell32_main.h"
26
27 #include "shlguid.h"
28
29 /*************************************************************************
30  *                              CommandLineToArgvW      [SHELL32.7]
31  */
32 LPWSTR* WINAPI CommandLineToArgvW(LPWSTR cmdline,LPDWORD numargs)
33 { LPWSTR  *argv,s,t;
34         int     i;
35   TRACE(shell,"\n");
36
37         /* to get writeable copy */
38         cmdline = HEAP_strdupW( GetProcessHeap(), 0, cmdline);
39         s=cmdline;i=0;
40   while (*s)
41   { /* space */
42     if (*s==0x0020) 
43     { i++;
44                         s++;
45                         while (*s && *s==0x0020)
46                                 s++;
47                         continue;
48                 }
49                 s++;
50         }
51         argv=(LPWSTR*)HeapAlloc( GetProcessHeap(), 0, sizeof(LPWSTR)*(i+1) );
52         s=t=cmdline;
53         i=0;
54   while (*s)
55   { if (*s==0x0020)
56     { *s=0;
57                         argv[i++]=HEAP_strdupW( GetProcessHeap(), 0, t );
58                         *s=0x0020;
59                         while (*s && *s==0x0020)
60                                 s++;
61                         if (*s)
62                                 t=s+1;
63                         else
64                                 t=s;
65                         continue;
66                 }
67                 s++;
68         }
69         if (*t)
70                 argv[i++]=(LPWSTR)HEAP_strdupW( GetProcessHeap(), 0, t );
71         HeapFree( GetProcessHeap(), 0, cmdline );
72         argv[i]=NULL;
73         *numargs=i;
74         return argv;
75 }
76
77 /*************************************************************************
78  *                              Control_RunDLL          [SHELL32.12]
79  *
80  * Wild speculation in the following!
81  *
82  * http://premium.microsoft.com/msdn/library/techart/msdn193.htm
83  */
84
85 void WINAPI Control_RunDLL( HWND32 hwnd, LPCVOID code, LPCSTR cmd, DWORD arg4 )
86 {
87     FIXME(shell, "(0x%08x, %p, %s, 0x%08lx): stub\n", hwnd, code,
88           debugstr_a(cmd), arg4);
89 }
90
91 /*************************************************************************
92  *  SHGetFileInfoA              [SHELL32.254]
93  *
94  * FIXME
95  *   
96  */
97
98 DWORD WINAPI SHGetFileInfo32A(LPCSTR path,DWORD dwFileAttributes,
99                               SHFILEINFO32A *psfi, UINT32 sizeofpsfi,
100                               UINT32 flags )
101 {       CHAR            szTemp[MAX_PATH];
102         LPPIDLDATA      pData;
103         LPITEMIDLIST    pPidlTemp = NULL;
104         DWORD           ret=0;
105   
106         TRACE(shell,"(%s,0x%lx,%p,0x%x,0x%x)\n",
107               path,dwFileAttributes,psfi,sizeofpsfi,flags);
108
109         /* translate the pidl to a path*/
110         if (flags & SHGFI_PIDL)
111         { pPidlTemp = (LPCITEMIDLIST)path;
112           SHGetPathFromIDList32A (pPidlTemp, szTemp);
113           TRACE(shell,"pidl=%p is %s\n", path, szTemp);
114         }
115         else
116         { strcpy(szTemp,path);
117           TRACE(shell,"path=%s\n", szTemp);
118         }
119
120         if (flags & SHGFI_ATTRIBUTES)
121         { if (flags & SHGFI_PIDL)
122           { pData = _ILGetDataPointer((LPCITEMIDLIST)path);
123             psfi->dwAttributes = pData->u.generic.dwSFGAO; /* fixme: no direct access*/
124             ret=TRUE;
125           }
126           else
127           { psfi->dwAttributes=SFGAO_FILESYSTEM;
128             ret=TRUE;
129           }
130           FIXME(shell,"file attributes, stub\n");           
131         }
132
133         if (flags & SHGFI_DISPLAYNAME)
134         { if (flags & SHGFI_PIDL)
135           { strcpy(psfi->szDisplayName,szTemp);
136           }
137           else
138           { strcpy(psfi->szDisplayName,path);
139           }
140           TRACE(shell,"displayname=%s\n", psfi->szDisplayName);   
141           ret=TRUE;
142         }
143   
144         if (flags & SHGFI_TYPENAME)
145         { FIXME(shell,"get the file type, stub\n");
146           strcpy(psfi->szTypeName,"FIXME: Type");
147           ret=TRUE;
148         }
149   
150   if (flags & SHGFI_ICONLOCATION)
151   { FIXME(shell,"location of icon, stub\n");
152     strcpy(psfi->szDisplayName,"");
153     ret=TRUE;
154   }
155
156   if (flags & SHGFI_EXETYPE)
157     FIXME(shell,"type of executable, stub\n");
158
159   if (flags & SHGFI_LINKOVERLAY)
160     FIXME(shell,"set icon to link, stub\n");
161
162   if (flags & SHGFI_OPENICON)
163     FIXME(shell,"set to open icon, stub\n");
164
165   if (flags & SHGFI_SELECTED)
166     FIXME(shell,"set icon to selected, stub\n");
167
168   if (flags & SHGFI_SHELLICONSIZE)
169     FIXME(shell,"set icon to shell size, stub\n");
170
171   if (flags & SHGFI_USEFILEATTRIBUTES)
172     FIXME(shell,"use the dwFileAttributes, stub\n");
173  
174   if (flags & SHGFI_ICON)
175   { FIXME(shell,"icon handle\n");
176     if (flags & SHGFI_SMALLICON)
177      { TRACE(shell,"set to small icon\n"); 
178        psfi->hIcon=pImageList_GetIcon(ShellSmallIconList,32,ILD_NORMAL);
179        ret = (DWORD) ShellSmallIconList;
180      }
181      else
182      { TRACE(shell,"set to big icon\n");
183        psfi->hIcon=pImageList_GetIcon(ShellBigIconList,32,ILD_NORMAL);
184        ret = (DWORD) ShellBigIconList;
185      }      
186   }
187
188         if (flags & SHGFI_SYSICONINDEX)
189         { if (!pPidlTemp)
190           { pPidlTemp = ILCreateFromPath (szTemp);
191           }
192           psfi->iIcon = SHMapPIDLToSystemImageListIndex (NULL, pPidlTemp, 0);
193           TRACE(shell,"-- SYSICONINDEX %i\n", psfi->iIcon);
194
195           if (flags & SHGFI_SMALLICON)
196           { TRACE(shell,"set to small icon\n"); 
197             ret = (DWORD) ShellSmallIconList;
198           }
199           else        
200           { TRACE(shell,"set to big icon\n");
201             ret = (DWORD) ShellBigIconList;
202           }
203         }
204
205         return ret;
206 }
207
208 /*************************************************************************
209  *  SHGetFileInfo32W            [SHELL32.255]
210  *
211  * FIXME
212  *   
213  */
214
215 DWORD WINAPI SHGetFileInfo32W(LPCWSTR path,DWORD dwFileAttributes,
216                               SHFILEINFO32W *psfi, UINT32 sizeofpsfi,
217                               UINT32 flags )
218 {       FIXME(shell,"(%s,0x%lx,%p,0x%x,0x%x)\n",
219               debugstr_w(path),dwFileAttributes,psfi,sizeofpsfi,flags);
220         return 0;
221 }
222
223 /*************************************************************************
224  *             ExtractIcon32A   (SHELL32.133)
225  */
226 HICON32 WINAPI ExtractIcon32A( HINSTANCE32 hInstance, LPCSTR lpszExeFileName,
227         UINT32 nIconIndex )
228 {   HGLOBAL16 handle = InternalExtractIcon(hInstance,lpszExeFileName,nIconIndex, 1);
229     TRACE(shell,"\n");
230     if( handle )
231     {
232         HICON16* ptr = (HICON16*)GlobalLock16(handle);
233         HICON16  hIcon = *ptr;
234
235         GlobalFree16(handle);
236         return hIcon;
237     }
238     return 0;
239 }
240
241 /*************************************************************************
242  *             ExtractIcon32W   (SHELL32.180)
243  */
244 HICON32 WINAPI ExtractIcon32W( HINSTANCE32 hInstance, LPCWSTR lpszExeFileName,
245         UINT32 nIconIndex )
246 { LPSTR  exefn;
247   HICON32  ret;
248   TRACE(shell,"\n");
249
250   exefn = HEAP_strdupWtoA(GetProcessHeap(),0,lpszExeFileName);
251   ret = ExtractIcon32A(hInstance,exefn,nIconIndex);
252
253         HeapFree(GetProcessHeap(),0,exefn);
254         return ret;
255 }
256
257 /*************************************************************************
258  *             FindExecutable32A   (SHELL32.184)
259  */
260 HINSTANCE32 WINAPI FindExecutable32A( LPCSTR lpFile, LPCSTR lpDirectory,
261                                       LPSTR lpResult )
262 { HINSTANCE32 retval=31;    /* default - 'No association was found' */
263     char old_dir[1024];
264
265   TRACE(shell, "File %s, Dir %s\n", 
266                  (lpFile != NULL?lpFile:"-"), 
267                  (lpDirectory != NULL?lpDirectory:"-"));
268
269     lpResult[0]='\0'; /* Start off with an empty return string */
270
271     /* trap NULL parameters on entry */
272     if (( lpFile == NULL ) || ( lpResult == NULL ))
273   { /* FIXME - should throw a warning, perhaps! */
274         return 2; /* File not found. Close enough, I guess. */
275     }
276
277     if (lpDirectory)
278   { GetCurrentDirectory32A( sizeof(old_dir), old_dir );
279         SetCurrentDirectory32A( lpDirectory );
280     }
281
282     retval = SHELL_FindExecutable( lpFile, "open", lpResult );
283
284   TRACE(shell, "returning %s\n", lpResult);
285   if (lpDirectory)
286     SetCurrentDirectory32A( old_dir );
287     return retval;
288 }
289
290 /*************************************************************************
291  *             FindExecutable32W   (SHELL32.219)
292  */
293 HINSTANCE32 WINAPI FindExecutable32W(LPCWSTR lpFile, LPCWSTR lpDirectory,
294                                      LPWSTR lpResult)
295 {
296   FIXME(shell, "(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
297   return 31;    /* default - 'No association was found' */
298 }
299
300 typedef struct
301 { LPCSTR  szApp;
302     LPCSTR  szOtherStuff;
303     HICON32 hIcon;
304 } ABOUT_INFO;
305
306 #define         IDC_STATIC_TEXT         100
307 #define         IDC_LISTBOX             99
308 #define         IDC_WINE_TEXT           98
309
310 #define         DROP_FIELD_TOP          (-15)
311 #define         DROP_FIELD_HEIGHT       15
312
313 extern HICON32 hIconTitleFont;
314
315 static BOOL32 __get_dropline( HWND32 hWnd, LPRECT32 lprect )
316 { HWND32 hWndCtl = GetDlgItem32(hWnd, IDC_WINE_TEXT);
317     if( hWndCtl )
318   { GetWindowRect32( hWndCtl, lprect );
319         MapWindowPoints32( 0, hWnd, (LPPOINT32)lprect, 2 );
320         lprect->bottom = (lprect->top += DROP_FIELD_TOP);
321         return TRUE;
322     }
323     return FALSE;
324 }
325
326 /*************************************************************************
327  *                              SHAppBarMessage32       [SHELL32.207]
328  */
329 UINT32 WINAPI SHAppBarMessage32(DWORD msg, PAPPBARDATA data)
330 { FIXME(shell,"(0x%08lx,%p): stub\n", msg, data);
331 #if 0
332   switch (msg)
333   { case ABM_ACTIVATE:
334         case ABM_GETAUTOHIDEBAR:
335         case ABM_GETSTATE:
336         case ABM_GETTASKBARPOS:
337         case ABM_NEW:
338         case ABM_QUERYPOS:
339         case ABM_REMOVE:
340         case ABM_SETAUTOHIDEBAR:
341         case ABM_SETPOS:
342         case ABM_WINDOWPOSCHANGED:
343             ;
344     }
345 #endif
346     return 0;
347 }
348
349
350 /*************************************************************************
351  *  SHGetDesktopFolder          [SHELL32.216]
352  * 
353  *  SDK header win95/shlobj.h: This is equivalent to call CoCreateInstance with
354  *  CLSID_ShellDesktop
355  *  CoCreateInstance(CLSID_Desktop, NULL, CLSCTX_INPROC, IID_IShellFolder, &pshf);
356  *
357  * RETURNS
358  *   the interface to the shell desktop folder.
359  *
360  * FIXME
361  *   the pdesktopfolder has to be released at the end (at dll unloading???)
362  */
363 LPSHELLFOLDER pdesktopfolder=NULL;
364
365 DWORD WINAPI SHGetDesktopFolder(LPSHELLFOLDER *shellfolder)
366 { HRESULT       hres = E_OUTOFMEMORY;
367   LPCLASSFACTORY lpclf;
368         TRACE(shell,"%p->(%p)\n",shellfolder,*shellfolder);
369
370   if (pdesktopfolder) {
371     hres = NOERROR;
372   } else {
373     lpclf = IClassFactory_Constructor();
374     /* fixme: the buildin IClassFactory_Constructor is at the moment only 
375                 for rclsid=CLSID_ShellDesktop, so we get the right Interface (jsch)*/
376     if(lpclf) {
377       hres = IClassFactory_CreateInstance(lpclf,NULL,(REFIID)&IID_IShellFolder, (void*)&pdesktopfolder);
378       IClassFactory_Release(lpclf);
379           }  
380   }
381         
382   if (pdesktopfolder) {
383     *shellfolder = pdesktopfolder;
384     pdesktopfolder->lpvtbl->fnAddRef(pdesktopfolder);
385   } else {
386     *shellfolder=NULL;
387         }
388
389   TRACE(shell,"-- %p->(%p)\n",shellfolder, *shellfolder);
390         return hres;
391 }
392
393 /*************************************************************************
394  *                       SHGetPathFromIDList            [SHELL32.221][NT 4.0: SHELL32.219]
395  */
396 BOOL32 WINAPI SHGetPathFromIDList32(LPCITEMIDLIST pidl,LPSTR pszPath)     
397 { TRACE(shell,"(pidl=%p,%p)\n",pidl,pszPath);
398   return SHGetPathFromIDList32A(pidl,pszPath);
399 }
400
401 /*************************************************************************
402  *                       SHGetSpecialFolderLocation     [SHELL32.223]
403  * gets the folder locations from the registry and creates a pidl
404  * creates missing reg keys and directorys
405  * 
406  * PARAMS
407  *   hwndOwner [I]
408  *   nFolder   [I] CSIDL_xxxxx
409  *   ppidl     [O] PIDL of a special folder
410  *
411  * RETURNS
412  *    HResult
413  *
414  * FIXME
415  *   - look for "User Shell Folder" first
416  *
417  */
418 HRESULT WINAPI SHGetSpecialFolderLocation(HWND32 hwndOwner, INT32 nFolder, LPITEMIDLIST * ppidl)
419 { LPSHELLFOLDER shellfolder;
420   DWORD pchEaten,tpathlen=MAX_PATH,type,dwdisp,res;
421   CHAR pszTemp[256],buffer[256],tpath[MAX_PATH],npath[MAX_PATH];
422   LPWSTR lpszDisplayName = (LPWSTR)&pszTemp[0];
423   HKEY key;
424
425         enum 
426         { FT_UNKNOWN= 0x00000000,
427           FT_DIR=     0x00000001, 
428           FT_DESKTOP= 0x00000002,
429           FT_SPECIAL= 0x00000003
430         } tFolder; 
431
432         TRACE(shell,"(%04x,0x%x,%p)\n", hwndOwner,nFolder,ppidl);
433
434         strcpy(buffer,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\");
435
436         res=RegCreateKeyEx32A(HKEY_CURRENT_USER,buffer,0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&key,&dwdisp);
437         if (res)
438         { ERR(shell,"Could not create key %s %08lx \n",buffer,res);
439           return E_OUTOFMEMORY;
440         }
441
442         tFolder=FT_DIR; 
443         switch (nFolder)
444         { case CSIDL_BITBUCKET:
445             strcpy (buffer,"xxx");                      /*not in the registry*/
446             TRACE (shell,"looking for Recycler\n");
447             tFolder=FT_UNKNOWN;
448             break;
449           case CSIDL_CONTROLS:
450             strcpy (buffer,"xxx");                      /*virtual folder*/
451             TRACE (shell,"looking for Control\n");
452             tFolder=FT_UNKNOWN;
453             break;
454           case CSIDL_DESKTOP:
455             strcpy (buffer,"xxx");                      /*virtual folder*/
456             TRACE (shell,"looking for Desktop\n");
457             tFolder=FT_DESKTOP;                 
458             break;
459           case CSIDL_DESKTOPDIRECTORY:
460           case CSIDL_COMMON_DESKTOPDIRECTORY:
461             strcpy (buffer,"Desktop");
462             break;
463           case CSIDL_DRIVES:
464             strcpy (buffer,"xxx");                      /*virtual folder*/
465             TRACE (shell,"looking for Drives\n");
466             tFolder=FT_SPECIAL;
467             break;
468           case CSIDL_FONTS:
469             strcpy (buffer,"Fonts");                    
470             break;
471           case CSIDL_NETHOOD:
472             strcpy (buffer,"NetHood");                  
473             break;
474           case CSIDL_PRINTHOOD:
475             strcpy (buffer,"PrintHood");                        
476             break;
477           case CSIDL_NETWORK:
478             strcpy (buffer,"xxx");                              /*virtual folder*/
479             TRACE (shell,"looking for Network\n");
480             tFolder=FT_UNKNOWN;
481             break;
482           case CSIDL_APPDATA:
483             strcpy (buffer,"Appdata");                  
484             break;
485           case CSIDL_PERSONAL:
486             strcpy (buffer,"Personal");                 
487             break;
488           case CSIDL_FAVORITES:
489             strcpy (buffer,"Favorites");                        
490             break;
491           case CSIDL_PRINTERS:
492             strcpy (buffer,"PrintHood");
493             break;
494           case CSIDL_COMMON_PROGRAMS:
495           case CSIDL_PROGRAMS:
496             strcpy (buffer,"Programs");                 
497             break;
498           case CSIDL_RECENT:
499             strcpy (buffer,"Recent");
500             break;
501           case CSIDL_SENDTO:
502             strcpy (buffer,"SendTo");
503             break;
504           case CSIDL_COMMON_STARTMENU:
505           case CSIDL_STARTMENU:
506             strcpy (buffer,"Start Menu");
507             break;
508           case CSIDL_COMMON_STARTUP:  
509           case CSIDL_STARTUP:
510             strcpy (buffer,"Startup");                  
511             break;
512           case CSIDL_TEMPLATES:
513             strcpy (buffer,"Templates");                        
514             break;
515           default:
516             ERR (shell,"unknown CSIDL 0x%08x\n", nFolder);
517             tFolder=FT_UNKNOWN;                 
518             break;
519         }
520
521         TRACE(shell,"Key=%s\n",buffer);
522
523         type=REG_SZ;
524
525         switch (tFolder)
526         { case FT_DIR:
527             /* Directory: get the value from the registry, if its not there 
528                         create it and the directory*/
529             if (RegQueryValueEx32A(key,buffer,NULL,&type,(LPBYTE)tpath,&tpathlen))
530             { GetWindowsDirectory32A(npath,MAX_PATH);
531               PathAddBackslash32A(npath);
532               switch (nFolder)
533               { case CSIDL_DESKTOPDIRECTORY:
534                 case CSIDL_COMMON_DESKTOPDIRECTORY:
535                   strcat (npath,"Desktop");
536                   break;
537                 case CSIDL_FONTS:
538                   strcat (npath,"Fonts");                       
539                   break;
540                 case CSIDL_NETHOOD:
541                   strcat (npath,"NetHood");                     
542                   break;
543                 case CSIDL_PRINTHOOD:
544                   strcat (npath,"PrintHood");                   
545                   break;
546                 case CSIDL_APPDATA:
547                   strcat (npath,"Appdata");                     
548                   break;
549                 case CSIDL_PERSONAL:
550                   strcpy (npath,"C:\\Personal");                        
551                   break;
552                 case CSIDL_FAVORITES:
553                   strcat (npath,"Favorites");                   
554                   break;
555                 case CSIDL_PRINTERS:
556                   strcat (npath,"PrintHood");                   
557                   break;
558                 case CSIDL_COMMON_PROGRAMS:
559                 case CSIDL_PROGRAMS:
560                   strcat (npath,"Start Menu");                  
561                   CreateDirectory32A(npath,NULL);
562                   strcat (npath,"\\Programs");                  
563                   break;
564                 case CSIDL_RECENT:
565                   strcat (npath,"Recent");
566                   break;
567                 case CSIDL_SENDTO:
568                   strcat (npath,"SendTo");
569                   break;
570                 case CSIDL_COMMON_STARTMENU:
571                 case CSIDL_STARTMENU:
572                   strcat (npath,"Start Menu");
573                   break;
574                 case CSIDL_COMMON_STARTUP:  
575                 case CSIDL_STARTUP:
576                   strcat (npath,"Start Menu");                  
577                   CreateDirectory32A(npath,NULL);
578                   strcat (npath,"\\Startup");                   
579                   break;
580                 case CSIDL_TEMPLATES:
581                   strcat (npath,"Templates");                   
582                   break;
583                 default:
584                   RegCloseKey(key);
585                   return E_OUTOFMEMORY;
586               }
587               if (RegSetValueEx32A(key,buffer,0,REG_SZ,(LPBYTE)npath,sizeof(npath)+1))
588               { ERR(shell,"could not create value %s\n",buffer);
589                 RegCloseKey(key);
590                 return E_OUTOFMEMORY;
591               }
592               TRACE(shell,"value %s=%s created\n",buffer,npath);
593               CreateDirectory32A(npath,NULL);
594               strcpy(tpath,npath);
595             }
596             break;
597           case FT_DESKTOP:
598             strcpy (tpath,"Desktop");
599             break;
600           case FT_SPECIAL:
601             if (nFolder==CSIDL_DRIVES)
602             strcpy (tpath,"My Computer");
603             break;
604           default:
605             RegCloseKey(key);
606             return E_OUTOFMEMORY;
607         }
608
609         RegCloseKey(key);
610
611         TRACE(shell,"Value=%s\n",tpath);
612         LocalToWideChar32(lpszDisplayName, tpath, 256);
613   
614         if (SHGetDesktopFolder(&shellfolder)==S_OK)
615         { shellfolder->lpvtbl->fnParseDisplayName(shellfolder,hwndOwner, NULL,lpszDisplayName,&pchEaten,ppidl,NULL);
616           shellfolder->lpvtbl->fnRelease(shellfolder);
617         }
618
619         TRACE(shell, "-- (new pidl %p)\n",*ppidl);
620         return NOERROR;
621 }
622 /*************************************************************************
623  * SHHelpShortcuts_RunDLL [SHELL32.224]
624  *
625  */
626 DWORD WINAPI SHHelpShortcuts_RunDLL (DWORD dwArg1, DWORD dwArg2, DWORD dwArg3, DWORD dwArg4)
627 { FIXME (exec, "(%lx, %lx, %lx, %lx) empty stub!\n",
628         dwArg1, dwArg2, dwArg3, dwArg4);
629
630   return 0;
631 }
632
633 /*************************************************************************
634  * SHLoadInProc [SHELL32.225]
635  *
636  */
637
638 DWORD WINAPI SHLoadInProc (DWORD dwArg1)
639 { FIXME (shell, "(%lx) empty stub!\n", dwArg1);
640     return 0;
641 }
642
643 /*************************************************************************
644  *             ShellExecute32A   (SHELL32.245)
645  */
646 HINSTANCE32 WINAPI ShellExecute32A( HWND32 hWnd, LPCSTR lpOperation,
647                                     LPCSTR lpFile, LPCSTR lpParameters,
648                                     LPCSTR lpDirectory, INT32 iShowCmd )
649 {   TRACE(shell,"\n");
650     return ShellExecute16( hWnd, lpOperation, lpFile, lpParameters,
651                            lpDirectory, iShowCmd );
652 }
653
654 /*************************************************************************
655  * ShellExecute32W [SHELL32.294]
656  * from shellapi.h
657  * WINSHELLAPI HINSTANCE APIENTRY ShellExecuteW(HWND hwnd, LPCWSTR lpOperation, 
658  * LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd);   
659  */
660 HINSTANCE32 WINAPI 
661 ShellExecute32W(
662        HWND32 hwnd, 
663        LPCWSTR lpOperation, 
664        LPCWSTR lpFile, 
665        LPCWSTR lpParameters, 
666        LPCWSTR lpDirectory, 
667        INT32 nShowCmd) {
668
669        FIXME(shell,": stub\n");
670        return 0;
671 }
672
673 /*************************************************************************
674  *             AboutDlgProc32  (not an exported API function)
675  */
676 BOOL32 WINAPI AboutDlgProc32( HWND32 hWnd, UINT32 msg, WPARAM32 wParam,
677                               LPARAM lParam )
678 {   HWND32 hWndCtl;
679     char Template[512], AppTitle[512];
680
681     TRACE(shell,"\n");
682
683     switch(msg)
684     { case WM_INITDIALOG:
685       { ABOUT_INFO *info = (ABOUT_INFO *)lParam;
686             if (info)
687         { const char* const *pstr = SHELL_People;
688                 SendDlgItemMessage32A(hWnd, stc1, STM_SETICON32,info->hIcon, 0);
689                 GetWindowText32A( hWnd, Template, sizeof(Template) );
690                 sprintf( AppTitle, Template, info->szApp );
691                 SetWindowText32A( hWnd, AppTitle );
692                 SetWindowText32A( GetDlgItem32(hWnd, IDC_STATIC_TEXT),
693                                   info->szOtherStuff );
694                 hWndCtl = GetDlgItem32(hWnd, IDC_LISTBOX);
695                 SendMessage32A( hWndCtl, WM_SETREDRAW, 0, 0 );
696                 SendMessage32A( hWndCtl, WM_SETFONT, hIconTitleFont, 0 );
697                 while (*pstr)
698           { SendMessage32A( hWndCtl, LB_ADDSTRING32, (WPARAM32)-1, (LPARAM)*pstr );
699                     pstr++;
700                 }
701                 SendMessage32A( hWndCtl, WM_SETREDRAW, 1, 0 );
702             }
703         }
704         return 1;
705
706     case WM_PAINT:
707       { RECT32 rect;
708             PAINTSTRUCT32 ps;
709             HDC32 hDC = BeginPaint32( hWnd, &ps );
710
711             if( __get_dropline( hWnd, &rect ) ) {
712                 SelectObject32( hDC, GetStockObject32( BLACK_PEN ) );
713                 MoveToEx32( hDC, rect.left, rect.top, NULL );
714                 LineTo32( hDC, rect.right, rect.bottom );
715             }
716             EndPaint32( hWnd, &ps );
717         }
718         break;
719
720     case WM_LBTRACKPOINT:
721         hWndCtl = GetDlgItem32(hWnd, IDC_LISTBOX);
722         if( (INT16)GetKeyState16( VK_CONTROL ) < 0 )
723       { if( DragDetect32( hWndCtl, *((LPPOINT32)&lParam) ) )
724         { INT32 idx = SendMessage32A( hWndCtl, LB_GETCURSEL32, 0, 0 );
725                 if( idx != -1 )
726           { INT32 length = SendMessage32A( hWndCtl, LB_GETTEXTLEN32, (WPARAM32)idx, 0 );
727                     HGLOBAL16 hMemObj = GlobalAlloc16( GMEM_MOVEABLE, length + 1 );
728                     char* pstr = (char*)GlobalLock16( hMemObj );
729
730                     if( pstr )
731             { HCURSOR16 hCursor = LoadCursor16( 0, MAKEINTRESOURCE16(OCR_DRAGOBJECT) );
732                         SendMessage32A( hWndCtl, LB_GETTEXT32, (WPARAM32)idx, (LPARAM)pstr );
733                         SendMessage32A( hWndCtl, LB_DELETESTRING32, (WPARAM32)idx, 0 );
734                         UpdateWindow32( hWndCtl );
735                         if( !DragObject16((HWND16)hWnd, (HWND16)hWnd, DRAGOBJ_DATA, 0, (WORD)hMemObj, hCursor) )
736                             SendMessage32A( hWndCtl, LB_ADDSTRING32, (WPARAM32)-1, (LPARAM)pstr );
737                     }
738             if( hMemObj )
739               GlobalFree16( hMemObj );
740                 }
741             }
742         }
743         break;
744
745     case WM_QUERYDROPOBJECT:
746         if( wParam == 0 )
747       { LPDRAGINFO lpDragInfo = (LPDRAGINFO)PTR_SEG_TO_LIN((SEGPTR)lParam);
748             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA )
749         { RECT32 rect;
750                 if( __get_dropline( hWnd, &rect ) )
751           { POINT32 pt;
752             pt.x=lpDragInfo->pt.x;
753             pt.x=lpDragInfo->pt.y;
754                     rect.bottom += DROP_FIELD_HEIGHT;
755                     if( PtInRect32( &rect, pt ) )
756             { SetWindowLong32A( hWnd, DWL_MSGRESULT, 1 );
757                         return TRUE;
758                     }
759                 }
760             }
761         }
762         break;
763
764     case WM_DROPOBJECT:
765         if( wParam == hWnd )
766       { LPDRAGINFO lpDragInfo = (LPDRAGINFO)PTR_SEG_TO_LIN((SEGPTR)lParam);
767             if( lpDragInfo && lpDragInfo->wFlags == DRAGOBJ_DATA && lpDragInfo->hList )
768         { char* pstr = (char*)GlobalLock16( (HGLOBAL16)(lpDragInfo->hList) );
769                 if( pstr )
770           { static char __appendix_str[] = " with";
771
772                     hWndCtl = GetDlgItem32( hWnd, IDC_WINE_TEXT );
773                     SendMessage32A( hWndCtl, WM_GETTEXT, 512, (LPARAM)Template );
774                     if( !lstrncmp32A( Template, "WINE", 4 ) )
775                         SetWindowText32A( GetDlgItem32(hWnd, IDC_STATIC_TEXT), Template );
776                     else
777           { char* pch = Template + strlen(Template) - strlen(__appendix_str);
778                         *pch = '\0';
779                         SendMessage32A( GetDlgItem32(hWnd, IDC_LISTBOX), LB_ADDSTRING32, 
780                                         (WPARAM32)-1, (LPARAM)Template );
781                     }
782
783                     lstrcpy32A( Template, pstr );
784                     lstrcat32A( Template, __appendix_str );
785                     SetWindowText32A( hWndCtl, Template );
786                     SetWindowLong32A( hWnd, DWL_MSGRESULT, 1 );
787                     return TRUE;
788                 }
789             }
790         }
791         break;
792
793     case WM_COMMAND:
794         if (wParam == IDOK)
795     {  EndDialog32(hWnd, TRUE);
796             return TRUE;
797         }
798         break;
799     }
800     return 0;
801 }
802
803
804 /*************************************************************************
805  *             ShellAbout32A   (SHELL32.243)
806  */
807 BOOL32 WINAPI ShellAbout32A( HWND32 hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
808                              HICON32 hIcon )
809 {   ABOUT_INFO info;
810     TRACE(shell,"\n");
811     info.szApp        = szApp;
812     info.szOtherStuff = szOtherStuff;
813     info.hIcon        = hIcon;
814     if (!hIcon) info.hIcon = LoadIcon16( 0, MAKEINTRESOURCE16(OIC_WINEICON) );
815     return DialogBoxIndirectParam32A( WIN_GetWindowInstance( hWnd ),
816                          SYSRES_GetResPtr( SYSRES_DIALOG_SHELL_ABOUT_MSGBOX ),
817                                       hWnd, AboutDlgProc32, (LPARAM)&info );
818 }
819
820
821 /*************************************************************************
822  *             ShellAbout32W   (SHELL32.244)
823  */
824 BOOL32 WINAPI ShellAbout32W( HWND32 hWnd, LPCWSTR szApp, LPCWSTR szOtherStuff,
825                              HICON32 hIcon )
826 {   BOOL32 ret;
827     ABOUT_INFO info;
828
829     TRACE(shell,"\n");
830     
831     info.szApp        = HEAP_strdupWtoA( GetProcessHeap(), 0, szApp );
832     info.szOtherStuff = HEAP_strdupWtoA( GetProcessHeap(), 0, szOtherStuff );
833     info.hIcon        = hIcon;
834     if (!hIcon) info.hIcon = LoadIcon16( 0, MAKEINTRESOURCE16(OIC_WINEICON) );
835     ret = DialogBoxIndirectParam32A( WIN_GetWindowInstance( hWnd ),
836                          SYSRES_GetResPtr( SYSRES_DIALOG_SHELL_ABOUT_MSGBOX ),
837                                       hWnd, AboutDlgProc32, (LPARAM)&info );
838     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szApp );
839     HeapFree( GetProcessHeap(), 0, (LPSTR)info.szOtherStuff );
840     return ret;
841 }
842
843 /*************************************************************************
844  *                              Shell_NotifyIcon        [SHELL32.296]
845  *      FIXME
846  *      This function is supposed to deal with the systray.
847  *      Any ideas on how this is to be implimented?
848  */
849 BOOL32 WINAPI Shell_NotifyIcon( DWORD dwMessage, PNOTIFYICONDATA pnid )
850 {   TRACE(shell,"\n");
851     return FALSE;
852 }
853
854 /*************************************************************************
855  *                              Shell_NotifyIcon        [SHELL32.297]
856  *      FIXME
857  *      This function is supposed to deal with the systray.
858  *      Any ideas on how this is to be implimented?
859  */
860 BOOL32 WINAPI Shell_NotifyIconA(DWORD dwMessage, PNOTIFYICONDATA pnid )
861 {   TRACE(shell,"\n");
862     return FALSE;
863 }
864
865 /*************************************************************************
866  * FreeIconList
867  */
868 void WINAPI FreeIconList( DWORD dw )
869 { FIXME(shell, "(%lx): stub\n",dw);
870 }
871
872 /*************************************************************************
873  * SHGetPathFromIDList32A        [SHELL32.261][NT 4.0: SHELL32.220]
874  *
875  * PARAMETERS
876  *  pidl,   [IN] pidl 
877  *  pszPath [OUT] path
878  *
879  * RETURNS 
880  *  path from a passed PIDL.
881  *
882  * NOTES
883  *     exported by name
884  *
885  * FIXME
886  *  fnGetDisplayNameOf can return different types of OLEString
887  */
888 DWORD WINAPI SHGetPathFromIDList32A (LPCITEMIDLIST pidl,LPSTR pszPath)
889 {       STRRET lpName;
890         LPSHELLFOLDER shellfolder;
891         CHAR  buffer[MAX_PATH],tpath[MAX_PATH];
892         DWORD type,tpathlen=MAX_PATH,dwdisp;
893         HKEY  key;
894
895         TRACE(shell,"(pidl=%p,%p)\n",pidl,pszPath);
896
897   if (!pidl)
898   {  strcpy(buffer,"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\");
899
900      if (RegCreateKeyEx32A(HKEY_CURRENT_USER,buffer,0,NULL,REG_OPTION_NON_VOLATILE,KEY_WRITE,NULL,&key,&dwdisp))
901      { return E_OUTOFMEMORY;
902      }
903      type=REG_SZ;    
904      strcpy (buffer,"Desktop");                                 /*registry name*/
905      if ( RegQueryValueEx32A(key,buffer,NULL,&type,(LPBYTE)tpath,&tpathlen))
906      { GetWindowsDirectory32A(tpath,MAX_PATH);
907        PathAddBackslash32A(tpath);
908        strcat (tpath,"Desktop");                                /*folder name*/
909        RegSetValueEx32A(key,buffer,0,REG_SZ,(LPBYTE)tpath,tpathlen);
910        CreateDirectory32A(tpath,NULL);
911      }
912      RegCloseKey(key);
913      strcpy(pszPath,tpath);
914   }
915   else
916   { if (SHGetDesktopFolder(&shellfolder)==S_OK)
917         { shellfolder->lpvtbl->fnGetDisplayNameOf(shellfolder,pidl,SHGDN_FORPARSING,&lpName);
918           shellfolder->lpvtbl->fnRelease(shellfolder);
919         }
920   /*WideCharToLocal32(pszPath, lpName.u.pOleStr, MAX_PATH);*/
921         strcpy(pszPath,lpName.u.cStr);
922         /* fixme free the olestring*/
923   }
924         TRACE(shell,"-- (%s)\n",pszPath);
925         return NOERROR;
926 }
927 /*************************************************************************
928  * SHGetPathFromIDList32W [SHELL32.262]
929  */
930 DWORD WINAPI SHGetPathFromIDList32W (LPCITEMIDLIST pidl,LPWSTR pszPath)
931 {       char sTemp[MAX_PATH];
932
933         TRACE (shell,"(pidl=%p)\n", pidl);
934
935         SHGetPathFromIDList32A (pidl, sTemp);
936         lstrcpyAtoW(pszPath, sTemp);
937
938         TRACE(shell,"-- (%s)\n",debugstr_w(pszPath));
939
940         return NOERROR;
941 }
942
943 /*************************************************************************
944  * global variables of the shell32.dll
945  *
946  */
947 void    (WINAPI* pDLLInitComctl)(LPVOID);
948 INT32   (WINAPI* pImageList_AddIcon) (HIMAGELIST himl, HICON32 hIcon);
949 INT32   (WINAPI* pImageList_ReplaceIcon) (HIMAGELIST, INT32, HICON32);
950 HIMAGELIST (WINAPI * pImageList_Create) (INT32,INT32,UINT32,INT32,INT32);
951 HICON32 (WINAPI * pImageList_GetIcon) (HIMAGELIST, INT32, UINT32);
952 INT32   (WINAPI* pImageList_GetImageCount)(HIMAGELIST);
953
954 LPVOID  (WINAPI* pCOMCTL32_Alloc) (INT32);  
955 BOOL32  (WINAPI* pCOMCTL32_Free) (LPVOID);  
956
957 HDPA    (WINAPI* pDPA_Create) (INT32);  
958 INT32   (WINAPI* pDPA_InsertPtr) (const HDPA, INT32, LPVOID); 
959 BOOL32  (WINAPI* pDPA_Sort) (const HDPA, PFNDPACOMPARE, LPARAM); 
960 LPVOID  (WINAPI* pDPA_GetPtr) (const HDPA, INT32);   
961 BOOL32  (WINAPI* pDPA_Destroy) (const HDPA); 
962 INT32   (WINAPI *pDPA_Search) (const HDPA, LPVOID, INT32, PFNDPACOMPARE, LPARAM, UINT32);
963
964 /* user32 */
965 HICON32 (WINAPI *pLookupIconIdFromDirectoryEx32)(LPBYTE dir, BOOL32 bIcon, INT32 width, INT32 height, UINT32 cFlag);
966 HICON32 (WINAPI *pCreateIconFromResourceEx32)(LPBYTE bits,UINT32 cbSize, BOOL32 bIcon, DWORD dwVersion, INT32 width, INT32 height,UINT32 cFlag);
967
968 static BOOL32           bShell32IsInitialized = 0;
969 static HINSTANCE32      hComctl32;
970 static INT32            shell32_RefCount = 0;
971
972 INT32           shell32_ObjCount = 0;
973 HINSTANCE32     shell32_hInstance; 
974 /*************************************************************************
975  * SHELL32 LibMain
976  *
977  */
978
979 BOOL32 WINAPI Shell32LibMain(HINSTANCE32 hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
980 {       HMODULE32 hUser32;
981
982         TRACE(shell,"0x%x 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
983
984         shell32_hInstance = hinstDLL;
985   
986         switch (fdwReason)
987         { case DLL_PROCESS_ATTACH:
988             if (!bShell32IsInitialized)
989             { hComctl32 = LoadLibrary32A("COMCTL32.DLL");       
990               hUser32 = GetModuleHandle32A("USER32");
991               if (hComctl32 && hUser32)
992               { pDLLInitComctl=(void*)GetProcAddress32(hComctl32,"InitCommonControlsEx");
993                 if (pDLLInitComctl)
994                 { pDLLInitComctl(NULL);
995                 }
996                 pImageList_Create=(void*)GetProcAddress32(hComctl32,"ImageList_Create");
997                 pImageList_AddIcon=(void*)GetProcAddress32(hComctl32,"ImageList_AddIcon");
998                 pImageList_ReplaceIcon=(void*)GetProcAddress32(hComctl32,"ImageList_ReplaceIcon");
999                 pImageList_GetIcon=(void*)GetProcAddress32(hComctl32,"ImageList_GetIcon");
1000                 pImageList_GetImageCount=(void*)GetProcAddress32(hComctl32,"ImageList_GetImageCount");
1001
1002                 /* imports by ordinal, pray that it works*/
1003                 pCOMCTL32_Alloc=(void*)GetProcAddress32(hComctl32, (LPCSTR)71L);
1004                 pCOMCTL32_Free=(void*)GetProcAddress32(hComctl32, (LPCSTR)73L);
1005                 pDPA_Create=(void*)GetProcAddress32(hComctl32, (LPCSTR)328L);
1006                 pDPA_Destroy=(void*)GetProcAddress32(hComctl32, (LPCSTR)329L);
1007                 pDPA_GetPtr=(void*)GetProcAddress32(hComctl32, (LPCSTR)332L);
1008                 pDPA_InsertPtr=(void*)GetProcAddress32(hComctl32, (LPCSTR)334L);
1009                 pDPA_Sort=(void*)GetProcAddress32(hComctl32, (LPCSTR)338L);
1010                 pDPA_Search=(void*)GetProcAddress32(hComctl32, (LPCSTR)339L);
1011                 /* user32 */
1012                 pLookupIconIdFromDirectoryEx32=(void*)GetProcAddress32(hUser32,"LookupIconIdFromDirectoryEx");
1013                 pCreateIconFromResourceEx32=(void*)GetProcAddress32(hUser32,"CreateIconFromResourceEx");
1014               }
1015               else
1016               { ERR(shell,"P A N I C SHELL32 loading failed\n");
1017                 return FALSE;
1018               }
1019               SIC_Initialize();
1020               bShell32IsInitialized = TRUE;
1021             }
1022             shell32_RefCount++;
1023             break;
1024
1025           case DLL_THREAD_ATTACH:
1026             shell32_RefCount++;
1027             break;
1028
1029           case DLL_THREAD_DETACH:
1030             shell32_RefCount--;
1031             break;
1032
1033           case DLL_PROCESS_DETACH:
1034             shell32_RefCount--;
1035             if ( !shell32_RefCount )
1036             { FreeLibrary32(hComctl32);
1037               bShell32IsInitialized = FALSE;
1038
1039               if (pdesktopfolder) 
1040               { pdesktopfolder->lpvtbl->fnRelease(pdesktopfolder);
1041               }
1042
1043               /* this one is here ot check if AddRef/Release is balanced */
1044               if (shell32_ObjCount)
1045               { FIXME(shell,"%u objects left\n", shell32_ObjCount);
1046               }
1047             }
1048             TRACE(shell, "refcount=%u objcount=%u \n", shell32_RefCount, shell32_ObjCount);
1049             break;            
1050         }
1051
1052         return TRUE;
1053 }