Hi John,
I can only guess at what is going wrong. I see two possible errors. One
being that the array is managed and not of constant length. The other being
that you use a class instead of a struct. Perhaps you should try the
following:
[ StructLayout( LayoutKind.Sequential, Pack = 1 ) ]
public struct Frame_t
{
[ MarshalAs( UnmanagedType.ByValArray,
ArraySubType = UnmanagedType.U1,
SizeConst = 144 ) ]
public byte[] Block;
}
//...
public void MyDataHandler( IntPtr appContext, IntPtr data )
{
Frame_t frame = ( Frame_t ) Marshal.PtrToStructure (
data,
typeof( Frame_t )
);
// ...
}
That should work.
HTH,
Tom T.
"John" wrote:
public const int FRAME_LENGTH=144;
[StructLayout(LayoutKind.Sequential, Pack=1)]
public class FRAME_T
{
public byte []Block = new byte[FRAME_LENGTH]; }
public void MyDataHandler(IntPtr appContext, IntPtr data)
FRAME_T frame = new FRAME_T();
Marshal.PtrToStructure(data, frame);
This code throws an exception on the PtrToStructure saying there is a
null reference.
What am I doing wrong?
THANKS!!!
John