日期:2014-05-18 浏览次数:21021 次
        [StructLayout(LayoutKind.Sequential)]
        public struct FP_MatchParam
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
            public Int32[] nFPosArr;//指位信息,0-9为合法值
            [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.SysInt, SizeConst = 2)]
            public IntPtr[] probe_finger;//指纹特征数组,NULL表示无指纹特征
            public Int32 nThreshold; //比对相似度阈值,建议设为260
            public Int32 nCandidateN; //最大返回候选数量,通常设为1
        }
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
        public struct FP_MatchResult
        {
            public Int32 nCandidateN;//实际返回候选数量
            public IntPtr id_arr;//候选结果ID列表
            public IntPtr SimArr;//候选结果相似度列表
        }
            [DllImport("MyDll.dll")]
            public static extern int FP_Match([In] ref FP_MatchParam pMatchParam, [Out] out FP_MatchResult pResult);
            const int MaxCandidate = 2;
            FP_MatchParam param = new FP_MatchParam();
            param.nFPosArr = new Int32[2] { 9, 9 };
            Byte[] probe_finger1 = new Byte[10];
            Byte[] probe_finger2 = new Byte[10];
            GCHandle gch1 = GCHandle.Alloc(probe_finger1, GCHandleType.Pinned);
            GCHandle gch2 = GCHandle.Alloc(probe_finger2, GCHandleType.Pinned);
            param.probe_finger = new IntPtr[2] { 
                Marshal.UnsafeAddrOfPinnedArrayElement(probe_finger1, 0), 
                Marshal.UnsafeAddrOfPinnedArrayElement(probe_finger2, 0) };
            param.nThreshold = 260;
            param.nCandidateN = MaxCandidate;
            FP_MatchResult result = new FP_MatchResult();
            IntPtr[] arrIdPtr = new IntPtr[MaxCandidate];
            Int32[] arrSim = new Int32[MaxCandidate];
            GCHandle gch3 = GCHandle.Alloc(arrIdPtr, GCHandleType.Pinned);
            GCHandle gch4 = GCHandle.Alloc(arrSim, GCHandleType.Pinned);
            result.id_arr = Marshal.UnsafeAddrOfPinnedArrayElement(arrIdPtr, 0);
            result.SimArr = Marshal.UnsafeAddrOfPinnedArrayElement(arrSim, 0);
            LibWrap.FP_Match(ref param, out result);
            for (int i = 0; i < result.nCandidateN; i++)
            {
                Console.WriteLine("ID:{0}", Marshal.PtrToStringA