I am calling an c dll function which has a callback. The callback gets
called once and my grid gets populated. The grid should have 4 rows, but as
soon as the first row gets populated the programs halts with an error:
Attempted to read or write protected memory. This is often an indication
that other memory is corrupt. Calling the function from Delphi works great
and returns 4 rows. It uses cdelc for calling convention, I tried using the
line below:
<DllImport("remotapi.dll", CallingConvention:=CallingConvention.Cdecl)> _
Sub rlist(ByRef INRLIST_PARMS As TRLIST_PARMS, ByRef INRLIST_RESP As
TRLIST_RESP, ByVal incb As ListDelegate)
End Sub
I end up with the same error. Any ideas would be appreciated. Thanks
Form1
Private Sub RLIST_POPULATE(ByRef RLIST_DETAIL As TRLIST_DETAIL)
Try
Dim source As String = StripNull(RLIST_DETAIL.source_name)
Dim RegNum As String = StripNull(RLIST_DETAIL.request_nbr)
Dim Target As String = StripNull(RLIST_DETAIL.target_name)
Dim ref_id_1 As String = StripNull(RLIST_DETAIL.ref_id_1)
Dim ref_id_2 As String = StripNull(RLIST_DETAIL.ref_id_2) & " "
Dim lvDate As String = StripNull(RLIST_DETAIL.creation_date)
Dim lvTime As String = StripNull(RLIST_DETAIL.creation_time)
Dim row1 As String() = {source, RegNum, Target, ref_id_1,
ref_id_2, lvDate, lvTime}
grd.Rows.Add(row1)
grd.Refresh()
Catch
MessageBox.Show("Error in Populate")
End Try
End Sub
.....
Private Sub cmdList_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdList.Click
RLIST_PARMS.size = Marshal.SizeOf(RLIST_PARMS)
RLIST_RESP.size = Marshal.SizeOf(RLIST_RESP)
RLIST_PARMS.ref_id_1 = edtRef1.Text & New String(Chr(0), 11 -
Len(edtRef1.Text))
RLIST_PARMS.hostname = edtHost.Text & New String(Chr(0), 101 -
Len(edtHost.Text))
RLIST_PARMS.system_user = "CHAINLNK" & New String(Chr(0), 101 - 8)
RLIST_PARMS.system_password = "CHAINLNK" & New String(Chr(0), 101 -
8)
RLIST_PARMS.system_select = edtStore.Text & New String(Chr(0), 11 -
Len(edtStore.Text))
RLIST_PARMS.target_name = edtStore.Text & New String(Chr(0), 11 -
Len(edtStore.Text))
RLIST_PARMS.proc_status_code = "REA" & New String(Chr(0), 4 - 3)
RLIST_PARMS.source_name = edtSource.Text & New String(Chr(0), 11 -
Len(edtSource.Text))
Dim cb As New ListDelegate(AddressOf RLIST_POPULATE)
---> rlist(RLIST_PARMS, RLIST_RESP, cb) <--- Errors here
Module 1
Public Declare sub rlist Lib "remotapi.dll" (ByRef RLIST_PARMS As
TRLIST_PARMS, ByRef RLIST_RESP As TRLIST_RESP, ByVal incb As ListDelegate)