Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C++CLI / VB .Net / .Net-Framework » SCARD32.DLL und VB.NET

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
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
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
30.05.2008, 21:09 Uhr
citkid



Hallo,

habe meinen Fehler gefunden.

Die deklaration in VB6:
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

und hir in VB.NET:
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

Der letzte Übergabeparameter "DataOutLen" ist in VB6 ohne "ByVal" angegeben und somit "ByRef". In VB.NET hatte ich auch nichts eingegeben. Hier hat VB.NET die fehlende Angabe jedoch "ByVal/ByRef" selbst mit "ByVal" eingetragen.

So muß es in VB.NET richtig sein:
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, ByRef DataOutLen As Integer) As Integer

Vielen Dank an alle, die sich schon hierüber den Kopf zerbrochen haben.

citkid
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C++CLI / VB .Net / .Net-Framework ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: