Dim maxDeviceNum As Integer = 10
Dim DeviceNameArray(maxDeviceNum - 1) As IntPtr
BRAC_EnumAudioCapture(DeviceNameArray(0), maxDeviceNum)
Dim i As Integer = 0
Do While (i < maxDeviceNum)
Dim tBytes As Byte()
Dim j As Integer = 0
While (Marshal.ReadByte(DeviceNameArray(i), j) <> 0)
ReDim Preserve tBytes(j)
tBytes(j) = Marshal.ReadByte(DeviceNameArray(i), j)
j += 1
End While
Dim DeivceName As String = Encoding.Default.GetString(tBytes)
Marshal.FreeHGlobal(DeviceNameArray(i))
i = i + 1
Loop
经过仔细比对发现原来是给的DEMO里面的函数声明出了问题
'注意:这里将CHAR**类型的参数lpDeviceName定义为引用传递的IntPtr类型,请注意这里传递回来的CHAR*指针所指缓冲区为函数在内部所分配,应注意手工释放该缓冲区,具体请参见相应SDK文档
'// 枚举本地音频采集设备
'BRAC_API DWORD BRAC_EnumAudioCapture(CHAR** lpDeviceName, DWORD& dwDeviceNum);
<DllImport(AnyChatSDKDLL, EntryPoint:="BRAC_EnumAudioCapture", CallingConvention:=CallingConvention.Cdecl)> _
Function BRAC_EnumAudioCapture(ByRef lpDeviceName As Integer, ByRef dwDeviceNum As Integer) As Integer
End Function
'注意:这里将CHAR**类型的参数lpDeviceName定义为引用传递的IntPtr类型,请注意这里传递回来的CHAR*指针所指缓冲区为函数在内部所分配,应注意手工释放该缓冲区,具体请参见相应SDK文档
'// 枚举本地视频采集设备
'BRAC_API DWORD BRAC_EnumVideoCapture(CHAR** lpDeviceName, DWORD& dwDeviceNum);
<DllImport(AnyChatSDKDLL, EntryPoint:="BRAC_EnumVideoCapture", CallingConvention:=CallingConvention.Cdecl)> _
Function BRAC_EnumVideoCapture(ByRef lpDeviceName As IntPtr, ByRef dwDeviceNum As Integer) As Integer
End Function