// usblismpi26_loader.h
// Dynamic DLL loader for USB LISM-PI26xx V2 API.
// Compatible with Embarcadero C++Builder and Microsoft Visual C++.


#pragma once

#ifndef WIN32_LEAN_AND_MEAN
#  define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>

#include <stdint.h>
typedef int8_t   Int8;
typedef int16_t  Int16;
typedef uint8_t  UInt8;
typedef uint16_t UInt16;
typedef uint32_t UInt32;
typedef int32_t  Int32;

#ifndef WINAPI
#  define WINAPI __stdcall
#endif

typedef void* LSHandle;
typedef UInt32 LSResult;

#define LS_THREAD_PRIORITY_NORMAL       0
#define LS_THREAD_PRIORITY_ABOVE_NORMAL 1
#define LS_THREAD_PRIORITY_HIGH         2

/* BEGIN GENERATED LS ERROR CODES */
#define LS_OK                                  ((LSResult)0)
#define LS_ERR_NO_DEVICES_ATTACHED             ((LSResult)0x20000001)
#define LS_ERR_DEVICE_INDEX_OUT_OF_RANGE       ((LSResult)0x20000002)
#define LS_ERR_SERIAL_NUM_NOT_FOUND            ((LSResult)0x20000003)
#define LS_ERR_INVALID_HANDLE                  ((LSResult)6)
#define LS_ERR_DEVICE_ACTIVE                   ((LSResult)0x20000011)
#define LS_ERR_CONTROL_TRANSFER                ((LSResult)0x20000015)
#define LS_ERR_TIMEOUT                         ((LSResult)1460)
#define LS_ERR_DEVICE_ALREADY_OPEN             ((LSResult)0x20000013)
#define LS_ERR_NOT_IMPLEMENTED                 ((LSResult)0x20000014)
#define LS_ERR_ALLOCATE_THREADPARAM_MEM        ((LSResult)0x20000004)
#define LS_ERR_PATH_INVALID_HANDLE             ((LSResult)0x20000006)
#define LS_ERR_INVALID_DATALEN                 ((LSResult)0x21000001)
#define LS_ERR_I2C_NACK                        ((LSResult)0x21000004)
#define LS_ERR_I2C_ERROR                       ((LSResult)0x21000005)
#define LS_ERR_I2C_UNKNOWN                     ((LSResult)0x21000006)
#define LS_ERR_I2C_MUX_DISABLED                ((LSResult)0x21000007)
#define LS_ERR_INVALID_PACKETLENGTH            ((LSResult)0x21000002)
#define LS_ERR_CMD_NOT_SUPPORTED               ((LSResult)0x21000003)
#define LS_ERR_PIPE_CANCELLED                  ((LSResult)109)
#define LS_ERR_INVALID_TIMEOUT                 ((LSResult)0x21000008)
#define LS_ERR_INVALID_THREAD_PRIORITY         ((LSResult)0x21000009)
#define LS_ERR_THREAD_PRIORITY_FAILED          ((LSResult)0x2100000A)
/* END GENERATED LS ERROR CODES */

// Common constants
#define RET_OK          0x00000000u

#define _512            512u
#define _1kB            (_512 * 2u)
#define _2kB            (_1kB * 2u)
#define _4kB            (_2kB * 2u)
#define _8kB            (_4kB * 2u)
#define _16kB           (_8kB * 2u)
#define _32kB           (_16kB * 2u)
#define _64kB           (_32kB * 2u)
#define _128kB          (_64kB * 2u)
#define _256kB          (_128kB * 2u)
#define _512kB          (_256kB * 2u)
#define _1MB            (_512kB * 2u)
#define _2MB            (_1MB * 2u)
#define _4MB            (_2MB * 2u)
#define _8MB            (_4MB * 2u)
#define _16MB           (_8MB * 2u)
#define _32MB           (_16MB * 2u)
#define _64MB           (_32MB * 2u)
#define _128MB          (_64MB * 2u)
#define _256MB          (_128MB * 2u)

#define _1ms            1u
#define _1s             (1000u * _1ms)

#define LISM_ADDR       0xFEu

