How to retrieve a BOOL type value returned from a .dll function

15 次查看(过去 30 天)
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!

采纳的回答

Philip Borghesani
Philip Borghesani 2012-1-10
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 个评论
Philip Borghesani
Philip Borghesani 2012-1-12
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.
Qian
Qian 2012-1-12
It has indeed been resolved! I'm not sure why it didn't work yesterday but it seems to run just fine now. Thanks guys!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Call C from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by