组件对象模型与ATL实现
2010-09-04 20:48:02 来源:WEB开发网第三步 添加其他对象
这些对象都是ATL简单类型。名称为:Layers、Layer、Shapes、Shape。除了选择支持ISupportErrorInfo,其他都是采取默认设置。最后,手动修改类型库,修改后的IDL如下:
// MapLib.idl : MapLib 的IDL 源
//
// 此文件将由MIDL 工具处理以
// 产生类型库(MapLib.tlb)和封送处理代码。
#include "olectl.h"
import "oaidl.idl";
import "ocidl.idl";
[
uuid(C8C046AB-3D44-45EF-B11C-C5822862049A),
version(1.0),
helpstring("MapLib 1.0 类型库")
]
library MapLibLib
{
importlib("stdole2.tlb");
// 预先声明
interface ICanvas;
interface ILayers;
interface ILayer;
interface IShapes;
interface IShape;
[
object,
uuid(A74C036D-B046-4F53-B53A-F8EF611F576D),
dual,
nonextensible,
helpstring("ICanvas 接口"),
pointer_default(unique)
]
interface ICanvas : IDispatch{
[propput, bindable, requestedit, id(DISPID_BACKCOLOR)]
HRESULT BackColor([in]OLE_COLOR clr);
[propget, bindable, requestedit, id(DISPID_BACKCOLOR)]
HRESULT BackColor([out,retval]OLE_COLOR* pclr);
[propput, bindable, requestedit, id(DISPID_APPEARANCE)]
HRESULT Appearance([in]short nAppearance);
[propget, bindable, requestedit, id(DISPID_APPEARANCE)]
HRESULT Appearance([out, retval]short* pnAppearance);
};
[
object,
uuid(874C2033-17F1-4534-BAB3-8F0367C45D14),
dual,
nonextensible,
helpstring("ILayers 接口"),
pointer_default(unique)
]
interface ILayers : IDispatch{
};
[
object,
uuid(8D7872CF-9D97-4C4D-A26F-2BBEC59B7CB6),
dual,
nonextensible,
helpstring("ILayer 接口"),
pointer_default(unique)
]
interface ILayer : IDispatch{
};
[
object,
uuid(E374F693-C4B3-49E7-948D-10C38C170DF7),
dual,
nonextensible,
helpstring("IShapes 接口"),
pointer_default(unique)
]
interface IShapes : IDispatch{
};
[
object,
uuid(C576412D-69D0-42A8-AA96-FFD534472C0C),
dual,
nonextensible,
helpstring("IShape 接口"),
pointer_default(unique)
]
interface IShape : IDispatch{
};
[
uuid(BC3D7FCC-C1AE-4476-A59C-431457A1173C),
control,
helpstring("Canvas Class")
]
coclass Canvas
{
[default] interface ICanvas;
};
[
uuid(155C20C5-F3A0-47D7-AC5E-EB3F31EF3AD1),
helpstring("Layers Class")
]
coclass Layers
{
[default] interface ILayers;
};
[
uuid(F6543476-E5D9-4CC0-84B4-DD772D555686),
helpstring("Layer Class")
]
coclass Layer
{
[default] interface ILayer;
};
[
uuid(754A7947-8EDD-4B81-8522-9AF6B35F290D),
helpstring("Shapes Class")
]
coclass Shapes
{
[default] interface IShapes;
};
[
uuid(DE163AAE-62CF-46D7-956C-5884685DE634),
helpstring("Shape Class")
]
coclass Shape
{
[default] interface IShape;
};
};
到目前为止,我们已经把需要的ATL类添加到类型库(MapLib.dll)中,编译全部通过。这样,基本的对象全都有了,对象模型初步建立OK。
更多精彩
赞助商链接