I'm trying to load some .dll library functions for a camera driver into Matlab using the loadlibrary command without success. I'm using Win7 x64, running R2011a. Also, I have MS Visual Studio 2010 pro as the compiler. I've tried running this from both the matlabroot directory, as well as the directory containing the .dll and .h files (which has been added to the search path), and I'm running Matlab as administrator.
If I run this simple script:
dllfile = 'C:\Program Files\Andor SOLIS\Drivers\atmcd64d.dll'; hfile = 'C:\Program Files\Andor SOLIS\Drivers\ATMCD32D.H'; [nofound,warn] = loadlibrary(dllfile,hfile);
I get the following error stream:
??? Error using ==> loadlibrary at 441 Building atmcd64d_thunk_pcwin64 failed. Compiler output is: cl -I"C:\Program Files\MATLAB\R2011a\extern\include" /Zp8 /W3 /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /nologo -I"C:\Program Files\Andor SOLIS\Drivers" -I"C:\Program Files\Andor SOLIS\Drivers" "atmcd64d_thunk_pcwin64.c" -LD -Fe"atmcd64d_thunk_pcwin64.dll" atmcd64d_thunk_pcwin64.c atmcd64d_thunk_pcwin64.c(1284) : warning C4114: same type qualifier used more than once atmcd64d_thunk_pcwin64.c(1284) : error C2166: l-value specifies const object
[nofound,warn] = loadlibrary(dllfile,hfile);
If you are using 64-bit MATLAB, you must ensure that you are loading a 64-bit DLL. From the names of your files: atmcd64d.dll and ATMCD32D.H, it seems that the DLL is 64-bit, but the header file you are using to load it for the 32-bit version of the library. Could you verify if that is the case (the name doesn't necessarily tell us anything, so you can use the dumpbin utility with the /headers option to verify whether you have a 64-bit binary)? Are you able to load this DLL is a 64-bit C/C++ application outside of MATLAB?
Actually, I've just been able to successfully create the thunk file needed for 64-bit loadlibrary() operation.
The issue is with the OA_xxx functions in the amcd32d.h file. They use function signatures like: OA_Initialize(const char * const pcFilename,...)
The doubled-up use of const makes the compiler unhappy.
In general, the thunk-file generator for 64-bit loadlibrary is quite sensitive to syntax in header files that often worked under 32-bit loadlibrary(). In part it's because it requires strict C syntax. So generally, the header files have to be massaged to allow the thunk file generation to proceed. This was a new one for me.
In this case, those OA_xx functions are somewhat ancillary, so I just commented them out. If you need those functions, some signature change would be needed in the header to allow the loadlibrary() thunk file gen to work.