Problems with calling a function from a dll
1 view (last 30 days)
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.
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')