ReactOS 0.4.15-dev-7924-g5949c20
batt.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winreg.h>
#include <winuser.h>
#include <setupapi.h>
#include <initguid.h>
#include <devguid.h>
#include <debug.h>
Include dependency graph for batt.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define NDEBUG
 

Functions

static DWORD InstallCompositeBattery (_In_ HDEVINFO DeviceInfoSet, _In_opt_ PSP_DEVINFO_DATA DeviceInfoData, _In_ PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
 
DWORD WINAPI BatteryClassInstall (_In_ DI_FUNCTION InstallFunction, _In_ HDEVINFO DeviceInfoSet, _In_opt_ PSP_DEVINFO_DATA DeviceInfoData)
 
DWORD WINAPI BatteryClassCoInstaller (IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, IN OUT PCOINSTALLER_CONTEXT_DATA Context)
 
BOOL WINAPI DllMain (_In_ HINSTANCE hinstDll, _In_ DWORD dwReason, _In_ LPVOID reserved)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 21 of file batt.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file batt.c.

Function Documentation

◆ BatteryClassCoInstaller()

DWORD WINAPI BatteryClassCoInstaller ( IN DI_FUNCTION  InstallFunction,
IN HDEVINFO  DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData  OPTIONAL,
IN OUT PCOINSTALLER_CONTEXT_DATA  Context 
)

Definition at line 209 of file batt.c.

213{
214 switch (InstallFunction)
215 {
216 default:
217 DPRINT("Install function %u ignored\n", InstallFunction);
218 return ERROR_DI_DO_DEFAULT;
219 }
220}
#define ERROR_DI_DO_DEFAULT
Definition: setupapi.h:310
#define DPRINT
Definition: sndvol32.h:71

◆ BatteryClassInstall()

DWORD WINAPI BatteryClassInstall ( _In_ DI_FUNCTION  InstallFunction,
_In_ HDEVINFO  DeviceInfoSet,
_In_opt_ PSP_DEVINFO_DATA  DeviceInfoData 
)

Definition at line 170 of file batt.c.

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}
#define DPRINT1
Definition: precomp.h:8
static DWORD InstallCompositeBattery(_In_ HDEVINFO DeviceInfoSet, _In_opt_ PSP_DEVINFO_DATA DeviceInfoData, _In_ PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
Definition: batt.c:26
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI SetupDiGetDeviceInstallParamsW(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL, OUT PSP_DEVINSTALL_PARAMS_W DeviceInstallParams)
Definition: devinst.c:4451
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_opt_ PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1528
#define DIF_INSTALLDEVICE
Definition: setupapi.h:121
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

◆ DllMain()

BOOL WINAPI DllMain ( _In_ HINSTANCE  hinstDll,
_In_ DWORD  dwReason,
_In_ LPVOID  reserved 
)

Definition at line 225 of file batt.c.

229{
230 switch (dwReason)
231 {
234 break;
235
237 break;
238 }
239
240 return TRUE;
241}
DWORD dwReason
Definition: misc.cpp:154
#define TRUE
Definition: types.h:120
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85

◆ InstallCompositeBattery()

static DWORD InstallCompositeBattery ( _In_ HDEVINFO  DeviceInfoSet,
_In_opt_ PSP_DEVINFO_DATA  DeviceInfoData,
_In_ PSP_DEVINSTALL_PARAMS_W  DeviceInstallParams 
)
static

Definition at line 26 of file batt.c.

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}
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
static const WCHAR szDeviceId[]
Definition: provider.c:60
#define GetProcessHeap()
Definition: compat.h:736
#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 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
unsigned int BOOL
Definition: ntddk_ex.h:94
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#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
#define SetupDiSetSelectedDriver
Definition: setupapi.h:2622
#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 ZeroMemory
Definition: winbase.h:1712
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by BatteryClassInstall().