+static
+BOOL
+SETUP_CallInstaller(
+ IN DI_FUNCTION InstallFunction,
+ IN HDEVINFO DeviceInfoSet,
+ IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL,
+ IN PSP_ADDPROPERTYPAGE_DATA PageData)
+{
+ PSP_CLASSINSTALL_HEADER pClassInstallParams = NULL;
+ DWORD dwSize = 0;
+ DWORD dwError;
+ BOOL ret = TRUE;
+
+ /* Get the size of the old class install parameters */
+ if (!SetupDiGetClassInstallParams(DeviceInfoSet,
+ DeviceInfoData,
+ NULL,
+ 0,
+ &dwSize))
+ {
+ dwError = GetLastError();
+ if (dwError != ERROR_INSUFFICIENT_BUFFER)
+ {
+ ERR("SetupDiGetClassInstallParams failed (Error %lu)\n", dwError);
+ return FALSE;
+ }
+ }
+
+ /* Allocate a buffer for the old class install parameters */
+ pClassInstallParams = HeapAlloc(GetProcessHeap(), 0, dwSize);
+ if (pClassInstallParams == NULL)
+ {
+ ERR("Failed to allocate the parameters buffer!\n");
+ return FALSE;
+ }
+
+ /* Save the old class install parameters */
+ if (!SetupDiGetClassInstallParams(DeviceInfoSet,
+ DeviceInfoData,
+ pClassInstallParams,
+ dwSize,
+ &dwSize))
+ {
+ ERR("SetupDiGetClassInstallParams failed (Error %lu)\n", GetLastError());
+ ret = FALSE;
+ goto done;
+ }
+
+ /* Set the new class install parameters */
+ if (!SetupDiSetClassInstallParams(DeviceInfoSet,
+ DeviceInfoData,
+ &PageData->ClassInstallHeader,
+ sizeof(SP_ADDPROPERTYPAGE_DATA)))
+ {
+ ERR("SetupDiSetClassInstallParams failed (Error %lu)\n", dwError);
+ ret = FALSE;
+ goto done;
+ }
+
+ /* Call the installer */
+ ret = SetupDiCallClassInstaller(InstallFunction,
+ DeviceInfoSet,
+ DeviceInfoData);
+ if (ret == FALSE)
+ {
+ ERR("SetupDiCallClassInstaller failed\n");
+ goto done;
+ }
+
+ /* Read the new class installer parameters */
+ if (!SetupDiGetClassInstallParams(DeviceInfoSet,
+ DeviceInfoData,
+ &PageData->ClassInstallHeader,
+ sizeof(SP_ADDPROPERTYPAGE_DATA),
+ NULL))
+ {
+ ERR("SetupDiGetClassInstallParams failed (Error %lu)\n", GetLastError());
+ ret = FALSE;
+ goto done;
+ }
+
+done:
+ /* Restore and free the old class install parameters */
+ if (pClassInstallParams != NULL)
+ {
+ SetupDiSetClassInstallParams(DeviceInfoSet,
+ DeviceInfoData,
+ pClassInstallParams,
+ dwSize);
+
+ HeapFree(GetProcessHeap(), 0, pClassInstallParams);
+ }
+
+ return ret;
+}
+