The example uses the FLI to find the position of the cursor using the Windows functionGetCursorPos
, which has the following C prototype:
BOOL GetCursorPos( LPPOINT )
TheLPPOINT
argument is a pointer to thePOINT
structure, which has the following C definition:
typedef struct tagPOINT { LONG x; LONG y; } POINT;
First we use thefli:define-c-typedef
macro to define a number of basic types which are needed to pass data to and from the Windows function.
(fli:define-c-typedef bool (:boolean :int)) (fli:define-c-typedef long :long)
This defines two types,BOOL
andLONG
, which are used to associate a Lisp boolean value (t
ornil
) with a C boolean of typeint
, and a Lispbignum
with a Clong
. These are required because the Windows functionGetCursorPos
returns a boolean to indicate if it has executed successfully, and the cursor's x and y positions are specified in along
format in thePOINT
structure.
Next, we need to define a structure for the FLI which is used to get the coordinates of the cursor. These coordinates will consist of an x and a y position. We use thefli:define-c-struct
macro for this, and the resulting Lisp FLI code has obvious parallels with the CtagPOINT
structure.
(fli:define-c-struct tagpoint (x long) (y long))
ThetagPOINT
structure for the FLI, corresponding to the C structure of the same name, has been defined. This now needs to be further defined as a type for the FLI, usingfli:define-c-typedef
.
(fli:define-c-typedef point (:struct tagpoint))
Finally, a pointer type to point to the structure is required. It is this FLI pointer which will be passed to the Windows functionGetCursorPos
, so thatGetCursorPos
can change thex
andy
values of the structure pointed to.
(fli:define-c-typedef lppoint (:pointer point))
All the required FLI types have now been defined. Although it may seem that there is a level of duplicity in the definitions of the structures, pointers and types in this section, this was necessary to match the data structures of the C functions to which the FLI will interface. We can now move on to the definition of FLI functions to perform the interfacing.