当前位置:首页 > 关于matlab与c#混合编程的问题
是“项目名称Native.dll”,这2个dll的差别可以通过\文件夹源码来观察。“distrib”就是源代码的文件夹。如下图所示,src文件夹的文件示意图:
我们2.2中新建的类名是TestDemo,所以生成的的源码名称也是TestDemo,看看这2个cs文件中的代码,同时类的方法也可以在VS中通过对象浏览器来查看dll有哪些方法以及方法的参数类型。直接贴这2个cs文件的代码,顺便解释和对比下: TestDemo.cs文件源码:
1/*
2* MATLAB Compiler: 4.17 (R2012a) 3* Date: Mon Sep 09 16:19:01 2013
4* Arguments: \\ 5* \
\
6* \ 7* \\ 8* \
\\ 9*/
10using System;
11using System.Reflection;
12using System.IO;
13using MathWorks.MATLAB.NET.Arrays; 14using MathWorks.MATLAB.NET.Utility; 15
16#if SHARED
17 [assembly: System.Reflection.AssemblyKeyFile(@\)] 18#endif 19
20namespace PlotTest 21 { 22
23///
24/// The TestDemo class provides a CLS compliant, MWArray interface to the M-functions
25/// contained in the files: 26///
27/// D:\\Work\\DevelopMent_SVN\\Matlab\\MatlabBlog\\PlotTest.m 28///
30///
34/// @Version 0.0 35///
36publicclass TestDemo : IDisposable 37 {
38#region Constructors 39
40/// 41/// The static constructor instantiates and initializes the MATLAB Compiler Runtime 42/// instance. 43///
44static TestDemo() 45 {
46if (MWMCR.MCRAppInitialized) 47 {
48 Assembly assembly= Assembly.GetExecutingAssembly(); 49
50string ctfFilePath= assembly.Location; 51
52int lastDelimiter= ctfFilePath.LastIndexOf(@\); 53
54 ctfFilePath= ctfFilePath.Remove(lastDelimiter, (ctfFilePath.Length - lastDelimiter)); 55
56string ctfFileName = \; 57
58 Stream embeddedCtfStream = null; 59
60 String[] resourceStrings = assembly.GetManifestResourceNames(); 61
62foreach (String name in resourceStrings) 63 {
64if (name.Contains(ctfFileName)) 65 {
66 embeddedCtfStream =
assembly.GetManifestResourceStream(name); 67break;
68 } 69 }
70 mcr= new MWMCR(\,
71 ctfFilePath, embeddedCtfStream, true); 72 } 73else 74 {
75thrownew ApplicationException(\initialized\); 76 } 77 } 78 79
80///
81/// Constructs a new instance of the TestDemo class. 82///
83public TestDemo() 84 { 85 } 86 87
88#endregion Constructors 89
90#region Finalize 91
92/// 93/// Class destructor called by the CLR garbage collector. 94///
97 Dispose(false); 98 } 99 100
101///
102/// Frees the native resources associated with this object 103///
104publicvoid Dispose() 105 {
106 Dispose(true); 107
108 GC.SuppressFinalize(this); 109 } 110 111
112///
115protectedvirtualvoid Dispose(bool disposing) 116 {
117if (!disposed) 118 {
119 disposed= true; 120
121if (disposing) 122 {
123// Free managed resources; 124 } 125
126// Free native resources 127 } 128 } 129 130
131#endregion Finalize 132
133#region Methods 134
135///
136/// Provides a void output, 0-input MWArrayinterface to the PlotTest M-function.
共分享92篇相关文档