I have demo C++ code. However, the main project was written in Matlab, and I want to add demo C++ code into Matlab creating .m file by calling mex. The .dll, and .h file is available in the folder, but the .dll is not compiled package. Is there any way to construct mex in that case?

 Accepted Answer

Walter Roberson
Walter Roberson on 6 Apr 2019

0 votes

In the situation you describe you are more likely to use loadlibrary to make the calls.
Using mex is possible but you would have to write the interface yourself: code to accept matlab data structure and extract the data and call into the dll and package the results back for MATLAB.

2 Comments

Nasire Uluc
Nasire Uluc on 10 Apr 2019
Thank you for your prompt answer. Actually, I am more likely to use loadlibrary to make calls. Because of the fact that the compony only provides 32 bit DLL, and our whole main project was designed into Matlab 64, I could not call 32 bit DLL into matlab 64. On the other hand, DLL 32 is working into matlab 2015b(32bit). Could you have any solution to call dll 32 library into MATLAB 64? Although the company send me the DLL64, 64 bit dll is not supported by the company. When I tried to use loadlibrary to make calls, DLL 64 into matlab 64 could not enable to connect to the device.
Unfortunately, it is a limitation of MS Windows that 64 bit Windows programs cannot invoke 32 bit DLL. This is a very very common limitation in operating systems, that programs compiled for larger number of bits cannot call libraries compiled for smaller number of bits.
Unfortunately, this means that even if you tried to use a mex interface, the 64 bit MATLAB would not be able to call the 32 bit DLL.
The trick to get around this kind of problem is to write a 32 bit "shim" program (probably not written in MATLAB) that listens for TCP connections, accepts data and requests, and calls into the 32 bit DLL, and sends back the results. The MATLAB session connects to the server and undertakes appropriate communications.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!