【问题标题】:How to access an IUnknown com interface on com如何访问 com 上的 IUnknown com 接口
【发布时间】:2015-10-13 21:12:00
【问题描述】:

据我了解,每个使用 com 通信的程序都必须实现 IUnknown 接口。

查询接口方法是调用查询接口的方法。

我的问题是如何使用此方法或访问此 IUnknown 接口, 使用 Jacob jar 甚至使用 vbscript?

如果可能的话,我想要一个 vbscript 中的代码示例。

【问题讨论】:

    标签: java dll vbscript com


    【解决方案1】:
    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.  
    

    【讨论】:

    • 1.我如何运行这个 vb 示例? java代码也可以吗?有没有 iunknown 的 java 例子?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 2013-08-21
    • 2014-01-06
    • 2010-12-17
    • 2010-10-20
    • 2014-02-19
    相关资源
    最近更新 更多