Home All Groups Group Topic Archive Search About

Strange ActiveX-Exe behaviour

Author
7 Sep 2010 11:32 AM
Anders Jorgenson
I have an ActiveX exe and I am having a hard time to have it raise an event.

My problem is that the class of the ActiveX-Exe does not receive the
withevent from the form. Is that a known problem? What am I missing?

When I instantitate the ActiveX-Exe on a form I have the following code:

Option Explicit

Private WithEvents d As DeviceNotifier6.clsDeviceNotifier

Private Sub d_DeviceChanged()

     Stop

End Sub

Private Sub Form_Load()

     Set d = New DeviceNotifier6.clsDeviceNotifier

End Sub



The code of my ActiveX-Exe looks like this

'*** clsDeviceNotifier ****
Option Explicit

Public Event DeviceChanged()

Private WithEvents F As frmMain

Private Sub Class_Initialize()

     Set F = New frmMain
     Load F

End Sub

Private Sub Class_Terminate()

     Unload F

End Sub

Private Sub f_DeviceChanged()

     RaiseEvent DeviceChanged

End Sub

'*** frmMain.frm
Option Explicit

Private WithEvents cDevChange As clsDeviceChange

Public Event DeviceChanged()

Private Sub cDevChange_DevChangeInfo(ByVal Info As String)

    'This sub IS called

     lbDevInfo.AddItem Info

    'But this event is not received by the ActiveX-Exe's class
     RaiseEvent DeviceChanged

End Sub

Private Sub Form_Load()

    'all this works fine
     Set cDevChange = New clsDeviceChange

     Call cDevChange.Hook(Me)

End Sub

Private Sub Form_Unload(Cancel As Integer)

     Call cDevChange.Unhook(Me)

     Set cDevChange = Nothing

End Sub

Author
7 Sep 2010 2:03 PM
Mayayana
I think you want to change this:

Private Sub f_DeviceChanged()
   RaiseEvent DeviceChanged
End Sub

to this:

Friend Sub f_DeviceChanged()
   RaiseEvent DeviceChanged
End Sub

   Also, this may not be a problem, but it
seems risky and a case of poor design
to me that you've named both events
exactly the same -- in the class as well as
in the form. Since the form is
essentially internal I'd be inclined to name
that event something like FormDeviceChanged.



--
--
Show quoteHide quote
"Anders Jorgenson" <a.j***@lycos.com> wrote in message
news:eQHMMCoTLHA.620@TK2MSFTNGP06.phx.gbl...
|I have an ActiveX exe and I am having a hard time to have it raise an
event.
|
| My problem is that the class of the ActiveX-Exe does not receive the
| withevent from the form. Is that a known problem? What am I missing?
|
| When I instantitate the ActiveX-Exe on a form I have the following code:
|
| Option Explicit
|
| Private WithEvents d As DeviceNotifier6.clsDeviceNotifier
|
| Private Sub d_DeviceChanged()
|
|     Stop
|
| End Sub
|
| Private Sub Form_Load()
|
|     Set d = New DeviceNotifier6.clsDeviceNotifier
|
| End Sub
|
|
|
| The code of my ActiveX-Exe looks like this
|
| '*** clsDeviceNotifier ****
| Option Explicit
|
| Public Event DeviceChanged()
|
| Private WithEvents F As frmMain
|
| Private Sub Class_Initialize()
|
|     Set F = New frmMain
|     Load F
|
| End Sub
|
| Private Sub Class_Terminate()
|
|     Unload F
|
| End Sub
|
| Private Sub f_DeviceChanged()
|
|     RaiseEvent DeviceChanged
|
| End Sub
|
| '*** frmMain.frm
| Option Explicit
|
| Private WithEvents cDevChange As clsDeviceChange
|
| Public Event DeviceChanged()
|
| Private Sub cDevChange_DevChangeInfo(ByVal Info As String)
|
| 'This sub IS called
|
|     lbDevInfo.AddItem Info
|
| 'But this event is not received by the ActiveX-Exe's class
|     RaiseEvent DeviceChanged
|
| End Sub
|
| Private Sub Form_Load()
|
| 'all this works fine
|     Set cDevChange = New clsDeviceChange
|
|     Call cDevChange.Hook(Me)
|
| End Sub
|
| Private Sub Form_Unload(Cancel As Integer)
|
|     Call cDevChange.Unhook(Me)
|
|     Set cDevChange = Nothing
|
| End Sub
|
|
|
Author
7 Sep 2010 5:55 PM
Anders Jorgenson
Mayayana,

