【发布时间】: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-forum.com/topic/217965