Solved

Function call to get Processor Speed and Type?

Posted on 2002-05-28
10
933 Views
Last Modified: 2013-12-03
Is there a Win32 function call to get the Processor Speed and Type? Ideally, this would be the same regardless of win9X or WinNT based systems.

Thanks,
Frank
0
Comment
Question by:magenta
10 Comments
 
LVL 1

Expert Comment

by:mite51
Comment Utility
lurking
0
 
LVL 4

Expert Comment

by:mblat
Comment Utility
I am not aware of any API call for that, but www.intel.com has file called cpuinfo.zip.

This file has executable and code to find out what you want.

Disclamer: Never used it ( code portion) only know it is there...

Hope it helps...
0
 
LVL 12

Expert Comment

by:pjknibbs
Comment Utility
mblat is correct in that there's no API which will return this information--you'll need to use code to do it. I would imagine that Intel CPUINFO utility wouldn't work for non-Intel processors, though, so you might want to spread your search a little wider if you want to cover the likes of AMD, VIA (nee Cyrix) and Transmeta.
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 10

Expert Comment

by:makerp
Comment Utility
gets the cpu speed, quite good too

#pragma warning(disable : 4244) /* C4244 warning expected from the
conversion between float and int in getCurrentLoad */
 
#pragma warning(disable : 4035) /* C4113 warning expected from the
theCycleCounter function */

/* creates two byes of data in the current text segment of the program
this is used to help get the CPU speed */
static inline unsigned __int64 theCycleCounter()
{      
    _asm    _emit 0x0F
    _asm    _emit 0x31 /* this implicetly pushes a return value
     on the stack, thats why i ignore the waring */
}

     /* work out the cpu speed first, this has provded to be very
     acurate (+/-  1 Mhz) */    
     unsigned __int64  start = 0;
     unsigned __int64  overhead = 0;

     start = theCycleCounter();
     Sleep(1000L);
     
     unsigned cpuspeed100 =
          (unsigned)((theCycleCounter() - start - overhead) / 10000);

     cpu_speed = cpuspeed100 / 100;    
0
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
Read it from the registry - HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0 has a value named '~MHz'
0
 
LVL 1

Expert Comment

by:Toad224
Comment Utility
Try using this code to get the CPU speed:

int GetProcSpeed()
{
     LONG result;
     HKEY hKey;
     DWORD data;
     DWORD dataSize;

     result = RegOpenKeyEx (HKEY_LOCAL_MACHINE, "Hardware\\Description\\System\\CentralProcessor\\0", 0, KEY_QUERY_VALUE, &hKey);

     if (result == ERROR_SUCCESS)
     {
          result = RegQueryValueEx (hKey, "~MHz", NULL, NULL,
               (LPBYTE)&data, &dataSize);
     }
     else
     {
          RegCloseKey (hKey);
          return -1;
     }

     RegCloseKey (hKey);

     return (int)data;
}


Hope this helps.  Good luck!
0
 

Expert Comment

by:The_Real_Spaceman_Spliff
Comment Utility
I may have missed something (you guys have pretty complex answers, direct interaction with reg keys may depend on permissions, so I like to avoid it), but I think this is easier, and works just as well (in C, I put this with the WM_PAINT handler of WndProc):

case WM_PAINT:
 {
   //...

   SYSTEM_INFO sInfo;
   GetSystemInfo(&siSysInfo);
   TCHAR szBuffer[10];

   //begin painting...

   TextOut (hdc, 100, 100, szBuffer, wsprintf (szBuffer, TEXT ("%5d"),       siSysInfo.dwProcessorType));

   //...end painting
 } break;

You can play with it a little, I just used it to write the processor type at x=100, y=100 in the window.  Obviously szBuffer doesn't NEED to be 10 (not that I know of, as long as it's greater than the output width, ie. > 5), but I used szBuffer to do a few things in my app, too lazy to double-check the necessity...
0
 

Expert Comment

by:The_Real_Spaceman_Spliff
Comment Utility
Sorry, typo there, ammend the SYSTEM_INFO line:

   SYSTEM_INFO siSysInfo;

(insert embarrased emoticon here)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now