im linking to a DLL that i want to create a control on the form, ive managed to get it to work in test programs without any problems but for some reason in my actual program, the button that im trying to create doesnt show up. i find this wierd as there is no obvious differences between the test program and mine, its the same code, it has the approach the same process, the same DLL, it just makes no sense. There was a time when i could make the button appear on the form but clicking the button ran no function, but i know it has a function because a.) it works in the test program and b.) i run it when the button is first created using ->Click(). At the moment though the button doesnt show up at all! Anyone got any ideas?
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!
Code:
//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);
cl*** 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;
//***ign 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
{
//***ign 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;
}
}
}