Gradually, I began to realize that C ++ is not just C ++. It is backed by powerful APIs and class libraries, but also STL. This is what a good project should have-everyone is willing to use it and willing to contribute code to it.
Not to mention, easycraft encountered the problem of obtaining hardware information and modifying windows configurations. The first thing you need is the setupdigetclassdevs function. The prototype is as follows:
HDEVINFO SetupDiGetClassDevs( IN PGUID ClassGuid, /* optional */ IN PCTSTR Enumerator, /* optional */ IN HWND hwndParent, /* optional */ IN DWORD Flags );
The function is to enumerate device information. You can obtain various types of devices by modifying the classguid parameter. The instance function is as follows:
Void getgraphics (STD: String devices [10]) {DWORD dwidx = 0; sp_devinfo_data adapterdata; DWORD dwtype = 0; DWORD dwbuflen = 0; char * pbuf = NULL; hdevinfo hscsi = invalid_handle_value; // guidguid guidscsiraid = {0x4d36e968, 0xe325, 0x11ce, {0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 }}; bool Bret = false; hscsi = setupdigetclassdevs (& guidscsiraid, null, null, digcf_present); adapterdata. cbsize = sizeof (sp_devinfo_data); // start to enumerate the graphics card for (dwidx = 0; setupdienumdeviceinfo (hscsi, dwidx, & adapterdata); dwidx ++) {swap (hscsi, & adapterdata, spdrp_devicedesc, & dwtype, null, 0, & dwbuflen); If (Bytes = getlasterror () {pbuf = (char *) malloc (dwbuflen); If (setupdigetdeviceregistryproperty (hscsi, & adapterdata, spdrp_devicedesc, & dwtype, (unsigned char *) pbuf, dwbuflen, null) {devices [dwidx] = pbuf;} Free (pbuf); pbuf = NULL ;}} setupdidestroydeviceinfolist (hscsi );}
As shown in the above function, assign each obtained pbuf to the string variable devices, but not to the char * type variable. Otherwise, memory errors and garbled characters may occur.
This classguid can be found on msdn, such as this page: http://msdn.microsoft.com/en-us/library/windows/hardware/ff553426%28v=vs.85%29.aspx
Classguid of several common devices:
-
CD-ROM drives (disc drive)
-
-
Class = CDROM
-
Classguid = {4d36e965-e325-11ce-bfc1-08002be10318}
This class has des CD-ROM drives, including SCSI CD-ROM drives. By default, the system's CD-ROM class installer also installa system-supplied CD audio driver and CD-ROM changer driver as Plug and Play filters.
-
Display adapters)
-
-
Class = display
-
Classguid = {4d36e968-e325-11ce-bfc1-08002be10318}
This class includes des video adapters. Drivers for this class include display drivers and video miniport drivers.
-
Hard Disk controllers)
-
-
Class = HDC
-
Classguid = {4d36e96a-e325-11ce-bfc1-08002be10318}
This class includes des hard disk controllers, including ATA/atapi controllers but not SCSI and raid disk controllers.
-
Network Adapter)
-
-
Class = Net
-
Classguid = {4d36e972-e325-11ce-bfc1-08002be10318}
This class implements des NDIS miniport drivers excluding fast-IR miniport drivers, NDIS Intermediate Drivers (of virtual adapters), and condis MCM miniport drivers.
-
Processors (processor)
-
-
Class = Processor
-
Classguid = {50347dc3-0f36-415e-a6cc-4cb3be910b65}
This class implements des processor types.
-
Storage volumes)
-
-
Class = Volume
-
Classguid = {71a27cdd-812a-11d0-bec7-08002be2092f}
This class implements des storage volumes as defined by the System-supplied logical volume manager and class drivers that create Device objects to represent storage volumes, such as the System Disk class driver.