000
24.05.2008, 23:31 Uhr
citkid
|
Hallo,
bin noch Anfänger in VB.NET aber durchaus erfahren in Visual Basic. In Visual Basic funktioniert diese Methode: ------------------------------------------------------------- Declare Function SCardComand Lib "SCARD32.DLL" _ (Handle As Long, ByVal Cmd As String, CmdLen As Long, ByVal DataIn As String, _ DataInLen As Long, ByVal DataOut As String, DataOutLen As Long) As Long
Private sSCardDataOut As String Private lSCardDataOutLen As Long
Type CardInfo Error As Long CardDaten As String CardPinDaten As String Status As String LockedBy As String Typ As String Protocol As String CardCount As Long CardPower As Boolean MemSize As Long PinSize As Integer PinCnt As Integer AtrBinary As String AtrBinarySize As Integer End Type Public tCardInfo As CardInfo
Private Function ChipCardComand(Cmd$, DataIn$, MaxIn As Long) Dim CmdLen As Long Dim DataInLen As Long
Cmd$ = Cmd$ + Chr$(0) CmdLen = 0 'bei unverschlüsselter Übertragung muß CmdLen = 0 sein DataInLen = Len(DataIn$) DataIn$ = DataIn$ + Chr$(0) lSCardDataOutLen = MaxIn sSCardDataOut = String$(lSCardDataOutLen + 1, 0) On Error GoTo noChipDriveTreiber tCardInfo.Error = SCardComand(0, Cmd$, CmdLen, DataIn$, DataInLen, sSCardDataOut$, lSCardDataOutLen) On Error GoTo 0 If tCardInfo.Error = 0 Then ChipCardComand = True Exit Function
noChipDriveTreiber: tCardInfo.Error = 1 On Error GoTo 0
End Function .... -------------------------------------------------------------
Nun möchte ich das ganze in VB.NET übernehmen. Habe schon einmal festgestellt, dass Long nicht gleich long und Integer nicht gleich integer ist. Also habe ich alle Long in integer und alle integer in short geändert. Nun sind die Bytegrößen der geforderten Variablen wieder i.O.. Funktioniert aber nicht. Es gibt immer die Fehlermeldung: Eine Ausnahme (erste Chance) des Typs "System.AccessViolationException" ist in WindowsApplication1.exe aufgetreten. In VB.NET sieht mein Prog. so aus: -------------------------------------------------------------
Public Structure CardInfo Public Fehler As Integer 'Alt: Error (long) Public CardDaten As String Public CardPinDaten As String Public Status As String Public LockedBy As String Public Typ As String Public Protocol As String Public CardCount As Integer '(long) Public CardPower As Boolean Public MemSize As Integer '(long) Public PinSize As Short '(integer) Public PinCnt As Short '(integer) Public AtrBinary As String Public AtrBinarySize As Short '(integer) End Structure
Public Class KlasseChipDrive
Declare Function SCardComand Lib "SCARD32.DLL" _ (ByVal Handle As Integer, ByVal Cmd As String, ByVal CmdLen As Integer, ByVal DataIn As String, _ ByVal DataInLen As Integer, ByVal DataOut As String, ByVal DataOutLen As Integer) As Integer _ '(long) -> integer
Private sSCardDataOut As String Private lSCardDataOutLen As Integer '(long) Public tCardInfo As CardInfo
Private Function ChipCardComand(ByVal Cmd As String, ByVal DataIn As String, ByVal MaxIn As Integer) As Boolean '(long) -> integer Dim CmdLen As Integer '(long) Dim DataInLen As Integer '(long)
ChipCardComand = False Cmd = Cmd + Chr(0) CmdLen = 0 'bei unverschlüsselter Übertragung muß CmdLen = 0 sein DataInLen = Len(DataIn) DataIn = DataIn + Chr(0) lSCardDataOutLen = MaxIn sSCardDataOut = Microsoft.VisualBasic.Strings.StrDup(CInt(lSCardDataOutLen) + 1, Chr(0)) 'On Error GoTo noChipDriveTreiber tCardInfo.Fehler = SCardComand(0, Cmd, CmdLen, DataIn, DataInLen, sSCardDataOut$, lSCardDataOutLen) 'On Error GoTo 0 If tCardInfo.Fehler = 0 Then ChipCardComand = True End If Exit Function
noChipDriveTreiber: tCardInfo.Fehler = 1 On Error GoTo 0
End Function .... -------------------------------------------------------------
Kann mir jemand helfen? Danke citkid |