How to acces lib.pointer in C++ Mex Files

Hello everyone,
I want to access lib.pointer within a mexFile using Matlab's C++ API. The pointer is transported as matlab::data::ArrayType::HANDLE_OBJECT_REF, but I don't know how to access the values within this structure. I want to convert this to a void pointer later. The lib.pointer contains a handle to a device and I am using this to communicate with the device via a separate API.
Hopefully someone can help me further.
Thank you in advance.

답변 (1개)

埃博拉酱
埃博拉酱 2025년 1월 21일
편집: 埃博拉酱 2025년 1월 21일

0 개 추천

lib.pointer has a Value property. Pass that to your MEX function.

댓글 수: 4

Richard Z.
Richard Z. 2025년 1월 22일
Hi and thanks for your reply.
I thought that passing this value is essentially a 64bit Number and I have to cast this later on to void Pointer? I thought there is a safer or even better way to protect the handle and therefor keep it in this lib.pointer. Passing the handle as a uint64 already works.
Hopefully you or someone can enlight me what is the best way.
Thanks in advance.
埃博拉酱
埃博拉酱 2025년 1월 22일
편집: 埃博拉酱 2025년 1월 22일
What do you mean by "protect the handle"? What does it mean to "keep it in this lib.pointer"? Passing the Value to a MEX function doesn't mean you're taking it away from lib.pointer as long as you don't delete this object in the MATLAB workspace - it's still in lib.pointer. And lib.pointer is just a container, a segment of memory, containing that value, and it doesn't have any "protect" functionality that I understand.
Richard Z.
Richard Z. 2025년 1월 23일
Hmm ok but matlab is giving an error if I want to access the property:
The datatype and size of the value must be defined before the value can be retrieved.
The datatype of this libpointer is 'voidPtr'. Do you have a tip for me?
Thanks in advance!

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

카테고리

도움말 센터File Exchange에서 Call C from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2023a

태그

질문:

2025년 1월 21일

댓글:

2025년 1월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by