473,378 Members | 1,351 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

WinScard.dll, ScardTransmit

Hi All
i am using Asp.net2.0, C#, VS2005
and i am using winscrsd.dll, ScardTransmit. i have this error no. =
2148532228 in return, so please i need your help.

thank you in advance.
this is the code i wrote:
int pContextHandle;
int pCardHandle;
UInt32 byActiveprotocol;
byte[] pbyReaderNames = new byte[1000];
string szReaderName;
uint len = 1000;
//
[DllImport("WINSCARD.DLL")]
static extern int SCardBeginTransaction(int hCard);
//
[DllImport("Winscard.dll")]//
private extern static int SCardEstablishContext(
uint scope,
IntPtr reserved1,
IntPtr reserved2,
out int handle);
//
[DllImport("WINSCARD.dll", EntryPoint = "SCardListReadersA", CharSet =
CharSet.Ansi)]
public static extern int SCardListReaders(
int hContext,
byte[] mszGroups,
byte[] mszReaders,
ref UInt32 pcchReaders);
//
[DllImport("winscard.dll")]
static extern uint SCardTransmit(
int hCard,
ref SCARD_IO_REQUEST pioSendPci,
byte[] pbSendBuffer,
int cbSendLength,
IntPtr pioRecvPci,
byte[] pbRecvBuffer,
ref int pcbRecvLength);
//
[DllImport("winscard.dll", EntryPoint = "SCardConnect", CharSet =
CharSet.Auto)]
static extern int SCardConnect(
int hContext,
[MarshalAs(UnmanagedType.LPTStr)] string szReader,
UInt32 dwShareMode,
UInt32 dwPreferredProtocols,
out int phCard,
out UInt32 pdwActiveProtocol);
[DllImport("Winscard.dll")]
private extern static int SCardDisconnect(UIntPtr cardHandle, int
disposition);

// Private/Internal Types
[StructLayout(LayoutKind.Sequential)]
internal class SCARD_IO_REQUEST
{
internal uint dwProtocol;
internal int cbPciLength;
public SCARD_IO_REQUEST()
{
dwProtocol = 0;
}
}
[DllImport("kernel32.dll")]
private extern static IntPtr LoadLibrary(string fileName);
[DllImport("kernel32.dll")]
private extern static void FreeLibrary(IntPtr handle);
[DllImport("kernel32.dll")]
private extern static IntPtr GetProcAddress(IntPtr handle, string
procName);
private static IntPtr GetPciT0()
{
IntPtr handle = LoadLibrary("Winscard.dll");
IntPtr pci = GetProcAddress(handle, "g_rgSCardT0Pci");
FreeLibrary(handle);
return pci;
}
private byte[] GetSendBuffer()
{
string cla = "A0";
string ins = "A4";
string p1 = "00";
string p2 = "00";
string lc = "02";
string body = "3F00";
string script = String.Format("{0}{1}{2}{3}{4}{5}", cla, ins, p1, p2,
lc, body);
byte[] buffer = new byte[script.Length / 2];
for (int i = 0; i < script.Length; i = i + 2)
{
string temp = script.Substring(i, 2);
buffer[i / 2] = byte.Parse(temp,
System.Globalization.NumberStyles.HexNumber);
}
return buffer;
}
public void Transmit()
{
try
{
/*
* for me to use the transmit method as far as i know i need to do this
* 1 - SCardEstablishContext
* 2 - SCardListReaders
* 3 - SCardConnect
* 4 - SCardBeginTransaction
* 5 - SCardTransmit
* 6 - SCardEndTransaction
* 7 - SCardDisconnect
*/
long ret = 0;
ret = SCardEstablishContext(2, IntPtr.Zero, IntPtr.Zero, out
pContextHandle);
ret = SCardListReaders(pContextHandle, null, pbyReaderNames, ref len);
szReaderName = Encoding.ASCII.GetString(pbyReaderNames);
ret = SCardConnect(pContextHandle, szReaderName, 2, (0x00000001 |
0x00000002), out pCardHandle, out byActiveprotocol);
ret = SCardBeginTransaction(pCardHandle);
//
SCARD_IO_REQUEST ioRecv = new SCARD_IO_REQUEST();
byte[] pbRecvBuffer = new byte[255];
int pcbRecvLength = 255;
byte[] pbsendBuffer = this.GetSendBuffer();
int pbsendBufLen = pbsendBuffer.Length;
ioRecv.cbPciLength = ioRecv.ToString().Length;
IntPtr SCARD_PCI_T0 = GetPciT0();
uint uintret = SCardTransmit(pCardHandle, ref ioRecv, pbsendBuffer,
pbsendBufLen, SCARD_PCI_T0, pbRecvBuffer, ref pcbRecvLength);

Aug 7 '06 #1
0 7467

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ray | last post by:
I am having a problem with issuing commands to my smartcard, I converted the call to SCardTransmit as follows: public static extern uint SCardTransmit( uint hCard, byte pioSendPci, ...
3
by: Aaron | last post by:
SCardTransmit(.....) is an API, you can find it from MSDN, from "Winscard.dll" that used to send commands, in bytes, to smart card and get response, also in bytes, from that smart card, and the...
0
by: Chua Wen Ching | last post by:
Hi there, I had 2 questions. In SCardConnect function in Winscard.h: extern WINSCARDAPI LONG WINAPI SCardConnectA( IN SCARDCONTEXT hContext, IN LPCSTR szReader,
8
by: Schwarz | last post by:
Hi guyz I'm stuck up in this smart card SCardTransmit function. I still don't get how this function works . I'm currently trying to write some data to the smart card. Can anyone help me with some...
0
by: Ramazzotti... | last post by:
Hi All i am using Asp.net2.0, C#, VS2005 and i am using winscrsd.dll, ScardTransmit. i have this error no. = 2148532228 in return, so please i need your help. thank you in advance. this is the...
0
by: DavidL | last post by:
Error Code meaning in Winscard.dll functions? I am using the SCardTransmit function from winscard and getting errors back like: 0x00000006 0x0000054f 0x0000045d I can not find the...
0
by: nieve | last post by:
Hello all, I'm working on a c# application using smart cards. I've been using vs2008 on an XP machine and everything was ok till I tried installing and running a demo on a vista machine. What...
2
by: John Whitworth | last post by:
Hi, I'm rewriting an old VB6 app of mine in VB2008. All has been going well with calls to winscard.dll, until I needed to send an array of bytes as part of a structure. When using a winscard...
2
by: concoction | last post by:
What parameters i need to pass to send user data into the smart card using SCardTransmit function. what other functions are required to achieve writing user data?
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.