Hi,
For what I know, if SCardConnect returns SCARD_S_SUCCESS there is a Card
inserted so:
DWORD rv = SCardEstablishContext( SCARD_SCOPE_SYSTEM, 0, 0, &hContext );
if (rv == SCARD_S_SUCCESS){
printf("Card detected");
}
--
Marc Rios Vallès
[email protected]
C3PO, S.A.
http://www.c3po.es
C/ Alejandro Goicoechea, 6 Local 9 - 08960 St. Just Desvern, Barcelona
Tel. 93 417 99 55 - Fax 93 253 12 80
On Tuesday 13 April 2010 09:51:04 pm Anderson Goulart wrote:
> Hello all,
>
> I am trying to use pcsclite API just to check if the card is inserted on the
> reader or not, based on the API reference and some example codes at muscle
> site:
>
> #include <stdio.h>
> #include <PCSC/pcsclite.h>
> #include <stdlib.h>
>
> int main() {
>
> SCARDCONTEXT hContext;
> SCARDHANDLE hCard;
> char *lpcReaders;
> DWORD dwReaders;
> DWORD dwActive, dwState, dwRlen;
> DWORD dwProtocol, dwAtrLen;
> BYTE Atr[MAX_ATR_SIZE];
>
> SCardEstablishContext( SCARD_SCOPE_SYSTEM, 0, 0,
> &hContext );
>
> dwReaders = 0;
> lpcReaders = 0;
>
> SCardListReaders( hContext, 0, NULL, &dwReaders );
> lpcReaders = (char *)malloc(sizeof(char)*dwReaders);
> SCardListReaders( hContext, 0, lpcReaders, &dwReaders );
>
> SCardConnect( hContext, lpcReaders, SCARD_SHARE_EXCLUSIVE,
> SCARD_PROTOCOL_T0,
> &hCard, &dwActive );
>
> dwState = 0;
>
> // here lpcReaders prints the value "OmniKey CardMan 3121 00 00"
> // This 00 00 should be there? I think the problem is here...
>
> SCardStatus( hCard, lpcReaders, &dwReaders, &dwState, &dwProtocol,
> Atr, &dwAtrLen );
>
> SCardDisconnect( hCard, SCARD_UNPOWER_CARD );
> SCardReleaseContext( hContext );
>
> if ( dwState & SCARD_PRESENT ) {
> return 1;
> }
>
> return 0;
> }
>
> This code compiles and execute without an error... but it does not detect
> the presence of the smartcard. Any ideas?
>
>
> thanks, global
>
_______________________________________________
Muscle mailing list
[email protected]
http://lists.drizzle.com/mailman/listinfo/muscle