Smart Card Reader 
Author Message
 Smart Card Reader

Hi All,

I am having a few problems trying to get a SmartCard reader to work. I've
pasted my code in below. Can someone please help?

<<<<START CODE>>>>

Option Explicit On
Public Class Form1
Inherits System.Windows.Forms.Form
Dim ReaderPort As Integer
Dim ResponsePort As Integer
Dim T0Instruction As T0InsStruct
Dim T0Error As T0ErrorStruct
Dim APDUCommand As ADPUStruct
Dim InputString As String
Dim OutputString As String
Dim dummy As Integer
' Error structure
'=======================
Structure T0ErrorStruct
Dim SW12 As Integer
Dim Err As Integer
End Structure
' ISO7816 ADPU Part4 command
'======================
Structure ADPUStruct
Dim ADPUClass As Integer
Dim Instruction As Integer
Dim param1 As Integer
Dim param2 As Integer
Dim lc As Integer
Dim le As Integer
End Structure

' ISO7816 T=0 read or write
'==========================
Structure T0InsStruct
Dim ADPUClass As Integer
Dim Instruction As Integer
Dim P1 As Integer
Dim P2 As Integer
Dim P3 As Integer
End Structure

'NEW DLL VERSION
' for SM1
'===========================================================================
=========

com_port As Integer) As Integer

com_port As Integer) As Integer

(ByVal Version As String) As Integer
Declare Function GisSMReaderStatus Lib "GISSM12N.dll" Alias

Declare Function GisSM7816Reset Lib "GISSM12N.dll" Alias

count As Integer) As Integer
Declare Function GisSMCardDisable Lib "GISSM12N.dll" Alias

Declare Function GisSMT0WriteCmd Lib "GISSM12N.dll" Alias

T0InsStruct, ByVal BUFFER As String, ByVal T0Error As T0ErrorStruct) As
Integer
Declare Function GisSMT0ReadCmd Lib "GISSM12N.dll" Alias

T0InsStruct, ByVal BUFFER As String, ByVal T0Error As T0ErrorStruct) As
Integer

(ByVal port As Integer, ByVal adpu As ADPUStruct, ByVal BuffOut As String,
ByVal BuffIn As String, ByVal Part4Error As T0ErrorStruct) As Integer
#Region " Windows Form Designer generated code "
.
.
.

Private Sub OpenReader_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles OpenReader.Click
ReaderPort = 2
ResponsePort = GisSMOpen(ReaderPort)
Response.Text = CStr(ResponsePort)
APDUCommand.ADPUClass = &H80
APDUCommand.Instruction = &HCA
APDUCommand.param1 = &H9F
APDUCommand.param2 = &H58
APDUCommand.lc = &H0
APDUCommand.le = &H4
GisSMPart4Cmd(ResponsePort, APDUCommand, OutputString, InputString, T0Error)
<----- IT FAILS HERE!!
ResponseString.Text = OutputString
End Sub
End Class

<<<<END OF CODE>>>>

The above program is failing, telling me that I have a
System.NullreferenceException. Additional Information: Object reference not
set to an instance of an object.

When I display GisSMOpen and GisSMPart4Cmd in the watch window, I get
messages telling me that (for the GisCMPart4Cmd):

Argument not specified for parameter 'Port' of 'Private Shared function
GisSMPart4Cmd(port as integer, myProg.APDUCommand, ...)'

I don't understand this, as I am passing an integer into the original
GisSMOpen function, in an attempt to open the Smart Card Reader on COM port
2. It is returning a value of 0xFFFF, which I am sure cannot be correct. In
the watch window, I get a message similar to the one for GisSMPart4Cmd,
basically telling me that I have not specified an argument for parameter
'com_port'.

Can anyone please tell me where I am going wrong here? The DLL is definitely
in the right place, as before I put it there, I just had errors telling me
that a DLL entry point could not be found.

Thanks

--
JW
See my photography exploits at: http://www.*-*-*.com/
To email me, simply remove NO--SPAM from my reported email address!



Fri, 04 Nov 2005 03:09:20 GMT  
 Smart Card Reader

Hi,

        I have gotten with the same error message with other api calls when using byval when byref should be used.  Try this.  The code is untested.

Quote:

> (ByVal port As Integer, ByVal adpu As ADPUStruct, ByRef BuffOut As String,
> ByVal BuffIn As String, ByRef Part4Error As T0ErrorStruct) As Integer

Ken
--------------
Quote:

> Hi All,

> I am having a few problems trying to get a SmartCard reader to work. I've
> pasted my code in below. Can someone please help?

> <<<<START CODE>>>>

