Jump to content

How would I use this Windows structure?


Recommended Posts

I'm experimenting with various Windows functions and structures. I am currently trying to use the SystemInfo struct and GetSystemInfo function.

SYSTEM_INFO Structure

GetSystemInfo Function

The definition of the SystemInfo struct is:

typedef struct _SYSTEM_INFO 
{
    union 
    {
        DWORD dwOemId;
        struct 
        {
            WORD wProcessorArchitecture;
            WORD wReserved;
        } ;
    } ;
    DWORD dwPageSize;
    LPVOID lpMinimumApplicationAddress;
    LPVOID lpMaximumApplicationAddress;
    DWORD_PTR dwActiveProcessorMask;
    DWORD dwNumberOfProcessors;
    DWORD dwProcessorType;
    DWORD dwAllocationGranularity;
    WORD wProcessorLevel;
    WORD wProcessorRevision;
} SYSTEM_INFO;

I think the problem is the union. I don't know how to properly implement this in AutoIt? MSDN says the dwOemId is obsolete. How would I use this struct in AutoIt please?

I have an example of what I've tried currently. The script hangs on DllCall().

*edit* newest revision returns an array from dllcall, so i think I fixed it!

Global Const $tagSystemInfo = _
        "word ProcessorArchitecture;" & _
        "word Reserved;" & _
        "dword PageSize;" & _
        "ptr MinimumApplicationAddress;" & _
        "ptr MaximumApplicationAddress;" & _
        "dword_ptr ActiveProcessorMask;" & _
        "dword NumberOfProcessors;" & _
        "dword ProcessorType;" & _
        "dword AllocationGranularity;" & _
        "word ProcessorLevel;" & _
        "word ProcessorRevision"

Global Const $SystemInfo = DllStructCreate($tagSystemInfo)

Global Const $ptrSystemInfo = DllStructGetPtr($SystemInfo)

Switch @CPUArch
    Case "X64"
        Global $GetSystemInfo = "GetNativeSystemInfo"
    Case Else
        $GetSystemInfo = "GetSystemInfo"
EndSwitch

Global Const $Result = DllCall("Kernel32.dll", "none", $GetSystemInfo, "ptr", $ptrSystemInfo)

; display the system information
Global Const $Arch = DllStructGetData($SystemInfo, "ProcessorArchitecture")
Global Const $Type = DllStructGetData($SystemInfo, "ProcessorType")

ConsoleWrite( _
        "Processor Architecture : " & DisplayArchName($Arch) & @LF & _
        "PageSize   : " & DllStructGetData($SystemInfo, "PageSize") & @LF & _
        "MinimumApplicationAddress : " & DllStructGetData($SystemInfo, "MinimumApplicationAddress") & @LF & _
        "MaximumApplicationAddress : " & DllStructGetData($SystemInfo, "MaximumApplicationAddress") & @LF & _
        "ActiveProcessorMask    : " & DllStructGetData($SystemInfo, "ActiveProcessorMask") & @LF & _
        "NumberOfProcessors     : " & DllStructGetData($SystemInfo, "NumberOfProcessors") & @LF & _
        "ProcessorType  : " & DisplayArchType($Type) & @LF & _
        "AllocationGranularity  : " & DllStructGetData($SystemInfo, "AllocationGranularity") & @LF & _
        "ProcessorLevel     : " & DllStructGetData($SystemInfo, "ProcessorLevel") & @LF & _
        "ProcessorRevision  : " & DllStructGetData($SystemInfo, "ProcessorRevision") & @LF)

Func DisplayArchName(Const $_Arch)
    Local Const $StrideKey = 2
    Local Const $ProcessorArchs[8] = [0, "INTEL", 6, "IA64", 9, "AMD64", 0xFFFF, "UNKNOWN"]

    For $i = 0 To 6 Step $StrideKey
        If $_Arch = $ProcessorArchs[$i] Then
            Return $ProcessorArchs[$i + 1]
            ExitLoop
        EndIf
    Next
EndFunc ;==>DisplayArchName

Func DisplayArchType(Const $_Type)
    Local Const $PROCESSOR_INTEL_386 = 386
    Local Const $PROCESSOR_INTEL_486 = 486
    Local Const $PROCESSOR_INTEL_PENTIUM = 586
    Local Const $PROCESSOR_INTEL_IA64 = 2200
    Local Const $PROCESSOR_AMD_X8664 = 8664
    Local Const $StrideKey = 2
    Local Const $ProcessorTypes[10] = [$PROCESSOR_INTEL_386, "INTEL_386", $PROCESSOR_INTEL_486, "INTEL_486", $PROCESSOR_INTEL_PENTIUM, "INTEL_PENTIUM", $PROCESSOR_INTEL_IA64, "INTEL_IA64", $PROCESSOR_AMD_X8664, "AMD_X8664"]

    For $i = 0 To 8 Step $StrideKey
        If $_Type = $ProcessorTypes[$i] Then
            Return $ProcessorTypes[$i + 1]
            ExitLoop
        EndIf
    Next
EndFunc ;==>DisplayArchType
Edited by jaberwocky6669
Link to comment
Share on other sites

union means you can write your structure to be this or that. (those aren't links)

If you want two words, you create structure with two words and if you want one dword you create another structure with one dword instead two words. It's all matter of interpretation of read data.

There is nothing mysterious about unions.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Ah, thanks for your reply!

Well, I said that this was solved but now I have to reopen the case. The ProcesserArchitecture returns zero.

Processor Architecture: 0
PageSize: 4096
MinimumApplicationAddress: 65536
MaximumApplicationAddress: 4294901759
ActiveProcessorMask: 3
NumberOfProcessors: 2
ProcessorType: 586
AllocationGranularity: 65536
ProcessorLevel: 15
ProcessorRevision: 27394

Ow wow, I'm dumb, I figured it out.

Scratch that, the ProcessorArchitecture should return 9 on my system because I am using an x64 AMD.

Edited by jaberwocky6669
Link to comment
Share on other sites

Scratch what?

The original or already scratched?

Global Const $tagSystemInfo = "word ProcessorArchitecture;" & _
        "word Reserved;" & _
        "dword PageSize;" & _
        "ptr MinimumApplicationAddress;" & _
        "ptr MaximumApplicationAddress;" & _
        "dword_ptr ActiveProcessorMask;" & _
        "dword NumberOfProcessors;" & _
        "dword ProcessorType;" & _
        "dword AllocationGranularity;" & _
        "word ProcessorLevel;" & _
        "word ProcessorRevision"
;...

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

OK Trancexx, I used your structure instead but I'm still getting 0 for the processor architecture.

I also get 586 for the processor type which means PROCESSOR_INTEL_PENTIUM. I think I should get 8664 because I'm running an x64 AMD. Any body out there in AutoIt land know what's up?

Ohhhhh! I have to call the GetNativeSystemInfo function!!!!!!!!!!!!

YUP! That's what it was! Thanks Trancexx for your helpful insights!

Edited by jaberwocky6669
Link to comment
Share on other sites

OK Trancexx, I used your structure instead but I'm still getting 0 for the processor architecture.

I also get 586 for the processor type which means PROCESSOR_INTEL_PENTIUM. I think I should get 8664 because I'm running an x64 AMD. Any body out there in AutoIt land know what's up?

I don't know about AutoIt land but I do know about this. Call GetNativeSystemInfo.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...