I am working with visual basic express. I am having trouble with a code that works fine in VB6, but is giving me the error "Attempted to read or write protected memory. This is often an indication that other memory has been corrupted" in vb express.
I need to use the following function from a dll. It takes as a parameter the address of an array of pointers to the rows in a 2D array.
'The function is declared as follows...
Private Declare Function Identify Lib "Dompin.dll" (ByRef Template As Long) As Long
'....
Public class A
Private Template(200, 9) As Byte '2D array of bytes
Private Sub Indent()
Dim ret as Long
Dim Buffer(9) As Long 'Will store pointers to each of the 10 rows of Template
For i = 0 To 9
Buffer(i) = VarPtr(Template(0, i))
Next i
ret = Identify(Buffer(0))
end sub
'VarPtr is not available in VB6 so VarPtr method is coded as follows...
Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As GCHandle = GCHandle.Alloc(o, GCHandleType.Pinned)
Dim ret As IntPtr = GC.AddrOfPinnedObject().ToInt32
GC.Free()
Return ret
End Function
End Class
When I call Indent I get the stated error in the line "ret = Identify(Buffer(0))".
Can anyone help me on this?
Thanks!
I need to use the following function from a dll. It takes as a parameter the address of an array of pointers to the rows in a 2D array.
'The function is declared as follows...
Private Declare Function Identify Lib "Dompin.dll" (ByRef Template As Long) As Long
'....
Public class A
Private Template(200, 9) As Byte '2D array of bytes
Private Sub Indent()
Dim ret as Long
Dim Buffer(9) As Long 'Will store pointers to each of the 10 rows of Template
For i = 0 To 9
Buffer(i) = VarPtr(Template(0, i))
Next i
ret = Identify(Buffer(0))
end sub
'VarPtr is not available in VB6 so VarPtr method is coded as follows...
Public Function VarPtr(ByVal o As Object) As Integer
Dim GC As GCHandle = GCHandle.Alloc(o, GCHandleType.Pinned)
Dim ret As IntPtr = GC.AddrOfPinnedObject().ToInt32
GC.Free()
Return ret
End Function
End Class
When I call Indent I get the stated error in the line "ret = Identify(Buffer(0))".
Can anyone help me on this?
Thanks!