matlab与VB混合编程的实现步骤1111

更新时间:2024-05-23 16:53:02 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

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指定模块之类的提示。

本文来源:https://www.bwwdw.com/article/4qx7.html

Top