Jump to content

[resolved]Need Dll expert


spudw2k
 Share

Recommended Posts

Link to comment
Share on other sites

I need some help converting this code to autoit, but I am nay skilled at dll calls. Please help. :)

I haven't answered my request. I forum searched for GetVersionEx and then got the script at

http://www.autoitscript.com/forum/index.ph...ost&p=75019

to return some info.

;#include <DllMem.au3>

#cs
    From MSDN:
    typedef struct _OSVERSIONINFO
    {
    DWORD dwOSVersionInfoSize;
    DWORD dwMajorVersion;
    DWORD dwMinorVersion;
    DWORD dwBuildNumber;
    DWORD dwPlatformId;
    TCHAR szCSDVersion[ 128 ];
    } OSVERSIONINFO;
#ce
;  http://www.autoitscript.com/forum/index.php?s=&showtopic=10710&view=findpost&p=75019
; http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx
; http://msdn.microsoft.com/en-us/library/ms724833(VS.85).aspx
$OSVersionInfo_struct = "dword;dword;dword;dword;dword;char[128]"

$dwOSVersionInfoSize = 1
$dwMajorVersion = 2
$dwMinorVersion = 3
$dwBuildNumber = 4
$dwPlatformId = 5
$szCSDVersion = 6

;DllStructSetDataDataType("long",4)
$p = DllStructCreate($OSVersionInfo_struct)

;think of this as p->dwOSVersionInfoSize = sizeof(OSVERSIONINFO)
DllStructSetData($p, 1, DllStructGetSize($p), 1)
ConsoleWrite(DllStructGetSize($p) & @CRLF)
$ret = DllCall("kernel32.dll", "int", "GetVersionEx", "ptr", DllStructGetPtr($p))
ConsoleWrite($ret[0] & @CRLF)
If Not $ret[0] Then
    MsgBox(0, "DllCall Error", "DllCall Failed")
    Exit
EndIf

$major = DllStructGetData($p, $dwMajorVersion)
$minor = DllStructGetData($p, $dwMinorVersion)
$build = DllStructGetData($p, $dwBuildNumber)
$platform = DllStructGetData($p, $dwPlatformId)
$version = DllStructGetData($p, $szCSDVersion)

;$version    = ""
;While DllStructGetData($p,$i)
;   $version    = $version & Chr(DllStructGetData($p,$i))
;   $i            = $i + 1
;WEnd

MsgBox(0, "", "Major: " & $major & @CRLF & _
        "Minor: " & $minor & @CRLF & _
        "Build: " & $build & @CRLF & _
        "Platform ID: " & $platform & @CRLF & _
        "Version: " & $version)

And I'm no expert.

Link to comment
Share on other sites

I need some help converting this code to autoit, but I am nay skilled at dll calls. Please help. :)

Referring to the example code you would like converted, It appears the structure the DLL call returns to consists of a block of 156 bytes. They call it "hBuf".

This script may explain. And with the results from the above script, other post, you can check if the correct results are returned in this script.

#cs
    From http://techsupt.winbatch.com/ts/T000001060F2.html
    MajorVersion = BinaryPeek4(hBuf,4)   <===== 2nd element/index of DLL Structure
    MinorVersion = BinaryPeek4(hBuf,8)
    BuildNumber = BinaryPeek4(hBuf,12)
    PlatformID = BinaryPeek4(hBuf,16)
    CSDVersion = BinaryPeekStr(hBuf,20,128)
    SPMajorVersion = BinaryPeek2(hBuf,148)
    SPMinorVersion = BinaryPeek2(hBuf,150)
    SuiteMask = BinaryPeek2(hBuf,152)
    ProductType = BinaryPeek(hBuf,154)
#ce
; $OSVersionInfo_struct = 1st Size of structure: 2nd Major byte[1]: rest of info in bytes
$OSVersionInfo_struct = "byte[4];byte[1];byte[151]" ;total must be 156

