Solved

Detecting single/dual processors

Posted on 2001-06-08
5
158 Views
Last Modified: 2010-04-02
Visual C++ 6.0, Windows NT 4.0 and Windows 2000

Does anybody know how to detect for how many processors are in the system?

This should be easy, but I can't seem to find it anywhere.

0
Comment
Question by:Mcplanck
  • 3
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6169438
Simply use 'GetSystemInfo()" - it fills in a 'SYSTEM_INFO' struct that has a member 'dwNumberOfProcessors'

0
 
LVL 86

Expert Comment

by:jkr
ID: 6169443
BTW, here's a sample:

SYSTEM_INFO si;

GetSystemInfo ( &si);

printf ( "Number of Processors: %d", si.dwNumberOfProcessors);
0
 
LVL 86

Expert Comment

by:jkr
ID: 6169450
See also the API reference at http://msdn.microsoft.com/library/psdk/sysmgmt/sysinfo_3t67.htm and the article 'Getting Hardware Information' (http://msdn.microsoft.com/library/psdk/sysmgmt/sysinfo_9ige.htm):

SYSTEM_INFO siSysInfo;   // struct. for hardware information
int aTabs[1] = {260};    // tab stop for TabbedTextOut
 
TCHAR tchBuffer[BUFFER]; // buffer for expanded string
int nSize;               // size of string
 
// Display the "hardware information" header.
 
nSize = sprintf(tchBuffer,
    "Hardware information:");
TextOut(hdc, 15, 20, tchBuffer, nSize);
 
// Copy the hardware information to the SYSTEM_INFO structure.
 
GetSystemInfo(&siSysInfo);
 
// Display the contents of the SYSTEM_INFO structure.
 
nSize = sprintf(tchBuffer,
    "OEM ID: %u\tNumber of Processors: %u",
    siSysInfo.dwOemId,
    siSysInfo.dwNumberOfProcessors);
TabbedTextOut(hdc, 25, 40, tchBuffer,
    nSize, 1, aTabs, 25);
 
nSize = sprintf(tchBuffer,
    "Page size: %u\tProcessor Type: %u",
    siSysInfo.dwPageSize,
    siSysInfo.dwProcessorType);
TabbedTextOut(hdc, 25, 60, tchBuffer,
    nSize, 1, aTabs, 25);
 
nSize = sprintf(tchBuffer,
    "Minimum app address: %lx\tMaximum app address: %lx",
    siSysInfo.lpMinimumApplicationAddress,
    siSysInfo.lpMaximumApplicationAddress);
TabbedTextOut(hdc, 25, 80, tchBuffer,
    nSize, 1, aTabs, 25);
 
nSize = sprintf(tchBuffer,
    "Active processor mask: %u",
    siSysInfo.dwActiveProcessorMask);
TextOut(hdc, 25, 100, tchBuffer, nSize);
0
 

Author Comment

by:Mcplanck
ID: 6170269
Doh!

Thanks dude, I was looking under OSInfo, not System info!

0
 
LVL 30

Expert Comment

by:Axter
ID: 6170348
MS doesn't make it easy for anyone to look up stuff.

You think they would have cross reference it.  But that would make things to easy for us programmers. And we can't have that. :-)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to copy an image file into clipboard C/C++? 1 170
Better understanding on C++ Class serialization and formats 9 65
Safe conversion? 4 69
designing in object programming 12 79
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

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