I'm working on an application that's embedding Mono, and I have a simple C# struct that is one of the parameters to one of my functions.

How do I create and pass that struct from C++ to C#?

If I have a C# struct like so:

 struct CSStruct
 {
     int mInt;
     float mFloat;
 }

Can I create a strict C++ version and pass it to mono like so?

struct CStruct
{
    int mInt;
    float mFloat;
}

// ...
CStruct var = { 10, 30.0f };
void* args[1] = { &var };
mono_runtime_invoke(method, NULL, args, NULL);
有帮助吗?

解决方案

Yes, that is the way it's supposed to work: value types are passed in the arguments array in mono_runtime_invoke () by taking the pointer to the value type data.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top