ReactOS  0.4.15-dev-448-gd6c4411
classinst.c File Reference
#include "desk.h"
#include <debug.h>
Include dependency graph for classinst.c:

Go to the source code of this file.

Functions

DWORD WINAPI DisplayClassInstaller (IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
 
DWORD WINAPI MonitorClassInstaller (IN DI_FUNCTION InstallFunction, IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
 

Function Documentation

◆ DisplayClassInstaller()

DWORD WINAPI DisplayClassInstaller ( IN DI_FUNCTION  InstallFunction,
IN HDEVINFO  DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData  OPTIONAL 
)

Definition at line 16 of file classinst.c.

20 {
21  SP_DEVINSTALL_PARAMS InstallParams;
22  SP_DRVINFO_DATA DriverInfoData;
24  TCHAR SectionName[MAX_PATH];
26  TCHAR DeviceName[12];
27  SP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
28  HKEY hDriverKey = INVALID_HANDLE_VALUE; /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
29  HKEY hSettingsKey = NULL;
31  HKEY hServiceKey = NULL;
32  HKEY hDeviceSubKey = NULL;
33  DWORD disposition, cchMax, cbData;
34  WORD wIndex;
35  BOOL result;
36  LONG rc;
37  HRESULT hr;
38 
39  if (InstallFunction != DIF_INSTALLDEVICE)
40  return ERROR_DI_DO_DEFAULT;
41 
42  /* Set DI_DONOTCALLCONFIGMG flag */
43  InstallParams.cbSize = sizeof(InstallParams);
45  if (!result)
46  {
47  rc = GetLastError();
48  DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc);
49  goto cleanup;
50  }
51 
52  InstallParams.Flags |= DI_DONOTCALLCONFIGMG;
53 
55  if (!result)
56  {
57  rc = GetLastError();
58  DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc);
59  goto cleanup;
60  }
61 
62  /* Do normal install */
64  if (!result)
65  {
66  rc = GetLastError();
67  DPRINT("SetupDiInstallDevice() failed with error 0x%lx\n", rc);
68  goto cleanup;
69  }
70 
71  /* Get .inf file name and section name */
72  DriverInfoData.cbSize = sizeof(DriverInfoData);
74  if (!result)
75  {
76  rc = GetLastError();
77  DPRINT("SetupDiGetSelectedDriver() failed with error 0x%lx\n", rc);
78  goto cleanup;
79  }
80 
81  DriverInfoDetailData.cbSize = sizeof(DriverInfoDetailData);
83  &DriverInfoData, &DriverInfoDetailData,
84  sizeof(DriverInfoDetailData), NULL);
86  {
87  rc = GetLastError();
88  DPRINT("SetupDiGetDriverInfoDetail() failed with error 0x%lx\n", rc);
89  goto cleanup;
90  }
91 
92  hInf = SetupOpenInfFile(DriverInfoDetailData.InfFileName, NULL, INF_STYLE_WIN4, NULL);
93  if (hInf == INVALID_HANDLE_VALUE)
94  {
95  rc = GetLastError();
96  DPRINT("SetupOpenInfFile() failed with error 0x%lx\n", rc);
97  goto cleanup;
98  }
99 
100  cchMax = MAX_PATH - (sizeof(_T(".SoftwareSettings")) / sizeof(TCHAR));
102  DriverInfoDetailData.SectionName,
103  SectionName,
104  cchMax,
105  NULL,
106  NULL);
107  if (!result)
108  {
109  rc = GetLastError();
110  DPRINT("SetupDiGetActualSectionToInstall() failed with error 0x%lx\n", rc);
111  goto cleanup;
112  }
113  hr = StringCbCat(SectionName, sizeof(SectionName), _T(".SoftwareSettings"));
114  if (FAILED(hr))
115  {
117  goto cleanup;
118  }
119 
120  /* Open driver registry key and create Settings subkey */
121  hDriverKey = SetupDiOpenDevRegKey(
125  if (hDriverKey == INVALID_HANDLE_VALUE)
126  {
127  rc = GetLastError();
128  DPRINT("SetupDiOpenDevRegKey() failed with error 0x%lx\n", rc);
129  goto cleanup;
130  }
131  rc = RegCreateKeyEx(
132  hDriverKey, L"Settings",
134 #if _WIN32_WINNT >= 0x502
136 #else
138 #endif
139  NULL, &hSettingsKey, &disposition);
140  if (rc != ERROR_SUCCESS)
141  {
142  DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc);
143  goto cleanup;
144  }
145 
146  /* Install .SoftwareSettings to Settings subkey */
148  InstallParams.hwndParent, hInf, SectionName,
149  SPINST_REGISTRY, hSettingsKey,
150  NULL, 0, NULL, NULL,
151  NULL, NULL);
152  if (!result)
153  {
154  rc = GetLastError();
155  DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc);
156  goto cleanup;
157  }
158 
159  /* Get service name and open service registry key */
164  if (!result)
165  {
166  rc = GetLastError();
167  DPRINT("SetupDiGetDeviceRegistryProperty() failed with error 0x%lx\n", rc);
168  goto cleanup;
169  }
170 
171  rc = RegOpenKeyEx(
172  HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services"),
174  if (rc != ERROR_SUCCESS)
175  {
176  DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc);
177  goto cleanup;
178  }
179  rc = RegOpenKeyEx(
181  0, KEY_CREATE_SUB_KEY, &hServiceKey);
182  if (rc != ERROR_SUCCESS)
183  {
184  DPRINT("RegOpenKeyEx() failed with error 0x%lx\n", rc);
185  goto cleanup;
186  }
187 
188  /* Create a new DeviceX subkey */
189  for (wIndex = 0; wIndex < 9999; wIndex++)
190  {
191  _stprintf(DeviceName, _T("Device%hu"), wIndex);
192 
193  rc = RegCreateKeyEx(
194  hServiceKey, DeviceName, 0, NULL,
196  &hDeviceSubKey, &disposition);
197  if (rc != ERROR_SUCCESS)
198  {
199  DPRINT("RegCreateKeyEx() failed with error 0x%lx\n", rc);
200  goto cleanup;
201  }
202 
203  if (disposition == REG_CREATED_NEW_KEY)
204  break;
205 
206  if (wIndex == 9999)
207  {
208  rc = ERROR_GEN_FAILURE;
209  DPRINT("RegCreateKeyEx() failed\n");
210  goto cleanup;
211  }
212 
213  RegCloseKey(hDeviceSubKey);
214  hDeviceSubKey = NULL;
215  }
216 
217  /* Install SoftwareSettings section */
218  /* Yes, we're installing this section for the second time.
219  * We don't want to create a link to Settings subkey */
221  InstallParams.hwndParent, hInf, SectionName,
222  SPINST_REGISTRY, hDeviceSubKey,
223  NULL, 0, NULL, NULL,
224  NULL, NULL);
225  if (!result)
226  {
227  rc = GetLastError();
228  DPRINT("SetupInstallFromInfSection() failed with error 0x%lx\n", rc);
229  goto cleanup;
230  }
231 
232  /* Add Device Description string */
233  cbData = (DWORD)(_tcslen(DriverInfoData.Description) + 1) * sizeof(TCHAR);
234  rc = RegSetValueEx(hDeviceSubKey,
235  _T("Device Description"),
236  0,
237  REG_SZ,
238  (const BYTE*)DriverInfoData.Description,
239  cbData);
240  if (rc != ERROR_SUCCESS)
241  {
242  DPRINT("RegSetValueEx() failed with error 0x%lx\n", rc);
243  goto cleanup;
244  }
245 
246  /* FIXME: install OpenGLSoftwareSettings section */
247 
248  rc = ERROR_SUCCESS;
249 
250 cleanup:
251  if (hInf != INVALID_HANDLE_VALUE)
252  SetupCloseInfFile(hInf);
253  if (hDriverKey != INVALID_HANDLE_VALUE)
254  {
255  /* SetupDiOpenDevRegKey returns INVALID_HANDLE_VALUE in case of error! */
256  RegCloseKey(hDriverKey);
257  }
258  if (hSettingsKey != NULL)
259  RegCloseKey(hSettingsKey);
260  if (hServicesKey != NULL)
262  if (hServiceKey != NULL)
263  RegCloseKey(hServiceKey);
264  if (hDeviceSubKey != NULL)
265  RegCloseKey(hDeviceSubKey);
266 
267  return rc;
268 }
#define _WIN32_WINNT
Definition: precomp.h:14
#define INF_STYLE_WIN4
Definition: infsupp.h:41
#define SetupInstallFromInfSection
Definition: setupapi.h:2640
#define ERROR_SUCCESS
Definition: deptool.c:10
HRESULT hr
Definition: shlfolder.c:183
#define KEY_SET_VALUE
Definition: nt_native.h:1017
#define KEY_READ
Definition: nt_native.h:1023
#define SetupDiGetDeviceInstallParams
Definition: setupapi.h:2594
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SetupDiGetDeviceRegistryProperty
Definition: setupapi.h:2598
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define SetupDiGetSelectedDriver
Definition: setupapi.h:2605
#define DWORD
Definition: nt_native.h:44
VOID WINAPI SetupCloseInfFile(IN HINF InfHandle)
Definition: infsupp.c:43
CHAR SectionName[LINE_LEN]
Definition: setupapi.h:1060
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define SetupDiGetActualSectionToInstall
Definition: setupapi.h:2583
#define DI_DONOTCALLCONFIGMG
Definition: setupapi.h:63
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
BOOL WINAPI SetupDiInstallDevice(IN HDEVINFO DeviceInfoSet, IN OUT PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:5370
size_t __cdecl _tcslen(const _TCHAR *str)
Definition: tcslen.h:9
#define SPINST_REGISTRY
Definition: setupapi.h:585
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define REG_CREATED_NEW_KEY
Definition: nt_native.h:1084
#define DIF_INSTALLDEVICE
Definition: setupapi.h:121
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
#define KEY_WRITE
Definition: nt_native.h:1031
static HANDLE hServicesKey
Definition: devinst.c:21
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
#define StringCbCat
Definition: strsafe.h:334
LPTSTR ServiceName
Definition: ServiceMain.c:15
LONG HRESULT
Definition: typedefs.h:78
#define SetupDiSetDeviceInstallParams
Definition: setupapi.h:2614
#define MAX_PATH
Definition: compat.h:26
_In_opt_ PSP_DEVINFO_DATA DeviceInfoData
Definition: setupapi.h:1523
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
UINT cchMax
static const WCHAR L[]
Definition: oid.c:1250
#define SPDRP_SERVICE
Definition: setupapi.h:506
HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, DWORD Scope, DWORD HwProfile, DWORD KeyType, REGSAM samDesired)
Definition: devinst.c:5935
unsigned char BYTE
Definition: xxhash.c:193
#define SetupDiGetDriverInfoDetail
Definition: setupapi.h:2599
#define _stprintf
Definition: utility.h:124
#define RegOpenKeyEx
Definition: winreg.h:520
#define DICS_FLAG_GLOBAL
Definition: setupapi.h:113
CHAR Description[LINE_LEN]
Definition: setupapi.h:1001
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
#define ERROR_DI_DO_DEFAULT
Definition: setupapi.h:305
#define DIREG_DRV
Definition: setupapi.h:182
char * cleanup(char *str)
Definition: wpickclick.c:99
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
CHAR InfFileName[MAX_PATH]
Definition: setupapi.h:1061
GLuint64EXT * result
Definition: glext.h:11304
#define KEY_CREATE_SUB_KEY
Definition: nt_native.h:1018
BYTE * PBYTE
Definition: pedump.c:66
#define RegSetValueEx
Definition: winreg.h:533
#define RegCreateKeyEx
Definition: winreg.h:501
#define SetupOpenInfFile
Definition: setupapi.h:2647
#define MAX_SERVICE_NAME_LEN
Definition: setupapi.h:25
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define KEY_ENUMERATE_SUB_KEYS
Definition: nt_native.h:1019
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define REG_SZ
Definition: layer.c:22

◆ MonitorClassInstaller()

DWORD WINAPI MonitorClassInstaller ( IN DI_FUNCTION  InstallFunction,
IN HDEVINFO  DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData  OPTIONAL 
)

Definition at line 271 of file classinst.c.

275 {
276  return ERROR_DI_DO_DEFAULT;
277 }
#define ERROR_DI_DO_DEFAULT
Definition: setupapi.h:305