• 大小: 22KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-25
  • 语言: C#
  • 标签: C#  ID卡  

资源简介

C# ID卡识别硬件读写示例代码

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Collections;
//Download by http://www.codefans.net
namespace IDCard
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public delegate int HookProc(int nCode int wParam IntPtr lParam);
        static int hHook = 0;
        public const int WH_KEYBOARD_LL = 13;
        //LowLevel键盘截获,如果是WH_KEYBOARD=2,并不能对系统键盘截取,Acrobat Reader会在你截取之前获得键盘。  
        HookProc KeyBoardHookProcedure;
        [DllImport(“kernel32“)]
        public static extern int Beep(int dwFreq int dwDuration);//让计算机蜂鸣
        string DataPath = ““;//数据库路径
        OleDbConnection con;//OleDbConnection对象,连接数据库
        OleDbCommand cmd;//OleDbCommand对象,执行SQL语句
        //键盘Hook结构函数  
        [StructLayout(LayoutKind.Sequential)]
        public class KeyBoardHookStruct
        {
            public int vkCode;
            public int scanCode;
            public int flags;
            public int time;
            public int dwExtraInfo;
        }
        [DllImport(“user32.dll“)]
        public static extern int SetWindowsHookEx(int idHook HookProc lpfn IntPtr hInstance int threadId);
        [DllImport(“user32.dll“ CharSet = CharSet.Auto CallingConvention = CallingConvention.StdCall)]
        //抽掉钩子  
        public static extern bool UnhookWindowsHookEx(int idHook);
        [DllImport(“user32.dll“)]
        //调用下一个钩子  
        public static extern int CallNextHookEx(int idHook int nCode int wParam IntPtr lParam);
        [DllImport(“kernel32.dll“)]
        public static extern IntPtr GetModuleHandle(string name);

        public string  getNum(string code)
        {
            string flag = ““;
            switch (code)
            {
                case “048“:
                    flag=“0“; break;
                case “049“:
                    flag = “1“; break;
                case “050“:
                    flag = “2“; break;
                case “051“:
                    flag = “3“; break;
                case “052“:
                    flag = “4“; break;
                case “053“:
                    flag = “5“; break;
                case “054“:
                    flag = “6“; break;
                case “055“:
                    flag = “7“; break;
                case “056“:
                    flag = “8“; break;
                case “057“:
                    flag = “9“; break;
            }
            return flag;
        }
        public void Hook_Start()
        {

            // 安装键盘钩子  
            if (hHook == 0)
            {
                KeyBoardHookProcedure = new HookProc(KeyBoardHookProc);
                

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

----------- ---------  ---------- -----  ----

               254879                    16


评论

共有 条评论