可以在控件的IDL文件中编写代码,见彩色部分代码。
import "oaidl.idl";
import "ocidl.idl";
[
object,
uuid(A0A2E087-0A96-4861-BED2-549F9A0AC2C2),
dual,
nonextensible,
helpstring("IHLMessage Interface"),
pointer_default(unique)
]
interface IHLMessage : IDispatch{
//在方法中使用枚举
[id(1), helpstring("method A")] HRESULT A([in] enum HL_MSG_STYLE style);
[id(2), helpstring("method B")] HRESULT B([in] LONG i);
};
[
uuid(5181C89F-A37F-4632-8241-92F152A8D426),
version(1.0),
helpstring("ActiveX for HuaLong Message Component 1.0")
]
library HuaLongALib
{
importlib("stdole2.tlb");
//定义枚举
enum HL_MSG_STYLE
{
HL_MSG_INFOMATION = 0,
HL_MSG_ERROR = 1
} ;
[
uuid(D8EC72C0-6018-4572-88C2-AC9D2F3873AC),
helpstring("_IHLMessage Event Interface")
]
dispinterface _IHLMessageEvents
{
properties:
methods:
//在事件中使用枚举
[id(1), helpstring("Event OnA")] HRESULT OnA([in] enum HL_MSG_STYLE style);
};
[
uuid(414A7FDA-F1C4-438F-98D0-abA598827D7F),
helpstring("HLMessage Class")
]
coclass HLMessage
{
[default] interface IHLMessage;
[default, source] dispinterface _IHLMessageEvents;
};
};