首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 开源 FAQ 第二书店 博文视点 程序员
频道: 研发 数据库 中间件 信息化 视频 .NET Java 游戏 移动 服务: 人才 外包 培训
    图书品种:235680
       
热门搜索: ASP.NET Ajax Spring Hibernate Java

Visual Basic 6 Clients

Visual Basic 6客户端

Visual Basic 6基于COM技术,所以它可以用来编写示范一个访问我们服务组件的COM客户端。

在注册了服务组件之后,你可以用VB6编写一个客户端。为示范起见,一个简单的标准EXE应用程序就可以了。你需要引用regsvcs.exe生成的类型库CourseManagement.tlb。regsvcs.exe同时会在COM+目录内配置我们的组件和把COM注册信息写到注册表中。在VB6中,接口的名称是由类型库的名称和接口CourseManagement.ICourseManagement的名称组成的。定义了变量oCourseManagement后(见代码段4-9),你可以创建COMInteropDemo.CourseManagement类的新对象。这样你可以使用oCourseManagement对象的GetCourse方法来获取一个序列化过的对象并传递到客户端,也可以通过GetCustomerControl方法得到对另外一个企业服务组件对象的引用。

代码段4-9  Visual Basic 6客户端

Dim oCourseManagement As COMInteropDemo.ICourseManagement

Set oCourseManagement = New COMInteropDemo.CourseManagement

' get a serialized course object

Dim oCourse As COMInteropDemo.ICourseInfo

Set oCourse = oCourseManagement.GetCourse

MsgBox (oCourse.Number & " " & oCourse.Title)

' get a reference to another serviced component

Dim oCustomerControl As COMInteropDemo.CustomerControl

Set oCustomerControl = oCourseManagement.GetCustomerControl()

' get a serialized customer

Dim oCustomer As COMInteropDemo.Customer

Set oCustomer = oCustomerControl.GetCustomer()

MsgBox (oCustomer.Name)

对于那些能在类型库里找到信息的方法,在编写代码时Visual Basic 6提供了Intellisense功能。接口ICourseManagement和ICourseInfo是这样的情况,但CustomerControl和Customer就不是如此。后面两个类型只提供了调度接口,关于方法、属性和参数的信息只能在运行时由反射机制获得。

所以,对于Visual Basic 6客户端,较好的选择是调度接口和双重接口。在.NET组件创建双重接口也是可行的,只需应用特性[ClassInterface(ClassInterface Type.AutoDual)]到类上即可,下面会有介绍。

查看所有评论(0)条】

最近评论



正在载入评论列表...
热点评论