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