Convert voidPtrPtr to voidPtr for clib

2 vues (au cours des 30 derniers jours)
vadim onuchin
vadim onuchin le 11 Août 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.

Réponse acceptée

vadim onuchin
vadim onuchin le 12 Août 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.

Plus de réponses (0)

Catégories

En savoir plus sur C Shared Library Integration dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by