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)
{
...
}