//
// Call function with null to begin with,
// then use the returned buffer size
// to Alloc the buffer. Keep calling until
// success or an unknown failure.
//
while (!SetupDiGetDeviceRegistryProperty(
hDevInfo,
&DeviceInfoData,
SPDRP_DEVICEDESC,
&DataT,
(PBYTE)buffer,
buffersize,
&buffersize))
{
if (GetLastError() ==
ERROR_INSUFFICIENT_BUFFER)
{
// Change the buffer size.
if (buffer) LocalFree(buffer);
buffer = LocalAlloc(LPTR,buffersize);
}
else
{
// Insert error handling here.
break;
}
}
return 0;
}
The following code fragment demonstrates how to retreive a set of all display adapters on a system.
hDevInfo = SetupDiGetClassDevs(
(LPGUID) &GUID_DEVCLASS_DISPLAY,
0,
0,
DIGCF_PRESENT);
The following code fragment demonstrates how to retrieve a set of all devices on the Peripheral Component Interconnect (PCI) bus.
hDevInfo = SetupDiGetClassDevs(NULL,
REGSTR_KEY_PCIENUM, // Enumerator
0,
DIGCF_PRESENT | DIGCF_ALLCLASSES );
Windows API functions that require a Device Instance Handle, such as the Config Manager set of API functions, can use the DevInst value in the structure SP_DEVINFO_DATA returned by the SetupDiEnumDeviceInfo function.
REFERENCES
SetupDi API calls are documented in the Windows 2000 Device Development Kit (DDK).
不过 ,您需要 DDK..
applies to:
Microsoft Windows 2000 Driver Development Kit (DDK)
Microsoft Windows NT 4.0 Driver Development Kit (DDK)