[CLASS2]
[reactos.git] / reactos / base / applications / msconfig_new / comctl32ex / comctl32supp.c
1 /*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/msconfig_new/comctl32ex/comctl32supp.c
5 * PURPOSE: Common Controls helper functions.
6 * COPYRIGHT: Copyright 2011-2012 Hermes BELUSCA - MAITO <hermes.belusca@sfr.fr>
7 */
8
9 #include "precomp.h"
10
11 HRESULT GetComCtl32Version(OUT PDWORD pdwMajor, OUT PDWORD pdwMinor, OUT PDWORD pdwBuild)
12 {
13 HRESULT hr = S_OK;
14 HINSTANCE hDll;
15 DLLGETVERSIONPROC pDllGetVersion;
16 DLLVERSIONINFO dvi;
17
18 *pdwMajor = 0;
19 *pdwMinor = 0;
20 *pdwBuild = 0;
21
22 /*
23 * WARNING! DISCLAIMER!
24 *
25 * This method of retrieving a handle to an already loaded comctl32.dll
26 * is known to not be reliable in case the program is using SxS, or if
27 * this code is used from inside a DLL.
28 */
29
30 /*
31 * See: https://msdn.microsoft.com/en-us/library/windows/desktop/hh298349(v=vs.85).aspx
32 * and: http://www.geoffchappell.com/studies/windows/shell/comctl32/history/
33 * for the possible version values to be returned.
34 */
35
36 /* Get a handle to comctl32.dll that must already be loaded */
37 hDll = GetModuleHandleW(L"comctl32.dll"); // NOTE: We must not call FreeLibrary on the returned handle!
38 if (!hDll) return E_FAIL;
39
40 pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hDll, "DllGetVersion");
41 if (pDllGetVersion)
42 {
43 ZeroMemory(&dvi, sizeof(dvi));
44 dvi.cbSize = sizeof(dvi);
45
46 hr = (*pDllGetVersion)(&dvi);
47 if (SUCCEEDED(hr))
48 {
49 *pdwMajor = dvi.dwMajorVersion;
50 *pdwMinor = dvi.dwMinorVersion;
51 *pdwBuild = dvi.dwBuildNumber;
52
53 #if 0
54 // #include "stringutils.h"
55
56 LPWSTR strVersion =
57 FormatString(L"ComCtl32 version %d.%d, Build %d, Platform %d",
58 dvi.dwMajorVersion, dvi.dwMinorVersion, dvi.dwBuildNumber, dvi.dwPlatformID);
59 MessageBoxW(NULL, strVersion, L"ComCtl32 version", MB_OK);
60 MemFree(strVersion);
61 #endif
62 }
63 }
64 else
65 {
66 /*
67 * If GetProcAddress failed, the DLL is a version
68 * previous to the one shipped with IE 3.x.
69 */
70 *pdwMajor = 4;
71 *pdwMinor = 0;
72 *pdwBuild = 0;
73 }
74
75 return hr;
76 }