I'm currently working on mini app with vb .net, trying to control Mach4 through IPC library.
here is defined Function:
'Get the line of Gcode from the loaded gcode file.
<DllImport("Mach4IPC.dll", EntryPoint:="mcCntlGetGcodeLine", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)>
Public Function mcCntlGetGcodeLine(<MarshalAs(UnmanagedType.I4)> mInst As Integer,
<MarshalAs(UnmanagedType.I4)> LineNumber As Integer,
GcodeAdressPointer As IntPtr,
<MarshalAs(UnmanagedType.U4)> BufferLength As Int32) As Integer
End Function
and when trying to call from function:
Public Function GetCurrentLine(Optional nLine As Integer = -1) As String
If nLine = -1 Then
GetRuningLineNumber(nLine)
End If
Dim _modIntPtr As IntPtr = Marshal.AllocHGlobal(128)
mcCntlGetGcodeLine(0, nLine, _modIntPtr, 128)
Return Marshal.PtrToStringAnsi(_modIntPtr)
End Function
throw error :
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
can someone help me