$p = DllStructCreate($OSVersionInfo_struct)

DllStructSetData($p, 1, DllStructGetSize($p), 1)
ConsoleWrite(DllStructGetSize($p) & @CRLF)
$ret = DllCall("kernel32.dll", "int", "GetVersionEx", "ptr", DllStructGetPtr($p))
ConsoleWrite($ret[0] & @CRLF)
If Not $ret[0] Then
    MsgBox(0, "DllCall Error", "DllCall Failed")
    Exit
EndIf

$major = DllStructGetData($p, 2)
MsgBox(0, "", "Major: " & Dec(Hex($major)))

There is a lot more work to get all the info returned.

Never got to "The SuiteMask field is a bit masked value" looks like once a value is returned, a BitAnd() operation is performed on the return value.

I think it would be easier to create a structure to retrieve all the info individually. Starting with byte[4] -size of Structure, then byte[1];byte[...... With the total number of bytes being 156. There is more than one way of doing this.

Link to comment
Share on other sites

Refer to BitMask:

;===================================================================================================

=================
Func ycmMemGetOsVersion()
    Local $StructVer = DllStructCreate( "dword;dword;dword;dword;dword;char[128];ushort;ushort;ushort;ushort" )
       ; typedef struct _OSVERSIONINFO {
       ; DWORD  dwOSVersionInfoSize;
       ; DWORD  dwMajorVersion;
       ; DWORD  dwMinorVersion;
       ; DWORD  dwBuildNumber;
       ; DWORD  dwPlatformId;
       ; TCHAR  szCSDVersion[ 128 ];
       ; USHORT SPMajorVersion;
       ; USHORT SPMinerVersion;
       ; USHORT SuiteMask;
       ; USHORT ProductType;
       ; } OSVERSIONINFO;
       ; http://msdn.microsoft.com/en-us/library/ms724451(VS.85).aspx

    DllStructSetData( $StructVer , 1 , DllStructGetSize( $StructVer ) , 1 )

    ycmMemGetPtr( $_DLL_PTR_Kernel32 , "Kernel32.dll" , @ScriptLineNumber )

    DllCall( $_DLL_PTR_Kernel32 , "int" , "GetVersionEx" , "ptr" , DllStructGetPtr( $StructVer ) )

    Local $MajorVersion = DllStructGetData( $StructVer , 2 )
    Local $MinorVersion = DllStructGetData( $StructVer , 3 )
    Local $BuildNumber = DllStructGetData( $StructVer , 4 )
    Local $PlatformID = DllStructGetData( $StructVer , 5 )
    Local $CSDVersion = DllStructGetData( $StructVer , 6 )
    Local $SPMajor = DllStructGetData( $StructVer , 7 )
    Local $SPMiner = DllStructGetData( $StructVer , 8 )
    Local $SuiteMask = DllStructGetData( $StructVer , 9 )
    Local $ProductType = DllStructGetData( $StructVer , 10 )

    Local $PlatformStr = String( "" )

    ycmEvalBit( $PlatformID , 0x0 , $PlatformStr , ", " , "Win32S" )
    ycmEvalBit( $PlatformID , 0x1 , $PlatformStr , ", " , "Win32Windows" )
    ycmEvalBit( $PlatformID , 0x2 , $PlatformStr , ", " , "Win32NT" )
    ycmEvalBit( $PlatformID , 0x4 , $PlatformStr , ", " , "WinCE" )
    ycmEvalBit( $PlatformID , 0x8 , $PlatformStr , ", " , "Unix" )
    ycmEvalBit( $PlatformID , 0x10 , $PlatformStr , ", " , "Xbox" )
    ycmEvalBit( $PlatformID , 0x20 , $PlatformStr , ", " , "MacOSX" )

    If StringLen( $PlatformStr ) = 0 Then
        $PlatformStr &= "Undefined"
    EndIf

    Local $SuiteStr = String( "" )

    ycmEvalBit( $SuiteMask , 0x1 , $SuiteStr , ", " , "SMALLBUSINESS" )
    ycmEvalBit( $SuiteMask , 0x2 , $SuiteStr , ", " , "ENTERPRISE" )
    ycmEvalBit( $SuiteMask , 0x4 , $SuiteStr , ", " , "BACKOFFICE" )
    ycmEvalBit( $SuiteMask , 0x8 , $SuiteStr , ", " , "COMMUNICATIONS" )
    ycmEvalBit( $SuiteMask , 0x10 , $SuiteStr , ", " , "TERMINAL" )
    ycmEvalBit( $SuiteMask , 0x20 , $SuiteStr , ", " , "SMALLBUSINESS_RESTRICTED" )
    ycmEvalBit( $SuiteMask , 0x40 , $SuiteStr , ", " , "EMBEDDEDNT" )
    ycmEvalBit( $SuiteMask , 0x80 , $SuiteStr , ", " , "DATACENTER" )
    ycmEvalBit( $SuiteMask , 0x100 , $SuiteStr , ", " , "SINGLEUSERTS" )
    ycmEvalBit( $SuiteMask , 0x200 , $SuiteStr , ", " , "PERSONAL" )
    ycmEvalBit( $SuiteMask , 0x400 , $SuiteStr , ", " , "BLADE" )

    If StringLen( $SuiteStr ) = 0 Then
        $SuiteStr &= "Undefined"
    EndIf

    Local $ProductStr = String( "" )

    ycmEvalBit( $ProductType , 0x0 , $ProductStr , ", " , "An unknown product" )
    ycmEvalBit( $ProductType , 0x1 , $ProductStr , ", " , "Ultimate" )
    ycmEvalBit( $ProductType , 0x2 , $ProductStr , ", " , "Home Basic" )
    ycmEvalBit( $ProductType , 0x3 , $ProductStr , ", " , "Home Premium" )
    ycmEvalBit( $ProductType , 0x4 , $ProductStr , ", " , "Enterprise" )
    ycmEvalBit( $ProductType , 0x5 , $ProductStr , ", " , "Home Basic N" )
    ycmEvalBit( $ProductType , 0x6 , $ProductStr , ", " , "Business" )
    ycmEvalBit( $ProductType , 0x7 , $ProductStr , ", " , "Server Standard (full installation)" )
    ycmEvalBit( $ProductType , 0x8 , $ProductStr , ", " , "Server Datacenter (full installation)" )
    ycmEvalBit( $ProductType , 0x9 , $ProductStr , ", " , "Windows Small Business Server" )
    ycmEvalBit( $ProductType , 0xA , $ProductStr , ", " , "Server Enterprise (full installation)" )
    ycmEvalBit( $ProductType , 0xB , $ProductStr , ", " , "Starter" )
    ycmEvalBit( $ProductType , 0xC , $ProductStr , ", " , "Server Datacenter (core installation)" )
    ycmEvalBit( $ProductType , 0xD , $ProductStr , ", " , "Server Standard (core installation)" )
    ycmEvalBit( $ProductType , 0xE , $ProductStr , ", " , "Server Enterprise (core installation)" )
    ycmEvalBit( $ProductType , 0xF , $ProductStr , ", " , "Server Enterprise for Itanium-based Systems" )
    ycmEvalBit( $ProductType , 0x10 , $ProductStr , ", " , "Business N" )
    ycmEvalBit( $ProductType , 0x11 , $ProductStr , ", " , "Web Server (full installation)" )
    ycmEvalBit( $ProductType , 0x12 , $ProductStr , ", " , "HPC Edition" )
    ycmEvalBit( $ProductType , 0x14 , $ProductStr , ", " , "Storage Server Express" )
    ycmEvalBit( $ProductType , 0x15 , $ProductStr , ", " , "Storage Server Standard" )
    ycmEvalBit( $ProductType , 0x16 , $ProductStr , ", " , "Storage Server Workgroup" )
    ycmEvalBit( $ProductType , 0x17 , $ProductStr , ", " , "Storage Server Enterprise" )
    ycmEvalBit( $ProductType , 0x18 , $ProductStr , ", " , "Windows Server 2008 for Windows Essential Server Solutions" )
    ycmEvalBit( $ProductType , 0x1A , $ProductStr , ", " , "Home Premium N" )
    ycmEvalBit( $ProductType , 0x1B , $ProductStr , ", " , "Enterprise N" )
    ycmEvalBit( $ProductType , 0x1C , $ProductStr , ", " , "Ultimate N" )
    ycmEvalBit( $ProductType , 0x1D , $ProductStr , ", " , "Web Server (core installation)" )
    ycmEvalBit( $ProductType , 0x1E , $ProductStr , ", " , "Windows Essential Business Server Management Server" )
    ycmEvalBit( $ProductType , 0x1F , $ProductStr , ", " , "Windows Essential Business Server Security Server" )
    ycmEvalBit( $ProductType , 0x20 , $ProductStr , ", " , "Windows Essential Business Server Messaging Server" )
    ycmEvalBit( $ProductType , 0x23 , $ProductStr , ", " , "Windows Server 2008 without Hyper-V for Windows Essential Server Solutions" )
    ycmEvalBit( $ProductType , 0x24 , $ProductStr , ", " , "Server Standard without Hyper-V (full installation)" )
    ycmEvalBit( $ProductType , 0x25 , $ProductStr , ", " , "Server Datacenter without Hyper-V (full installation)" )
    ycmEvalBit( $ProductType , 0x26 , $ProductStr , ", " , "Server Enterprise without Hyper-V (full installation)" )
    ycmEvalBit( $ProductType , 0x27 , $ProductStr , ", " , "Server Datacenter without Hyper-V (core installation)" )
    ycmEvalBit( $ProductType , 0x28 , $ProductStr , ", " , "Server Standard without Hyper-V (core installation)" )
    ycmEvalBit( $ProductType , 0x29 , $ProductStr , ", " , "Server Enterprise without Hyper-V (core installation) " )
    ycmEvalBit( $ProductType , 0x2A , $ProductStr , ", " , "Microsoft Hyper-V Server" )

    If StringLen( $ProductStr ) = 0 Then
        $ProductStr &= "Undefined"
    EndIf

    Return "MajorVersion: " & $MajorVersion & " #MinorVersion: " & $MinorVersion & " #BuildNumber: " & $BuildNumber & " #PlatformID: " & $PlatformID & " (" & $PlatformStr & ") #CSDVersion: " & $CSDVersion & " #SPMajor: " & $SPMajor & " #SPMiner: " & $SPMiner & " #SuiteMask: " & $SuiteMask & " (" & $SuiteStr & ") #ProductType: " & $ProductType & " (" & $ProductStr & ")"
EndFunc
Link to comment
Share on other sites

Hi GoodMan,

Would you be able to post a copy of the ycmEvalBit() function, please.

This would give a better understanding of the ycmMemGetOsVersion() function already posted.

Malkey.

Sure.

;===================================================================================================

=================
Func ycmEvalBit( $iv_BitMask , $iv_BitChk , ByRef $iv_VarName , $iv_Separate = ", " , $iv_Description = "" )
    If ( $iv_BitMask = 0x0 AND $iv_BitChk = 0x0 ) OR ( $iv_BitMask >= 0x1 AND $iv_BitChk >= 0x1 AND BitAND( $iv_BitMask , $iv_BitChk ) = $iv_BitChk ) Then
        If StringLen( $iv_VarName ) >= 1 Then
            $iv_VarName &= $iv_Separate
        EndIf

        $iv_VarName &= $iv_Description

        Return 1
    Else
        Return 0
    EndIf
EndFunc
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...