> Option Explicit On
> Public Class Form1
> Inherits System.Windows.Forms.Form
> Dim ReaderPort As Integer
> Dim ResponsePort As Integer
> Dim T0Instruction As T0InsStruct
> Dim T0Error As T0ErrorStruct
> Dim APDUCommand As ADPUStruct
> Dim InputString As String
> Dim OutputString As String
> Dim dummy As Integer
> ' Error structure
> '=======================
> Structure T0ErrorStruct
> Dim SW12 As Integer
> Dim Err As Integer
> End Structure
> ' ISO7816 ADPU Part4 command
> '======================
> Structure ADPUStruct
> Dim ADPUClass As Integer
> Dim Instruction As Integer
> Dim param1 As Integer
> Dim param2 As Integer
> Dim lc As Integer
> Dim le As Integer
> End Structure

> ' ISO7816 T=0 read or write
> '==========================
> Structure T0InsStruct
> Dim ADPUClass As Integer
> Dim Instruction As Integer
> Dim P1 As Integer
> Dim P2 As Integer
> Dim P3 As Integer
> End Structure

> 'NEW DLL VERSION
> ' for SM1
> '===========================================================================
> =========

> com_port As Integer) As Integer

> com_port As Integer) As Integer

> (ByVal Version As String) As Integer
> Declare Function GisSMReaderStatus Lib "GISSM12N.dll" Alias

> Declare Function GisSM7816Reset Lib "GISSM12N.dll" Alias

> count As Integer) As Integer
> Declare Function GisSMCardDisable Lib "GISSM12N.dll" Alias

> Declare Function GisSMT0WriteCmd Lib "GISSM12N.dll" Alias

> T0InsStruct, ByVal BUFFER As String, ByVal T0Error As T0ErrorStruct) As
> Integer
> Declare Function GisSMT0ReadCmd Lib "GISSM12N.dll" Alias

> T0InsStruct, ByVal BUFFER As String, ByVal T0Error As T0ErrorStruct) As
> Integer

> (ByVal port As Integer, ByVal adpu As ADPUStruct, ByVal BuffOut As String,
> ByVal BuffIn As String, ByVal Part4Error As T0ErrorStruct) As Integer
> #Region " Windows Form Designer generated code "
> .
> .
> .

> Private Sub OpenReader_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles OpenReader.Click
> ReaderPort = 2
> ResponsePort = GisSMOpen(ReaderPort)
> Response.Text = CStr(ResponsePort)
> APDUCommand.ADPUClass = &H80
> APDUCommand.Instruction = &HCA
> APDUCommand.param1 = &H9F
> APDUCommand.param2 = &H58
> APDUCommand.lc = &H0
> APDUCommand.le = &H4
> GisSMPart4Cmd(ResponsePort, APDUCommand, OutputString, InputString, T0Error)
> <----- IT FAILS HERE!!
> ResponseString.Text = OutputString
> End Sub
> End Class

> <<<<END OF CODE>>>>

> The above program is failing, telling me that I have a
> System.NullreferenceException. Additional Information: Object reference not
> set to an instance of an object.

> When I display GisSMOpen and GisSMPart4Cmd in the watch window, I get
> messages telling me that (for the GisCMPart4Cmd):

> Argument not specified for parameter 'Port' of 'Private Shared function
> GisSMPart4Cmd(port as integer, myProg.APDUCommand, ...)'

> I don't understand this, as I am passing an integer into the original
> GisSMOpen function, in an attempt to open the Smart Card Reader on COM port
> 2. It is returning a value of 0xFFFF, which I am sure cannot be correct. In
> the watch window, I get a message similar to the one for GisSMPart4Cmd,
> basically telling me that I have not specified an argument for parameter
> 'com_port'.

> Can anyone please tell me where I am going wrong here? The DLL is definitely
> in the right place, as before I put it there, I just had errors telling me
> that a DLL entry point could not be found.

> Thanks

> --
> JW
> See my photography exploits at: http://www.essexchurches.co.uk
> To email me, simply remove NO--SPAM from my reported email address!



Fri, 04 Nov 2005 09:27:39 GMT  
 Smart Card Reader

Thanks Ken. I tried what you suggested, but still no joy!

