So in making a little music player I am trying to get a call back with the mcisendstring function so that I can move onto another song here is the relevant code I have tried

[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
public const int MM_MCINOTIFY = 0x3B9;
public void open(string File)
{
string Format = @"open ""{0}"" type MPEGVideo alias MediaFile";
string command = string.Format(Format, File);
mciSendString(command, null, 0, IntPtr.Zero);
}

public void play()
{
string command = "play MediaFile notify";
mciSendString(command, null, 0, this.Handle);
}
public void stop()
{
string command = "stop MediaFile";
mciSendString(command, null, 0, IntPtr.Zero);
}
public void Dispose()
{
string command = "close MediaFile";
}
protected override void WndProc(ref Message m)
{
if (m.Msg == MM_MCINOTIFY)
{
Dispose();
currentTrack++;
openSongFrom();
}
base.WndProc(ref m);
}
private void pictureBox4_Click(object sender, EventArgs e)
{
playingCD();
openSongFrom();
}
private void playingCD()
{
playingCDNode = masterList.Pop();
}
private void openSongFrom()
{
if (currentTrack < playingCDNode.CDData.trackListCD.Count)
{
open(playingCDNode.CDData.trackListCD[currentTrack].filePath);
play();
}
else
{
currentTrack = 0;
playingCDNode = masterList.Pop();
open(playingCDNode.CDData.trackListCD[currentTrack].filePath);
play();

}
}

It plays the first song fine and it sends the call back and it seems like its going to play the second but just nothing happens has anyone any suggestions?

I thought then about just creating the mp3player as an instantiable class and I could then just create a new one and let the old be garbage collected after every song BUT when it comes to mcsiSendString I dont know how to get it to send the call back to another object as the 4th parameter of the function is a handle and I dunno what fits there or how I can get it to work to do what I want.

Would it be a viable solution to have the call back call a delegate with a method which gets the other object to do the creation of anew mp3player object?

source