By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,321 Members | 1,909 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,321 IT Pros & Developers. It's quick & easy.

How to play a MIDI file in C# ?

P: n/a
I wrote following code:

using System.Runtime.InteropServices;
[DllImport("winmm.dll")]
public static extern int mciSendString(string lpstrCommand, string
lpstrReturnString,int uReturnLength,
int dwCallback);
[DllImport("winmm.dll")]
public static extern int mciGetErrorString(int errCode,string errMsg,uint
buflen);

private void btnPlay_Click(object sender, System.EventArgs e)
{
int r1,r2;
string s1,s2;
string Playingfile;
s1="";
s2="";

Playingfile=listBox1.SelectedItem.ToString();
r1=mciSendString("OPEN "+Playingfile+" TYPE Sequencer wait","",0,0);
r2=mciSendString("PLAY "+Playingfile,"",0,0);
mciGetErrorString(r1,s1,128);
mciGetErrorString(r2,s2,128);
MessageBox.Show("s1="+s1 +" s2="+s2+" r1="+r1.ToString()+"
r2="+r2.ToString());
}

The MessageBox shows s1 s2 are empty string, while r1=0 and r2=337.
I don't know what the return value 337 mean.
I just want to play a MIDI file in C#. any better way?
Waiting for reply. Thanks.
Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.