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!