C # calls the DLL of C + +, the structure body array as a reference parameter passing way

Source: Internet
Author: User

C # calls a DLL of C + +, which returns an array of the DLL's custom structures, and the parameters passed in C # are the first element of the custom structure array, remembering that it is the first element, not the first address. The parameters of C + + are pointers to custom structure bodies.

1.c# Code:

(1)

public class Form1:System.Windows.Forms.Form
{
public struct Leak_rect
{
int x;
int y;
int width;
int height;
};
[DllImport (@ "ObjectScan.dll", CharSet = charset.ansi, callingconvention = callingconvention.stdcall, EntryPoint = "leak _crack_detect ")]
public extern static byte Leak_crack_detect (string imgname, string txtfile, ref int c_x, ref int c_y, ref int C_W, ref int C_h, ref leak_rect leak_rects, ref int leak_num);

...

}

private void Button3_Click (object sender, EventArgs e)
{
String txtfile= "D:\\detect.txt";//text file, format per line: filename, 1 or 0 (with a leak of 1, otherwise 0), 1 or 0 (with crack 1, no 0)
Create a Detect.txt file in the selected directory
int c_x=0;//crack box X coordinate
int c_y = 0;//fracture box y-coordinate
int c_w=0;//Crack Box width
int c_h=0;//crack Box high
leak_rect[] leak_rects = new LEAK_RECT[20];
int leak_num=0;
Best Picture frame still leaking with red box, crack with green box, consistent with the file I generated
byte Bdetect = leak_crack_detect (m_filename,txtfile,ref c_x,ref c_y,ref c_w,ref c_h,ref leak_rects[0],ref);
}

(2) C + + code

. h Files:

struct RECT_STRU
{
int x;
int y;
int width;
int height;
};

. cpp file:

extern "C" __declspec (dllexport) bool __stdcall leak_crack_detect (char* imgname,char* txtfile,int &c_x,int-&c_y , int &c_w,int &c_h,rect_stru *leak_rects,int &leak_num)
{

...

}

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.