Randall,Originally Posted by Randall
it depends on the API function. If you check Microsoft documentation about MoveToEx at http://msdn2.microsoft.com/en-us/library/ms534247.aspx you will see that lpPoint parameter is a pointer to a structure and below, in parameters description, documentation says "If this parameter is a NULL pointer, the previous position is not returned.".
What does it means?
You correctly defined MoveToEx in this way:
DECLARE FUNCTION MoveToEx LIB "gdi32.dll" ALIAS "MoveToEx" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINT_TYPE) As Long
"lpPoint As POINT_TYPE" is a structure passed BYREF (because with no explicit indications about BYREF/BYVAL, thinbasic assume BYREF in exteternal fucntions). Every time a parameter is passed BYREF in reality a pointer to the parameter is passed, so it is like calling
[code=thinbasic]MoveToEx(hdc, x, y, VARPTR(lpPoint))[/code]
But this operation to pass a pointer to the structure is done automatically by thinBasic.
Now, a pointer to a strcuture is nothing different than a standard 32bit DWORD number so called function (MoveToEx) internaly can do something like the following (imagine code in C or ASM, I do not know):
if lpPoint = 0 then
'---Assign to a POINT_TYPE structure pointed by lpPoint some values
That's why you can pass now a %NULL or zero number. Mainly you are telling you do not need to have back the previous position pointer. In Microsoft API there are a lot of situations like that where a ZERO pointer means "I'm not passing any structure". Till now it was not possible in thinBasic because engine was expecting a variable and a pointer to that variable was passed automatically. Now you can pass an UDT (and thinbasic will pass a pointer to that UDT) or a numeric expression (and thinbasic will pass the result of the expression). Of course it will be programmer responsability to pass a number that will represent a memory location where the structure is present or enough memory is reserved to have back an UDT otherwise Windows will generate a GPF.
Hope to have given some more info about why i changed and better optimized external function calling.
One of the activities I often do is to look at the code people using thinBasic post in forum. What I search is ocde that is enough general to be converted into native compiled thinBasic function because this will improve script execution when used as native. Another thing I check are situations like the one I reported about the UDT passed BYREF and see if I can do something about it to improve the language. Many time people do not report difficulties in using a language but we all tend to try our own solutions. Well, I try to catch those clever solutions and transform them into thinBasic features
Sometimes I'm able, sometimes not but what Ive seen is that it is worth to try.