?
Solved

Function call to get Processor Speed and Type?

Posted on 2002-05-28
10
Medium Priority
?
946 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

771 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