Calling C/C++ libraries (with associated cstring pointers) in MATLAB
8 次查看(过去 30 天)
显示 更早的评论
Hey i want to call library sb of external software into MATLAB. I tried unsing following:
[Status, Errormsg]=calllib(‘sb’, ‘sbdb’, Dbloc, Dbname)
But calllib function could not be executed. MATLAB is giving error msg: “No matching method found”
Please tell me how can I call functions with cstring pointers in MATLAB
Thanks & Regards,
Somayyah
3 个评论
Philip Borghesani
2016-3-17
编辑:Philip Borghesani
2016-3-17
Is SPDB here a typo or did you not give the signature for sbdb? Does SBDB show up in the libfunctions output?
采纳的回答
Philip Borghesani
2016-3-17
编辑:Philip Borghesani
2016-3-17
You can only call functions that appear int the output of libfunctions -full with arguments that can be converted to those listed. If the function you want is not there then you need to debug your loadlibrary call or you need to use a different function. From your description it looks like errormsg must be an input to the function and if the signature you gave is correct then the length of the buffer probably needs to be passed too. Note that the functions appeared to matlab as upper cased. Given the documentation you supplied I would call:
[status,~,~,errmessage]=calllib('sb','SBDB', 'C:\extsoft’,’rfdb.mdb’,blanks(200));
blanks(200) produces a buffer to hold the error message. The needed length of the buffer should be documented somewhere or there should be an extra parameter to specify it. No need for libpointers at all.
2 个评论
Philip Borghesani
2016-3-17
编辑:Philip Borghesani
2016-3-17
To call the function according to the prototype you gave you will need to call:
sz=200;
[~,~,sizeout,errmessage]=calllib('sb','SBDB', 'C:\extsoft’,’rfdb.mdb’,sz, blanks(sz));
I am not sure about the use of sz it may be that it is status not size;
I believe you are mi-interpreting the documentation or something else is in error. Without more information and the header declarations there is no way to verify what is expected.
This line:
Errormsg is a pointer to buffer that will be filled with error message.
Implies that errormsg is an input parameter that will be used for output.
A basic understanding on how functions pass parameters in C is probably needed to properly utilize loadlibrary and calllib.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Call C from MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!