The Delphi language is still alive and kicking and has been used to interface with UPDD.
This example is using the UPDD API from Delphi in Windows.
Accessing the UPDD API can be achieved by calling its DLL exported functions in the same way as you might for Windows API functions.
But to do so, you will need declarations to allow the calling program to link correctly with these functions.
A .dpr sample provided here, apidemo.zip illustrates this and provides declarations for the most commonly used features of the API.
To use other features of the API refer to the C header file upddapi.h which is installed with the driver, using this and the examples in apidemo.dpr it should be straightforward to achieve this.
This sample is for illustration and not expected to be used asis, there is no error checking and the code structure should be adapted to your specific needs.
The specific aspects illustrated are:
- Loading the api library
- Referencing functions within the api library
- Opening and verifying a connection to the driver
- Closing the driver after use.
- Setting an integer value in UPDD settings.
- Setting a string value in UPDD settings.
- Getting an integer value in UPDD settings.
- Getting a string value in UPDD settings.
- Registering to receive callbacks for multiple event types.
- Implementing the callback handler.
- Getting a handle to the first device registered with UPDD.
- A method to access the common data area of the callback record (union in C terms)
You should pay particular attention to the comments around thread safety in the callback, especially if you need to perform UI actions in response to a callback, in a typical GUI app UI actions must be handled in the primary (UI) thread, so an event should be posted to that thread and handled there.
This implementation is only for 64 bit support. With UPDD version 6, the 64 bit api can be downloaded from <link> and should be extracted to …\updd\x64api.
For updd version 7, 64 bit support is the default; the library reference
SetCurrentDir('c:\program files (x86)\updd\x64api');
h_updd := LoadLibrary('upddapi_x64.dll');
Should be changed to
SetCurrentDir('c:\program files\updd');
h_updd := LoadLibrary('upddapi.dll');
Accessing the flags bits of the DigitiserSubEvent record.
In the C definition of the struct DigitiserEvent, the first byte is a series of bit flags to represent various states relating to touch or pen.
In the equivalent Delphi record DigitiserSubEvent there is a corresponding byte named flags.
To access the individual flag bits in Delphi use the logical and operator. For example, if the expression
flags and 1
is true then the tipswitch / touchingLeft bit is set.