diff options
Diffstat (limited to 'ext/win32ole')
-rw-r--r-- | ext/win32ole/win32ole.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index 5d8c59dbf..c63401a7c 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); @@ -4260,6 +4261,53 @@ fole_method_help(VALUE self, VALUE cmdname) } /* + * 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); |