> If you know how to develop such application please put here complete
source code. I think it will be VERY helpful for beginners like me and
for next generations ;)
I think I have found the solution, see below soure files in bcb6.
############ dll.cpp ###################
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include "MainUnit.h"
#pragma hdrstop
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
class TriangleShape : public AbstractPolygonShape
{
public:
TriangleShape(){};
~TriangleShape(){};
virtual char* GetShapeName();
virtual char* GetShapeName2();
};
char* TriangleShape::GetShapeName()
{
return "triangle1";
}
char* TriangleShape::GetShapeName2()
{
return "triangle2";
}
extern "C" __declspec(dllexport)
void* __stdcall RegisterShape()
{
return (new TriangleShape());
}
############ END - dll.cpp #################
############ MainUnit.h ####################
//---------------------------------------------------------------------------
#ifndef MainUnitH
#define MainUnitH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
class AbstractPolygonShape
{
public:
AbstractPolygonShape(){};
~AbstractPolygonShape(){};
virtual char* GetShapeName() = 0;
virtual char* GetShapeName2() = 0;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
############ END MainUnit.h ####################
############ MainUnit.cpp ##################
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "MainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
typedef void* (__stdcall *REGFUNCADDR)();
HINSTANCE DllInstance;
REGFUNCADDR regFunc;
AbstractPolygonShape *thisShape;
DllInstance = ::LoadLibrary("dll.dll");
if(DllInstance)
{
regFunc = (REGFUNCADDR) GetProcAddress(DllInstance, "RegisterShape");
if(regFunc)
{
thisShape = (AbstractPolygonShape *) regFunc();
}
if(thisShape)
{
char* ThisShapeName =thisShape->GetShapeName();
char* ThisShapeName2=thisShape->GetShapeName2();
ShowMessage((AnsiString)ThisShapeName);
ShowMessage((AnsiString)ThisShapeName2);
delete thisShape;
}
FreeLibrary(DllInstance);
}
}
//---------------------------------------------------------------------------
############ END - MainUnit.cpp ##############