Click here to Skip to main content
11,646,838 members (73,242 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: 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 14:26pm
Edited 6-Nov-12 1: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
0 510
1 Sergey Alexandrovich Kryukov 478
2 OriginalGriff 428
3 CPallini 334
4 F-ES Sitecore 309
0 OriginalGriff 1,253
1 994
2 DamithSL 896
3 Sergey Alexandrovich Kryukov 833
4 CPallini 720

Advertise | Privacy | Mobile
Web01 | 2.8.150731.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2015
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