How to read and write to global variables of shared library(using loadlibrary)?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nilendra Gadre
el 1 de Abr. de 2020
Editada: Mohammad Sami
el 1 de Abr. de 2020
A C dll contains functions fn1(),fn2() etc which take some input arguments and give some outputs.
The processing and output of the fn1() depends on global varaibles (exported in dll header).
When the dll is loaded using
>> loadlibrary('dllname','dllname.h')
>> m = libfunctions('dllname', '-full')
Output is:
>> m =
'fn1'
'fn2'
'lib.pointer globalVar1'
'lib.pointer globalVar2'
.
.
Question is how to modify value of this globalVar1 in matlab?
Ex:
prev_value = globalVar1;
globalVar1 = newValue;
output = calllib('dllname','fn1',arg1);
Similarly, how to modify if the global variables are structures?
Thanks in Advance.
0 comentarios
Respuesta aceptada
Mohammad Sami
el 1 de Abr. de 2020
Editada: Mohammad Sami
el 1 de Abr. de 2020
You need to get the pointer first. Try the following to see if it works.
Also you did not specify what data type the pointer is pointing to in the question.
globalpointer1 = calllib('dllname','globalVar1');
prev_value = globalpointer1.Value;
globalpointer1.Value = int8(2); % assuming a data type and value.
output = calllib('dllname','fn1',arg1);
Structures should be returned as libstruct objects. See the libstruct documentations for details.
3 comentarios
Mohammad Sami
el 1 de Abr. de 2020
Editada: Mohammad Sami
el 1 de Abr. de 2020
try this way.
globalpointer1 = calllib('dllname','globalVar1');
setdatatype(globalpointer1,'int32Ptr',1,1);
prev_value = globalpointer1.Value;
globalpointer1.Value = int32(2); % assuming a data type and value.
% arg1 ....
output = calllib('dllname','fn1',arg1);
Más respuestas (0)
Ver también
Categorías
Más información sobre Naming Conventions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!