From 40d2e595148f6b19463892cfa293f2813c40a88f Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Wed, 19 Sep 2007 17:51:44 -0700 Subject: [PATCH] Implement SetupDiGetDeviceInstanceIdW --- dlls/setupapi/devinst.c | 56 ++++++++++++++++++++++++++++++++++++----- dlls/setupapi/tests/devinst.c | 11 -------- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index 95d45ae..36c982c 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -97,7 +97,10 @@ static struct DeviceInfo *SETUPDI_Alloca devInfo->instanceId = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(instanceId) + 1) * sizeof(WCHAR)); if (devInfo->instanceId) + { lstrcpyW(devInfo->instanceId, instanceId); + struprW(devInfo->instanceId); + } else { HeapFree(GetProcessHeap(), 0, devInfo); @@ -886,7 +889,7 @@ BOOL WINAPI SetupDiCreateDeviceInfoW( SetLastError(ERROR_INVALID_DEVINST_NAME); else { - static const WCHAR newDeviceFmt[] = {'R','o','o','t','\\','%','s', + static const WCHAR newDeviceFmt[] = {'R','O','O','T','\\','%','s', '\\','%','0','4','d',0}; DWORD devId; @@ -938,7 +941,7 @@ BOOL WINAPI SetupDiCreateDeviceInfoW( struct DeviceInfo *devInfo = (struct DeviceInfo *)set->devices[i].Reserved; - if (!lstrcmpW(DeviceName, devInfo->instanceId)) + if (!lstrcmpiW(DeviceName, devInfo->instanceId)) { SetLastError(ERROR_DEVINST_ALREADY_EXISTS); ret = FALSE; @@ -1050,8 +1053,16 @@ BOOL WINAPI SetupDiGetDeviceInstanceIdA( if (!len) ret = FALSE; - else if (RequiredSize) - *RequiredSize = len; + else + { + if (len > DeviceInstanceIdSize) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + ret = FALSE; + } + if (RequiredSize) + *RequiredSize = len; + } } HeapFree(GetProcessHeap(), 0, instanceId); } @@ -1068,10 +1079,41 @@ BOOL WINAPI SetupDiGetDeviceInstanceIdW( DWORD DeviceInstanceIdSize, PDWORD RequiredSize) { - FIXME("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId, + struct DeviceInfoSet *set = (struct DeviceInfoSet *)DeviceInfoSet; + struct DeviceInfo *devInfo; + + TRACE("%p %p %p %d %p\n", DeviceInfoSet, DeviceInfoData, DeviceInstanceId, DeviceInstanceIdSize, RequiredSize); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; + + if (!DeviceInfoSet || DeviceInfoSet == INVALID_HANDLE_VALUE) + { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + if (set->magic != SETUP_DEVICE_INFO_SET_MAGIC) + { + SetLastError(ERROR_INVALID_HANDLE); + return FALSE; + } + if (!DeviceInfoData || DeviceInfoData->cbSize != sizeof(SP_DEVINFO_DATA) + || !DeviceInfoData->Reserved) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + devInfo = (struct DeviceInfo *)DeviceInfoData->Reserved; + TRACE("instance ID: %s\n", debugstr_w(devInfo->instanceId)); + if (DeviceInstanceIdSize < lstrlenW(devInfo->instanceId) + 1) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); + if (RequiredSize) + *RequiredSize = lstrlenW(devInfo->instanceId) + 1; + return FALSE; + } + lstrcpyW(DeviceInstanceId, devInfo->instanceId); + if (RequiredSize) + *RequiredSize = lstrlenW(devInfo->instanceId) + 1; + return TRUE; } /*********************************************************************** diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c index 28e2624..c88ad24 100644 --- a/dlls/setupapi/tests/devinst.c +++ b/dlls/setupapi/tests/devinst.c @@ -217,12 +217,10 @@ static void testGetDeviceInstanceId(void } SetLastError(0xdeadbeef); ret = pSetupDiGetDeviceInstanceIdA(NULL, NULL, NULL, 0, NULL); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError()); SetLastError(0xdeadbeef); ret = pSetupDiGetDeviceInstanceIdA(NULL, &devInfo, NULL, 0, NULL); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLEHANDLE, got %08x\n", GetLastError()); set = pSetupDiCreateDeviceInfoList(&guid, NULL); @@ -235,23 +233,19 @@ static void testGetDeviceInstanceId(void SetLastError(0xdeadbeef); ret = pSetupDiGetDeviceInstanceIdA(set, NULL, NULL, 0, NULL); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); SetLastError(0xdeadbeef); ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, NULL); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); SetLastError(0xdeadbeef); ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); devInfo.cbSize = sizeof(devInfo); SetLastError(0xdeadbeef); ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size); - todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError()); ret = pSetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid, @@ -259,14 +253,11 @@ static void testGetDeviceInstanceId(void ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError()); SetLastError(0xdeadbeef); ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, NULL, 0, &size); - todo_wine ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %08x\n", GetLastError()); ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID, sizeof(instanceID), NULL); - todo_wine ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError()); - todo_wine ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0000"), "Unexpected instance ID %s\n", instanceID); ret = pSetupDiCreateDeviceInfoA(set, "LEGACY_BOGUS", &guid, @@ -274,9 +265,7 @@ static void testGetDeviceInstanceId(void ok(ret, "SetupDiCreateDeviceInfoA failed: %08x\n", GetLastError()); ret = pSetupDiGetDeviceInstanceIdA(set, &devInfo, instanceID, sizeof(instanceID), NULL); - todo_wine ok(ret, "SetupDiGetDeviceInstanceIdA failed: %08x\n", GetLastError()); - todo_wine ok(!lstrcmpA(instanceID, "ROOT\\LEGACY_BOGUS\\0001"), "Unexpected instance ID %s\n", instanceID); pSetupDiDestroyDeviceInfoList(set); -- 1.4.1