I have a managed C++ function which returns a class array:
Managed C++ code:
public ref class Sample
{
public:
double Open;
double Close;
};
public ref class ManagedTest
{
array<Sample^>^ ManagedTest::TestFunction()
{
//body
}
};
TestFunction()
is called in a C# application. I created same Sample
Class in C# and try to get return value. But I get compilation error about conversion.
Here is my C# code:
[StructLayout(LayoutKind.Sequential, Size = 100), Serializable]
public class Sample
{
public double Open;
public double Close;
}
//No. 100 I can manage, just written a random number
Sample[] randomValues = new Sample[100]; //Array of random numbers
GCHandle handle = GCHandle.Alloc(randomValues, GCHandleType.Pinned);
var randPtr = handle.AddrOfPinnedObject();
var test = new ManagedTest();
randPtr = test.TestFunction();
How can I convert this managed C++ class array into C# one?