Convert voidPtrPtr to voidPtr for clib

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

vadim onuchin
vadim onuchin il 12 Ago 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.

Più risposte (0)

Categorie

Scopri di più su C Shared Library Integration in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by