2

我尝试使用 WMI,但到目前为止没有成功。

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")

无论我接下来尝试做什么都会触发 OLE 异常。是否有任何其他已知方法可以从 REALbasic 以编程方式获取 CPU 计数。我知道我可以从 shell 类执行一个 vbscript,但这对我来说有点难看。

4

1 回答 1

3

您可以调用GetSystemInfo函数并使用SYSTEM_INFO 结构的dwNumberOfProcessors成员。

看看下面的示例代码:

  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)

SYSTEM_INFO 结构的大小为 36 字节。dwNumberOfProcessors 之前的成员大小为 20 字节。

于 2011-11-13T15:09:59.420 回答