OSDN Git Service

add dist
[rec10/rec10-git.git] / dist / trunk / b25-remote / b25-client.cpp
1 // MllMain.cpp : DLL \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\83G\83\93\83g\83\8a \83|\83C\83\93\83g\82ð\92è\8b`\82µ\82Ü\82·\81B\r
2 //\r
3 #include <winscard.h>
4 #include <stdio.h>\r
5 #include "CasProxy.h"\r
6 #include "W2L.h"\r
7 #ifndef SCARD_AUTOALLOCATE
8   #define SCARD_AUTOALLOCATE (DWORD)(-1)  /**< see SCardFreeMemory() */
9 #endif\r
10
11 //////////////////////////////////////////////////////////////////////\r
12 // WinSCard\83t\83b\83N\r
13 //////////////////////////////////////////////////////////////////////\r
14 LONG SCardConnect(SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol)\r
15 {\r
16         // \83v\83\8d\83L\83V\83C\83\93\83X\83^\83\93\83X\90\90¬\r
17         CCasProxy *pCasProxy = new CCasProxy();\r
18
19         // \83T\81[\83o\82É\90Ú\91±\r
20         if(!pCasProxy->Connect()){\r
21                 delete pCasProxy;\r
22                 *phCard = NULL;\r
23                 return SCARD_E_READER_UNAVAILABLE;\r
24                 }
25 \r
26         // \83n\83\93\83h\83\8b\82É\96\84\82ß\8d\9e\82Þ\r
27         *phCard = reinterpret_cast<SCARDHANDLE>(pCasProxy);\r
28         if(pdwActiveProtocol)*pdwActiveProtocol = SCARD_PROTOCOL_T1;\r
29 \r
30         return SCARD_S_SUCCESS;\r
31 }\r
32 \r
33 LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)\r
34 {\r
35         // \83T\81[\83o\82©\82ç\90Ø\92f\r
36         CCasProxy *pCasProxy = reinterpret_cast<CCasProxy *>(hCard);\r
37         if(pCasProxy)delete pCasProxy;\r
38 \r
39         return SCARD_S_SUCCESS;\r
40 }\r
41 \r
42 LONG SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext)\r
43 {
44         return SCARD_S_SUCCESS;\r
45 }\r
46 \r
47 LONG SCardFreeMemory(SCARDCONTEXT hContext, LPCVOID pvMem)\r
48 {\r
49         return SCARD_S_SUCCESS;\r
50 }\r
51 \r
52 LONG SCardListReaders(SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders)\r
53 {\r
54         const char szReaderName[] = "BonCasLink Proxy Card Reader\0";\r
55 \r
56         if(pcchReaders){\r
57                 if((*pcchReaders == SCARD_AUTOALLOCATE) && mszReaders){\r
58                         *((LPCSTR *)mszReaders) = szReaderName;         \r
59                         return SCARD_S_SUCCESS;\r
60                         }\r
61                 else{\r
62                         *pcchReaders = sizeof(szReaderName);\r
63                         }\r
64                 }\r
65 \r
66         if(mszReaders) memcpy(mszReaders, szReaderName, sizeof(szReaderName));\r
67 \r
68         return SCARD_S_SUCCESS;\r
69 }\r
70 \r
71 LONG SCardTransmit(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength)\r
72 {\r
73         // \83T\81[\83o\82É\83\8a\83N\83G\83X\83g\91\97\8eó\90M\r
74         CCasProxy *pCasProxy = reinterpret_cast<CCasProxy *>(hCard);\r
75         if(!pCasProxy)return SCARD_E_READER_UNAVAILABLE;\r
76 \r
77         DWORD dwRecvLen = pCasProxy->TransmitCommand(pbSendBuffer, cbSendLength, pbRecvBuffer);\r
78         if(pcbRecvLength)*pcbRecvLength = dwRecvLen;\r
79 \r
80         return (dwRecvLen)? SCARD_S_SUCCESS : SCARD_E_TIMEOUT;\r
81 }\r
82 \r
83 LONG SCardReleaseContext(SCARDCONTEXT hContext)\r
84 {\r
85         return SCARD_S_SUCCESS;\r
86 }\r
87