Forcing a singleton to be treated as a SAFEARRAY
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a C# method that I want to call from MATLAB that takes as input an array of 'int32's (int[] in C#). The signature in MATLAB is like this:
MyMethod = handle MyMethod(handle, SafeArray(int32))
Sometimes I want the input array to only have one element. This is causing me problems since, whereas I can pass a matrix with multiple elements as a SAFEARRAY, if I have a 1x1 matrix it gives me an error, presumably because it's being passed as type int32 and not SafeArray(int32).
Is there any way I can create in MATLAB a SAFEARRAY with only one element? I can work around this issue by padding a 1x1 matrix with a dummy element, but I'd prefer to do it the right way.
댓글 수: 0
답변 (1개)
Martijn
2011년 2월 25일
The default data conversion rules for MATLAB's COM interface convert all non-scalar MATLAB arrays into 2-dimensional SAFEARRAYs.
Beginning with MATLAB 7.0.4 (R14SP2) it is possible to work around the default data conversion rule and have MATLAB convert a MATLAB array into a single dimensional SAFEARRAY. You can pass data to ActiveX servers as one-dimensional arrays by executing the following command at the MATLAB prompt:
feature('COM_SafeArraySingleDim', 1)
After executing this command, MATLAB will convert any single column matrix to a 1 dimensional array when passed to a COM object.
On a whole different note though, since MATLAB 7.9 (R2009b) you can directly call .NET Assemblies so you do not have to call them through a COM Interface anymore:
참고 항목
카테고리
Help Center 및 File Exchange에서 ActiveX에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!