Attribute VB_Name = "Module2"
Option Explicit
  

Public g_iCrntCam As Long
Public bCallbackActiv As Boolean
Public bSaveRAW As Boolean
Public bNewRawData As Boolean

Dim buf() As Byte
Dim bSize As Long
Dim bFrameCounter As Long

' externals
' =====================================================================
         
Private Declare Sub memCPY _
    Lib "kernel32" Alias "RtlMoveMemory" _
   (ByRef hpvDest As Any, _
    ByRef hpvSource As Any, _
    ByVal cbCopy As Long)
    
' =====================================================================


    
Public Function MyCallback(ByRef pBuf As Long, ByVal lBufferSize As Long, ByVal pCBContext As Long) As Long

If bSaveRAW = True Then
    bSaveRAW = False
                
    ReDim buf(lBufferSize)
        
    memCPY buf(0), ByVal VarPtr(pBuf), lBufferSize  ' Copy FramData to memory

    bNewRawData = True                              ' Flag for saving memory to file
       
End If

bSize = lBufferSize
bFrameCounter = bFrameCounter + 1

        'Do not edit formControls here, do it in an timer or thread !!!
        'Form1.Text1 = i
    
End Function

Public Function fSetCallback(ByVal iCrntCam As Long) As Boolean

If ICubeSDK_SetCallback(iCrntCam, CALLBACK_RGB, AddressOf MyCallback, 0) = IC_ERROR Then
    MsgBox ("Error: ICubeSDK_SetCallback")
End If

bFrameCounter = 0

bCallbackActiv = True
End Function

Public Sub UpdateDisplay()

   If bCallbackActiv = True Then
   
         Form1.LabelFrames = "Frames:  " & CStr((bFrameCounter))
         Form1.LabelBuffersize = "BufferSize:  " & CStr((bSize))

        If bNewRawData = True Then
        bNewRawData = False
        
        Open "test.raw" For Binary Access Read Write Lock Read Write As #1
        Put #1, , buf()
        Close #1
        End If
    End If
     
End Sub
