How to DllImport this struct?

// C++
struct SM_PARAM
{
char SCA[16];
char TPA[16];
char TP_PID;
char TP_DCS;
char TP_SCTS[16];
char TP_UD[161];
char index;
} ;

How deal as C# struct


Answer this question

How to DllImport this struct?

  • Stormin

    Thank you very much!

  • Chintan Vyas

    i think this depend on the function you will pass this structure to it any way

    is this worked after you change it to CharSet.Ansi



  • MMMalik

    try this

    try this

    [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]

    struct SM_PARAM

    {

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]

    string SCA;

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]

    string TPA;

    char TP_PID;

    char TP_DCS;

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]

    string TP_SCTS;

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 161)]

    string TP_UD;

    char index;

    }

    note:the size of the last array is 161 is thic correct or it is atypo



  • hazz

    I think there should be [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Ansi)]

  • How to DllImport this struct?