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?

 채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 6일

0 개 추천

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

Nasire Uluc
Nasire Uluc 2019년 4월 10일
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.
Walter Roberson
Walter Roberson 2019년 4월 10일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

태그

질문:

2019년 4월 6일

댓글:

2019년 4월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by