I am trying to connect and send command to smart Card through Windows smart Card api , below is the code i have from MSDN. Here the SCardTransmit function always Returns me 0x000005aa , can some one let me know what i am doing wrong.
int _tmain(int argc, _TCHAR* argv[])
{
SCARDCONTEXT hContext;
LONG lReturn;
SCARDHANDLE hCardHandle;
DWORD dwAP;
const DWORD BUF_LEN = 512;
DWORD dwRecv;
BYTE pbRecv[BUF_LEN];
BYTE sendCommand[]={0x00,0x0A4,0x00,0x00,0x02,0x3F,0x00};
lReturn = SCardEstablishContext(SCARD_SCOPE_USER, NULL,NULL,&hContext);
if ( SCARD_S_SUCCESS != lReturn )
{
printf("Failed SCardEstablishContext\n");
SCardReleaseContext(hContext);
return 0;
}
lReturn = SCardConnect( hContext, "OMNIKEY CardMan 3x21 0",
SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
&hCardHandle, &dwAP );
if ( SCARD_S_SUCCESS != lReturn )
{
printf("Failed SCardConnect\n");
SCardReleaseContext(hContext);
return 0;
}
switch ( dwAP )
{
case SCARD_PROTOCOL_T0:
printf("Active protocol T0\n");
break;
case SCARD_PROTOCOL_T1:
printf("Active protocol T1\n");
break;
case SCARD_PROTOCOL_UNDEFINED:
default:
printf("Active protocol unnegotiated or unknown\n");
break;
}
lReturn = SCardTransmit(hCardHandle,SCARD_PCI_T0,sendCommand,7,
NULL,pbRecv,&dwRecv );
if ( SCARD_S_SUCCESS != lReturn )
{
printf("Failed SCardTransmit\n");
}
lReturn = SCardReleaseContext(hContext);
return 0;
}
As suggested in comments by Retired Ninja. the variable dwRecv needs to initialize, after initializing the variable the program works. thanks.
User contributions licensed under CC BY-SA 3.0