Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: dili900 on May 10, 2022, 09:02:00 AM
-
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
-
Hello,
That's a flat C API I think and none of the programmers here work in VB anymore.
Theoretically it will work but it's untested by anyone at NFS.
Sorry I can't be of more help.
-
maybe someone has done in C#?