Convert voidPtrPtr to voidPtr for clib

2 Ansichten (letzte 30 Tage)
vadim onuchin
vadim onuchin am 11 Aug. 2021
Beantwortet: vadim onuchin am 12 Aug. 2021
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.

Akzeptierte Antwort

vadim onuchin
vadim onuchin am 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.

Weitere Antworten (0)

Kategorien

Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by