Libpointer to enumerated structure class converts all numeric field data types to "double".
4 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
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.
See Also
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!