[DllImport("winscard.dll", EntryPoint="SCardListReadersA", CharSet=CharSet.Ansi)]
static extern int SCardListReaders(int hContext, IntPtr mszGroups, out IntPtr mszReaders, ref int pcchReaders);
None.
None.
if you invoke SCardListReaders with the hContext parameter set to null, you'll get the list of the installed readers (not the plugged ones !)
long ret = 0;
int hContext;
Int32 pcchReaders = 0;
int nullindex = -1;
char nullchar = (char) 0;
ArrayList readersList = new ArrayList();
//establish context
ret = SCardEstablishContext(SCARD_SCOPE_USER,IntPtr.Zero,IntPtr.Zero,out hContext);
//get readers buffer len
ret = SCardListReaders(hContext,IntPtr.Zero,null,ref pcchReaders);
byte[] mszReaders = new byte[pcchReaders];
// fill readers' buffer
ret = SCardListReaders(hContext,IntPtr.Zero ,mszReaders, ref pcchReaders);
//fill readersList
//remember that readers is a multistring with a double trailing \0
ASCIIEncoding ascii = new ASCIIEncoding();
string currbuff = ascii.GetString(mszReaders);
int len = pcchReaders;
while (currbuff[0]!=nullchar)
{
nullindex = currbuff.IndexOf(nullchar); //get null end character
string reader = currbuff.Substring(0, nullindex);
readersList.Add(reader);
len = len-(reader.Length+1);
currbuff = currbuff.Substring(nullindex+1,len);
}
ret = SCardReleaseContext(hContext);
TODO