Core Function DLLStructSetData
From Sputnik Wiki
DLLStructSetData( <dllstruct>, <element>, <index> )
Contents |
Description
Set the data of an element of the struct
Parameters
dllstruct
The struct returned by DLLStructCreate.
element
Which element of the struct you want to access by its element name as defined in DllStructCreate.
value
Optional; If the element is an array, you need to specify which index to set, otherwise it sets index 0. The first element is 0.
index
Optional; If the element is an array, you need to specify which index to return, otherwise it returns index 1. The first element is 1.
Return Value
None.
Remarks
Used in DLLCall.
When the element is char[n] the data can be a string otherwise it has to be a number.
When the element is byte[n] OR ubyte[n] and index is omitted the byte array can be set using a Binary Variable example :
// Create a struct with a byte array of 20 in size $Struct = DLLStructCreate("byte a[20]"); // Create a binary variable containing "Hello World!" $binaryVar = BinaryFromStr("Hello World!"); // Set the binary variables data to the dll structs variable // This will populate its array DLLStructSetData($Struct, "a", $binaryVar); // Get the whole byte array and store it as Binary data $Binary = DLLStructGetData($Struct, "a"); // Loop through and see what we got Foreach ($Binary as $i) { if(!$i) break; // Break on zero terminator println( "Byte: " . $i . " | Hex: " . Hex($i) . " | Char: " . Chr($i) ); }
Example
/*========================================================= Create the struct struct { int var1; unsigned char var2; unsigned int var3; char var4[128]; } =========================================================*/ $str = "int var1;ubyte var2;uint var3;char var4[128]"; $a = DllStructCreate($str); if ( !$a ) { MsgBox("Error in DllStructCreate"); exit(); } /*========================================================= Set data in the struct struct.var1 = -1; struct.var2 = 255; struct.var3 = 777; strcpy(struct.var4,"Hello"); struct.var4[0] = 'h'; =========================================================*/ DllStructSetData($a,"var1",-1); DllStructSetData($a,"var2",255); DllStructSetData($a,"var3",777); DllStructSetData($a,"var4","Hello"); DllStructSetData($a,"var4","G",0); /*========================================================= Display info in the struct ;=========================================================*/ MsgBox("Struct Size: " . DllStructGetSize($a) . @CRLF . "Struct pointer: " . DllStructGetPtr($a) . @CRLF . "Data:" . @CRLF . DllStructGetData($a,"var1") . @CRLF . DllStructGetData($a,"var2") . @CRLF . DllStructGetData($a,"var3") . @CRLF . DllStructGetData($a,"var4"), "DllStruct");