'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))
End Sub
End Class
'Anyone got an idea as to why?