Playing a MIDI file from a RES file.

How do you play a MIDI file from a .RES?
Code would be appreciated.
Who is Participating?
jfaylingConnect With a Mentor Commented:
Assuming you have a midi file stored in a resource under a CUSTOM folder then you would do the following:

    SaveFileFromRes 101, "CUSTOM", "C:\TEMPJ.MID"
    Me.MMControl1.filename = "C:\TEMPJ.MID"
    Me.MMControl1.DeviceType = "Sequencer"
    Me.MMControl1.Command = "open"
    Me.MMControl1.Command = "play"

Good Luck!!!!

Public Function SaveFileFromRes(vntResourceID As Variant, sType As String, sFileName As String) As Boolean
'FUNCTION: SaveFileFromRes   AUTHOR: Mike Dixon         '
'DATE:     July 23, 1997     '
'PURPOSE:  Loads a Custom Resource from the Resource    '
'          File and saves it to a file on the disk.     '
'RETURNS:  True if there were no errors, false if error '
'NOTES:    sType must match the resource type by case!  '
'          Assumes sFilename is a valid, writable file  '
Dim bytImage() As Byte ' Always store binary data in byte arrays!
Dim iFileNum As Integer 'Free File Handle

On Error GoTo SaveFileFromRes_Err

    SaveFileFromRes = True
    'Load Binary Data from Resource file
    bytImage = LoadResData(vntResourceID, sType)
    'Get Free File Handle
    iFileNum = FreeFile
    'Open the file and save the data
    Open sFileName For Binary As iFileNum
        Put #iFileNum, , bytImage
    Close iFileNum
    Exit Function
    SaveFileFromRes = False: Exit Function
End Function

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.