问题描述
请教在win764位上运行此程序SCardTransmit返回-2146435068在32位操作系统上就正常,是什么原因?publicbyte[]sendAPDU(stringsendMessage,byte[]SW12){if(sendMessage.Length%2!=0){sendMessage=sendMessage+"0";}byte[]sendMessageBuffer=StringToByteSequence(sendMessage);byte[]receiveMessageByte=newbyte[256];intreceiveLength=256;runResult=PCSCDLL.SCardTransmit(hCard,SCARD_PCI_T1,sendMessageBuffer,sendMessageBuffer.Length,null,receiveMessageByte,refreceiveLength);if(runResult!=SCARD_SUCCESS){errMsg="获取读卡器列表,错误代码为:"+runResult.ToString("X");Log.WriteLog(errMsg);thrownewException(errMsg);}byte[]retMessage=newbyte[receiveLength-2];for(inti=0;i<receiveLength-2;i++){retMessage[i]=receiveMessageByte[i];}SW12[0]=receiveMessageByte[receiveLength-2];SW12[1]=receiveMessageByte[receiveLength-1];returnretMessage;}///////////////////////////////////////////////////////////////////////////////////////////////publicclassSCARD_IO_REQUEST{publicintdwProtocol;publicintcbPciLength;}//////////////////////////////////////////////////////////////////////////////////////////////////<summary>///向卡片发送数据///</summary>///<paramname="hCard">卡片句柄</param>///<paramname="pioSendPci">指令的协议头结构的指针</param>///<paramname="pbSendBuffer">写卡数据</param>///<paramname="cbSendLength">写卡数据长度</param>///<paramname="pioRecvPci"></param>///<paramname="pbRecvBuffer">返回数据</param>///<paramname="pcbRecvLength"></param>///<returns></returns>[DllImport("WinSCard.dll")]publicstaticexternintSCardTransmit(inthCard,IntPtrpioSendPci,byte[]pbSendBuffer,intcbSendLength,SCARD_IO_REQUESTpioRecvPci,byte[]pbRecvBuffer,refintpcbRecvLength);
解决方案
解决方案二:
检验一下参数中是否有些数据类型的位数64位跟32位不同
解决方案三:
原型LONGWINAPISCardTransmit(_In_SCARDHANDLEhCard,_In_LPCSCARD_IO_REQUESTpioSendPci,_In_LPCBYTEpbSendBuffer,_In_DWORDcbSendLength,_Inout_opt_LPSCARD_IO_REQUESTpioRecvPci,_Out_LPBYTEpbRecvBuffer,_Inout_LPDWORDpcbRecvLength);代码中是这样
解决方案四:
'操作读卡器大多是要调用提供的DLL动态库的,但DLL是区分32和64位的,而为了省事厂家都只会提供32位版本,所以楼主明白了吗