Scripting Clients
脚本客户端
脚本客户端只能使用服务组件的IDispatch接口。对于VBScript,CreateObject方法被用于创建COM组件的实例,这里的传入参数是组件的progid。在这些代码背后,调用courseManagement.GetCourse方法时,脚本客户端首先会调用GetIDsOfNames把方法名“GetCourse”作为参数传入以得到dispid中,然后才会调用Invoke执行服务组件上对应的方法。这和你前面看到的C++客户端示例类似。只是对于脚本客户端,这些都在脚本运行时自动完成了。
代码段4-12 VBScript客户端
' VBScript source code
Dim courseManagement
Set courseManagement =
CreateObject("Demos.COMInterop.CourseManagement")
Dim course
Set course = courseManagement.GetCourse()
MsgBox course.Number & " " & course.Title
Dim customerControl
Set customerControl = courseManagement.GetCustomerControl()
Dim customer
Set customer = customerControl.GetCustomer()
MsgBox customer.Name
脚本客户端只能使用IDispatch接口,所以只有调度接口和双重接口才起作用。






