《matlab与VB混合编程的实现步骤1111.doc》由会员分享,可在线阅读,更多相关《matlab与VB混合编程的实现步骤1111.doc(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、1、 首先运行mbuild setup.进行相应设置,运行结果如下: mbuild -setupPlease 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:MATLAB1syslcc 2 Microsoft Visual C+ 6.0 in C:Program FilesMicrosoft Visual S
2、tudio 0 None Compiler: 2 Please verify your choices: Compiler: Microsoft Visual C+ 6.0 Location: C:Program FilesMicrosoft Visual Studio Are these correct?(y/n): y Trying to update options file: C:Documents and SettingsckwjApplication DataMathWorksMATLABR2007acompopts.bat From template: C:MATLAB1binw
3、in32mbuildoptsmsvc60compp.bat Done . . . - C:MATLAB1binwin32mwregsvr C:MATLAB1binwin32mwcomutil.dll DllRegisterServer in C:MATLAB1binwin32mwcomutil.dll succeeded - C:MATLAB1binwin32mwregsvr C:MATLAB1binwin32mwcommgr.dll DllRegisterServer in C:MATLAB1binwin32mwcommgr.dll succeeded 2、打开DEPLOYTOOL工具,进行
4、相应选择和输入 deploytool-creat a new deployment projiect-MATLAB build for .NET-generic com component-name: shiyan.prj-location: D:COM3、建立M文件,直接拷贝代码function y = mymagic(x)y = magic(x);保存完毕4、add the file 5、deployment project setting MCR option6、build the project编译结果如下:Build output( 2008-12-27 15:52:50).mcc
5、-F D:COMshiyan.prjmcc -W com:shiyan,shiyanclass,1.0 -d D:COMshiyansrc -T link:lib -v classshiyanclass:D:COMmymagic.m mcc -W com:shiyan,shiyanclass,1.0 -d D:COMshiyansrc -T link:lib -v classshiyanclass:D:COMmymagic.m Compiler version: 4.6 (R2007a) Processing C:MATLABR2007atoolboxmatlabmcc.enc Process
6、ing C:MATLABR2007atoolboxdatabasemcc.enc Processing include files. 2 item(s) added. Processing directories installed with MCR. The file D:COMshiyansrcmccExcludedFiles.log contains a list of functions excluded from the CTF archive. 2 item(s) added. Generating MATLAB path for the compiled application.
7、 Created 37 path items. Begin validation of MEX files: Sat Dec 27 15:53:22 2008 Validating C:MATLABR2007atoolboxcompilerdeploydeploywhich.mexw32. No conflicting M-file found. Validating C:MATLABR2007atoolboxcompilerdeployreadline.mexw32. No conflicting M-file found. End validation of MEX files: Sat
8、Dec 27 15:53:22 2008 Deleting 2 temporary MEX authorization files. Removing: C:DOCUME1ckwjLOCALS1Tempmathworks_tmp_4147_4260.auth. Removing: C:DOCUME1ckwjLOCALS1Tempmathworks_tmp_19702_4260.auth. Parsing file D:COMmymagic.m (Referenced from: Compiler Command Line). Parsing file C:MATLABR2007atoolbox
9、compilerdeploymatlabrc.m (Referenced from: Compiler Command Line). Parsing file C:MATLABR2007atoolboxcompilerdirname.m (Referenced from: Compiler Command Line). Parsing file C:MATLABR2007atoolboxcompilerdeploydeployprint.m (Referenced from: Compiler Command Line). Parsing file C:MATLABR2007atoolboxc
10、ompilerdeployprintdlg.m (Referenced from: Compiler Command Line). Parsing file C:MATLABR2007atoolboxmatlabelmatmagic.m (Referenced from: D:COMmymagic.m). Parsing file C:MATLABR2007atoolboxmatlabiofunfilesep.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR200
11、7atoolboxcompilerdeployhgrc.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxmatlabcodetoolsinitdesktoputils.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxlocalinitprefs.m (Referenced from: C
12、:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxmatlabgeneralisdeployed.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxmatlabgeneralispc.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing
13、 file C:MATLABR2007atoolboxmatlablanglasterror.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxlocalpathdef.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxmatlabgeneralpwd.m (Referenced from:
14、 C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxmatlabgeneralrecycle.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxlocalreporterrorlogs.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsi
15、ng file C:MATLABR2007atoolboxmatlabstrfunstr2double.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxmatlabgeneralusejava.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploymatlabrc.m). Parsing file C:MATLABR2007atoolboxmatlabiofunfileparts.m
16、(Referenced from: C:MATLABR2007atoolboxcompilerdirname.m). Parsing file C:MATLABR2007atoolboxmatlabtimefundatestr.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolboxmatlabgraphicsgetappdata.m (Referenced from: C:MATLABR2007atoolboxcompilerdeployd
17、eployprint.m). Parsing file C:MATLABR2007atoolboxmatlabdatatypesisfield.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolboxmatlabuitoolsmsgbox.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolb
18、oxmatlabtimefunnow.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolboxmatlabdatatypesnum2cell.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolboxmatlabstrfunnum2str.m (Referenced from: C:MATLA
19、BR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolboxmatlabgraphicsorient.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolboxmatlabgraphicsprint.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsi
20、ng file C:MATLABR2007atoolboxmatlabstrfunstr2num.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolboxmatlabiofuntempname.m (Referenced from: C:MATLABR2007atoolboxcompilerdeploydeployprint.m). Parsing file C:MATLABR2007atoolboxmatlabgeneralpath.m (
21、Referenced from: C:MATLABR2007atoolboxcompilerdeployprintdlg.m). Parsing file C:MATLABR2007atoolboxmatlabgeneralrmpath.m (Referenced from: C:MATLABR2007atoolboxcompilerdeployprintdlg.m). Generating file D:COMshiyansrcshiyan_idl.idl. Generating file D:COMshiyansrcshiyanclass_com.hpp. Generating file
22、D:COMshiyansrcshiyanclass_com.cpp. Generating file D:COMshiyansrcshiyan_dll.cpp. Generating file D:COMshiyansrcshiyan.def. Generating file D:COMshiyansrcshiyan.rc. Generating file D:COMshiyansrcreadme.txt. Generating file D:COMshiyansrcshiyan_mcc_component_data.c. Executing command: mbuild -O -v -ou
23、tput shiyan_1_0 -ID:COMshiyansrc mwcomtypes.idl D:COMshiyansrcshiyan_idl.idl mclcommain.lib D:COMshiyansrcshiyanclass_com.cpp D:COMshiyansrcshiyan_dll.cpp D:COMshiyansrcshiyan.def D:COMshiyansrcshiyan.rc D:COMshiyansrcshiyan_mcc_component_data.c -link dll -outdir D:COMshiyansrc -regsvr This is mbuil
24、d Copyright 1984-2006 The MathWorks, Inc. - Default options filename found in C:Documents and SettingsckwjApplication DataMathWorksMATLABR2007a - - Options file = C:Documents and SettingsckwjApplication DataMathWorksMATLABR2007acompopts.bat - COMPILER = cl - Compiler flags: COMPFLAGS = -c -Zp8 -G5 -
25、GX -W3 -nologo -IC:MATLAB1externincludewin32 -DMSVC -DIBMPC -DMSWIND OPTIMFLAGS = -O2 -DNDEBUG DEBUGFLAGS = -Zi -FdD:COMshiyansrcshiyan_1_0.pdb arguments = -ID:COMshiyansrc Name switch = /Fo - Pre-linking commands = - LINKER = link - Link directives: LINKFLAGS = kernel32.lib user32.lib gdi32.lib adv
26、api32.lib oleaut32.lib ole32.lib /LIBPATH:C:MATLAB1externlibwin32microsoft /nologo mclmcrrt.lib /dll /implib:D:COMshiyansrcshiyan_1_0.lib /def:D:COMshiyansrcshiyan.def LINKFLAGSPOST = Name directive = /out:D:COMshiyansrcshiyan_1_0.dll File link directive = Lib. link directive = Rsp file indicator =
27、- Resource Compiler = rc /fo D:COMshiyansrcshiyan.res - Resource Linker = - - copy C:MATLAB1externincludewin32mwcomutil.tlb . ? 1 ?t? - midl /nologo /win32 /I C:MATLAB1externinclude /D NDEBUG /out D:COMshiyansrc mwcomtypes.idl mwcomtypes.idl oaidl.idl objidl.idl unknwn.idl wtypes.idl ocidl.idl oleid
28、l.idl servprov.idl urlmon.idl msxml.idl Processing C:MATLAB1externincludemwcomtypes.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEoaidl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEobjidl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEunknwn.idl
29、Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEwtypes.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEocidl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEoleidl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEservprov.idl Processing C:Pr
30、ogram FilesMicrosoft Visual StudioVC98INCLUDEurlmon.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEmsxml.idl - midl /nologo /win32 /I C:MATLAB1externinclude /D NDEBUG /out D:COMshiyansrc D:COMshiyansrcshiyan_idl.idl shiyan_idl.idl oaidl.idl objidl.idl unknwn.idl wtypes.idl ocidl.idl
31、 oleidl.idl servprov.idl urlmon.idl msxml.idl mwcomtypes.idl Processing D:COMshiyansrcshiyan_idl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEoaidl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEobjidl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLU
32、DEunknwn.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEwtypes.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEocidl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEoleidl.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEservprov.idl Pr
33、ocessing C:Program FilesMicrosoft Visual StudioVC98INCLUDEurlmon.idl Processing C:Program FilesMicrosoft Visual StudioVC98INCLUDEmsxml.idl Processing C:MATLAB1externincludemwcomtypes.idl - del mwcomutil.tlb - cl -ID:COMshiyansrc -c -Zp8 -G5 -GX -W3 -nologo -IC:MATLAB1externincludewin32 -DMSVC -DIBMP
34、C -DMSWIND /FoC:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97shiyanclass_com.obj -IC:MATLAB1externinclude -IC:MATLAB1simulinkinclude -O2 -DNDEBUG D:COMshiyansrcshiyanclass_com.cpp shiyanclass_com.cpp - cl -ID:COMshiyansrc -c -Zp8 -G5 -GX -W3 -nologo -IC:MATLAB1externincludewin32
35、-DMSVC -DIBMPC -DMSWIND /FoC:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97shiyan_dll.obj -IC:MATLAB1externinclude -IC:MATLAB1simulinkinclude -O2 -DNDEBUG D:COMshiyansrcshiyan_dll.cpp shiyan_dll.cpp - cl -ID:COMshiyansrc -c -Zp8 -G5 -GX -W3 -nologo -IC:MATLAB1externincludewin32 -D
36、MSVC -DIBMPC -DMSWIND /FoC:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97shiyan_mcc_component_data.obj -IC:MATLAB1externinclude -IC:MATLAB1simulinkinclude -O2 -DNDEBUG D:COMshiyansrcshiyan_mcc_component_data.c shiyan_mcc_component_data.c - rc /fo D:COMshiyansrcshiyan.res D:COMshiy
37、ansrcshiyan.rc Contents of C:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97mbuild_tmp.rsp: mclcommain.lib C:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97shiyanclass_com.obj C:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97shiyan_dll.obj C:DOCU
38、ME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97shiyan_mcc_component_data.obj D:COMshiyansrcshiyan.res - link /out:D:COMshiyansrcshiyan_1_0.dll kernel32.lib user32.lib gdi32.lib advapi32.lib oleaut32.lib ole32.lib /LIBPATH:C:MATLAB1externlibwin32microsoft /nologo mclmcrrt.lib /dll /impl
39、ib:D:COMshiyansrcshiyan_1_0.lib /def:D:COMshiyansrcshiyan.def C:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97mbuild_tmp.rsp Creating library D:COMshiyansrcshiyan_1_0.lib and object D:COMshiyansrcshiyan_1_0.exp - if exist C:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F
40、54D4BB97templib.def del C:DOCUME1ckwjLOCALS1Tempmbuild_085BF459-513B-4CF7-8F8C-E67F54D4BB97templib.def - mwregsvr D:COMshiyansrcshiyan_1_0.dll DllRegisterServer in D:COMshiyansrcshiyan_1_0.dll succeeded Copying: D:COMshiyansrcshiyan_1_0.dll - D:COMshiyandistribCopying: D:COMshiyansrcshiyan.ctf - D:C
41、OMshiyandistribCompilation completed succesfully. The output is located in D:COMshiyandistrib.You can package the component by clicking on the Package icon in the Deployment Tool toolbar, or by clicking the Tools-Package menu when the Deployment Tool panel is selected. To include additional files in
42、 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 = 0Exit SubHandle_Error: MsgBox (Err.Description)End Sub