Hello Guest it is April 24, 2024, 07:30:22 PM

Author Topic: Trouble getting current Runnig line  (Read 458 times)

0 Members and 1 Guest are viewing this topic.

Trouble getting current Runnig line
« 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

GOOMBA

*
Re: Trouble getting current Runnig line
« Reply #1 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.
Re: Trouble getting current Runnig line
« Reply #2 on: May 11, 2022, 11:11:06 AM »
maybe someone has done in C#?