Solved

Fire event from DLL to calling EXE

Posted on 2006-06-13
7
391 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 55
how can i unlock a picture file that was loaded in a picturebox in visual c#? 4 85
Run code from text file in vb 1 56
Hide vba in gp 7 82
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 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

21 Experts available now in Live!

Get 1:1 Help Now