- Home /
Is it possible to pass references to structures containing array of references as from C# to C dll?
Hi everyone! I am trying to write a C dll plugin for my Unity project that performs some algorithmic calculation based on a set of structured data. As an example, I have a few structures defined in C++ below to explain what I mean.
struct typeC
{
int units;
};
struct typeB
{
char* name;
int index;
float speed;
typeC** pArrayofC;
int NumOfC;
};
struct typeA
{
int NumObj;
typeB** pArrayOfB;
int NumOfB;
};
As you can see from the above structs, typeA contains an array of pointers to typeB objects and a corresponding number indicating the size of the array. Struct typeB and typeC has similar relationship. This forms some of sort of database with chain referencing in C++.
The problem is I want the Unity C# class to be the owner of these objects (fully in charge of creation and deletion of them) and simply pass a reference to a single typeA object to the C dll such that it can read through the whole "database" and perform its algorithm but I have no idea how to write the C# definitions and code for these structs. I have read abit about marshalling structures to/fro C#/C and have seen some examples but couldn't find any examples similar to my case.
Is it possible to do what I have described? Can anyone give me some help/tips/advice on this?
Your answer
