From 0fc321d02445deefd12b5c2b29a45236762648ff Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Fri, 21 Sep 2007 17:08:28 -0700 Subject: [PATCH] Implement SetupDiDeleteDeviceInterfaceRegKey --- dlls/setupapi/devinst.c | 99 ++++++++++++++++++++++++++++++++++--------- dlls/setupapi/setupapi.spec | 1 2 files changed, 80 insertions(+), 20 deletions(-) diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 04447f7..6c31064 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -2224,6 +2224,33 @@ HKEY WINAPI SetupDiCreateDeviceInterface return key; } +static PWSTR SETUPDI_GetInstancePath(struct InterfaceInfo *ifaceInfo) +{ + static const WCHAR hash[] = {'#',0}; + PWSTR instancePath = NULL; + + if (ifaceInfo->referenceString) + { + instancePath = HeapAlloc(GetProcessHeap(), 0, + (lstrlenW(ifaceInfo->referenceString) + 2) * sizeof(WCHAR)); + if (instancePath) + { + lstrcpyW(instancePath, hash); + lstrcatW(instancePath, ifaceInfo->referenceString); + } + else + SetLastError(ERROR_OUTOFMEMORY); + } + else + { + instancePath = HeapAlloc(GetProcessHeap(), 0, + (lstrlenW(hash) + 1) * sizeof(WCHAR)); + if (instancePath) + lstrcpyW(instancePath, hash); + } + return instancePath; +} + /*********************************************************************** * SetupDiCreateDeviceInterfaceRegKeyW (SETUPAPI.@) */ @@ -2271,28 +2298,10 @@ HKEY WINAPI SetupDiCreateDeviceInterface if (!(l = RegCreateKeyExW(interfacesKey, bracedGuidString, 0, NULL, 0, samDesired, NULL, &parent, NULL))) { - static const WCHAR hash[] = {'#',0}; struct InterfaceInfo *ifaceInfo = (struct InterfaceInfo *)DeviceInterfaceData->Reserved; - LPCWSTR instancePath = NULL; - LPWSTR referencePath = NULL; + PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo); - if (ifaceInfo->referenceString) - { - referencePath = HeapAlloc(GetProcessHeap(), 0, - (lstrlenW(ifaceInfo->referenceString) + 2) * - sizeof(WCHAR)); - if (referencePath) - { - lstrcpyW(referencePath, hash); - lstrcatW(referencePath, ifaceInfo->referenceString); - instancePath = referencePath; - } - else - SetLastError(ERROR_OUTOFMEMORY); - } - else - instancePath = hash; if (instancePath) { LONG l; @@ -2307,7 +2316,7 @@ HKEY WINAPI SetupDiCreateDeviceInterface else if (InfHandle) FIXME("INF section installation unsupported\n"); } - HeapFree(GetProcessHeap(), 0, referencePath); + HeapFree(GetProcessHeap(), 0, instancePath); RegCloseKey(parent); } else @@ -2320,6 +2329,56 @@ HKEY WINAPI SetupDiCreateDeviceInterface } /*********************************************************************** + * SetupDiDeleteDeviceInterfaceRegKey (SETUPAPI.@) + */ +BOOL WINAPI SetupDiDeleteDeviceInterfaceRegKey( + HDEVINFO DeviceInfoSet, + PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, + DWORD Reserved) +{ + struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet; + HKEY parent; + BOOL ret = FALSE; + + TRACE("%p %p %d\n", DeviceInfoSet, DeviceInterfaceData, Reserved); + + if (!DeviceInfoSet || DeviceInfoSet == (HDEVINFO)INVALID_HANDLE_VALUE || + set->magic != SETUP_DEVICE_INFO_SET_MAGIC) + { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + if (!DeviceInterfaceData || + DeviceInterfaceData->cbSize != sizeof(SP_DEVICE_INTERFACE_DATA) || + !DeviceInterfaceData->Reserved) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + parent = SetupDiOpenClassRegKeyExW(&DeviceInterfaceData->InterfaceClassGuid, + KEY_ALL_ACCESS, DIOCR_INTERFACE, NULL, NULL); + if (parent != INVALID_HANDLE_VALUE) + { + struct InterfaceInfo *ifaceInfo = + (struct InterfaceInfo *)DeviceInterfaceData->Reserved; + PWSTR instancePath = SETUPDI_GetInstancePath(ifaceInfo); + + if (instancePath) + { + LONG l = RegDeleteKeyW(parent, instancePath); + + if (l) + SetLastError(l); + else + ret = TRUE; + HeapFree(GetProcessHeap(), 0, instancePath); + } + RegCloseKey(parent); + } + return ret; +} + +/*********************************************************************** * SetupDiEnumDeviceInterfaces (SETUPAPI.@) * * PARAMS diff --git a/dlls/setupapi/setupapi.spec b/dlls/setupapi/setupapi.spec index 5ba940e..f9589b1 100644 --- a/dlls/setupapi/setupapi.spec +++ b/dlls/setupapi/setupapi.spec @@ -295,6 +295,7 @@ # Yes, Microsoft really misspelled this @ stub SetupDiDeleteDevRegKey @ stub SetupDiDeleteDeviceInfo @ stub SetupDiDeleteDeviceInterfaceData +@ stdcall SetupDiDeleteDeviceInterfaceRegKey(ptr ptr long) @ stub SetupDiDeleteDeviceRegKey @ stub SetupDiDestroyClassImageList @ stdcall SetupDiDestroyDeviceInfoList(long) -- 1.4.1