Structure pointer

I want to write a wrapper for an sdk board with C #. function implementation in sdk:

void WINAPI GetSysInfo(TC_INI_TYPE *TmpIni);

that TC_INI_TYPE is a structure as shown 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 can i write a shell for a structure TC_INI_TYPE.

+3
source share
1 answer
[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 also want to change the value of Pack based on what you need.

For GetSysInfo, follow these steps:

[DllImport("")] 
private static extern void GetSysInfo([In,Out] ref TC_INI_TYPE tcIniType); 
+4
source

Source: https://habr.com/ru/post/1727865/


All Articles