Thank you. This is how to link an external DLL, but how do I call some function in the DLL? And do I need to LoadLibrary the dll again in mex-file? Thanks.
You call functions from the lib file just like you would call any other function in your code. As long as the function is exported in the lib file, and you have included the appropriate prototypes in your source code (e.g. via a header file), there is nothing else special you need to do. LoadLibrary has nothing to do with this.
I am having some problems with this in Matlab 2018a/Windows 10. I have a MEX file that depends on a DLL, say, CCC.DLL. I placed this CCC.DLL into the same directory as the MEX DLL. I was having some issues with the MEX DLL not loading, and I used the Visual C++ debugger to see what DLLs were being loaded.
To my suprise I found that when the MEX DLL was loaded, a CCC.DLL that happened to be in the system PATH was being loaded before the CCC.DLL that was in the same directory as the MEX file. This seems contrary to the normal rules of LoadLibrary but things are not quite as simple as they use to be on Windows.
Furthermore, once I removed from the PATH the directory that contained the rogue CCC.DLL, I was able to verify that when the MEX DLL loaded, it also correctly loaded it's local CCC.DLL.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
5 Comments
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_479480
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_479480
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_479484
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_479484
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_628132
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_628132
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_692621
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_692621
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_706340
Direct link to this comment
https://in.mathworks.com/matlabcentral/answers/99915-can-i-call-an-external-shared-library-dll-from-a-matlab-mex-file#comment_706340
Sign in to comment.