php调用dll函数,[转载]matlab调用DLL中的函数
首先,這種調用在 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
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 告訴出錯,可不要撓頭。
2,
loadlibrary 成功了。但是查詢 libfunctions 或卸載 unloadlibrary 不成功。
怪了。我仔細看了看 loadlibrary 中的頭文件。由于我寫 DLL 的時候提供的頭文件是給 VC 用的,所以其中有些是 VC 環境中自定義的東西。我把這個頭文件改了改,把
DLL 相關的部分給注釋掉,如:
#ifdef
DATATRANSFER_API
//#define DATATRANSFER_API
extern "C" __declspec(dllexport)
#else
#define DATATRANSFER_API extern
"C" __declspec(dllimport)
#endif
//DATATRANSFER_API
int
GYZPrepare(void);
如上面,把這個 DLL 相關的注釋掉,就剩下一個簡單的 .h 文件。呵呵,這樣就通過了。
3,
參數傳遞。
由于我的程序很簡單,所以就不管這些啦。
總結
以上是生活随笔為你收集整理的php调用dll函数,[转载]matlab调用DLL中的函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php如何压缩txt文件怎么打开,PHP
- 下一篇: Java解码vhd的磁盘文件,VHD J