<span style="font-family: 'Courier New', Courier, Monospace; font-size: 12px"><p><span style="font-size:12px;"><span style="font-family:arial,helvetica,sans-serif;">Yes, I saw you closed your issue, but I was going to suggest we move the discussion over hear beforehand.  It's probably not not something I will get around to fixing, but I was interested in tracking down the cause of the behavior you were seeing.</span></span></p>

<p><span style="font-size:12px;"><span style="font-family:arial,helvetica,sans-serif;">Moving your project into CLR C++ might simplify the work syntactically, but your still going to require the same careful attention.  I find it is quite easy to write mixed C#/C++ as long as you follow a rigid pattern for how you operate on your data, where you do your allocations, and how you write your C++ signatures.</span></span></p>

<div> </div>

<div>
<div><span style="font-size: 11px;">///----------------------------------------------------------------------------</span></div>

<div>    Your Code</div>

<div><span style="font-size: 11px;">///----------------------------------------------------------------------------</span></div>
</div>

<div> </div>

<div>
<div><span style="font-size:11px;">// Create two points.<br />
float[] pt0 = new float[3] { 0.0F, 0.0F, 0.0F };<br />
float[] pt1 = new float[3] { 1.0F, 1.0F, 1.0F };</span></div>

<div> </div>

<div><span style="font-size:11px;">fixed(float* pt0_p = pt0, pt1_p = pt1)<br />
{<br />
    // Find the squared distance between the points.<br />
    squaredDistance = vtkMath.Distance2BetweenPoints(new IntPtr(pt0_p), new IntPtr(pt1_p));<br />
}</span></div>

<div> </div>

<div><span style="font-size:11px;">double distance = Math.Sqrt(squaredDistance);</span></div>

<div> </div>

<div><span style="font-size:11px;">///----------------------------------------------------------------------------</span></div>

<div>    The ActiViz generated pinvoke signature </div>

<div><span style="font-size:11px;">///----------------------------------------------------------------------------</span></div>
</div>

<div> </div>

<div><span style="font-size:11px;">[DllImport(vtkCommonCoreEL_dll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "vtkMath_Distance2BetweenPoints_21")]<br />
internal static extern float vtkMath_Distance2BetweenPoints_21(IntPtr p1, IntPtr p2);</span></div>

<div> </div>

<div>
<div><br />
<span style="font-size:11px;">///----------------------------------------------------------------------------</span></div>

<div>    The ActiViz generated wrapper function</div>

<div><span style="font-size:11px;">///----------------------------------------------------------------------------<br />
<br />
public static float Distance2BetweenPoints(IntPtr p1, IntPtr p2)<br />
{</span><br />
    <span style="font-size:11px;">float rv = vtkMath_Distance2BetweenPoints_21(p1, p2);</span><br />
    <span style="font-size:11px;">return rv;<br />
}</span></div>

<div> </div>

<div><font face="arial, helvetica, sans-serif">I don't know if it is an option for your project, but as I said previously, I normally use the unsafe flag, so that I can do allocation in C#, pin those arrays, then pass pointers into C functions to be operated on.  Unlike the Activiz autogenerated signature above, by not using IntPtr, and using strongly type pointers, its is much easier to keep track of what is going on.</font></div>

<div> </div>

<div>
<div>
<div><span style="font-size: 11px;">///----------------------------------------------------------------------------</span></div>

<div>    Sample signature </div>

<div><span style="font-size: 11px;">///----------------------------------------------------------------------------</span></div>
</div>

<div> </div>

<div><span style="font-size: 11px;">[DllImport(myDSP_dll, CallingConvention = CallingConvention.Cdecl, EntryPoint = "myDSP_doSomething")]<br />
internal static extern int myDSP_doSomething(double* input, double* output);</span></div>

<div> </div>

<div>
<div>
<div><span style="font-size: 11px;">///----------------------------------------------------------------------------</span></div>

<div>    Sample C# Code</div>

<div><span style="font-size: 11px;">///----------------------------------------------------------------------------</span></div>
</div>

<div><br />
<span style="font-size: 11px;">double[] x = new double[3] { 0.0, 0.0, 0.0 };<br />
double[] y = new double[3];</span></div>

<div>
<div> </div>

<div><span style="font-size: 11px;">fixed(double* px = x, py = y)<br />
{<br />
    if(!myDSP_doSomething(px,py))</span></div>

<div>        throw new MyException()<br />
<span style="font-size: 11px;">}</span></div>
</div>

<div> </div>

<div><span style="font-family: arial, helvetica, sans-serif;">With attention to house keeping inside of your C++ </span>DllMain<span style="font-family: arial, helvetica, sans-serif;">,  it is rather easy to keep allocations split up between managed and unmanaged, and stay out of trouble generating memory leaks.  So I will end up with only code having to do with the GUI, user interaction, in the C# side, and all of the data processing happening in C++.</span></div>
</div>
</div>
</div>

<div> 
<div>Mark DeArman</div>

<div>Cascade Acoustic Research</div>

<div>http://www.cascadeacoustic.com</div>

<div>(253) 200-5353</div>
</div>

<div> </div>

<hr align="center" size="2" width="100%" />
<div><span style="font-family: tahoma,arial,sans-serif; font-size: 10pt;"><b>From</b>: "csumushu" <csumushu@126.com><br />
<b>Sent</b>: Thursday, November 9, 2017 5:45 AM<br />
<b>To</b>: vtkusers@vtk.org<br />
<b>Subject</b>: Re: [vtkusers] SPAM-LOW: How to use vtkMath functions in ActiViz.NET for data of type double?</span>

<div> </div>
Oh wow, nice to see you again, a few days ago I had questions to ask your<br />
advice on Github.<br />
How about using C++ CLR instead of PInvoke? For some classes, such as<br />
vtkTransform, I want to call the entire class, not some member functions.<br />
<br />
<br />
<br />
--<br />
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html<br />
_______________________________________________<br />
Powered by www.kitware.com<br />
<br />
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html<br />
<br />
Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ<br />
<br />
Search the list archives at: http://markmail.org/search/?q=vtkusers<br />
<br />
Follow this link to subscribe/unsubscribe:<br />
http://public.kitware.com/mailman/listinfo/vtkusers<br />
 </div></span>