Core Function DLLStructGetData

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Remarks)
Line 33: Line 33:
 
When the element is char[n] and index is omitted the data returned is a String, otherwise it returns a number.
 
When the element is char[n] and index is omitted the data returned is a String, otherwise it returns a number.
  
When the element is byte[n] OR ubyte[n] and index is omitted teh data is returned as a Binary Variable example :
+
When the element is byte[n] OR ubyte[n] and index is omitted the data is returned as a Binary Variable example :
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
// Create a struct with a byte array of 20 in size
 
// Create a struct with a byte array of 20 in size

Revision as of 17:57, 29 November 2011

DLLStructGetData( <dllstruct>, <element>, <index> ) 

Contents

Description

Returns 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.

index

Optional; If the element is an array, you need to specify which index to return, otherwise it returns index 0. The first element is 0.

Return Value

Success: Data in the element of the struct.

Failure: 0.

Remarks

Used in DLLCall.

When the element is char[n] and index is omitted the data returned is a String, otherwise it returns a number.

When the element is byte[n] OR ubyte[n] and index is omitted the data is returned as a Binary Variable example :

// Create a struct with a byte array of 20 in size
$Struct = DLLStructCreate("ubyte a[20]; ubyte b[5]");
 
DLLStructSetData($Struct, "a", 12, 0);
DLLStructSetData($Struct, "a", 22, 1);
DLLStructSetData($Struct, "a", 44, 2);
 
DLLStructSetData($Struct, "b", 44, 0);
DLLStructSetData($Struct, "b", 66, 1);
DLLStructSetData($Struct, "b", 88, 2);
 
// Get the whole byte array and store it as Binary data
$BinaryA = DLLStructGetData($Struct, "a");
 
println("\nData in A");
Foreach ($BinaryA as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($i) );
}
 
$BinaryB = DLLStructGetData($Struct, "b");
println("\nData in B");
Foreach ($BinaryB as $i)
{
	println( "Byte: " . $i . " | Hex: " . Hex($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");
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox