Helpful Information
 
 
Category: Delphi Programming
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!

See my reply to your thread on the C forum :)

Thank you very much..now it works. As I thought,it was something of really stupid....but I'm a raw in c++!

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!










privacy (GDPR)