How to retrieve a BOOL type value returned from a .dll function
6 views (last 30 days)
Show older comments
Hi! I'm new to the external interface tools of MATLAB and I'm not very familiar with C/C++ so I was wondering if anyone here has experience.
I'm writing a control script for a near-infrared camera, which came with a driver .dll file and a brief description of the functions within it.
For example, I have a function described as:
BOOL DLL_Get_Spectra(double* pdblData, double* pdblCaseTemperature);
Description: Acquire one snapshot spectrum.
Parameter: double* pdblData: Pointer of spectrum power array allocated by the user (Buffer size >= pixel count)
double* pdblCaseTemperature: Pionter of case temperature.
Return value: Boolean TRUE: Operation completed FALSE: Operation failed
After loading dll and using libfunction, we see that the library is loaded without any problems:
[lib.pointer, doublePtr] DLL_Get_Wavelenth(double, doublePtr)
I have read how to pass pointers into MATLAB, but not much on how to read pointers from MATLAB, do I just use doublePtr.Value?
Also, MATLAB does not have a BOOL type, so how am I suppose to read the returned lib.pointer as TRUE or FALSE?
Thanks!
0 Comments
Accepted Answer
Philip Borghesani
on 10 Jan 2012
That function should not be returning a lib.pointer to MATLAB something went wrong loading the dll. What warnings were reported when loading the library?
BOOL is not a traditional c data type and should be returned to MATLAB as a simple number 0 for false and 1 for true. However a header file is frequently needed to define BOOL for a library. In this case I expect the library header expects windows.h to be included before it is used.
You can fix the header file by adding appropriate typedefs or includes. Or you can generate a prototype file and fix that using uint8 or logical as the data type.
9 Comments
Philip Borghesani
on 12 Jan 2012
I agree with Walter the BOOL issue has been fixed. I expect that one of the values you are passing into the function is not correct. You will need to supply the MATLAB code you are using to call DLL_Get_Spectraband and more information like the pixel count you expect. I suggest creating a new question with this information.
More Answers (0)
See Also
Categories
Find more on Call C++ from MATLAB 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!