Click here to Skip to main content
15,885,980 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,
I m using SCardTransmit function but its returning error code -2146435068
code is:
CSS
typedef long (__stdcall *Transmit)(SCARDHANDLE ,LPCSCARD_IO_REQUEST,BYTE,DWORD ,LPSCARD_IO_REQUEST,BYTE,LPDWORD );

 BYTE sendCommand[]={0x00,0xA4,0x00,0x00,0x02,0x3F,0x00};
	 BYTE recvCommand[256];
	 long result,sendlen=sizeof(sendCommand);
	DWORD recvlen;
	 SCARD_IO_REQUEST pioSendPci;
	  
	 pioSendPci.dwProtocol=SCARD_PROTOCOL_T0;
	 pioSendPci.cbPciLength= sizeof(pioSendPci);

	 result= com(phCard,&pioSendPci,sendCommand[0],sendlen,NULL,recvCommand[0], &recvlen);
	 if(result!=SCARD_S_SUCCESS){
	 printf("command not  transmitted\n");
	 }

Here the com function is acting as SCardTransmit function.provide some link for these kind of errors because wherever i see errors are in form of Hexadecimal. Nobody provides error in this form.
Posted
Comments
Carlos Gama 28-Oct-14 10:55am    
The value 0xA4 isn't correct. you need calculate values upper to 7F (127) to negative,

like C0 => 192 + 0 = 192

so:
192 -128 = -64

then
C0 = -64

Convert -2146435068 into an unsigned value (e.g. unsigned int), this gives you 2148532228. Convert this to hexadecimal and you get: 0x80100004. After a little bit of googling for 80100004 and SCardTransmit it turns out this means: SCARD_E_INVALID_PARAMETER. So there you have it.
 
Share this answer
 
Thats work:

C++
HRESULT gsCard::pfApduSend(char * ARef, const char * AStr)
{
  // * Apdu Cmd to send
  char * lCmd = (char*)new char[255];
  // *  
  lCmd = gsApdu::gfApduCmd(strlen(AStr), AStr);
  // * get "00 C0 00 00 12" pass to (0)(-64)(0)(0)(18)  // * <------ pay attention
  // *
  // * Apdu Cmd Size
  unsigned long lLen = sizeof(lCmd) +1;                 // * <------ pay attention
  // *
  // * pointer to IO request
  SCARD_IO_REQUEST lPio;
  lPio.dwProtocol = 0;
  lPio.cbPciLength= sizeof(lPio);
  // *
  // * buffer & size to return by Api
  LPBYTE lBuf;                                          // * <------ pay attention
  unsigned long lSze = 255;
  // *
  // * Ask Apdu to Scard
  lRet = SCardTransmit(sCardHandle, &lPio, lCmd, lLen, NULL, (LPBYTE)&lBuf, &lSze);
   
  if (lRet == SCARD_S_SUCCESS) {
    gsChar::gfCharToAscHex(*ARef, (unsigned char*)(LPBYTE)&lBuf, lSze);
    // * get "o\x14‚\x01\x14ƒ\x02 \x10†\x04‡ÿÿ"        // * <------ pay attention
    // * pass to 
    // * "6F 14 82 01 14 83 02 20 10 86 04 87 FF FF 00 85 01 00 61 04"  
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900