How to invoke a .NET-method which expects a .NET-struct as parameter?
2 ビュー (過去 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!