C # How to call the complex structure of VC DLL

Source: Internet
Author: User

VC Structure

 

Struct HY_RECT_S

{

Long lLeft;

Long lRight;

Long lTop;

Long lBottom;

};

 

Struct ID_CARD_S

{

Char szText [10] [256];

HY_RECT_S idRect [10];

};

It took a long time to resolve the problem of code Pasting and share it with friends who encountered the same problem.

 

Code
Using System;
Using System. Collections. Generic;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Text;
Using System. Windows. Forms;
Using System. Runtime. InteropServices;

Namespace Test
{
Public partial class Form1: Form
{
[StructLayout (LayoutKind. Sequential, CharSet = CharSet. Ansi, Pack = 1)]
Public struct HY_RECT_S
{
Public long lLeft;
Public long lRight;
Public long lTop;
Public long lBottom;
}
[StructLayout (LayoutKind. Sequential, CharSet = CharSet. Ansi, Pack = 1)]
Public struct ID_CARD_S
{
[Financialas (UnmanagedType. ByValArray, SizeConst = 2560)]
Public byte [] szText;
[Financialas (unmanagedtype. byvalarray, sizeconst = 10)]
Public hy_rect_s [] idrect;
}

[Dllimport ("D: \ dll \ idrcore. dll", entrypoint = "get_idcdata", charset = charset. ANSI)]
Public extern static int get_idcdata (
Int icardtype,
String szFileNameIn,
String szFullFileNameOut,
String szHeadFileNameOut,
Ref ID_CARD_S pstOut );
[DllImport ("D: \ DLL \ IDRCore. dll", EntryPoint = "Device_Open", CharSet = CharSet. Ansi)]
Public static extern int Device_Open ();

[DllImport ("D: \ DLL \ IDRCore. dll", EntryPoint = "Get_IdcPic", CharSet = CharSet. Ansi)]
Unsafe public static extern int Get_IdcPic (int iCardType, String szFileNameIn );

Public Form1 ()
{
InitializeComponent ();
}
Private void button4_Click (object sender, EventArgs e)
{
ID_CARD_S idCardS = new ID_CARD_S ();
StringBuilder szFullFileNameOut = new StringBuilder (1024 );
StringBuilder szHeadFileNameOut = new StringBuilder (1024 );
Unsafe
{

// Fixed (ID_CARD_S * pids = & idCardS)
//{
// IntPtr ipIds = (IntPtr) pids;
Int i0 = Device_Open ();

Int i1 = Get_IdcPic (2, "C: \ 1.bmp ");

Int i2 = Get_IdcData (2, "C: \ 1.bmp", "C: \ 2.bmp", "C: \ 3.bmp", ref idCardS );
Byte [] result = new byte [256];
String [] strResult = new String [10];
Int k = 0;
For (int I = 0; I <10; I ++)
{
For (int j = 0; j <256; j ++)
{
Result [J] = idcards. sztext [k ++];

}
Strresult [I] = fromasciibytearray (result );
}

String S = fromasciibytearray (idcards. sztext );
MessageBox. Show (s );

//}
}

}

Public static String FromASCIIByteArray (byte [] characters)
{
Encoding myEncoding = Encoding. GetEncoding ("gb2312 ");
String sData = myEncoding. GetString (characters );
String constructedString = sData. Trim (). TrimEnd ('\ 0 ');
Return (constructedString );
}
}
}

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.