SCardTransmit in VB6

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 sample code written in VB6. I have a very tight dead line here without much documentation on hand.
I have the following code:-

Public Function updateSCard(ByVal lAddress As Byte, ByVal xStr As String) As Strin
''Dim abyGetChallenge(0 To 8) As Byt
Dim abyGetChallenge(0 To 4) As Byt

Dim pioSendPci As SCARD_IO_REQUES
Dim abyRecvBuffer(0 To intByteMax) As Byt
Dim byteData(0 To 3) As Byt
Dim rv As Lon
Dim xHex As Strin
Dim xFilledStr As Strin

pioSendPci.dwProtocol = SCARD_PROTOCOL_T
pioSendPci.dbPciLength = Len(pioSendPci

xFilledStr = xStr & Chr(0) & Chr(0) & Chr(0) & Chr(0
byteData(0) = Asc(Mid(xFilledStr, 1, 1)
byteData(1) = Asc(Mid(xFilledStr, 2, 1)
byteData(2) = Asc(Mid(xFilledStr, 3, 1)
byteData(3) = Asc(Mid(xFilledStr, 4, 1)

abyGetChallenge(0) = &H8
abyGetChallenge(1) = &HD
abyGetChallenge(2) = &H
abyGetChallenge(3) = lAddres
abyGetChallenge(4) = byteData(0

rv = SCardTransmit(m_hCard, pioSendPci, abyGetChallenge(0),
UBound(abyGetChallenge) - LBound(abyGetChallenge) + 5,
pioSendPci, abyRecvBuffer(0),
UBound(abyRecvBuffer) - LBound(abyRecvBuffer) + 1

If rv <> SCARD_S_SUCCESS The
MsgBox r
Call MsgBox("updateSCard failed", vbCritical
updateSCard = "
Exit Functio
End I

If Not (&H90 = abyRecvBuffer(0) And &H0 = abyRecvBuffer(1)) The
Call MsgBox("updateSCard - update smart card failed..", vbCritical, "PCSC"
End I


End Function
 
Hi,

This isn't a VB6 newsgroup, so answers may be scarce.

That having been said, we (at least, I) don't have enough information.
Since I've never done anything with a smart card, I'd be guessing. Post the
protocol requirements, not just the code and declares. I have suspects, but
cannot convict. For example:
Dim abyGetChallenge(0 To 4) As Byte
<<

Is this really a five-byte datum?

This code:
xFilledStr = xStr & Chr(0) & Chr(0) & Chr(0) & Chr(0)
byteData(0) = Asc(Mid(xFilledStr, 1, 1))
byteData(1) = Asc(Mid(xFilledStr, 2, 1))
byteData(2) = Asc(Mid(xFilledStr, 3, 1))
byteData(3) = Asc(Mid(xFilledStr, 4, 1))
<<

Is overdone. It could be:

byteData(0) = 0
byteData(1) = 0
byteData(2) = 0
byteData(3) = 0

If you want to post more details about what you need to do, I'll try to help
more. That is, post the same information that the card manufacturer
provides you.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
Hi,
Thanks for your kind reply. I have to apologize for the insufficient info posted :
Anyway, I'm supposed to write a program to perform basic function like reading & writing to the smart card using WinAPI in VB6
So, as for now, I have managed to read the card successfully and left only the writing part.
As for the writing to the smart card, I was actually writing a function to accept a parameter to accept the Address of card to write and secondly the string to write to the card. As posted previously, the function was updateSCard()
Probrably u can just ignore the rest of the code inside because I can't really understand how this ScardTransmit function supposed to work anyway. I got this function from the smart card section but there isn't any good example for how an example of data can be written to a smart card. If u can help me by gettin a workable example in VB6 for this function will be just good enought for me to understand.



----- Dick Grier wrote: ----

Hi

This isn't a VB6 newsgroup, so answers may be scarce

That having been said, we (at least, I) don't have enough information
Since I've never done anything with a smart card, I'd be guessing. Post th
protocol requirements, not just the code and declares. I have suspects, bu
cannot convict. For example
Dim abyGetChallenge(0 To 4) As Byt
<

Is this really a five-byte datum

This code
xFilledStr = xStr & Chr(0) & Chr(0) & Chr(0) & Chr(0
byteData(0) = Asc(Mid(xFilledStr, 1, 1)
byteData(1) = Asc(Mid(xFilledStr, 2, 1)
byteData(2) = Asc(Mid(xFilledStr, 3, 1)
byteData(3) = Asc(Mid(xFilledStr, 4, 1)
<

Is overdone. It could be

byteData(0) =
byteData(1) =
byteData(2) =
byteData(3) =

If you want to post more details about what you need to do, I'll try to hel
more. That is, post the same information that the card manufacture
provides you

Dic

--
Richard Grier (Microsoft Visual Basic MVP

See www.hardandsoftware.net for contact information

Author of Visual Basic Programmer's Guide to Serial Communications, 3r
Edition ISBN 1-890422-27-4 (391 pages) published February 2002
 
hi Schwarz


Currently i am in smart card coding using vb. I have to read and write
data to Memory Card.

ScardEstablish,ScardConnect,ScardStatus return Scard_s_Success, i do
struct up at ScardTransmit Function

Will u guide me, so that i can refer some website or any sample, so that
i will be clear in reading datas from smart card. Any websites or sample
will be of more help to me

thank you in advance

rraji
 
Hi guys,

Am in need of that too..and urgently...

My requirement is reading a serial number a unique 16 digit code...

i am in a lone island and surrounded by water..kindly give me a boat..

A raft was provided by you guys...(the code which was posted for
transmitting data), but still i need some rows as well..lol..kindly help
guys..

Regards

A programmer species like you.
 
It seems to me that this is more a question than an answer,

However this is a VBNet newsgroup,

for VB classic the newsgroups are

microsoft.public.vb there are a bunch,

I hope you find your answer quick,

Cor
 
What exactly do you want ?
Whats the error that you are getting ?
What format is the apdu u are sending ?
Are you converting it to int before populating the command array ?

LG.
 
Back
Top