Problems with calling a function from a dll

3 次查看(过去 30 天)
Hello, I have a question regarding the usage of a dll with the calllib function. More precisely, I want to read in data from a laser and as I have limited experience with C, C++ and whatnot, I am using Matlab. The dll is provided by the laser manufacturer and I actually can establish a connection with the sensor via the loadlibrary and the calllib function. However I have a particular problem with one function, which is needed for getting information from the sensor and which I need to proceed. My question is if you guys can check my little piece of code, in order to tell me if there is a something entirely wrong with it.
% -- Download the linearisation table from the sensor for the DLL --
% libfunctionsview shows:
% [int32, voidPtr, cstring, cstring] EthernetScanner_GetInfo (voidPtr, cstring, int32, cstring)
Following is the information from the provided header file.
void *pEthernetScanner: the Handle of the Scanner
%char *chInfo: String-Buffer for the general Information's(eds with \0)
%int iBuffer: Size of the String Buffer
%char *chMode: resesrved for future: "xml"
extern int _stdcall EthernetScanner_GetInfo(void *pEthernetScanner, char *chInfo, int iBuffer, char *chMode);
And this is how I am calling the function.
iRes = calllib ('EthernetScanner','EthernetScanner_GetInfo', m_CEthernetScannerScanner1, blanks(100), numel(blanks(100)), 'xml');
I have found a C++ test file where it is called like this:
iRes = EthernetScanner_GetInfo(m_CEthernetScannerScanner1, m_chEthernetScanner1InfoXML, ETHERNETSCANNER_GETINFOSIZEMAX, "xml");
with the iBuffer
#define ETHERNETSCANNER_GETINFOSIZEMAX 128 * 1024
Any advice is appreciated.
Cheers

回答(1 个)

Philip Borghesani
Philip Borghesani 2017-6-23
编辑:Philip Borghesani 2017-6-23
Without an error message or description of what is going wrong all we can do is guess at it. I would start with this code instead:
ScannerSizeMax=128*1024 ; % any size big enough should work
[iRes, ~, info] = calllib ('EthernetScanner','EthernetScanner_GetInfo', m_CEthernetScannerScanner1, blanks(ScannerSizeMax), ScannerSizeMax, 'xml')
  1 个评论
Kaindl
Kaindl 2017-7-5
The thing is there is no error message, just a wrong result. I thought I got the wrong result due to wrong programming in Matlab. The dll is provided by a third party, therefore I cannot look into it. Anyway to cut a long story short, it seemed the issue was with the dll. I got my hands on an updated version and now it seems to work. Thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by