我需要使用公共结构" _PROCESSOR_INFO_UNION"? 没有它" dwNumberOfProcessors"返回15而不是实际数量的处理器,但是当它使用它时返回4
Imports System.Runtime.InteropServices Public Class Form1
<DllImport("kernel32.dll")> _
Public Shared Sub GetSystemInfo(<MarshalAs(UnmanagedType.Struct)> ByRef lpSystemInfo As SYSTEM_INFO)
End Sub
<StructLayout(LayoutKind.Sequential)> _
Public Structure SYSTEM_INFO
Friend uProcessorInfo As _PROCESSOR_INFO_UNION
Public dwPageSize As UInteger
Public lpMinimumApplicationAddress As IntPtr
Public lpMaximumApplicationAddress As IntPtr
Public dwActiveProcessorMask As IntPtr
Public dwNumberOfProcessors As UInteger
Public dwProcessorType As UInteger
Public dwAllocationGranularity As UInteger
Public dwProcessorLevel As UShort
Public dwProcessorRevision As UShort
End Structure
<StructLayout(LayoutKind.Explicit)> _
Public Structure _PROCESSOR_INFO_UNION
'<FieldOffset(0)> _
'Friend dwOemId As UInteger
'<FieldOffset(0)> _
'Friend wProcessorArchitecture As UShort
'<FieldOffset(2)> _
'Friend wReserved As UShort
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim infos As New SYSTEM_INFO
GetSystemInfo(infos)
TextBox2.Text = (infos.dwNumberOfProcessors)
End Sub
End Class
答案 0 :(得分:0)
因为dwNumberOfProcessors在现代cpu上运行不正常而_PROCESSOR_INFO_UNION修复了它
答案 1 :(得分:0)
现代处理器可以拥有virtual
内核,因此您需要在机器上找到实际数量的物理处理器,您必须使用这种语法。
我很久以前就C#代码的这种情况问了一个类似的问题,在那里我得到了一个关于如何调用它的很好的答案: