Error using structs in calling unmanaged dll

C

Claire

I don't understand the following error I'm getting when I call the DoOpen
function of my unmanaged dll. Can someone explain please

[DllImport(DllName, CharSet=charset)]
public static extern int DoOpen(ref sRDetails RDetails);

"An unhandled exception of type 'System.TypeLoadException' occurred in
mmonitor.dll
Additional information: Can not marshal field ChDetails of type sRDetails:
This type can not be marshaled as a structure field."

[StructLayout(LayoutKind.Sequential)]
public struct sRDetails
{
public int UniqueID;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_SNAME)]
public string SName;
public sTM TStamp;
public int ChEntries;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = MAX_CH)]
public sChDetails[] ChDetails;
}

[StructLayout(LayoutKind.Sequential)]
public struct sChDetails
{
public sHCode HCode;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_CH_NAME)]
public string ChName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_UNITS)]
public string Units1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_UNITS)]
public string Units2;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_HLLIMIT)]
public string HLLimit;
public float Value;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAXSTR_TRSTATE)]
public string TrState;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top