PDA

View Full Version : Nested UDT structures passed as param to API function



ErosOlmi
30-10-2008, 11:05
Next thinBasic 1.7.0.0 preview will have a feature requested some time ago: passing nested UDT structure to API functions as parameter.
It is more difficult to describe than to show :D

Imagine one of the following API:



Declare Function GetCursorPos Lib "USER32.DLL" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
Declare Function GetClientRect Lib "USER32.DLL" Alias "GetClientRect" (ByVal hwnd As Dword, lpRect As RECT) As Long


Both expect a structure parameter variable passed BYREF.
But what if your POINTAPI or RECT variable are inside a personalized UDT (maybe 2/3 level deeper)? For example like the following UDT:

type MyType
'---....
MyPT As POINTAPI
MyRC As RECT
'---....
end type
'...
DIM MyVAR as MyType
DIM hWnd as LONG


Since now you had to put in place some trick like getting the pointer to MyVAR.MyPT using VARPTR and then pass that pointer to the API function.

In next thinBasic 1.7.0.0 you will just simply:


GetCursorPos MyVAR.MyPT
'...
GetClientRect hWnd, MyVAR.MyRC

thinBasic will now do homeworks on this ;)

Hope you like it.
Eros

Petr Schreiber
31-10-2008, 09:24
Hi Eros,

good! I really like it!


Petr