-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfcapi.cs
76 lines (61 loc) · 3.04 KB
/
nfcapi.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace NFC_Reader_WPF
{
class nfcapi
{
[DllImport("winscard.dll")]
public static extern uint SCardEstablishContext(uint dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out IntPtr phContext);
[DllImport("winscard.dll", EntryPoint = "SCardListReadersW", CharSet = CharSet.Unicode)]
public static extern uint SCardListReaders(
IntPtr hContext, byte[] mszGroups, byte[] mszReaders, ref UInt32 pcchReaders);
[DllImport("winscard.dll")]
public static extern uint SCardReleaseContext(IntPtr phContext);
[DllImport("winscard.dll", EntryPoint = "SCardConnectW", CharSet = CharSet.Unicode)]
public static extern uint SCardConnect(IntPtr hContext, string szReader,
uint dwShareMode, uint dwPreferredProtocols, ref IntPtr phCard,
ref IntPtr pdwActiveProtocol);
[DllImport("winscard.dll")]
public static extern uint SCardDisconnect(IntPtr hCard, int Disposition);
[StructLayout(LayoutKind.Sequential)]
internal class SCARD_IO_REQUEST
{
internal uint dwProtocol;
internal int cbPciLength;
public SCARD_IO_REQUEST()
{
dwProtocol = 0;
}
}
[DllImport("winscard.dll")]
public static extern uint SCardTransmit(IntPtr hCard, IntPtr pioSendRequest, byte[] SendBuff, int SendBuffLen, SCARD_IO_REQUEST pioRecvRequest,
byte[] RecvBuff, ref int RecvBuffLen);
[DllImport("winscard.dll")]
public static extern uint SCardControl(IntPtr hCard, int controlCode, byte[] inBuffer, int inBufferLen, byte[] outBuffer, int outBufferLen, ref int bytesReturned);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SCARD_READERSTATE
{
internal string szReader;
internal IntPtr pvUserData;
internal UInt32 dwCurrentState;
internal UInt32 dwEventState;
internal UInt32 cbAtr;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 36)]
internal byte[] rgbAtr;
}
[DllImport("winscard.dll", EntryPoint = "SCardGetStatusChangeW", CharSet = CharSet.Unicode)]
public static extern uint SCardGetStatusChange(IntPtr hContext, int dwTimeout, [In, Out] SCARD_READERSTATE[] rgReaderStates, int cReaders);
[DllImport("winscard.dll")]
public static extern int SCardStatus(IntPtr hCard, string szReader, ref int cch, ref int state, ref int protocol, ref byte[] bAttr, ref int cByte);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll")]
public static extern void FreeLibrary(IntPtr handle);
[DllImport("kernel32.dll")]
public static extern IntPtr GetProcAddress(IntPtr handle, string procName);
}
}