How to invoke a .NET-method which expects a .NET-struct as parameter?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
is this possible at all in Matlab? I have a .NET assembly with a method that expects a .NET struct as parameter. I can't figure out how to create an appropriate struct for the method. I always get the error
"No method 'TestNETNameSpace.TestNETClass.passStructToMe' with matching signature found."
with this Matlab code or my other attempts:
asmbl = NET.addAssembly('C:\Test\testNETAssembly.dll');
import TestNETNameSpace.*
result1 = TestNETClass.passIntToMe(42); % This works fine.
% Question: How to make this right?
Matlabstruct.stringInStruct = "hello";
Matlabstruct.doubleInStruct = 12.5;
result2 = TestNETClass.passStructToMe(Matlabstruct); % This throws an error.
This is the C# -code of my assembly testNETAssembly.dll.
namespace TestNETNameSpace
{
public static class TestNETClass
{
public struct TestNETStruct
{
public string stringInStruct;
public double doubleInStruct;
}
public static string passStructToMe(TestNETStruct str)
{
return str.stringInStruct;
}
public static int passIntToMe(int i)
{
return i;
}
}
}
0 个评论
回答(1 个)
Mohammad Sami
2025-4-23
编辑:Mohammad Sami
2025-4-23
You can follow the type converstion between Matlab and .NET here
In particular your .NET function would need to accept the following type of variable.
MathWorks.MATLAB.Types.MATLABStruct
MathWorks.MATLAB.Types.MATLABStruct[]
MathWorks.MATLAB.Types.MATLABStruct[,,...]
If you are trying to use a third parties code, I assume you will then have to write your own wrapper functions in .NET which covert your matlab data into the type required for your third party library to work.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!