Hello,
I am trying to create a C# DLL layer for out current C dll. The
following is the current code.
(I apologize if I made any mistakes in converting it to
non-confidential. Also, I'm a complete C# newbie... )
****************************************************************
namespace MyDotNetLayer
{
public enum tRdrEnum1
{
HW = 0,
SW = 1,
};
[StructLayout(LayoutKind.Sequential)]
public struct tRdrStruct1
{
public long mask;
} ;
[StructLayout(LayoutKind.Sequential)]
public struct tRdrStruct2
{
public long plane;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=(int)5 )]
public tRdrStruct1[] s1 ;
} ;
[StructLayout(LayoutKind.Sequential)]
public struct tRdrStruct3
{
public tRdrEnum1 type;
public tRdrStruct2 s2;
} ;
public class CMyDotNetLayer
{
...
[DllImport("mydll.dll",EntryPoint="RdrFunc1")]
private static extern int oRdrFunc1(int rdr, ref tRdrStruct3
s3 ) ;
public int RdrFunc1(int rdr, ref tRdrStruct3 s3 )
{
return oRdrFunc1( rdr, ref s3 ) ;
}
}
}
****************************************************************
This is the calling code :
****************************************************************
private void Form1_Load(object sender, System.EventArgs e)
{
CMyDotNetLayer n = new CMyDotNetLayer() ;
tRdrStruct3 s3 = new tRdrStruct3() ;
s3.type = tRdrEnum1.HW ;
s3.s2.plane = 1 ;
s3.s2.s1 = new tRdrStruct1[ 5 ];
s3.s2.s1[0].mask = 1 ;
n.RdrFunc1( rdr, ref s3 ) ;
}
****************************************************************
When I call oRdrFunc1 (which should be inside the original DLL) I get
the following message box:
****************************************************************
An unhandled exception of type 'System.TypeLoadException' occurred in
MyDotNetLayer.dll
Additional information: Can not marshal field masks of type
MyDotNetLayer.tRdrStruct3: The type definition of this field has no
layout information.
****************************************************************
I've got some other stuff working, so I know I've got something right.
I'm tackling the more complicated functions first, to ensure that
this layer CAN be completed at all.
Thanks in advance,