crashdemons Posted September 20, 2008 Share Posted September 20, 2008 (edited) okay, well, I'm having a little issue in one of my DLLStructs where changing one element of the struct, without changing the byte length, changes the value of all the elements that follow. Technical details: AutoIt 3.2.12.1 32-bit WinXP SP2. Applied concepts/premises: Data strings can by put into structures to format the data the way you want by loading it into a structure and creating another structure using the original struct's pointer. Post by Smoke_N --- ULong and UByte Var[4] both have a byte length of 4 Help File, DllStructGetData ubyte 8bit(1byte) unsigned char ulong 32bit(4bytes) unsigned integer Tests, (see scripts attached below for more info on the "results") Test A: Here we declare a 5-element structure from the data loaded from a file (simulated here with a string) and output the value of each element. As you see the $FileData has been written so certain bytes should fall in certain struct fields, for ease of viewing. -Expected results i: 26985 j: 0x6a6a6a6a data1: 11 data2: 22 value: vvvv -Actual results same as expected, this is our control group. Test B: Here we form a test exactly like Test A with the exception that 'ubyte j[4]' is now 'ulong j' -Expected results i: 26985 j: ? (0x6a6a6a6a as ulong) data1: 11 data2: 22 value: vvvv -Actual results j: 825422090 (?) data1: 22 data2: vv value: vv&B As you can see, the results from Test B don't exactly meet my expectations - am I at fault here for some misunderstanding? Test scripts attached: Edited September 20, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
martin Posted September 20, 2008 Share Posted September 20, 2008 expandcollapse popupGlobal $tStruct='align 2;short i;ulong j;ubyte data1[2];ubyte data2[2];ubyte value[4]' $FileData='iijjjj1122vvvv';simulated for this PoC $StructA=DllStructCreate('ubyte data[14]') DllStructSetData($StructA,1,$FileData) $PointerA=DllStructGetPtr($StructA) $StructB=DllStructCreate($tStruct,$PointerA);put the FileData into the prefered structure, as posted in past threads ;i'd dispose of $StructA here, but doing so or ending it's existance ;(including closing a function) changes StructB's value - which is aggravating but unrelated to this issue MsgBox(0,'StructB Values', _ 'i: '&DllStructGetData($StructB,1)&@CRLF& _ 'j: '& '0x' & Hex(DllStructGetData($StructB,2))&@CRLF& _ 'data1: '&BinaryToString(DllStructGetData($StructB,3))&@CRLF& _ 'data2: '&BinaryToString(DllStructGetData($StructB,4))&@CRLF& _ 'value: '&BinaryToString(DllStructGetData($StructB,5))) ;====================================================================align 2 Global $tStruct='short i;ubyte j[4];ubyte data1[2];ubyte data2[2];ubyte value[4]' $FileData='iijjjj1122vvvv';simulated for this PoC $StructA=DllStructCreate('ubyte data[14]') DllStructSetData($StructA,1,$FileData) $PointerA=DllStructGetPtr($StructA) $StructB=DllStructCreate($tStruct,$PointerA);put the FileData into the prefered structure, as posted in past threads ;i'd dispose of $StructA here, but doing so or ending it's existance ;(including closing a function) changes StructB's value - which is aggravating but unrelated to this issue MsgBox(0,'StructB Values', _ 'i: '&DllStructGetData($StructB,1)&@CRLF& _ 'j: '& DllStructGetData($StructB,2)&@CRLF& _ 'data1: '&BinaryToString(DllStructGetData($StructB,3))&@CRLF& _ 'data2: '&BinaryToString(DllStructGetData($StructB,4))&@CRLF& _ 'value: '&BinaryToString(DllStructGetData($StructB,5))) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
crashdemons Posted September 23, 2008 Author Share Posted September 23, 2008 (edited) Thanks, that helps alot - I see the small mention of 'align' in the help file with the example By default, a structure alignment of 8 is used...DllStructCreate("short;int"); structure is 8 bytes, the "int" is at offset 4 DllStructCreate("align 2;short;int"); structure is 6 bytes, the "int" is at offset 2 Although that didn't explain to me what was going on, or more importantly, which alignment to use when... I read this article on Wikipedia about Data Structure alignment, but it didn't really help me visualize the process. Edited September 23, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) 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