Featured post
vb.net - Raising events in a class library exposed to COM -
i'm trying write wrapper service, used existing vb6 project. i've got of basic framework working, except 1 important aspect: can reference wrapper in vb6 project , subs/function calls etc. work expected, events not. events visible in vb6 app, never fire.
vb.net code:
public event action_response(byval status string) public function testevent() raiseevent action_response("test done") return "done" end function
vb6 code:
dim withevents my_wrapper wrapper_class private sub cmdtest_click() set my_wrapper = new wrapper_class debug.print my_wrapper.testevent() end sub private sub my_wrapper_action_response(byval status string) debug.print status set my_wrapper = nothing end sub
so, cmdtest button code prints 'done' expected, action_response event doesn't fire. there else need event fire?
its write in comment, i'll make answer....
first, identify .net class want expose com. i'll pick class called core.
create interface describes events core object source (ie generate).
<comvisible(true)> _ <guid("some guid here...use guidgen, i'll call guid1")> _ <interfacetype(cominterfacetype.interfaceisidispatch)> _ public interface icoreevents <system.runtime.interopservices.dispid(1)> _ sub fileloaded(byval message string) end interface
next, create interface com exposed properties , methods of class.
<comvisible(true)> _ <guid("another guid, i'll call guid2")> _ <interfacetype(cominterfacetype.interfaceisdual)> _ public interface icore readonly property property1() boolean readonly property anotherproperty() isettings readonly property name() string readonly property phone() string end interface
now, create actual .net class
<comvisible(true)> _ <classinterface(classinterfacetype.none)> _ <comdefaultinterface(gettype(icore))> _ <comsourceinterfaces(gettype(icoreevents))> _ <guid("a third guid, i'll call guid3")> _ public class core implements icore <system.runtime.interopservices.comvisible(false)> _ public delegate sub onfileloaded(byval message string) public event fileloaded onfileloaded end class
now, when need raise fileloaded event, raiseevent fileloaded(message) within class. .net forward event out com because you've hooked comsourceinterfaces attribute.
the attribute shorthand of of this, unfortunately doesn't give quite control need things (for instance retain version compatibility on com interfaces).
- Get link
- X
- Other Apps
Comments
Post a Comment