IC卡读写器c++builder源代码(2)

本文提供了一段使用C++Builder编写的IC卡读写器的详细代码,包括读卡、写卡、修改密码和读取设备编号等功能。通过动态链接库OUR_MIFARE.dll实现与IC卡的交互,代码中包含错误处理和操作提示。
摘要由CSDN通过智能技术生成

 

 

IC读卡器使用界面:

 

 

 

 

 

 

 

详细代码

 

 

 

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

//控制字定义
#define BLOCK0_EN  0x01
#define BLOCK1_EN  0x02
#define BLOCK2_EN  0x04
#define NEEDSERIAL 0x08
#define EXTERNKEY  0x10
#define NEEDHALT   0x20
//广州荣士电子有限公司,联系电话020-82318861,82322852,定制13826029618 网址http://www.icmcu.com

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::Button1Click(TObject *Sender)
//轻松读卡
{
/*
技术支持:
网站:
*/

        unsigned char status;//存放返回值
        unsigned char myareano;//区号
        unsigned char authmode;//密码类型,用A密码或B密码
        unsigned char myctrlword;//控制字
 unsigned char mypicckey[6];//密码
        unsigned char mypiccserial[4];//卡序列号
        unsigned char mypiccdata[48]; //卡数据缓冲

        unsigned char (__stdcall *piccreadex)(unsigned char ctrlword,unsigned char *serial,unsigned char area,unsigned char keyA1B0,unsigned char *picckey,unsigned char *piccdata0_2);
        //判断动态库是否存在
        AnsiString FileName=ExtractFilePath(Application->ExeName);
        if(FileName.SubString(FileName.Length(),1) != "//")
        {
             FileName += "//";
        }
        FileName += "OUR_MIFARE.dll";
        if(!FileExists(FileName))
        {
                ShowMessage("无法在应用程序的文件夹找到OUR_MIFARE.dll");
                return;
        }
        //提取函数
        HINSTANCE hDll;
        hDll=LoadLibrary(FileName.c_str());
        piccreadex = (unsigned char (__stdcall *)(unsigned char,unsigned char *,unsigned char,unsigned char,unsigned char *,unsigned char *))GetProcAddress(hDll,"piccreadex");

        //控制字指定,控制字的含义请查看本公司网站提供的动态库说明
        myctrlword = BLOCK0_EN + BLOCK1_EN + BLOCK2_EN + EXTERNKEY;

        //指定区号
        myareano = 8;//指定为第8区
        //批定密码模式
        authmode = 1;//大于0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值