尝试了一些API编程,遇到了AVICAP32.dll的capGetDriverDescription函数的问题:
Declare Function capGetDriverDescriptionA Lib "avicap32.dll" (ByVal wDriver As Short, _
ByVal lpszName As String, ByVal cbName As Integer, ByVal lpszVer As String, _
ByVal cbVer As Integer) As Boolean
据我所知,lpszName
参数是用于获取驱动程序描述的缓冲区,我在某处读到缓冲区应该作为引用类型(ByRef
而不是ByVal
)传递,当然它应该是引用,因为存储了我的信息从函数返回后需要。但在这个函数中,它是一个值类型,而且工作正常!即使我尝试将其更改为 ByRef 但应用程序没有运行!我缺少什么知识?这个缓冲区如何在传递值类型时存储我的信息?
这是代码调用函数以获取可用网络摄像头的方式:
Private Sub LoadDeviceList()
On Error Resume Next
Dim strName As String = Space(100)
Dim strVer As String = Space(100)
Dim bReturn As Boolean
Dim x As Integer = 0
Do
bReturn = capGetDriverDescriptionA(x, strName, 100, strVer, 100)
If bReturn Then
lst1.Items.Add(strName.Trim)
End If
x += 1
Application.DoEvents()
Loop Until bReturn = False
End Sub