Not able to Call C# Function from MATLAB Script

I am using below C# function :
[InterfaceType(ComInterfaceType.InterfaceIsDual), Guid("XXXXX-XXXX-XXXX-XXXX-XXXXXXX")]
public interface ILauncher
{
void launch();
}
[ClassInterface(ClassInterfaceType.None), Guid("YYYYYYY-YYYY-YYYY-YYYY-YYYYYYY"), ProgId("ActiveXObjects.Launcher")]
public class Launcher : ILauncher
{
public void launch()
{
Console.WriteLine("I launch scripts for a living.");
}
}
I want this C# function to be called from my MATLAB Script : like this : net = actxserver('ActiveXObjects.Launcher');
net.launch()
But I am not able to Launch Console Window,I am Expecting output as "I launch scripts for a living.".
Can anyone please suggest am I doing something wrong ?
Simply I am getting ActiveX on Command window whenever I run the Script.
Is this a right way to call C# Function from MATLAB ?

回答(1 个)

There is no need to give your .Net class a dual interface, nor is there any need to go through COM to call .Net code from matlab. You can call .Net code directly from matlab.
Something like this should work:
NET.addAssembly('fullpathtoyourassembly');
YourAssemblyName.Launcher.launch

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

提问:

2016-6-16

回答:

2016-6-16

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by