Problems in integration between C ++ and C #

1

Hello, I'm having problems integrating a C ++ DLL with Unity C #. I found some code ( link )

This is my C ++ code, in it theoretically I send a structure with 2 points for Unity in C #.

struct Pontos {
int i;
float f;
};
Pontos **pontos;
DllExport bool SetPoints(Pontos *** a, int *i)
{
pontos = new Pontos*[4];
for (int j = 0; j < 4; j++) {
        pontos[j] = new Pontos; // Actually create each object.
        pontos[j]->i = j;
        pontos[j]->f = (float)j;
    }
    *a = pontos;
    *i = 4;
    return true;
}

Here is the C # code, where I try to get the points I send and save. In Unity where the script gets added the following message appears "In MonoBehaviour scripts in the file, or their names do not match the file name", I do not know what that means.

[DllImport("dll")]
 private static extern bool SetPoints(out IntPtr ptrResultVerts, out int resultVertLength);
public struct Pontos
{
int i;
float f;
};     
void Start()
{ 
IntPtr ptrNativeData = IntPtr.Zero;
int itemsLength = 0;

bool success = SetPoints(out ptrNativeData, out itemsLength);
if (!success)
{
    return;
}

Pontos[] SArray = new Pontos[itemsLength];  // Where the final data will be stored.
IntPtr[] SPointers = new IntPtr[itemsLength];

Debug.Log("Length: " + itemsLength); // Works!
Marshal.Copy(ptrNativeData, SPointers, 0, itemsLength); // Seems not to work.

for (int i = 0; i < itemsLength; i++)
{
    Debug.Log("Pointer: " + SPointers[i]);
    SArray[i] = (Pontos)Marshal.PtrToStructure(SPointers[i], typeof(Pontos));
}

If someone knows what's wrong please help me. Thanks.

    
asked by anonymous 02.05.2017 / 21:26

0 answers