我想通过 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 的实例?