Function Reference

DllStructSetData

Sets the data in of an element in the struct.

DllStructSetData ( Struct, Element, value [, index ] )

 

Parameters

Struct The struct returned by DllStructCreate.
Element Which element of the struct you want to access, starting at 1 or the element name as defined in DllStructCreate.
value The new value to place in the struct.
index [optional] For elements that are an array this specifies the 1-based index to set. if omitted or the Default keyword then as much of the value as possible will be set in element starting at index 1 (Useful for quickly setting strings). Not used for non-array elements.

 

Return Value

Success: value, which is read back from the struct.
Failure: 0.
@Error: 0 = No Error.
1 = Struct not a correct struct returned by DllStructCreate.
2 = Element value out of range.
3 = index would be outside of the struct.
4 = Element data type is unknown
5 = index <= 0.

 

Remarks

When the element is char[n], byte[n] or ubyte[n] the data can be a string otherwise it has to be a number.

 

Related

DllStructCreate, DllStructGetData, DllStructGetSize

 

Example


;=========================================================
;   Create the struct
;   struct {
;       int             var1;
;       unsigned char   var2;
;       unsigned int    var3;
;       char            var4[128];
;   }
;=========================================================
$str        = "int;ubyte;uint;char[128]"
$a          = DllStructCreate($str)
if @error Then
    MsgBox(0,"","Error in DllStructCreate " & @error);
    exit
endif

;=========================================================
;   Set data in the struct
;   struct.var1 = -1;
;   struct.var2 = 255;
;   struct.var3 = INT_MAX; -1 will be typecasted to (unsigned int)
;   strcpy(struct.var4,"Hello");
;   struct.var4[0]  = 'h';
;=========================================================
DllStructSetData($a,1,-1)
DllStructSetData($a,2,255)
DllStructSetData($a,3,-1)
DllStructSetData($a,4,"Hello")
DllStructSetData($a,4,Asc("h"),1)

;=========================================================
;   Display info in the struct
;=========================================================
MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($a) & @CRLF & _
        "Struct pointer: " & DllStructGetPtr($a) & @CRLF & _
        "Data:" & @CRLF & _
        DllStructGetData($a,1) & @CRLF & _
        DllStructGetData($a,2) & @CRLF & _
        DllStructGetData($a,3) & @CRLF & _
        DllStructGetData($a,4))

;=========================================================
;   Free the memory allocated for the struct
;=========================================================
$a = 0