I have a third-party (Win32) DLL, written in C, that exposes the following interface:
DLL_EXPORT typedef enum
{
DEVICE_PCI = 1,
DEVICE_USB = 2
} DeviceType;
DLL_EXPORT int DeviceStatus(DeviceType kind);
I wish to call it from Delphi.
How do I get access to the DeviceType constants in my Delphi code? Or, if I should just use the values 1 and 2 directly, what Delphi type should I use for the “DeviceType kind” parameters? Integer? Word?
The usual way to declare the interface from an external DLL in C is to expose its interface in a .H header file. Then, to access the DLL from C the .H header file has to be
#included in the C source code.Translated to Delphi terms, you need to create a unit file that describes the same interface in pascal terms, translating the c syntax to pascal.
For your case, you would create a file such as…
And the you would declare it in the
usesclause of your source code. And invoke the function this way: