Click here to Skip to main content
12,767,637 members (52,274 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
'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?
Posted 5-Nov-12 15:26pm
Updated 6-Nov-12 2:14am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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#.)


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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100