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
10 #define WIN32_NO_STATUS
26 InstallCompositeBattery(
27 _In_ HDEVINFO DeviceInfoSet
,
28 _In_opt_ PSP_DEVINFO_DATA DeviceInfoData
,
29 _In_ PSP_DEVINSTALL_PARAMS_W DeviceInstallParams
)
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
;
38 DPRINT("InstallCompositeBattery(%p %p %p)\n",
39 DeviceInfoSet
, DeviceInfoData
, DeviceInstallParams
);
41 NewDeviceInfoSet
= SetupDiCreateDeviceInfoList(&GUID_DEVCLASS_SYSTEM
,
42 DeviceInstallParams
->hwndParent
);
43 if (NewDeviceInfoSet
== INVALID_HANDLE_VALUE
)
45 DPRINT1("SetupDiCreateDeviceInfoList() failed (Error %lu)\n", GetLastError());
46 return GetLastError();
49 NewDeviceInfoData
= HeapAlloc(GetProcessHeap(),
51 sizeof(SP_DEVINFO_DATA
));
52 if (NewDeviceInfoData
== NULL
)
54 dwError
= ERROR_OUTOFMEMORY
;
58 NewDeviceInfoData
->cbSize
= sizeof(SP_DEVINFO_DATA
);
59 if (!SetupDiCreateDeviceInfoW(NewDeviceInfoSet
,
60 L
"Root\\COMPOSITE_BATTERY\\0000",
61 &GUID_DEVCLASS_SYSTEM
,
63 DeviceInstallParams
->hwndParent
,
67 dwError
= GetLastError();
68 if (dwError
== ERROR_DEVINST_ALREADY_EXISTS
)
70 dwError
= ERROR_SUCCESS
;
74 DPRINT1("SetupDiCreateDeviceInfoW() failed (Error %lu 0x%08lx)\n", dwError
, dwError
);
78 if (!SetupDiRegisterDeviceInfo(NewDeviceInfoSet
,
85 dwError
= GetLastError();
86 DPRINT1("SetupDiRegisterDeviceInfo() failed (Error %lu 0x%08lx)\n", dwError
, dwError
);
90 bDeviceRegistered
= TRUE
;
92 ZeroMemory(szDeviceId
, sizeof(szDeviceId
));
93 wcscpy(szDeviceId
, L
"COMPOSITE_BATTERY");
95 if (!SetupDiSetDeviceRegistryPropertyW(NewDeviceInfoSet
,
99 (wcslen(szDeviceId
) + 2) * sizeof(WCHAR
)))
101 dwError
= GetLastError();
102 DPRINT1("SetupDiSetDeviceRegistryPropertyW() failed (Error %lu 0x%08lx)\n", dwError
, dwError
);
106 if (!SetupDiBuildDriverInfoList(NewDeviceInfoSet
,
110 dwError
= GetLastError();
111 DPRINT1("SetupDiBuildDriverInfoList() failed (Error %lu 0x%08lx)\n", dwError
, dwError
);
115 bHaveDriverInfoList
= TRUE
;
117 DriverInfoData
.cbSize
= sizeof(SP_DRVINFO_DATA
);
118 if (!SetupDiEnumDriverInfo(NewDeviceInfoSet
,
124 dwError
= GetLastError();
125 DPRINT1("SetupDiEnumDriverInfo() failed (Error %lu 0x%08lx)\n", dwError
, dwError
);
129 if (!SetupDiSetSelectedDriver(NewDeviceInfoSet
,
133 dwError
= GetLastError();
134 DPRINT1("SetupDiSetSelectedDriver() failed (Error %lu 0x%08lx)\n", dwError
, dwError
);
138 if (!SetupDiInstallDevice(NewDeviceInfoSet
,
141 dwError
= GetLastError();
142 DPRINT1("SetupDiInstallDevice() failed (Error %lu 0x%08lx)\n", dwError
, dwError
);
146 dwError
= ERROR_SUCCESS
;
149 if (bHaveDriverInfoList
)
150 SetupDiDestroyDriverInfoList(NewDeviceInfoSet
,
154 if (bDeviceRegistered
)
155 SetupDiDeleteDeviceInfo(NewDeviceInfoSet
,
158 if (NewDeviceInfoData
!= NULL
)
159 HeapFree(GetProcessHeap(), 0, NewDeviceInfoData
);
161 if (NewDeviceInfoSet
!= INVALID_HANDLE_VALUE
)
162 SetupDiDestroyDeviceInfoList(NewDeviceInfoSet
);
171 _In_ DI_FUNCTION InstallFunction
,
172 _In_ HDEVINFO DeviceInfoSet
,
173 _In_opt_ PSP_DEVINFO_DATA DeviceInfoData
)
175 SP_DEVINSTALL_PARAMS_W DeviceInstallParams
;
178 DPRINT("BatteryClassInstall(%u %p %p)\n",
179 InstallFunction
, DeviceInfoSet
, DeviceInfoData
);
181 if (InstallFunction
!= DIF_INSTALLDEVICE
)
182 return ERROR_DI_DO_DEFAULT
;
184 DeviceInstallParams
.cbSize
= sizeof(DeviceInstallParams
);
185 if (!SetupDiGetDeviceInstallParamsW(DeviceInfoSet
,
187 &DeviceInstallParams
))
189 DPRINT1("SetupDiGetDeviceInstallParamsW() failed (Error %lu)\n", GetLastError());
190 return GetLastError();
193 /* Install the composite battery device */
194 dwError
= InstallCompositeBattery(DeviceInfoSet
,
196 &DeviceInstallParams
);
197 if (dwError
== ERROR_SUCCESS
)
199 /* Install the battery device */
200 dwError
= ERROR_DI_DO_DEFAULT
;
209 BatteryClassCoInstaller(IN DI_FUNCTION InstallFunction
,
210 IN HDEVINFO DeviceInfoSet
,
211 IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
,
212 IN OUT PCOINSTALLER_CONTEXT_DATA Context
)
214 switch (InstallFunction
)
217 DPRINT("Install function %u ignored\n", InstallFunction
);
218 return ERROR_DI_DO_DEFAULT
;
226 _In_ HINSTANCE hinstDll
,
228 _In_ LPVOID reserved
)
232 case DLL_PROCESS_ATTACH
:
233 DisableThreadLibraryCalls(hinstDll
);
236 case DLL_PROCESS_DETACH
: