我想通過Ruby訪問CUIAutomation對象。 OLE/COM對象查看器報告以下細節:如何使用ruby的WIN32OLE獲取非「IDispatch」接口的實例?
[
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的實例?
似乎我不是第一個有這個問題的人https://www.ruby-forum.com/topic/217965 –