【发布时间】:2015-10-13 21:12:00
【问题描述】:
据我了解,每个使用 com 通信的程序都必须实现 IUnknown 接口。
查询接口方法是调用查询接口的方法。
我的问题是如何使用此方法或访问此 IUnknown 接口, 使用 Jacob jar 甚至使用 vbscript?
如果可能的话,我想要一个 vbscript 中的代码示例。
【问题讨论】:
据我了解,每个使用 com 通信的程序都必须实现 IUnknown 接口。
查询接口方法是调用查询接口的方法。
我的问题是如何使用此方法或访问此 IUnknown 接口, 使用 Jacob jar 甚至使用 vbscript?
如果可能的话,我想要一个 vbscript 中的代码示例。
【问题讨论】:
Set x = CreateObject("Object.Name")
那是 VBScript。
这来自自动化编程参考的附录中的帮助。注意 VBS 只做 GetObject/CreateObject。所以 CoCreateInstance 得到 IUnknown。然后用于查询 IDispatch。所有其他接口都继承自 IUnknown,因此您可以在任何接口上查询引用,因为 IUnknown 的方法在每个接口中。
**Component Automation**
将 Visual Basic 映射到自动化
Visual Basic 完全支持自动化。下表列出了 Visual Basic 语句如何转换为 OLE API。
Visual Basic statement OLE APIs
CreateObject (ProgID)
CLSIDFromProgID
CoCreateInstance
QueryInterface to get IDispatch interface.
GetObject (filename, ProgID)
CLSIDFromProgID
CoCreateInstance
QueryInterface for IPersistFile interface.
Load on IPersistFile interface.
QueryInterface to get IDispatch interface.
GetObject (filename)
CreateBindCtx creates the bind context for the subsequent functions.
MkParseDisplayName returns a moniker handle for BindMoniker.
BindMoniker returns a pointer to the IDispatch interface.
Release on moniker handle.
Release on context.
GetObject (ProgID)
CLSIDFromProgID
GetActiveObject on class ID.
QueryInterface to get IDispatch interface.
Dim x As New interface
Find CLSID for interface.
CoCreateInstance
QueryInterface
© Microsoft Corporation. All rights reserved.
【讨论】: