Calling C/C++ libraries (with associated cstring pointers) in MATLAB

4 views (last 30 days)
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 Comments
Philip Borghesani
Philip Borghesani on 17 Mar 2016
Edited: Philip Borghesani on 17 Mar 2016
Is SPDB here a typo or did you not give the signature for sbdb? Does SBDB show up in the libfunctions output?
somayyah jurair
somayyah jurair on 17 Mar 2016
Yes its a typo. Yes SBDB is visible in libfunctions output. I've also generated prototype m file using loadlibrary. And SBDB is also present there.

Sign in to comment.

Accepted Answer

Philip Borghesani
Philip Borghesani on 17 Mar 2016
Edited: Philip Borghesani on 17 Mar 2016
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 Comments
Philip Borghesani
Philip Borghesani on 17 Mar 2016
Edited: Philip Borghesani on 17 Mar 2016
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.
somayyah jurair
somayyah jurair on 21 Mar 2016
Thanks alot Mr. Philip Borghesani. Through your suggested code:
sz=200; [~,~,sizeout,errmessage]=calllib('sb','SBDB', 'C:\extsoft’,’rfdb.mdb’,sz, blanks(sz)); I am finally able to call my library function.
Regards, Somayyah Jurair

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!