Gold mine of Visual C++ tricks!
How to get the CPU Name String?
![]()
While taking the System properties, you have noticed the processor name string. For instance, in my laptop it is – “Intel(R) Core(TM)2 Duo CPU T5250 @ 1.50GHz“. Ever though about how to get this processor name string?

Image Courtesy – Wallpaper Mania.
![]()
You can use the function – __cpuid(), which generates the instruction – cpuid. Have a look at the code snippet. Code taken and modified from MSDN.
#include <iostream>
#include <intrin.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
// Get extended ids.
int CPUInfo[4] = {-1};
__cpuid(CPUInfo, 0x80000000);
unsigned int nExIds = CPUInfo[0];
// Get the information associated with each extended ID.
char CPUBrandString[0x40] = { 0 };
for( unsigned int i=0x80000000; i<=nExIds; ++i)
{
__cpuid(CPUInfo, i);
// Interpret CPU brand string and cache information.
if (i == 0x80000002)
{
memcpy( CPUBrandString,
CPUInfo,
sizeof(CPUInfo));
}
else if( i == 0x80000003 )
{
memcpy( CPUBrandString + 16,
CPUInfo,
sizeof(CPUInfo));
}
else if( i == 0x80000004 )
{
memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
}
}
cout << "Cpu String: " << CPUBrandString;
}
![]()
You can get a lot of information about cpu by using __cpuid. Have a look at the MSDN Documentation.
![]()
Targeted Audiance – Intermeidate.
| Print article | This entry was posted by Jijo Raj on June 21, 2009 at 6:29 pm, and is filed under Uncategorized, Visual C++. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 5 months ago
Thanks a lot. It is helpful.
about 5 months ago
Hi ice,
Happy to know that you liked it.
Best Regards,
Jijo.
about 4 months ago
I shortened your code a bit
char CPUBrandString[49];
__cpuid((int*)CPUBrandString, 0×80000002);
__cpuid((int*)(CPUBrandString+16), 0×80000003);
__cpuid((int*)(CPUBrandString+32), 0×80000004);
CPUBrandString[48] = 0;