Libpointer to enumerated structure class converts all numeric field data types to "double".

4 views (last 30 days)
Hello,
I'm trying to use loadlibrary() with libpointer() to utilize a C DLL. The primary function in this DLL has an input/output parameter that is an enumerated type "TD1" (using C's typedef() functionality in the DLL's header file) that is a C structure containing an assortment of various numeric data types, e.g. 'uint8', 'uint16', 'uint32', 'int32', 'double'. The problem I'm encountering is that when I try to create a libpointer to the structure in Matlab that is correctly defined in terms of field names/types, the libpointer is created, but all of the fields of the structure in the 'Value' property of the libpointer are converted to type 'double' (except for the 'uint8' ones) before I can even pass it to the DLL function.
Does anyone know of a work-around / solution?
Must I use Matlab's mex functionality instead of the loadlibrary one?
Thanks in advance,
Nathan

Answers (1)

Philip Borghesani
Philip Borghesani on 3 Mar 2011
loadlibrary/libstruct respects the data types defined in the header file.
What you are seeing is that the values are automatically converted to and from double when returned to MATLAB. This is done because double has traditionally been the standard data type in MATLAB.
The data types used in the structure by MATLAB can be verified by examining the MATLAB file generated with the mfilename option to loadlibrary and by using the structsize method of libstruct objects.
To resolve the actual cause of your problem I suggest posting a new question with some example code and the structure definition and what error you are getting.
  2 Comments
Nathan
Nathan on 4 Mar 2011
Thanks for your help, the majority of the data types are defined correctly per the prototype file generated via the mfilename option. However, one user-defined type (using C's typedef() in one of the header files) I'm including in the DLL load is resulting in an error. This type is used several times for fields within the structure I described earlier.
Theoretically, is there any inherent problem with having user-defined-typed fields in user-defined-typed structures in the header files that are included with the DLL being loaded? In other words must all of the fields in a user-defined structure type be of a built-in C data type for use in loadlibrary()?
I'm reluctant to dump all of the pertinent code into this field because of the magnitude of some of the header files I'm trying to use (I didn't write them.).
Nathan
Nathan on 4 Mar 2011
Also, every time I edit the file containing the loadlibrary command with the mfilename option in order to change the name under which the prototype file will be stored, I have to close and restart Matlab before executing in order to get it to work properly (the prototype file isn't generated otherwise). Is this a known problem, or am I doing something wrong there too?

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!