【问题标题】:Getting number of CPUs on Windows with realbasic使用 realbasic 在 Windows 上获取 CPU 数量
【发布时间】:2011-11-13 14:24:06
【问题描述】:

我尝试使用 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,但它对我来说有点太丑了。

【问题讨论】:

    标签: windows wmi realbasic


    【解决方案1】:

    您可以调用GetSystemInfo 函数并使用SYSTEM_INFO structuredwNumberOfProcessors 成员。

    看看下面的示例代码:

      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-07-13
      • 1970-01-01
      • 2016-09-06
      • 1970-01-01
      • 1970-01-01
      • 2010-11-26
      • 1970-01-01
      • 2020-10-18
      • 1970-01-01
      相关资源
      最近更新 更多