VB2010 Express Net MidiOutOpen错误 [英] VB2010 Express Net MidiOutOpen Error

查看:77
本文介绍了VB2010 Express Net MidiOutOpen错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

''当我注意到我愚蠢地使用ByVal lphMidiOut而不是ByRef时,以下问题已得到解决!!!!向所有人致歉.

``我对为什么该程序失败感到困惑

''The problem described below has now been solved when I noticed I had stupidly put ByVal lphMidiOut instead of ByRef !!!! Apologies to all.

''I am baffled as to why this program fails

Imports System.Runtime.InteropServices
Public Class Form1
    Declare Function midiOutOpen Lib "winmm.dll" Alias "midiOutOpen" _
        (ByVal lphMidiOut As Int32, ByVal uDeviceID As Int32, _
         ByVal dwCallback As Int32, ByVal dwInstance As Int32, _
         ByVal dwFlags As Int32) As Int32

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
                            Handles Me.Load
        Dim lpMO As Int32
        Dim rv As Int32 = midiOutOpen(lpMO, -1, 0, 0, 0)
        Debug.Print(CStr(rv))

        '''''  the above code returns error 11 (MMSYSERR_INVALPARAM) ?? '''''
        '''''           -1 is the uDeviceID for the MIDI_MAPPER         '''''
        '''''  It also fails for uDeviceID = 0 (my on-board sound card) '''''
    End Sub
End Class



为什么有人知道?



''Anyone got an idea as to why?

推荐答案

至少一个,第一个参数是错误的.它是指向句柄的指针,因此您需要为此传递一个out参数:
http://msdn.microsoft.com/zh-我们/library/windows/desktop/dd798476%28v=vs.85%29.aspx [http://www.pinvoke.net/search.aspx?search=midiOutOpen&namespace= [全部] [ ^ ].

对于VB.NET,不支持out参数传递方法(对此感到羞耻),因此改用ByRef. (区别纯粹是语法上的:ref参数应该在传递之前进行初始化,out不需要这样做,但是被调用的代码应该对其进行初始化,这在C#中也是必需的.)

—SA
At least one, first parameter is wrong. It''s a pointer to a handle, so you need an out parameter passing for this one instead:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd798476%28v=vs.85%29.aspx[^].

This should work:
http://www.pinvoke.net/search.aspx?search=midiOutOpen&namespace=[All][^].

For VB.NET, out parameters passing method is not supported (shame on it), so ByRef is used instead. (The difference is purely syntactic: ref parameter should be initialized before passing, out does not require that, but the called code is supposed to initialize it, which is also required — in C#.)

—SA


这篇关于VB2010 Express Net MidiOutOpen错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