Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: dili900 on May 10, 2022, 09:02:00 AM

Title: Trouble getting current Runnig line
Post 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:
Code: [Select]
'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:
Code: [Select]
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 :
Code: [Select]
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'can someone help me
Title: Re: Trouble getting current Runnig line
Post by: GOOMBA on May 11, 2022, 10:54:44 AM
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.
Title: Re: Trouble getting current Runnig line
Post by: dili900 on May 11, 2022, 11:11:06 AM
maybe someone has done in C#?