Problems with calling a function from a dll

조회 수: 3 (최근 30일)
Kaindl
Kaindl 2017년 6월 23일
댓글: Kaindl 2017년 7월 5일
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