NextPrevUpTopContentsIndex

1.2.1 Defining FLI types

The example uses the FLI to find the position of the cursor using the Windows function GetCursorPos , which has the following C prototype:

BOOL GetCursorPos( LPPOINT )

The LPPOINT argument is a pointer to the POINT structure, which has the following C definition:

typedef struct tagPOINT {
    LONG x; 
    LONG y; 
} POINT; 

First we use the 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 and LONG , which are used to associate a Lisp boolean value ( t or nil ) with a C boolean of type int , and a Lisp bignum with a C long . These are required because the Windows function GetCursorPos returns a boolean to indicate if it has executed successfully, and the cursor's x and y positions are specified in a long format in the POINT 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 the define-c-typedef macro for this, and the resulting Lisp FLI code has obvious parallels with the C tagPOINT structure.

(fli:define-c-struct tagpoint
  (x long)
  (y long))

The tagPOINT 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, using 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 function GetCursorPos , so that GetCursorPos can change the x and y 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.


LispWorks Foreign Language Interface User Guide and Reference Manual - 27 Mar 2005

NextPrevUpTopContentsIndex