调用wince扫描机红外扫描
public class CLR_Barcode_1D { [DllImport("DeviceAPI.dll",EntryPoint="Barcode1D_init")] private static extern bool Barcode1D_init(); [DllImport("DeviceAPI.dll", EntryPoint = "Barcode1D_scan")] private static extern int Barcode1D_scan(byte[] pszData); [DllImport("DeviceAPI.dll", EntryPoint = "Barcode1D_free")] private static extern void Barcode1D_free(); public static bool Scan(out string barcode) { Barcode1D_init(); byte[] pszData = new byte[64]; int iRes = Barcode1D_scan(pszData); Barcode1D_free(); if (iRes > 0) { barcode = System.Text.Encoding.GetEncoding(0).GetString(pszData, 0, iRes).Trim(); if (barcode.Length > 0) { return true; } else { return false; } } else { barcode = string.Empty; return false; } } }
调用
string barcode; bool result = CLR_Barcode_1D.Scan(out barcode); this.txtBarcode.Text = barcode;//扫描结果 if (result) { //TODO }