MATLAB: Loadlibrary – Matlab R2013b 64bit

64-biterrorloadlibrarymex -setup

Hello,
I have been trying to load a 64-bit library (.dll) using the command "loadlibrary" on Matlab 64-bit, but I always receive the following error:
Error using loadlibrary (line 418) C:\Users\****\AppData\Local\Temp\tpe7fb8e10_222c_47c3_ad59_ab00161c9411\shrlibsample_thunk_pcwin64.dll is not a valid Win32 application.
As you may see, the library I am attempting to load is the shrlibsample, using the following commands:
>> addpath(fullfile(matlabroot,'extern','examples','shrlib')) >> loadlibrary('shrlibsample','shrlibsample.h')
And I also have Microsoft Software Development Kit (SDK) 7.1 set as compiler for Matlab (mbuild -setup).
I have already read several questions related to this issue, but I did not find any similar to the problem I am facing: I am trying to load a 64-bit library on a 64-bit Matlab and the error reported by the latter is related to an expectation of loading a 32-bit library, what does not make sense to me.
Some additional info: I also have Matlab 32-bit installed on my computer (Win7 64-bit), which also makes use of SDK 7.1 as compiler and I am able to load any (32-bit) library on that Matlab.
Any ideas or suggestions are very much appreciated.
Thanks, Guilherme

Best Answer

Contacting support may be your best option for this problem. Something is most likely not configured or installed correctly with your compiler.
All 64bit and 32bit windows programs & dlls are considered to be win32 applications this is a Microsoft oddity (system32 contains all 64bit programs...). The error message does not necessarily indicate improper program type or confusion, just that it could not be loaded.
I would start by adding mfilename option to your loadlibrary command and then running Dependency Walker on the generated thunk dll to see if you can figure out what is wrong with it.
Does the mex command work correctly for you? Can you build and run an example mex file? What version of Matlab are you running the way loadlibrary builds the thunk files has changed in recent versions.