Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Callback function not working?? Video capture.

Callback function not working?? Video capture.

Scheduled Pinned Locked Moved Visual Basic
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DK KiloDunse
    wrote on last edited by
    #1

    Hi. I can't seem to get my¨callback function to work... plz help. This code will throw an error: Public Function myCallBack(ByVal lwnd As Long, ByVal lpVHdr As Long) As Boolean Dim VideoData() As Byte Dim gh As GCHandle = GCHandle.Alloc(lpVHdr, GCHandleType.Pinned) Dim AddrOflpVHdr As IntPtr = gh.AddrOfPinnedObject() ' **The error come's here.** Dim VideoHeader As VIDEOHDR = CType(Marshal.PtrToStructure(AddrOflpVHdr, _ GetType(VIDEOHDR)), VIDEOHDR) gh.Free() End Function The error is: An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object reference not set to an instance of an object.

    O 1 Reply Last reply
    0
    • D DK KiloDunse

      Hi. I can't seem to get my¨callback function to work... plz help. This code will throw an error: Public Function myCallBack(ByVal lwnd As Long, ByVal lpVHdr As Long) As Boolean Dim VideoData() As Byte Dim gh As GCHandle = GCHandle.Alloc(lpVHdr, GCHandleType.Pinned) Dim AddrOflpVHdr As IntPtr = gh.AddrOfPinnedObject() ' **The error come's here.** Dim VideoHeader As VIDEOHDR = CType(Marshal.PtrToStructure(AddrOflpVHdr, _ GetType(VIDEOHDR)), VIDEOHDR) gh.Free() End Function The error is: An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module. Additional information: Object reference not set to an instance of an object.

      O Offline
      O Offline
      OICU812
      wrote on last edited by
      #2

      Marshal.PtrToStructure(ptr,structure) is a Shared Sub and doesn't return a value. Try this revised code. I can't test it live but this is what i suspect is wrong with your code.

      Public Function myCallBack(ByVal lwnd As Long, ByVal lpVHdr As Long) As Boolean
      Dim VideoData() As Byte
      Dim gh As Runtime.InteropServices.GCHandle _
      = Runtime.InteropServices.GCHandle.Alloc _
      (lpVHdr, Runtime.InteropServices.GCHandleType.Pinned)

          Dim AddrOflpVHdr As IntPtr = gh.AddrOfPinnedObject()
      
          Dim VideoHeader As New VIDEOHDR
          Marshal.PtrToStructure(AddrOflpVHdr, VideoHeader)
      
          gh.Free()
      
      End Function
      
      D 1 Reply Last reply
      0
      • O OICU812

        Marshal.PtrToStructure(ptr,structure) is a Shared Sub and doesn't return a value. Try this revised code. I can't test it live but this is what i suspect is wrong with your code.

        Public Function myCallBack(ByVal lwnd As Long, ByVal lpVHdr As Long) As Boolean
        Dim VideoData() As Byte
        Dim gh As Runtime.InteropServices.GCHandle _
        = Runtime.InteropServices.GCHandle.Alloc _
        (lpVHdr, Runtime.InteropServices.GCHandleType.Pinned)

            Dim AddrOflpVHdr As IntPtr = gh.AddrOfPinnedObject()
        
            Dim VideoHeader As New VIDEOHDR
            Marshal.PtrToStructure(AddrOflpVHdr, VideoHeader)
        
            gh.Free()
        
        End Function
        
        D Offline
        D Offline
        DK KiloDunse
        wrote on last edited by
        #3

        This error appeares when it comes to: Marshal.PtrToStructure(AddrOflpVHdr, VideoHeader) An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll Additional information: The structure must not be a value class. The structure look like this: Structure VIDEOHDR Dim lpData As Integer '// address of video buffer Dim dwBufferLength As Integer '// size, in bytes, of the Data buffer Dim dwBytesUsed As Integer '// see below Dim dwTimeCaptured As Integer '// see below Dim dwUser As Integer '// user-specific data Dim dwFlags As Integer '// see below Dim dwReserved() As Integer '// reserved; do not use} 'UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1026"' Public Sub Initialize() ReDim dwReserved(3) End Sub End Structure

        O 1 Reply Last reply
        0
        • D DK KiloDunse

          This error appeares when it comes to: Marshal.PtrToStructure(AddrOflpVHdr, VideoHeader) An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll Additional information: The structure must not be a value class. The structure look like this: Structure VIDEOHDR Dim lpData As Integer '// address of video buffer Dim dwBufferLength As Integer '// size, in bytes, of the Data buffer Dim dwBytesUsed As Integer '// see below Dim dwTimeCaptured As Integer '// see below Dim dwUser As Integer '// user-specific data Dim dwFlags As Integer '// see below Dim dwReserved() As Integer '// reserved; do not use} 'UPGRADE_TODO: "Initialize" must be called to initialize instances of this structure. Click for more: 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="vbup1026"' Public Sub Initialize() ReDim dwReserved(3) End Sub End Structure

          O Offline
          O Offline
          OICU812
          wrote on last edited by
          #4

          I found a WebCam class here's a link "http://dotnetjunkies.com/WebLog/principal/articles/32662.aspx" it's in C# but you can either convert it to vb or compile it as a .dll and use it that way. This is the structure I pulled out of the class example in the link above. _ Public Structure VIDEOHDR _ Public lpData As Integer _ Public dwBufferLength As Integer _ Public dwBytesUsed As Integer _ Public dwTimeCaptured As Integer _ Public dwUser As Integer _ Public dwFlags As Integer _ Public dwReserved() As Integer End Structure 'VIDEOHDR

          D 1 Reply Last reply
          0
          • O OICU812

            I found a WebCam class here's a link "http://dotnetjunkies.com/WebLog/principal/articles/32662.aspx" it's in C# but you can either convert it to vb or compile it as a .dll and use it that way. This is the structure I pulled out of the class example in the link above. _ Public Structure VIDEOHDR _ Public lpData As Integer _ Public dwBufferLength As Integer _ Public dwBytesUsed As Integer _ Public dwTimeCaptured As Integer _ Public dwUser As Integer _ Public dwFlags As Integer _ Public dwReserved() As Integer End Structure 'VIDEOHDR

            D Offline
            D Offline
            DK KiloDunse
            wrote on last edited by
            #5

            I've found the problem: the garbage collector. :mad: Solved it by using GC.KeepAlive() Thanks for you help.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups