找回密码
 加入
搜索
查看: 113|回复: 3

[AU3基础] DllStructCreate返回的类型不正确

[复制链接]
发表于 2024-5-7 10:36:30 | 显示全部楼层 |阅读模式
Local $short = DllStructCreate("SHORT a")
Local $int = DllStructCreate("INT a")
Local $float = DllStructCreate("FLOAT a")
Local $double = DllStructCreate("DOUBLE a")

ConsoleWrite("short size: " & BinaryLen($short.a) & " bytes" & @CRLF)
ConsoleWrite("int size: " & BinaryLen($int.a) & " bytes" & @CRLF)
ConsoleWrite("float size: " & BinaryLen($float.a) & " bytes" & @CRLF)
ConsoleWrite("double size: " & BinaryLen($double.a) & " bytes" & @CRLF)

$short.a = 1
$int.a = 1
$float.a = 1
$double.a = 1

ConsoleWrite("short value: " & $short.a & @CRLF)
ConsoleWrite("int value: " & $int.a & @CRLF)
ConsoleWrite("float value: " & $float.a & @CRLF)
ConsoleWrite("double value: " & $double.a & @CRLF)

ConsoleWrite("short Hex: " & Hex($short.a) & @CRLF)
ConsoleWrite("int Hex: " & Hex($int.a) & @CRLF)
ConsoleWrite("float Hex: " & Hex($float.a) & @CRLF)
ConsoleWrite("double Hex: " & Hex($double.a) & @CRLF)
定义的short,本来应该是2字节,返回了4字节的int类型
定义的float,本来应该是4字节,返回了8字节的double类型

特别是这个float,正确的4字节hex应该是“3F800000”,结果返回了“3FF0000000000000”,与double一致

这是怎么回事,我哪里搞错了吗?
 楼主| 发表于 2024-5-7 10:37:28 | 显示全部楼层
autoit的版本是3.3.16.1
发表于 2024-5-7 22:39:33 | 显示全部楼层
楼主你理解错了吧:
BinaryLen($short.a)  相当于 BinaryLen(0) ,默认值当做整数来处理,就是4个字节。DllStructGetSize($short)才是真正的大小。
其他同理,自己体会。
 楼主| 发表于 2024-5-8 09:40:15 | 显示全部楼层
haijie1223 发表于 2024-5-7 22:39
楼主你理解错了吧:
BinaryLen($short.a)  相当于 BinaryLen(0) ,默认值当做整数来处理,就是4个字节。Dll ...
Local $short = DllStructCreate("SHORT a")
Local $int = DllStructCreate("INT a")
Local $float = DllStructCreate("FLOAT a")
Local $double = DllStructCreate("DOUBLE a")

; share memory
Local $byte_2_for_short = DllStructCreate("BYTE[2]", DllStructGetPtr($short))
Local $byte_4_for_int = DllStructCreate("BYTE[4]", DllStructGetPtr($int))
Local $byte_4_for_float = DllStructCreate("BYTE[4]", DllStructGetPtr($float))
Local $byte_8_for_double = DllStructCreate("BYTE[8]", DllStructGetPtr($double))

ConsoleWrite("short size: " & DllStructGetSize($short) & " bytes" & @CRLF) ;~ should be 2
ConsoleWrite("int size: " & DllStructGetSize($int) & " bytes" & @CRLF) ;~ should be 4
ConsoleWrite("float size: " & DllStructGetSize($float) & " bytes" & @CRLF) ;~ should be 4
ConsoleWrite("double size: " & DllStructGetSize($double) & " bytes" & @CRLF) ;~ should be 8

$short.a = 1
$int.a = 1
$float.a = 1
$double.a = 1

; 返回值与预期一致了

Local $hexStringForShort = DllStructGetData($byte_2_for_short, 1)
Local $hexStringForInt = DllStructGetData($byte_4_for_int, 1)
Local $hexStringForFloat = DllStructGetData($byte_4_for_float, 1)
Local $hexStringForDouble = DllStructGetData($byte_8_for_double, 1)

ConsoleWrite("short Hex: 0x" & Hex($hexStringForShort) & @CRLF) ;~ should be 0x0001
ConsoleWrite("int Hex: 0x" & Hex($hexStringForInt) & @CRLF) ;~ should be 0x00000001
ConsoleWrite("float Hex: 0x" & Hex($hexStringForFloat) & @CRLF) ;~ should be 0x3f800000
ConsoleWrite("double Hex: 0x" & Hex($hexStringForDouble) & @CRLF) ;~ should be 0x3ff0000000000000

谢谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-20 06:52 , Processed in 0.099413 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表