How do I implement an event in an Interface?

Is it possible in VB6.0 to implement events in an interface? I've got an ActiveX dll with a base class and an inherited class (ITest and test_1). I want the inherited class to be able to raise an event that is then handled by an event handler on my test form.

The code below gives me a run-time error '459' Object or class does not support the set of events.

Help!

' ITest
Public Event MyEvent()

Public Function DoSomething()
'
End Function

' test_1
Implements ITest

Public Event MyEvent()

Private Function ITest_DoSomething() As Variant
  RaiseEvent MyEvent
End Function

' form1
Private WithEvents myI As Project1.ITest

Private Sub Command1_Click()
  Set myI = New Project1.test_1
  myI.DoSomething
 
End Sub

Private Sub myI_MyEvent()
  MsgBox "done"
End Sub
SIMONJAsked:
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.

Da_WeaselSenior Software AnalystCommented:
Grabbed this from the MSDN.

"Important   The Implements feature does not support outgoing interfaces. Thus, any events you declare in the class module will be ignored."

Looks like 'Implements' ignores any outbound interfaces.  Which mean you either have to create events in each class or you have to create your own event system if you want to use something like this.  This requires you using subclassing, and various hooks depending on what you want to do.

"Create events in each class" method (best for simple systems with out complex requirements):
------------
ITest Class:
------------
Public Sub DoSomething()
'
End Sub
-------------
test_1 Class:
-------------
Implements ITest
Public Event MyEvent()
Public Sub ITest_DoSomething()
    RaiseEvent MyEvent
End Sub
-----------
Form1 Form:
-----------
Public WithEvents myTest As test_1
Private Sub Form_Load()
    Set myTest = New test_1
    myTest.ITest_DoSomething
End Sub
Private Sub myTest_MyEvent()
    MsgBox "What are you looking at!"
End Sub

"Create your own event system" method (best for complex systems that need event and handling):

xen:OS by k23 Productions is a great example of this.  Its available at www.xen-os.net in source and binary.  If you want to see a project that uses xen:OS then goto www.cloud9ine.com, we are currently developing iceFireXL and Cloud9ine using xen:OS.  All of these are open source via the GNU General Public Licence.
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
SIMONJAuthor Commented:
Thanks Da_Weasel, you confirmed my fear that this was not possible.

Wanted to write my own wrapper for different versions of Outlook.Application and I thought a common interface was the way to go, but if I can't handle the events with a common handler then I'm back to square one. I guess I could use callbacks instead...
0
Da_WeaselSenior Software AnalystCommented:
no a prob, good luck with that....
0
SIMONJAuthor Commented:
decided to go with MAPI in the end rather than automating Outlook. I'm still using an interface, but not bothering to handle events. The send method simply returns true or false depending on whether the user cancels the mail or sends.
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.