I have changed the sub to friend sub. I also renamed the one event.
But it is still not raised.

The sub

Friend Sub f_pDeviceChanged()

     Beep 1000, 500

    RaiseEvent DeviceChanged 'This does not work

End Sub

in the ActiveX-Exe is called, I here it from the Beep, but then the
event to the "outside world" is not raised or not received by the
outside world.

Any more ideas?
Author
7 Sep 2010 11:51 PM
Mayayana
| I have changed the sub to friend sub. I also renamed the one event.
| But it is still not raised.
|

Maybe it has to do with the order. In class
initialize you have:

  Set F = New frmMain
  Load F

You've set the object for events and then
load it. Again, I'm not certain that won't
work, but the way I do it is like this:

Load frmMain
Set F = frmMain

  It's hard to test your code as-is, but I have
done what you want to do and made it work.
But I'm also not clear on what you did. With
your new code sample you seem to be saying
the EXE is not raising the event, but before you
said the EXE was not receiving the form event.


Show quoteHide quote
| The sub
|
| Friend Sub f_pDeviceChanged()
|
|     Beep 1000, 500
|
|    RaiseEvent DeviceChanged 'This does not work
|
| End Sub
|
| in the ActiveX-Exe is called, I here it from the Beep, but then the
| event to the "outside world" is not raised or not received by the
| outside world.
|
| Any more ideas?
Author
8 Sep 2010 6:30 AM
Anders Jorgenson
Changing to this did not change anything:
>
> Load frmMain
> Set F = frmMain

>    It's hard to test your code as-is, but I have
> done what you want to do and made it work.
> But I'm also not clear on what you did. With
> your new code sample you seem to be saying
> the EXE is not raising the event, but before you
> said the EXE was not receiving the form event.

Yes. I don't know if the ActiveX exe is not raising the event or if it's
not received by the instantiating app.

I do know that this sub is called:

>
>
> | The sub
> |
> | Friend Sub f_pDeviceChanged()
> |
> |     Beep 1000, 500
> |
> |    RaiseEvent DeviceChanged 'This does not work
> |
> | End Sub

But the RaiseEvent DeviceChanged is either not send (by the ActiveX-exe)
or not received (by the instantiating application).

Any more ideas? How could I check if it's a) not being sent or b) not
being received?
Author
8 Sep 2010 7:15 AM
Anders Jorgenson
Private Sub cDevChange_DevChangeInfo(ByVal Info As String)

     'This sub IS called

     lbDevInfo.AddItem Info

     'But this event is not received by the ActiveX-Exe's class
     RaiseEvent DeviceChanged

End Sub

For some reason, this did not work.
But when I do this....


Private Sub cDevChange_DevChangeInfo(ByVal Info As String)

     'This sub IS called

     lbDevInfo.AddItem Info

     'But this event is not received by the ActiveX-Exe's class
     'RaiseEvent DeviceChanged

    Me.Timer1.Interval = 50
    Me.Timer1.Enabled = True

End Sub
Private sub Timer1_Timer()

    Me.Timer1.Enabled = False
    RaiseEvent DeviceChanged

End Sub

, it will work.

Why????? Why is the RaiseEvent in the cDevChange_DevChangeInfo ignored?
Author
9 Sep 2010 1:54 PM
Mayayana
| Why????? Why is the RaiseEvent in the cDevChange_DevChangeInfo ignored?
|

   I thought that maybe someone else would have
an idea about this, but I guess not. If you
don't get it then you might want to post a sample
project that shows the problem.
   You seem to have an event coming from
a custom control, that's picked up by a form, that
then fires an event that's picked up by a class.
It's hard for anyone else to test that scenario.
Author
10 Sep 2010 5:24 AM
Anders Jorgenson
Should I post a project? Would anybody download and test it?

Show quoteHide quote
> | Why????? Why is the RaiseEvent in the cDevChange_DevChangeInfo ignored?
> |
>
>     I thought that maybe someone else would have
> an idea about this, but I guess not. If you
> don't get it then you might want to post a sample
> project that shows the problem.
>     You seem to have an event coming from
> a custom control, that's picked up by a form, that
> then fires an event that's picked up by a class.
> It's hard for anyone else to test that scenario.
>
>
Author
10 Sep 2010 12:51 PM
Mayayana
| Should I post a project? Would anybody download and test it?
|

  If you do post it you should put it on a website
in a zip. And it shouldn't be a "code dump" of
what you're working on, but rather the simplest
possible demo that shows the problem in a
repeatable way. I'd look at it if I'm not too busy and
it's not too complex. I find ActiveX controls interesting.