Loading C++ shared library DLL into matlab
77 views (last 30 days)
Show older comments
Hello,
I want to load a C++ DLL library into Matlab (and ultimately use functions from there in Simulink). I know there is a function called loadlibrary(SHRLIB,HDRFILE) but i was told it works only with pure C libraries (when i tried to load my library it kept spewing errors:
...C:\Users\Username\Desktop\SDK_Download\CoolerMasterSDK\SDK\x86\SDKDLL.h:421:1:
warning: null character(s) ignored...
(the same error would fill whole command window and it would start at ...\SDKDLL.h:348:1: and end at \SDKDLL.h:421:1:)
Is there such function but specifically for C++ libraries? Or other means to load external C++ DLL library? Im attaching the library i want to load. I have MATLAB Support for MinGW-w64 C/C++ Compiler version 17.2.0 installed using Add-On Manager.
0 Comments
Answers (2)
Guillaume
on 18 Dec 2017
Edited: Guillaume
on 18 Dec 2017
Solely from looking at this:
warning: null character(s) ignored
/ / S D K D l l . h : S D K D l l D L L m a i n h e a d e r f i l e
I would suspect that the file uses UTF-16 encoding but is being read as UTF-8. This would explain the warning about the null characters and the letter spacing in the comment.
It may be that before all else, all the files need to be converted to UTF-8 with an editor that support both unicode encodings.
It may be that UTF-16 is the result of your editing, in which case, make sure your editor saves as UTF-8.
7 Comments
Philip Borghesani
on 19 Dec 2017
Guillaume, I wish there was a way to plus 1 a comment. I think you correctly covered all the major issues.
I expect the reason the dll does not load for you is that you don't have the needed hardware and driver installed to use the Cooler master SDK.
Philip Borghesani
on 15 Dec 2017
Edited: Walter Roberson
on 19 Dec 2017
Loadlibrary works for C or C++ libraries that have C interfaces. It appears to me (from a quick look at the header file) that the CoolerMasterSDK has a C interface that is partly broken and was never actually tested from C.
It is possible that the header can be fixed to be compatible with Loadlibrary but it may take a bit of work. Many of the problems I see have been addressed in one or more questions here. If you wish more help I suggest posting the line you used to load the library and the first error message you see here.
To get you started
- If you are using 64 bit MATLAB you want the files from x64 not x86.
- The line near line 64: extern "C" { needs a protective guard it is c++ code
- This file needs windows.h add
#include <windows.h>
to the top of it
See Also
Categories
Find more on C++ Shared Library Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!