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
谢谢 |