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 );
}
}
}