Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

I create a program to operate a device. The device is check acceptor. When the device is ready accepting, I place the check and the device will feed. But the exception raise after check is feeding "Attempt to read or write Protected Memory. This is often an indicating that other memory is corrupt".

How to solve this kind of problem.? My code to accept is below:

VB
Public Shared Function StartAccepting(ByVal intTime As Integer) As Boolean
    Dim ret As Boolean
    Dim time As Integer = intTime
    Dim strTmp(300) As Byte
    Dim strStr As String
    Dim enc As New System.Text.ASCIIEncoding()
    Try
        ret = RunAccept(time, strTmp(0))
        strStr = enc.GetString(strTmp)
        If ret Then
            Return True
        Else
            Return False
        End If
    Catch ex As Exception
        MsgBox("Error opening:ExMsg-" & ex.Message)
        Return False
    End Try
End Function



Exception raise after the bold code. after it return..
Posted
Comments
Sergey Alexandrovich Kryukov 3-Dec-13 20:44pm    
Not enough information. Where is the declaration of "RunAccept"?
—SA
Mike Meinz 3-Dec-13 21:36pm    
Could it be that you declare an array Dim strTmp(300) As Byte but you do not instantiate it?
Luiey Ichigo 3-Dec-13 21:57pm    
Hi SA,

The RunAccept will call the event from dll function. This is the sample of code that vendor provide. How to handle the bytes that return from the device? Which mean I want to count the bytes receive first before assign to to my declaration.

Actually this is my first time handling hardware engineering..

This is where you have to contact the manufacturer of your device and the SDK. It's extremely unlikely anyone here is going to have any experience with the exact device you're using.
 
Share this answer
 
Found it..when calling DLL import on RunAccept, I put the declaration as ByRef. I search and found someone advise to change to ByVal. And it's work..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900