Clear Filters
Clear Filters

Convert voidPtrPtr to voidPtr for clib

15 views (last 30 days)
Hello. I can't find the resolve of my problem.
I want to convert voidPtrPtr in MATLAB which I use in method on C in MyLibExport.dll:
int32_t CreateInstance(void **instance) {
*instance = (void *)malloc(sizeof(MyStruct));
return 1;
}
in voidPtr which I use in next method on C in MyLibExport.dll:
int32_t DeleteInstance(void *instance) {
free(instance);
return 2;
}
MATLAB code of using MyLibExport.dll and methods CreateInstance and DeleteInstance:
loadlibrary('MyLibExport', 'MyLibExport.h'); % load my DLL
pv = libpointer('voidPtrPtr', 0); % Create 'void **variable = NULL;'
resultInt32 = calllib('MyLibExport','CreateInstance',pv); % Create
resultInt32 = calllib('MyLibExport','DeleteInstance', ???); % what can I use here?
OS Windows. DLL build in VS2019.

Accepted Answer

vadim onuchin
vadim onuchin on 12 Aug 2021
It was not difficult as it turned out.
loadlibrary('MyLibExport', 'MyLibExport.h'); % load my DLL
pv = libpointer('voidPtr', 0); % Create 'void *variable = NULL;'
pvPtr = libpointer('voidPtrPtr', pv); % Create 'void **variablePtr = &variable;'
resultInt32 = calllib('MyLibExport','CreateInstance',pvPtr); % Create
resultInt32 = calllib('MyLibExport','DeleteInstance', pv); % Free
Debug with pdb files (OS Windows VS2019) show it.
Good Luck everyone.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!