📄 testpdacarddlg.cpp
字号:
// testpdacardDlg.cpp : implementation file
//
#include "stdafx.h"
#include "testpdacard.h"
#include "testpdacardDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestpdacardDlg dialog
CTestpdacardDlg::CTestpdacardDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestpdacardDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestpdacardDlg)
iSid=1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestpdacardDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTestpdacardDlg)
DDX_Control(pDX, IDC_LIST_DATA, m_list_data);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestpdacardDlg, CDialog)
//{{AFX_MSG_MAP(CTestpdacardDlg)
ON_BN_CLICKED(IDC_BTN_READ, OnBtnRead)
ON_BN_CLICKED(IDC_BTN_CLOSE, OnBtnClose)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestpdacardDlg message handlers
BOOL CTestpdacardDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
this->SetWindowText(_T("卡测试"));
return TRUE; // return TRUE unless you set the focus to a control
}
void CTestpdacardDlg::OnBtnClose()
{
// TODO: Add your control notification handler code here
typedef int (WINAPI *ICCCLOSE)(int);
HINSTANCE dllinstance;
dllinstance=::LoadLibrary(_T("ICC_DLL.dll"));
if (dllinstance==NULL)
{
m_list_data.AddString(_T("装载ICC_DLL.dll失败!"));
return ;
}
ICCCLOSE ICC_Close;
ICC_Close=(ICCCLOSE)GetProcAddress(dllinstance,_T("ICC_Close"));
if (ICC_Close==NULL)
{
m_list_data.AddString(_T("函数寻址失败!"));
return ;
}
int i=ICC_Close(3);
CString temp="";
temp.Format(_T("%d"),i);
m_list_data.AddString(temp);
FreeLibrary(dllinstance);
}
void CTestpdacardDlg::OnBtnRead()
{
// TODO: Add your control notification handler code here
typedef int (WINAPI *ICC_INIT)(int,int);
typedef int (WINAPI *ICCRDETECT)(int);
typedef int (WINAPI *ICCR_AUTHENTICATE_A)(int ,int ,byte*);
typedef int (WINAPI *ICCR_AUTHENTICATE_B)(int ,int ,byte*);
typedef int (WINAPI *ICCREAD)(int ,int ,void*,int*);
typedef int (WINAPI *ICCWRITE)(int ,int ,void*,int);
HINSTANCE dllinstance;
dllinstance=::LoadLibrary(_T("ICC_DLL.dll"));
if (dllinstance==NULL)
{
m_list_data.AddString(_T("装载ICC_DLL.dll失败!"));
return ;
}
ICC_INIT ICC_Init;
ICCRDETECT ICCR_Detect;
ICCR_AUTHENTICATE_A ICCR_Authenticate_A;
ICCR_AUTHENTICATE_B ICCR_Authenticate_B;
ICCREAD ICC_Read;
ICCWRITE ICC_Write;
ICC_Init=(ICC_INIT)GetProcAddress(dllinstance,_T("ICC_Init"));
ICCR_Detect=(ICCRDETECT)GetProcAddress(dllinstance,_T("ICCR_Detect"));
ICCR_Authenticate_A=(ICCR_AUTHENTICATE_A)GetProcAddress(dllinstance,_T("ICCR_Authenticate_A"));
ICCR_Authenticate_B=(ICCR_AUTHENTICATE_B)GetProcAddress(dllinstance,_T("ICCR_Authenticate_B"));
ICC_Read=(ICCREAD)GetProcAddress(dllinstance,_T("ICCRead"));
ICC_Write=(ICCWRITE)GetProcAddress(dllinstance,_T("ICCWrite"));
if (ICC_Init==NULL&&ICCR_Detect==NULL&&ICC_Read==NULL&&ICC_Write==NULL&&ICCR_Authenticate_A==NULL&&ICCR_Authenticate_B==NULL)
{
m_list_data.AddString(_T("函数寻址失败!"));
return ;
}
CString temp,temp1;
unsigned char sendbuf[6]={0};
unsigned char recvbuf[20]={0};
int len=0;
unsigned char code=1;
iSid=ICC_Init(3,51);
if (iSid<0)
{
temp=_T("初始化非接触式IC卡控制器发生错误");
m_list_data.AddString(temp);
return ;
}
m_cardstate=ICCR_Detect(iSid);
temp.Format(_T("%d"),m_cardstate);
temp=_T("检测是否有卡:")+temp;
m_list_data.AddString(temp);
m_cardstate=ICCR_Authenticate_A(iSid,0,&code);
temp.Format(_T("%d"),m_cardstate);
temp=_T("AUTHENTICATE_A:")+temp;
m_list_data.AddString(temp);
memset(sendbuf,0xff,6);
ICC_Write(iSid,0,sendbuf,10);
ICC_Read(iSid,0,recvbuf,&len);
for(int i=0;i<len;i++)
{
temp.Format(_T("%02X "),recvbuf[i]);
temp1+=temp;
}
m_list_data.AddString(temp1);
FreeLibrary(dllinstance);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -