//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

typedef void TFeedbackFunc (BYTE);
typedef void __declspec(dllimport) TStringFunction (char *);
typedef void __declspec(dllimport) TInitFunc (TFeedbackFunc*);

TStringFunction *pOpen, *pExtract, *pAdd;
TInitFunc *pInit;
void Feed (BYTE Progress)
{
  Form1->ProgressBar1->Position=Progress;
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  HMODULE mod = LoadLibrary ((ExtractFilePath(ParamStr(0))+"extract.dll").c_str());
  if (mod != NULL)
  {
    pOpen = (TStringFunction*)GetProcAddress (mod, "_OpenArchive");
    pExtract = (TStringFunction*)GetProcAddress (mod, "_ExtractArchive");
    pAdd = (TStringFunction*)GetProcAddress (mod, "_AddFilesToExtract");
    pInit = (TInitFunc*)GetProcAddress (mod, "_InitFeedback");
    if (pInit == NULL || pOpen == NULL || pExtract==NULL || pAdd==NULL)
    {
      ShowMessage ("Îøèáêà");
      FreeLibrary (mod);
      return;
    }
    pInit (&Feed);
    pOpen (Edit1->Text.c_str());
    pAdd ("*.*");
    pExtract (Edit2->Text.c_str());
  }
  FreeLibrary (mod);
  ProgressBar1->Position=0;
}
//---------------------------------------------------------------------------
