如何访问 com 上的 IUnknown com 接口

How to access an IUnknown com interface on com

据我了解,每个使用 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 提供对自动化的全面支持。以下 table 列出了 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.