大家一起找BUG,这个问题对我太顽固,三天没找到原因,求大神关注!!!

lianghong 2018-02-16 01:22:35
'环境:Win10 VB.net2008
'请大家一起找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
...全文
1434 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuliiii 2018-02-28
  • 打赏
  • 举报
回复
win7 2017没问题
minfugan 2018-02-26
  • 打赏
  • 举报
回复
我在网上找到的mixerOpen的定义,楼主可以试试把mixerOpen的声明改一下看看结果。先调用mixerOpen,再调用mixerGetLineInfo。 Public Declare Function mixerOpen Lib "winmm.dll" _ (ByRef phmx As Integer, ByVal uMxId As Integer, ByVal dwCallback As IntPtr, _ ByVal dwInstance As IntPtr, ByVal fdwOpen As Integer) As Int32
lianghong 2018-02-24
  • 打赏
  • 举报
回复
这是在win10 ,vb6.0中文版执行mixerGetLineInfo,不产生错误的截图,结构大小仍然是168:
lianghong 2018-02-24
  • 打赏
  • 举报
回复
多谢! minfugan,照你的修改,并测试了,我这里mixerGetLineInfo仍然返回不是0,0代表MMSYSERR_NOERROR,即无错误!,现在返回错误MMSYSERR_INVALFLAG = 10。照minfugan的修改:结构体MIXERLINE的大小由168变成172,不知道各位老师执行mixerGetLineInfo成功时,调试: MxrLine.cbStruct = Marshal.SizeOf(MxrLine) 时的结构大小是多少??我在win10 ,vb.net 2008速成版里的 MxrLine.cbStruct大小是168,没有成功过,但同是这台电脑,VB6.0 中MxrLine.cbStruct大小是168,mixerGetLineInfo执行不参生错误!下面是我的调试截图:
minfugan 2018-02-23
  • 打赏
  • 举报
回复
楼主,问题找到——结构体MIXERLINE中的变量dwUser定义错误,改为Dim dwUser As IntPtr就OK了。VS2005测试。
lianghong 2018-02-21
  • 打赏
  • 举报
回复
是声卡驱动的问题? 我的电脑声音播放都一直正常啊,按照 “秋的红果实”的代码改了,还是错误11,返回 :False ,截图如下:

清晨曦月 元老 2018-02-21
  • 打赏
  • 举报
回复
查了一些资料,可能是win7之类的有一些改动,具体什么改动不知道,手头没有WIN7,你可以自己看一看WIN7调用时使用的堆栈之类的内容然后改一下API声明。又或者,弄点简单的吧,项目——管理NuGet程序包,找一个第三方库。
lianghong 2018-02-21
  • 打赏
  • 举报
回复
@秋的红果实, 函数GetGetControlID只有mixerGetLineInfo执行正确 ,当它返回 0,即MMSYSERR_NOERROR=0 ,函数GetGetControlID返回true. 相反:mixerGetLineInfo发生其他任何错误情况下,包括错误11,函数GetGetControlID都返回False,。
秋的红果实 2018-02-21
  • 打赏
  • 举报
回复
奇怪了,既然返回错误11,怎么还会有返回false呢?
秋的红果实 2018-02-20
  • 打赏
  • 举报
回复
win10,vs2013也不出错 请尝试强类型转换,VB我记得好像是根据赋值 代码如下

Private Function GetControlID() As Boolean
    Dim Ret As Integer
    Dim MxrLine As New MIXERLINE

    Ret = mixerOpen(mhMixer, 0, 0, 0, 0)

    If Ret = CType(MMSYSERR_NOERROR, Integer) Then
        MxrLine.cbStruct = Marshal.SizeOf(MxrLine)
        MxrLine.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS  '

        Ret = mixerGetLineInfo(mhMixer, MxrLine, MIXER_GETLINEINFOF_COMPONENTTYPE)

        If Ret = CType(MMSYSERR_NOERROR, Integer) Then
            Return True
        Else
            If Ret = CType(MMSYSERR_INVALPARAM, Integer) Then Return False Else Return False '求原因

        End If
    End If

End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Call GetControlID()
    Dim result As Boolean
    result = GetControlID()
    MessageBox.Show("Execute result:" + result.ToString())


End Sub

我这里,返回是True,你的函数里,有2个地方都返回True,最好能细化
秋的红果实 2018-02-20
  • 打赏
  • 举报
回复
请尝试强类型转换,VB我记得好像是根据赋值 ==> 请尝试强类型转换,VB我记得好像是根据赋值确定类型 我这里,返回是True,你的函数里,有2个地方都返回True,最好能细化 ==> 我这里,返回是True,你的函数里,有2个地方都返回False,最好能细化
真相重于对错 2018-02-18
  • 打赏
  • 举报
回复
不懂vb.net 看着头疼 11错误的意思指 试图加载格式不正确的程序
lianghong 2018-02-16
  • 打赏
  • 举报
回复
另外,按照”清晨曦月 “的方法改了代码,同样返回,错误:11
lianghong 2018-02-16
  • 打赏
  • 举报
回复
这就奇怪了啊! 我在两台电脑上(不同配置)调试都返回错误 11,这个截图:
清晨曦月 元老 2018-02-16
  • 打赏
  • 举报
回复
win10 x64 vs2017测试 ret=0。 何不<StructLayoutAttribute(LayoutKind.Sequential, CharSet:=CharSet.Auto, Pack:=1)> <DllImport("winmm.dll", CharSet:=CharSet.Auto)> Private Shared Function mixerGetLineInfo(ByVal hmxobj As Integer, ByRef pmxl As MIXERLINE, ByVal fdwInfo As Int32) As Integer End Function
思考 2018-02-16
  • 打赏
  • 举报
回复
Vs 2008,也不出错啊,win7
思考 2018-02-16
  • 打赏
  • 举报
回复
Vs 2010,不出错

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