loadlibrary issue with dll

30 views (last 30 days)
tmd
tmd on 17 Jun 2015
Hello,
I'm trying to load a vendor dll and header file and call from Matlab. I've been able to successfully call this dll from Python, but I'm having mixed results in Matlab.
The library loads without out errors and it appears that I'm able to connect to the device (Total Phase Aardvark). However, a simple function call to turn on the target power does not work (it doesn't throw errors though).
The dll and header file are attached. Any thoughts on why this isn't completely working? Here is the code that I've been using.
%load dll shared library
[warnings, notfound] = loadlibrary('aardvark','aardvark.h');
This line returns several warnings:
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by structure AardvarkVersion does not exist. The structure may
not be usable.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_find_devices does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_find_devices_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_find_devices_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_unique_id does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_target_power does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_sleep_ms does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_sleep_ms does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_bus_timeout does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_write_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_enable does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_enable does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_enable does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_set_response does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_set_response does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_write_stats_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_slave_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_slave_read_ext does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_monitor_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_i2c_monitor_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_i2c_pullup does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_spi_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_spi_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_spi_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_spi_write does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_spi_slave_set_response does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_spi_slave_set_response does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_spi_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'errorPtr' used by function c_aa_spi_slave_read does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_gpio_direction does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_gpio_pullup does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_gpio_set does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
Warning: The data type 'error' used by function c_aa_gpio_change does not exist.
> In C:\Program Files\MATLAB\R2014b\toolbox\matlab\general\loadlibrary.p>loadlibrary at 424
the return variable notfound shows that some of the data types have errors which I feel may be the source of why it isn't completely working.
>> notfound
notfound =
aardvark.h
Type 'unsignedint__int8' was not found. Defaulting to type error.
Found on line 80 of input from line 79 of file H:\\Matlab\\aardvark.h
Type 'unsigned__int16' was not found. Defaulting to type error.
Found on line 81 of input from line 80 of file H:\\Matlab\\aardvark.h
Type 'unsigned__int32' was not found. Defaulting to type error.
Found on line 82 of input from line 81 of file H:\\Matlab\\aardvark.h
Type '__int8' was not found. Defaulting to type error.
Found on line 84 of input from line 83 of file H:\\Matlab\\aardvark.h
Type '__int16' was not found. Defaulting to type error.
Found on line 85 of input from line 84 of file H:\\Matlab\\aardvark.h
Type '__int32' was not found. Defaulting to type error.
Found on line 86 of input from line 85 of file H:\\Matlab\\aardvark.h
aardvark_thunk_pcwin64.c
Creating library aardvark_thunk_pcwin64.lib and object aardvark_thunk_pcwin64.exp
listing the available functions using:
libfunctions aardvark
shows all of the functions have loaded:
Functions in library aardvark:
c_aa_async_poll c_aa_i2c_monitor_read c_aa_open_ext
c_aa_close c_aa_i2c_pullup c_aa_port
c_aa_configure c_aa_i2c_read c_aa_sleep_ms
c_aa_features c_aa_i2c_read_ext c_aa_spi_bitrate
c_aa_find_devices c_aa_i2c_slave_disable c_aa_spi_configure
c_aa_find_devices_ext c_aa_i2c_slave_enable c_aa_spi_master_ss_polarity
c_aa_gpio_change c_aa_i2c_slave_read c_aa_spi_slave_disable
c_aa_gpio_direction c_aa_i2c_slave_read_ext c_aa_spi_slave_enable
c_aa_gpio_get c_aa_i2c_slave_set_response c_aa_spi_slave_read
c_aa_gpio_pullup c_aa_i2c_slave_write_stats c_aa_spi_slave_set_response
c_aa_gpio_set c_aa_i2c_slave_write_stats_ext c_aa_spi_write
c_aa_i2c_bitrate c_aa_i2c_write c_aa_status_string
c_aa_i2c_bus_timeout c_aa_i2c_write_ext c_aa_target_power
c_aa_i2c_free_bus c_aa_i2c_write_read c_aa_unique_id
c_aa_i2c_monitor_disable c_aa_log c_aa_version
c_aa_i2c_monitor_enable c_aa_open
Despite the notfounds and warnings I'm able to successfully connect to the device using:
aa_handle = calllib('aardvark','c_aa_open',0);
aa_handle returns a 1 which based on the dll documentation indicates it's a valid handle.
At this point I should be able to issue lib calls to functions such as turning on the target power. However, the device does not appear to respond to this function call (although it does using Python):
%turn on adapter power 0x03
calllib('aardvark','c_aa_target_power',aa_handle,3);

Accepted Answer

Philip Borghesani
Philip Borghesani on 22 Jun 2015
These lines of code :
typedef unsigned __int8 u08;
Are making use of a Microsoft extension to the c language ( __int8 ) and are not supported by loadlibrary. There may be no easy solution to the problem. I would probably make a copy of aardvark.h and edit it as need to make loadlibrary work. Your other option is to give up on loadlibrary and create your own mex file.
To make a modified version of aardvark.h work the typedefs secion might need to look like:
typedef unsigned char u08;
typedef unsigned short u16;
...
typedef char s08;
typedef short s16;
...
To get the include of aardvark to work correctly you might need to change it to
#include "aardvark.h"
That is standard c syntax if the header is in the same directory and not on the include path.
  3 Comments
