Click here to Skip to main content
14,421,274 members
Rate this:
Please Sign up or sign in to vote.
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:

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()
        ret = RunAccept(time, strTmp(0))
        strStr = enc.GetString(strTmp)
        If ret Then
            Return True
            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..
Not enough information. Where is the declaration of "RunAccept"?
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..
Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

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..

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100