ReactOS 0.4.15-dev-7906-g1b85a5f
batt.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS system libraries
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll\win32\batt\batt.c
5 * PURPOSE: Battery Class installers
6 * PROGRAMMERS: Copyright 2010 Eric Kohl
7 */
8
9
10#define WIN32_NO_STATUS
11#include <stdarg.h>
12#include <windef.h>
13#include <winbase.h>
14#include <winreg.h>
15#include <winuser.h>
16#include <setupapi.h>
17
18#include <initguid.h>
19#include <devguid.h>
20
21#define NDEBUG
22#include <debug.h>
23
24static
30{
31 WCHAR szDeviceId[32];
32 SP_DRVINFO_DATA DriverInfoData;
33 HDEVINFO NewDeviceInfoSet = INVALID_HANDLE_VALUE;
34 PSP_DEVINFO_DATA NewDeviceInfoData = NULL;
35 BOOL bDeviceRegistered = FALSE, bHaveDriverInfoList = FALSE;
36 DWORD dwError = ERROR_SUCCESS;
37
38 DPRINT("InstallCompositeBattery(%p %p %p)\n",
40
41 NewDeviceInfoSet = SetupDiCreateDeviceInfoList(&GUID_DEVCLASS_SYSTEM,
42 DeviceInstallParams->hwndParent);
43 if (NewDeviceInfoSet == INVALID_HANDLE_VALUE)
44 {
45 DPRINT1("SetupDiCreateDeviceInfoList() failed (Error %lu)\n", GetLastError());
46 return GetLastError();
47 }
48
49 NewDeviceInfoData = HeapAlloc(GetProcessHeap(),
51 sizeof(SP_DEVINFO_DATA));
52 if (NewDeviceInfoData == NULL)
53 {
54 dwError = ERROR_OUTOFMEMORY;
55 goto done;
56 }
57
58 NewDeviceInfoData->cbSize = sizeof(SP_DEVINFO_DATA);
59 if (!SetupDiCreateDeviceInfoW(NewDeviceInfoSet,
60 L"Root\\COMPOSITE_BATTERY\\0000",
61 &GUID_DEVCLASS_SYSTEM,
62 NULL,
63 DeviceInstallParams->hwndParent,
64 0,
65 NewDeviceInfoData))
66 {
67 dwError = GetLastError();
68 if (dwError == ERROR_DEVINST_ALREADY_EXISTS)
69 {
70 dwError = ERROR_SUCCESS;
71 goto done;
72 }
73
74 DPRINT1("SetupDiCreateDeviceInfoW() failed (Error %lu 0x%08lx)\n", dwError, dwError);
75 goto done;
76 }
77
78 if (!SetupDiRegisterDeviceInfo(NewDeviceInfoSet,
79 NewDeviceInfoData,
80 0,
81 NULL,
82 NULL,
83 NULL))
84 {
85 dwError = GetLastError();
86 DPRINT1("SetupDiRegisterDeviceInfo() failed (Error %lu 0x%08lx)\n", dwError, dwError);
87 goto done;
88 }
89
90 bDeviceRegistered = TRUE;
91
93 wcscpy(szDeviceId, L"COMPOSITE_BATTERY");
94
95 if (!SetupDiSetDeviceRegistryPropertyW(NewDeviceInfoSet,
96 NewDeviceInfoData,
99 (wcslen(szDeviceId) + 2) * sizeof(WCHAR)))
100 {
101 dwError = GetLastError();
102 DPRINT1("SetupDiSetDeviceRegistryPropertyW() failed (Error %lu 0x%08lx)\n", dwError, dwError);
103 goto done;
104 }
105
106 if (!SetupDiBuildDriverInfoList(NewDeviceInfoSet,
107 NewDeviceInfoData,
109 {
110 dwError = GetLastError();
111 DPRINT1("SetupDiBuildDriverInfoList() failed (Error %lu 0x%08lx)\n", dwError, dwError);
112 goto done;
113 }
114
115 bHaveDriverInfoList = TRUE;
116
117 DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
118 if (!SetupDiEnumDriverInfo(NewDeviceInfoSet,
119 NewDeviceInfoData,
121 0,
122 &DriverInfoData))
123 {
124 dwError = GetLastError();
125 DPRINT1("SetupDiEnumDriverInfo() failed (Error %lu 0x%08lx)\n", dwError, dwError);
126 goto done;
127 }
128
129 if (!SetupDiSetSelectedDriver(NewDeviceInfoSet,
130 NewDeviceInfoData,
131 &DriverInfoData))
132 {
133 dwError = GetLastError();
134 DPRINT1("SetupDiSetSelectedDriver() failed (Error %lu 0x%08lx)\n", dwError, dwError);
135 goto done;
136 }
137
138 if (!SetupDiInstallDevice(NewDeviceInfoSet,
139 NewDeviceInfoData))
140 {
141 dwError = GetLastError();
142 DPRINT1("SetupDiInstallDevice() failed (Error %lu 0x%08lx)\n", dwError, dwError);
143 goto done;
144 }
145
146 dwError = ERROR_SUCCESS;
147
148done:
149 if (bHaveDriverInfoList)
150 SetupDiDestroyDriverInfoList(NewDeviceInfoSet,
151 NewDeviceInfoData,
153
154 if (bDeviceRegistered)
155 SetupDiDeleteDeviceInfo(NewDeviceInfoSet,
156 NewDeviceInfoData);
157
158 if (NewDeviceInfoData != NULL)
159 HeapFree(GetProcessHeap(), 0, NewDeviceInfoData);
160
161 if (NewDeviceInfoSet != INVALID_HANDLE_VALUE)
162 SetupDiDestroyDeviceInfoList(NewDeviceInfoSet);
163
164 return dwError;
165}
166
167
168DWORD
169WINAPI
171 _In_ DI_FUNCTION InstallFunction,
174{
176 DWORD dwError;
177
178 DPRINT("BatteryClassInstall(%u %p %p)\n",
179 InstallFunction, DeviceInfoSet, DeviceInfoData);
180
181 if (InstallFunction != DIF_INSTALLDEVICE)
182 return ERROR_DI_DO_DEFAULT;
183
188 {
189 DPRINT1("SetupDiGetDeviceInstallParamsW() failed (Error %lu)\n", GetLastError());
190 return GetLastError();
191 }
192
193 /* Install the composite battery device */
197 if (dwError == ERROR_SUCCESS)
198 {
199 /* Install the battery device */
200 dwError = ERROR_DI_DO_DEFAULT;
201 }
202
203 return dwError;
204}
205
206
207DWORD
208WINAPI
213{
214 switch (InstallFunction)
215 {
216 default:
217 DPRINT("Install function %u ignored\n", InstallFunction);
218 return ERROR_DI_DO_DEFAULT;
219 }
220}
221
222
223BOOL
224WINAPI
226 _In_ HINSTANCE hinstDll,
229{
230 switch (dwReason)
231 {
234 break;
235
237 break;
238 }
239
240 return TRUE;
241}
242
243/* EOF */
#define DPRINT1
Definition: precomp.h:8
DWORD dwReason
Definition: misc.cpp:154
DWORD WINAPI BatteryClassInstall(_In_ DI_FUNCTION InstallFunction, _In_ HDEVINFO DeviceInfoSet, _In_opt_ PSP_DEVINFO_DATA DeviceInfoData)
Definition: batt.c:170
static DWORD InstallCompositeBattery(_In_ HDEVINFO DeviceInfoSet, _In_opt_ PSP_DEVINFO_DATA DeviceInfoData, _In_ PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
Definition: batt.c:26
DWORD WINAPI BatteryClassCoInstaller(IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN OUT PCOINSTALLER_CONTEXT_DATA Context)
Definition: batt.c:209
BOOL WINAPI DllMain(_In_ HINSTANCE hinstDll, _In_ DWORD dwReason, _In_ LPVOID reserved)
Definition: batt.c:225
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR szDeviceId[]
Definition: provider.c:60
#define GetProcessHeap()
Definition: compat.h:736
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
BOOL WINAPI SetupDiGetDeviceInstallParamsW(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
Definition: devinst.c:4451
BOOL WINAPI SetupDiRegisterDeviceInfo(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Flags, PSP_DETSIG_CMPPROC CompareProc, PVOID CompareContext, PSP_DEVINFO_DATA DupDeviceInfoData)
Definition: devinst.c:1711
BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO DeviceInfoSet, PCWSTR DeviceName, CONST GUID *ClassGuid, PCWSTR DeviceDescription, HWND hwndParent, DWORD CreationFlags, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:1570
BOOL WINAPI SetupDiDeleteDeviceInfo(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:4712
BOOL WINAPI SetupDiInstallDevice(IN HDEVINFO DeviceInfoSet, IN OUT PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:5365
BOOL WINAPI SetupDiSetDeviceRegistryPropertyW(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Property, const BYTE *PropertyBuffer, DWORD PropertyBufferSize)
Definition: devinst.c:3452
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2893
HDEVINFO WINAPI SetupDiCreateDeviceInfoList(const GUID *ClassGuid, HWND hwndParent)
Definition: devinst.c:1205
BOOL WINAPI SetupDiBuildDriverInfoList(IN HDEVINFO DeviceInfoSet, IN OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN DWORD DriverType)
Definition: driver.c:718
BOOL WINAPI SetupDiDestroyDriverInfoList(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN DWORD DriverType)
Definition: driver.c:1208
r reserved
Definition: btrfs.c:3006
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define _In_
Definition: ms_sal.h:308
#define _In_opt_
Definition: ms_sal.h:309
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define ERROR_DEVINST_ALREADY_EXISTS
Definition: setupapi.h:303
SP_DRVINFO_DATA_V2 SP_DRVINFO_DATA
Definition: setupapi.h:1054
_In_opt_ PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1528
#define ERROR_DI_DO_DEFAULT
Definition: setupapi.h:310
#define SetupDiSetSelectedDriver
Definition: setupapi.h:2622
UINT DI_FUNCTION
Definition: setupapi.h:672
#define DIF_INSTALLDEVICE
Definition: setupapi.h:121
#define SetupDiEnumDriverInfo
Definition: setupapi.h:2587
struct _SP_DEVINFO_DATA SP_DEVINFO_DATA
#define SPDRP_HARDWAREID
Definition: setupapi.h:508
#define SPDIT_COMPATDRIVER
Definition: setupapi.h:506
#define DPRINT
Definition: sndvol32.h:71
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define IN
Definition: typedefs.h:39
#define OUT
Definition: typedefs.h:40
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180