Const IID_Event_NetEvent = "{79823C92-F3CE-444A-946E-6F3872C56EAC}"'事件IID
Const IID_NetEvent = "{79823C92-F3CE-444A-946E-6F3872C56EAB}"'接口IID
Const CLSID_NetEvent = "{562625B2-58C1-43B8-A7B8-FD801CE8F0BB}"'组件CLSID
Const ProgID_NetEvent = "NetEvent"'组件ProID
DECLARE_EVENT_MAP(TestEvent ,IID_Event_NetEvent)'事件接口声明
Function myadd(ByVal v As VARIANT Ptr) As VARIANT
'COM组件方法(参数必须为variant ptr,实为variant()数组,返回值必须为variant类型)
dim vv as VARIANT
Raise_TestEvent.Run("xxx" ,123) '调用事件接口
MsgBox cobject("xxxx").ToString
Return vv
End Function
BEGIN_COM_MAP(NetEvent ,IID_NetEvent) '组件声明
BEGIN_EVENT_MAP(TestEvent)'事件接口入口
BEGIN_DISPATCH_MAP(NetEvent)'方法ID映射表声明
DISP_FUNCTION_ID(1 ,myadd)'方法ID映射声明
DECLARE_DISPATCH_MAP(NetEvent)'方法调用表声明
DISP_sub(1 ,myadd) END_DISPATCH_MAP() '调用方法
OBJECT_ENTRY(NetEvent ,ProgID_NetEvent ,CLSID_NetEvent)'Activex DLL入口函数
'OBJECT_ENTRY2(NetEvent ,ProgID_NetEvent ,CLSID_NetEvent)'Activex Exe入口函数
'DLL入口函数和Exe入口函数仅能选一种
'ROT(NetEvent ,CLSID_NetEvent)'非Activex程序com活动对象注册,Activex Exe已自带该宏无需重复使用
vb6使用:
Private Sub Command1_Click()
Dim o As Object
Set o = CreateObject("NetEvent")
o.myadd
End Sub
Private Sub Command2_Click() 'Activex Exe或使用ROT非Activex工程使用
Dim o As Object
Set o = GetObject(, "NetEvent")
o.myadd
End Sub