0

for a what I need to use Public Structure "_PROCESSOR_INFO_UNION"? Without it "dwNumberOfProcessors" returns 15 instead of real number of processors, but when it used it's returns 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
lfreedoml
  • 55
  • 6
  • I the function' declaration use it.... Why not use it? Maybe you can check this: http://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c – Morcilla de Arroz Mar 17 '15 at 07:51
  • possible duplicate of [Get hardware information such as Graphic Card capabilities](http://stackoverflow.com/questions/26079786/get-hardware-information-such-as-graphic-card-capabilities). Just use `Win32_ComputerSystem` and `Win32_Processor` to get CPU info – Ňɏssa Pøngjǣrdenlarp Mar 17 '15 at 12:35
  • @ good, but i need to use dwNumberOfProcessors – lfreedoml Mar 17 '15 at 13:34

2 Answers2

0

Because dwNumberOfProcessors works improperly on modern cpu and _PROCESSOR_INFO_UNION fix it

lfreedoml
  • 55
  • 6
0

The modern processors can have a virtual cores, and there fore to get actual number of physical processors found on the machine you have to use such syntax.

I've asked a similar question time ago about such situation for C# code, and there I got a great answer about how to invoke it:

PInvoke for GetLogicalProcessorInformation Function

Community
  • 1
  • 1
VMAtm
  • 27,943
  • 17
  • 79
  • 125