1) how can i sumulate NULL as struct param?
To pass NULL as a parameter, you must define the parameter as a pointer. By default, struct parameters are defined as "references", and there is no way to pass NULL as a reference in Basic4GL.
You can define a pointer-to-structure parameter using the "ModParamPointer" method.
registry.RegisterFunction("DescribeID", Func_DescribeID, DLL_BASIC4GL_STRING);
registry.AddStrucParam(idHandle);
registry.ModParamPointer(1);
Now the function can be called like this:
dim ID Tom
Tom = MakeID("Tom", 23, "Tom's house", "Tom's street", "Tom's town", "New Zealand")
print DescribeID(&Tom) ' Passing pointer to Tom structure
print DescribeID(null) ' Passing null
Very important. When using pointer parameters you MUST check for NULL before reading the data. If you try to read the data for a NULL pointer, Basic4GL will crash.
In Basic4GL, a "pointer" is stored as an integer. 0 corresponds to NULL.
So you can test for a NULL pointer like this:
if (basic4gl.GetIntParam(1) == 0) {
// ... Pointer is NULL
}
else {
// ... Pointer is not NULL
}
Once you know the pointer is not NULL, you can read it like you would read a standard structure param:
ID id;
basic4gl.SetType(idHandle);
basic4gl.GetParam(1, &id);
They are NOT real memory addresses.
Basic4GL stores its variables in a dynamic array.
Each element is 4 bytes, and can correspond to either a:
* 4 byte signed integer
* 4 byte floating point number
* A string identifier index (strings are stored in a separate string table)
There are a few more conventions, such as:
* Pointers are stored as indexes into the array. ("memAddr" is such a pointer). The 0 array index is reserved to mean NULL.
* Arrays have a special syntax:
Firstly there is the size of the array (as an integer)
Then there is the size of each element
Followed by the elements themselves.
* A 2D array is simply an array of 1D arrays.
That's a quick overview of the Basic4GL memory syntax.
If you understand how the data is laid out, you can use the DirectXXX methods to read and write it.
But I
strongly recommend using the other methods instead unless there really is no other way to get to the data.
There is no way to get the size of a structure in Basic4GL.
(What do you need this for?)
-Tom