Problems with calling a function from a dll

3 views (last 30 days)
Kaindl
Kaindl on 23 Jun 2017
Commented: Kaindl on 5 Jul 2017
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

Answers (1)

Philip Borghesani
Philip Borghesani on 23 Jun 2017
Edited: Philip Borghesani on 23 Jun 2017
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 Comment
Kaindl
Kaindl on 5 Jul 2017
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

Sign in to comment.

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!