Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 :)

like image 299
Aghdas Avatar asked Aug 03 '26 04:08

Aghdas


1 Answers

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();
like image 170
CitizenInsane Avatar answered Aug 04 '26 16:08

CitizenInsane