Legacy methods and Windows registry
Mike,
If you have access to a ancient version of MSVC1.52 or earlier (from 1993) then there was a legacy function called _bios_equiplist(...). We used to use this function to read stuff for DOS applications. This development environment is no longer readily available and WinNT/2000/XP will not even allow this function due to direct read of secured memory addresses.
There is a modern way to read this information from the Windows registry. Below is another technique using the Windows registry. This is an older program that I wrote years ago in plain-C and it has some stylistic problems. Nevertheless, the function calls are important. The example shows some queries about the CPU characteristics.
Other gurus will certainly know how to do this better. There are many wrapper-classes available as free-ware for reading the registry.
Sincerely, Chris.
:)
Code:
#include <windows.h>
#include <iostream>
#include <string>
// This is an old legacy C-function for reading the Windows registry
// sections related to the central processing unit.
static BOOL QueryValue_HKEY_LOCAL_MACHINE__CentralProcessor(BYTE* abyOut, const char* pstrIn, DWORD dwSize)
{
const char strHKEY_CPU[] =
"Hardware\\Description\\System\\CentralProcessor\\0";
auto LONG lResult = 0;
// Use statics since address passing to subroutine will be used.
static HKEY hKey;
static DWORD dwDataSize;
static BYTE abyData[1024];
BOOL bOK = FALSE;
// Initialize variables
dwDataSize = dwSize;
memset((void*) abyData, 0, sizeof(abyData));
// Get the CPU information
lResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
strHKEY_CPU,
0,
KEY_READ,
&hKey);
if(lResult == ERROR_SUCCESS)
{
// Query desired registry value.
lResult = RegQueryValueEx(hKey,
pstrIn,
NULL,
NULL,
abyData,
&dwDataSize);
if(lResult == ERROR_SUCCESS)
{
memcpy(abyOut, abyData, dwDataSize * sizeof(BYTE));
bOK = TRUE;
}
}
// Make sure to close the reg key
RegCloseKey(hKey);
return bOK;
}
int main(int argc, char* argv[])
{
BYTE data[128];
// Read CPU Frequency
::memset(data, 0, 128 * sizeof(BYTE));
::QueryValue_HKEY_LOCAL_MACHINE__CentralProcessor(data,
"~MHz",
sizeof(DWORD));
DWORD dw_MHz = *(reinterpret_cast<DWORD*>(&data[0]));
::std::cout << "CPU Frequency [MHz]: " << dw_MHz << ::std::endl;
// Test for genuine Intel
::memset(data, 0, 128 * sizeof(BYTE));
::QueryValue_HKEY_LOCAL_MACHINE__CentralProcessor(data,
"VendorIdentifier",
sizeof("GenuineIntel"));
if(::std::string(reinterpret_cast<char*>(data)) == ::std::string("GenuineIntel"))
{
::std::cout << "Is genuine Intel!" << ::std::endl;
}
return 1;
}