How to start a C# project with VTK

Thanks for the feedback. The problem on your side may be caused by the use of gcnew, I would need to investigate further. The following approach works well on my side:

C#:

    [DllImport("NativeVTK.dll", CallingConvention = CallingConvention.Cdecl)]
    static extern void PrintPoints(IntPtr points);

    public static void Main(String[] argv)
    {
        vtkSphereSource sphere = vtkSphereSource.New();
        sphere.Update();
        PrintPoints(sphere.GetOutput().GetPoints().GetCppThis().Handle);
    }

C++:

#include "vtkPoints.h"

extern "C" __declspec(dllexport) void PrintPoints(void* pts) {
  vtkPoints* points = static_cast<vtkPoints*>(pts);
  std::cout << "PTS " << points->GetNumberOfPoints() << std::endl;
}
1 Like