justin
justin on 10 Nov 2017
On a very similar issue, I am trying to load a .h file with
typedef struct _D128STATE {
unsigned int CONTROL;
int DEMAND;
int WIDTH;
int RECOVERY;
int DWELL;
unsigned int CPULSE;
unsigned int COOC;
unsigned int CTOOFAST;
unsigned int FSTATE;
} D128STATE;
typedef struct _D128DEVICESTATE {
int D128_DeviceID;
int D128_VersionID;
int D128_Error;
D128STATE D128_State;
} D128DEVICESTATE;
typedef struct _DEVHDR {
int DeviceCount;
} DEVHDR;
typedef struct _D128 {
DEVHDR Header;
D128DEVICESTATE State[];
} D128, *PD128;
and more typedef structs similar. that returns
Warning: The data type 's_D128DEVICESTATE#' used by structure s_D128 does not exist.
The structure may not be usable.
I have gotten loadlibrary to work with other headers and dlls, but they never attempted to typedef a struct. Is there a similar fix to the int/short/long one??
Niravkumar Ambaliya
Niravkumar Ambaliya on 4 Mar 2019
Hi Justin,
Were you able to solve the problem? I am getting similar errors when using structs having struct array.
Thanks,
nambaliya

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 18 Jun 2015
You may need to use a later compiler, or you might need to set your compiler to c99 mode. See also http://stackoverflow.com/questions/734802/fixed-width-integers-in-c
  2 Comments
tmd
tmd on 18 Jun 2015
I'm not sure I understand what your're saying. I'm not compiling anything, outside of Matlab that is. Are you saying I need to change Mex to c99 mode?
I've found other people have similar issues, albeit with different data types, which have been resolved by adding include statements in the headers file (windows.h, stint.h, etc.) but these have not worked for me.
Walter Roberson
Walter Roberson on 18 Jun 2015
Yes I think you will need to change mex to c99 mode. Also earlier versions of the microsoft compilers did not define __int* variables, which are microsoft specific anyhow. If using a later microsoft compiler with c99 mode does not solve the problem with the __int* types then the link I gave talks about where to find appropriate header files to account for these microsoft built-in types.

Sign in to comment.


Philip Borghesani
Philip Borghesani on 18 Jun 2015
I do believe the problem is a missing header. The addheader loadlibrary option is NOT the solution by itself. Start with a c example that calls the function and look at all header #included before aardvark.h one or more of these is likely the problem. The simplest solution is to create a new header file (myheader.h) and add all includ statments from the example up to and including the include for aardvark then call
loadlibrary('aardvark','myheader.h','addheader','aardvark')
If you still have no progress post the header code for a few of the functions and the matching lines with comments from a prototype file created with the mfilename option to loadlibrary.
  3 Comments
Philip Borghesani
Philip Borghesani on 19 Jun 2015
Edited: Philip Borghesani on 19 Jun 2015
u16 and similar types are not standard types and the definition must be in some header file. It is possible that Walter is on the correct track and that the definitions are using c99 types that are not supported by loadlibrary and your combination of compilers.
Your header myheader.h is not correct it is missing #include <aardvark.h> you missed the "up to and including" in my instructions above.
What platform, MATLAB version and compiler are you using? This may need to be a support call or enhancement request.
What code is on line 79 of aardvark.h?
tmd
tmd on 22 Jun 2015
Hi Philip,
I added the '#include aardvark.h' into myheader.h but Matlab can't seem to load the header file now despite the file being in my workspace.
>> [warnings, notfound] = loadlibrary('aardvark','myheader.h','addheader','aardvark')
Error using loadlibrary (line 440)
Failed to preprocess the input file.
Output from preprocessor is:myheader.h
H:\Matlab\myheader.h(4) : fatal error C1083: Cannot open include file: 'aardvark.h': No such file or
directory
I'm using Windows 7 64bit, Matlab R2014b and the compiler information is:
>> mex -setup
MEX configured to use 'Microsoft Windows SDK 7.1 (C)' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
Here is the typedef section in aardvark.h, Line 79 is 'typedef unsigned __int8 u08;'
/*=========================================================================
| TYPEDEFS
========================================================================*/
#ifndef TOTALPHASE_DATA_TYPES
#define TOTALPHASE_DATA_TYPES
#ifndef _MSC_VER
/* C99-compliant compilers (GCC) */
#include <stdint.h>
typedef uint8_t u08;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s08;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
#else
/* Microsoft compilers (Visual C++) */
typedef unsigned __int8 u08;
typedef unsigned __int16 u16;
typedef unsigned __int32 u32;
typedef unsigned __int64 u64;
typedef signed __int8 s08;
typedef signed __int16 s16;
typedef signed __int32 s32;
typedef signed __int64 s64;
#endif /* __MSC_VER */
typedef float f32;
typedef double f64;
#endif /* TOTALPHASE_DATA_TYPES */

Sign in to comment.

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!