From: Johannes Anderwald Date: Sun, 20 Dec 2009 00:53:21 +0000 (+0000) Subject: [SETUPAPI] X-Git-Tag: backups/aicom-network-stable@46924~248 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=98485b0feb046ae2658fcaaf5acbe74719f43f28;hp=cf7f39eaba51997b557d2185c855675f00b53549;ds=inline [SETUPAPI] - Implement SetupDiOpenDeviceInterfaceRegKey svn path=/trunk/; revision=44661 --- diff --git a/reactos/dll/win32/setupapi/interface.c b/reactos/dll/win32/setupapi/interface.c index 09234df3194..1d207097d00 100644 --- a/reactos/dll/win32/setupapi/interface.c +++ b/reactos/dll/win32/setupapi/interface.c @@ -337,11 +337,9 @@ InstallOneInterface( IN HDEVINFO DeviceInfoSet, IN struct DeviceInfo *devInfo) { - BOOL ret; HKEY hKey, hRefKey; LPWSTR Path; SP_DEVICE_INTERFACE_DATA DeviceInterfaceData; - PLIST_ENTRY InterfaceListEntry; struct DeviceInterface *DevItf = NULL; if (InterfaceFlags != 0) @@ -425,6 +423,8 @@ SetupDiInstallDeviceInterfaces( SetLastError(ERROR_INVALID_HANDLE); else if (!DeviceInfoData) SetLastError(ERROR_INVALID_PARAMETER); + else if (DeviceInfoData && DeviceInfoData->Reserved == 0) + SetLastError(ERROR_INVALID_USER_BUFFER); else if (DeviceInfoData && DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA)) SetLastError(ERROR_INVALID_USER_BUFFER); else @@ -537,3 +537,87 @@ cleanup: TRACE("Returning %d\n", ret); return ret; } + +HKEY WINAPI +SetupDiOpenDeviceInterfaceRegKey( + IN HDEVINFO DeviceInfoSet, IN PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, IN DWORD Reserved, IN REGSAM samDesired) +{ + HKEY hKey = INVALID_HANDLE_VALUE, hDevKey; + struct DeviceInfoSet * list; + + TRACE("%p %p %p 0x%08x 0x%08x)\n", DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired); + + if (!DeviceInfoSet) + SetLastError(ERROR_INVALID_PARAMETER); + else if (DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE) + SetLastError(ERROR_INVALID_HANDLE); + else if ((list = (struct DeviceInfoSet *)DeviceInfoSet)->magic != SETUP_DEVICE_INFO_SET_MAGIC) + SetLastError(ERROR_INVALID_HANDLE); + else if (!DeviceInterfaceData) + SetLastError(ERROR_INVALID_PARAMETER); + else if (DeviceInterfaceData && DeviceInterfaceData->Reserved == 0) + SetLastError(ERROR_INVALID_USER_BUFFER); + else if (DeviceInterfaceData && DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA)) + SetLastError(ERROR_INVALID_USER_BUFFER); + else + { + struct DeviceInterface *DevItf; + LPWSTR Path, Guid, Slash; + DWORD Length; + DevItf = (struct DeviceInterface *)DeviceInterfaceData->Reserved; + + Length = wcslen(DevItf->SymbolicLink); + + Path = HeapAlloc(GetProcessHeap(), 0, (Length+2) * sizeof(WCHAR)); + if (!Path) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return INVALID_HANDLE_VALUE; + } + + wcscpy(Path, DevItf->SymbolicLink); + + Guid = wcsrchr(Path, '}'); + Slash = wcsrchr(Path, '\\'); + if (!Guid || !Slash) + { + SetLastError(ERROR_INVALID_PARAMETER); + return INVALID_HANDLE_VALUE; + } + + if ((ULONG_PTR)Slash > (ULONG_PTR)Guid) + { + /* Create an extra slash */ + memmove(Slash+1, Slash, (wcslen(Slash) + 1) * sizeof(WCHAR)); + Slash[1] = L'#'; + } + + Guid = Path; + while((ULONG_PTR)Guid < (ULONG_PTR)Slash) + { + if (*Guid == L'\\') + *Guid = L'#'; + + Guid++; + } + + hKey = SetupDiOpenClassRegKeyExW(&DeviceInterfaceData->InterfaceClassGuid, samDesired, DIOCR_INTERFACE, NULL, NULL); + if (hKey != INVALID_HANDLE_VALUE) + { + if (RegOpenKeyExW(hKey, Path, 0, samDesired, &hDevKey) == ERROR_SUCCESS) + { + RegCloseKey(hKey); + hKey = hDevKey; + } + else + { + RegCloseKey(hKey); + hKey = INVALID_HANDLE_VALUE; + } + } + + HeapFree(GetProcessHeap(), 0, Path); + } + + return hKey; +} diff --git a/reactos/dll/win32/setupapi/stubs.c b/reactos/dll/win32/setupapi/stubs.c index c3b1a401b33..37b53f4c060 100644 --- a/reactos/dll/win32/setupapi/stubs.c +++ b/reactos/dll/win32/setupapi/stubs.c @@ -241,8 +241,4 @@ WINSETUPAPI BOOL WINAPI SetupDiGetDeviceInterfaceAlias(IN HDEVINFO DeviceInfoSe return FALSE; } -HKEY WINAPI SetupDiOpenDeviceInterfaceRegKey(IN HDEVINFO DeviceInfoSet, IN PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, IN DWORD Reserved, IN REGSAM samDesired) -{ - FIXME("%p %p %p 0x%08x 0x%08x: stub\n", DeviceInfoSet, DeviceInterfaceData, Reserved, samDesired); - return INVALID_HANDLE_VALUE; -} +