5d68bb719714dde5db1d7207b3a7b7ea22677b57
[reactos.git] / reactos / lib / shlwapi / shlwapi_main.c
1 /*
2 * SHLWAPI initialisation
3 *
4 * Copyright 1998 Marcus Meissner
5 * Copyright 1998 Juergen Schmied (jsch)
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "wine/debug.h"
28 #define NO_SHLWAPI_REG
29 #define NO_SHLWAPI_STREAM
30 #include "shlwapi.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(shell);
33
34 HINSTANCE shlwapi_hInstance = 0;
35 HMODULE SHLWAPI_hshell32 = 0;
36 HMODULE SHLWAPI_hwinmm = 0;
37 HMODULE SHLWAPI_hcomdlg32 = 0;
38 HMODULE SHLWAPI_hcomctl32 = 0;
39 HMODULE SHLWAPI_hmpr = 0;
40 HMODULE SHLWAPI_hmlang = 0;
41 HMODULE SHLWAPI_hurlmon = 0;
42 HMODULE SHLWAPI_hversion = 0;
43
44 DWORD SHLWAPI_ThreadRef_index = TLS_OUT_OF_INDEXES;
45
46 /*************************************************************************
47 * SHLWAPI {SHLWAPI}
48 *
49 * The Shell Light-Weight Api dll provides a large number of utility functions
50 * which are commonly required by Win32 programs. Originally distributed with
51 * Internet Explorer as a free download, it became a core part of Windows when
52 * Internet Explorer was 'integrated' into the O/S with the release of Win98.
53 *
54 * All functions exported by ordinal are undocumented by MS. The vast majority
55 * of these are wrappers for Unicode functions that may not exist on early 16
56 * bit platforms. The remainder perform various small tasks and presumably were
57 * added to facilitate code reuse amongst the MS developers.
58 */
59
60 /*************************************************************************
61 * SHLWAPI DllMain
62 *
63 * NOTES
64 * calling oleinitialize here breaks sone apps.
65 */
66 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
67 {
68 TRACE("%p 0x%lx %p\n", hinstDLL, fdwReason, fImpLoad);
69 switch (fdwReason)
70 {
71 case DLL_PROCESS_ATTACH:
72 DisableThreadLibraryCalls(hinstDLL);
73 shlwapi_hInstance = hinstDLL;
74 SHLWAPI_ThreadRef_index = TlsAlloc();
75 break;
76 case DLL_PROCESS_DETACH:
77 if (SHLWAPI_hshell32) FreeLibrary(SHLWAPI_hshell32);
78 if (SHLWAPI_hwinmm) FreeLibrary(SHLWAPI_hwinmm);
79 if (SHLWAPI_hcomdlg32) FreeLibrary(SHLWAPI_hcomdlg32);
80 if (SHLWAPI_hcomctl32) FreeLibrary(SHLWAPI_hcomctl32);
81 if (SHLWAPI_hmpr) FreeLibrary(SHLWAPI_hmpr);
82 if (SHLWAPI_hmlang) FreeLibrary(SHLWAPI_hmlang);
83 if (SHLWAPI_hurlmon) FreeLibrary(SHLWAPI_hurlmon);
84 if (SHLWAPI_hversion) FreeLibrary(SHLWAPI_hversion);
85 if (SHLWAPI_ThreadRef_index != TLS_OUT_OF_INDEXES) TlsFree(SHLWAPI_ThreadRef_index);
86 break;
87 }
88 return TRUE;
89 }
90
91 /***********************************************************************
92 * DllGetVersion [SHLWAPI.@]
93 *
94 * Retrieve "shlwapi.dll" version information.
95 *
96 * PARAMS
97 * pdvi [O] pointer to version information structure.
98 *
99 * RETURNS
100 * Success: S_OK. pdvi is updated with the version information
101 * Failure: E_INVALIDARG, if pdvi->cbSize is not set correctly.
102 *
103 * NOTES
104 * You may pass either a DLLVERSIONINFO of DLLVERSIONINFO2 structure
105 * as pdvi, provided that the size is set correctly.
106 * Returns version as shlwapi.dll from IE5.01.
107 */
108 HRESULT WINAPI SHLWAPI_DllGetVersion (DLLVERSIONINFO *pdvi)
109 {
110 DLLVERSIONINFO2 *pdvi2 = (DLLVERSIONINFO2*)pdvi;
111
112 TRACE("(%p)\n",pdvi);
113
114 switch (pdvi2->info1.cbSize)
115 {
116 case sizeof(DLLVERSIONINFO2):
117 pdvi2->dwFlags = 0;
118 pdvi2->ullVersion = MAKEDLLVERULL(5, 0, 2314, 0);
119 /* Fall through */
120 case sizeof(DLLVERSIONINFO):
121 pdvi2->info1.dwMajorVersion = 5;
122 pdvi2->info1.dwMinorVersion = 0;
123 pdvi2->info1.dwBuildNumber = 2314;
124 pdvi2->info1.dwPlatformID = 1000;
125 return S_OK;
126 }
127 if (pdvi)
128 WARN("pdvi->cbSize = %ld, unhandled\n", pdvi2->info1.cbSize);
129 return E_INVALIDARG;
130 }