大家好!前几天刚到一家新公司,我参与的系统中是完全基于COM组件的开发,其中用到了大量的Connection Point方法,被逼无奈,只好抱一抱佛脚了,经过一段时间的学习,总算有了一些体会,来与大家分享一下,各位莫笑。
让我们用示例来说明:
COM服务器:
1.新建一个COM对象CA实现IA接口,利用向导来实现这一步。
2.添加IEvent接口的定义,并将它声明为COM对象A的外部接口(Outgoing Interface)
// 优快云.idl : IDL source for 优快云.dll
//
// This file will be processed by the MIDL tool to
// produce the type library (优快云.tlb) and marshalling code.
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(2EE8F461-7200-4C13-A2FC-2552F8773089),
dual,
helpstring("IA Interface"),
pointer_default(unique)
]
interface IA : IDispatch
{
[id(1), helpstring("method Init")] HRESULT Init();
};
[
object,
uuid(C5C88155-7CAB-4109-9610-234A6AD529DC),
dual,
helpstring("IEvent Interface"),
pointer_default(unique)
]
interface IEvent : IUnknown
{
[id(1), helpstring("method OnDataChanged")] HRESULT OnDataChanged();
};