#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    milan
    Posts
    14
    Rep Power
    0

    Question using event in DLL


    HI!
    I'm doing my work of thesis on a c++ project using C++ Builder 5.
    My tutor has obliged me to do a thing (that I've had yet in a simpler way) using a DLL.
    Here come the problems.
    In fact in a common application like this:

    PHP Code:
    __fastcall TForm1::TForm1(TComponentOwner
    TForm(Owner

    Application->OnShortCut Key

    void __fastcall TForm1::KeyEvent(TWMKey &Msgbool &Handled

    if (
    Msg.CharCode == VK_RETURN

    ShowMessage("Enter disabled"); 
    Handled true


    , I'm able to use the command Application->OnShortCut. And the application does what required (the message is displayed).
    Instead if I try to do a similar thing using a DLL, everything is harder (actually too hard for me).
    In fact I think it's not possible to use a declaration like
    void __fastcall TForm1::KeyEvent(TWMKey &Msg, bool &Handled)
    in the body of the DLL, because of the fact that I cannot declare it anywhere (there isn't a header file to do this like in common applications).
    So to avoid this problem I decided to add to my DLL a fictitious Form (Form2) where I declared the event KeyEvent: in the main body of the DLL I used the command Application->OnShortCut=Form2->KeyEvent.
    According to me, everything should work, but it seems that the pushing of the key is not recognized. But I don't know why.

    PHP Code:

    //---------------------------------------------------------------------------
    /* Unit1.cpp ----it's the body of the DLL*/
    #include <vcl.h>
    #include <windows.h>
    #pragma hdrstop
    //---------------------------------------------------------------------------
    #pragma argsused
    #include "Unit2.h"
    int WINAPI DllEntryPoint(HINSTANCE hinstunsigned long reasonvoidlpReserved)
    {
            
    Form2 = new TForm2(NULL);
            
    Application->OnShortCut Form2->KeyEvent;
            return 
    1;
    }
    //---------------------------------------------------------------------------
    extern "C"
    {
    bool __export GetEvent()
            {
            
    bool ret false;
            if (
    come == true)
                    {
                    
    ret=true;
                    }
            return 
    ret;
            }
    }


    /* Unit2.h ------ it's the header file of Form2 */


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

    #ifndef Unit2H
    #define Unit2H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------

    class TForm2 : public TForm
    {
    __published:    // IDE-managed Components
    private:    // User declarations
    public:        // User declarations
            
    __fastcall TForm2(TComponentOwner);
            
    void __fastcall TForm2::KeyEvent(Messages::TWMKey &Msgbool &Handled);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm2 *Form2;
    extern bool come;
    //---------------------------------------------------------------------------
    #endif


    /* Unit2.cpp */


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

    #include <vcl.h>
    #pragma hdrstop

    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm2 *Form2;
    bool come;
    //---------------------------------------------------------------------------
    __fastcall TForm2::TForm2(TComponentOwner)
            : 
    TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm2::KeyEvent(Messages::TWMKey &Msgbool &Handled)
    {
    if (
    Msg.CharCode==VK_RETURN)
    come=true;
    else
    come=false;


    This simple application should return true if the RETURN key has been pushed, false in the other cases.
    Any ideas?
    Thanx
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,607
    Rep Power
    4247
    Try showing your form?
    Code:
    int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
    {
            Form2 = new TForm2(NULL);
            Application->OnShortCut = Form2->KeyEvent;
            Form2->Show();
            return 1;
    }
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    milan
    Posts
    14
    Rep Power
    0
    The problem wasn't due to the showing of the form but to the unchecked option "Build with runtime packages" in Projects|Options|Packages.
    Thanx 4 your help!

IMN logo majestic logo threadwatch logo seochat tools logo