Visual Basic .net中的AVI捕获程序停止使用记录期间启用的回叫功能

问题描述 投票:2回答:1

我已经使用avicap32.dll调用编写了一个Visual Basic .net桌面应用程序。在我引入回调whilstrecording video之前,这完全可以按预期工作。在录制之前启用回调,在录制完成并写入输出文件之后禁用回调。

通过将CAPTUREPARMS fYield参数设置为1进行记录。因此,记录<。该应用程序可能会多次记录正在使用的回调,但是有时我会感到恐惧,“该应用程序处于中断模式”。未处理的异常:System.NullReferenceException:'对象引用未设置为对象的实例。'

调试输出:引发的异常:未知模块中的'System.NullReferenceException'。在未知模块中发生了类型为'System.NullReferenceException'的未处理异常。对象引用未设置为对象的实例。

  • 这表明它是一个外部异常,如果是这样,该怎么办?

  • 为什么回调应该起作用然后停止?
  • 我是否正确且以最佳方式设置了回调?
  • 经过大量研究之后,我被卡住了!

我正在使用:声明函数SendMessageP Lib“ user32”别名“ SendMessageA”(ByVal hWnd作为IntPtr,ByVal wMsg作为整数,ByVal wParam作为整数,ByVal lParam作为ErrorCall)作为整数

代替旧的:声明函数SendMessageP Lib“ user32”别名“ SendMessageA”(ByVal hWnd作为IntPtr,ByVal wMsg作为整数,ByVal wParam作为整数,ByVal lParam作为整数)作为整数

向lparam发送

addressof

回调例程的位置相关代码:

dim UseEvents as Boolean ' if UseEvents = True then write to rich text box using events and delegates Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Boolean, ByRef lParam As Integer) As Boolean Declare Function SendMessageP Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As ErrorCall) As Integer 'Define the public signature of our callback procedure... Public Delegate Sub ErrorCall(ByVal hWnd As IntPtr, ByVal iID As Integer, ByVal ipstrStatusText As String) Private Sub MyErrorCallback(ByVal hWnd As IntPtr, ByVal iID As Integer, ByVal ipstrStatusText As String) ' IDS_CAP_DRIVER_ERROR = 418 '/* Driver specific error message */ If iID = 0 Then Exit Sub If isRecording Then If UseEvents Then ' have to use a delegate to write to the info box RaiseEvent GotCallback(Me, "Callback Error " + iID.ToString() + ": " + ipstrStatusText, Color.Orange) Else ' record in a global variable LastError = "Callback Error " + iID.ToString() + ": " + ipstrStatusText End If Else showme("Callback Error " + iID.ToString() + ": " + ipstrStatusText, Color.Orange) End If End Sub Declare Function SendMessagePS Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As StatusCall) As Integer 'Define the signature of our callback procedure... Public Delegate Sub StatusCall(ByVal hWnd As IntPtr, ByVal iID As Integer, ByVal ipstrStatusText As String) Private Sub MyStatusCallback(ByVal hWnd As IntPtr, ByVal iID As Integer, ByVal ipstrStatusText As String) If iID = 0 Then Exit Sub If isRecording Then If iID = 511 Or iID = 512 Then ' show only the end of recording fps, lost frames and audio details If UseEvents Then ' have to use a delegate to write to the info box RaiseEvent GotCallback(Me, ipstrStatusText, Color.BlueViolet) Else ' Record in a global variable LastStatus = ipstrStatusText 'Debug.Print("Status " + iID.ToString() + ": " + ipstrStatusText) End If End If Else showme("Status " + iID.ToString() + ": " + ipstrStatusText, Color.BlueViolet) End If End Sub Public Const WM_CAP As Short = &H400S Public Const WM_CAP_SET_CALLBACK_ERROR = WM_CAP + 2 Public Const WM_CAP_SET_CALLBACK_STATUS = WM_CAP + 3 ' Call back initialisation: dim CbE,CbS as boolean ' showme is a helper routine to write to a rich text box Private Sub SetCallBacks() On Error Resume Next CbE = SendMessageP(hHwnd, WM_CAP_SET_CALLBACK_ERROR, 0, AddressOf MyErrorCallback) showme("Set Error callback " + CbE.ToString()) CbS = SendMessagePS(hHwnd, WM_CAP_SET_CALLBACK_STATUS, 0, AddressOf MyStatusCallback) showme("Set Status callback " + CbS.ToString()) Application.DoEvents() End Sub Private Sub StopCallbacks() Dim retval As Boolean On Error Resume Next showme("") If CbE Then retval = SendMessage(hHwnd, WM_CAP_SET_CALLBACK_ERROR, 0, vbNull) showme("Set Error Callback off " + Str(retval)) CbE = False End If If CbS Then retval = SendMessage(hHwnd, WM_CAP_SET_CALLBACK_STATUS, 0, vbNull) showme("Set Status Callback off " + Str(retval)) CbS = False End If Application.DoEvents() End Sub

如果将UseEvents设置为False并将反馈消息传输到全局变量,则会发生相同的崩溃。

我也尝试过将消息作为指针传递,但结果相同。

我已经使用avicap32.dll调用编写了一个Visual Basic .net桌面应用程序。在我录制视频时引入回调之前,这完全可以按预期工作。在...

vb.net video callback delegates
1个回答
0
投票
作为回调函数地址传递的参数丢失。这似乎是由于必须将委托声明为公共的结果。

我为回调设置了专用地址,以维护对回调委托的引用:

Private MyErrorAddress As New ErrorCall(AddressOf MyErrorCallback) Private MyStatusAddress As New StatusCall(AddressOf MyStatusCallback)

现在是回调设置子例程

Private Sub SetCallBacks() On Error Resume Next CbE = SendMessageP(hHwnd, WM_CAP_SET_CALLBACK_ERROR, 0, MyErrorAddress) CbS = SendMessagePS(hHwnd, WM_CAP_SET_CALLBACK_STATUS, 0, MyStatusAddress) Application.DoEvents() End Sub

这可能有助于希望为后台线程注册回调的其他人。
© www.soinside.com 2019 - 2024. All rights reserved.