📄 pccard.cpp
字号:
#include "stdafx.h"
#include "pccard.h"
const int READ_SIZE = 512;
const int MAX_REGIONS_NUM = 32;
const int BUFFER_SIZE = 16*1024;
HANDLE CSWDM;
extern BYTE *Buffer;
const DWORD UnitSize [8] =
{
512UL, 2048UL, 8192UL, 32768UL,
128*1024UL, 512*1024UL, 2048*1024UL, 0
};
DWORD CSOpen (VOID)
{
// CSWDM = CreateFile("\\\\.\\APSoft-Func-Device0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
// NULL, OPEN_EXISTING, 0, NULL);
CSWDM = CreateFile("\\\\.\\FUJIXEROX-READCARD-Device0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (CSWDM == INVALID_HANDLE_VALUE)
return GetLastError ();
else
return NO_ERROR;
}
DWORD CSGetCardServicesInfo(VOID)
{
DWORD dwResult = 0;
BOOL bStatus;
DWORD dwVersion = 0;
bStatus = DeviceIoControl(CSWDM, IOCTL_GET_VERSION,
NULL, 0,
&dwVersion, sizeof(dwVersion),
&dwResult, NULL);
if(!bStatus)
{
return -1;
}
return NO_ERROR;
}
DWORD CSRegClient()
{
BOOL bStatus; // Status of the IOCTL ...
DWORD dwBytesRet = 0; // Number of the returned bytes
bStatus = DeviceIoControl(CSWDM, IOCTL_REG_CLIENT,
NULL, 0,
NULL, 0,
&dwBytesRet, NULL);
if(!bStatus)
{
return -1;
}
return NO_ERROR;
}
DWORD CSRelClient()
{
BOOL bStatus; // Status of the IOCTL ...
DWORD dwBytesRet = 0; // Number of the returned bytes
bStatus = DeviceIoControl(CSWDM, IOCTL_REL_CLIENT,
NULL, 0,
NULL, 0,
&dwBytesRet, NULL);
if(!bStatus)
{
return -1;
}
return NO_ERROR;
}
DWORD CSDetectCard(WORD &dwSocket)
{
BOOL bStatus; // Status of the IOCTL ...
DWORD dwMask = 0; // Socket mask
DWORD dwBytesRet = 0; // Number of the returned bytes
DWORD dwSockMask = 0; // Output structure for IOCTL
int Socket = 0;
bStatus = DeviceIoControl(CSWDM, IOCTL_GET_MASK,
NULL, 0,
&dwSockMask, sizeof(dwSockMask),
&dwBytesRet, NULL);
if(!bStatus)
{
return -1;
}
dwMask = dwSockMask;
for (int i = 0; i < 32; i++)
{
if ( dwMask & (0x01 << i) )
{
Socket = i;
}
}
dwSocket = Socket;
return NO_ERROR;
}
DWORD ReadMemoryRegion(WORD Socket, DWORD CardOff, DWORD ReadCount)
{
BOOL bStatus; // Status of the IOCTL ...
GET_READMEMORY InIOCTL; // Input structure of the IOCTL ...
DWORD dwBytesRet = 0; // Number of the returned bytes
memset (&InIOCTL, 0, sizeof(InIOCTL));
memset (Buffer, 0, BUFFER_SIZE);
InIOCTL.dwOffset = CardOff;
InIOCTL.dwLength = ReadCount;
bStatus = DeviceIoControl(CSWDM, IOCTL_GET_MEMORY,
&InIOCTL, sizeof(InIOCTL),
Buffer, BUFFER_SIZE,
&dwBytesRet, NULL);
if(!bStatus)
return -1;
return 0;
}
DWORD GetParams(WORD Socket,CS_TYPE &type,DWORD &dwCardSize)
{
BOOL bStatus; // Status of the IOCTL ...
BYTE TubleData[256];
DWORD dwBytesRet = 0;
bStatus = DeviceIoControl(CSWDM, IOCTL_GET_CIS,
NULL, 0,
TubleData, 256,
&dwBytesRet, NULL);
if(!bStatus)
return -1;
int i,units,sizecode,DevType;
i = 3;
DevType = TubleData [2] >> 4;
if ((TubleData[2] & 7) == 7)
//* skip "Extended Device Speed" bytes *
while (TubleData[i++] & 0x80);
if (DevType == 14)
//* skip "Extended Device Type" bytes *
while (TubleData[i++] & 0x80);
units = (TubleData[i] >> 3) + 1;
sizecode = TubleData [i] & 7;
dwCardSize = UnitSize [sizecode] * units;
type = (CS_TYPE)DevType;
return NO_ERROR;
}
BOOL CSClose (VOID)
{
return CloseHandle (CSWDM);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -