Core Function DLLStructCreateDef
DLLStructCreateDef( <name>, <def string> )
Contents |
Description
Creates a named C/C++ style structure definition that can be used with DLLStructCreate and can also be placed inside other DLLStructs.
Parameters
name
Name of the DLLStruct to create for use later in DLLStructCreate using this name
def string
A string representing the structure to create (See DLLStructCreate for full details).
Return Value
Success: 1.
Failure: 0.
Remarks
Used in DLLCall.
This will create the DLLStruct definition similar to a prototype in C/C++ once it has been made you can use its name to create new structs or place its name inside a struct to create more of them.
You can then get/set data from the struct and even structs deep inside other structs.
However you must make sure you never include a struct that will include your struct else that will cause an infinite loop.
Example
// Create a struct definition to be used later DLLStructCreateDef("POINT", "int x;int y"); // Create a new struct using the name of the struct def we just made $Struct = DLLStructCreate("POINT"); // $Struct now contains a POINT struct println( "Size: " . DLLStructGetSize($Struct) ); // Show its size // Set its data DLLStructSetData($Struct, "x", 333); DLLStructSetData($Struct, "y", 444); // Get its data $x = DLLStructGetData($Struct, "x"); $y = DLLStructGetData($Struct, "y"); // Print its data println("X: $x"); println("Y: $y");
This example has a struct inside a struct and shows how to get/set its data
// Create the struct definitions to be used later DLLStructCreateDef("TEST", "int a;int b"); DLLStructCreateDef("POINT", "int x;int y;TEST t"); // Create a new struct using the name of the struct def we just made $Struct = DLLStructCreate("POINT"); // $Struct now contains a POINT struct println( "Size: " . DLLStructGetSize($Struct) ); // Show its size // Set its data DLLStructSetData($Struct, "x", 333); DLLStructSetData($Struct, "y", 444); // Set data of the included struct DLLStructSetData($Struct, "t->a", 555); DLLStructSetData($Struct, "t->b", 777); // Get its data $x = DLLStructGetData($Struct, "x"); $y = DLLStructGetData($Struct, "y"); // Get data of the included struct $ta = DLLStructGetData($Struct, "t->a"); $tb = DLLStructGetData($Struct, "t->b"); // Print its data println("X: $x"); println("Y: $y"); // Print data of the included struct println("t->a: $ta"); println("t->b: $tb");
Of course you could place any number of structs inside other structs including arrays of structs the choice is yours.
However you must make sure you never include a struct that will include your struct else that will cause an infinite loop.