我的项目结构
myApp
-->WCFSerLibrary
-->ClassLib1
-->ClassLib2 // This one uses winscard.dll 我想和一个附加智能卡的收割机沟通。
我遵循的四个步骤是
前三个步骤成功地执行,但是当我尝试执行SCardTransmit时,它会返回87的响应代码。
第二方面,上面提到的场景是当我从WCF服务调用它时。现在,我在Windows应用程序中使用相同的ClassLib2,它正确地进行通信。
retCode = ModWinsCard.SCardTransmit(hCard, ref pioSendRequest, ref SendBuff[0], sendLen, ref pioSendRequest, ref RecvBuff[0], ref recvLen);像在ModWinsCard类中一样
[DllImport("winscard.dll"l)]
public static extern Int64 SCardTransmit(UInt64 hCard, ref SCARD_IO_REQUEST pioSendRequest, ref byte SendBuff, int SendBuffLen, ref SCARD_IO_REQUEST pioRecvRequest, ref byte RecvBuff, ref int RecvBuffLen);发布于 2012-10-31 06:35:30
87是无效参数。该方法返回一个不太长的int。此外,您只传入输入和输出缓冲区中的第一项。卡句柄应使用IntPtr。
LONG WINAPI SCardTransmit(
_In_ SCARDHANDLE hCard,
_In_ LPCSCARD_IO_REQUEST pioSendPci,
_In_ LPCBYTE pbSendBuffer,
_In_ DWORD cbSendLength,
_Inout_opt_ LPSCARD_IO_REQUEST pioRecvPci,
_Out_ LPBYTE pbRecvBuffer,
_Inout_ LPDWORD pcbRecvLength
);可以试试下面的pinvoke签名吗?
[DllImport("winscard.dll"l)]
public static extern int SCardTransmit(
IntPtr hCard,
ref SCARD_IO_REQUEST pioSendRequest,
byte[] SendBuff,
int SendBuffLen,
ref SCARD_IO_REQUEST pioRecvRequest,
IntPtr RecvBuff, // Copy with marshal.copy to a managed array after call.
ref int RecvBuffLen);https://stackoverflow.com/questions/13152226
复制相似问题