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

    Join Date
    Nov 2003
    Location
    milan
    Posts
    14
    Rep Power
    0

    Unhappy still problems with linker error


    Hi! I'm tryin' to create a simple dll with an included module (Form7) with BCB5 but Iíve some linking problems.
    This is the code:
    PHP Code:
    // Mydll.cpp

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

    #include <vcl.h>
    #include <windows.h>
    #pragma hdrstop
    //---------------------------------------------------------------------------
    #include "Unit7.h"
    #pragma argsused
    int WINAPI DllEntryPoint(HINSTANCE hinstunsigned long reasonvoidlpReserved)
    {
    Form7=new TForm7(NULL);
    Application->OnShortCut=Form7->KeyEvent;
    KeyPressed false;
    return 
    1;
    }
    //---------------------------------------------------------------------------
    extern "C"
    {
    bool __export GetEvent()
            {
            
    bool ret=false;
            if (
    KeyPressed)
                    {
                    
    ret=true;
                    
    KeyPressed=false;
                    }
            return 
    ret;
            }
    }

    // Unit7.cpp

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

    #include <vcl.h>
    #pragma hdrstop

    #include "Unit7.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm7 *Form7;
    bool KeyPressed;
    //---------------------------------------------------------------------------
    __fastcall TForm7::TForm7(TComponentOwner)
            : 
    TForm(Owner)
    {
    }

    //---------------------------------------------------------------------------
    void __fastcall KeyEvent(Messages::TWMKey &Msgbool &Handled)
    {
    if(
    Msg.CharCode == VK_ESCAPE)
        {
            
    KeyPressed=true;
            
    Handled true;
        }
    }

    // Unit7.h

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

    #ifndef Unit7H
    #define Unit7H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    //---------------------------------------------------------------------------
    class TForm7 : public TForm
    {
    __published:    // IDE-managed Components
    private:    // User declarations
    public:        // User declarations
            
    __fastcall TForm7(TComponentOwner);
            
    void __fastcall KeyEvent(Messages::TWMKey &Msgbool &Handled);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm7 *Form7;
    extern bool KeyPressed;
    //---------------------------------------------------------------------------
    #endif 
    When I compile, everything itís OK, but Iíve this linker error:
    PHP Code:
    [Linker ErrorUnresolved external '__fastcall TForm7::KeyEvent(Messages::TWMKey&, bool&)' referenced from D:\DOCUMENTS AND SETTINGS\MATTEO\DESKTOP\PROVALADLL\MYDLL.OBJ 
    Iíve tried to change the position of the declaration of void __fastcall KeyEvent (I think this is the problem), but I still have errors of this kind.
    Anyone can help me, please?
    Bye,
    Castoro

    PS:Iíve forgot to say that the dll should simply return true if the key ďEscĒ has been pushed (without generating a OnKeyPress event Ė so using the OnShortCut event of TApplication), else return false in the other cases (generating a OnKeyPress event).
    Bye
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    In unit7.cpp, change this line:
    void __fastcall KeyEvent(Messages::TWMKey &Msg, bool &Handled)

    to this:
    void __fastcall TForm7::KeyEvent(Messages::TWMKey &Msg, bool &Handled)
    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
    Yes,this is the error. now my dll is well compiled and linked but still doesn't do what I need. If I use it in a simple program as:

    PHP Code:
    //---------------------------------------------------------------------------

    #include <vcl.h>
    #pragma hdrstop

    #include "Prova_src.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    FARPROC myfunc;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponentOwner)
            : 
    TForm(Owner)
    {
    HINSTANCE mylib LoadLibrary("trigger3sec.dll");
     if(
    mylib){
      
    myfunc GetProcAddress(mylib,"_GetEvent");
     }
    }
    //---------------------------------------------------------------------------

    void __fastcall TForm1::Timer1Timer(TObject *Sender)
    {
    if((
    myfunc) && myfunc()){
      if (
    Color==clBtnFaceColor=clRed;
      else 
    Color=clBtnFace;
     }
    }
    //--------------------------------------------------------------------------- 



    if I push the "Esc" key my dll doesn't respond with the Form7->KeyEvent as should do.
    It could be a problem due to the fictitious form (Form7) that I've decided to use??
    Is there a way to use an event in a dll without using this fictitious form?
    And in this case where I should declare this function in the dll?
    Thanks for your help, hoping u will have still some time to dedicate to my problem (and to understand my English,too;-))!
    Bye

IMN logo majestic logo threadwatch logo seochat tools logo