Returning a Vector3 array from c++ native code

I’ve got a c++ plugin which calculates a vertex array, and I need to assign it to a mesh in c#. I’m wondering how I might be able to transfer my calculated vertex buffer back into c# managed code.

Do I need to deal with Marshalling, or put c# into unsafe mode? I’m not really following the examples I’ve seen so far.

Hi

you have to create a struct in c++ like this in your cpp.h’s extern “C” { } :

	typedef struct _VECTOR3
	{
		float x;
		float y;
		float z;
	} VECTOR3;

Than you can create a method in c++ that accepts an Array of VECTOR3 and can change it.

cpp.h

CPPDLL_API int CreateMesh(VECTOR3* pArray, int size);

cpp.cpp

CPPDLL_API int CreateMesh(VECTOR3* pArray, int size)
{
	for (int i = 0; i < size; i++)
	{
		pArray*.x += 100;*
  • }*
  • return 0;*
    }