Solved

Fire event from DLL to calling EXE

Posted on 2006-06-13
7
390 Views
Last Modified: 2012-05-05
Hi

I'm a programming newbie that needs a little help with RaiseEvent.

I am calling an ActiveX DLL from an EXE app.  The DLL consists of a class and a form.  The EXE initiates the class in the DLL which shows the form.  My goal is to let the EXE know when the DLL is done.

My class exposes an event called DLLDONE.  I am able to trap this event in my EXE when the class (in the dll) raises the event before calling the form.  

My trouble comes after the form (in the DLL) is shown by the class: I tried the following > show the form which collects data from the user, performs processing and then calls a public sub the in the class that raises the event.  I found that doing it this way the event can be trapped in the form (in the DLL) but not in the exe.

Is there any way I can call the DLL class, show the DLL form and from there raise an event back to the EXE?

Hope I explained properly!
Thanks
0
Comment
Question by:PantoffelSlippers
  • 2
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16898420

try to use public event DLLDONE


and declare the class at the top withevents:

Dim WithEvents testclass As CustomClass

where CustomClass is an existing class, and testclass is the variable you should use to reference to it
0
 

Author Comment

by:PantoffelSlippers
ID: 16900283
Thanks Mark_FreeSoftware,

I will compare your suggestion with what I've got and get back to you ASAP.

Thanks
0
 
LVL 13

Expert Comment

by:Mark_FreeSoftware
ID: 16901137

ok,

some info for the next time:

>>My class exposes an event called DLLDONE.

if you explain things like this, it is a nice practise to give the code (or a part of it)
then it's easier to see what could be the problem for the experts



ps are you from nl?
0
 

Author Comment

by:PantoffelSlippers
ID: 16926749
Mark_FreeSoftware ,

Thanks for the tip

I've been able to answer my question for myself by playing around a bit but I'll explain what I was looking for anyway:

---------------
I have an EXE that calls a DLL in the following way:

Option Explicit
  Private WithEvents x As ProjectEvent.ClassEvent

Private Sub Command1_Click()
  Set x = New ProjectEvent.ClassEvent
  Call x.StartMe
End Sub

Private Sub x_DLLDONE()
  MsgBox "EventFired in EXE" 'I wanted to achieve this!
  Set x = Nothing
End Sub

-------------------------------------------------

The DLL has a class (ClassEvent) with public sub StartMe that shows a form.  In my experiment I only have a button on this form that needs to let the EXE know that the DLL has completed a certain task by raising an event called DLLDONE in the EXE.  Obvioulsy, one cannot raise the event from the form in DLL so I tried calling a sub in the class to raise the event but it didnt work.  I realised that the solution is easy : at the point where the code on the form should raise the event or call a sub in the class to raise the event, it just unloads the form which returns control back to the class that called the form and now the class can raise the event from there as follows:

'The class in the DLL
Option Explicit
  Public Event DLLDONE()
 
Public Sub StartMe()

  Form1.Show vbModal

  'adding the following two lines solved my problem - it will get executed when the form unloads itself.
  MsgBox "Event fired in DLL (class)"
  RaiseEvent DLLDONE

End Sub

'Calling this sub from the form doesnt work.
Public Sub FireTheEvent()
  MsgBox "Event fired on DLL class"
  RaiseEvent DLLDONE
End Sub
----------------------------------

Solving this little experiment helped me solve my problem in my real project.  Thanks for your response. I apologise if I explained poorly.

ps:  whats nl?
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 17337939
PAQ / Refund
ee ai construct, community support moderator
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now