delphimidisfx

Delphi - Make a Delphi program that Self-extract a MIDI file


I'm writing a program in Delphi 7, and I think in put a music to run in Background. So, I composed a song in .MIDI called Song.MID, now I want to put my Delphi program to self-extract(SFX) this song and execute, in the end of the program delete it. It's like write it in Hex, I think. How can I do it?


Solution

  • Create a new text file, and write: MIDI RCDATA 1.mid, save text file as MID.rc Then create a new text file, and write: brcc32 mid.rc, save it as "brcc.bat"

    run the brcc.bat, to convert *.rc file to *.res Move MediaPlayer to your form (the media player is on the "System"tab). Now copy this code to Your project:

    unit Unit1;
    
    interface
    
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, MPlayer;
    
    type
      TForm1 = class(TForm)
        mplayer: TMediaPlayer;
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    {$R mid.res}
    
    procedure TForm1.FormCreate(Sender: TObject);
    var
      stream:tresourcestream;
      tmp:string;
    begin
      try
        stream:=tresourcestream.Create(hinstance,'MIDI',RT_RCDATA);
        try
          setlength(tmp,300);
          setlength(tmp,GetTempPath(300,pchar(tmp)));
          tmp:=tmp+inttostr(hinstance)+'.mid';
          stream.SaveToFile(tmp);
        finally
          stream.free;
        end;
        mplayer.FileName:=tmp;
        mplayer.Open;
        mplayer.Play;
      except
      end;
    end;
    
    end.
    

    this is the easiest example. So, keygens use a special sound format - *.XM, the file is read into memory from a resource and played using libraries like FMOD (read more in internet)