?
Solved

Raising an Event in DLL and Traping that event in EXE

Posted on 2006-04-14
3
Medium Priority
?
291 Views
Last Modified: 2010-04-17
Hi,
I want to raise an event in ActiveX DLL and want to trap that event in a exe. This exe is calling that ActiveX DLL.
I am successful able to raise an event in ActiveX DLL but its not firing that event in Exe.
Kindly tell me why it is not working, or am I doing something wrong?
Any help will be highly appericiated.


Here is the code for my Project:
ActiveX DLL Name: CalledDLL(classes: CNotify,MyDLL. Form: FrmFromDLL.frm(form Has button: Lauch EXE's TestForm)
Exe Name : CallingEXE(FrmMain.frm,TestForm)

***EXE***
Form frmMain
--------------------------------------------

Private WithEvents objNotify As CalledDLL.CNotify

Private Sub cmdDLL_Click()

Dim objMyDLL As New CalledDLL.MyDLL
objMyDLL.ShowDLLForm
End Sub

Private Sub Form_Load()
Set objNotify = New CalledDLL.CNotify
End Sub

Public Sub objNotify_Notify(sMsg As String)
MsgBox sMsg
End Sub



***ActiveX DLL***
cNotify
--------------------------------------------
Option Explicit

Public Event Notify(ByRef Source As String)

Public Sub CallNotify(Source As String)
RaiseEvent Notify(Source)
End Sub

MyDLL
--------------------------------------------

Public Event MyEvent()
Private m_Client As New CNotify

Public Sub ShowDLLForm()
frmFormDLL.Show
End Sub

Public Sub TestCallback()
' Something that requires an "event"
If Not (m_Client Is Nothing) Then
m_Client.CallNotify ("fee")
Else
RaiseEvent MyEvent
End If
End Sub

frmFormDLL
--------------------------------------------
Public Event Notify(ByRef Source As String)

Private Sub cmdTest_Click()
CallNotify ("Test")
End Sub

Private Sub Form_Load()
'Set objNotify = New CNotify
End Sub

Public Sub CallNotify(Source As String)
RaiseEvent Notify(Source)
End Sub
0
Comment
Question by:hmnpa
  • 2
3 Comments
 
LVL 7

Accepted Solution

by:
jacobhoover earned 1300 total points
ID: 16472127
***EXE***
Form frmMain
--------------------------------------------

Option Explicit
Private WithEvents objNotify As CalledDLL.CNotify
Private objMyDLL As New CalledDLL.MyDLL
Private Sub cmdDLL_Click()
    objMyDLL.TestCallback
End Sub
Private Sub Form_Load()
    Set objNotify = objMyDLL.m_Notify
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set objNotify = Nothing
End Sub

Public Sub objNotify_Notify(sMsg As String)
    MsgBox sMsg
End Sub

***ActiveX DLL***
cNotify
--------------------------------------------
Option Explicit
Public Event Notify(ByRef Source As String)
Public Sub OnNotify(ByRef Source As String)
    RaiseEvent Notify(Source)
End Sub

MyDLL
--------------------------------------------

Public WithEvents m_Notify As CNotify

Public Sub ShowDLLForm()
    Dim frm As New frmFormDLL
    frm.m_Notify = Me.m_Notify
    frm.Show
End Sub

Public Sub TestCallback()
' Something that requires an "event"
If Not (m_Notify Is Nothing) Then
    m_Notify.OnNotify ("fee")
Else
RaiseEvent MyEvent
End If

End Sub

Private Sub Class_Initialize()
    Set m_Notify = New CNotify
End Sub

Private Sub Class_Terminate()
    Set m_Notify = Nothing
End Sub

frmFormDLL
--------------------------------------------
Option Explicit
Public WithEvents m_Notify As CNotify

Private Sub cmdTest_Click()
    m_Notify.OnNotify ("Test")
End Sub
0
 
LVL 7

Expert Comment

by:jacobhoover
ID: 16492564
hmnpa,
  did you try the above code?  Did you have any questions?
0
 

Author Comment

by:hmnpa
ID: 16537010
Sorry Jacobhoover, I had to travel so I could not respond earlier. The above code worked. Thanks very much. I am giving you the points.

Thanks and appreciate your help
hmnpa
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Simple Linear Regression
Six Sigma Control Plans

600 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