2013-08-16 50 views
0

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

+0

似乎我不是第一个有这个问题的人https://www.ruby-forum.com/topic/217965 –

回答

0

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

+0

我已经快速浏览了https://github.com/djberg96/pr- WIN32OLE。我认为我可以使用它来实现调用公开接口的东西。 –

相关问题