c++ - SCardTransmit returns error 0x000005aa -
i trying connect , send command smart card through windows smart card api , below code have msdn. here scardtransmit function returns me 0x000005aa , can 1 let me know 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 retired ninja. variable dwrecv needs initialize, after initializing variable program works. thanks.
Comments
Post a Comment