Solved

Fire event from DLL to calling EXE

Posted on 2006-06-13
7
399 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

717 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