Reputation: 71
i want to write wrapper for a board sdk with c#. the function implementation in sdk is :
void WINAPI GetSysInfo(TC_INI_TYPE *TmpIni);
that TC_INI_TYPE is a structure as below:
typedef struct {
WORD wCardNo;
WORD wCardType;
WORD wConnect;
WORD wIRQ;
char cbDir[LEN_FILEPATH];
WORD wAddress[MAX_CARD_NO];
WORD wMajorVer;
WORD wMinorVer;
WORD wChType[MAX_CHANNEL_NO];
} TC_INI_TYPE;
how i can write wrapper for structure TC_INI_TYPE
.
Upvotes: 3
Views: 271
Reputation: 50018
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 4)]
public struct TC_INI_TYPE
{
public short wCardNo;
public short wCardType;
public short wConnect;
public short wIRQ;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 32)] // change 32 to LEN_FILEPATH
public char[] cbDir;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 32)] // change 32 to MAX_CARD_NO
public short[] wAddress;
public short wMajorVer;
public short wMinorVer;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 32)] // change 32 to MAX_CHANNEL_NO
public short[] wChType;
}
You might want to also change the Pack value based on what you need.
For GetSysInfo, do the following:
[DllImport("")]
private static extern void GetSysInfo([In,Out] ref TC_INI_TYPE tcIniType);
Upvotes: 4