Home All Groups Group Topic Archive Search About

How to expose vb.net events to Vb6?

Author
7 Feb 2006 7:43 AM
Frank Rizzo
Hello, how can I expose events in a vb.net class to a vb6 client?

'Here is the vb.net code
<GuidAttribute("1b08d99b-cb12-420e-bb47-4ec73795bd9c")> _
<ClassInterface(ClassInterfaceType.AutoDual)> _
public Class DotNetClass
    Public Event GenericEvent(ByVal EventName As String)

    public sub new()
    end sub

    public sub test()
        RaiseEvent GenericEvent("test")
    end sub
end class


'Here is the vb6 code
private withevents oDotNet as DotNetClass

I get an error here saying that 'Object does not source automation events'

What am I missing here?
Thanks

Author
7 Feb 2006 11:46 AM
Ken Tucker [MVP]
Hi,

        Mark the class and its methods as comvisible.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicescomvisibleattributeclasstopic.asp

Ken
----------------
Show quoteHide quote
"Frank Rizzo" <fri***@notn.com> wrote in message
news:OmMPmo7KGHA.1760@TK2MSFTNGP10.phx.gbl...
> Hello, how can I expose events in a vb.net class to a vb6 client?
>
> 'Here is the vb.net code
> <GuidAttribute("1b08d99b-cb12-420e-bb47-4ec73795bd9c")> _
> <ClassInterface(ClassInterfaceType.AutoDual)> _
> public Class DotNetClass
> Public Event GenericEvent(ByVal EventName As String)
>
> public sub new()
> end sub
>
> public sub test()
> RaiseEvent GenericEvent("test")
> end sub
> end class
>
>
> 'Here is the vb6 code
> private withevents oDotNet as DotNetClass
>
> I get an error here saying that 'Object does not source automation events'
>
> What am I missing here?
> Thanks