From ef7d00ae15f4ffa46595cb3c3838d0369d9ae754 Mon Sep 17 00:00:00 2001 From: Justin Ko Date: Tue, 1 Mar 2016 11:10:09 -0500 Subject: [PATCH 1/1] Patch for Watir-Classic --- ext/win32ole/win32ole.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 4d664e8..0be255c 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -3879,6 +3879,39 @@ free_enc2cp(void) st_free_table(enc2cp_table); } +/* + * WIN32OLE.connect_unknown( pUnknown ) --> aWIN32OLE + * ---- + * Returns running OLE Automation object or WIN32OLE object from an IUnknown pointer + * the IUnknown pointer is passed in as a FIXNUM + */ +static VALUE +fole_s_connect_unknown(VALUE self, VALUE iUnknown) +{ + HRESULT hr; + IDispatch *pDispatch; + IUnknown *pUnknown; + + /* initialize to use OLE */ + ole_initialize(); + + //cast from int to IUnknown* + pUnknown = (IUnknown*)FIX2INT(iUnknown); + + hr = pUnknown->lpVtbl->QueryInterface(pUnknown, &IID_IDispatch, + (void **)&pDispatch); + if(FAILED(hr)) { + OLE_RELEASE(pUnknown); + ole_raise(hr, eWIN32OLERuntimeError, + "Failed to connect to WIN32OLE server `%d'", + FIX2INT(iUnknown)); + } + + OLE_RELEASE(pUnknown); + + return create_win32ole_object(self, pDispatch, 0,0); +} + static void com_hash_free(void *ptr) { @@ -3931,6 +3964,7 @@ Init_win32ole(void) rb_define_method(cWIN32OLE, "initialize", fole_initialize, -1); rb_define_singleton_method(cWIN32OLE, "connect", fole_s_connect, -1); + rb_define_singleton_method(cWIN32OLE, "connect_unknown", fole_s_connect_unknown, 1); rb_define_singleton_method(cWIN32OLE, "const_load", fole_s_const_load, -1); rb_define_singleton_method(cWIN32OLE, "ole_free", fole_s_free, 1); -- 1.9.5.github.0