Removed resource.h.
[wine/wine64.git] / dlls / shell32 / shell32_main.c
blob4402538614966239378908230c617f59ff1ab15a
1 /*
2 * Shell basics
4 * 1998 Marcus Meissner
5 * 1998 Juergen Schmied (jsch) * <juergen.schmied@metronet.de>
6 */
7 #include <stdlib.h>
8 #include <string.h>
10 #include "wine/winuser16.h"
11 #include "winerror.h"
12 #include "heap.h"
13 #include "dlgs.h"
14 #include "ldt.h"
15 #include "sysmetrics.h"
16 #include "debugtools.h"
17 #include "winreg.h"
18 #include "authors.h"
19 #include "winversion.h"
21 #include "shellapi.h"
22 #include "pidl.h"
24 #include "shlobj.h"
25 #include "shell32_main.h"
26 #include "shlguid.h"
27 #include "wine/undocshell.h"
28 #include "shpolicy.h"
30 DEFAULT_DEBUG_CHANNEL(shell)
31 DECLARE_DEBUG_CHANNEL(exec)
33 #define MORE_DEBUG 1
34 /*************************************************************************
35 * CommandLineToArgvW [SHELL32.7]
37 LPWSTR* WINAPI CommandLineToArgvW(LPWSTR cmdline,LPDWORD numargs)
38 { LPWSTR *argv,s,t;
39 int i;
40 TRACE("\n");
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;
54 s++;
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;
72 s++;
74 if (*t)
75 argv[i++]=(LPWSTR)HEAP_strdupW( GetProcessHeap(), 0, t );
77 HeapFree( GetProcessHeap(), 0, cmdline );
78 argv[i]=NULL;
79 *numargs=i;
80 return argv;
83 /*************************************************************************
84 * Control_RunDLL [SHELL32.12]
86 * Wild speculation in the following!
88 * http://premium.microsoft.com/msdn/library/techart/msdn193.htm
91 void WINAPI Control_RunDLL( HWND hwnd, LPCVOID code, LPCSTR cmd, DWORD arg4 )
93 FIXME("(0x%08x, %p, %s, 0x%08lx): stub\n", hwnd, code,
94 debugstr_a(cmd), arg4);
97 /*************************************************************************
98 * SHGetFileInfoA [SHELL32.254]
101 DWORD WINAPI SHGetFileInfoA(LPCSTR path,DWORD dwFileAttributes,
102 SHFILEINFOA *psfi, UINT sizeofpsfi,
103 UINT flags )
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;
113 TRACE("(%s,0x%lx,%p,0x%x,0x%x)\n",
114 (flags & SHGFI_PIDL)? "pidl" : path, dwFileAttributes, psfi, sizeofpsfi, flags);
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;
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)
126 pidl = (LPCITEMIDLIST) path;
127 if (!pidl )
129 ERR("pidl is null!\n");
130 return FALSE;
133 else if (!(flags & SHGFI_USEFILEATTRIBUTES))
135 hr = SHILCreateFromPathA ( path, &pidl, &dwAttributes);
136 /* note: the attributes in ISF::ParseDisplayName are not implemented */
139 /* get the parent shellfolder */
140 if (pidl)
142 hr = SHBindToParent( pidl, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
145 /* get the attributes of the child */
146 if (SUCCEEDED(hr) && (flags & SHGFI_ATTRIBUTES))
148 if (!(flags & SHGFI_ATTR_SPECIFIED))
150 psfi->dwAttributes = 0xffffffff;
152 IShellFolder_GetAttributesOf(psfParent, 1 , &pidlLast, &(psfi->dwAttributes));
155 /* get the displayname */
156 if (SUCCEEDED(hr) && (flags & SHGFI_DISPLAYNAME))
158 if (flags & SHGFI_USEFILEATTRIBUTES)
160 strcpy (psfi->szDisplayName, PathFindFilenameA(path));
162 else
164 STRRET str;
165 hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_INFOLDER, &str);
166 StrRetToStrNA (psfi->szDisplayName, MAX_PATH, &str, pidlLast);
170 /* get the type name */
171 if (SUCCEEDED(hr) && (flags & SHGFI_TYPENAME))
173 _ILGetFileType(pidlLast, psfi->szTypeName, 80);
176 /* ### icons ###*/
177 if (flags & SHGFI_LINKOVERLAY)
178 FIXME("set icon to link, stub\n");
180 if (flags & SHGFI_OPENICON)
181 FIXME("set to open icon, stub\n");
183 if (flags & SHGFI_SELECTED)
184 FIXME("set icon to selected, stub\n");
186 if (flags & SHGFI_SHELLICONSIZE)
187 FIXME("set icon to shell size, stub\n");
189 /* get the iconlocation */
190 if (SUCCEEDED(hr) && (flags & SHGFI_ICONLOCATION ))
192 UINT uDummy,uFlags;
193 hr = IShellFolder_GetUIObjectOf(psfParent, 0, 1, &pidlLast, &IID_IExtractIconA, &uDummy, (LPVOID*)&pei);
195 if (SUCCEEDED(hr))
197 hr = IExtractIconA_GetIconLocation(pei, 0, szLoaction, MAX_PATH, &iIndex, &uFlags);
198 /* fixme what to do with the index? */
200 if(uFlags != GIL_NOTFILENAME)
201 strcpy (psfi->szDisplayName, szLoaction);
202 else
203 ret = FALSE;
205 IExtractIconA_Release(pei);
209 /* get icon index (or load icon)*/
210 if (SUCCEEDED(hr) && (flags & (SHGFI_ICON | SHGFI_SYSICONINDEX)))
212 if (flags & SHGFI_USEFILEATTRIBUTES)
214 char sTemp [MAX_PATH];
215 char * szExt;
216 DWORD dwNr=0;
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))
223 if (!strcmp("%1",sTemp)) /* icon is in the file */
225 strcpy(sTemp, path);
227 /* FIXME: if sTemp contains a valid filename, get the icon
228 from there, index is in dwNr
230 psfi->iIcon = 2;
232 else /* default icon */
234 psfi->iIcon = 0;
237 else
239 if (!(PidlToSicIndex(psfParent, pidlLast, (flags && SHGFI_LARGEICON), &(psfi->iIcon))))
241 ret = FALSE;
244 if (ret)
246 ret = (DWORD) ((flags && SHGFI_LARGEICON) ? ShellBigIconList : ShellSmallIconList);
250 /* icon handle */
251 if (SUCCEEDED(hr) && (flags & SHGFI_ICON))
252 psfi->hIcon = pImageList_GetIcon((flags && SHGFI_LARGEICON) ? ShellBigIconList:ShellSmallIconList, psfi->iIcon, ILD_NORMAL);
255 if (flags & SHGFI_EXETYPE)
256 FIXME("type of executable, stub\n");
258 if (flags & (SHGFI_UNKNOWN1 | SHGFI_UNKNOWN2 | SHGFI_UNKNOWN3))
259 FIXME("unknown attribute!\n");
261 if (psfParent)
262 IShellFolder_Release(psfParent);
264 if (hr != S_OK)
265 ret = FALSE;
267 #ifdef MORE_DEBUG
268 TRACE ("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;
274 /*************************************************************************
275 * SHGetFileInfoW [SHELL32.255]
278 DWORD WINAPI SHGetFileInfoW(LPCWSTR path,DWORD dwFileAttributes,
279 SHFILEINFOW *psfi, UINT sizeofpsfi,
280 UINT flags )
281 { FIXME("(%s,0x%lx,%p,0x%x,0x%x)\n",
282 debugstr_w(path),dwFileAttributes,psfi,sizeofpsfi,flags);
283 return 0;
286 /*************************************************************************
287 * ExtractIconA [SHELL32.133]
289 HICON WINAPI ExtractIconA( HINSTANCE hInstance, LPCSTR lpszExeFileName,
290 UINT nIconIndex )
291 { HGLOBAL16 handle = InternalExtractIcon16(hInstance,lpszExeFileName,nIconIndex, 1);
292 TRACE("\n");
293 if( handle )
295 HICON16* ptr = (HICON16*)GlobalLock16(handle);
296 HICON16 hIcon = *ptr;
298 GlobalFree16(handle);
299 return hIcon;
301 return 0;
304 /*************************************************************************
305 * ExtractIconW [SHELL32.180]
307 HICON WINAPI ExtractIconW( HINSTANCE hInstance, LPCWSTR lpszExeFileName,
308 UINT nIconIndex )
309 { LPSTR exefn;
310 HICON ret;
311 TRACE("\n");
313 exefn = HEAP_strdupWtoA(GetProcessHeap(),0,lpszExeFileName);
314 ret = ExtractIconA(hInstance,exefn,nIconIndex);
316 HeapFree(GetProcessHeap(),0,exefn);
317 return ret;
320 /*************************************************************************
321 * FindExecutableA [SHELL32.184]
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];
328 TRACE("File %s, Dir %s\n",
329 (lpFile != NULL?lpFile:"-"),
330 (lpDirectory != NULL?lpDirectory:"-"));
332 lpResult[0]='\0'; /* Start off with an empty return string */
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. */
340 if (lpDirectory)
341 { GetCurrentDirectoryA( sizeof(old_dir), old_dir );
342 SetCurrentDirectoryA( lpDirectory );
345 retval = SHELL_FindExecutable( lpFile, "open", lpResult );
347 TRACE("returning %s\n", lpResult);
348 if (lpDirectory)
349 SetCurrentDirectoryA( old_dir );
350 return retval;
353 /*************************************************************************
354 * FindExecutableW [SHELL32.219]
356 HINSTANCE WINAPI FindExecutableW(LPCWSTR lpFile, LPCWSTR lpDirectory,
357 LPWSTR lpResult)
359 FIXME("(%p,%p,%p): stub\n", lpFile, lpDirectory, lpResult);
360 return 31; /* default - 'No association was found' */
363 typedef struct
364 { LPCSTR szApp;
365 LPCSTR szOtherStuff;
366 HICON hIcon;
367 } ABOUT_INFO;
369 #define IDC_STATIC_TEXT 100
370 #define IDC_LISTBOX 99
371 #define IDC_WINE_TEXT 98
373 #define DROP_FIELD_TOP (-15)
374 #define DROP_FIELD_HEIGHT 15
376 extern HICON hIconTitleFont;
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;
386 return FALSE;
389 /*************************************************************************
390 * SHAppBarMessage32 [SHELL32.207]
392 UINT WINAPI SHAppBarMessage(DWORD msg, PAPPBARDATA data)
394 FIXME("(0x%08lx,%p hwnd=0x%08x): stub\n", msg, data, data->hWnd);
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;
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;
417 return 0;
420 /*************************************************************************
421 * SHHelpShortcuts_RunDLL [SHELL32.224]
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);
428 return 0;
431 /*************************************************************************
432 * SHLoadInProc [SHELL32.225]
436 DWORD WINAPI SHLoadInProc (DWORD dwArg1)
437 { FIXME("(%lx) empty stub!\n", dwArg1);
438 return 0;
441 /*************************************************************************
442 * ShellExecuteA [SHELL32.245]
444 HINSTANCE WINAPI ShellExecuteA( HWND hWnd, LPCSTR lpOperation,
445 LPCSTR lpFile, LPCSTR lpParameters,
446 LPCSTR lpDirectory, INT iShowCmd )
447 { TRACE("\n");
448 return ShellExecute16( hWnd, lpOperation, lpFile, lpParameters,
449 lpDirectory, iShowCmd );
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);
458 HINSTANCE WINAPI
459 ShellExecuteW(
460 HWND hwnd,
461 LPCWSTR lpOperation,
462 LPCWSTR lpFile,
463 LPCWSTR lpParameters,
464 LPCWSTR lpDirectory,
465 INT nShowCmd) {
467 FIXME(": stub\n");
468 return 0;
471 /*************************************************************************
472 * AboutDlgProc32 (internal)
474 BOOL WINAPI AboutDlgProc( HWND hWnd, UINT msg, WPARAM wParam,
475 LPARAM lParam )
476 { HWND hWndCtl;
477 char Template[512], AppTitle[512];
479 TRACE("\n");
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++;
499 SendMessageA( hWndCtl, WM_SETREDRAW, 1, 0 );
502 return 1;
504 case WM_PAINT:
505 { RECT rect;
506 PAINTSTRUCT ps;
507 HDC hDC = BeginPaint( hWnd, &ps );
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 );
514 EndPaint( hWnd, &ps );
516 break;
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 );
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 );
536 if( hMemObj )
537 GlobalFree16( hMemObj );
541 break;
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;
560 break;
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";
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 );
581 strcpy( Template, pstr );
582 strcat( Template, __appendix_str );
583 SetWindowTextA( hWndCtl, Template );
584 SetWindowLongA( hWnd, DWL_MSGRESULT, 1 );
585 return TRUE;
589 break;
591 case WM_COMMAND:
592 if (wParam == IDOK)
593 { EndDialog(hWnd, TRUE);
594 return TRUE;
596 break;
597 case WM_CLOSE:
598 EndDialog(hWnd, TRUE);
599 break;
602 return 0;
606 /*************************************************************************
607 * ShellAboutA [SHELL32.243]
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("\n");
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;
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 );
630 /*************************************************************************
631 * ShellAboutW [SHELL32.244]
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;
640 TRACE("\n");
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;
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;
658 /*************************************************************************
659 * FreeIconList
661 void WINAPI FreeIconList( DWORD dw )
662 { FIXME("(%lx): stub\n",dw);
665 /***********************************************************************
666 * DllGetVersion [COMCTL32.25]
668 * Retrieves version information of the 'SHELL32.DLL'
670 * PARAMS
671 * pdvi [O] pointer to version information structure.
673 * RETURNS
674 * Success: S_OK
675 * Failure: E_INVALIDARG
677 * NOTES
678 * Returns version of a shell32.dll from IE4.01 SP1.
681 HRESULT WINAPI SHELL32_DllGetVersion (DLLVERSIONINFO *pdvi)
683 if (pdvi->cbSize != sizeof(DLLVERSIONINFO))
684 { WARN("wrong DLLVERSIONINFO size from app");
685 return E_INVALIDARG;
688 pdvi->dwMajorVersion = 4;
689 pdvi->dwMinorVersion = 72;
690 pdvi->dwBuildNumber = 3110;
691 pdvi->dwPlatformID = 1;
693 TRACE("%lu.%lu.%lu.%lu\n",
694 pdvi->dwMajorVersion, pdvi->dwMinorVersion,
695 pdvi->dwBuildNumber, pdvi->dwPlatformID);
697 return S_OK;
699 /*************************************************************************
700 * global variables of the shell32.dll
701 * all are once per process
704 void (WINAPI* pDLLInitComctl)(LPVOID);
705 INT (WINAPI* pImageList_AddIcon) (HIMAGELIST himl, HICON hIcon);
706 INT (WINAPI* pImageList_ReplaceIcon) (HIMAGELIST, INT, HICON);
707 HIMAGELIST (WINAPI * pImageList_Create) (INT,INT,UINT,INT,INT);
708 BOOL (WINAPI* pImageList_Draw) (HIMAGELIST himl, int i, HDC hdcDest, int x, int y, UINT fStyle);
709 HICON (WINAPI * pImageList_GetIcon) (HIMAGELIST, INT, UINT);
710 INT (WINAPI* pImageList_GetImageCount)(HIMAGELIST);
711 COLORREF (WINAPI *pImageList_SetBkColor)(HIMAGELIST, COLORREF);
713 LPVOID (WINAPI* pCOMCTL32_Alloc) (INT);
714 BOOL (WINAPI* pCOMCTL32_Free) (LPVOID);
716 HDPA (WINAPI* pDPA_Create) (INT);
717 INT (WINAPI* pDPA_InsertPtr) (const HDPA, INT, LPVOID);
718 BOOL (WINAPI* pDPA_Sort) (const HDPA, PFNDPACOMPARE, LPARAM);
719 LPVOID (WINAPI* pDPA_GetPtr) (const HDPA, INT);
720 BOOL (WINAPI* pDPA_Destroy) (const HDPA);
721 INT (WINAPI *pDPA_Search) (const HDPA, LPVOID, INT, PFNDPACOMPARE, LPARAM, UINT);
722 LPVOID (WINAPI *pDPA_DeletePtr) (const HDPA hdpa, INT i);
724 /* user32 */
725 HICON (WINAPI *pLookupIconIdFromDirectoryEx)(LPBYTE dir, BOOL bIcon, INT width, INT height, UINT cFlag);
726 HICON (WINAPI *pCreateIconFromResourceEx)(LPBYTE bits,UINT cbSize, BOOL bIcon, DWORD dwVersion, INT width, INT height,UINT cFlag);
728 /* ole2 */
729 HRESULT (WINAPI* pOleInitialize)(LPVOID reserved);
730 void (WINAPI* pOleUninitialize)(void);
731 HRESULT (WINAPI* pDoDragDrop)(IDataObject* pDataObject, IDropSource * pDropSource, DWORD dwOKEffect, DWORD *pdwEffect);
732 HRESULT (WINAPI* pRegisterDragDrop)(HWND hwnd, IDropTarget* pDropTarget);
733 HRESULT (WINAPI* pRevokeDragDrop)(HWND hwnd);
735 static HINSTANCE hComctl32;
736 static HINSTANCE hOle32;
737 static INT shell32_RefCount = 0;
739 INT shell32_ObjCount = 0;
740 HINSTANCE shell32_hInstance;
741 HIMAGELIST ShellSmallIconList = 0;
742 HIMAGELIST ShellBigIconList = 0;
744 /*************************************************************************
745 * SHELL32 LibMain
747 * NOTES
748 * calling oleinitialize here breaks sone apps.
751 BOOL WINAPI Shell32LibMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
753 HMODULE hUser32;
755 TRACE("0x%x 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
757 switch (fdwReason)
759 case DLL_PROCESS_ATTACH:
760 shell32_RefCount++;
761 if (shell32_hInstance)
763 ERR("shell32.dll instantiated twice in one address space!\n");
765 else
767 /* we only want to call this the first time shell32 is instantiated */
768 SHInitRestricted(NULL, NULL);
771 shell32_hInstance = hinstDLL;
773 hComctl32 = LoadLibraryA("COMCTL32.DLL");
774 hOle32 = LoadLibraryA("OLE32.DLL");
775 hUser32 = GetModuleHandleA("USER32");
777 if (!hComctl32 || !hUser32 || !hOle32)
779 ERR("P A N I C SHELL32 loading failed\n");
780 return FALSE;
783 /* comctl32 */
784 pDLLInitComctl=(void*)GetProcAddress(hComctl32,"InitCommonControlsEx");
785 pImageList_Create=(void*)GetProcAddress(hComctl32,"ImageList_Create");
786 pImageList_AddIcon=(void*)GetProcAddress(hComctl32,"ImageList_AddIcon");
787 pImageList_ReplaceIcon=(void*)GetProcAddress(hComctl32,"ImageList_ReplaceIcon");
788 pImageList_GetIcon=(void*)GetProcAddress(hComctl32,"ImageList_GetIcon");
789 pImageList_GetImageCount=(void*)GetProcAddress(hComctl32,"ImageList_GetImageCount");
790 pImageList_Draw=(void*)GetProcAddress(hComctl32,"ImageList_Draw");
791 pImageList_SetBkColor=(void*)GetProcAddress(hComctl32,"ImageList_SetBkColor");
792 pCOMCTL32_Alloc=(void*)GetProcAddress(hComctl32, (LPCSTR)71L);
793 pCOMCTL32_Free=(void*)GetProcAddress(hComctl32, (LPCSTR)73L);
794 pDPA_Create=(void*)GetProcAddress(hComctl32, (LPCSTR)328L);
795 pDPA_Destroy=(void*)GetProcAddress(hComctl32, (LPCSTR)329L);
796 pDPA_GetPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)332L);
797 pDPA_InsertPtr=(void*)GetProcAddress(hComctl32, (LPCSTR)334L);
798 pDPA_DeletePtr=(void*)GetProcAddress(hComctl32, (LPCSTR)336L);
799 pDPA_Sort=(void*)GetProcAddress(hComctl32, (LPCSTR)338L);
800 pDPA_Search=(void*)GetProcAddress(hComctl32, (LPCSTR)339L);
801 /* user32 */
802 pLookupIconIdFromDirectoryEx=(void*)GetProcAddress(hUser32,"LookupIconIdFromDirectoryEx");
803 pCreateIconFromResourceEx=(void*)GetProcAddress(hUser32,"CreateIconFromResourceEx");
804 /* ole2 */
805 pOleInitialize=(void*)GetProcAddress(hOle32,"OleInitialize");
806 pOleUninitialize=(void*)GetProcAddress(hOle32,"OleUninitialize");
807 pDoDragDrop=(void*)GetProcAddress(hOle32,"DoDragDrop");
808 pRegisterDragDrop=(void*)GetProcAddress(hOle32,"RegisterDragDrop");
809 pRevokeDragDrop=(void*)GetProcAddress(hOle32,"RevokeDragDrop");
811 /* initialize the common controls */
812 if (pDLLInitComctl)
814 pDLLInitComctl(NULL);
817 SIC_Initialize();
818 SYSTRAY_Init();
820 break;
822 case DLL_THREAD_ATTACH:
823 shell32_RefCount++;
824 break;
826 case DLL_THREAD_DETACH:
827 shell32_RefCount--;
828 break;
830 case DLL_PROCESS_DETACH:
831 shell32_RefCount--;
833 if ( !shell32_RefCount )
835 shell32_hInstance = 0;
837 if (pdesktopfolder)
839 IShellFolder_Release(pdesktopfolder);
840 pdesktopfolder = NULL;
843 SIC_Destroy();
845 /* this one is here to check if AddRef/Release is balanced */
846 if (shell32_ObjCount)
848 WARN("leaving with %u objects left (memory leak)\n", shell32_ObjCount);
852 FreeLibrary(hOle32);
853 FreeLibrary(hComctl32);
855 TRACE("refcount=%u objcount=%u \n", shell32_RefCount, shell32_ObjCount);
856 break;
858 return TRUE;
861 /*************************************************************************
862 * DllInstall [SHELL32.202]
864 * PARAMETERS
866 * BOOL bInstall - TRUE for install, FALSE for uninstall
867 * LPCWSTR pszCmdLine - command line (unused by shell32?)
870 HRESULT WINAPI DllInstall(BOOL bInstall, LPCWSTR cmdline)
872 FIXME("(%s, %s): stub!\n", bInstall ? "TRUE":"FALSE", debugstr_w(cmdline));
874 return S_OK; /* indicate success */