Raising an Event in DLL and Traping that event in EXE

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
hmnpaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jacobhooverCommented:
***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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jacobhooverCommented:
hmnpa,
  did you try the above code?  Did you have any questions?
0
hmnpaAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.