简体   繁体   中英

Using C# dll functions in matlab code

I have a C# project, and I want to use the function of my project in 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,

temp = NET.addAssembly('../../foo')

and then foo.Classes , there is no class! 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 code

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

% 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM