Error loading a 32bit DLL with 64bit Matlab

19 views (last 30 days)
I am trying to load a 32bit DLL using loadlibrary() in R2012a 64bit matlab on window 7. I have both the DLL and h files. I have added the DLL and h file locations to the environment path variable and matlab path.
The error I get from loadlibrary() is: dllname.dll is not a valid Win32 application.
While searching for an answere to my problem I have noticed Kaustubha Govind has stated the answer below several times:
  • The "is not a valid Win32 application" error usually means that you are attempting to load a 32-bit DLL using 64-bit MATLAB. Perhaps there are no 64-bit versions of the NI DLLs available? You can try installing 32-bit MATLAB on your 64-bit machine and see if you are able to load the libraries from that installation.
I do not have a 64bit version of the DLL available.
Is there any way to load 32bit dll a 64bit matlab?
Timothy Miller
Timothy Miller on 26 Jun 2012
Thank you for your comment and suggestion!
I installed the 32 bit version of MATLAB R2012a this morning and was able to load and work with the 32 bit DLL. I will see if the DLL provider can compile a 64bit version for me.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Jun 2012
Sorry, it is not possible to load a 32 bit dll from a 64 bit windows executable. This is an operating systems limitation (and also a limitation in the machine architecture.)
Walter Roberson
Walter Roberson on 8 Nov 2017
To use a 32 bit DLL with a 64 bit MATLAB, you need to have a "shim", such as an ActiveX control running as a separate process that you have the MATLAB session pass the requests to, the control calls the DLL, and sends back the results. This would not be transparent by any means.
This is not a MATLAB-specific issue. The last time I saw an operating system written for a higher number of bits able to call libraries written for a lower number of bits, it was the early 1980s involving a 32 bit Motorola 68000 operating system stuffing parameters into a globally-writable page and triggering a deliberate reset fault to allow the 16 bit Z80 to take over the processing.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!