// usblismpi26_loader.c
// Dynamic DLL loader for USB LISM-PI26xx V2 API.

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

static HMODULE g_hDll = 0;

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


static const char* selectDefaultDllName(void)
{
#if defined(_WIN64)
    return "usblismpi2664.dll";
#else
    return "usblismpi2632.dll";
#endif
}

#define RESOLVE_SYM(type_name, fn) do {                                      \
    fn = (type_name)(GetProcAddress(g_hDll, #fn));          \
    if (!(fn)) {                                                               \
        const DWORD resolveError = GetLastError();                           \
        uiFreeLibrary();                                                       \
        return resolveError != ERROR_SUCCESS ? resolveError                    \
                                             : ERROR_PROC_NOT_FOUND;           \
    }                                                                          \
} while (0)

UInt32 uiLoadLibrary(const char* dllPathA)
{
    if (g_hDll)
        return RET_OK;

    const char* const path = (dllPathA && dllPathA[0])
                           ? dllPathA
                           : selectDefaultDllName();

    g_hDll = LoadLibraryA(path);
    if (!g_hDll)
        return (UInt32)(GetLastError());

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


    return RET_OK;
}

void uiFreeLibrary(void)
{
    if (g_hDll) {
        FreeLibrary(g_hDll);
        g_hDll = 0;
    }

    ls_libversion = 0;
    ls_initialize = 0;
    ls_enumdevices = 0;
    ls_getfwversion = 0;
    ls_getvendorname = 0;
    ls_getproductname = 0;
    ls_getserialnumber = 0;
    ls_devicecount = 0;
    ls_currentdeviceindex = 0;
    ls_opendevicebyindex = 0;
    ls_opendevicebyserial = 0;
    ls_closedevice = 0;
    ls_waitforpipe = 0;
    ls_waitforpipecount = 0;
    ls_getpipe = 0;
    ls_setpacketlength = 0;
    ls_seteptimeout = 0;
    ls_geteptimeout = 0;
    ls_getfps = 0;
    ls_geterrorstring = 0;
    ls_customfirmware = 0;
    ls_setcfg1 = 0;
    ls_getcfg1 = 0;
    ls_getpacketlength = 0;
    ls_setmuxchannel = 0;
    ls_getmuxchannel = 0;
    ls_readi2c_ext = 0;
    ls_writei2c_ext = 0;
    ls_readi2c = 0;
    ls_writei2c = 0;
    ls_i2cread1byte = 0;
    ls_i2cread2bytes = 0;
    ls_i2cread4bytes = 0;
    ls_i2cwrite1byte = 0;
    ls_i2cwrite2bytes = 0;
    ls_i2cwrite4bytes = 0;
    ls_i2cwritecmd = 0;
    ls_hw_reset = 0;
    ls_suspend = 0;
    ls_resume = 0;
    ls_updateparam = 0;
    ls_setstate = 0;
    ls_setmodeconfig = 0;
    ls_setifconfig = 0;
    ls_setstpulse = 0;
    ls_setsthigh = 0;
    ls_setstlow = 0;
    ls_setlinesperframe = 0;
    ls_setquadcount = 0;
    ls_setsofttriggertime = 0;
    ls_settriggerdelay = 0;
    ls_settriggerwidth = 0;
    ls_setpixelcount = 0;
    ls_setedgedelay = 0;
    ls_setadcvref = 0;
    ls_setadcgain = 0;
    ls_setadcoffset = 0;
    ls_setadcbias = 0;
    ls_setslaveaddress = 0;
    ls_saveslaveaddress = 0;
    ls_savesettings = 0;
    ls_reloadsettings = 0;
    ls_resetsettings = 0;
    ls_getmcuversion = 0;
    ls_getctgversion = 0;
    ls_getctgstate = 0;
    ls_getstate = 0;
    ls_getmodeconfig = 0;
    ls_getifconfig = 0;
    ls_getstpulse = 0;
    ls_getsthigh = 0;
    ls_getstlow = 0;
    ls_getlinesperframe = 0;
    ls_getquadcount = 0;
    ls_getsofttriggertime = 0;
    ls_gettriggerdelay = 0;
    ls_gettriggerwidth = 0;
    ls_getpixelcount = 0;
    ls_getedgedelay = 0;
    ls_getadcvref = 0;
    ls_getadcgain = 0;
    ls_getadcoffset = 0;
    ls_getadcbias = 0;
    ls_getslaveaddress = 0;
    ls_gethw1id = 0;
    ls_gethw1version = 0;
    ls_gethw2version = 0;
    ls_getgainmult = 0;
    ls_getgaindiv = 0;
    ls_getinitstatus = 0;
    ls_getcomresult = 0;
    ls_shutdown = 0;
    ls_seteptimeout_ex = 0;
    ls_geteptimeout_ex = 0;
    ls_setthreadpriority_ex = 0;
    ls_getthreadpriority_ex = 0;
    ls_opendevicebyindex_ex = 0;
    ls_opendevicebyserial_ex = 0;
    ls_closedevice_ex = 0;
    ls_getpipe_ex = 0;
    ls_waitforpipe_ex = 0;
    ls_waitforpipecount_ex = 0;
    ls_getfps_ex = 0;
    ls_getpacketlength_ex = 0;
    ls_customfirmware_ex = 0;
    ls_setcfg1_ex = 0;
    ls_getcfg1_ex = 0;
    ls_setslaveaddress_ex = 0;
    ls_getslaveaddress_ex = 0;
    ls_saveslaveaddress_ex = 0;
    ls_setmuxchannel_ex = 0;
    ls_getmuxchannel_ex = 0;
    ls_readi2c_ex = 0;
    ls_writei2c_ex = 0;
    ls_readi2c_ext_ex = 0;
    ls_writei2c_ext_ex = 0;
    ls_i2cread1byte_ex = 0;
    ls_i2cread2bytes_ex = 0;
    ls_i2cread4bytes_ex = 0;
    ls_i2cwrite1byte_ex = 0;
    ls_i2cwrite2bytes_ex = 0;
    ls_i2cwrite4bytes_ex = 0;
    ls_i2cwritecmd_ex = 0;
    ls_hw_reset_ex = 0;
    ls_resume_ex = 0;
    ls_suspend_ex = 0;
    ls_updateparam_ex = 0;
    ls_setstate_ex = 0;
    ls_setmodeconfig_ex = 0;
    ls_setifconfig_ex = 0;
    ls_setsthigh_ex = 0;
    ls_setstlow_ex = 0;
    ls_setstpulse_ex = 0;
    ls_setlinesperframe_ex = 0;
    ls_setquadcount_ex = 0;
    ls_setsofttriggertime_ex = 0;
    ls_settriggerdelay_ex = 0;
    ls_settriggerwidth_ex = 0;
    ls_setpixelcount_ex = 0;
    ls_setedgedelay_ex = 0;
    ls_setadcvref_ex = 0;
    ls_setadcgain_ex = 0;
    ls_setadcoffset_ex = 0;
    ls_setadcbias_ex = 0;
    ls_getctgstate_ex = 0;
    ls_getstate_ex = 0;
    ls_getmodeconfig_ex = 0;
    ls_getifconfig_ex = 0;
    ls_getsthigh_ex = 0;
    ls_getstlow_ex = 0;
    ls_getstpulse_ex = 0;
    ls_getlinesperframe_ex = 0;
    ls_getquadcount_ex = 0;
    ls_getsofttriggertime_ex = 0;
    ls_gettriggerdelay_ex = 0;
    ls_gettriggerwidth_ex = 0;
    ls_getpixelcount_ex = 0;
    ls_getedgedelay_ex = 0;
    ls_getadcvref_ex = 0;
    ls_getadcgain_ex = 0;
    ls_getgainmult_ex = 0;
    ls_getgaindiv_ex = 0;
    ls_getadcoffset_ex = 0;
    ls_getadcbias_ex = 0;
    ls_savesettings_ex = 0;
    ls_reloadsettings_ex = 0;
    ls_resetsettings_ex = 0;
    ls_getinitstatus_ex = 0;
    ls_getcomresult_ex = 0;
    ls_getmcuversion_ex = 0;
    ls_getctgversion_ex = 0;
    ls_gethw1id_ex = 0;
    ls_gethw1version_ex = 0;
    ls_gethw2version_ex = 0;

}

int uiLibraryLoaded(void)
{
    return g_hDll != 0;
}
