1

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?

Adriano rox
  • 173
  • 1
  • 8
  • 2
    Add the file as a resource and then extract it with `TResourceStream`. Probably no need to save to file either. Just play it from memory. You might be able to give the player a URL that identifies the resource and extracts and then plays. – David Heffernan Nov 01 '15 at 16:05
  • @DavidHeffernan if I am not mistaken I don't think midi files can be played directly from a memory stream, at least not without some external multimedia library. – Craig Nov 01 '15 at 17:10
  • There's a way to play direct on memory? Like the Keygens do? – Adriano rox Nov 01 '15 at 17:33
  • 1
    @Victor Do you know what a resource is? What aspect of this are you stuck on? – David Heffernan Nov 01 '15 at 19:35

1 Answers1

3

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)

The North Star
  • 104
  • 1
  • 10