#define MODE_FREE_RUNNING           0x00u
#define MODE_EXT_RISING_EDGE_SL     0x01u
#define MODE_EXT_HIGH_LEVEL         0x02u
#define MODE_INT_SOFT_TRIGGER       0x03u
#define MODE_QUAD_ENC_TRIGGER       0x04u
#define MODE_EXT_RISING_EDGE_ML     0x05u
#define MODE_ENCODER_DIR_CW         0x00u
#define MODE_ENCODER_DIR_CCW        0x10u
#define MODE_ENCODER_CNT_DISABLE    0x00u
#define MODE_ENCODER_CNT_ENABLE     0x20u

#define IF_DCLK_400KHZ              0x00u
#define IF_DCLK_500KHZ              0x01u
#define IF_DCLK_800KHZ              0x02u
#define IF_DCLK_1MHZ                0x03u
#define IF_DCLK_2MHZ                0x04u
#define IF_DCLK_4MHZ                0x05u
#define IF_DCLK_10MHZ               0x06u
#define IF_DCLK_20MHZ               0x07u
#define IF_DCLK_POL_RISING_EDGE     0x00u
#define IF_DCLK_POL_FALLING_EDGE    0x08u
#define IF_LINE_VALID_HIGH          0x00u
#define IF_LINE_VALID_LOW           0x10u
#define IF_FRAME_VALID_HIGH         0x00u
#define IF_FRAME_VALID_LOW          0x20u
#define IF_TRIGGER_OUTPUT_HIGH      0x00u
#define IF_TRIGGER_OUTPUT_LOW       0x40u

#define ADC_VREF_1V6                0x00u
#define ADC_VREF_2V0                0x01u

