Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Function call to get Processor Speed and Type?

Posted on 2002-05-28
10
Medium Priority
?
948 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
9 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
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…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

810 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