VB2010 - "FatalExecutionError" - 0xc0000005 on umanaged DLL import

  • Thread starter Thread starter FredMar
  • Start date Start date
F

FredMar

Guest
Dear friends,

I want to use a API for a software protection dongle with vb.net.
So i import the API DLL and work with it.
All fine.
But after a random time, the vb.net project crash with the failure "FatalExecutionError" - 0xc0000005
on a random position in the project.
So i started debugging the code.
I found out, what line is "the beast".

The crash comes, if i have a background load on the cpu (TCP Listener,...) und following line is called:

rev = LC_read(LC2_Handle, BlockNumber, buffer) 'KILL Read

The full call is:

Function DongleReadBlock(ByVal AccessLevel As Int32, ByVal Password As String, ByVal BlockNumber As Int32) As Byte()
Dim rev As Integer
Dim UserPassByteArray As Byte() = System.Text.Encoding.ASCII.GetBytes(Password)
Dim buffer(255) As Byte
DongleReadBlock = buffer 'For default
If UserPassByteArray.Length <> 8 Then
Exit Function 'Exit. Password didn't match.
End If

Dim LC2_Handle As System.UInt32 'lc_handle_t = UInt32
Try
For i As Integer = 0 To 255
rev = LC_open(DongleDeveloperID, i, LC2_Handle)
If rev = LC_SUCCESS Then
rev = LC_passwd(LC2_Handle, AccessLevel, UserPassByteArray) '0=Admin 1=User 2=Authentification
If rev = LC_SUCCESS Then
rev = LC_read(LC2_Handle, BlockNumber, buffer) 'KILL Read
If rev = LC_SUCCESS Then
Return buffer
End If
End If
End If
Next i
Catch ex As Exception
MsgBox("Dongle Error 3: " & ex.Message.ToString)
LC_close(LC2_Handle)
Finally
If LC2_Handle <> 0 Then
LC_close(LC2_Handle)
End If
End Try

Dim ClearBuffer(255) As Byte 'Deb
Return ClearBuffer
End Function


The DLL import is as follow:

<DllImport("LC.dll", SetLastError:=True, CharSet:=CharSet.Unicode)>
Private Function LC_read(ByVal handle As System.UInt32, ByVal block As Int32, ByVal buffer As Byte()) As Int32
End Function


So, someone has an idea, how i can catch or avoid the failure?

Best regards,
FredMar

Continue reading...
 
Back
Top