I have c++ unmanaged code that i want to access from c#. So i followed some tutorials and i build a dll for my project (only one class btw). Now i want to use it from c#, an
I think you should just pass Arrays of your types and then convert them to vector<T>
's or List's in the relative functions.
What it could also be is the fact you referenced a static extern
INTcalibrate_to_file()
and in C++ it is VOIDcalibrate_to_file()
UPDATE:
And I think you are missing the DLLEXPORT
tags on your functions?
You could marshal a C# array as a C++ std::vector, but it would be very complicated and is simply not a good idea because the layout and implementation of std::vector is not guaranteed to be the same between compiler versions.
Instead you should change the parameter into a pointer to an array, and add a parameter specifying the length of the array:
int calibrate_to_file(points* pontos, int length);
And in C# declare the method as taking an array and apply the MarshalAs(UnmanagedType.LPArray) attribute:
static extern int calibrate_to_file([MarshalAs(UnmanagedType.LPArray)]] Point[] pontos, int length);
Note also that your C++ point structure is not compatible with System.Windows.Point. The latter doesn't have a z member.
But a bigger issue with your code is that you can't really expect to DLL-import an instance method and be able to call it just like that. An instance method needs an instance of its class, and there's no easy way to create an instance of a non-COM C++ class from C# (and is also not a good idea). Therefore, you should turn this into a COM class, or create a C++/CLI wrapper for it.