Problem with loadlibrary and commercial dll

5 views (last 30 days)
Hi everyone,
I try to connect to a commercial motorized-mirror-mount driver (Newport Newfocus PICOMOTOR CONTROLLOER 8742) with Matlab. It is connected via USB and is supplied with dll and header file. A standalone application is also supplied and does work flawlessly on my machine. However, I cannot manage to import the dll properly. I should mention, that (although I have successfully loaded some other dlls in the past) I'm not a C/C++ expert...
My System is Windows 7 Enterprise 64 bit, Matlab 8.1.0.604 (R2013a) 64bit. The dll is a 64bit version. The compiler chosen via mex -setup is "Microsoft Software Development Kit (SDK) 7.1 in C:\Program Files (x86)\Microsoft Visual Studio 10.0".
The manual of the device (section C++ sample code) tells "The Newport USB Driver (UsbDll.dll) allows software running on a PC to communicate with Newport hardware over a Universal Serial Bus. The driver is a Dynamic Link Library made up of custom software from Newport and third party software from Jungo. UsbDll.dll is written in native C++ so the public interface functions are defined and documented in the C++ header file NewpDll.h. Some of these functions have a specific scenario in which they are intended to be used and require special setup before they can be used."
I have already read that the dlls for loadlibrary must be C and must not be C++, unless the functions defined in the header are C conform. As the NewpDll.h starts with a >extern "C"< statement that should be OK, right? The source code corresponding to the dll is not available to me, so I can't recompile it.
When I call loadlibrary('usbdll.dll','NewpDll.h') I get the following output printed below.
Any suggestions?!
The dll and header files are attached in the file test.zip.
Best regards and thank you in advance,
Joachim
------ here comes the error message -------------
Error loading library intermediate output follows.
The actual error is at the end of this output.
*********
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 37 of input from line 36 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 51 of input from line 50 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 70 of input from line 69 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'intvoidEXTERN_C' was not found. Defaulting to type error.
Found on line 77 of input from line 76 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 94 of input from line 93 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 109 of input from line 108 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 121 of input from line 120 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 136 of input from line 135 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 149 of input from line 148 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 168 of input from line 167 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 186 of input from line 185 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 200 of input from line 199 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 215 of input from line 214 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 231 of input from line 230 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 245 of input from line 244 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 261 of input from line 260 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 275 of input from line 274 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
Type 'longEXTERN_C' was not found. Defaulting to type error.
Found on line 290 of input from line 289 of file C:\\Users\\labuser\\Desktop\\test\\NewpDll.h
*********
Error using loadlibrary (line 419)
Building usbdll_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\Program Files\MATLAB\R2013a\extern\include" /W3 /D_CRT_SECURE_NO_DEPRECATE
/D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /nologo -I"C:\Users\labuser\Desktop\test"
-I"C:\Users\labuser\Desktop\test" "usbdll_thunk_pcwin64.c" -LD
-Fe"usbdll_thunk_pcwin64.dll"
usbdll_thunk_pcwin64.c
C:\Users\labuser\Desktop\test\NewpDll.h(36) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(50) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(69) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(76) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(93) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(108) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(120) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(135) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(148) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(167) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(185) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(199) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(214) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(230) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(244) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(260) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(274) : error C2143: syntax error : missing '{'
before '__cdecl'
C:\Users\labuser\Desktop\test\NewpDll.h(289) : error C2143: syntax error : missing '{'
before '__cdecl'
usbdll_thunk_pcwin64.c(25) : error C2061: syntax error : identifier
'longEXTERN_CvoidThunk'
usbdll_thunk_pcwin64.c(25) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(25) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(31) : error C2061: syntax error : identifier
'longEXTERN_Cint32Thunk'
usbdll_thunk_pcwin64.c(31) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(31) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(40) : error C2061: syntax error : identifier
'longEXTERN_Cint32boolvoidPtrThunk'
usbdll_thunk_pcwin64.c(40) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(40) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(55) : error C2061: syntax error : identifier
'voidEXTERN_CvoidThunk'
usbdll_thunk_pcwin64.c(55) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(55) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(61) : error C2061: syntax error : identifier
'longEXTERN_Cint32voidPtrThunk'
usbdll_thunk_pcwin64.c(61) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(61) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(73) : error C2061: syntax error : identifier
'longEXTERN_Ccstringint32Thunk'
usbdll_thunk_pcwin64.c(73) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(73) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(85) : error C2061: syntax error : identifier
'longEXTERN_CcstringThunk'
usbdll_thunk_pcwin64.c(85) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(85) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(94) : error C2061: syntax error : identifier
'longEXTERN_CvoidPtrvoidPtrThunk'
usbdll_thunk_pcwin64.c(94) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(94) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(106) : error C2061: syntax error : identifier
'longEXTERN_Cint32cstringThunk'
usbdll_thunk_pcwin64.c(106) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(106) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(118) : error C2061: syntax error : identifier
'longEXTERN_CvoidPtrThunk'
usbdll_thunk_pcwin64.c(118) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(118) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(127) : error C2061: syntax error : identifier
'longEXTERN_CvoidPtrvoidPtrvoidPtrvoidPtrThunk'
usbdll_thunk_pcwin64.c(127) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(127) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(145) : error C2061: syntax error : identifier
'longEXTERN_CcstringcstringulongvoidPtrThunk'
usbdll_thunk_pcwin64.c(145) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(145) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(163) : error C2061: syntax error : identifier
'longEXTERN_ClongcstringulongvoidPtrThunk'
usbdll_thunk_pcwin64.c(163) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(163) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(181) : error C2061: syntax error : identifier
'longEXTERN_CcstringcstringulongThunk'
usbdll_thunk_pcwin64.c(181) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(181) : error C2059: syntax error : 'type'
usbdll_thunk_pcwin64.c(196) : error C2061: syntax error : identifier
'longEXTERN_ClongcstringulongThunk'
usbdll_thunk_pcwin64.c(196) : error C2059: syntax error : ';'
usbdll_thunk_pcwin64.c(196) : error C2059: syntax error : 'type'
Error in picotest (line 5)
loadlibrary('usbdll.dll','NewpDll.h');

Accepted Answer

Philip Borghesani
Philip Borghesani on 27 Jan 2014
Best guess is that this header is designed to produce a c (or other language) callable dll but the header itself is not c compilable. The usual way to produce a header that works with both is to do something like
#ifdef __cplusplus
extern "C" {
#endif
function definitions ...
#ifdef __cplusplus
} // closing brace for extern "C"
#endif
If you look at the header and do not see any checks for __cplusplus then the header is probably not c compatible.
Given the errors posted above it may be that adding:
#define EXTERN_C
To the top of the header file will fix the problem or it may just expose other errors.
If you can post a few excerpts from the header containing introductory code and the deceleration of one function we may be able to give better answers. Posting many nearly identical error messages is not particularly helpful.
  4 Comments
Joachim
Joachim on 27 Jan 2014
Hi Philip,
hi anyone else, I realize that although the dll works in principle I have some problems left: -- first, the above warnings are still there -- second, Matlab crashes irregularly and not perfectly reproducibly when excecuting the dll: "MATLAB has encountered an internal problem and needs to close." Any chance it has something to do with these warnings?
Best regards,
Joachim
Philip Borghesani
Philip Borghesani on 28 Jan 2014
Those warnings are harmless as long as you are not using the mentioned functions which will not work. Memory corruption is typically caused by improperly passing parameters to a function. Isolate which function or variables are causing the problem and post a new question with reproduction steps, the function prototype and any information on what the function is expecting for parameters.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!