This next step uses the define-foreign-function macro to define a FLI function, or interface function, to be used to call the
GetCursorPos
function. An interface function takes its arguments, converts them into a C format, calls the foreign function, receives the return values, and converts them into a suitable Lisp format.
(fli:define-foreign-function (get-cursor-position "GetCursorPos")
((lp-point lppoint))
:result-type bool)
In this example, the defined FLI function is
get-cursor-position
. It takes as its argument a pointer of type
lppoint
, converts this to a C format, and calls
GetCursorPos
. It takes the return value it receives from
GetCursorPos
and converts it into the FLI
bool
type we defined earlier.
We have now defined all the types and functions required to get the cursor position. The next step is to allocate memory for an instance of the
tagPOINT
structure using allocate-foreign-object. The following line of code binds
location
to a pointer that points to such an instance.
(setq location (fli:allocate-foreign-object :type 'point))
Finally, we can use our interface function
get-cursor-position
to get the cursor position:
(get-cursor-position location)