[英]Using C# dll functions in matlab code
I have a C# project, and I want to use the function of my project in matlab. 我有一个C#项目,我想在matlab中使用我的项目的功能。 I've added 我已经添加
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
befor every classes in my project and make the out put type class library. 在我的项目中的每个类,并制作输出类型类库。 but when I use of dll in matlab, 但是当我在matlab中使用dll时,
temp = NET.addAssembly('../../foo')
and then foo.Classes
, there is no class! 然后是foo.Classes
,没有课! what should i do?! 我该怎么办?! plz help me :) 请帮助我:)
Sample regarding above comment 关于上述评论的示例
To use a class from a .NET assembly using NET.addAssembly(...)
, there is no need to make the class COM Visible but the class, as well as the methods you want to access to , have to be public . 要使用NET.addAssembly(...)
从.NET程序NET.addAssembly(...)
使用类,不需要使类COM可见,但是类以及要访问的方法必须是公共的 。
.NET code .NET代码
namespace foo
{
public class SampleClass
{
// Constructor
public SampleClass() { }
// Static example
public static string StaticMethod() { return "Hello from static method."; }
// Instance example
public string InstanceMethod() { return "Hello from instance method."; }
}
}
Usage from Matlab 来自Matlab的用法
% Loading the .NET assembly
NET.addAssembly('..\..\Foo.dll');
% Call of a static method
foo.SampleClass.StaticMethod()
% Call of an instance method
instance = foo.SampleClass();
instance.InstanceMethod();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.