3

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

4
  • It is not necessary to make your class COM visible to use NET.addAssembly but your class just need at least to be public Commented Jul 15, 2014 at 9:22
  • hmm, tnQ. but now I cant access to the methods! Commented Jul 15, 2014 at 10:51
  • Well, the methods you want to access have to be public too ... Commented Jul 15, 2014 at 14:23
  • See sample code in my answer. Commented Jul 15, 2014 at 14:38

1 Answer 1

3

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.