首先,这种调用在 Matlab 的帮助文档中有说明。它的英文名称为:
MATLAB Interface to Generic
DLLs
从这个帮助文档,我们不难看出,整个过程为:加载
DLL ,调用相关函数,和卸载 DLL 。
看起来简单,但是在实际操作中遇到了如下几个问题:
1,
loadlibrary 出错。错误报告为:
Error using ==>
loadlibrary Failed to preprocess input file. Output from
preprocessor is: 'c:\program' is not recognized as an internal or
external command, operable or batch file
错误的原因很简单,就是 loadlibrary 的问题。由于你的 matlab 是安装在 C:\program
file 目录下,中间有一个空格。所以出错了。这在
Matlab R14sp2
及其以前的版本都有这个问题。
解决办法:
-
重新安装 matlab ,换一个目录,中间不带空格。
modify
line 168 of loadlibrary.m in
toolbox\matlab\general from:
cc=[lcc ' -noregistrylookup'
ccinclude ' -E "' header '"'];
to:
cc=['"' lcc '"
-noregistrylookup' ccinclude ' -E "' header '"']; If your header
has #include statements, then it might also be n