Why does (MLApp.MLApp)Marshal.GetActiveObject("MATLAB.Desktop.Application") return NULL?
显示 更早的评论
I am attempting to create a COM connection to a running MATLAB instance from a .NET assembly with the code:
class Program
{
static void Main(string[] args)
{
//Variable
Type matlab;
object[] parameter = new object[1];
object mlObject;
try
{
matlab = Type.GetTypeFromProgID("Matlab.Application");
mlObject = Activator.CreateInstance(matlab);
object[] command = { "matlabroot" };
object testResult = (object)matlab.InvokeMember("Execute", System.Reflection.BindingFlags.InvokeMethod, null, mlObject, command);
....
On some machines this works with any MATLAB version I try it with, where as on others it will not work at all. In these cases, the function simply returns "NULL". This is resolved by using the MATLAB command "regmatlabserver", at which point it will work for any MATLAB instance. I would like to avoid this, as this command requires Admin rights.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Write COM Applications to Work with MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!