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

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

typedef void (*pCreateChart)();
typedef int (*pAttach)(HWND hWnd);
typedef void (*pSetTitle)(wchar_t *title);
typedef int (*pAddPoint2D)(double x, double y, int nDataIndex, int nPlotIndex);
typedef bool (*pSetConfineRect)(RECT rect);
typedef void (*pReDraw)();

HMODULE hDLL = 0;

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------


void __fastcall TForm1::FormCreate(TObject *Sender)
{
    hDLL = LoadLibrary("CChartu.dll");
    if(hDLL)
    {
        pCreateChart CreateChart = pCreateChart(GetProcAddress(hDLL, "?CreateChart@Classless@@YAXXZ"));
        pAttach Attach = pAttach(GetProcAddress(hDLL, "?Attach@Classless@@YAHPAUHWND__@@@Z"));
        pSetTitle SetTitle = pSetTitle(GetProcAddress(hDLL, "?SetTitle@Classless@@YAXPB_W@Z"));
        pAddPoint2D AddPoint2D = pAddPoint2D(GetProcAddress(hDLL, "?AddPoint2D@Classless@@YAHNNHH@Z"));
        pSetConfineRect SetConfineRect = pSetConfineRect(GetProcAddress(hDLL, "?SetConfineRect@Classless@@YA_NUtagRECT@@@Z"));

        if(!CreateChart || !Attach || !SetTitle || !AddPoint2D || !SetConfineRect)return;

        CreateChart();
        Attach(Form1->Handle);
        for(int i=-10; i<=10; i++)
        {
            AddPoint2D(i, i*i, 0, 0);
        }
        SetTitle(L"C++ Builder±êÌâ");
    }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormDestroy(TObject *Sender)
{
    if(hDLL)
    {
        FreeLibrary(hDLL);
    }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormResize(TObject *Sender)
{
    if(hDLL)
    {
        pReDraw ReDraw = pReDraw(GetProcAddress(hDLL, "?ReDraw@Classless@@YAXXZ"));
        if(!ReDraw)return;
        ReDraw();
    }
}
//---------------------------------------------------------------------------

