Opened 16 years ago
Closed 16 years ago
#1288 closed Bug (Fixed)
DLLStructSetData behavior with binary variant data
| Reported by: | evilertoaster | Owned by: | Valik |
|---|---|---|---|
| Milestone: | 3.3.1.6 | Component: | AutoIt |
| Version: | 3.3.0.0 | Severity: | None |
| Keywords: | Cc: |
Description (last modified by )
As demonstrated in this thread
There might be some expected behavior when using DLLStructSetData with binary variants. Some examples:
Consider $a:
$a=DllStructCreate('byte[4]')
These two lines:
DllStructSetData($a,1,Binary('0xAABB'),2)
and
DllStructSetData($a,1,Number(Binary('0xAABB'),2)
Produce different results. (The first only sets 0xAA).
DllStructSetData($a,1,Binary('0xFFFFFFFF'),1)
and
DllStructSetData($a,1,Binary('0xFFFFFFFF'))
Also produce different results, the first only sets 0xFF. Even though according to the documentation, omitting the 1 as the index argument should be identical to specifying 1.
Help file says:
"If the element is an array, you need to specify which index to set, otherwise it sets index 1."
Attachments (0)
Change History (4)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
| Description: | modified (diff) |
|---|
comment:3 by , 16 years ago
From my reply on the forum:
This is a documentation error. The documentation claims that the index defaults to 1 when not specified. This is wrong. AutoIt defaults to writing as much of the source string into as much of the destination buffer as it can. That's why these two lines behave differently:
Local $a=DllStructCreate('byte[4]')
DllStructSetData($a,1,Binary('0xAABB'), 1) ; Writes only 0xAA because it was explicitly told to write to index 1.
ConsoleWrite(DllStructGetData($a, 1) & @CRLF)
DllStructSetData($a,1,Binary('0xAABB')) ; Writes the entire string.
ConsoleWrite(DllStructGetData($a, 1) & @CRLF)
I will correct the documentation to describe the actual behavior.
comment:4 by , 16 years ago
| Milestone: | → 3.3.1.6 |
|---|---|
| Owner: | set to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [5373] in version: 3.3.1.6

Sorry I didn't check the claims made in the post avidly enough. The 2nd and 3rd code blocks do set the same data, but DllStructSetData($a,1,0xAABB,2) sets it differently. to me, I would have though all 3 to set the data to: 0xFFAABBFF.