• Advertisement
Sign in to follow this  

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

This topic is 4960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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

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
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
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
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
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
Does any one know how can I find out the memory size of the VGA card?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement