Thread: linker error

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

    Join Date
    Nov 2003
    Location
    milan
    Posts
    14
    Rep Power
    0

    Unhappy linker error


    Hi! I'm tryin' to create a dll with BCB5 but I've some linking problems. These are the errors:

    [Linker Error] Unresolved external '__fastcall TForm2::KeyEvent(Messages::TWMKey&, bool&)' referenced from D:\DOCUMENTS AND SETTINGS\MATTEO\DESKTOP\NEW FOLDER\TRIGGER3SEC_SRC.OBJ
    [Linker Error] Unresolved external '_KeyPressed' referenced from D:\DOCUMENTS AND SETTINGS\MATTEO\DESKTOP\NEW FOLDER\TRIGGER3SEC_SRC.OBJ

    And this is the code:


    // trigger3sec_src


    //---------------------------------------------------------------------------
    #include <vcl.h>
    #include <windows.h>
    #pragma hdrstop

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

    #include <time.h>
    #include "Unit2.h"
    #pragma argsused
    time_t start;


    int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
    {
    Form2=new TForm2(NULL);
    Application->OnShortCut=Form2->KeyEvent;
    start=time(NULL);
    KeyPressed=false;
    return 1;
    }
    //---------------------------------------------------------------------------
    extern "C"
    {
    bool __export GetEvent()
    {
    bool ret=false;
    time_t now=time(NULL);
    if((now-start>3))//||(KeyPressed))
    {
    ret=true;
    start=time(NULL);
    // KeyPressed=false;
    }
    return ret;
    }
    }


    // Unit2.cpp


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

    #include <vcl.h>
    #pragma hdrstop

    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm2 *Form2;
    //---------------------------------------------------------------------------
    __fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall KeyEvent(Messages::TWMKey &Msg, bool &Handled)
    {
    if(Msg.CharCode == VK_ESCAPE)
    {
    KeyPressed=true;
    Handled = true;
    }
    }


    // Unit2.h


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

    #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(TComponent* Owner);
    void __fastcall KeyEvent(Messages::TWMKey &Msg, bool &Handled);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm2 *Form2;
    extern bool KeyPressed;
    //---------------------------------------------------------------------------
    #endif

    The program should change the Color of Form2 every 3 sec or if the key Esc is pressed.
    Anyone can help me, please?
    Sorry 4 my English!

    Comments on this post

    • Gran Roguismo agrees
  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
    See my reply to your thread on the C forum
    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

    Smile


    Thank you very much..now it works. As I thought,it was something of really stupid....but I'm a raw in c++!
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    milan
    Posts
    14
    Rep Power
    0

    Question


    Uhmmm…maybe I’m more stupid than I thought ‘cause it DOESN’T work…
    I’ve modified the code as follow:


    // trigger3sec_src


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

    #include <vcl.h>
    #include <windows.h>
    #pragma hdrstop
    //---------------------------------------------------------------------------

    #include <time.h>
    #include "Unit2.h"
    #pragma argsused
    time_t start;


    int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
    {
    Form2=new TForm2(NULL);
    Application->OnShortCut=Form2->KeyEvent;
    start=time(NULL);
    KeyPressed=false;
    return 1;
    }
    //---------------------------------------------------------------------------


    extern "C"
    {
    bool __export GetEvent()
    {
    bool ret=false;
    time_t now=time(NULL);
    if((now-start>3)||(KeyPressed))
    {
    ret=true;
    start=time(NULL);
    KeyPressed=false;
    }
    return ret;
    }
    }


    // Unit2.cpp


    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop

    #include "Unit2.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm2 *Form2;
    bool KeyPressed;
    //---------------------------------------------------------------------------
    __fastcall TForm2::TForm2(TComponent* Owner)
    : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall KeyEvent(Messages::TWMKey &Msg, bool &Handled)
    {
    if(Msg.CharCode == VK_ESCAPE)
    {
    KeyPressed=true;
    Handled = true;
    }
    }

    // Unit2.h


    //---------------------------------------------------------------------------
    #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(TComponent* Owner);
    void __fastcall KeyEvent(Messages::TWMKey &Msg, bool &Handled);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm2 *Form2;
    extern bool KeyPressed;

    //---------------------------------------------------------------------------
    #endif

    Now there is only one linker error:
    [Linker Error] Unresolved external '__fastcall TForm2::KeyEvent(Messages::TWMKey&, bool&)' referenced from D:\DOCUMENTS AND SETTINGS\MATTEO\DESKTOP\NEW FOLDER\TRIGGER3SEC_SRC.OBJ
    related to KeyEvent. The error related to KeyPressed desappeared.
    Any suggestion?
    Thanx!

IMN logo majestic logo threadwatch logo seochat tools logo