libpointer datatypes, is boolean possible?

조회 수: 6 (최근 30일)
bkbirge
bkbirge 2015년 1월 14일
댓글: Guillaume 2015년 1월 14일
Trying to call a C++ dll from within Matlab. One of the dll inputs is a pointer to a Boolean. I don't see matlab's datatypes as supporting this and casual experimentation has failed to make it work.
This is the original code that bombs with "Pointer type must match data type": mute = libpointer('doublePtr',mute);
I changed to: mute = boolean(mute); ..and the code didn't bomb (but did give bad results) but this is actually incorrect since the C++ prototype is defined to receive... bool* mute
Any ideas that don't require me to modify the C++ code?

답변 (1개)

Guillaume
Guillaume 2015년 1월 14일
What is the true type of your boolean? In C, boolean is often a macro or typedef alias of an integer, so have you tried:
mute = libpointer('int32Ptr', mute)
  댓글 수: 2
bkbirge
bkbirge 2015년 1월 14일
편집: bkbirge 2015년 1월 14일
Apologies, it's actually C++ code, not C. I'll edit the question. I did try that suggestion anyway but it's says the type doesn't match.
Guillaume
Guillaume 2015년 1월 14일
In C++, bool is an integer type whose size is implementation defined. So look up the size in your compiler documentation or get it with sizeof(bool) and use the corresponding integer size for your pointer. For example if sizeof(bool) == 1
mute = libpointer('int8Ptr', mute);

댓글을 달려면 로그인하십시오.

카테고리

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