#2
lianghong2018-02-16 23:49
|
'环境:Win10
'请大家一起找BUG!!!!
'mixerGetLineInfo一直返回错误11,我找不到原因,我反复检查了输入参数,没问题呀!
'下面是我的代码:
Imports System.Runtime.InteropServices
Public Class Form1
Private mhMixer As Integer
Private Const MMSYSERR_NOERROR = &H0
Private Const MMSYSERR_INVALPARAM = &HB '{一个或多个参数无效}
Private Const MIXER_GETLINEINFOF_COMPONENTTYPE = &H3
Private Const MIXERLINE_COMPONENTTYPE_DST_SPEAKERS = &H4
<StructLayoutAttribute(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
Structure MIXERLINE
Dim cbStruct As Integer
Dim dwDestination As Integer
Dim dwSource As Integer
Dim dwLineID As Integer
Dim fdwLine As Integer
Dim dwUser As Integer
Dim dwComponentType As Integer
Dim cChannels As Integer
Dim cConnections As Integer
Dim cControls As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=16)> _
Dim szShortName As String
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> _
Dim szName As String
Dim dwType As Integer
Dim dwDeviceID As Integer
Dim wMid As Short
Dim wPid As Short
Dim vDriverVersion As Integer
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)> _
Dim szPname As String
End Structure
Public Declare Function mixerOpen Lib "winmm.dll" _
(ByRef phmx As Integer, ByVal uMxId As Integer, ByVal dwCallback As IntPtr, _
ByVal dwInstance As Integer, ByVal fdwOpen As Integer) As Int32
Private Declare Function mixerGetLineInfo Lib "winmm.dll" _
Alias "mixerGetLineInfoA" (ByVal hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Int32) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call GetControlID()
End Sub
'取得Mixer控制的ID 如: Volume
Private Function GetControlID() As Boolean
Dim Ret As Integer
Dim MxrLine As New MIXERLINE
Ret = mixerOpen(mhMixer, 0, 0, 0, 0)
If Ret = MMSYSERR_NOERROR Then
MxrLine.cbStruct = Marshal.SizeOf(MxrLine)
MxrLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS '
Ret = mixerGetLineInfo(mhMixer, MxrLine, MIXER_GETLINEINFOF_COMPONENTTYPE)
If Ret = MMSYSERR_NOERROR Then
Return True
Else
If Ret = MMSYSERR_INVALPARAM Then Return False Else Return False '求原因
End If
End If
End Function
End Class