Error loading a 32bit DLL with 64bit Matlab
29 views (last 30 days)
Show older comments
Timothy Miller
on 25 Jun 2012
Commented: Walter Roberson
on 8 Nov 2017
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?
2 Comments
Image Analyst
on 25 Jun 2012
Good question. I just encountered the same thing today when someone asked me to run (on 64 bit Win7, 64 bit MATLAB) an old app where the author used a custom-written 32 bit DLL. The only solution I gave them was to run 32 bit MATLAB. I might be able to find the source code and perhaps if I could get it to recompile as a 64 bit DLL, it might work. I haven't tried that yet though. Maybe you can try that if you have the source code for the DLL.
Accepted Answer
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.)
4 Comments
RobertF
on 7 Nov 2017
So now when 32-bits versions of MATLAB are no longer available (post 2015b), we have no way of using 32-bit DLLs?
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.
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown 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!