Define Missing MLTYPE Parameter

1 view (last 30 days)
hello,
i try to call several c/c++ function in a library and have a problem with **void output parameter.
This is the description of the c++ function :
Prototype
int32_t ME100_API ME3_acquireImage(DET_t det, void **dataBuffer, uint32_t *dataSize void **inputsBuffer, uint32_t *inputsSize);
Parameters
  • In – det: handle to the detector.
  • Out – databuffer: handle to memory allocated by API that stores the lines acquired.
  • Out – dataSize: size of allocated buffer.
  • Out – inputsBuffer: handle to memory allocated by API that stores the sub-D9 inputs.
  • Out – inputsSize: size of allocated buffer.
After using the "clibgen.generateLibraryDefinition" function, i need to missing MLTYPE parameter for this function :
This is what i got for this function :
C++ function ME3_acquireImage with MATLAB name clib.ME100.ME3_acquireImage
C++ Signature: int32_t ME3_acquireImage(DET_t det,void * * dataBuffer,uint32_t * dataSize,void * * inputsBuffer,uint32_t * inputsSize)
%ME3_acquireImageDefinition = addFunction(libDef, ...
% "int32_t ME3_acquireImage(DET_t det,void * * dataBuffer,uint32_t * dataSize,void * * inputsBuffer,uint32_t * inputsSize)", ...
% "MATLABName", "clib.ME100.ME3_acquireImage", ...
% "Description", "clib.ME100.ME3_acquireImage Representation of C++ function ME3_acquireImage." + newline + ...
% "Acquire an image. Must be called between ME3_prepareAcquisition and ME3_unPrepareAcquisition." + newline + ...
% "MUST�NOT�BE�USED when MEDET_startAcquisition has been called", ...
% "DetailedDescription", "This content is from the external library documentation."); % Modify help description values as needed.
%defineArgument(ME3_acquireImageDefinition, "det", "clib.ME100.ME100_base", "input", <SHAPE>, "Description", "[in] det concerned detector");
%defineArgument(ME3_acquireImageDefinition, "dataBuffer", <MLTYPE>, "output", 1, "Description", "[in] buffer memory to store acquired lines"); % <MLTYPE> can be an existing typedef name for void* or a new typedef name to void*.
%defineArgument(ME3_acquireImageDefinition, "dataSize", "clib.array.ME100.UnsignedInt", "input", <SHAPE>, "Description", "[in] size size of buffer, in bytes."); % <MLTYPE> can be "clib.array.ME100.UnsignedInt", or "uint32"
%defineArgument(ME3_acquireImageDefinition, "inputsBuffer", <MLTYPE>, "output", 1); % <MLTYPE> can be an existing typedef name for void* or a new typedef name to void*.
%defineArgument(ME3_acquireImageDefinition, "inputsSize", "clib.array.ME100.UnsignedInt", "input", <SHAPE>); % <MLTYPE> can be "clib.array.ME100.UnsignedInt", or "uint32"
%defineOutput(ME3_acquireImageDefinition, "RetVal", "int32", "Description", "ME_SUCCESS on success, after the image has been acquired.");
%validate(ME3_acquireImageDefinition);
How to define in particular the output parameter "dataBuffer" which is define as a void** in C library and should give the buffer of an 2Dimage ?
This is what i tried :
ME3_acquireImageDefinition = addFunction(libDef, ...
"int32_t ME3_acquireImage(DET_t det,void * * dataBuffer,uint32_t * dataSize,void * * inputsBuffer,uint32_t * inputsSize)", ...
"MATLABName", "clib.ME100.ME3_acquireImage", ...
"Description", "clib.ME100.ME3_acquireImage Representation of C++ function ME3_acquireImage." + newline + ...
"Acquire an image. Must be called between ME3_prepareAcquisition and ME3_unPrepareAcquisition." + newline + ...
"MUST�NOT�BE�USED when MEDET_startAcquisition has been called", ...
"DetailedDescription", "This content is from the external library documentation."); % Modify help description values as needed.
defineArgument(ME3_acquireImageDefinition, "det", "clib.ME100.ME100_base", "input", 1, "Description", "[in] det concerned detector");
defineArgument(ME3_acquireImageDefinition, "dataBuffer", "uint32", "output", "dataSize", "Description", "[in] buffer memory to store acquired lines"); % <MLTYPE> can be an existing typedef name for void* or a new typedef name to void*.
defineArgument(ME3_acquireImageDefinition, "dataSize", "uint32", "output", 1, "Description", "[in] size size of buffer, in bytes."); % <MLTYPE> can be "clib.array.ME100.UnsignedInt", or "uint32"
defineArgument(ME3_acquireImageDefinition, "inputsBuffer", "uint32", "output", "inputsSize"); % <MLTYPE> can be an existing typedef name for void* or a new typedef name to void*.
defineArgument(ME3_acquireImageDefinition, "inputsSize", "uint32", "output", 1); % <MLTYPE> can be "clib.array.ME100.UnsignedInt", or "uint32"
defineOutput(ME3_acquireImageDefinition, "RetVal", "int32", "Description", "ME_SUCCESS on success, after the image has been acquired.");
validate(ME3_acquireImageDefinition);
Building the library give the following error:
>> build(defineME100)
Error using defineME100
Invalid MATLABType specified for argument 'dataBuffer'.
Expected type is one of the following: an existing typedef
name for void* or a new typedef name for void*.
Can you help please?
Thank you
Philippe

Accepted Answer

Abhishek Chakram
Abhishek Chakram on 7 Feb 2024
Hi philippe duvauchelle,
When working with MATLAB's C/C++ integration features, defining the correct types for interfacing with C/C++ functions is crucial. In your case, the “dataBuffer” parameter is defined as a “void**” in C, which means it is a pointer to a pointer. This is often used in C APIs to allow the function to allocate memory and pass back a pointer to this memory to the caller.
In MATLAB, you'll need to define a new type that corresponds to “void*” and then use that type for “dataBuffer” and “inputsBuffer”. Here is how to do it:
  • Define a new type for “void*” using “ addOpaqueType” with a MATLAB type that can hold a pointer. Since MATLAB does not directly support “void*”, you typically use a numeric type like “uint64” to represent it.
  • Use this new type for “dataBuffer” and “inputsBuffer” in “defineArgument”.
Here is an example for the same:
% Define a new type for void*, using uint64 as a stand-in
addOpaqueType(libDef, "Name", "voidPtr", "MATLABType", "uint64", "Description", "Pointer type");
% Define the dataBuffer and inputsBuffer arguments using the new type
defineArgument(ME3_acquireImageDefinition, "dataBuffer", "voidPtr", "output", 1, "Description", "[out] dataBuffer Memory allocated by API to store acquired lines");
defineArgument(ME3_acquireImageDefinition, "inputsBuffer", "voidPtr", "output", 1, "Description", "[out] inputsBuffer Memory allocated by API to store the sub-D9 inputs");
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!