【问题标题】:How do you use ruby's WIN32OLE to get an instance of a non "IDispatch" interface?如何使用 ruby​​ 的 WIN32OLE 获取非“IDispatch”接口的实例?
【发布时间】:2013-08-21 12:20:24
【问题描述】:

我想通过 Ruby 访问 CUIAutomation 对象。 OLE/COM 对象查看器报告以下详细信息:

[
  uuid(FF48DBA4-60EF-4201-AA87-54103EEF594E),
  version(1.0),
  helpstring("The Central Class for UIAutomation")
]
coclass CUIAutomation {
    [default] interface IUIAutomation;
};

我尝试使用 UUID 访问它

 WIN32OLE.new('{FF48DBA4-60EF-4201-AA87-54103EEF594E}')
WIN32OLERuntimeError: failed to create WIN32OLE object from `{FF48DBA4-60EF-4201-AA87-54103EEF594E}'
    HRESULT error code:0x80004002
      No such interface supported

查看WIN3OLE.new 的实现,它尝试获取IDispatch 接口,但失败了。

...
/* get IDispatch interface */
hr = CoCreateInstance(&clsid, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
                      &IID_IDispatch, &p);
...

Microsoft examples中的代码直接使用了IID_IUIAutomation接口

#include <uiautomation.h>

// CoInitialize must be called before calling this function, and the  
// caller must release the returned pointer when finished with it.
// 
HRESULT InitializeUIAutomation(IUIAutomation **ppAutomation)
{
    return CoCreateInstance(CLSID_CUIAutomation, NULL,
        CLSCTX_INPROC_SERVER, IID_IUIAutomation, 
        reinterpret_cast<void**>(ppAutomation));
}

我需要修补和重建 Win32OLE 吗?我还能如何获得 CUIAutomation 的实例?

【问题讨论】:

标签: ruby com win32ole


【解决方案1】:

简短的回答是 - 你不知道。 Win32Ole 需要 IDispatch 提供的功能。如果 COM 对象不公开对 IDispatch 的访问,则它与 Win32Ole 不兼容。唯一的选择是使用另一种语言(如 C/C++)开发您自己的 IDispatch 包装器,然后您可以将其与 Win32Ole 一起使用。

【讨论】:

猜你喜欢
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
  • 2017-01-10
  • 1970-01-01
  • 2011-10-24
  • 1970-01-01
  • 1970-01-01
  • 2021-04-12
相关资源
最近更新 更多