Sign in to follow this  
signbit

How do I get Hardware Info in C++/MFC?

Recommended Posts

signbit    122
Hello, How do I get Hardware Info (CPU, VGA Card, RAM, Ports, etc, etc) in C++/MFC... Any suggestions... (links to some aritcals would really help)..

Share this post


Link to post
Share on other sites
signbit    122
Thanks, I am fetching:

1. processor information from: HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0 .

2. RAM Info from: GlobalMemoryStatus()

3. Hard-Disk Info from: GetVolumeInformation()

Any suggestions about VGA, Sound Card and Ports (USB, Serial, Communication)...

Bye,

Share this post


Link to post
Share on other sites
code_evo    146

Dont know if you want to include the libraries just for graphics info but opengl/directx have functions which supply the information.

i'm sure theres a better way.

/jeff

Share this post


Link to post
Share on other sites
Lantz    142
For vga cards I think EnumDisplayDevices will do the trick. And most devices seems to registered under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum.

Share this post


Link to post
Share on other sites
aboeing    180
For sound card you can use:
waveOutGetNumDevs
waveOutGetDevCaps
from mmsystem

However, if you do decide to use DirectX to query the hardware you can get a lot more information from direct sound and directshow. Also you can obviously use direct3d to get information about the graphics hardware. You can do similar with opengl.
A simple capabilites viewing app is here

Share this post


Link to post
Share on other sites
aboeing    180
I'm just trying it out myself now to get info from the ports, but I cant seem to get it working.

#include <windows.h>
#include <Setupapi.h>
#include <Stdio.h>
//#include <devguid.h> //includes all the guid

HDEVINFO DoDeviceEnum( GUID InterfaceClassGuid )
{
long Err;
HDEVINFO DeviceInfoSet;
HDEVINFO NewDeviceInfoSet;
DeviceInfoSet = SetupDiCreateDeviceInfoList(NULL, NULL);

if(DeviceInfoSet == INVALID_HANDLE_VALUE) {
Err = GetLastError();
printf( "SetupDiCreateDeviceInfoList failed: %lx.\n", Err );
return 0;
}

NewDeviceInfoSet = SetupDiGetClassDevsEx( &InterfaceClassGuid, //class guid
NULL, //enumerator
NULL, //hwndParent
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE, //flags
DeviceInfoSet,
NULL, //machine name
NULL //reserved
);
if(NewDeviceInfoSet == INVALID_HANDLE_VALUE)
{
Err = GetLastError();
printf( "SetupDiGetClassDevsEx failed: %lx.\n", Err );
return 0;
}

return NewDeviceInfoSet;
}

//taken from vc6 devguid.h
DEFINE_GUID( GUID_DEVCLASS_PORTS, 0x4d36e978L, 0xe325, 0x11ce, 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 );

int main() {
HDEVINFO hdi;
GUID ports = GUID_DEVCLASS_PORTS;
hdi=DoDeviceEnum(ports);

SP_DEVICE_INTERFACE_DATA sdid;
memset(&sdid,0,sizeof(SP_DEVICE_INTERFACE_DATA));
sdid.cbSize=sizeof(SP_DEVICE_INTERFACE_DATA);

if (!SetupDiEnumDeviceInterfaces(hdi,
NULL,
&ports,
0, //index
&sdid) ) {
printf("error enumerating devices\n");
return 0;
}
printf("%d\n",ports);
printf("%d\n",sdid.InterfaceClassGuid);
printf("%d\n",sdid.Flags);

PSP_INTERFACE_DEVICE_DETAIL_DATA pDevDetail = NULL;
DWORD Size;
SetupDiGetDeviceInterfaceDetail(
hdi, &sdid, NULL, 0, &Size, NULL );
pDevDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(Size);
pDevDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
SP_DEVINFO_DATA DevInfoData;
DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);

if(!SetupDiGetDeviceInterfaceDetail(
hdi, &sdid, pDevDetail, Size, NULL, &DevInfoData))
{
printf("failed to get device detail\n");
return 0;
}
printf("device name:%s\n",pDevDetail->DevicePath);
char *buff = NULL;
DWORD dwData;
DWORD buffersize = 0;
//get size
if (!SetupDiGetDeviceRegistryProperty(hdi,
&DevInfoData,
SPDRP_DEVTYPE,
&dwData, //?
(BYTE *)buff,
buffersize,
&buffersize)
) {
DWORD error=GetLastError();
printf("error:%d\n",error);
printf("failed1\n");
return 0;
}
buff = new char[buffersize+1];
//put data
if (!SetupDiGetDeviceRegistryProperty(hdi,
&DevInfoData,
SPDRP_DEVTYPE,
&dwData, //?
(BYTE *)buff,
buffersize,
&buffersize)
) {
printf("failed2\n");
return 0;
}
printf("%s\n",buff);
SetupDiDestroyDeviceInfoList(hdi); // destroy device information list
return 0;
}

The code is pritty much just cut and pasted from msdn with bits filled in.

I get this output:
1295444344
1295444344
1
device name:\\?\acpi#pnp0501#1#{4d36e978-e325-11ce-bfc1-08002be10318}
error:13
failed1


But I cant see whats wrong.. (ERROR_INVALID_DATA?)

Anyway, I'm assuming I'm on the right track, so you just need to lookup the SetupDiCreateDeviceInfoList & related functions. If anyone manages to get something working please post the code.

Share this post


Link to post
Share on other sites
signbit    122
Thanks a lot bro (aboeing), I'll not be working on that assignment for a week or so... (Actually have another assignment to make first, It's a game of NIM in MFC in which the computer always wins (or mostly wins) )

Will post the code for this one as soon as I start working on this one again (and most importantly, get anything working ;) )

Bye,

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this