Jump to content
Sign in to follow this  
LeeRekka

Help with DllStructSetData()

Recommended Posts

LeeRekka

Hello,

why only byte work? how set data for short or int?,

I thank you at once

Example:

$d = Binary("0x00112233445566778899AABBCCDDEEFF")
$s = BinaryLen($d)

;   BYTE 8bit(1byte) unsigned char

$dsc = DllStructCreate("byte data[" & $s & "]")
DllStructSetData($dsc,"data",$d)
ConsoleWrite("byte: ")
For $i = 1 To $s Step 1
    $dsgd = DllStructGetData($dsc, "data",$i)
    ConsoleWrite(Hex($dsgd,2) & " ")
Next
ConsoleWrite(@CRLF)

;   short 16bit(2bytes) signed integer

$dsc = DllStructCreate("short data[" & $s & "]")
DllStructSetData($dsc,"data",$d)
ConsoleWrite("short: ")
For $i = 1 To $s Step 1
    $dsgd = DllStructGetData($dsc, "data",$i)
    ConsoleWrite(Hex($dsgd,4) & " ")
Next
ConsoleWrite(@CRLF)

;   USHORT 16bit(2bytes) unsigned integer

$dsc = DllStructCreate("ushort data[" & $s & "]")
DllStructSetData($dsc,"data",$d)
ConsoleWrite("ushort: ")
For $i = 1 To $s Step 1
    $dsgd = DllStructGetData($dsc, "data",$i)
    ConsoleWrite(Hex($dsgd,4) & " ")
Next
ConsoleWrite(@CRLF)

;   int 32bit(4bytes) signed integer 

$dsc = DllStructCreate("int data[" & $s & "]")
DllStructSetData($dsc,"data",$d)
ConsoleWrite("int: ")
For $i = 1 To $s Step 1
    $dsgd = DllStructGetData($dsc, "data",$i)
    ConsoleWrite(Hex($dsgd,8) & " ")
Next
ConsoleWrite(@CRLF)

;   UINT 32bit(4bytes) unsigned integer 

$dsc = DllStructCreate("uint data[" & $s & "]")
DllStructSetData($dsc,"data",$d)
ConsoleWrite("uint: ")
For $i = 1 To $s Step 1
    $dsgd = DllStructGetData($dsc, "data",$i)
    ConsoleWrite(Hex($dsgd,8) & " ")
Next
ConsoleWrite(@CRLF)

Share this post


Link to post
Share on other sites
Yashied

$bData = Binary('0x00112233445566778899AABBCCDDEEFF')
$iLen = BinaryLen($bData)

; "byte" 8bit(1byte) unsigned char

$tByte = DllStructCreate('byte Data[' & $iLen & ']')
DllStructSetData($tByte, 'Data', $bData)

ConsoleWrite('byte: ')
For $i = 1 To $iLen
    ConsoleWrite(Hex(DllStructGetData($tByte, 'Data', $i), 2) & ' ')
Next
ConsoleWrite(@CRLF)

; "int" 32bit(4bytes) signed integer

$tInt = DllStructCreate('int Data[' & Round($iLen / 4) & ']', DllStructGetPtr($tByte))

ConsoleWrite('int:  ')
For $i = 1 To Round($iLen / 4)
    ConsoleWrite(Hex(DllStructGetData($tInt, 'Data', $i)) & ' ')
Next
ConsoleWrite(@CRLF)

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.