#ifdef __cplusplus
extern "C" {
#endif

// Library version
typedef UInt16 (WINAPI *T_libversion)(void);

// Legacy single-device API
typedef UInt32 (WINAPI *T_initialize)(UInt32 pipe_size, UInt32 packet_length, UInt32 thread_class, Int32 thread_priority, const char* message_id);
typedef Int32 (WINAPI *T_enumdevices)(void);
typedef UInt16 (WINAPI *T_getfwversion)(Int32 index);
typedef const char* (WINAPI *T_getvendorname)(Int32 index);
typedef const char* (WINAPI *T_getproductname)(Int32 index);
typedef const char* (WINAPI *T_getserialnumber)(Int32 index);
typedef UInt8 (WINAPI *T_devicecount)(void);
typedef Int32 (WINAPI *T_currentdeviceindex)(void);
typedef UInt32 (WINAPI *T_opendevicebyindex)(Int32 index);
typedef UInt32 (WINAPI *T_opendevicebyserial)(const char* serial_num);
typedef UInt32 (WINAPI *T_closedevice)(void);
typedef UInt32 (WINAPI *T_waitforpipe)(UInt32 timeout_ms);
typedef UInt32 (WINAPI *T_waitforpipecount)(Int32 count, Int32* available, UInt32 timeout_ms);
typedef UInt32 (WINAPI *T_getpipe)(void* buffer, UInt32 to_read, UInt32* read_count);
typedef UInt32 (WINAPI *T_setpacketlength)(UInt32 packet_length);
typedef UInt32 (WINAPI *T_seteptimeout)(UInt32 timeout_ms);
typedef UInt32 (WINAPI *T_geteptimeout)(void);
typedef UInt32 (WINAPI *T_getfps)(void);
typedef const char* (WINAPI *T_geterrorstring)(UInt32 error_code);
typedef UInt32 (WINAPI *T_customfirmware)(UInt32* custom_firmware);
typedef UInt32 (WINAPI *T_setcfg1)(UInt8 cfg1);
typedef UInt32 (WINAPI *T_getcfg1)(UInt8* cfg1);
typedef UInt32 (WINAPI *T_getpacketlength)(UInt32* packet_length);
typedef UInt32 (WINAPI *T_setmuxchannel)(UInt8 mux);
typedef UInt32 (WINAPI *T_getmuxchannel)(Int8* mux);
typedef UInt32 (WINAPI *T_readi2c_ext)(UInt8 i2c_address, void* buffer, UInt16* length);
typedef UInt32 (WINAPI *T_writei2c_ext)(UInt8 i2c_address, const void* buffer, UInt16 length);
typedef UInt32 (WINAPI *T_readi2c)(UInt8 i2c_address, void* buffer, UInt16* length);
typedef UInt32 (WINAPI *T_writei2c)(UInt8 i2c_address, const void* buffer, UInt16 length);
typedef UInt32 (WINAPI *T_i2cread1byte)(UInt8 i2c_address, UInt8 i2c_register, UInt8* value);
typedef UInt32 (WINAPI *T_i2cread2bytes)(UInt8 i2c_address, UInt8 i2c_register, UInt16* value);
typedef UInt32 (WINAPI *T_i2cread4bytes)(UInt8 i2c_address, UInt8 i2c_register, UInt32* value);
typedef UInt32 (WINAPI *T_i2cwrite1byte)(UInt8 i2c_address, UInt8 i2c_register, UInt8 value);
typedef UInt32 (WINAPI *T_i2cwrite2bytes)(UInt8 i2c_address, UInt8 i2c_register, UInt16 value);
typedef UInt32 (WINAPI *T_i2cwrite4bytes)(UInt8 i2c_address, UInt8 i2c_register, UInt32 value);
typedef UInt32 (WINAPI *T_i2cwritecmd)(UInt8 i2c_address, UInt8 i2c_command);
typedef UInt32 (WINAPI *T_hw_reset)(UInt8 address);
typedef UInt32 (WINAPI *T_suspend)(UInt8 address);
typedef UInt32 (WINAPI *T_resume)(UInt8 address);
typedef UInt32 (WINAPI *T_updateparam)(UInt8 address);
typedef UInt32 (WINAPI *T_setstate)(UInt8 address, UInt8 state);
typedef UInt32 (WINAPI *T_setmodeconfig)(UInt8 address, UInt8 mode);
typedef UInt32 (WINAPI *T_setifconfig)(UInt8 address, UInt8 config);
typedef UInt32 (WINAPI *T_setstpulse)(UInt8 address, UInt32 high_value, UInt32 low_value);
typedef UInt32 (WINAPI *T_setsthigh)(UInt8 address, UInt32 high_value);
typedef UInt32 (WINAPI *T_setstlow)(UInt8 address, UInt32 low_value);
typedef UInt32 (WINAPI *T_setlinesperframe)(UInt8 address, UInt16 lines);
typedef UInt32 (WINAPI *T_setquadcount)(UInt8 address, UInt32 count);
typedef UInt32 (WINAPI *T_setsofttriggertime)(UInt8 address, UInt32 time_value);
typedef UInt32 (WINAPI *T_settriggerdelay)(UInt8 address, UInt32 delay_value);
typedef UInt32 (WINAPI *T_settriggerwidth)(UInt8 address, UInt32 width_value);
typedef UInt32 (WINAPI *T_setpixelcount)(UInt8 address, UInt16 pixel_count);
typedef UInt32 (WINAPI *T_setedgedelay)(UInt8 address, UInt8 edge_delay);
typedef UInt32 (WINAPI *T_setadcvref)(UInt8 address, UInt8 vref);
typedef UInt32 (WINAPI *T_setadcgain)(UInt8 address, UInt8 gain);
typedef UInt32 (WINAPI *T_setadcoffset)(UInt8 address, UInt16 offset);
typedef UInt32 (WINAPI *T_setadcbias)(UInt8 address, UInt16 bias);
typedef UInt32 (WINAPI *T_setslaveaddress)(UInt8 address, UInt8 new_address);
typedef UInt32 (WINAPI *T_saveslaveaddress)(UInt8 address);
typedef UInt32 (WINAPI *T_savesettings)(UInt8 address);
typedef UInt32 (WINAPI *T_reloadsettings)(UInt8 address);
typedef UInt32 (WINAPI *T_resetsettings)(UInt8 address);
typedef UInt32 (WINAPI *T_getmcuversion)(UInt8 address, UInt16* version);
typedef UInt32 (WINAPI *T_getctgversion)(UInt8 address, UInt16* version);
typedef UInt32 (WINAPI *T_getctgstate)(UInt8 address, UInt8* state);
typedef UInt32 (WINAPI *T_getstate)(UInt8 address, UInt8* state);
typedef UInt32 (WINAPI *T_getmodeconfig)(UInt8 address, UInt8* mode);
typedef UInt32 (WINAPI *T_getifconfig)(UInt8 address, UInt8* config);
typedef UInt32 (WINAPI *T_getstpulse)(UInt8 address, UInt32* high_value, UInt32* low_value);
typedef UInt32 (WINAPI *T_getsthigh)(UInt8 address, UInt32* high_value);
typedef UInt32 (WINAPI *T_getstlow)(UInt8 address, UInt32* low_value);
typedef UInt32 (WINAPI *T_getlinesperframe)(UInt8 address, UInt16* lines);
typedef UInt32 (WINAPI *T_getquadcount)(UInt8 address, UInt32* count);
typedef UInt32 (WINAPI *T_getsofttriggertime)(UInt8 address, UInt32* time_value);
typedef UInt32 (WINAPI *T_gettriggerdelay)(UInt8 address, UInt32* delay_value);
typedef UInt32 (WINAPI *T_gettriggerwidth)(UInt8 address, UInt32* width_value);
typedef UInt32 (WINAPI *T_getpixelcount)(UInt8 address, UInt16* pixel_count);
typedef UInt32 (WINAPI *T_getedgedelay)(UInt8 address, UInt8* edge_delay);
typedef UInt32 (WINAPI *T_getadcvref)(UInt8 address, UInt8* vref);
typedef UInt32 (WINAPI *T_getadcgain)(UInt8 address, UInt8* gain);
typedef UInt32 (WINAPI *T_getadcoffset)(UInt8 address, UInt16* offset);
typedef UInt32 (WINAPI *T_getadcbias)(UInt8 address, UInt16* bias);
typedef UInt32 (WINAPI *T_getslaveaddress)(UInt8 address, UInt8* new_address);
typedef UInt32 (WINAPI *T_gethw1id)(UInt8 address, UInt16* hardware_id);
typedef UInt32 (WINAPI *T_gethw1version)(UInt8 address, UInt16* version);
typedef UInt32 (WINAPI *T_gethw2version)(UInt8 address, UInt16* version);
typedef UInt32 (WINAPI *T_getgainmult)(UInt8 address, UInt16* multiplier);
typedef UInt32 (WINAPI *T_getgaindiv)(UInt8 address, UInt16* divisor);
typedef UInt32 (WINAPI *T_getinitstatus)(UInt8 address, UInt8* status);
typedef UInt32 (WINAPI *T_getcomresult)(UInt8 address, UInt8* result_value);
typedef UInt32 (WINAPI *T_shutdown)(void);

// Handle-based multi-device API
typedef LSResult (WINAPI *T_seteptimeout_ex)(LSHandle handle, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_geteptimeout_ex)(LSHandle handle, UInt32* timeout_ms);
typedef LSResult (WINAPI *T_setthreadpriority_ex)(LSHandle handle, Int32 priority);
typedef LSResult (WINAPI *T_getthreadpriority_ex)(LSHandle handle, Int32* priority);
typedef LSResult (WINAPI *T_opendevicebyindex_ex)(Int32 index, UInt32 pipe_size, UInt32 packet_length, LSHandle* handle);
typedef LSResult (WINAPI *T_opendevicebyserial_ex)(const char* serial_num, UInt32 pipe_size, UInt32 packet_length, LSHandle* handle);
typedef LSResult (WINAPI *T_closedevice_ex)(LSHandle handle);
typedef LSResult (WINAPI *T_getpipe_ex)(LSHandle handle, void* buffer, UInt32 to_read, UInt32* read_count);
typedef LSResult (WINAPI *T_waitforpipe_ex)(LSHandle handle, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_waitforpipecount_ex)(LSHandle handle, Int32 count, Int32* available, UInt32 timeout_ms);
typedef UInt32 (WINAPI *T_getfps_ex)(LSHandle handle);
typedef LSResult (WINAPI *T_getpacketlength_ex)(LSHandle handle, UInt32* packet_length, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_customfirmware_ex)(LSHandle handle, UInt32* custom_firmware, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setcfg1_ex)(LSHandle handle, UInt8 cfg1, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getcfg1_ex)(LSHandle handle, UInt8* cfg1, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setslaveaddress_ex)(LSHandle handle, UInt8 address, UInt8 new_address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getslaveaddress_ex)(LSHandle handle, UInt8 address, UInt8* new_address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_saveslaveaddress_ex)(LSHandle handle, UInt8 address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setmuxchannel_ex)(LSHandle handle, UInt8 mux, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getmuxchannel_ex)(LSHandle handle, Int8* mux, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_readi2c_ex)(LSHandle handle, UInt8 i2c_address, void* buffer, UInt16* length, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_writei2c_ex)(LSHandle handle, UInt8 i2c_address, const void* buffer, UInt16 length, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_readi2c_ext_ex)(LSHandle handle, UInt8 i2c_address, void* buffer, UInt16* length, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_writei2c_ext_ex)(LSHandle handle, UInt8 i2c_address, const void* buffer, UInt16 length, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_i2cread1byte_ex)(LSHandle handle, UInt8 i2c_address, UInt8 i2c_register, UInt8* value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_i2cread2bytes_ex)(LSHandle handle, UInt8 i2c_address, UInt8 i2c_register, UInt16* value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_i2cread4bytes_ex)(LSHandle handle, UInt8 i2c_address, UInt8 i2c_register, UInt32* value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_i2cwrite1byte_ex)(LSHandle handle, UInt8 i2c_address, UInt8 i2c_register, UInt8 value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_i2cwrite2bytes_ex)(LSHandle handle, UInt8 i2c_address, UInt8 i2c_register, UInt16 value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_i2cwrite4bytes_ex)(LSHandle handle, UInt8 i2c_address, UInt8 i2c_register, UInt32 value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_i2cwritecmd_ex)(LSHandle handle, UInt8 i2c_address, UInt8 i2c_command, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_hw_reset_ex)(LSHandle handle, UInt8 address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_resume_ex)(LSHandle handle, UInt8 address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_suspend_ex)(LSHandle handle, UInt8 address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_updateparam_ex)(LSHandle handle, UInt8 address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setstate_ex)(LSHandle handle, UInt8 address, UInt8 state, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setmodeconfig_ex)(LSHandle handle, UInt8 address, UInt8 mode, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setifconfig_ex)(LSHandle handle, UInt8 address, UInt8 config, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setsthigh_ex)(LSHandle handle, UInt8 address, UInt32 high_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setstlow_ex)(LSHandle handle, UInt8 address, UInt32 low_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setstpulse_ex)(LSHandle handle, UInt8 address, UInt32 high_value, UInt32 low_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setlinesperframe_ex)(LSHandle handle, UInt8 address, UInt16 lines, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setquadcount_ex)(LSHandle handle, UInt8 address, UInt32 count, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setsofttriggertime_ex)(LSHandle handle, UInt8 address, UInt32 time_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_settriggerdelay_ex)(LSHandle handle, UInt8 address, UInt32 delay_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_settriggerwidth_ex)(LSHandle handle, UInt8 address, UInt32 width_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setpixelcount_ex)(LSHandle handle, UInt8 address, UInt16 pixel_count, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setedgedelay_ex)(LSHandle handle, UInt8 address, UInt8 edge_delay, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setadcvref_ex)(LSHandle handle, UInt8 address, UInt8 vref, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setadcgain_ex)(LSHandle handle, UInt8 address, UInt8 gain, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setadcoffset_ex)(LSHandle handle, UInt8 address, UInt16 offset, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_setadcbias_ex)(LSHandle handle, UInt8 address, UInt16 bias, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getctgstate_ex)(LSHandle handle, UInt8 address, UInt8* state, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getstate_ex)(LSHandle handle, UInt8 address, UInt8* state, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getmodeconfig_ex)(LSHandle handle, UInt8 address, UInt8* mode, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getifconfig_ex)(LSHandle handle, UInt8 address, UInt8* config, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getsthigh_ex)(LSHandle handle, UInt8 address, UInt32* high_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getstlow_ex)(LSHandle handle, UInt8 address, UInt32* low_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getstpulse_ex)(LSHandle handle, UInt8 address, UInt32* high_value, UInt32* low_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getlinesperframe_ex)(LSHandle handle, UInt8 address, UInt16* lines, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getquadcount_ex)(LSHandle handle, UInt8 address, UInt32* count, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getsofttriggertime_ex)(LSHandle handle, UInt8 address, UInt32* time_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_gettriggerdelay_ex)(LSHandle handle, UInt8 address, UInt32* delay_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_gettriggerwidth_ex)(LSHandle handle, UInt8 address, UInt32* width_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getpixelcount_ex)(LSHandle handle, UInt8 address, UInt16* pixel_count, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getedgedelay_ex)(LSHandle handle, UInt8 address, UInt8* edge_delay, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getadcvref_ex)(LSHandle handle, UInt8 address, UInt8* vref, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getadcgain_ex)(LSHandle handle, UInt8 address, UInt8* gain, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getgainmult_ex)(LSHandle handle, UInt8 address, UInt16* multiplier, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getgaindiv_ex)(LSHandle handle, UInt8 address, UInt16* divisor, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getadcoffset_ex)(LSHandle handle, UInt8 address, UInt16* offset, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getadcbias_ex)(LSHandle handle, UInt8 address, UInt16* bias, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_savesettings_ex)(LSHandle handle, UInt8 address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_reloadsettings_ex)(LSHandle handle, UInt8 address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_resetsettings_ex)(LSHandle handle, UInt8 address, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getinitstatus_ex)(LSHandle handle, UInt8 address, UInt8* status, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getcomresult_ex)(LSHandle handle, UInt8 address, UInt8* result_value, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getmcuversion_ex)(LSHandle handle, UInt8 address, UInt16* version, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_getctgversion_ex)(LSHandle handle, UInt8 address, UInt16* version, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_gethw1id_ex)(LSHandle handle, UInt8 address, UInt16* hardware_id, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_gethw1version_ex)(LSHandle handle, UInt8 address, UInt16* version, UInt32 timeout_ms);
typedef LSResult (WINAPI *T_gethw2version_ex)(LSHandle handle, UInt8 address, UInt16* version, UInt32 timeout_ms);

// Function pointers resolved by uiLoadLibrary()
extern T_libversion ls_libversion;
extern T_initialize ls_initialize;
extern T_enumdevices ls_enumdevices;
extern T_getfwversion ls_getfwversion;
extern T_getvendorname ls_getvendorname;
extern T_getproductname ls_getproductname;
extern T_getserialnumber ls_getserialnumber;
extern T_devicecount ls_devicecount;
extern T_currentdeviceindex ls_currentdeviceindex;
extern T_opendevicebyindex ls_opendevicebyindex;
extern T_opendevicebyserial ls_opendevicebyserial;
extern T_closedevice ls_closedevice;
extern T_waitforpipe ls_waitforpipe;
extern T_waitforpipecount ls_waitforpipecount;
extern T_getpipe ls_getpipe;
extern T_setpacketlength ls_setpacketlength;
extern T_seteptimeout ls_seteptimeout;
extern T_geteptimeout ls_geteptimeout;
extern T_getfps ls_getfps;
extern T_geterrorstring ls_geterrorstring;
extern T_customfirmware ls_customfirmware;
extern T_setcfg1 ls_setcfg1;
extern T_getcfg1 ls_getcfg1;
extern T_getpacketlength ls_getpacketlength;
extern T_setmuxchannel ls_setmuxchannel;
extern T_getmuxchannel ls_getmuxchannel;
extern T_readi2c_ext ls_readi2c_ext;
extern T_writei2c_ext ls_writei2c_ext;
extern T_readi2c ls_readi2c;
extern T_writei2c ls_writei2c;
extern T_i2cread1byte ls_i2cread1byte;
extern T_i2cread2bytes ls_i2cread2bytes;
extern T_i2cread4bytes ls_i2cread4bytes;
extern T_i2cwrite1byte ls_i2cwrite1byte;
extern T_i2cwrite2bytes ls_i2cwrite2bytes;
extern T_i2cwrite4bytes ls_i2cwrite4bytes;
extern T_i2cwritecmd ls_i2cwritecmd;
extern T_hw_reset ls_hw_reset;
extern T_suspend ls_suspend;
extern T_resume ls_resume;
extern T_updateparam ls_updateparam;
extern T_setstate ls_setstate;
extern T_setmodeconfig ls_setmodeconfig;
extern T_setifconfig ls_setifconfig;
extern T_setstpulse ls_setstpulse;
extern T_setsthigh ls_setsthigh;
extern T_setstlow ls_setstlow;
extern T_setlinesperframe ls_setlinesperframe;
extern T_setquadcount ls_setquadcount;
extern T_setsofttriggertime ls_setsofttriggertime;
extern T_settriggerdelay ls_settriggerdelay;
extern T_settriggerwidth ls_settriggerwidth;
extern T_setpixelcount ls_setpixelcount;
extern T_setedgedelay ls_setedgedelay;
extern T_setadcvref ls_setadcvref;
extern T_setadcgain ls_setadcgain;
extern T_setadcoffset ls_setadcoffset;
extern T_setadcbias ls_setadcbias;
extern T_setslaveaddress ls_setslaveaddress;
extern T_saveslaveaddress ls_saveslaveaddress;
extern T_savesettings ls_savesettings;
extern T_reloadsettings ls_reloadsettings;
extern T_resetsettings ls_resetsettings;
extern T_getmcuversion ls_getmcuversion;
extern T_getctgversion ls_getctgversion;
extern T_getctgstate ls_getctgstate;
extern T_getstate ls_getstate;
extern T_getmodeconfig ls_getmodeconfig;
extern T_getifconfig ls_getifconfig;
extern T_getstpulse ls_getstpulse;
extern T_getsthigh ls_getsthigh;
extern T_getstlow ls_getstlow;
extern T_getlinesperframe ls_getlinesperframe;
extern T_getquadcount ls_getquadcount;
extern T_getsofttriggertime ls_getsofttriggertime;
extern T_gettriggerdelay ls_gettriggerdelay;
extern T_gettriggerwidth ls_gettriggerwidth;
extern T_getpixelcount ls_getpixelcount;
extern T_getedgedelay ls_getedgedelay;
extern T_getadcvref ls_getadcvref;
extern T_getadcgain ls_getadcgain;
extern T_getadcoffset ls_getadcoffset;
extern T_getadcbias ls_getadcbias;
extern T_getslaveaddress ls_getslaveaddress;
extern T_gethw1id ls_gethw1id;
extern T_gethw1version ls_gethw1version;
extern T_gethw2version ls_gethw2version;
extern T_getgainmult ls_getgainmult;
extern T_getgaindiv ls_getgaindiv;
extern T_getinitstatus ls_getinitstatus;
extern T_getcomresult ls_getcomresult;
extern T_shutdown ls_shutdown;
extern T_seteptimeout_ex ls_seteptimeout_ex;
extern T_geteptimeout_ex ls_geteptimeout_ex;
extern T_setthreadpriority_ex ls_setthreadpriority_ex;
extern T_getthreadpriority_ex ls_getthreadpriority_ex;
extern T_opendevicebyindex_ex ls_opendevicebyindex_ex;
extern T_opendevicebyserial_ex ls_opendevicebyserial_ex;
extern T_closedevice_ex ls_closedevice_ex;
extern T_getpipe_ex ls_getpipe_ex;
extern T_waitforpipe_ex ls_waitforpipe_ex;
extern T_waitforpipecount_ex ls_waitforpipecount_ex;
extern T_getfps_ex ls_getfps_ex;
extern T_getpacketlength_ex ls_getpacketlength_ex;
extern T_customfirmware_ex ls_customfirmware_ex;
extern T_setcfg1_ex ls_setcfg1_ex;
extern T_getcfg1_ex ls_getcfg1_ex;
extern T_setslaveaddress_ex ls_setslaveaddress_ex;
extern T_getslaveaddress_ex ls_getslaveaddress_ex;
extern T_saveslaveaddress_ex ls_saveslaveaddress_ex;
extern T_setmuxchannel_ex ls_setmuxchannel_ex;
extern T_getmuxchannel_ex ls_getmuxchannel_ex;
extern T_readi2c_ex ls_readi2c_ex;
extern T_writei2c_ex ls_writei2c_ex;
extern T_readi2c_ext_ex ls_readi2c_ext_ex;
extern T_writei2c_ext_ex ls_writei2c_ext_ex;
extern T_i2cread1byte_ex ls_i2cread1byte_ex;
extern T_i2cread2bytes_ex ls_i2cread2bytes_ex;
extern T_i2cread4bytes_ex ls_i2cread4bytes_ex;
extern T_i2cwrite1byte_ex ls_i2cwrite1byte_ex;
extern T_i2cwrite2bytes_ex ls_i2cwrite2bytes_ex;
extern T_i2cwrite4bytes_ex ls_i2cwrite4bytes_ex;
extern T_i2cwritecmd_ex ls_i2cwritecmd_ex;
extern T_hw_reset_ex ls_hw_reset_ex;
extern T_resume_ex ls_resume_ex;
extern T_suspend_ex ls_suspend_ex;
extern T_updateparam_ex ls_updateparam_ex;
extern T_setstate_ex ls_setstate_ex;
extern T_setmodeconfig_ex ls_setmodeconfig_ex;
extern T_setifconfig_ex ls_setifconfig_ex;
extern T_setsthigh_ex ls_setsthigh_ex;
extern T_setstlow_ex ls_setstlow_ex;
extern T_setstpulse_ex ls_setstpulse_ex;
extern T_setlinesperframe_ex ls_setlinesperframe_ex;
extern T_setquadcount_ex ls_setquadcount_ex;
extern T_setsofttriggertime_ex ls_setsofttriggertime_ex;
extern T_settriggerdelay_ex ls_settriggerdelay_ex;
extern T_settriggerwidth_ex ls_settriggerwidth_ex;
extern T_setpixelcount_ex ls_setpixelcount_ex;
extern T_setedgedelay_ex ls_setedgedelay_ex;
extern T_setadcvref_ex ls_setadcvref_ex;
extern T_setadcgain_ex ls_setadcgain_ex;
extern T_setadcoffset_ex ls_setadcoffset_ex;
extern T_setadcbias_ex ls_setadcbias_ex;
extern T_getctgstate_ex ls_getctgstate_ex;
extern T_getstate_ex ls_getstate_ex;
extern T_getmodeconfig_ex ls_getmodeconfig_ex;
extern T_getifconfig_ex ls_getifconfig_ex;
extern T_getsthigh_ex ls_getsthigh_ex;
extern T_getstlow_ex ls_getstlow_ex;
extern T_getstpulse_ex ls_getstpulse_ex;
extern T_getlinesperframe_ex ls_getlinesperframe_ex;
extern T_getquadcount_ex ls_getquadcount_ex;
extern T_getsofttriggertime_ex ls_getsofttriggertime_ex;
extern T_gettriggerdelay_ex ls_gettriggerdelay_ex;
extern T_gettriggerwidth_ex ls_gettriggerwidth_ex;
extern T_getpixelcount_ex ls_getpixelcount_ex;
extern T_getedgedelay_ex ls_getedgedelay_ex;
extern T_getadcvref_ex ls_getadcvref_ex;
extern T_getadcgain_ex ls_getadcgain_ex;
extern T_getgainmult_ex ls_getgainmult_ex;
extern T_getgaindiv_ex ls_getgaindiv_ex;
extern T_getadcoffset_ex ls_getadcoffset_ex;
extern T_getadcbias_ex ls_getadcbias_ex;
extern T_savesettings_ex ls_savesettings_ex;
extern T_reloadsettings_ex ls_reloadsettings_ex;
extern T_resetsettings_ex ls_resetsettings_ex;
extern T_getinitstatus_ex ls_getinitstatus_ex;
extern T_getcomresult_ex ls_getcomresult_ex;
extern T_getmcuversion_ex ls_getmcuversion_ex;
extern T_getctgversion_ex ls_getctgversion_ex;
extern T_gethw1id_ex ls_gethw1id_ex;
extern T_gethw1version_ex ls_gethw1version_ex;
extern T_gethw2version_ex ls_gethw2version_ex;


// Loads the requested DLL. If dllPathA is null or empty, the loader selects
// usblismpi2632.dll or usblismpi2664.dll according to the application bitness.
// Returns RET_OK on success, otherwise a Win32 error code.
UInt32 uiLoadLibrary(const char* dllPathA);

// Unloads the DLL and resets every resolved function pointer to 0.
void uiFreeLibrary(void);

// Returns true after a successful uiLoadLibrary() call.
int uiLibraryLoaded(void);

#ifdef __cplusplus
}
#endif
