Any help would be greatly appreciated ive been pulling out my hair for weeks on this one!
ive posted the code bellow for reference, i think the problem is with the bodge i have used to create an OnClick function for the button any ideas on how to clean this up would be great, i know it has something to do with the __closure typedef but im not sure what!
//functions in the DLL
void CreateTheControls(TWinControl* SentPanel)
{
// Button1->Handle = SentPanel->Handle;
Button1 = new TButton(SentPanel);
Button1->ParentFont = false;
Button1->Parent = SentPanel;
Button1->Left = 10;
Button1->Caption = "Pause";
Button1->Name = "TheButton";
Button1->Width = 100;
Button1->Height = 50;
Button1->Top = 50;
Button1->Visible = true;
Button1->Enabled = true;
Button1->OnClick = prog->TheButtonClick;
Button1->Click();
}
void __fastcall aProgram::TheButtonClick(TObject *Sender)
{
Pause = !Pause;
ShowMessage("Hello");
}
//dll header
extern "C"
{
__declspec(dllexport)void SetTheHDC(HDC sentHDC);
__declspec(dllexport)void Render();
__declspec(dllexport)void CreateTheControls(TWinControl *SentPanel);
class aProgram : public TObject //this is the bodge that i dont like
{
__published:
void __fastcall TheButtonClick(TObject *Sender);
private:
public:
};
aProgram *prog = new aProgram;
}
void DrawShapes();
bool Pause;
TButton *Button1;
//this is the RunDLL function in the program:
void __fastcall TActiveTutorialForm::RunDLL()
{
//load in libary libary
dllhandle = LoadLibrary("MakeDllProjectFile.dll");//this->ActiveDllString.c_str());
if(!dllhandle)
{
ShowMessage("Unable to load DLL :-(, try again");
}
else
{
bool Abort = false;
//assign functions from DLL to functions created here
Render = (RENDER)GetProcAddress(dllhandle, "_Render");
SetHDC = (SETHDC)GetProcAddress(dllhandle, "_SetTheHDC");
CreateControls = (CREATECONTROLS)GetProcAddress(dllhandle, "_CreateTheControls");
Initialize = (INITIALISE)GetProcAddress(dllhandle, "_Initialize");
MouseMoveFunc = (MOUSEMOVE)GetProcAddress(dllhandle, "_MouseMove");
if(!Render)
{
Application->MessageBoxA("Render Function Doesnt Exist in dll file, aborting", "Fatal Error", MB_OK);
Abort = true;
}
if(!SetHDC)
{
Application->MessageBoxA("SetHDC Function Doesnt Exist in dll file, aborting", "Fatal Error", MB_OK);
Abort = true;
}
if(Abort)
{
return;// false;
}
else
{
//assign other possible functions
// this->OnKeyDown = (ONKEYDOWN)GetProcAddress(dllhandle, "_OnKeyDown"); //???
//finalise and activate
//ready application for openGL
hdc = GetDC(Handle);
SetPixelFormatDescriptor();
hrc = wglCreateContext(hdc);
if(hrc == NULL)
ShowMessage("hrc == NULL, sorry! try again");
if(wglMakeCurrent(hdc, hrc) == false)
ShowMessage("Could not MakeCurrent, sorry! try again");
width = this->OpenGlPanel->Width;
height = ClientHeight +(this->Height - (this->OpenGlPanel->Height));
this->FormStyle = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
glClearColor(0.0f,0.0f,0.0f,0.0f);
glEnable(GL_DEPTH_TEST);
//begin the openGL-DLL application
SetHDC(hdc);
if(Initialize)
{
Initialize();
}
if(CreateControls)
{
CreateControls(this->ControlsInExamplePanel);
}
Application->OnIdle = IdleLoop;
FormResize(NULL);
Disabled = false;
}
}
}


Sign In
Create Account

Back to top