JW

  Hi,

          I have gotten with the same error message with other api calls when using byval when byref should be used.  Try this.  The code is untested.


  > (ByVal port As Integer, ByVal adpu As ADPUStruct, ByRef BuffOut As String,
  > ByVal BuffIn As String, ByRef Part4Error As T0ErrorStruct) As Integer

  Ken
  --------------

  > Hi All,
  >
  > I am having a few problems trying to get a SmartCard reader to work. I've
  > pasted my code in below. Can someone please help?
  >
  > <<<<START CODE>>>>
  >
  > Option Explicit On
  > Public Class Form1
  > Inherits System.Windows.Forms.Form
  > Dim ReaderPort As Integer
  > Dim ResponsePort As Integer
  > Dim T0Instruction As T0InsStruct
  > Dim T0Error As T0ErrorStruct
  > Dim APDUCommand As ADPUStruct
  > Dim InputString As String
  > Dim OutputString As String
  > Dim dummy As Integer
  > ' Error structure
  > '=======================
  > Structure T0ErrorStruct
  > Dim SW12 As Integer
  > Dim Err As Integer
  > End Structure
  > ' ISO7816 ADPU Part4 command
  > '======================
  > Structure ADPUStruct
  > Dim ADPUClass As Integer
  > Dim Instruction As Integer
  > Dim param1 As Integer
  > Dim param2 As Integer
  > Dim lc As Integer
  > Dim le As Integer
  > End Structure
  >
  > ' ISO7816 T=0 read or write
  > '==========================
  > Structure T0InsStruct
  > Dim ADPUClass As Integer
  > Dim Instruction As Integer
  > Dim P1 As Integer
  > Dim P2 As Integer
  > Dim P3 As Integer
  > End Structure
  >
  > 'NEW DLL VERSION
  > ' for SM1
  > '===========================================================================
  > =========

  > com_port As Integer) As Integer

  > com_port As Integer) As Integer

  > (ByVal Version As String) As Integer
  > Declare Function GisSMReaderStatus Lib "GISSM12N.dll" Alias

  > Declare Function GisSM7816Reset Lib "GISSM12N.dll" Alias

  > count As Integer) As Integer
  > Declare Function GisSMCardDisable Lib "GISSM12N.dll" Alias

  > Declare Function GisSMT0WriteCmd Lib "GISSM12N.dll" Alias

  > T0InsStruct, ByVal BUFFER As String, ByVal T0Error As T0ErrorStruct) As
  > Integer
  > Declare Function GisSMT0ReadCmd Lib "GISSM12N.dll" Alias

  > T0InsStruct, ByVal BUFFER As String, ByVal T0Error As T0ErrorStruct) As
  > Integer

  > (ByVal port As Integer, ByVal adpu As ADPUStruct, ByVal BuffOut As String,
  > ByVal BuffIn As String, ByVal Part4Error As T0ErrorStruct) As Integer
  > #Region " Windows Form Designer generated code "
  > .
  > .
  > .
  >
  > Private Sub OpenReader_Click(ByVal sender As System.Object, ByVal e As
  > System.EventArgs) Handles OpenReader.Click
  > ReaderPort = 2
  > ResponsePort = GisSMOpen(ReaderPort)
  > Response.Text = CStr(ResponsePort)
  > APDUCommand.ADPUClass = &H80
  > APDUCommand.Instruction = &HCA
  > APDUCommand.param1 = &H9F
  > APDUCommand.param2 = &H58
  > APDUCommand.lc = &H0
  > APDUCommand.le = &H4
  > GisSMPart4Cmd(ResponsePort, APDUCommand, OutputString, InputString, T0Error)
  > <----- IT FAILS HERE!!
  > ResponseString.Text = OutputString
  > End Sub
  > End Class
  >
  > <<<<END OF CODE>>>>
  >
  > The above program is failing, telling me that I have a
  > System.NullreferenceException. Additional Information: Object reference not
  > set to an instance of an object.
  >
  > When I display GisSMOpen and GisSMPart4Cmd in the watch window, I get
  > messages telling me that (for the GisCMPart4Cmd):
  >
  > Argument not specified for parameter 'Port' of 'Private Shared function
  > GisSMPart4Cmd(port as integer, myProg.APDUCommand, ...)'
  >
  > I don't understand this, as I am passing an integer into the original
  > GisSMOpen function, in an attempt to open the Smart Card Reader on COM port
  > 2. It is returning a value of 0xFFFF, which I am sure cannot be correct. In
  > the watch window, I get a message similar to the one for GisSMPart4Cmd,
  > basically telling me that I have not specified an argument for parameter
  > 'com_port'.
  >
  > Can anyone please tell me where I am going wrong here? The DLL is definitely
  > in the right place, as before I put it there, I just had errors telling me
  > that a DLL entry point could not be found.
  >
  > Thanks
  >
  > --
  > JW
  > See my photography exploits at: http://www.essexchurches.co.uk
  > To email me, simply remove NO--SPAM from my reported email address!
  >
  >



Sat, 05 Nov 2005 02:53:59 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. smart card reader

2. Is thers a smart card reader ActiveX control?

3. Interfacing with a smart card in VB ??

4. Smart Cards

5. Smart card

6. Smart Cards

7. Smart and CHIP Cards

8. Smart Cards

9. Smart Cards

10. Smart card or id logon authentication.

11. pocket pc + smart cards

12. want control card reader

 

 
Powered by phpBB® Forum Software