I am trying to use C++ code in my C# application. The following structure is created:
System.Runtime.InteropServices.StructLayout(
System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct My_FSet
{
public int Num;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 100)]
public uint[] Freqs;
}
I want to use it like an array in my code, like
My_FSet FSet = new My_FSet();
FSet.Freqs[0] = 1000;
FSet.Freqs[1] = 2500;
FSet.Freqs[3] = 3200;
But I get an error:
An unhandled exception of type 'System.NullReferenceException' occurred in MyApp.exe
Additional information: Object reference not set to an instance of an object.
It seems as if the array is not properly initialized, but I cannot do that in the struct, so how can I resolve this?