Imports System.Runtime.InteropServices

Module POS_CIDR
    <UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet:=CharSet.Unicode)>
    Public Delegate Sub Callback(ByVal line As Integer, <MarshalAs(UnmanagedType.LPWStr)> msg As String)

    <DllImport("POS_CIDR.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode)>
    Private Function CIDR_Info() As IntPtr
    End Function

    <DllImport("POS_CIDR.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode)>
    Public Function CIDR_RegisterEvent(funcPtr As Callback, mask As Int32) As Int32
    End Function

    <DllImport("POS_CIDR.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode)>
    Public Function CIDR_SaveLine(line As Int32, <MarshalAs(UnmanagedType.LPWStr)> fileName As String, <MarshalAs(UnmanagedType.LPWStr)> param As String) As Int32
    End Function

    <DllImport("POS_CIDR.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode)>
    Public Function CIDR_PlayLine(line As Int32) As Int32
    End Function

    Public Function CIDR_InfoStr() As String
        Dim ptr As IntPtr
        ptr = CIDR_Info()
        Return Marshal.PtrToStringUni(ptr)
    End Function

    Public Function CIDR_GetInfo(ByRef dll_info As String, ByRef lines As Integer) As Boolean
        dll_info = ""
        lines = 0
        Try
            Dim s As String = CIDR_InfoStr()
            Dim parts As String() = s.Split(New String() {vbCrLf}, StringSplitOptions.None)

            If ((parts.Length > 3) And (parts(0).Contains("POS")) And (parts(2).Contains(":"))) Then
                dll_info = parts(0)
                Dim p As Integer = parts(2).IndexOf(":")
                lines = Convert.ToInt16(parts(2).Substring(p + 1).Trim())
                Return True
            End If
        Catch
        End Try
        Return False
    End Function

End Module
