I have a three layer application:
- C # managed layer.
- C ++ / cli managed layer.
- Unmanaged C ++ level.
The second level is used as the level of communication between C # and native C ++.
public class ManagedResult
{
public float[] firstArray;
public float[] secondArray;
}
and unmanaged class
class UnmanagedResult
{
public:
float* firstArray, secondArray;
int arrayLength;
UnmanagedResult(){};
~UnmanagedResult(){};
}
At the second level, I have the following class method that displays a managed object:
ManagedResult^ CLIContext::GetResults(){
ManagedResult^ primitiveResult = gcnew ManagedResult();
pin_ptr<int> pFirst = &(primitiveResult->firstArray[0]);
pin_ptr<float> pSecond = &(primitiveResult->secondArray[0]);
UnmanagedResult result =UnmanagedResult();
result.firstArray = pFirst;
result.secondArray = pSecond;
_context->GetResults(result);
return primitiveResult;
}
Here _context is an object of an unmanaged class type that manipulates an object of type UnmanagedResult and affects its contents.
This solution is working fine. But I want to be able to pass an object by reference and using a third-party API to distribute and populate the two elements firstArrayand secondArray. How to transfer data from an unmanaged result back to primitiveResult?