Miha
Miha

Reputation: 73

Getting number of CPUs on Windows with realbasic

I tried using WMI, but with no success so far.

Dim objLocator As New OLEObject("WbemScripting.SWbemLocator")
Dim objService As OLEObject
objService = objLocator.ConnectServer(".", "root\cimv2")
Dim instances As OLEObject
instances = objService.InstancesOf("Win32_ComputerSystem")

Whatever I try to do next trigers an OLE exception. Is there any other known way of getting a CPU count programaticly from REALbasic. I know I could execute a vbscript from the shell class, but it's a bit too ugly for me.

Upvotes: 2

Views: 404

Answers (1)

Norbert Willhelm
Norbert Willhelm

Reputation: 2609

You can call the GetSystemInfo function and use the dwNumberOfProcessors member of the SYSTEM_INFO structure.

Have a look at the following example code:

  Declare Sub GetSystemInfo Lib "kernel32" Alias "GetSystemInfo" (lpSystemInfo As Ptr)

  Dim SystemInfo as MemoryBlock=new MemoryBlock(36)
  GetSystemInfo(SystemInfo)
  Dim ProcessorCount as Integer=SystemInfo.Long(20)

The SYSTEM_INFO structure has a size of 36 Bytes. The members before dwNumberOfProcessors have a size of 20 bytes.

Upvotes: 3

Related Questions