您链接的代码创建一个SWbemObjectSet,然后列出其成员(声音设备)的属性。从我所知道的,你想要那个对象,但不想列出属性(“输出”)。
如果这是正确的,创建一个函数删除输出语句,并返回SWbemObjectSet对象。
Public Function getSoundDevices(Optional strComputer As String = ".") As Object
Const cstrQuery As String = "Select * from Win32_SoundDevice"
Dim objWMIService As Object 'TypeName = SWbemServicesEx '
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set getSoundDevices = objWMIService.ExecQuery(cstrQuery, , 48)
Set objWMIService = Nothing
End Function
然后调用函数使用SWbemObjectSet输入您的其他代码。
Public Sub test_getSoundDevices()
Dim objSoundDevices As Object 'TypeName = SWbemObjectSet '
Dim objDevice As Object 'TypeName = SWbemObjectEx '
Set objSoundDevices = getSoundDevices()
For Each objDevice In objSoundDevices
'* do what you want for each sound device here *'
Debug.Print "ProductName: " & objDevice.ProductName
Next objDevice
Set objDevice = Nothing
Set objSoundDevices = Nothing
End Sub
我想不通为什么这么难!基本上,每一种做任何记录的软件都需要具有选择输入设备的功能。这确实没有什么不同。 – Icode4food 2011-03-31 11:58:49
是VB.Net(VB 9)中的声明吗? – Oneide 2011-03-31 12:39:06
它看起来不比任何Windows API调用困难。您应该感谢您使用开发平台,通过使用Windows API调用来扩展功能。我不知道任何可比较的数据库开发工具都可以做到这一点(与Access完全可比的唯一工具是FileMaker Pro和OpenOffice Base)。我有兴趣听到他们是否可以。 – 2011-04-02 02:17:27