Click here to Skip to main content
15,850,214 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
'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)

        '''''  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?
Updated 6-Nov-12 2:14am

1 solution

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:[^].

This should work:[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#.)

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900