Home > Blockchain >  kernel32 GetSystemInfo not returning info
kernel32 GetSystemInfo not returning info

Time:07-12

All of the SI fields are 0 after the call to GetSystemInfo in the code below, that's the issue I am trying to solve here.

This is about the same code as several examples which can be found with a quick web search on GetSystemInfo, so I do not think the code itself is at fault:

Private Structure SYSTEM_INFO
    Public dwOemID As Long
    Public dwPageSize As Long
    Public lpMinimumApplicationAddress As Long
    Public lpMaximumApplicationAddress As Long
    Public dwActiveProcessorMask As Long
    Public dwNumberOfProcessors As Long
    Public dwProcessorType As Long
    Public dwAllocationGranularity As Long
    Public wProcessorLevel As Integer
    Public wProcessorRevision As Integer
End Structure

Private Declare Sub GetSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)

Private Sub GetProcessorInfo()
    Dim SI As SYSTEM_INFO
    Dim tmp As String

    Call GetSystemInfo(SI)   

    Select Case SI.dwProcessorType
        Case PROCESSOR_INTEL_386 : tmp = "386"
        Case PROCESSOR_INTEL_486 : tmp = "486"
        Case PROCESSOR_INTEL_PENTIUM : tmp = "Pentium"
        Case PROCESSOR_MIPS_R4000 : tmp = "MIPS 4000"
        Case PROCESSOR_ALPHA_21064 : tmp = "Alpha"
    End Select    

    Select Case SI.wProcessorLevel
        Case PROCESSOR_LEVEL_80386 : tmp = "Intel 80386"
        Case PROCESSOR_LEVEL_80486 : tmp = "Intel 80486"
        Case PROCESSOR_LEVEL_PENTIUM : tmp = "Intel Pentium"
        Case PROCESSOR_LEVEL_PENTIUMII : tmp = "Intel Pentium Pro, II, III or 4"
    End Select

End Sub

I am testing this code in a debug session from a unit test. OS is Windows 10, VS Enterprise 2019.

EDIT: Code was converted from VB6 to VB.Net, there might be an issue with the Structure, which was initially a Type, or the type of the contained data, or the way it is passed to GetSystemInfo.

CodePudding user response:

There are a number of errors in your definitions

  • DWORD should be Integer
  • WORD should be Short
  • LPVOID and DWORD_PTR should be IntPtr
  • You need to pass a reference to your structure, use <Out()> ByRef
Private Structure SYSTEM_INFO
    Public dwOemID As Integer
    Public dwPageSize As Integer
    Public lpMinimumApplicationAddress As IntPtr
    Public lpMaximumApplicationAddress As IntPtr
    Public dwActiveProcessorMask As IntPtr
    Public dwNumberOfProcessors As Integer
    Public dwProcessorType As Integer
    Public dwAllocationGranularity As Integer
    Public wProcessorLevel As Short
    Public wProcessorRevision As Short
End Structure

Private Declare Sub GetSystemInfo Lib "kernel32" (<Out()> ByRef lpSystemInfo As SYSTEM_INFO)
  • Related