How to call an external .dll library in MATLAB ?

28 ビュー (過去 30 日間)
Mana V
Mana V 2015 年 7 月 10 日
コメント済み: Ian Peikon 2016 年 2 月 12 日
Hello!
I am quite new at using MATLAB and I am trying to load an external library to MATLAB. One of the function of this library is supposed to return me a value but instead it returned nothing (a libpointer) when I used loadlibray and calllib. So I am wondering if I can call the .dll and .h files in C++ and then call this C++ file in MATLAB (using MEX)? Having no knowledge in C++, any help would be very appreciated :)
Mana
  10 件のコメント
Mana V
Mana V 2015 年 7 月 16 日
編集済み: Mana V 2015 年 7 月 16 日
a = 1;
b = 780;
c = -1;
value = calllib('x704IO','PortRead',a,b,c);
setdatatype(value,'uint8Ptr',1);
value.Value;
get(value);
However, it works randomly: if I run the function several times, "value"'s value will vary and sometimes MATLAB will crash...
Ian Peikon
Ian Peikon 2016 年 2 月 12 日
Hi Mana, I hope you still check this thread. Anyway, we had exactly the same problem with you, with exactly the same library (from MedAssociates). The fix is very simply. All you need to do is modify the header file (I suggest making a separate header file so that your other programs that depend on 704IO.dll, etc. are still working). Here is the offending code:
extern "C" short WINAPI EXPORT PortRead(short Rack, short Port, short Offset);
extern "C" void WINAPI EXPORT PortWrite(short Rack, short Port, short Offset, short Value);
This just needs to be changed, by removing the EXPORT, to:
extern "C" short WINAPI PortRead(short Rack, short Port, short Offset);
extern "C" void WINAPI PortWrite(short Rack, short Port, short Offset, short Value);
Just be sure to update the calls to the library to use your new header file (we just named it 704IOb.h).
Hope that helps!

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

回答 (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