' Listing 1 Declare Function midiOutOpen Lib "mmsystem" (handle As Integer, ByVal id As Integer, ByVal callback As Long, ByVal dwinstance As Long, ByVal flags As Long) As Integer Declare Sub midiOutClose Lib "mmsystem" (ByVal handle As Integer) Declare Function midiOutShortMsg Lib "mmsystem" (ByVal handle As Integer, ByVal message As Long) As Long Global hMidi As Integer Global istatus As Integer Global ichannel As Integer Global idata1 As Integer Global ldata2 As Long Global lmessage As Long ' Listing 2 Sub Form_Load () ' Try to open the default MIDI device. ErrCode = midiOutOpen(hmidi, -1, 0, 0, 0) ' Quit w/error if unable to. If ErrCode <> 0 Then st$ = "Error code " + Str$(ErrCode) MsgBox (st$) ', 16, "Error!") End Else ' Send the patch change ' for voice 25, the steel- ' string guitar in General MIDI. lmessage = &HC0 Or 0 Or (25 * 256) Or (0 * 65536) ic& = midiOutShortMsg(hmidi, lmessage) End If ' Set default values in the text boxes. ' This is the Note On message. text1.text = "&h90" ' This value isn't used for note on. text2.text = "0" ' Middle C. text3.text = "64" ' Maximum volume. text4.text = "127" End Sub ' Listing 3 Sub Form_Unload (Cancel As Integer) ' Close the MIDI device. This must be ' done; otherwise it can't be used until ' Windows is restarted. Call midiOutClose(hmidi) End Sub ' Listing 4 Sub Command1_Click () ' The 3 bytes of a MIDI message must be written to lmessage. lmessage = istatus Or ichannel Or (idata1 * 256) Or (ldata2 * 65536) ' Send the message to the hmidi device handle. ic& = midiOutShortMsg(hmidi, lmessage) End Sub ' Listing 5 Sub Command2_Click () ' Make sure you close the MIDI device handle ' before quitting VB. Call midiOutClose(hmidi) End End Sub ' Listing 6 Sub Text1_Change () ' This is the status byte portion ' of the MIDI message. ' Convert the value in the text ' box to an integer. istatus = Val(text1.text) End Sub ' Listing 7 Sub Text2_Change () ' This is the channel nybble of ' the status byte. ichannel = Val(text2.text) End Sub ' Listing 8 Sub Text3_Change () ' The first of 2 data bytes. ' Convert the value in the text ' box to an integer. idata1 = Val(text3.text) End Sub ' Listing 9 Sub Text4_Change () ' The second of 2 data bytes. ' Convert the value in the text ' box to an integer. ldata2 = Val(text4.text) End Sub