php调用dll函数,[转载]matlab调用DLL中的函数
首先,這種調(diào)用在 Matlab 的幫助文檔中有說明。它的英文名稱為:
MATLAB Interface to Generic
DLLs
從這個(gè)幫助文檔,我們不難看出,整個(gè)過程為:加載
DLL ,調(diào)用相關(guān)函數(shù),和卸載 DLL 。
看起來簡單,但是在實(shí)際操作中遇到了如下幾個(gè)問題:
1,
loadlibrary 出錯(cuò)。錯(cuò)誤報(bào)告為:
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
錯(cuò)誤的原因很簡單,就是 loadlibrary 的問題。由于你的 matlab 是安裝在 C:program
file 目錄下,中間有一個(gè)空格。所以出錯(cuò)了。這在
Matlab R14sp2
及其以前的版本都有這個(gè)問題。
解決辦法:
-
重新安裝 matlab ,換一個(gè)目錄,中間不帶空格。
modify
line 168 of loadlibrary.m in
toolboxmatlabgeneral 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 necessary to modify
the following lines:
line 106 from:
ccinclude = [ccinclude ' -I '
fullfile(matlabroot, 'extern','include')];
to:
ccinclude = [ccinclude ' -I "'
fullfile(matlabroot,'extern','?include"')];
line 166 from:
ccinclude = [ccinclude ' -I '
fullfile(matlabroot,'sys',...
'lcc','include')];
to:
ccinclude = [ccinclude ' -I "'
fullfile(matlabroot,'sys',...
'lcc','include"')];
The line numbers might be
different in previous releases, but the changes are the
same
注意:千萬注意其中的空格。否則, matlab 告訴出錯(cuò),可不要撓頭。
2,
loadlibrary 成功了。但是查詢 libfunctions 或卸載 unloadlibrary 不成功。
怪了。我仔細(xì)看了看 loadlibrary 中的頭文件。由于我寫 DLL 的時(shí)候提供的頭文件是給 VC 用的,所以其中有些是 VC 環(huán)境中自定義的東西。我把這個(gè)頭文件改了改,把
DLL 相關(guān)的部分給注釋掉,如:
#ifdef
DATATRANSFER_API
//#define DATATRANSFER_API
extern "C" __declspec(dllexport)
#else
#define DATATRANSFER_API extern
"C" __declspec(dllimport)
#endif
//DATATRANSFER_API
int
GYZPrepare(void);
如上面,把這個(gè) DLL 相關(guān)的注釋掉,就剩下一個(gè)簡單的 .h 文件。呵呵,這樣就通過了。
3,
參數(shù)傳遞。
由于我的程序很簡單,所以就不管這些啦。
總結(jié)
以上是生活随笔為你收集整理的php调用dll函数,[转载]matlab调用DLL中的函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php如何压缩txt文件怎么打开,PHP
- 下一篇: php去除最后一位,php字符串怎么去除