bittware Posted July 19, 2010 Share Posted July 19, 2010 (edited) Hello experts, I came across a weird situation. $data_byte_struct = DllStructCreate("int data_byte") $data_byte_ptr = DllStructGetPtr($data_byte_struct, 1) ConsoleWrite("$data_byte_ptr->" &$data_byte_ptr& @CRLF) $re_stat = DllCall($hDll, "int:cdecl", "sub_spi_config", "ptr", $hSubHandle, "int", 0, "int*", $data_byte_ptr);just get SPI config $re_stat_value = $re_stat[3] ConsoleWrite("SPI Config READ Content from Return Array->" & $re_stat_value & @CRLF) ConsoleWrite("SPI Config READ Content from Struct->" &"0x"&Hex(DllStructGetData($data_byte_struct,1), 4)& @CRLF) I use two different methods to watch data_byte_ptr pointer content. They should be with identical result. But why does the first print out the right content which is assigned within DLL function, whereas the second always print out 0x0000? Could anyone figure that out? Thanks. BRs, bittware Edited July 19, 2010 by bittware Link to comment Share on other sites More sharing options...
ProgAndy Posted July 19, 2010 Share Posted July 19, 2010 (edited) This is really simple. When using int*, AutoIt already creates an "internal int-structure ", you must not create it on your own. This is the result of your code: -> pointer to integer (internal) | <- function gets this pointer -> integer (holds pointer to your struct) | ... and sets the integer here -> integer (in your struct) | ... this int is never reached PS: assigning a pointer to an int does not work in x64-mode. (Pointer is 64bit wide, int onyl 32bit). In 32bit, both types have the same length of 32bits. Edited July 19, 2010 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
bittware Posted July 19, 2010 Author Share Posted July 19, 2010 This is really simple. When using int*, AutoIt already creates an "internal int-structure ", you must not create it on your own. This is the result of your code: -> pointer to integer (internal) | <- function gets this pointer -> integer (holds pointer to your struct) | ... and sets the integer here -> integer (in your struct) | ... this int is never reached PS: assigning a pointer to an int does not work in x64-mode. (Pointer is 64bit wide, int onyl 32bit). In 32bit, both types have the same length of 32bits. I am not sure 100% get your points. Do you mean function just changes the integer(the struct pointer) inside function (internally)? Once function returns, integer in the struct, which is outside function, is still kept unchanged? Link to comment Share on other sites More sharing options...
trancexx Posted July 19, 2010 Share Posted July 19, 2010 You have two threads about the same thing. Cool. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
bittware Posted July 20, 2010 Author Share Posted July 20, 2010 I understood. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now