From 4f6af40fc9700538c61010df7273c0bf89fcb886 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Sat, 7 Mar 2015 17:33:13 +0000 Subject: [PATCH] [MMSYS] - install software bus pnp enumerator when an audio device is installed svn path=/trunk/; revision=66599 --- reactos/dll/cpl/mmsys/mmsys.c | 96 +++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/reactos/dll/cpl/mmsys/mmsys.c b/reactos/dll/cpl/mmsys/mmsys.c index b0c56de366d..be7325fa5b2 100644 --- a/reactos/dll/cpl/mmsys/mmsys.c +++ b/reactos/dll/cpl/mmsys/mmsys.c @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -87,6 +88,14 @@ DeviceCreateHardwarePageEx(HWND hWndParent, UINT uNumberOfGuids, HWPAGE_DISPLAYMODE DisplayMode); +typedef BOOL (WINAPI *UpdateDriverForPlugAndPlayDevicesProto)(IN OPTIONAL HWND hwndParent, + IN LPCTSTR HardwareId, + IN LPCTSTR FullInfPath, + IN DWORD InstallFlags, + OUT OPTIONAL PBOOL bRebootRequired + ); + +#define UPDATEDRIVERFORPLUGANDPLAYDEVICES "UpdateDriverForPlugAndPlayDevicesW" #define NUM_APPLETS (1) @@ -328,6 +337,80 @@ InstallSystemSoundScheme() RegCloseKey(hKey); } +DWORD +InstallSoftwareBusPnpEnumerator(LPWSTR InfPath, LPCWSTR HardwareIdList) +{ + HDEVINFO DeviceInfoSet = INVALID_HANDLE_VALUE; + SP_DEVINFO_DATA DeviceInfoData; + GUID ClassGUID; + TCHAR ClassName[50]; + int Result = 0; + HMODULE hModule = NULL; + UpdateDriverForPlugAndPlayDevicesProto UpdateProc; + BOOL reboot = FALSE; + DWORD flags = 0; + + if (!SetupDiGetINFClass(InfPath,&ClassGUID,ClassName,sizeof(ClassName)/sizeof(ClassName[0]),0)) + { + return -1; + } + + DeviceInfoSet = SetupDiCreateDeviceInfoList(&ClassGUID,0); + if(DeviceInfoSet == INVALID_HANDLE_VALUE) + { + return -1; + } + + DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA); + if (!SetupDiCreateDeviceInfo(DeviceInfoSet, ClassName, &ClassGUID, NULL, 0, DICD_GENERATE_ID, &DeviceInfoData)) + { + SetupDiDestroyDeviceInfoList(DeviceInfoSet); + return -1; + } + + if(!SetupDiSetDeviceRegistryProperty(DeviceInfoSet, &DeviceInfoData, SPDRP_HARDWAREID, (LPBYTE)HardwareIdList, (lstrlen(HardwareIdList)+1+1)*sizeof(TCHAR))) + { + SetupDiDestroyDeviceInfoList(DeviceInfoSet); + return -1; + } + + if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, DeviceInfoSet, &DeviceInfoData)) + { + SetupDiDestroyDeviceInfoList(DeviceInfoSet); + return -1; + } + + if(GetFileAttributes(InfPath)==(DWORD)(-1)) { + SetupDiDestroyDeviceInfoList(DeviceInfoSet); + return -1; + } + + flags |= INSTALLFLAG_FORCE; + hModule = LoadLibraryW(L"newdev.dll"); + if(!hModule) { + SetupDiDestroyDeviceInfoList(DeviceInfoSet); + return -1; + } + + UpdateProc = (UpdateDriverForPlugAndPlayDevicesProto)GetProcAddress(hModule,UPDATEDRIVERFORPLUGANDPLAYDEVICES); + if(!UpdateProc) + { + SetupDiDestroyDeviceInfoList(DeviceInfoSet); + FreeLibrary(hModule); + return -1; + } + + if(!UpdateProc(NULL, HardwareIdList, InfPath, flags, &reboot)) + { + SetupDiDestroyDeviceInfoList(DeviceInfoSet); + FreeLibrary(hModule); + return -1; + } + + FreeLibrary(hModule); + SetupDiDestroyDeviceInfoList(DeviceInfoSet); + return Result; +} DWORD MMSYS_InstallDevice(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pspDevInfoData) @@ -401,7 +484,20 @@ MMSYS_InstallDevice(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pspDevInfoData) SetupTermDefaultQueueCallback(Context); SetupCloseInfFile(hInf); + Length = GetWindowsDirectoryW(szBuffer, MAX_PATH); + if (!Length || Length >= MAX_PATH - 14) + { + return ERROR_GEN_FAILURE; + } + pBuffer = PathAddBackslashW(szBuffer); + if (!pBuffer) + { + return ERROR_GEN_FAILURE; + } + + wcscpy(pBuffer, L"inf\\machine.inf"); + InstallSoftwareBusPnpEnumerator(szBuffer, L"ROOT\\SWENUM"); hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); if (!hSCManager)