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


// Mydll.cpp

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

#include <vcl.h>
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#include "Unit7.h"
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
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(TComponent* Owner)
: TForm(Owner)
{
}

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

When I compile, everything it’s OK, but I’ve this linker error:

[Linker Error] Unresolved 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

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)

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:



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

#include <vcl.h>
#pragma hdrstop

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

void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if((myfunc) && myfunc()){
if (Color==clBtnFace) Color=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










privacy (GDPR)