Now I have a list of curve (ON_NurbsCurve) calculated inside c++ codes, I want to return those curve data to c#. One solution will be return the number of the curves, then return those curves one by one by a Interop function call.
Is it possible to return those curve data in one call?
MY_C_FUNCTION int GetMyCurvesFunction( ON_SimpleArray<ON_Curve*>* pCurveArray)
{
int rc = 0;
if (pCurveArray)
{
// TODO: Append to curve array
// pCurveArray->Append(..);
rc = pCurveArray->Count();
}
return rc;
}
Managed:
public static Curve[] GetMyCurvesFunction()
{
using (var curves = new Rhino.Runtime.InteropWrappers.SimpleArrayCurvePointer())
{
var ptr_curves = curves.NonConstPointer();
var count = UnsafeNativeMethods.GetMyCurvesFunction(ptr_curves);
var rc = (count == 0)
? new Curve[0]
: curves.ToNonConstArray();
return rc;
}
}
Hi Dale,
In the c# function, the definition is : … ref IntPtr contourCrvs …
In the c++ function, the argument definition is , ON_SimpleArray<ON_Curve*>* contourCrvs …
I have added the following to the beginning of the c++ function:
Here is the exception message in the c# function:
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Source=
StackTrace:
What can be the issue in this case?
Do you know what configuration I need to set in the c# dll project so I can debug the c++ codes as well? Now I can’t step into the c++ codes.
Using the Debug Type drop down, on the standard VS toolbar, set the debug type to Mixed (.NET Framework). You’ll need your C++ project to be set as the “Startup Project” in order to do this.