'
'
'
'
'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Runtime.InteropServices
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MseqProcess
Friend Class ProcessingHookDataStruct
Public MilDigitizer As MIL_ID
Public MilImageDisp As MIL_ID
Public MilSeqContext As MIL_ID
Public ProcessedImageCount As MIL_INT
Public ProcessingOperation As ProcessingHookOperation
End Class
Friend Class EncodingFrameEndHookDataStruct
Public EncodedImageCount As MIL_INT
End Class
Friend Class DecodingFrameEndHookDataStruct
Public DecodedImageCount As MIL_INT
Public MilImageDisp As MIL_ID
End Class
Friend Enum ProcessingHookOperation
DISPLAY
ENCODE
End Enum
Friend Class Program
Private Const BUFFERING_SIZE_MAX As Integer = 20
Private Shared ReadOnly SEQUENCE_FILE As String = MIL.M_TEMP_DIR & "SeqProcess.mp4"
Private Shared ReadOnly REMOTE_SEQUENCE_FILE As String = "remote:///" + SEQUENCE_FILE
Shared Function Main(ByVal args() As String) As Integer
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilRemoteApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDigitizer As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilImageDisp As MIL_ID = MIL.M_NULL
Dim MilGrabBufferList(BUFFERING_SIZE_MAX - 1) As MIL_ID
Dim MilCompressContext As MIL_ID = MIL.M_NULL
Dim MilDecompressContext As MIL_ID = MIL.M_NULL
Dim LicenseModules As MIL_INT = 0
Dim MilSystemLocation As MIL_INT = MIL.M_NULL
Dim MilGrabBufferListSize As MIL_INT
Dim ProcessFrameCount As MIL_INT = 0
Dim NbFrames As MIL_INT = 0
Dim n As MIL_INT = 0
Dim EncodingDesiredFrameRate As Double = 0.0
Dim ProcessFrameRate As Double = 0.0
Dim SeqProcessFilePathSize As MIL_INT = 0
Dim SeqProcessFilePath As StringBuilder = Nothing
Dim ProcessingUserHookData As New ProcessingHookDataStruct()
Dim EncodingFrameEndUserHookData As New EncodingFrameEndHookDataStruct()
Dim DecodingFrameEndUserHookData As New DecodingFrameEndHookDataStruct()
Dim SeqSystemType As MIL_INT = MIL.M_NULL
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
MIL.MsysInquire(MilSystem, MIL.M_OWNER_APPLICATION, MilRemoteApplication)
MilSystemLocation = MIL.MsysInquire(MilSystem, MIL.M_LOCATION, MIL.M_NULL)
If (MIL.MappInquire(MilRemoteApplication, MIL.M_PLATFORM_OS_TYPE, MIL.M_NULL) <> MIL.M_OS_WINDOWS) Then
If (MilSystemLocation = MIL.M_REMOTE) Then
Console.WriteLine("The Distributed MIL server must run on a Windows system.")
Else
Console.WriteLine("This example only works with a Windows system.")
End If
Console.WriteLine("Press <Enter> to end.")
Console.ReadKey()
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
Return 0
End If
MIL.MappInquire(MilRemoteApplication, MIL.M_LICENSE_MODULES, LicenseModules)
If ((LicenseModules And MIL.M_LICENSE_JPEGSTD) <> MIL.M_LICENSE_JPEGSTD) Then
Console.WriteLine("Need a Compression/Decompression license to run this example.")
Console.WriteLine("Press <Enter> to end.")
Console.ReadKey()
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
Return 0
End If
MIL.MappControl(MIL.M_DEFAULT, MIL.M_ERROR, MIL.M_PRINT_DISABLE)
For MilGrabBufferListSize = 0 To BUFFERING_SIZE_MAX - 1
MIL.MbufAllocColor(MilSystem, MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_BAND, MIL.M_NULL), MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, MIL.M_NULL), MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, MIL.M_NULL), 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_GRAB + MIL.M_PROC, MilGrabBufferList(CType(MilGrabBufferListSize, Integer)))
If MilGrabBufferList(CType(MilGrabBufferListSize, Integer)) <> MIL.M_NULL Then
MIL.MbufClear(MilGrabBufferList(CType(MilGrabBufferListSize, Integer)), &HFF)
Else
Exit For
End If
Next MilGrabBufferListSize
MIL.MappControl(MIL.M_DEFAULT, MIL.M_ERROR, MIL.M_PRINT_ENABLE)
n = 0
Do While n < 2 AndAlso MilGrabBufferListSize > 0
MilGrabBufferListSize -= 1
MIL.MbufFree(MilGrabBufferList(CType(MilGrabBufferListSize, Integer)))
n += 1
Loop
If MilGrabBufferListSize = 0 Then
Console.WriteLine("!!! No grab buffers have been allocated. Need to set more Non-Paged Memory. !!!")
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
Console.WriteLine("Press <Enter> to end.")
Console.ReadKey()
Return 1
End If
ProcessingUserHookData.MilDigitizer = MilDigitizer
ProcessingUserHookData.MilSeqContext = MIL.M_NULL
ProcessingUserHookData.MilImageDisp = MilImageDisp
ProcessingUserHookData.ProcessedImageCount = 0
ProcessingUserHookData.ProcessingOperation = ProcessingHookOperation.DISPLAY
Dim hUserData As GCHandle = GCHandle.Alloc(ProcessingUserHookData)
Dim ProcessingFunctionDelegate As MIL_DIG_HOOK_FUNCTION_PTR = AddressOf ProcessingFunction
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_START, MIL.M_DEFAULT, ProcessingFunctionDelegate, GCHandle.ToIntPtr(hUserData))
Console.Write(vbNewLine + "H.264 IMAGE SEQUENCE COMPRESSION." + vbNewLine)
Console.Write("---------------------------------" + vbNewLine + vbNewLine)
Console.Write("Press <Enter> to start compression." + vbCr)
Console.ReadKey()
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_STOP, MIL.M_DEFAULT, ProcessingFunctionDelegate, GCHandle.ToIntPtr(hUserData))
MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_RATE, EncodingDesiredFrameRate)
Console.Write("Grabbing frames at {0:0.00} frames/sec." + vbNewLine, EncodingDesiredFrameRate)
MIL.MseqAlloc(MilSystem, MIL.M_DEFAULT, MIL.M_SEQ_COMPRESS, MIL.M_DEFAULT, MIL.M_DEFAULT, MilCompressContext)
MIL.MseqDefine(MilCompressContext, MIL.M_SEQ_OUTPUT(0) + MIL.M_SEQ_DEST(0), MIL.M_FILE, (If(MilSystemLocation <> MIL.M_REMOTE, SEQUENCE_FILE, REMOTE_SEQUENCE_FILE)), MIL.M_FILE_FORMAT_MP4)
'
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_BIT_RATE_MODE, MIL.M_VARIABLE)
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_BIT_RATE, 5000)
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_BIT_RATE_MAX, 5000)
If EncodingDesiredFrameRate <> 0 Then
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_FRAME_RATE, EncodingDesiredFrameRate)
End If
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_FRAME_RATE_MODE, MIL.M_VARIABLE)
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_QUALITY, 100)
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_PROFILE, MIL.M_PROFILE_HIGH)
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_LEVEL, MIL.M_LEVEL_4_2)
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_STREAM_GROUP_OF_PICTURE_SIZE, 30)
EncodingFrameEndUserHookData.EncodedImageCount = 0
Dim EncodingFrameEndUserHookDataHandle As GCHandle = GCHandle.Alloc(EncodingFrameEndUserHookData)
Dim FrameEncodingEndFunctionDelegate As MIL_SEQ_HOOK_FUNCTION_PTR = AddressOf FrameEncodingEndFunction
MIL.MseqHookFunction(MilCompressContext, MIL.M_FRAME_END, FrameEncodingEndFunctionDelegate, GCHandle.ToIntPtr(EncodingFrameEndUserHookDataHandle))
MIL.MseqControl(MilCompressContext, MIL.M_CONTEXT, MIL.M_BUFFER_SAMPLE, MilGrabBufferList(0))
MIL.MappControl(MIL.M_ERROR, MIL.M_PRINT_DISABLE)
MIL.MseqProcess(MilCompressContext, MIL.M_START, MIL.M_ASYNCHRONOUS)
If (CheckMseqProcessError(MilApplication, MilCompressContext)) Then
MIL.MseqProcess(MilCompressContext, MIL.M_STOP, MIL.M_NULL)
Dim SourceSizeX As MIL_INT = 0
Dim SourceSizeY As MIL_INT = 0
Dim SourceFPS As Double = 0.0
MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, SourceSizeX)
MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, SourceSizeY)
MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_RATE, SourceFPS)
Console.WriteLine("Unable to perform H.264 encoding with the current input source of")
Console.WriteLine("{0} X {1} @ {2:0.00} fps.", SourceSizeX, SourceSizeY, SourceFPS)
Console.WriteLine(vbNewLine + "Example parameters are optimized for sources of")
Console.WriteLine("1920 x 1080 @ 60 fps.")
Console.WriteLine(vbNewLine + "You can try changing encoding parameters to better match your source." + vbNewLine)
Console.WriteLine("Press <Enter> to end.")
Console.ReadKey()
Do While MilGrabBufferListSize > 0
MilGrabBufferListSize -= 1
MIL.MbufFree(MilGrabBufferList(CType(MilGrabBufferListSize, Integer)))
MilGrabBufferList(CType(MilGrabBufferListSize, Integer)) = MIL.M_NULL
Loop
MIL.MseqFree(MilCompressContext)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
Return 0
End If
MIL.MappControl(MIL.M_ERROR, MIL.M_PRINT_ENABLE)
Console.Write("Live image capture and compression to file using ")
MIL.MseqInquire(MilCompressContext, MIL.M_CONTEXT, MIL.M_CODEC_TYPE, SeqSystemType)
If SeqSystemType = MIL.M_HARDWARE + MIL.M_QSV Then
Console.WriteLine("Hardware acceleration.")
Else
Console.WriteLine("Software implementation.")
End If
'
ProcessingUserHookData.MilSeqContext = MilCompressContext
ProcessingUserHookData.ProcessedImageCount = 0
ProcessingUserHookData.ProcessingOperation = ProcessingHookOperation.ENCODE
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_START, MIL.M_DEFAULT, ProcessingFunctionDelegate, GCHandle.ToIntPtr(hUserData))
Console.WriteLine("Press <Enter> to stop." + vbNewLine)
Console.ReadKey()
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_STOP + MIL.M_WAIT, MIL.M_DEFAULT, ProcessingFunctionDelegate, GCHandle.ToIntPtr(hUserData))
hUserData.Free()
MIL.MseqProcess(MilCompressContext, MIL.M_STOP, MIL.M_WAIT)
GC.KeepAlive(FrameEncodingEndFunctionDelegate)
EncodingFrameEndUserHookDataHandle.Free()
MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_COUNT, ProcessFrameCount)
MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_RATE, ProcessFrameRate)
Console.WriteLine("{0} frames encoded at {1:0.00} frames/sec ({2:0.0} ms/frame).", ProcessFrameCount, ProcessFrameRate, 1000.0 / ProcessFrameRate)
Console.WriteLine()
MIL.MseqInquire(MilCompressContext, MIL.M_SEQ_OUTPUT(0) + MIL.M_SEQ_DEST(0), MIL.M_STREAM_FILE_NAME_SIZE, SeqProcessFilePathSize)
SeqProcessFilePath = New StringBuilder(CInt(Fix(SeqProcessFilePathSize)))
MIL.MseqInquire(MilCompressContext, MIL.M_SEQ_OUTPUT(0) + MIL.M_SEQ_DEST(0), MIL.M_STREAM_FILE_NAME, SeqProcessFilePath)
Console.WriteLine("The video sequence file was written to:")
Console.WriteLine("{0}.", SeqProcessFilePath.ToString())
Console.WriteLine()
Console.WriteLine("It can be played back using any compatible video player.")
Do While MilGrabBufferListSize > 0
MilGrabBufferListSize -= 1
MIL.MbufFree(MilGrabBufferList(CType(MilGrabBufferListSize, Integer)))
MilGrabBufferList(CType(MilGrabBufferListSize, Integer)) = MIL.M_NULL
Loop
MIL.MseqFree(MilCompressContext)
Console.WriteLine("Press <Enter> to replay encoded sequence.")
Console.ReadKey()
MIL.MseqAlloc(MilSystem, MIL.M_DEFAULT, MIL.M_SEQ_DECOMPRESS, MIL.M_DEFAULT, MIL.M_DEFAULT, MilDecompressContext)
MIL.MseqDefine(MilDecompressContext, MIL.M_SEQ_INPUT(0), MIL.M_FILE, (If(MilSystemLocation <> MIL.M_REMOTE, SEQUENCE_FILE, REMOTE_SEQUENCE_FILE)), MIL.M_FILE_FORMAT_MP4)
Dim outputFrameRate As Double = 0.0
MIL.MseqInquire(MilDecompressContext, MIL.M_SEQ_INPUT(0), MIL.M_STREAM_FRAME_RATE, outputFrameRate)
Console.WriteLine()
Console.WriteLine("Replaying file at {0:0.00} frames/second.", outputFrameRate)
DecodingFrameEndUserHookData.DecodedImageCount = 0
DecodingFrameEndUserHookData.MilImageDisp = MilImageDisp
Dim DecodingFrameEndUserHookDataHandle As GCHandle = GCHandle.Alloc(DecodingFrameEndUserHookData)
Dim FrameDecodingEndFunctionDelegate As MIL_SEQ_HOOK_FUNCTION_PTR = AddressOf FrameDecodingEndFunction
MIL.MseqHookFunction(MilDecompressContext, MIL.M_FRAME_END, FrameDecodingEndFunctionDelegate, GCHandle.ToIntPtr(DecodingFrameEndUserHookDataHandle))
MIL.MseqProcess(MilDecompressContext, MIL.M_START, MIL.M_ASYNCHRONOUS)
Console.WriteLine("Press <Enter> to stop." + vbNewLine)
Console.ReadKey()
MIL.MseqProcess(MilDecompressContext, MIL.M_STOP, MIL.M_NULL)
GC.KeepAlive(FrameDecodingEndFunctionDelegate)
DecodingFrameEndUserHookDataHandle.Free()
MIL.MseqFree(MilDecompressContext)
Console.WriteLine("Press <Enter> to end.")
Console.ReadKey()
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
Return 0
End Function
Private Const STRING_LENGTH_MAX As Integer = 20
Private Const STRING_POS_X As Integer = 20
Private Const STRING_POS_Y As Integer = 20
Private Shared Function ProcessingFunction(ByVal HookType As MIL_INT, ByVal HookId As MIL_ID, ByVal HookDataPtr As IntPtr) As MIL_INT
If (Not IntPtr.Zero.Equals(HookDataPtr)) Then
Dim hUserData As GCHandle = GCHandle.FromIntPtr(HookDataPtr)
Dim UserHookDataPtr As ProcessingHookDataStruct = TryCast(hUserData.Target, ProcessingHookDataStruct)
Dim ModifiedBufferId As MIL_ID = MIL.M_NULL
Dim Text As String
MIL.MdigGetHookInfo(HookId, MIL.M_MODIFIED_BUFFER + MIL.M_BUFFER_ID, ModifiedBufferId)
Select Case UserHookDataPtr.ProcessingOperation
Case ProcessingHookOperation.DISPLAY
MIL.MbufCopy(ModifiedBufferId, UserHookDataPtr.MilImageDisp)
Case ProcessingHookOperation.ENCODE
UserHookDataPtr.ProcessedImageCount += 1
Console.Write("Processing frame #{0}." & Constants.vbCr, UserHookDataPtr.ProcessedImageCount)
Text = String.Format("{0}", UserHookDataPtr.ProcessedImageCount)
MIL.MgraText(MIL.M_DEFAULT, ModifiedBufferId, STRING_POS_X, STRING_POS_Y, Text)
MIL.MseqFeed(UserHookDataPtr.MilSeqContext, ModifiedBufferId, MIL.M_DEFAULT)
MIL.MbufCopy(ModifiedBufferId, UserHookDataPtr.MilImageDisp)
End Select
End If
Return 0
End Function
Private Shared Function FrameEncodingEndFunction(ByVal HookType As MIL_INT, ByVal HookId As MIL_ID, ByVal HookDataPtr As IntPtr) As MIL_INT
If (Not IntPtr.Zero.Equals(HookDataPtr)) Then
Dim hUserData As GCHandle = GCHandle.FromIntPtr(HookDataPtr)
Dim UserHookDataPtr As EncodingFrameEndHookDataStruct = TryCast(hUserData.Target, EncodingFrameEndHookDataStruct)
If HookType = MIL.M_FRAME_END Then
Dim CompressedBufferId As MIL_ID = MIL.M_NULL
Dim CompressedDataPtr As MIL_INT = MIL.M_NULL
Dim CompressedDataSize As MIL_INT = 0
UserHookDataPtr.EncodedImageCount += 1
MIL.MseqGetHookInfo(HookId, MIL.M_MODIFIED_BUFFER + MIL.M_BUFFER_ID, CompressedBufferId)
MIL.MbufInquire(CompressedBufferId, MIL.M_HOST_ADDRESS, CompressedDataPtr)
MIL.MbufInquire(CompressedBufferId, MIL.M_SIZE_BYTE, CompressedDataSize)
End If
End If
Return 0
End Function
Private Shared Function FrameDecodingEndFunction(ByVal HookType As MIL_INT, ByVal HookId As MIL_ID, ByVal HookDataPtr As IntPtr) As MIL_INT
If (Not IntPtr.Zero.Equals(HookDataPtr)) Then
Dim hUserData As GCHandle = GCHandle.FromIntPtr(HookDataPtr)
Dim UserHookDataPtr As DecodingFrameEndHookDataStruct = TryCast(hUserData.Target, DecodingFrameEndHookDataStruct)
If HookType = MIL.M_FRAME_END Then
Dim DecompressedBufferId As MIL_ID = MIL.M_NULL
UserHookDataPtr.DecodedImageCount += 1
MIL.MseqGetHookInfo(HookId, MIL.M_MODIFIED_BUFFER + MIL.M_BUFFER_ID, DecompressedBufferId)
MIL.MbufCopy(DecompressedBufferId, UserHookDataPtr.MilImageDisp)
End If
End If
Return 0
End Function
Private Structure MSEQ_PARAM
Public Sub New(ByVal controlName As String, ByVal controlType As MIL_INT, ByVal originalValue As MIL_INT, ByVal effectiveValue As MIL_INT)
Me.ControlName = controlName
Me.ControlType = controlType
Me.OriginalValue = originalValue
Me.EffectiveValue = effectiveValue
End Sub
Public ControlName As String
Public ControlType As MIL_INT
Public OriginalValue As MIL_INT
Public EffectiveValue As MIL_INT
End Structure
Private Shared Function CheckMseqProcessError(ByVal MilApplication As MIL_ID, ByVal MilCompressContext As MIL_ID) As Boolean
Dim IsError As Boolean = False
Dim IsWarning As Boolean = False
Dim MilErrorCode As MIL_INT = PrintMilErrorMessage(MilApplication)
If MilErrorCode <> MIL.M_NULL_ERROR Then
Dim MseqParamList() As MSEQ_PARAM = {New MSEQ_PARAM("M_STREAM_BIT_RATE_MODE", MIL.M_STREAM_BIT_RATE_MODE, 0, 0), New MSEQ_PARAM("M_STREAM_BIT_RATE", MIL.M_STREAM_BIT_RATE, 0, 0), New MSEQ_PARAM("M_STREAM_BIT_RATE_MAX", MIL.M_STREAM_BIT_RATE_MAX, 0, 0), New MSEQ_PARAM("M_STREAM_FRAME_RATE_MODE", MIL.M_STREAM_FRAME_RATE_MODE, 0, 0), New MSEQ_PARAM("M_STREAM_QUALITY", MIL.M_STREAM_QUALITY, 0, 0), New MSEQ_PARAM("M_STREAM_PROFILE", MIL.M_STREAM_PROFILE, 0, 0), New MSEQ_PARAM("M_STREAM_LEVEL", MIL.M_STREAM_LEVEL, 0, 0), New MSEQ_PARAM("M_STREAM_GROUP_OF_PICTURE_SIZE", MIL.M_STREAM_GROUP_OF_PICTURE_SIZE, 0, 0)}
Dim NumberOfModifiedParams As MIL_INT = 0
For ParamIndex As Integer = 0 To MseqParamList.Length - 1
MIL.MseqInquire(MilCompressContext, MIL.M_CONTEXT, MseqParamList(ParamIndex).ControlType, MseqParamList(ParamIndex).OriginalValue)
MIL.MseqInquire(MilCompressContext, MIL.M_CONTEXT, MseqParamList(ParamIndex).ControlType Or MIL.M_EFFECTIVE_VALUE, MseqParamList(ParamIndex).EffectiveValue)
If MseqParamList(ParamIndex).OriginalValue <> MseqParamList(ParamIndex).EffectiveValue Then
If NumberOfModifiedParams = 0 Then
Console.Write(Constants.vbLf & "Parameter(s) that have been internally modified:" & Constants.vbLf)
End If
Console.WriteLine("- {0}", MseqParamList(ParamIndex).ControlName)
NumberOfModifiedParams += 1
IsWarning = True
End If
Next ParamIndex
Console.WriteLine()
'
If (Not IsWarning) Then
IsError = True
End If
End If
Return IsError
End Function
Private Shared Function PrintMilErrorMessage(ByVal MilApplication As MIL_ID) As MIL_INT
Dim MilErrorCode As MIL_INT
Dim MilErrorMsg As New StringBuilder(MIL.M_ERROR_MESSAGE_SIZE)
Dim MilErrorSubCode(2) As MIL_INT
Dim MilErrorSubMsg(2) As StringBuilder
For i As Integer = 0 To 2
MilErrorSubMsg(i) = New StringBuilder(MIL.M_ERROR_MESSAGE_SIZE)
Next i
MilErrorCode = MIL.MappGetError(MilApplication, MIL.M_CURRENT + MIL.M_MESSAGE, MilErrorMsg)
If MilErrorCode <> MIL.M_NULL_ERROR Then
Dim subCount As MIL_INT = 3
MIL.MappGetError(MilApplication, MIL.M_CURRENT_SUB_NB, subCount)
MilErrorSubCode(0) = MIL.MappGetError(MilApplication, MIL.M_CURRENT_SUB_1 + MIL.M_MESSAGE, MilErrorSubMsg(0))
MilErrorSubCode(1) = MIL.MappGetError(MilApplication, MIL.M_CURRENT_SUB_2 + MIL.M_MESSAGE, MilErrorSubMsg(1))
MilErrorSubCode(2) = MIL.MappGetError(MilApplication, MIL.M_CURRENT_SUB_3 + MIL.M_MESSAGE, MilErrorSubMsg(2))
Console.WriteLine(Constants.vbLf & "MseqProcess generated a warning or an error:")
Console.WriteLine(" {0}", MilErrorMsg.ToString())
For i As Integer = 0 To CType(subCount - 1, Integer)
If MilErrorSubCode(i) <> 0 Then
Console.WriteLine(" {0}", MilErrorSubMsg(i))
End If
Next i
End If
Return MilErrorCode
End Function
End Class
End Namespace