Logo Search packages:      
Sourcecode: pcsc-lite version File versions  Download package

LONG SCardListReaders ( SCARDCONTEXT  hContext,
LPCTSTR  mszGroups,
LPTSTR  mszReaders,
LPDWORD  pcchReaders 
)

This function returns a list of currently available readers on the system. mszReaders is a pointer to a character string that is allocated by the application. If the application sends mszGroups and mszReaders as NULL then this function will return the size of the buffer needed to allocate in pcchReaders.

Parameters:
[in] hContext Connection context to the PC/SC Resource Manager.
[in] mszGroups List of groups to list readers (not used).
[out] mszReaders Multi-string with list of readers.
pcchReaders [inout] Size of multi-string buffer including NULL's.
Returns:
Connection status.
Return values:
SCARD_S_SUCCESS Successful.
SCARD_E_INVALID_HANDLE Invalid Scope Handle.
SCARD_E_INSUFFICIENT_BUFFER Reader buffer not large enough.
Test:
 SCARDCONTEXT hContext;
 LPTSTR mszReaders;
 DWORD dwReaders;
 LONG rv;
 ...
 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 rv = SCardListReaders(hContext, NULL, NULL, &dwReaders);
 mszReaders = (LPTSTR)malloc(sizeof(char)*dwReaders);
 rv = SCardListReaders(hContext, NULL, mszReaders, &dwReaders); 

Definition at line 2587 of file winscard_clnt.c.

References psContextMap, SCardCheckDaemonAvailability(), SCardGetContextIndice(), SYS_MutexLock(), and SYS_MutexUnLock().

{
      DWORD dwReadersLen;
      int i, lastChrPtr;
      DWORD dwContextIndex;

      /*
       * Check for NULL parameters
       */
      if (pcchReaders == NULL)
            return SCARD_E_INVALID_PARAMETER;

      if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
            return SCARD_E_NO_SERVICE;

      /*
       * Make sure this context has been opened
       */
      dwContextIndex = SCardGetContextIndice(hContext);
      if (dwContextIndex == -1)
            return SCARD_E_INVALID_HANDLE;

      SYS_MutexLock(psContextMap[dwContextIndex].mMutex);   

      dwReadersLen = 0;
      for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
            if ((readerStates[i])->readerID != 0)
                  dwReadersLen += strlen((readerStates[i])->readerName) + 1;

      /* for the last NULL byte */
      dwReadersLen += 1;

      if ((mszReaders == NULL)      /* text array not allocated */
            || (*pcchReaders == 0)) /* size == 0 */
      {
            *pcchReaders = dwReadersLen;
            SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex); 
            return SCARD_S_SUCCESS;
      }
      
      if (*pcchReaders < dwReadersLen)
      {
            *pcchReaders = dwReadersLen;
            SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex); 
            return SCARD_E_INSUFFICIENT_BUFFER;
      }

      lastChrPtr = 0;
      for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
      {
            if ((readerStates[i])->readerID != 0)
            {
                  /*
                   * Build the multi-string
                   */
                  strcpy(&mszReaders[lastChrPtr], (readerStates[i])->readerName);
                  lastChrPtr += strlen((readerStates[i])->readerName)+1;
            }
      }
      mszReaders[lastChrPtr] = '\0';      /* Add the last null */

      *pcchReaders = dwReadersLen;

      SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex); 
      return SCARD_S_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index