Enumerate hardware devices

Source: Internet
Author: User

Download Source: Http://dl2.csdn.net/down4/20070627/27161251844.rar

HOWTO: Enumerating hardware devices by using the SETUPDI Call Function view products that this article applies to.
Article number : 259695
Last modified : March 10, 2004
Amendment : 2.0
This article was previously published under CHS259695 Overview to get a list of hardware devices installed in Windows 2000, an application can call SetupDiClass API functions.

Back to the top

More information The following code snippet shows how to display a list of all the hardware devices that have been installed:
#include <stdio.h> #include <windows.h> #include <setupapi.h> #include <devguid.h> #include    <regstr.h>int Main (int argc, char *argv[], char *envp[]) {Hdevinfo hdevinfo;    Sp_devinfo_data Deviceinfodata;    DWORD i;    Create a hdevinfo with all present devices. Hdevinfo = Setupdigetclassdevs (NULL, 0,//Enumerator 0, Digcf_present |        digcf_allclasses);        if (Hdevinfo = = Invalid_handle_value) {//Insert error handling here.    return 1;        }//Enumerate through all devices in Set.    deviceinfodata.cbsize = sizeof (Sp_devinfo_data); for (i=0;        Setupdienumdeviceinfo (Hdevinfo,i, &deviceinfodata); i++) {DWORD datat;        LPTSTR buffer = NULL;                DWORD buffersize = 0; 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 (Get                LastError () = = Error_insufficient_buffer) {//change the BUFFER size.                if (buffer) localfree (buffer);            Buffer = LocalAlloc (lptr,buffersize);                } else {//Insert error handling here.            Break                }} printf ("result:[%s]/n", buffer);    if (buffer) localfree (buffer); } if (GetLastError ()!=no_error && GetLastError ()!=error_no_more_items) {//Insert        Error handling here.    return 1;        }//Cleanup setupdidestroydeviceinfolist (Hdevinfo); return 0;}
The following code snippet shows how to retrieve all the display adapter groups on the system:
    Hdevinfo = Setupdigetclassdevs (        (lpguid) &guid_devclass_display,        0,        0,        digcf_present);
The following code snippet shows how to retrieve all the device groups on the Peripheral Component Interconnect (PCI) bus:
    Hdevinfo = Setupdigetclassdevs (NULL,        regstr_key_pcienum,//enumerator        0,        digcf_present | digcf_allclasses);
Windows API functions that require device instance handles (such as the Config Manager Group for API functions) can use the setupdienumdeviceinfo function to return the D in the SP_DEVINFO_DATA structure The Evinst value.

http://blog.csdn.net/kl222/article/details/1668843

Enumerate hardware devices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.