• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

Fire event from DLL to calling EXE

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
PantoffelSlippers
Asked:
PantoffelSlippers
  • 2
  • 2
1 Solution
 
Mark_FreeSoftwareCommented:

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
 
PantoffelSlippersAuthor Commented:
Thanks Mark_FreeSoftware,

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

Thanks
0
 
Mark_FreeSoftwareCommented:

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
 
PantoffelSlippersAuthor Commented:
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
 
ee_ai_constructCommented:
PAQ / Refund
ee ai construct, community support moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now