フィルターのクリア

Convert voidPtrPtr to voidPtr for clib

13 ビュー (過去 30 日間)
vadim onuchin
vadim onuchin 2021 年 8 月 11 日
回答済み: vadim onuchin 2021 年 8 月 12 日
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.

採用された回答

vadim onuchin
vadim onuchin 2021 年 8 月 12 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by