Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-26-2007, 04:37 PM
ChrisPepper1989 ChrisPepper1989 is offline
Newbie
 
Join Date: Dec 2006
Posts: 8
Credits: 0
Rep Power: 0
ChrisPepper1989 is on a distinguished road
Angry Strange DLL Error, creating controls

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;
                }


        }


}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange error in update app McMillan0520 C# Programming 1 08-08-2007 11:52 AM
Register Controls Anirban Chakraborty C and C++ 1 06-01-2007 10:48 AM


All times are GMT -5. The time now is 02:31 AM.

Contest Stats

Xav ........ 1322.18
MeTh0Dz|Reb0rn ........ 1053.7
morefood2001 ........ 879.43
John ........ 877.37
marwex89 ........ 869.98
WingedPanther ........ 830.24
Brandon W ........ 735.07
chili5 ........ 309.39
Steve.L ........ 239.84
dcs ........ 216.02

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 82%

Ads