.NET assembly - can I call a method with a second "out" argument?

2 views (last 30 days)
Hi all,
Short version:
Is it possible to use a method of a dotnet assembly that returns its second value as a double? Despite MATLAB docs here saying that "Pointer type arguments, function pointers, Dllimport keyword" are not supported, I'm not sure that what I'm trying to do actually falls under that category. Please see below for a clear description of the problem with working example.
Better version:
I have a .NET assembly successfully loaded into MATLAB (see the end of this post for download link to this .dll assembly if you want to try yourself):
ON = NET.addAssembly('c:\tmp\opennurbs\opennurbs.net\OpenNURBS.NET.dll')
I can make some "On3dPoints" (they're just one of the classes in my assembly) successfully, and I can successfully make a curve from them:
p1 = RMA.OpenNURBS.On3dPoint(-15,4,-20);
p2 = RMA.OpenNURBS.On3dPoint(0,0,0);
p3 = RMA.OpenNURBS.On3dPoint(2,5,7);
p4 = RMA.OpenNURBS.On3dPoint(12,15,17);
pArr = NET.createArray('RMA.OpenNURBS.IOn3dPoint', 4);
pArr.Set(0, p1); pArr.Set(1, p2);
pArr.Set(2, p3); pArr.Set(3, p4);
NC = RMA.OpenNURBS.OnNurbsCurve();
NC.CreateClampedUniformNurbs(3,3,pArr);
I can successfully use methods of my curve NC that return multiple outputs, as long as my second outputs are not native types (such as double). This is when the .NET signature includes a reference to a second output variable as one of its input arguments.
outPt = RMA.OpenNURBS.On3dPoint(); % Initialize an "On3dPoint" to store the output
[success, outPt] = NC.EvPoint(2.5, outPt); % Query the curve coords at loc. 2.5
The above returns success=1, and my outPt is now populated with the XYZ coordinates of my curve at location 2.5 of my curve. To me, this is a success at "passing output arguments by reference".
However, if that output argument is a double, then I simply cannot get things to work:
outLen1 = 0; % Try initialising as native MATLAB
outLen2 = System.Double; % Try as System.Double
[success, outLen1] = NC.GetLength(outLen1); % Returns success=0, outLen1=0
[success, outLen2] = NC.GetLength(outLen2); % Errors
The first attempt returns success=0, outLen1=0. The second attempt errors with "No method 'GetLength' with matching signature found for class 'RMA.OpenNURBS.OnNurbsCurve'."
No matter what I try, I simply cannot seem to get a return of anything into a second variable if the output type is double. Can anyone tell me why? Is there a workaround?
For reference, below is the signature to the two "methods" I used in the examples above, as returned by the methods(NC,'-full') command:
[RETURN ARGS] METHOD (METHOD ARGS)
[logical scalar RetVal, RMA.OpenNURBS.On3dPoint point] EvPoint(RMA.OpenNURBS.OnNurbsCurve this, double scalar t, RMA.OpenNURBS.On3dPoint point)
[logical scalar RetVal, double scalar length] GetLength(RMA.OpenNURBS.OnNurbsCurve this, double scalar length, double scalar fractional_tolerance)
To test specifically the assembly .dll file I'm using, you can get it from (<http://www.opennurbs.org>) - it's the "Toolkit (.NET)" download.

Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!