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

6 ビュー (過去 30 日間)
somayyah jurair
somayyah jurair 2016 年 3 月 16 日
編集済み: somayyah jurair 2020 年 8 月 8 日
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
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?
somayyah jurair
somayyah jurair 2016 年 3 月 17 日
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.

サインインしてコメントする。

採用された回答

Philip Borghesani
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
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.
somayyah jurair
somayyah jurair 2016 年 3 月 21 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCall C from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by