0

我想通过 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 示例中,代码直接使用 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 的实例?

4

1 回答 1

0

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

于 2013-08-21T04:20:24.510 回答