Solved

Function call to get Processor Speed and Type?

Posted on 2002-05-28
10
941 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
ID: 7040905
lurking
0
 
LVL 4

Expert Comment

by:mblat
ID: 7040931
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
ID: 7041105
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 23

Expert Comment

by:Roshan Davis
ID: 7041461
0
 
LVL 10

Expert Comment

by:makerp
ID: 7041637
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
ID: 7041807
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
ID: 7054908
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
ID: 12140759
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
ID: 12140809
Sorry, typo there, ammend the SYSTEM_INFO line:

   SYSTEM_INFO siSysInfo;

(insert embarrased emoticon here)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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