I've created a new boilerplate project, pasted and ammended your code. This works - and loops:
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Shown += new EventHandler(Form1_Shown);
}
void Form1\_Shown(object sender, EventArgs e)
{
DoPlay();
}
private const int MM\_MCINOTIFY = 0x3B9;
\[DllImport("winmm.dll")\]
private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, uint uReturnLength, IntPtr hwndCallback);
public bool PlayMidiFile(string midiFile)
{
if (File.Exists(midiFile))
{
mciSendString("stop midi", string.Empty, 0, IntPtr.Zero);
mciSendString("close midi", string.Empty, 0, IntPtr.Zero);
mciSendString("open sequencer!" + midiFile + " alias midi", string.Empty, 0, IntPtr.Zero);
int rtn = mciSendString("play midi notify", string.Empty, 0, this.Handle);
return (rtn == 0);
}
else
return false;
}
void DoPlay()
{
PlayMidiFile(@"C:\\Windows\\Media\\town.mid");
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == MM\_MCINOTIFY)
DoPlay();
}
}
}
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)