DllStructCreate返回的类型不正确
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一致
这是怎么回事,我哪里搞错了吗?
autoit的版本是3.3.16.1 楼主你理解错了吧:
BinaryLen($short.a)相当于 BinaryLen(0) ,默认值当做整数来处理,就是4个字节。DllStructGetSize($short)才是真正的大小。
其他同理,自己体会。 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", DllStructGetPtr($short))
Local $byte_4_for_int = DllStructCreate("BYTE", DllStructGetPtr($int))
Local $byte_4_for_float = DllStructCreate("BYTE", DllStructGetPtr($float))
Local $byte_8_for_double = DllStructCreate("BYTE", 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
谢谢
页:
[1]