C # Package C++dll

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.