unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

Type TXResult = Record
       FileSize : Integer;  // in byte
       FileCRC32: Cardinal; // Dec
       FileType : pchar;    // type + (ext)
       Extension: pchar;    // lowercase
       ReturnVal: pchar;    // a Return value: nil if everything is ok, an error message if something went wrong.
     End;

Const FileDet_Dll= 'FileDetector.dll';

var
  Form1: TForm1;
  Detect_File:function(Filename: Pchar): TXResult; stdcall;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
 var Handle  : Thandle;
     FileType: TXResult;
begin
  Handle:= LoadLibrary(pchar(FileDet_Dll)); {Get a handle for the dll}

  If Handle <> 0 then @Detect_File:= GetProcAddress(Handle, pchar('DetectFile')); {if we got a valid handle, get DetectFile function adress from the dll}

  If @Detect_File <> nil Then FileType:= Detect_File(Pchar(Edit1.Text)); {Check the function existance}

  If FileType.ReturnVal <> nil Then {Check the dll error report, if nil means everthing is ok}
   MessageBox(Form1.Handle, FileType.ReturnVal, Pchar('Error'), $00 or $10) {Error occured, So show the error message}
  Else {Everything goes OK}
   MessageBox(Form1.Handle,                 {Show the information}
                      Pchar('File Size: '+ IntToStr(FileType.FileSize Div 1024)+' KB'+#10+
                      'File CRC32: '+IntToHex(FileType.FileCRC32, 1)+#10+
                      'File Type: '+ FileType.FileType+#10+
                      'Extension: '+ FileType.Extension+#10),
                       Pchar('Result:'), $00 or $40);

  If Handle <> 0 Then FreeLibrary(Handle); {We finished, Free the dll handle}
end;

end.
