1. Create a new c#-windows-class library (for creating a C # Class library (. dll) type of project)
2. For normal C + + functions
XXXX_API void Cppfun (int i);
Add in CS code
[DllImport ("C++xxxx.dll")]
public static extern void Cppfun (int i);
3, for the struct in C + +, because the struct default access control in C + + is public, and the struct in C # defaults to private, so to display the specified
typedef struct {
Char sdvrip[16]; /* DVR IP Address */
Char sdvripmask[16]; /* DVR IP address Mask */
DWORD Dwnetinterface; /* 10m/100m Adaptive, Index */
WORD Wdvrport; /* Port number */
BYTE Bymacaddr[macaddr_len]; /* Physical Address of Server */
}net_posa_ethernet;
C # Correspondence
public struct net_posa_ethernet
{
[MarshalAs (UnmanagedType.ByValTStr, SizeConst = 16)]
public string Sdvrip; DVR IP Address
[MarshalAs (UnmanagedType.ByValTStr, SizeConst = 16)]
public string Sdvripmask; DVR IP Address Mask
public UINT Dwnetinterface; Network interface 1-10mbase-t 2-10mbase-t full-duplex 3-100mbase-tx 4-100m Full-duplex 5-10m/100m adaptive
public UINT Wdvrport; Port number
[MarshalAs (UnmanagedType.ByValArray, SizeConst = 6)]
Public byte[] BYMACADDR; [Macaddr_len]; PPPoE user name//physical address of the server
}
C # Package C++dll