Playing Midi files with Turbo Pascal Windows

Hello

I have a TPW routine which allows me to play a MIDI file and is supposed to
start it again when it's over. My problem is that in fact it plays it until the end
but then it stops... Has anybody got an idea about why it doesn't work...?
I'd also like to include my MIDI file in a resource file, is there a way to avoid
calling a MCI function to load the file in memory... ? Thank you.

Here is the portion of source code I use.

{routine called at the beginning, to load and play the file}
var
    OpenS:TMCI_OPEN_PARMS;
    PlayS:TMCI_PLAY_PARMS;

begin
  MIDI:=true;
  OpenS.lpstrElementName:='my_midi.mid';
  mciSend(0,MCI_OPEN,MCI_OPEN_ELEMENT,LongInt(@OpenS));
  MIDI_DeviceID:=OpenS.wDeviceID;
  PlayS.dwCallBack:=HWindow;
  mciSend(MIDI_DeviceID,MCI_PLAY,MCI_NOTIFY,LongInt(@PlayS));
end;

Procedure TWindow.MCISend;
Var err:LongInt;
    errs:String;
Begin
 if (uDeviceID <> 0) or (uMessage=MCI_OPEN) Then
  Begin
   Err:=MciSendCommand(uDeviceID,uMessage,dwParam1,dwParam2);
   MciGetErrorString(err,@errs[1],256);
   if err <> 0 Then MessageBox(HWindow, @errs[1],'MCI error !', MB_ICONEXCLAMATION);
  End;
End;

{routine called by a mm_mciNotify command -- this is where I guess the error might be}
{called by virtual wm_First + mm_mciNotify}

Procedure TWindow.MMNotify(var Msg: TMessage);
{reacts to the end of the music}
Var PlayS:TMCI_PLAY_PARMS;
Begin
{HaltTimer;} {I don't think i need this...?}
 if Msg.lParam=MCI_NOTIFY_SUCCESSFUL Then Begin
        PlayS.dwCallBack:=HWindow;
        PlayS.dwFrom:=0;
        MciSend(MIDI_DeviceID,MCI_PLAY,MCI_NOTIFY or MCI_FROM,LongInt(@PlayS));
 End;
{InitTimer;}
End;

--
Rene-Gilles Deberdt (Naoki)
http://www.namida.com/
Free Mah Jongg Solitaire
Japanese animation
Manga and J-Rock