From d50f882cf0a129129a5120a2b570dc0d0bf005b1 Mon Sep 17 00:00:00 2001 From: suke Date: Fri, 16 Mar 2007 13:24:06 +0000 Subject: [PATCH] * ext/win32ole/win32ole.c: add WIN32OLE#ole_activex_initialize, a little bit supporting ActiveX control. [ruby-talk:241188] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12082 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++ ext/win32ole/win32ole.c | 51 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 260b4d9eee..fb6f343aae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Mar 16 22:19:24 2007 Masaki Suketa + + * ext/win32ole/win32ole.c: add WIN32OLE#ole_activex_initialize, + a little bit supporting ActiveX control. [ruby-talk:241188] + Fri Mar 16 22:16:58 2007 Minero Aoki * lib/net/http.rb: merge Ruby-SSPI patch contributed by Justin diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 5d8c59dbf4..c63401a7c8 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -116,7 +116,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "1.0.1" +#define WIN32OLE_VERSION "1.0.2" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -363,6 +363,7 @@ static VALUE ole_usertype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE t static VALUE ole_ptrtype2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails); static VALUE ole_typedesc2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails); static VALUE fole_method_help(VALUE self, VALUE cmdname); +static VALUE fole_activex_initialize(VALUE self); static VALUE foletype_s_ole_classes(VALUE self, VALUE typelib); static VALUE foletype_s_typelibs(VALUE self); static VALUE foletype_s_progids(VALUE self); @@ -4259,6 +4260,53 @@ fole_method_help(VALUE self, VALUE cmdname) return obj; } +/* + * call-seq: + * WIN32OLE#ole_activex_initialize() -> Qnil + * + * Initialize WIN32OLE object(ActiveX Control) by calling + * IPersistMemory::InitNew. + * + * Before calling OLE method, some kind of the ActiveX controls + * created with MFC should be initialized by calling + * IPersistXXX::InitNew. + * + * If and only if you recieved the exception "HRESULT error code: + * 0x8000ffff catastrophic failure", try this method before + * invoking any ole_method. + * + * obj = WIN32OLE.new("ProgID_or_GUID_of_ActiveX_Control") + * obj.ole_activex_initialize + * obj.method(...) + * + */ +static VALUE +fole_activex_initialize(VALUE self) +{ + struct oledata *pole; + IPersistMemory *pPersistMemory; + + HRESULT hr = S_OK; + + OLEData_Get_Struct(self, pole); + + hr = pole->pDispatch->lpVtbl->QueryInterface(pole->pDispatch, &IID_IPersistMemory, + (void **)&pPersistMemory); + if (SUCCEEDED(hr)) { + hr = pPersistMemory->lpVtbl->InitNew(pPersistMemory); + OLE_RELEASE(pPersistMemory); + if (SUCCEEDED(hr)) { + return Qnil; + } + } + + if (FAILED(hr)) { + ole_raise(hr, eWIN32OLERuntimeError, "fail to initialize ActiveX control"); + } + + return Qnil; +} + /* * call-seq: * WIN32OLE_TYPE.ole_classes(typelib) @@ -7959,6 +8007,7 @@ Init_win32ole() rb_define_method(cWIN32OLE, "ole_method", fole_method_help, 1); rb_define_alias(cWIN32OLE, "ole_method_help", "ole_method"); + rb_define_method(cWIN32OLE, "ole_activex_initialize", fole_activex_initialize, 0); rb_define_method(cWIN32OLE, "ole_type", fole_type, 0); rb_define_alias(cWIN32OLE, "ole_obj_help", "ole_type"); rb_define_method(cWIN32OLE, "ole_typelib", fole_typelib, 0);