Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 17th, 2003, 11:39 AM
teo.castoro teo.castoro is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: milan
Posts: 14 teo.castoro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old November 18th, 2003, 03:59 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,495 Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level)Scorpions4ever User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 18 h 41 m 36 sec
Reputation Power: 857
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

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
  #3  
Old November 24th, 2003, 09:01 AM
teo.castoro teo.castoro is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Location: milan
Posts: 14 teo.castoro User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > using event in DLL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway