Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21301

MIDI receive User Control Callback problem

$
0
0
I'm trying to create a User Control that receives MIDI and then generates an event whenever MIDI is received. It's hacked from simple demos I've found online (which I know work). The problem is that I want the code to be in a User Control and not a module. Because the midiInOpen function uses a callback function, the callback function has to go into a module. This works fine, but how do I then get the data that arrives in the module, back to the user control.
Here's the code in the User Control:
Code:

Private Const CALLBACK_FUNCTION = &H30000
Private Declare Function midiInOpen Lib "winmm.dll" (lphMidiIn As Long, ByVal uDeviceID As Long, ByVal dwCallback As Any, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Private Declare Function midiInClose Lib "winmm.dll" (ByVal hMidiIn As Long) As Long
Private Declare Function midiInStart Lib "winmm.dll" (ByVal hMidiIn As Long) As Long
Private Declare Function midiInStop Lib "winmm.dll" (ByVal hMidiIn As Long) As Long
Private Declare Function midiInReset Lib "winmm.dll" (ByVal hMidiIn As Long) As Long
Private ri As Long
Public Sub StartMidiRecieve()
    Call StartMidiFunction(0) 'Choose different value for different midi interface
End Sub
Private Function StartMidiFunction(lngIndex As Long) As Boolean
    Call midiInOpen(ri, lngIndex, AddressOf MidiInProc, 0, CALLBACK_FUNCTION)
    Call midiInStart(ri)
End Function
Public Sub EndMidiRecieve()
    Call midiInReset(ri)
    Call midiInStop(ri)
    Call midiInClose(ri)
End Sub

and here's the Callback Function in the module:
Code:

Public Function MidiInProc(ByVal MidiInHandle As Long, ByVal Message As Long, ByVal Instance As Long, ByVal dw1 As Long, ByVal dw2 As Long) As Long
   
    '**** HOW DO I GET THIS DATA BACK TO THE USER CONTROL????
   
End Function

Thanks v much
Paul

Viewing all articles
Browse latest Browse all 21301

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>