matlab与VB混合编程的实现步骤1111
更新时间:2024-05-23 16:53:02 阅读量: 综合文库 文档下载
- matlab和c混合编程推荐度:
- 相关推荐
1、 首先运行mbuild –setup.进行相应设置,运行结果如下: >> mbuild -setup
Please choose your compiler for building standalone MATLAB applications:
Would you like mbuild to locate installed compilers [y]/n? y
Select a compiler:
[1] Lcc-win32 C 2.4.1 in C:\\MATLAB~1\\sys\\lcc
[2] Microsoft Visual C++ 6.0 in C:\\Program Files\\Microsoft Visual Studio
[0] None
Compiler: 2
Please verify your choices:
Compiler: Microsoft Visual C++ 6.0
Location: C:\\Program Files\\Microsoft Visual Studio
Are these correct?([y]/n): y
Trying to update options file: C:\\Documents and Settings\\ck@wj\\Application Data\\MathWorks\\MATLAB\\R2007a\\compopts.bat
From template: C:\\MATLAB~1\\bin\\win32\\mbuildopts\\msvc60compp.bat
Done . . .
--> \
DllRegisterServer in C:\\MATLAB~1\\bin\\win32\\mwcomutil.dll succeeded
--> \
DllRegisterServer in C:\\MATLAB~1\\bin\\win32\\mwcommgr.dll succeeded
2、打开DEPLOYTOOL工具,进行相应选择和输入 >> deploytool
-----creat a new deployment projiect -----MATLAB build for .NET -----generic com component ------name: shiyan.prj ------location: D:\\COM
3、建立M文件,直接拷贝代码
function y = mymagic(x) y = magic(x);
保存完毕
4、add the file
5、deployment project setting MCR option
6、build the project 编译结果如下:
Build output( 2008-12-27 15:52:50).
mcc -F 'D:\\COM\\shiyan.prj' mcc -W com:shiyan,shiyanclass,1.0 -d D:\\COM\\shiyan\\src class{shiyanclass:D:\\COM\\mymagic.m} mcc -W com:shiyan,shiyanclass,1.0 -d D:\\COM\\shiyan\\src class{shiyanclass:D:\\COM\\mymagic.m} Compiler version: 4.6 (R2007a)
Processing C:\\MATLABR2007a\\toolbox\\matlab\\mcc.enc Processing C:\\MATLABR2007a\\toolbox\\database\\mcc.enc
-T -T
link:lib link:lib
-v -v
Processing include files... 2 item(s) added.
Processing directories installed with MCR...
The file D:\\COM\\shiyan\\src\\mccExcludedFiles.log contains a list of functions excluded from the CTF archive. 2 item(s) added.
Generating MATLAB path for the compiled application... Created 37 path items.
Begin validation of MEX files: Sat Dec 27 15:53:22 2008
Validating 'C:\\MATLABR2007a\\toolbox\\compiler\\deploy\\deploywhich.mexw32'. No conflicting M-file found.
Validating 'C:\\MATLABR2007a\\toolbox\\compiler\\deploy\\readline.mexw32'. No conflicting M-file found.
End validation of MEX files: Sat Dec 27 15:53:22 2008 Deleting 2 temporary MEX authorization files.
Removing: 'C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mathworks_tmp_4147_4260.auth'. Removing: 'C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mathworks_tmp_19702_4260.auth'. Parsing file \ (Referenced from: \
Parsing file \ (Referenced from: \
Parsing file \ (Referenced from: \
Parsing file \ (Referenced from: \
Parsing file \ (Referenced from: \
Parsing file \ (Referenced from: \
Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \
(Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Parsing file \ (Referenced from: \ Generating file \
Generating file \ Generating file \ Generating file \ Generating file \
Generating file \ Generating file \
Generating file \
Executing command: mbuild -O -v -output \-I\\\\\\\\\-link dll -outdir \-regsvr
This is mbuild Copyright 1984-2006 The MathWorks, Inc.
-> Default options filename found in C:\\Documents and Settings\\ck@wj\\Application Data\\MathWorks\\MATLAB\\R2007a
----------------------------------------------------------------
-> Options file = C:\\Documents and Settings\\ck@wj\\Application Data\\MathWorks\\MATLAB\\R2007a\\compopts.bat -> COMPILER = cl -> Compiler flags:
COMPFLAGS = -c -Zp8 -G5 -GX -W3 -nologo -I\ OPTIMFLAGS = -O2 -DNDEBUG
DEBUGFLAGS = -Zi -Fd\ arguments = -ID:\\COM\\shiyan\\src Name switch = /Fo -> Pre-linking commands =
-> LINKER = link -> Link directives:
LINKFLAGS = kernel32.lib user32.lib gdi32.lib advapi32.lib oleaut32.lib ole32.lib /LIBPATH:\/nologo mclmcrrt.lib /dll /implib:\
LINKFLAGSPOST =
Name directive = \ File link directive = Lib. link directive = Rsp file indicator = @
-> Resource Compiler = rc /fo \ -> Resource Linker =
----------------------------------------------------------------
--> \
ò??′?? 1 ?????t?£
--> \/nologo /win32 /I \ /D \ /out \
mwcomtypes.idl oaidl.idl objidl.idl unknwn.idl wtypes.idl ocidl.idl oleidl.idl servprov.idl urlmon.idl msxml.idl
Processing C:\\MATLAB~1\\extern\\include\\mwcomtypes.idl
Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\oaidl.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\objidl.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\%unknwn.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\wtypes.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\ocidl.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\oleidl.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\servprov.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\%urlmon.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\msxml.idl
--> \/nologo /win32 /I \ /D \\
shiyan_idl.idl oaidl.idl objidl.idl unknwn.idl wtypes.idl ocidl.idl oleidl.idl servprov.idl urlmon.idl msxml.idl
mwcomtypes.idl
Processing D:\\COM\\shiyan\\src\\shiyan_idl.idl
Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\oaidl.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\objidl.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\%unknwn.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\wtypes.idl
/out Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\ocidl.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\oleidl.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\servprov.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\%urlmon.idl Processing C:\\Program Files\\Microsoft Visual Studio\\VC98\\INCLUDE\\msxml.idl Processing C:\\MATLAB~1\\extern\\include\\mwcomtypes.idl
--> \ --> \ -ID:\\COM\\shiyan\\src -c -Zp8 -G5 -GX -W3 -nologo -I\-DMSVC -DIBMPC -DMSWIND /FoC:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\shiyanclass_com.obj -IC:\\MATLAB~1\\extern\\include -IC:\\MATLAB~1\\simulink\\include -O2 -DNDEBUG D:\\COM\\shiyan\\src\\shiyanclass_com.cpp\
shiyanclass_com.cpp --> \ -ID:\\COM\\shiyan\\src -c -Zp8 -G5 -GX -W3 -nologo -I\-DMSVC -DIBMPC -DMSWIND /FoC:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\shiyan_dll.obj -IC:\\MATLAB~1\\extern\\include -IC:\\MATLAB~1\\simulink\\include -O2 -DNDEBUG D:\\COM\\shiyan\\src\\shiyan_dll.cpp\
shiyan_dll.cpp --> \ -ID:\\COM\\shiyan\\src -c -Zp8 -G5 -GX -W3 -nologo -I\-DMSVC -DIBMPC -DMSWIND /FoC:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\shiyan_mcc_component_data.obj -IC:\\MATLAB~1\\extern\\include -IC:\\MATLAB~1\\simulink\\include -O2 -DNDEBUG D:\\COM\\shiyan\\src\\shiyan_mcc_component_data.c\
shiyan_mcc_component_data.c
--> \ D:\\COM\\shiyan\\src\\shiyan.rc\
Contents of C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\mbuild_tmp.rsp: mclcommain.lib
C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\shiyanclass_com.obj
C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB9
7\\shiyan_dll.obj
C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\shiyan_mcc_component_data.obj D:\\COM\\shiyan\\src\\shiyan.res
--> \ kernel32.lib user32.lib gdi32.lib advapi32.lib oleaut32.lib ole32.lib /LIBPATH:\/nologo mclmcrrt.lib /dll /implib:\ @C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\mbuild_tmp.rsp \
Creating library D:\\COM\\shiyan\\src\\shiyan_1_0.lib and object D:\\COM\\shiyan\\src\\shiyan_1_0.exp --> \exist C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\templib.def del C:\\DOCUME~1\\ck@wj\\LOCALS~1\\Temp\\mbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97\\templib.def\
--> \
DllRegisterServer in D:\\COM\\shiyan\\src\\shiyan_1_0.dll succeeded
Copying: D:\\COM\\shiyan\\src\\shiyan_1_0.dll -> D:\\COM\\shiyan\\distrib
Copying: D:\\COM\\shiyan\\src\\shiyan.ctf -> D:\\COM\\shiyan\\distrib
Compilation completed succesfully. The output is located in D:\\COM\\shiyan\\distrib.
You can package the component by clicking on the \or by clicking the Tools->Package menu when the Deployment Tool panel is selected. To include additional files in the package, click Project->Settings).
7、打开VB
根据HELP文件编写VB程序
新建工程-----标准EXE-----引用shiyan1.0 trpe library------部件Microsoft Windows Common -------添加各种控件并相应修改属性-------编写代码如下: Private Sub Form_Load()
'This function is called when the form is loaded. 'Creates a new magic class instance. On Error GoTo Handle_Error
Set theMagic = New shiyan.shiyanclass
Size = 0 Exit Sub
Handle_Error:
MsgBox (Err.Description) End Sub
Private Sub btnCreate_Click()
'This function is called when the Create button is pressed. 'Calls the mymagic method, and displays the magic square. Dim y As Variant
If Size <= 0 Or theMagic Is Nothing Then Exit Sub On Error GoTo Handle_Error
Call theMagic.mymagic(1, y, Size) Call ShowMatrix(y) Exit Sub Handle_Error:
MsgBox (Err.Description) End Sub
Private Sub edtSize_Change()
'This function is called when ever the contents of the 'Text box change. Sets the current value of Size. On Error Resume Next Size = CDbl(edtSize.Text) If Err <> 0 Then Size = 0 End If End Sub
Private Sub ShowMatrix(y As Variant)
'This function populates the ListView with the contents of 'y. y is assumed to contain a 2D array. Dim n As Long Dim i As Long Dim j As Long Dim nLen As Long Dim Item As ListItem
On Error GoTo Handle_Error 'Get array size If IsArray(y) Then n = UBound(y, 1) Else
n = 1 End If
'Set up Column headers nLen = lstMagic.Width / 5 Call lstMagic.ListItems.Clear
Call lstMagic.ColumnHeaders.Clear
Call lstMagic.ColumnHeaders.Add(, , \ For i = 1 To n
Call lstMagic.ColumnHeaders.Add(, , _
\ Next
'Add array contents If IsArray(y) Then For i = 1 To n
Set Item = lstMagic.ListItems.Add(, , \ For j = 1 To n
Call Item.ListSubItems.Add(, , Format(y(i, j))) Next Next Else
Set Item = lstMagic.ListItems.Add(, , \ Call Item.ListSubItems.Add(, , Format(y)) End If Exit Sub Handle_Error:
MsgBox (Err.Description) End Sub
本机运行结果如下
7、package the project
回到DEPLOYTOOL中选择package the project
8、打开INSTALL.BAT发现需要文件MCRInstaller.exe
从电脑中搜索文件,然后找到_MCRInstaller.exe,将其改名为MCRInstaller.exe。
这里是错误的,应该找到MCRInstaller.exe,它有150M,比带前缀的不是同一个文件,带前缀的才78M。文件在C:\\MATLABR2007a\\toolbox\\compiler\\deploy\\win32
9、传到其它电脑上,运行那个****PKG.exe,全部选择Y,出现MCRRegCOMComponent.exe文件。
10、运行INSTALL.BAT。出现V70文件夹。然后电脑自己关闭了MSDOS窗口。检查INSTALL.BAT怀疑是安装完MCRInstaller.exe后没有运行MCRRegCOMComponent.exe和注册shiyan_1_0.dll就自己关闭了。然后运行程序时就出现
ActiveX部件不能创建对象。程序无法运行
试图注册shiyan_1_0.dll,但是注册失败,找不到shiyan_1_0.dll指定模块之类的提示。
7、package the project
回到DEPLOYTOOL中选择package the project
8、打开INSTALL.BAT发现需要文件MCRInstaller.exe
从电脑中搜索文件,然后找到_MCRInstaller.exe,将其改名为MCRInstaller.exe。
这里是错误的,应该找到MCRInstaller.exe,它有150M,比带前缀的不是同一个文件,带前缀的才78M。文件在C:\\MATLABR2007a\\toolbox\\compiler\\deploy\\win32
9、传到其它电脑上,运行那个****PKG.exe,全部选择Y,出现MCRRegCOMComponent.exe文件。
10、运行INSTALL.BAT。出现V70文件夹。然后电脑自己关闭了MSDOS窗口。检查INSTALL.BAT怀疑是安装完MCRInstaller.exe后没有运行MCRRegCOMComponent.exe和注册shiyan_1_0.dll就自己关闭了。然后运行程序时就出现
ActiveX部件不能创建对象。程序无法运行
试图注册shiyan_1_0.dll,但是注册失败,找不到shiyan_1_0.dll指定模块之类的提示。
正在阅读:
青岛版二年级数学上册总复习教案(1)03-06
车辆保险业务操作指导书06-23
宜春幼儿师范高等专科学校年度质量报告06-16
机械原理教案good06-05
土木工程材料02-28
《光学设计》上机实验指导书06-08
最新财经实习周记原创03-31
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 混合
- 步骤
- 编程
- 实现
- matlab
- 1111
- 2018年中国圆珠笔行业运行研究分析预测报告目录
- 小组工作计划书
- 浮力的复习及应用----解决台秤问题
- 室外道路、雨水、污水工程施工组织设计方案(二次修改) - 图文
- 新视野大学英语(第三版)第一册读写教程课后习题答案
- 基于核心素养的教学设计-认识信息与信息社会
- 私人会所开业计划书
- 对劳动关系中损害赔偿案件的认定及处理
- 古代女子服饰名称
- 《寡人之于国也》教案学校公开课
- 公共科目——素质教育概论试题与答案(70分包过)
- 地广大厦空调工程招标公告
- 【2018年中考语文真题】-江苏省淮安市中考语文试题及答案解析(wo
- 学生选课指导手册
- 项目施工安全风险评估报告
- 江苏省南京市玄武区2016~2017学年第二学期初三二模试题及答案
- 2017年元旦书法竞赛
- 《创客教育之机器人教学对学生创新能力培养的实践与研究》创客专
- 广东省中考选择与填空题
- ArcGIS Server10.0入门到熟悉及开发环境配置